e_comp_wl_input: use cursor_position_hint to warp the pointer upon unlock 22/296822/2
authorduna.oh <duna.oh@samsung.com>
Wed, 2 Aug 2023 07:04:40 +0000 (16:04 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Fri, 4 Aug 2023 09:42:51 +0000 (09:42 +0000)
There was a bug when locked_pointer destroys, pointer is warped by
cursor_position_hint and warped again by mouse_move_preventer.

Since cursor_position_hint and region is in surface-coordinate,
checking of inside region should be in the same coordinate.

Change-Id: I247840e9b48cad96e251a778e861e593b79c60a1

src/bin/e_comp_wl.c
src/bin/e_comp_wl_input.c

index 11b77ae..2261725 100644 (file)
@@ -3725,37 +3725,6 @@ _e_comp_wl_gl_shutdown(void)
    E_FREE(e_comp_wl->evas_gl);
 }
 
-static Eina_Bool
-_e_comp_wl_cb_mouse_move_preventer(void *d EINA_UNUSED, int t EINA_UNUSED, Ecore_Event_Mouse_Move *ev)
-{
-   static int saved_x = -1;
-   static int saved_y = -1;
-
-   E_Client *focus = e_client_focused_get();
-
-   if ((!e_comp_wl->ptr_constraints.activated) ||
-       (!focus) ||
-       (e_comp_wl->ptr_constraints.ec != focus))
-     {
-        if (saved_x != -1 || saved_y != -1)
-          {
-             e_input_device_pointer_warp(NULL, saved_x, saved_y);
-             saved_x = -1;
-             saved_y = -1;
-          }
-
-        return ECORE_CALLBACK_RENEW;
-     }
-
-   if (saved_x == -1 || saved_y == -1)
-     {
-        saved_x = ev->x;
-        saved_y = ev->y;
-     }
-
-   return ECORE_CALLBACK_DONE;
-}
-
 /* public functions */
 
 /**
@@ -3803,10 +3772,6 @@ e_comp_wl_init(void)
    if (!e_foreign_global_init(e_comp_wl->wl.disp))
      ELOGF("COMP", "Failed to initialize the e_foreign global", NULL);
 
-   /* prepend a mouse move event handler to prevent the mouse move event from being delivered to
-      the other mouse move event handlers when a pointer constraint is activated */
-   E_LIST_HANDLER_PREPEND(handlers, ECORE_EVENT_MOUSE_MOVE, _e_comp_wl_cb_mouse_move_preventer, NULL);
-
    /* add event handlers to catch E events */
    E_LIST_HANDLER_APPEND(handlers, E_EVENT_SCREEN_CHANGE,            _e_comp_wl_cb_randr_change,        NULL);
    E_LIST_HANDLER_APPEND(handlers, E_EVENT_COMP_OBJECT_ADD,         _e_comp_wl_cb_comp_object_add,     NULL);
index 631447a..e725350 100644 (file)
@@ -60,6 +60,11 @@ static char *_env_e_default_xkb_layout  = NULL;
 static char *_env_e_default_xkb_variant = NULL;
 static char *_env_e_default_xkb_opts    = NULL;
 
+static Eina_Bool
+_e_comp_wl_input_is_position_inside_constraint_region(E_Comp_Wl_Pointer_Constraint *constraint,
+                                                      wl_fixed_t fx,
+                                                      wl_fixed_t fy);
+
 static void
 _e_comp_wl_input_update_seat_caps(struct wl_client *wc)
 {
@@ -624,6 +629,19 @@ _e_comp_wl_input_pointer_constraint_notify_deactivated(E_Comp_Wl_Pointer_Constra
      zwp_confined_pointer_v1_send_unconfined(resource);
    else
      ERR("unknown pointer constraint type (%d) !", type);
+
+   if (constraint->ec &&
+       constraint->has_hint_set &&
+       _e_comp_wl_input_is_position_inside_constraint_region(constraint,
+                                                     constraint->hint_x,
+                                                     constraint->hint_y))
+     {
+        E_Client *ec = constraint->ec;
+        int cx = ec->client.x + wl_fixed_to_int(constraint->hint_x);
+        int cy = ec->client.y + wl_fixed_to_int(constraint->hint_y);
+        INF("Pointer Constraint deactivated. Pointer Warp to (%d, %d)", cx, cy);
+        e_input_device_pointer_warp(NULL, cx, cy);
+     }
 }
 
 static void
@@ -735,14 +753,16 @@ _e_comp_wl_input_pointer_constraints_check_enable(E_Comp_Wl_Pointer_Constraint *
      }
 
    E_Client *ec = constraint->ec;
+   wl_fixed_t cx = e_comp_wl->ptr.x - wl_fixed_from_int(ec->client.x);
+   wl_fixed_t cy = e_comp_wl->ptr.y - wl_fixed_from_int(ec->client.y);
 
    if ((!e_comp_wl->ptr.ec) || (e_comp_wl->ptr.ec != ec)
         || (!ec->pointer_enter_sent))
      return;
 
    if (!_e_comp_wl_input_is_position_inside_constraint_region(constraint,
-                                                              e_comp_wl->ptr.x,
-                                                              e_comp_wl->ptr.y))
+                                                              cx,
+                                                              cy))
      return;
 
    _e_comp_wl_input_pointer_constraint_enable(constraint);
@@ -901,6 +921,14 @@ _e_comp_wl_input_pointer_constraint_create(E_Client *ec,
         constraint->has_region_set = EINA_TRUE;
      }
 
+   constraint->hint_x = e_comp_wl->ptr.x - wl_fixed_from_int(ec->client.x);
+   constraint->hint_y = e_comp_wl->ptr.y - wl_fixed_from_int(ec->client.y);
+   constraint->is_hint_pending = EINA_FALSE;
+   constraint->has_hint_set = EINA_TRUE;
+   ERR("Pointer Constraint created. cursor position hint (%d, %d)",
+       wl_fixed_to_int(constraint->hint_x),
+       wl_fixed_to_int(constraint->hint_y));
+
    constraint->pointer_destroy_listener.notify =
      _e_comp_wl_input_cb_pointer_constraints_pointer_destroyed;
    constraint->surface_commit_listener.notify =
@@ -951,22 +979,6 @@ static void
 _e_comp_wl_input_cb_locked_pointer_destroy(struct wl_client *client,
                                            struct wl_resource *resource)
 {
-   E_Comp_Wl_Pointer_Constraint *constraint;
-   constraint = wl_resource_get_user_data(resource);
-
-   if (constraint &&
-       constraint->ec &&
-       constraint->has_hint_set &&
-       _e_comp_wl_input_is_position_inside_constraint_region(constraint,
-                                                     constraint->hint_x,
-                                                     constraint->hint_y))
-     {
-        E_Client *ec = constraint->ec;
-        int cx = ec->client.x + wl_fixed_to_int(constraint->hint_x);
-        int cy = ec->client.y + wl_fixed_to_int(constraint->hint_y);
-        e_input_device_pointer_warp(NULL, cx, cy);
-     }
-
    wl_resource_destroy(resource);
 }