e_devicemgr: Fix relative_motion_grab to destroy surface listener on ungrab 05/315905/2
authorduna.oh <duna.oh@samsung.com>
Tue, 6 Aug 2024 04:21:30 +0000 (13:21 +0900)
committerDuna Oh <duna.oh@samsung.com>
Fri, 9 Aug 2024 07:34:57 +0000 (07:34 +0000)
Change-Id: Iee13a7fbb8c8780d586950ab6303195d0e754aaa

src/bin/inputmgr/e_devicemgr_relative_motion_grab.c

index 1a63195b8cd86ae4150759e483f2dbce45879da5..b448a0b50e150a3f9115f9c21aae07f370facdbc 100644 (file)
@@ -8,8 +8,8 @@ e_devicemgr_relative_motion_is_grabbed(unsigned int boundaries)
 {
    if (e_devicemgr->relative_motion_grab.grabbed_boundaries & boundaries)
      {
-        DMINF("e_devicemgr_relative_motion_is_grabbed() grabbed:%d, boundaries:%d",
-              e_devicemgr->relative_motion_grab.grabbed_boundaries, boundaries);
+        DMINF("Relative Motion Grab. boundaries(%d) is grabbed. among others(%d)",
+              boundaries, e_devicemgr->relative_motion_grab.grabbed_boundaries);
         return EINA_TRUE;
      }
 
@@ -34,20 +34,17 @@ _e_devicemgr_relative_motion_grabbed_boundary_get(struct wl_client *client, E_Cl
    return boundary;
 }
 
-static Eina_Bool
+static void
 _e_devicemgr_relative_motion_grab_surface_remove(E_Client *ec,
                                                 unsigned int boundary)
 {
-   if (ec != e_devicemgr->relative_motion_grab.boundaries[boundary].ec)
-     return EINA_FALSE;
-
    e_devicemgr->relative_motion_grab.boundaries[boundary].client = NULL;
    e_devicemgr->relative_motion_grab.boundaries[boundary].ec = NULL;
    e_devicemgr->relative_motion_grab.boundaries[boundary].resource = NULL;
    e_devicemgr->relative_motion_grab.grabbed_boundaries &= ~(1 << boundary);
    e_devicemgr->relative_motion_grab.last_event_boundary = 0;
 
-   return EINA_TRUE;
+   return;
 }
 
 static void
@@ -72,20 +69,17 @@ _e_devicemgr_relative_motion_grab_surface_cb_destroy(struct wl_listener *l, void
      }
 }
 
-static Eina_Bool
+static void
 _e_devicemgr_relative_motion_grab_surface_add(E_Client *ec, uint32_t boundary,
                                               struct wl_client *client,
                                               struct wl_resource *resource)
 {
-   if (ec == e_devicemgr->relative_motion_grab.boundaries[boundary].ec)
-     return EINA_TRUE;
-
    e_devicemgr->relative_motion_grab.boundaries[boundary].client = client;
    e_devicemgr->relative_motion_grab.boundaries[boundary].ec = ec;
    e_devicemgr->relative_motion_grab.boundaries[boundary].resource = resource;
    e_devicemgr->relative_motion_grab.grabbed_boundaries |= (1 << boundary);
 
-   return EINA_TRUE;
+   return;
 }
 
 int
@@ -99,15 +93,21 @@ e_devicemgr_relative_motion_grab(struct wl_client *client, struct wl_resource *r
    if (boundary <= 0 || boundary > E_DEVICEMGR_BOUNDARY_MAX)
      return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
 
-   if (e_devicemgr->relative_motion_grab.boundaries[boundary].client &&
-       e_devicemgr->relative_motion_grab.boundaries[boundary].client != client)
+   ec = e_client_from_surface_resource(surface);
+   if (!ec)
+     return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
+
+   if ((e_devicemgr->relative_motion_grab.boundaries[boundary].client &&
+       e_devicemgr->relative_motion_grab.boundaries[boundary].client != client) ||
+       (e_devicemgr->relative_motion_grab.boundaries[boundary].ec &&
+       e_devicemgr->relative_motion_grab.boundaries[boundary].ec != ec))
      {
         return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
      }
 
-   ec = e_client_from_surface_resource(surface);
-   if (!ec)
-     return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_SURFACE;
+   // check if ec already grabs other boundary
+   if (_e_devicemgr_relative_motion_grabbed_boundary_get(client, ec) != 0)
+     return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
 
    destroy_listener = E_NEW(struct wl_listener, 1);
    if (!destroy_listener)
@@ -118,8 +118,7 @@ e_devicemgr_relative_motion_grab(struct wl_client *client, struct wl_resource *r
    destroy_listener->notify = _e_devicemgr_relative_motion_grab_surface_cb_destroy;
    wl_resource_add_destroy_listener(surface, destroy_listener);
 
-   if (!_e_devicemgr_relative_motion_grab_surface_add(ec, boundary, client, resource))
-     ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
+   _e_devicemgr_relative_motion_grab_surface_add(ec, boundary, client, resource);
 
    return ret;
 }
@@ -131,6 +130,7 @@ e_devicemgr_relative_motion_ungrab(struct wl_client *client, struct wl_resource
    int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
    E_Client *ec;
    unsigned int boundary;
+   struct wl_listener *destroy_listener = NULL;
 
    ec = e_client_from_surface_resource(surface);
    if (!ec)
@@ -138,10 +138,16 @@ e_devicemgr_relative_motion_ungrab(struct wl_client *client, struct wl_resource
 
    boundary = _e_devicemgr_relative_motion_grabbed_boundary_get(client, ec);
    if (boundary == 0)
-       return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
+     return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
+
+   destroy_listener = wl_resource_get_destroy_listener(surface, _e_devicemgr_relative_motion_grab_surface_cb_destroy);
+   if (destroy_listener)
+     {
+        wl_list_remove(&destroy_listener->link);
+        E_FREE(destroy_listener);
+     }
 
-   if (!_e_devicemgr_relative_motion_grab_surface_remove(ec, boundary))
-     ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED;
+   _e_devicemgr_relative_motion_grab_surface_remove(ec, boundary);
 
    return ret;
 }