ecore_wl2: support zwp_pointer_constraints protocol 19/296619/3
authorduna.oh <duna.oh@samsung.com>
Tue, 1 Aug 2023 10:48:27 +0000 (19:48 +0900)
committerduna.oh <duna.oh@samsung.com>
Fri, 4 Aug 2023 09:44:06 +0000 (18:44 +0900)
Change-Id: I784190c80be321cfaad7fec7c892c4b500c18e2e

packaging/efl.spec
src/lib/ecore_wl2/Ecore_Wl2.h
src/lib/ecore_wl2/ecore_wl2_display.c
src/lib/ecore_wl2/ecore_wl2_input.c
src/lib/ecore_wl2/ecore_wl2_private.h
src/lib/ecore_wl2/meson.build

index 37a9d6a..547c7c1 100644 (file)
@@ -50,6 +50,7 @@ BuildRequires:  pkgconfig(wtz-foreign-client)
 BuildRequires:  pkgconfig(wtz-screen-client)
 BuildRequires:  pkgconfig(wtz-shell-client)
 BuildRequires:  pkgconfig(relative-pointer-unstable-v1-client)
+BuildRequires:  pkgconfig(pointer-constraints-unstable-v1-client)
 BuildRequires:  wayland-protocols
 Requires:       libwayland-extension-client
 Requires:       libwayland-egl-tizen
index cacd475..7082e5c 100644 (file)
@@ -2629,6 +2629,13 @@ EAPI void ecore_wl2_window_pin_mode_set(Ecore_Wl2_Window *window, Eina_Bool pinn
 EAPI Eina_Bool ecore_wl2_window_pin_mode_get(Ecore_Wl2_Window *window);
 //
 
+// TIZEN_ONLY(20230801) : support zwp pointer constraints protocol
+EAPI Eina_Bool ecore_wl2_window_pointer_constraints_lock_pointer(Ecore_Wl2_Window *win);
+EAPI Eina_Bool ecore_wl2_window_pointer_constraints_unlock_pointer(Ecore_Wl2_Window *win);
+EAPI void ecore_wl2_window_locked_pointer_region_set(Ecore_Wl2_Window *win, int x, int y, int w, int h);
+EAPI void ecore_wl2_window_locked_pointer_cursor_position_hint_set(Ecore_Wl2_Window *win, int x, int y);
+//
+
 # undef EAPI
 # define EAPI
 
index 3af9c35..e3c818e 100644 (file)
@@ -1078,6 +1078,14 @@ _cb_global_add(void *data, struct wl_registry *registry, unsigned int id, const
                            &zwp_relative_pointer_manager_v1_interface, version);
      }
 //
+// TIZEN_ONLY(20230801) : support zwp pointer constraints protocol
+   else if (!strcmp(interface, "zwp_pointer_constraints_v1"))
+     {
+        ewd->wl.pointer_constraints =
+          wl_registry_bind(registry, id,
+                           &zwp_pointer_constraints_v1_interface, version);
+     }
+//
    //
 
 event:
@@ -1197,6 +1205,8 @@ _ecore_wl2_display_globals_cleanup(Ecore_Wl2_Display *ewd)
    if (ewd->wl.wtz_scr) wtz_screen_destroy(ewd->wl.wtz_scr);
    if (ewd->wl.relative_pointer_manager)
      zwp_relative_pointer_manager_v1_destroy(ewd->wl.relative_pointer_manager);
+   if (ewd->wl.pointer_constraints)
+     zwp_pointer_constraints_v1_destroy(ewd->wl.pointer_constraints);
 //
 
    if (ewd->wl.registry) wl_registry_destroy(ewd->wl.registry);
index 40ed4b6..a413c5d 100644 (file)
@@ -1255,6 +1255,33 @@ static const struct zwp_relative_pointer_v1_listener _relative_pointer_listener
 };
 //
 
+// TIZEN_ONLY(20230801) : support zwp pointer constraints protocol
+static void
+_locked_pointer_cb_locked(void *data, struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1 EINA_UNUSED)
+{
+   Ecore_Wl2_Input *input = (Ecore_Wl2_Input *)data;
+
+   // For Debug
+   ERR("[locked pointer] locked");
+   input->pointer_locked = EINA_TRUE;
+}
+
+static void
+_locked_pointer_cb_unlocked(void *data, struct zwp_locked_pointer_v1 *zwp_locked_pointer_v1 EINA_UNUSED)
+{
+   Ecore_Wl2_Input *input = (Ecore_Wl2_Input *)data;
+
+   // For Debug
+   ERR("[locked pointer] unlocked");
+   input->pointer_locked = EINA_FALSE;
+}
+
+static const struct zwp_locked_pointer_v1_listener _locked_pointer_listener = {
+   _locked_pointer_cb_locked,
+   _locked_pointer_cb_unlocked,
+};
+//
+
 static void
 _keyboard_cb_keymap(void *data, struct wl_keyboard *keyboard EINA_UNUSED, unsigned int format, int fd, unsigned int size)
 {
@@ -2470,6 +2497,8 @@ _ecore_wl2_input_add(Ecore_Wl2_Display *display, unsigned int id, unsigned int v
    input->repeat.delay = input->repeat.horizontal.delay = input->repeat.vertical.delay = 0.4;
    input->repeat.enabled = EINA_TRUE;
    input->repeat.changed = EINA_FALSE;
+   input->want_lock_pointer = EINA_FALSE;
+   input->pointer_locked = EINA_FALSE;
 
    wl_array_init(&input->data.selection.types);
    wl_array_init(&input->data.drag.types);
@@ -4066,3 +4095,152 @@ ecore_wl2_input_default_input_get(const Ecore_Wl2_Display *ewd)
 
    return input;
 }
+
+// TIZEN_ONLY(20230801) : support zwp pointer constraints protocol
+EAPI Eina_Bool
+ecore_wl2_window_pointer_constraints_lock_pointer(Ecore_Wl2_Window *win)
+{
+   Ecore_Wl2_Display *ewd;
+   Ecore_Wl2_Input *input;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(win, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(win->surface, EINA_FALSE);
+
+   ewd = win->display;
+   input = ecore_wl2_input_default_input_get(ewd);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
+
+   if (!ewd->wl.pointer_constraints)
+     {
+        ERR("Failed to lock pointer. constraints is NULL");
+        return EINA_FALSE;
+     }
+   if (!input->wl.locked_pointer)
+     {
+        INF("Pointer Constraint: lock pointer. (region: %p)", input->lock_region);
+        input->wl.locked_pointer =
+          zwp_pointer_constraints_v1_lock_pointer(ewd->wl.pointer_constraints,
+                                                  win->surface,
+                                                  input->wl.pointer,
+                                                  input->lock_region,
+                                                  ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
+        zwp_locked_pointer_v1_add_listener(input->wl.locked_pointer,
+                                           &_locked_pointer_listener, input);
+     }
+
+   if (input->wl.locked_pointer)
+     {
+        if (ewd->wl.relative_pointer_manager &&
+            !input->wl.relative_pointer)
+          {
+             input->wl.relative_pointer = zwp_relative_pointer_manager_v1_get_relative_pointer(
+                                            input->display->wl.relative_pointer_manager,
+                                            input->wl.pointer);
+             zwp_relative_pointer_v1_add_listener(input->wl.relative_pointer, &_relative_pointer_listener, input);
+          }
+     }
+   input->want_lock_pointer = EINA_TRUE;
+
+   return EINA_TRUE;
+}
+
+EAPI Eina_Bool
+ecore_wl2_window_pointer_constraints_unlock_pointer(Ecore_Wl2_Window *win)
+{
+   Ecore_Wl2_Display *ewd;
+   Ecore_Wl2_Input *input;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(win, EINA_FALSE);
+
+   ewd = win->display;
+   input = ecore_wl2_input_default_input_get(ewd);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
+
+   if (input->wl.locked_pointer)
+     {
+        INF("Pointer Constraint: Destroy locked pointer");
+        zwp_locked_pointer_v1_destroy(input->wl.locked_pointer);
+        input->wl.locked_pointer = NULL;
+     }
+   input->want_lock_pointer = EINA_FALSE;
+
+   return EINA_TRUE;
+}
+
+EAPI void
+ecore_wl2_window_locked_pointer_region_set(Ecore_Wl2_Window *win, int x, int y, int w, int h)
+{
+   Ecore_Wl2_Display *ewd;
+   Ecore_Wl2_Input *input;
+
+   EINA_SAFETY_ON_NULL_RETURN(win);
+
+   ewd = win->display;
+   input = ecore_wl2_input_default_input_get(ewd);
+   EINA_SAFETY_ON_NULL_RETURN(input);
+
+   if (input->lock_region)
+     {
+        wl_region_destroy(input->lock_region);
+        input->lock_region = NULL;
+     }
+
+   if ((w > 0) && (h > 0))
+     {
+        struct wl_region *region;
+
+        region = wl_compositor_create_region(ewd->wl.compositor);
+        if (!region)
+          {
+             ERR("Failed to create region of locked_pointer");
+             return;
+          }
+
+        input->lock_region = region;
+        wl_region_add(input->lock_region, x, y, w, h);
+
+        if (!input->wl.locked_pointer)
+          {
+             INF("No locked_pointer available. region (%d, %d) (w:%d, h:%d)", x, y, w, h);
+             return;
+          }
+
+        INF("Set region for locked_pointer (%d, %d) (w:%d, h:%d)", x, y, w, h);
+        zwp_locked_pointer_v1_set_region(input->wl.locked_pointer, input->lock_region);
+     }
+   else
+     {
+        if (!input->wl.locked_pointer)
+          {
+             INF("No locked_pointer available. region (%d, %d) (w:%d, h:%d)", x, y, w, h);
+             return;
+          }
+        INF("Set region for locked_pointer. NULL region");
+        zwp_locked_pointer_v1_set_region(input->wl.locked_pointer, NULL);
+     }
+}
+
+EAPI void
+ecore_wl2_window_locked_pointer_cursor_position_hint_set(Ecore_Wl2_Window *win, int x, int y)
+{
+   Ecore_Wl2_Display *ewd;
+   Ecore_Wl2_Input *input;
+
+   EINA_SAFETY_ON_NULL_RETURN(win);
+
+   ewd = win->display;
+   input = ecore_wl2_input_default_input_get(ewd);
+   EINA_SAFETY_ON_NULL_RETURN(input);
+
+   if (!input->wl.locked_pointer)
+     {
+        INF("No locked pointer available. cursor position hint (%d, %d)", x, y);
+        return;
+     }
+
+   INF("Set cursor position hint (%d, %d) for locked_pointer", x, y);
+   zwp_locked_pointer_v1_set_cursor_position_hint(input->wl.locked_pointer,
+                                                  wl_fixed_from_int(x),
+                                                  wl_fixed_from_int(y));
+}
+//
index 210a435..c3e626d 100644 (file)
 #include <relative-pointer-unstable-v1-client-protocol.h>
 //
 
+// TIZEN_ONLY(20230801) : support zwp pointer constraints protocol
+#include <pointer-constraints-unstable-v1-client-protocol.h>
+//
+
 extern int _ecore_wl2_log_dom;
 extern Eina_Bool no_session_recovery;
 
@@ -169,7 +173,9 @@ struct _Ecore_Wl2_Display
         // TIZEN_ONLY(20230801) : support zwp relative pointer protocol
         struct zwp_relative_pointer_manager_v1 *relative_pointer_manager;
         //
-
+        // TIZEN_ONLY(20230801) : support zwp pointer constraints protocol
+        struct zwp_pointer_constraints_v1 *pointer_constraints;
+        //
      } wl;
 
    uint32_t serial;
@@ -681,6 +687,9 @@ struct _Ecore_Wl2_Input
         // TIZEN_ONLY(20230801) : support zwp relative pointer protocol
         struct zwp_relative_pointer_v1 *relative_pointer;
         //
+        // TIZEN_ONLY(20230801) : support pointer constraints protocol
+        struct zwp_locked_pointer_v1 *locked_pointer;
+        //
      } wl;
 
    struct
@@ -832,6 +841,12 @@ struct _Ecore_Wl2_Input
    Ecore_Wl2_Window *repeat_win;
    int key_mode;
 //
+
+// TIZEN_ONLY(20230801) : support pointer constraints protocol
+   Eina_Bool want_lock_pointer;
+   Eina_Bool pointer_locked;
+   struct wl_region *lock_region;
+//
 };
 
 typedef struct Ecore_Wl2_Event_Window_WWW
index 22246da..4d110fa 100644 (file)
@@ -37,6 +37,7 @@ ecore_wl2_ext_deps += [
   dependency('wtz-screen-client'),
   dependency('wtz-shell-client'),
   dependency('relative-pointer-unstable-v1-client'),
+  dependency('pointer-constraints-unstable-v1-client'),
 ]
 ecore_wl2_src += files([
   'ecore_wl2_tbmsurface.c',