e_comp_wl & e_comp_wl_input: added an initial implementation for zwp_relative_pointer...
authorSungjin Park <sj76.park@samsung.com>
Tue, 18 Apr 2023 05:42:12 +0000 (14:42 +0900)
committerSungjin Park <sj76.park@samsung.com>
Tue, 18 Apr 2023 09:53:03 +0000 (18:53 +0900)
Signed-off-by: Sungjin Park <sj76.park@samsung.com>
src/bin/e_comp_wl.c
src/bin/e_comp_wl.h
src/bin/e_comp_wl_input.c
src/bin/e_comp_wl_input.h

index 3d68612d383ab4742f0a97030464e44890056eed..54ca5775486cb5eea5f85e7a47c3c8ed0580528a 100644 (file)
@@ -5597,6 +5597,47 @@ e_comp_wl_mouse_button_send(E_Client *ec, int buttons, Eina_Bool pressed, Ecore_
    return EINA_TRUE;
 }
 
+EINTERN Eina_Bool
+e_comp_wl_mouse_relative_motion_send(E_Client *ec,
+                                     int dx, int dy, int dx_unaccel, int dy_unaccel,
+                                     Ecore_Device *dev, uint64_t time)
+{
+   uint32_t serial;
+   struct wl_client *wc;
+   struct wl_resource *res;
+   Eina_List *l;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data->surface, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(e_comp_wl, EINA_FALSE);
+
+   E_Client *focused = e_client_focused_get();
+   if ((focused) && (ec != focused)) return EINA_FALSE;
+
+   wc = wl_resource_get_client(ec->comp_data->surface);
+   if (!time) time = e_util_timestamp_us_get();
+   serial = wl_display_next_serial(e_comp_wl->wl.disp);
+
+   if (dev) _e_comp_wl_send_event_device(wc, time, dev, serial);
+   else _e_comp_wl_device_send_last_event_device(ec, ECORE_DEVICE_CLASS_MOUSE, time);
+
+   EINA_LIST_FOREACH(e_comp_wl->relative_ptr.resources, l, res)
+     {
+        if (!e_comp_wl_input_relative_pointer_check(res)) continue;
+        if (wl_resource_get_client(res) != wc) continue;
+        zwp_relative_pointer_v1_send_relative_motion(res,
+                                                     (uint32_t)(time >> 32),
+                                                     (uint32_t)(time),
+                                                     wl_fixed_from_int(dx),
+                                                     wl_fixed_from_int(dy),
+                                                     wl_fixed_from_int(dx_unaccel),
+                                                     wl_fixed_from_int(dy_unaccel));
+     }
+
+   return EINA_TRUE;
+}
+
 EINTERN Eina_Bool
 e_comp_wl_mouse_move_send(E_Client *ec, int x, int y, Ecore_Device *dev, uint32_t time)
 {
index 123a81be43c1d924ac063bb62ad349c61ecc072e..a12d36604dc3e0dd0053ce125a090dabc9905440 100644 (file)
@@ -14,6 +14,9 @@ typedef struct _E_Comp_Wl_Pid_Hook E_Comp_Wl_Pid_Hook;
 
 #  include <xkbcommon/xkbcommon.h>
 
+#  include <relative-pointer-unstable-v1-server-protocol.h>
+#  include <pointer-constraints-unstable-v1-server-protocol.h>
+
 #  ifdef __linux__
 #   include <linux/input.h>
 #  else
@@ -236,6 +239,24 @@ struct _E_Comp_Wl_Data
         unsigned int num_devices;
      } ptr;
 
+   struct
+     {
+        Eina_List *resources;
+        E_Client *ec;
+        Eina_Bool enabled : 1;
+        struct wl_global *global;
+        struct wl_resource *resource;
+     } relative_ptr;
+
+   struct
+     {
+        Eina_List *resources;
+        E_Client *ec;
+        Eina_Bool enabled : 1;
+        struct wl_global *global;
+        struct wl_resource *resource;
+     } ptr_constraints;
+
    struct
      {
         Eina_List *resources;
@@ -598,6 +619,7 @@ EINTERN Eina_Bool e_comp_wl_mouse_move_send(E_Client *ec, int x, int y, Ecore_De
 EINTERN Eina_Bool e_comp_wl_mouse_wheel_send(E_Client *ec, int direction, int z, Ecore_Device *dev, uint32_t time);
 EINTERN Eina_Bool e_comp_wl_mouse_in_send(E_Client *ec, int x, int y, Ecore_Device *dev, uint32_t time);
 EINTERN Eina_Bool e_comp_wl_mouse_out_send(E_Client *ec, Ecore_Device *dev, uint32_t time);
+EINTERN Eina_Bool e_comp_wl_mouse_relative_motion_send(E_Client *ec, int dx, int dy, int dx_unaccel, int dy_unaccel, Ecore_Device *dev, uint64_t time);
 EINTERN void e_comp_wl_mouse_in_renew(E_Client *ec, int buttons, int x, int y, void *data, Evas_Modifier *modifiers, Evas_Lock *locks, unsigned int timestamp, Evas_Event_Flags event_flags, Evas_Device *dev, Evas_Object *event_src);
 EINTERN void e_comp_wl_mouse_out_renew(E_Client *ec, int buttons, int x, int y, void *data, Evas_Modifier *modifiers, Evas_Lock *locks, unsigned int timestamp, Evas_Event_Flags event_flags, Evas_Device *dev, Evas_Object *event_src);
 EINTERN Eina_Bool e_comp_wl_key_process(Ecore_Event_Key *ev, int type);
index 522bae6e43c5191319f43f8214ed780d43684eac..64b619e1e8f267241378fd07d199f1c041fd1062 100644 (file)
@@ -410,6 +410,89 @@ _e_comp_wl_input_cb_bind_seat(struct wl_client *client, void *data EINA_UNUSED,
      wl_seat_send_name(res, e_comp_wl->seat.name);
 }
 
+static void
+_e_comp_wl_cb_relative_pointer_destroy(struct wl_client *client,
+                                       struct wl_resource *resource)
+{
+   ERR("Destroy relative pointer: (resource: %u) (client: %p)", wl_resource_get_id(resource), client);
+   wl_resource_destroy(resource);
+}
+
+static const struct zwp_relative_pointer_v1_interface _e_relative_pointer_interface = {
+       _e_comp_wl_cb_relative_pointer_destroy
+};
+
+static void
+_e_comp_wl_cb_relative_pointer_manager_destroy(struct wl_client *client,
+                                               struct wl_resource *resource)
+{
+   ERR("Destroy relative pointer manager: (resource:%u) (client: %p)", wl_resource_get_id(resource), client);
+   wl_resource_destroy(resource);
+}
+
+static void
+_e_comp_wl_cb_unbind_relative_pointer(struct wl_resource *resource)
+{
+   ERR("Unbind relative_pointer: (resource: %u) (client: %p)", wl_resource_get_id(resource), wl_resource_get_client(resource));
+
+   e_comp_wl->relative_ptr.resources = 
+     eina_list_remove(e_comp_wl->relative_ptr.resources, resource);
+}
+
+static void
+_e_comp_wl_cb_relative_pointer_manager_get_relative_pointer(struct wl_client *client,
+                                                            struct wl_resource *resource,
+                                                            uint32_t id,
+                                                            struct wl_resource *pointer_resource)
+{
+   struct wl_resource *res = NULL;
+
+   res = wl_resource_create(client, &zwp_relative_pointer_v1_interface,
+                            1, id);
+
+   if (!res)
+     {
+        ERR("Could not create the resource for relative pointer: %m");
+        wl_client_post_no_memory(client);
+        return;
+     }
+
+   ERR("Relative pointer resource created: (resource:%u) (client: %p)", wl_resource_get_id(res), client);
+
+   e_comp_wl->relative_ptr.resources =
+     eina_list_append(e_comp_wl->relative_ptr.resources, res);
+
+   /* FIXME: must consider destroying relative pointer together
+             when the wl_pointer is destroyed */
+   (void) pointer_resource;
+   wl_resource_set_implementation(res, &_e_relative_pointer_interface, NULL, _e_comp_wl_cb_unbind_relative_pointer);
+}
+
+static const struct zwp_relative_pointer_manager_v1_interface _e_relative_pointer_manager_interface = {
+       _e_comp_wl_cb_relative_pointer_manager_destroy,
+       _e_comp_wl_cb_relative_pointer_manager_get_relative_pointer,
+};
+
+static void
+_e_comp_wl_input_cb_bind_relative_pointer_manager(struct wl_client *client, void *data EINA_UNUSED, uint32_t version, uint32_t id)
+{
+   struct wl_resource *resource = NULL;
+
+   resource = wl_resource_create(client,
+                                 &zwp_relative_pointer_manager_v1_interface,
+                                 1, id);
+   if (!resource)
+     {
+        ERR("Could not create resource for relative pointer manager: %m");
+        return;
+     }
+
+   DBG("Bind relative pointer: (resource:%u) (client: %p)", wl_resource_get_id(resource), client);
+
+   wl_resource_set_implementation(resource, &_e_relative_pointer_manager_interface, NULL, NULL);
+   //FIXME: consider to add unbind fucntion
+}
+
 static void
 _e_comp_wl_input_keymap_cache_create(const char *keymap_path, char *keymap_data)
 {
@@ -632,6 +715,18 @@ e_comp_wl_input_init(void)
         return EINA_FALSE;
      }
 
+   /* create the global resource for relative pointer */
+   e_comp_wl->relative_ptr.global =
+     wl_global_create(e_comp_wl->wl.disp,
+                      &zwp_relative_pointer_manager_v1_interface, 1,
+                      e_comp->wl_comp_data,
+                      _e_comp_wl_input_cb_bind_relative_pointer_manager);
+   if (!e_comp_wl->relative_ptr.global)
+     {
+        ERR("Could not create global for relative pointer: %m");
+        return EINA_FALSE;
+     }
+
    wl_array_init(&e_comp_wl->kbd.keys);
    wl_array_init(&e_comp_wl->kbd.routed_keys);
 
@@ -663,6 +758,11 @@ e_comp_wl_input_shutdown(void)
    EINA_LIST_FREE(e_comp_wl->ptr.resources, res)
      wl_resource_destroy(res);
 
+   /* destroy relative pointer resources */
+   EINA_LIST_FREE(e_comp_wl->relative_ptr.resources, res)
+     wl_resource_destroy(res);
+   //FIXME: destroy relative_pointer_manager
+
    /* destroy keyboard resources */
    EINA_LIST_FREE(e_comp_wl->kbd.resources, res)
      wl_resource_destroy(res);
@@ -693,6 +793,11 @@ e_comp_wl_input_shutdown(void)
    if (e_comp_wl->xkb.context)
      xkb_context_unref(e_comp_wl->xkb.context);
 
+   /* destroy the global relative pointer resource */
+   if (e_comp_wl->relative_ptr.global)
+     wl_global_destroy(e_comp_wl->relative_ptr.global);
+   e_comp_wl->relative_ptr.global = NULL;
+
    /* destroy the global seat resource */
    if (e_comp_wl->seat.global)
      wl_global_destroy(e_comp_wl->seat.global);
@@ -709,6 +814,13 @@ e_comp_wl_input_pointer_check(struct wl_resource *res)
                                   &_e_pointer_interface);
 }
 
+EINTERN Eina_Bool
+e_comp_wl_input_relative_pointer_check(struct wl_resource *res)
+{
+   return wl_resource_instance_of(res, &zwp_relative_pointer_v1_interface,
+                                  &_e_relative_pointer_interface);
+}
+
 EINTERN Eina_Bool
 e_comp_wl_input_keyboard_check(struct wl_resource *res)
 {
index fedcc6a91b0e58a3018c9e58c608c419acb0cace..1e9149881a9e9a61dbff48650bc5d7ddbc236128 100644 (file)
@@ -15,6 +15,7 @@ struct _E_Event_Text_Input_Panel_Visibility_Change
 EINTERN Eina_Bool e_comp_wl_input_init(void);
 EINTERN void e_comp_wl_input_shutdown(void);
 EINTERN Eina_Bool e_comp_wl_input_pointer_check(struct wl_resource *res);
+EINTERN Eina_Bool e_comp_wl_input_relative_pointer_check(struct wl_resource *res);
 EINTERN Eina_Bool e_comp_wl_input_keyboard_check(struct wl_resource *res);
 EINTERN Eina_Bool e_comp_wl_input_touch_check(struct wl_resource *res);