TIVI-2250: Fix crasher bug when using a system witout a mouse
[platform/upstream/ecore.git] / src / lib / ecore_wayland / ecore_wl_input.c
index 07b9a26..4d0d688 100644 (file)
@@ -150,6 +150,27 @@ ecore_wl_input_ungrab(Ecore_Wl_Input *input)
    input->grab_button = 0;
 }
 
+/* NB: This function should be called just before shell move and shell resize
+ * functions. Those requests will trigger a mouse/touch implicit grab on the
+ * compositor that will prevent the respective mouse/touch up events being
+ * released after the end of the operation. This function checks if such grab
+ * is in place for those windows and, if so, emit the respective mouse up
+ * event. It's a workaround to the fact that wayland doesn't inform the
+ * application about this move or resize grab being finished.
+ */
+void
+_ecore_wl_input_grab_release(Ecore_Wl_Input *input, Ecore_Wl_Window *win)
+{
+   LOGFN(__FILE__, __LINE__, __FUNCTION__);
+
+   if (!input) return;
+   if (input->grab != win) return;
+
+   _ecore_wl_input_mouse_up_send(input, input->grab,
+                                 input->grab_button, input->grab_timestamp);
+   ecore_wl_input_ungrab(input);
+}
+
 EAPI void
 ecore_wl_input_pointer_set(Ecore_Wl_Input *input, struct wl_surface *surface, int hot_x, int hot_y)
 {
@@ -404,7 +425,10 @@ _ecore_wl_input_cb_pointer_button(void *data, struct wl_pointer *pointer __UNUSE
    if (state)
      {
         if ((input->pointer_focus) && (!input->grab) && (state))
-          ecore_wl_input_grab(input, input->pointer_focus, button);
+          {
+             ecore_wl_input_grab(input, input->pointer_focus, button);
+             input->grab_timestamp = timestamp;
+          }
 
         _ecore_wl_input_mouse_down_send(input, input->pointer_focus, 
                                         button, timestamp);
@@ -695,7 +719,8 @@ _ecore_wl_input_cb_pointer_enter(void *data, struct wl_pointer *pointer __UNUSED
    input->pointer_enter_serial = serial;
 
    /* The cursor on the surface is undefined until we set it */
-   ecore_wl_input_cursor_from_name_set(input, "left_ptr");
+   if (input->pointer)
+     ecore_wl_input_cursor_from_name_set(input, "left_ptr");
 
    if ((win = wl_surface_get_user_data(surface)))
      {
@@ -704,37 +729,6 @@ _ecore_wl_input_cb_pointer_enter(void *data, struct wl_pointer *pointer __UNUSED
 
         _ecore_wl_input_mouse_in_send(input, win, input->timestamp);
      }
-
-   /* NB: This whole 'if' below is a major HACK due to wayland's stupidness 
-    * of not sending a mouse_up (or any notification at all for that matter) 
-    * when a move or resize grab is finished */
-   if (input->grab)
-     {
-        /* NB: This COULD mean a move has finished, or it could mean that 
-         * a 'drag' is being done to a different surface */
-
-        if ((input->grab == win) && (win->moving))
-          {
-             /* NB: 'Fake' a mouse_up for move finished */
-             win->moving = EINA_FALSE;
-             _ecore_wl_input_mouse_up_send(input, win, BTN_LEFT,
-                                           input->timestamp);
-
-             if ((input->grab) && (input->grab_button == BTN_LEFT))
-               ecore_wl_input_ungrab(input);
-          }
-        else if ((input->grab == win) && (win->resizing))
-          {
-             /* NB: 'Fake' a mouse_up for resize finished */
-             win->resizing = EINA_FALSE;
-             _ecore_wl_input_mouse_up_send(input, win, BTN_LEFT,
-                                           input->timestamp);
-
-             if ((input->grab) && (input->grab_button == BTN_LEFT))
-               ecore_wl_input_ungrab(input);
-          }
-        /* FIXME: Test d-n-d and potentially add needed case here */
-     }
 }
 
 static void 
@@ -855,6 +849,12 @@ _ecore_wl_input_cb_touch_down(void *data, struct wl_touch *touch __UNUSED__, uns
    input->sx = wl_fixed_to_int(x);
    input->sy = wl_fixed_to_int(y);
    _ecore_wl_input_cb_pointer_enter(data, NULL, serial, surface, x, y);
+   if ((input->pointer_focus) && (!input->grab))
+     {
+        ecore_wl_input_grab(input, input->pointer_focus, BTN_LEFT);
+        input->grab_timestamp = timestamp;
+     }
+
    _ecore_wl_input_mouse_down_send(input, input->pointer_focus, BTN_LEFT, timestamp);
 }
 
@@ -872,6 +872,8 @@ _ecore_wl_input_cb_touch_up(void *data, struct wl_touch *touch __UNUSED__, unsig
    /* input->timestamp = timestamp; */
    input->display->serial = serial;
    _ecore_wl_input_mouse_up_send(input, input->pointer_focus, BTN_LEFT, timestamp);
+   if ((input->grab) && (input->grab_button == BTN_LEFT))
+     ecore_wl_input_ungrab(input);
 }
 
 static void