ecore_wl2: fix for each window to be able to lock its pointer 71/299971/2 accepted/tizen/unified/20231014.105741
authorduna.oh <duna.oh@samsung.com>
Fri, 13 Oct 2023 03:57:24 +0000 (12:57 +0900)
committerduna.oh <duna.oh@samsung.com>
Fri, 13 Oct 2023 04:24:19 +0000 (13:24 +0900)
Change-Id: I51b75163249be9ccec966f4dd6161377583f825b

src/lib/ecore_wl2/ecore_wl2_input.c
src/lib/ecore_wl2/ecore_wl2_private.h

index 906dd27..07d4a01 100644 (file)
@@ -1301,12 +1301,12 @@ _locked_pointer_cb_locked(void *data, struct zwp_locked_pointer_v1 *zwp_locked_p
    // For Debug
    ERR("[locked pointer] locked");
 
-   input = data;
-   if (!input) return;
-   input->pointer_locked = EINA_TRUE;
-
-   window = input->focus.pointer;
+   window = data;
    if (!window) return;
+   window->ptr_constraints.pointer_locked = EINA_TRUE;
+
+   input = ecore_wl2_input_default_input_get(window->display);
+   if (!input) return;
 
    ev = calloc(1, sizeof(Ecore_Wl2_Event_Pointer_Constraints));
    if (!ev) return;
@@ -1331,17 +1331,12 @@ _locked_pointer_cb_unlocked(void *data, struct zwp_locked_pointer_v1 *zwp_locked
    // For Debug
    ERR("[locked pointer] unlocked");
 
-   input = data;
-   if (!input) return;
-   input->pointer_locked = EINA_FALSE;
+   window = data;
+   if (!window) return;
+   window->ptr_constraints.pointer_locked = EINA_FALSE;
 
-   window = input->focus.pointer;
-   if (!window)
-     {
-        window = input->focus.prev_pointer;
-        if (!window)
-          return;
-     }
+   input = ecore_wl2_input_default_input_get(window->display);
+   if (!input) return;
 
    ev = calloc(1, sizeof(Ecore_Wl2_Event_Pointer_Constraints));
    if (!ev) return;
@@ -2577,8 +2572,6 @@ _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);
@@ -4195,17 +4188,17 @@ ecore_wl2_window_pointer_constraints_lock_pointer(Ecore_Wl2_Window *win)
         ERR("Failed to lock pointer. constraints is NULL");
         return EINA_FALSE;
      }
-   if (!input->wl.locked_pointer)
+   if (!win->ptr_constraints.locked_pointer)
      {
-        INF("Pointer Constraint: lock pointer. (region: %p)", input->lock_region);
-        input->wl.locked_pointer =
+        INF("Pointer Constraint: lock pointer. (region: %p)", win->ptr_constraints.lock_region);
+        win->ptr_constraints.locked_pointer =
           zwp_pointer_constraints_v1_lock_pointer(ewd->wl.pointer_constraints,
                                                   win->surface,
                                                   input->wl.pointer,
-                                                  input->lock_region,
+                                                  win->ptr_constraints.lock_region,
                                                   ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
-        zwp_locked_pointer_v1_add_listener(input->wl.locked_pointer,
-                                           &_locked_pointer_listener, input);
+        zwp_locked_pointer_v1_add_listener(win->ptr_constraints.locked_pointer,
+                                           &_locked_pointer_listener, win);
      }
 
    if (ewd->wl.relative_pointer_manager &&
@@ -4216,7 +4209,7 @@ ecore_wl2_window_pointer_constraints_lock_pointer(Ecore_Wl2_Window *win)
                                        input->wl.pointer);
         zwp_relative_pointer_v1_add_listener(input->wl.relative_pointer, &_relative_pointer_listener, input);
      }
-   input->want_lock_pointer = EINA_TRUE;
+   win->ptr_constraints.want_lock_pointer = EINA_TRUE;
 
    return EINA_TRUE;
 }
@@ -4224,22 +4217,15 @@ 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)
 {
-   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)
+   if (win->ptr_constraints.locked_pointer)
      {
         INF("Pointer Constraint: Destroy locked pointer");
-        zwp_locked_pointer_v1_destroy(input->wl.locked_pointer);
-        input->wl.locked_pointer = NULL;
+        zwp_locked_pointer_v1_destroy(win->ptr_constraints.locked_pointer);
+        win->ptr_constraints.locked_pointer = NULL;
      }
-   input->want_lock_pointer = EINA_FALSE;
+   win->ptr_constraints.want_lock_pointer = EINA_FALSE;
 
    return EINA_TRUE;
 }
@@ -4248,23 +4234,19 @@ 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)
+   if (win->ptr_constraints.lock_region)
      {
-        wl_region_destroy(input->lock_region);
-        input->lock_region = NULL;
+        wl_region_destroy(win->ptr_constraints.lock_region);
+        win->ptr_constraints.lock_region = NULL;
      }
 
    if ((w > 0) && (h > 0))
      {
         struct wl_region *region;
+        ewd = win->display;
 
         region = wl_compositor_create_region(ewd->wl.compositor);
         if (!region)
@@ -4273,50 +4255,43 @@ ecore_wl2_window_locked_pointer_region_set(Ecore_Wl2_Window *win, int x, int y,
              return;
           }
 
-        input->lock_region = region;
-        wl_region_add(input->lock_region, x, y, w, h);
+        win->ptr_constraints.lock_region = region;
+        wl_region_add(win->ptr_constraints.lock_region, x, y, w, h);
 
-        if (!input->wl.locked_pointer)
+        if (!win->ptr_constraints.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);
+        zwp_locked_pointer_v1_set_region(win->ptr_constraints.locked_pointer, win->ptr_constraints.lock_region);
      }
    else
      {
-        if (!input->wl.locked_pointer)
+        if (!win->ptr_constraints.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);
+        zwp_locked_pointer_v1_set_region(win->ptr_constraints.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)
+   if (!win->ptr_constraints.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,
+   zwp_locked_pointer_v1_set_cursor_position_hint(win->ptr_constraints.locked_pointer,
                                                   wl_fixed_from_int(x),
                                                   wl_fixed_from_int(y));
 }
index c3e626d..cdb8e87 100644 (file)
@@ -496,6 +496,16 @@ struct _Ecore_Wl2_Window
    // TIZEN_ONLY(20230306): support pin mode
    Eina_Bool pinned : 1;
    //
+
+   // TIZEN_ONLY(20230801) : support pointer constraints protocol
+   struct
+     {
+        struct zwp_locked_pointer_v1 *locked_pointer;
+        Eina_Bool want_lock_pointer;
+        Eina_Bool pointer_locked;
+        struct wl_region *lock_region;
+   } ptr_constraints;
+   //
 };
 
 struct _Ecore_Wl2_Output
@@ -687,9 +697,6 @@ 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
@@ -841,12 +848,6 @@ 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