ecore wayland : add ECORE_WL_EVENT_GLOBAL_ADD/REMOVED, ECORE_WL_EVENT_KEYMAP_UPDATE... 96/65096/10
authorSung-Jin Park <sj76.park@samsung.com>
Tue, 5 Apr 2016 08:44:37 +0000 (17:44 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 18 Apr 2016 10:15:47 +0000 (03:15 -0700)
Change-Id: I48b54951261f7ab4357aa8b50c39ea199bde1f49

src/lib/ecore_wayland/Ecore_Wayland.h
src/lib/ecore_wayland/ecore_wl.c
src/lib/ecore_wayland/ecore_wl_input.c

index 194b7b6..4152dd1 100644 (file)
@@ -80,6 +80,22 @@ typedef struct _Ecore_Wl_Event_Aux_Hint_Allowed Ecore_Wl_Event_Aux_Hint_Allowed;
 typedef struct _Ecore_Wl_Event_Window_Iconify_State_Change Ecore_Wl_Event_Window_Iconify_State_Change;
 typedef struct _Ecore_Wl_Event_Effect Ecore_Wl_Event_Effect_Start;
 typedef struct _Ecore_Wl_Event_Effect Ecore_Wl_Event_Effect_End;
+typedef struct _Ecore_Wl_Display Ecore_Wl_Display;
+typedef struct _Ecore_Wl_Event_Global Ecore_Wl_Event_Global;
+typedef struct _Ecore_Wl_Event_Keymap_Update Ecore_Wl_Event_Keymap_Update;
+
+struct _Ecore_Wl_Event_Global
+{
+   Ecore_Wl_Display *display;
+   Eina_Stringshare *interface;
+   unsigned int id, version;
+};
+
+struct _Ecore_Wl_Event_Keymap_Update
+{
+   Ecore_Wl_Input *input;
+   struct xkb_keymap *keymap;
+};
 
 enum _Ecore_Wl_Window_Type
 {
@@ -419,6 +435,9 @@ EAPI extern int ECORE_WL_EVENT_AUX_HINT_ALLOWED;
 EAPI extern int ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE;
 EAPI extern int ECORE_WL_EVENT_EFFECT_START;
 EAPI extern int ECORE_WL_EVENT_EFFECT_END;
+EAPI extern int ECORE_WL_EVENT_GLOBAL_ADDED;
+EAPI extern int ECORE_WL_EVENT_GLOBAL_REMOVED;
+EAPI extern int ECORE_WL_EVENT_KEYMAP_UPDATE;
 
 /**
  * @defgroup Ecore_Wl_Init_Group Wayland Library Init and Shutdown Functions
index 1d5705f..7971ec7 100644 (file)
@@ -165,6 +165,9 @@ EAPI int ECORE_WL_EVENT_AUX_HINT_ALLOWED = 0;
 EAPI int ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE = 0;
 EAPI int ECORE_WL_EVENT_EFFECT_START = 0;
 EAPI int ECORE_WL_EVENT_EFFECT_END = 0;
+EAPI int ECORE_WL_EVENT_GLOBAL_ADDED = 0;
+EAPI int ECORE_WL_EVENT_GLOBAL_REMOVED = 0;
+EAPI int ECORE_WL_EVENT_KEYMAP_UPDATE = 0;
 
 static void
 _ecore_wl_init_callback(void *data, struct wl_callback *callback, uint32_t serial EINA_UNUSED)
@@ -253,6 +256,9 @@ ecore_wl_init(const char *name)
         ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE = ecore_event_type_new();
         ECORE_WL_EVENT_EFFECT_START = ecore_event_type_new();
         ECORE_WL_EVENT_EFFECT_END = ecore_event_type_new();
+        ECORE_WL_EVENT_GLOBAL_ADDED = ecore_event_type_new();
+        ECORE_WL_EVENT_GLOBAL_REMOVED = ecore_event_type_new();
+        ECORE_WL_EVENT_KEYMAP_UPDATE = ecore_event_type_new();
      }
 
    if (!(_ecore_wl_disp = calloc(1, sizeof(Ecore_Wl_Display))))
@@ -796,10 +802,21 @@ _ecore_wl_cb_pre_handle_data(void *data, Ecore_Fd_Handler *hdl EINA_UNUSED)
 }
 
 static void
+_cb_global_event_free(void *data EINA_UNUSED, void *event)
+{
+   Ecore_Wl_Event_Global *ev;
+
+   ev = event;
+   eina_stringshare_del(ev->interface);
+   free(ev);
+}
+
+static void
 _ecore_wl_cb_handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version)
 {
    Ecore_Wl_Display *ewd;
    Ecore_Wl_Global *global;
+   Ecore_Wl_Event_Global *ev;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
 
@@ -934,6 +951,19 @@ _ecore_wl_cb_handle_global(void *data, struct wl_registry *registry, unsigned in
 
         ecore_event_add(ECORE_WL_EVENT_INTERFACES_BOUND, ev, NULL, NULL);
      }
+
+   /* allocate space for event structure */
+   ev = calloc(1, sizeof(Ecore_Wl_Event_Global));
+   if (!ev) return;
+
+   ev->id = id;
+   ev->display = ewd;
+   ev->version = version;
+   ev->interface = eina_stringshare_add(interface);
+
+   /* raise an event saying a new global has been added */
+   ecore_event_add(ECORE_WL_EVENT_GLOBAL_ADDED, ev,
+                   _cb_global_event_free, NULL);
 }
 
 static void
@@ -941,6 +971,7 @@ _ecore_wl_cb_handle_global_remove(void *data, struct wl_registry *registry EINA_
 {
    Ecore_Wl_Display *ewd;
    Ecore_Wl_Global *global;
+   Ecore_Wl_Event_Global *ev;
    Eina_Inlist *tmp;
 
    LOGFN(__FILE__, __LINE__, __FUNCTION__);
@@ -950,6 +981,20 @@ _ecore_wl_cb_handle_global_remove(void *data, struct wl_registry *registry EINA_
    EINA_INLIST_FOREACH_SAFE(ewd->globals, tmp, global)
      {
         if (global->id != id) continue;
+
+        /* allocate space for event structure */
+        ev = calloc(1, sizeof(Ecore_Wl_Event_Global));
+        if (!ev) return;
+
+        ev->id = id;
+        ev->display = ewd;
+        ev->version = global->version;
+        ev->interface = eina_stringshare_add(global->interface);
+
+        /* raise an event saying a global has been removed */
+        ecore_event_add(ECORE_WL_EVENT_GLOBAL_REMOVED, ev,
+                        _cb_global_event_free, NULL);
+
         ewd->globals =
           eina_inlist_remove(ewd->globals, EINA_INLIST_GET(global));
         free(global->interface);
index 55ad373..cecc23c 100644 (file)
@@ -63,6 +63,7 @@ static void _ecore_wl_input_cb_pointer_motion(void *data, struct wl_pointer *poi
 static void _ecore_wl_input_cb_pointer_button(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned int serial, unsigned int timestamp, unsigned int button, unsigned int state);
 static void _ecore_wl_input_cb_pointer_axis(void *data, struct wl_pointer *pointer EINA_UNUSED, unsigned int timestamp, unsigned int axis, wl_fixed_t value);
 static void _ecore_wl_input_cb_pointer_frame(void *data, struct wl_callback *callback, unsigned int timestamp EINA_UNUSED);
+static Eina_Bool _ecore_wl_input_keymap_update_send(Ecore_Wl_Input *input);
 static void _ecore_wl_input_cb_keyboard_keymap(void *data, struct wl_keyboard *keyboard EINA_UNUSED, unsigned int format, int fd, unsigned int size);
 static void _ecore_wl_input_cb_keyboard_enter(void *data, struct wl_keyboard *keyboard EINA_UNUSED, unsigned int serial, struct wl_surface *surface, struct wl_array *keys EINA_UNUSED);
 static void _ecore_wl_input_cb_keyboard_leave(void *data, struct wl_keyboard *keyboard EINA_UNUSED, unsigned int serial, struct wl_surface *surface);
@@ -727,6 +728,26 @@ _ecore_wl_input_cb_pointer_frame(void *data, struct wl_callback *callback, unsig
      }
 }
 
+static Eina_Bool
+_ecore_wl_input_keymap_update_send(Ecore_Wl_Input *input)
+{
+   Ecore_Wl_Event_Keymap_Update *ev = NULL;
+
+   if (!input || !(input->xkb.keymap)) return EINA_FALSE;
+
+   /* allocate space for event structure */
+   ev = calloc(1, sizeof(Ecore_Wl_Event_Keymap_Update));
+   if (!ev) return EINA_FALSE;
+
+   ev->input = input;
+   ev->keymap = input->xkb.keymap;
+
+   /* raise an event saying the keymap has been updated */
+   ecore_event_add(ECORE_WL_EVENT_KEYMAP_UPDATE, ev, NULL, NULL);
+
+   return EINA_TRUE;
+}
+
 static void
 _ecore_wl_input_cb_keyboard_keymap(void *data, struct wl_keyboard *keyboard EINA_UNUSED, unsigned int format, int fd, unsigned int size)
 {
@@ -789,6 +810,13 @@ _ecore_wl_input_cb_keyboard_keymap(void *data, struct wl_keyboard *keyboard EINA
      1 << xkb_map_mod_get_index(input->xkb.keymap, XKB_MOD_NAME_CAPS);
    input->xkb.altgr_mask =
      1 << xkb_map_mod_get_index(input->xkb.keymap, "ISO_Level3_Shift");
+
+   if (!_ecore_wl_input_keymap_update_send(input))
+     {
+        xkb_map_unref(input->xkb.keymap);
+        input->xkb.keymap = NULL;
+        return;
+     }
 }
 
 static int