Add interception of key event 66/153966/4
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Wed, 4 Oct 2017 09:19:22 +0000 (11:19 +0200)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Fri, 6 Oct 2017 07:38:34 +0000 (09:38 +0200)
Module can intercept key events and send information
about them via dbus

Change-Id: I5e5f56ac3467e6bc7b22b224339f0c3d82e85b4b

src/Makefile.am
src/e_mod_main.c
src/e_mod_main.h
src/e_universal_switch.c [new file with mode: 0644]
src/e_universal_switch.h [new file with mode: 0644]

index 91443ce..c2cdbd3 100644 (file)
@@ -9,7 +9,8 @@ module_la_SOURCES      = \
        e_mod_main.c \
        e_screen_reader_config.c \
        e_screen_reader_gestures.c \
-       e_dispatch_gesture_event.c
+       e_dispatch_gesture_event.c \
+       e_universal_switch.c
 
 module_la_LIBADD       =
 module_la_CFLAGS       = @ENLIGHTENMENT_CFLAGS@
index 855a5d6..aa6ba5a 100644 (file)
@@ -5,6 +5,7 @@
 #include <e_screen_reader_private.h>
 #include <vconf.h>
 #include <e_dispatch_gesture_event.h>
+#include "e_universal_switch.h"
 
 #define E_A11Y_SERVICE_BUS_NAME "org.enlightenment.wm-screen-reader"
 #define E_A11Y_SERVICE_NAVI_IFC_NAME "org.tizen.GestureNavigation"
@@ -14,9 +15,6 @@
 int _eina_log_dom = 0;
 #define DBG(...)  do EINA_LOG_DOM_DBG(_eina_log_dom, __VA_ARGS__); while(0)
 
-// constant below allows to distinguish the origin of mouse events between one created in this module and the one created by user
-#define MAGIC_DEVICE_NUMBER 2048
-
 
 static Eina_Bool g_gesture_navi;
 static Eina_List *handlers;
@@ -27,8 +25,6 @@ Eina_Bool is_screen_reader_support;
 int highlighted_object_x, highlighted_object_y;
 Eina_Bool is_selection_mode;
 int object_needs_scroll_from_x, object_needs_scroll_from_y;
-Ecore_Event_Filter *ssp_ef = NULL;
-extern int device_number_shift;
 
 EAPI E_Module_Api e_modapi =
 {
@@ -36,15 +32,10 @@ EAPI E_Module_Api e_modapi =
    "Screen Reader Module of Window Manager"
 };
 
-typedef enum signal_type_ {
-       GESTURE_DETECTED_SIGNAL,
-       MOUSE_DOWN_SIGNAL,
-       MOUSE_UP_SIGNAL
-} signal_type;
-
 
 static Eldbus_Message *_sc_enable(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
 static Eldbus_Message *_ssp_enable(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
+static Eldbus_Message *_asp_enable(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
 static Eldbus_Message *_is_slider(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
 static Eldbus_Message *_highlighted_object_info(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
 static Eldbus_Message *_is_screen_reader_support(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
@@ -59,6 +50,9 @@ static const Eldbus_Method methods[] = {
       { "ScreenSwitchProviderEnabled", ELDBUS_ARGS({"b", "bool"}), NULL,
         _ssp_enable
       },
+      { "AccessoriesSwitchProviderEnabled", ELDBUS_ARGS({"b", "bool"}), NULL,
+        _asp_enable
+      },
       { "IsSlider", ELDBUS_ARGS({"b", "bool"}), NULL,
         _is_slider
       },
@@ -90,6 +84,8 @@ static const Eldbus_Signal signals[] = {
                                             0},
    [MOUSE_DOWN_SIGNAL] = {"MouseDown", ELDBUS_ARGS({"i", "deviceId"}), 0},
    [MOUSE_UP_SIGNAL] = {"MouseUp", ELDBUS_ARGS({"i", "deviceId"}), 0},
+   [KEY_DOWN_SIGNAL] = {"KeyDown", ELDBUS_ARGS({"s", "keyId"}), 0},
+   [KEY_UP_SIGNAL] = {"KeyUp", ELDBUS_ARGS({"s", "keyId"}), 0},
    { }
 };
 
@@ -306,47 +302,26 @@ _sc_enable(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
    return NULL;
 }
 
-static Eina_Bool
-_ssp_filter(void *data, void *loop_data, int type, void *event)
+static Eldbus_Message *
+_ssp_enable(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
 {
-   if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN || type == ECORE_EVENT_MOUSE_BUTTON_UP)
+   Eina_Bool enabled = EINA_FALSE;
+   if (!eldbus_message_arguments_get(msg, "b", &enabled))
       {
-         Ecore_Event_Mouse_Button *ev = event;
-
-         if (ev->multi.device >= MAGIC_DEVICE_NUMBER)
-            {
-               ev->multi.device = ev->multi.device - MAGIC_DEVICE_NUMBER;
-               return EINA_TRUE;
-            }
-
-         if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN)
-            eldbus_service_signal_emit(iface, MOUSE_DOWN_SIGNAL, ev->multi.device);
-         else
-            eldbus_service_signal_emit(iface, MOUSE_UP_SIGNAL, ev->multi.device);
-
-         return EINA_FALSE;
+         ERROR("eldbus_message_arguments_get() error\n");
+         return NULL;
       }
 
-   if (type == ECORE_EVENT_MOUSE_MOVE)
-      {
-         Ecore_Event_Mouse_Move *ev = event;
-
-         if (ev->multi.device >= MAGIC_DEVICE_NUMBER)
-            {
-               ev->multi.device = ev->multi.device - MAGIC_DEVICE_NUMBER;
-               return EINA_TRUE;
-            }
-         else
-            {
-               return EINA_FALSE;
-            }
-      }
+   if (enabled)
+      _ssp_submodule_init();
+   else
+      _ssp_submodule_shutdown();
 
-   return EINA_TRUE;
+   return eldbus_message_method_return_new(msg);
 }
 
 static Eldbus_Message *
-_ssp_enable(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
+_asp_enable(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
 {
    Eina_Bool enabled = EINA_FALSE;
    if (!eldbus_message_arguments_get(msg, "b", &enabled))
@@ -355,17 +330,10 @@ _ssp_enable(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
          return NULL;
       }
 
-   if (enabled && !ssp_ef)
-      {
-         ssp_ef = ecore_event_filter_add(NULL, _ssp_filter, NULL, NULL);
-         device_number_shift = MAGIC_DEVICE_NUMBER;
-      }
-   else if (!enabled)
-      {
-         ecore_event_filter_del(ssp_ef);
-         ssp_ef = NULL;
-         device_number_shift = 0;
-      }
+   if (enabled)
+      _asp_submodule_init();
+   else
+      _asp_submodule_shutdown();
 
    return eldbus_message_method_return_new(msg);
 }
index fc6520c..f239235 100644 (file)
@@ -10,4 +10,12 @@ EAPI void* e_modapi_init (E_Module *m);
 EAPI int e_modapi_shutdown (E_Module *m);
 EAPI int e_modapi_save (E_Module *m);
 
-#endif//__E_MOD_MAIN_H__
\ No newline at end of file
+typedef enum signal_type_ {
+       GESTURE_DETECTED_SIGNAL,
+       MOUSE_DOWN_SIGNAL,
+       MOUSE_UP_SIGNAL,
+       KEY_DOWN_SIGNAL,
+       KEY_UP_SIGNAL
+} signal_type;
+
+#endif//__E_MOD_MAIN_H__
diff --git a/src/e_universal_switch.c b/src/e_universal_switch.c
new file mode 100644 (file)
index 0000000..dd66869
--- /dev/null
@@ -0,0 +1,116 @@
+#include "e_universal_switch.h"
+#include "e_mod_main.h"
+
+// constant below allows to distinguish the origin of mouse events between one created in this module and the one created by user
+#define DEVICE_NUMBER_OFFSET 2048
+
+extern Eldbus_Service_Interface *iface;
+extern int device_number_shift;
+
+static Ecore_Event_Filter *screen_switch_provider_filter = NULL;
+static Ecore_Event_Filter *accessories_switch_provider_filter = NULL;
+
+static const char* uncaught_keys[] = {"XF86Back", "XF86Menu", "XF86AudioRaiseVolume", "XF86AudioLowerVolume"};
+
+static Eina_Bool _ssp_filter(void *data, void *loop_data, int type, void *event)
+{
+   if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN || type == ECORE_EVENT_MOUSE_BUTTON_UP)
+      {
+         Ecore_Event_Mouse_Button *ev = event;
+
+         if (ev->multi.device >= DEVICE_NUMBER_OFFSET)
+            {
+               ev->multi.device = ev->multi.device - DEVICE_NUMBER_OFFSET;
+               return EINA_TRUE;
+            }
+
+         if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN)
+            eldbus_service_signal_emit(iface, MOUSE_DOWN_SIGNAL, ev->multi.device);
+         else
+            eldbus_service_signal_emit(iface, MOUSE_UP_SIGNAL, ev->multi.device);
+
+         return EINA_FALSE;
+      }
+
+   if (type == ECORE_EVENT_MOUSE_MOVE)
+      {
+         Ecore_Event_Mouse_Move *ev = event;
+
+         if (ev->multi.device >= DEVICE_NUMBER_OFFSET)
+            {
+               ev->multi.device = ev->multi.device - DEVICE_NUMBER_OFFSET;
+               return EINA_TRUE;
+            }
+         else
+            {
+               return EINA_FALSE;
+            }
+      }
+
+   return EINA_TRUE;
+}
+
+static Eina_Bool _is_intercepted(const char *key)
+{
+   int uncaught_keys_size = sizeof(uncaught_keys) / sizeof(uncaught_keys[0]);
+
+   for (int i = 0; i < uncaught_keys_size; ++i)
+      if (strcmp(uncaught_keys[i], key) == 0)
+         return EINA_FALSE;
+
+   return EINA_TRUE;
+}
+
+static Eina_Bool _asp_filter(void *data, void *loop_data, int type, void *event)
+{
+   if (type != ECORE_EVENT_KEY_DOWN && type != ECORE_EVENT_KEY_UP)
+      return EINA_TRUE;
+
+   Ecore_Event_Key *ev = event;
+
+   if (!_is_intercepted(ev->key))
+      return EINA_TRUE;
+
+   if (type == ECORE_EVENT_KEY_DOWN)
+      eldbus_service_signal_emit(iface, KEY_DOWN_SIGNAL, ev->key);
+   else
+      eldbus_service_signal_emit(iface, KEY_UP_SIGNAL, ev->key);
+
+   return EINA_FALSE;
+}
+
+void _ssp_submodule_init()
+{
+   if (screen_switch_provider_filter)
+      return;
+
+   screen_switch_provider_filter = ecore_event_filter_add(NULL, _ssp_filter, NULL, NULL);
+   device_number_shift = DEVICE_NUMBER_OFFSET;
+}
+
+void _ssp_submodule_shutdown()
+{
+   if (!screen_switch_provider_filter)
+      return;
+
+   ecore_event_filter_del(screen_switch_provider_filter);
+   screen_switch_provider_filter = NULL;
+   device_number_shift = 0;
+}
+
+void _asp_submodule_init()
+{
+   if (accessories_switch_provider_filter)
+      return;
+
+   accessories_switch_provider_filter = ecore_event_filter_add(NULL, _asp_filter, NULL, NULL);
+}
+
+void _asp_submodule_shutdown()
+{
+   if (!accessories_switch_provider_filter)
+      return;
+
+   ecore_event_filter_del(accessories_switch_provider_filter);
+   accessories_switch_provider_filter = NULL;
+}
diff --git a/src/e_universal_switch.h b/src/e_universal_switch.h
new file mode 100644 (file)
index 0000000..3eaa190
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef E_UNIVERSAL_SWITCH_H_
+#define E_UNIVERSAL_SWITCH_H_
+
+void _ssp_submodule_init();
+void _ssp_submodule_shutdown();
+
+void _asp_submodule_init();
+void _asp_submodule_shutdown();
+
+#endif