ecore_wl2: add relative_motion_grab/ungrab API 60/314760/7 tizen
authorduna.oh <duna.oh@samsung.com>
Thu, 18 Jul 2024 11:17:55 +0000 (20:17 +0900)
committerDuna Oh <duna.oh@samsung.com>
Tue, 6 Aug 2024 05:43:46 +0000 (05:43 +0000)
@tizen_only

Change-Id: I6ca7db18052da43b5bafccb6a8a7fbb053ebfc87

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

index da8262c..f3b89a1 100644 (file)
@@ -548,6 +548,16 @@ typedef enum _Ecore_Wl2_Maximize_Direction
 } Ecore_Wl2_Maximize_Direction;
 //
 
+// TIZEN_ONLY(20240718) : add relative_motion grab/ungrab API
+typedef enum _Ecore_Wl2_Pointer_Boundary
+{
+   ECORE_WL2_POINTER_BOUNDARY_NONE = 0,
+   ECORE_WL2_POINTER_BOUNDARY_TOP,
+   ECORE_WL2_POINTER_BOUNDARY_RIGHT,
+   ECORE_WL2_POINTER_BOUNDARY_BOTTOM,
+   ECORE_WL2_POINTER_BOUNDARY_LEFT,
+} Ecore_Wl2_Pointer_Boundary;
+
 /** @internal */
 typedef struct _Ecore_Wl2_Event_Aux_Hint_Allowed
 {
@@ -2665,6 +2675,11 @@ EAPI void ecore_wl2_window_modal_set(Ecore_Wl2_Window *window, Eina_Bool modal);
 EAPI Eina_Bool ecore_wl2_window_modal_get(Ecore_Wl2_Window *window);
 //
 
+// TIZEN_ONLY(20240718) : add relative_motion grab/ungrab API
+EAPI Eina_Bool ecore_wl2_window_relative_motion_grab(Ecore_Wl2_Window *win, Ecore_Wl2_Pointer_Boundary boundary);
+EAPI Eina_Bool ecore_wl2_window_relative_motion_ungrab(Ecore_Wl2_Window *win);
+//
+
 # undef EAPI
 # define EAPI
 
index 6766d35..786605c 100644 (file)
@@ -1273,7 +1273,7 @@ _ecore_wl2_input_mouse_relative_move_send(Ecore_Wl2_Input *input, Ecore_Wl2_Wind
 
    ev->dev = _ecore_wl2_mouse_dev_get(input, window->id);
 
-   ERR("[Relative Move] timestamp=%u dx=%d, dy=%d, dx_unaccel=%d, dy_unaccel=%d", ev->timestamp, ev->dx, ev->dy, ev->dx_unaccel, ev->dy_unaccel);
+   ERR("[Relative Move] window = %p time=%u dx=%d, dy=%d, unaccel=(%d, %d)", window, ev->timestamp, ev->dx, ev->dy, ev->dx_unaccel, ev->dy_unaccel);
    ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, NULL, NULL);
 }
 //
@@ -1284,7 +1284,7 @@ _relative_pointer_cb_relative_motion(void *data, struct zwp_relative_pointer_v1*
                                      uint32_t ts_high, uint32_t ts_low, wl_fixed_t dx, wl_fixed_t dy, wl_fixed_t dx_unaccel, wl_fixed_t dy_unaccel)
 {
    Ecore_Wl2_Input *input;
-   Ecore_Wl2_Window *window;
+   Ecore_Wl2_Window *window = NULL;
     (void) relative_pointer;
 
    input = data;
@@ -1296,9 +1296,21 @@ _relative_pointer_cb_relative_motion(void *data, struct zwp_relative_pointer_v1*
 
    input->timestamp = (unsigned int)ts_low;
 
-   /* get currently focused window */
-   window = input->focus.pointer;
+// TIZEN_ONLY(20240718) : add relative_motion grab/ungrab API
+   if (input->focus.pointer && input->focus.pointer->ptr_constraints.want_lock_pointer)
+     {
+        /* get currently focused window */
+        window = input->focus.pointer;
+     }
+   else if (input->devmgr.last_event_boundary > 0 &&
+            input->devmgr.last_event_boundary <= ECORE_WL2_POINTER_BOUNDARY_MAX &&
+            input->devmgr.grabbed_pointer[input->devmgr.last_event_boundary] != NULL)
+     {
+        window = input->devmgr.grabbed_pointer[input->devmgr.last_event_boundary];
+     }
+
    if (!window) return;
+//
 
    _ecore_wl2_input_mouse_relative_move_send(input, window, wl_fixed_to_int(dx), wl_fixed_to_int(dy),
                                              wl_fixed_to_int(dx_unaccel), wl_fixed_to_int(dy_unaccel));
@@ -3999,6 +4011,20 @@ _ecore_wl2_input_device_manager_cb_max_touch_count(void *data, struct tizen_inpu
      }
 }
 
+static void
+_ecore_wl2_input_device_manager_cb_event_boundary(void *data, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, int32_t boundary)
+{
+   Ecore_Wl2_Display *ewd = (Ecore_Wl2_Display *)data;
+   Ecore_Wl2_Input *input;
+
+   if (!ewd) return;
+   input = ecore_wl2_input_default_input_get(ewd);
+   if (!input) return;
+
+   ERR("[tz device manager] event_boundary. (%d --> %d)", input->devmgr.last_event_boundary, boundary);
+   input->devmgr.last_event_boundary = boundary;
+}
+
 static const struct tizen_input_device_manager_listener _tz_input_device_mgr_listener =
 {
    _ecore_wl2_input_device_manager_cb_device_add,
@@ -4006,13 +4032,14 @@ static const struct tizen_input_device_manager_listener _tz_input_device_mgr_lis
    _ecore_wl2_input_device_manager_cb_error,
    _ecore_wl2_input_device_manager_cb_block_expired,
    _ecore_wl2_input_device_manager_cb_max_touch_count,
+   _ecore_wl2_input_device_manager_cb_event_boundary,
 };
 
 void
 _ecore_wl2_input_device_manager_setup(Ecore_Wl2_Display *ewd, unsigned int id, unsigned int version EINA_UNUSED)
 {
    ewd->wl.tz_input_device_manager =
-   wl_registry_bind(ewd->wl.registry, id, &tizen_input_device_manager_interface, 6);
+   wl_registry_bind(ewd->wl.registry, id, &tizen_input_device_manager_interface, 7);
 
    tizen_input_device_manager_add_listener(ewd->wl.tz_input_device_manager,
                                        &_tz_input_device_mgr_listener, ewd);
@@ -4540,3 +4567,89 @@ ecore_wl2_window_keyboard_ungrab(Ecore_Wl2_Window *win)
    return EINA_TRUE;
 }
 //
+
+// TIZEN_ONLY(20240718) : add relative_motion grab/ungrab API
+EAPI Eina_Bool
+ecore_wl2_window_relative_motion_grab(Ecore_Wl2_Window *win, Ecore_Wl2_Pointer_Boundary boundary)
+{
+   Ecore_Wl2_Display *ewd;
+   Ecore_Wl2_Input *input;
+
+   if (!win || !win->surface) return EINA_FALSE;
+   ewd = win->display;
+   if (!ewd || !ewd->wl.tz_input_device_manager) return EINA_FALSE;
+
+   uint32_t ver = wl_proxy_get_version((struct wl_proxy *)ewd->wl.tz_input_device_manager);
+#ifdef TIZEN_INPUT_DEVICE_MANAGER_GRAB_RELATIVE_MOTION_SINCE_VERSION
+   _devicemgr_error = -1;
+   tizen_input_device_manager_grab_relative_motion(ewd->wl.tz_input_device_manager,
+                                            win->surface, boundary);
+   ecore_wl2_display_sync(ewd);
+
+   if (_devicemgr_error != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
+     {
+        ERR("Relative motion grab failed.");
+        return EINA_FALSE;
+     }
+
+   input = ecore_wl2_input_default_input_get(ewd);
+   if (input)
+     {
+        if (boundary > 0 && boundary <= ECORE_WL2_POINTER_BOUNDARY_MAX)
+          input->devmgr.grabbed_pointer[boundary] = win;
+     }
+
+   // For Debug
+   ERR("Relative motion grab succeeded.");
+   return EINA_TRUE;
+#else
+   // For Debug
+   ERR("Relative motion grab is not supported on this version(%d).", ver);
+   return EINA_FALSE;
+#endif
+}
+
+EAPI Eina_Bool
+ecore_wl2_window_relative_motion_ungrab(Ecore_Wl2_Window *win)
+{
+   Ecore_Wl2_Display *ewd;
+   Ecore_Wl2_Input *input;
+   unsigned int boundary = 0;
+
+   if (!win || !win->surface) return EINA_FALSE;
+   ewd = win->display;
+   if (!ewd || !ewd->wl.tz_input_device_manager) return EINA_FALSE;
+
+   uint32_t ver = wl_proxy_get_version((struct wl_proxy *)ewd->wl.tz_input_device_manager);
+#ifdef TIZEN_INPUT_DEVICE_MANAGER_UNGRAB_RELATIVE_MOTION_SINCE_VERSION
+   _devicemgr_error = -1;
+   tizen_input_device_manager_ungrab_relative_motion(ewd->wl.tz_input_device_manager,
+                                              win->surface);
+   ecore_wl2_display_sync(ewd);
+
+   if (_devicemgr_error != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
+     {
+        ERR("Relative motion ungrab failed.");
+        return EINA_FALSE;
+     }
+
+   input = ecore_wl2_input_default_input_get(ewd);
+   if (input)
+     {
+        for (int i = 1; i < ECORE_WL2_POINTER_BOUNDARY_MAX + 1; i++)
+          {
+             if (input->devmgr.grabbed_pointer[i] == win)
+               input->devmgr.grabbed_pointer[i] = NULL;
+          }
+     }
+
+   // For Debug
+   ERR("Relative motion ungrab succeeded.");
+   return EINA_TRUE;
+#else
+   // For Debug
+   ERR("Relative motion ungrab is not supported on this version(%d).", ver);
+   return EINA_FALSE;
+#endif
+}
+//
index a09814e..7127a4e 100644 (file)
@@ -749,6 +749,8 @@ struct _Ecore_Wl2_Seat
    Eina_List *resources;
 };
 
+#define ECORE_WL2_POINTER_BOUNDARY_MAX 4
+
 struct _Ecore_Wl2_Input
 {
    EINA_INLIST;
@@ -902,6 +904,10 @@ struct _Ecore_Wl2_Input
         Ecore_Wl2_Tizen_Input_Device *last_device_ptr;
         Ecore_Wl2_Tizen_Input_Device *last_device_touch;
         Ecore_Wl2_Tizen_Input_Device *last_device_kbd;
+        //
+        Ecore_Wl2_Window *grabbed_pointer[ECORE_WL2_POINTER_BOUNDARY_MAX + 1]; // window to be get relative motion event
+        //
+        Ecore_Wl2_Pointer_Boundary last_event_boundary;
      } devmgr;
    struct
      {