window: use input event helper functions in grab operations.

This commit is contained in:
Carlos Garnacho 2011-06-09 17:46:17 +02:00
parent 3a8837f8ab
commit 66e9720cb7

View File

@ -43,12 +43,17 @@
#include <meta/group.h> #include <meta/group.h>
#include "window-props.h" #include "window-props.h"
#include "constraints.h" #include "constraints.h"
#include "input-events.h"
#include "mutter-enum-types.h" #include "mutter-enum-types.h"
#include <X11/Xatom.h> #include <X11/Xatom.h>
#include <X11/Xlibint.h> /* For display->resource_mask */ #include <X11/Xlibint.h> /* For display->resource_mask */
#include <string.h> #include <string.h>
#ifdef HAVE_XINPUT2
#include <X11/extensions/XInput2.h>
#endif
#ifdef HAVE_SHAPE #ifdef HAVE_SHAPE
#include <X11/extensions/shape.h> #include <X11/extensions/shape.h>
#endif #endif
@ -8963,7 +8968,10 @@ update_resize (MetaWindow *window,
typedef struct typedef struct
{ {
const XEvent *current_event; guint current_event_type;
Window current_event_window;
MetaDisplay *display;
MetaDevice *device;
int count; int count;
guint32 last_time; guint32 last_time;
} EventScannerData; } EventScannerData;
@ -8974,13 +8982,33 @@ find_last_time_predicate (Display *display,
XPointer arg) XPointer arg)
{ {
EventScannerData *esd = (void*) arg; EventScannerData *esd = (void*) arg;
Window xwindow;
#ifdef HAVE_XINPUT2
/* We are peeking into events not yet handled by GDK,
* Allocate cookie events here so we can handle XI2.
*
* GDK will handle later these events, and eventually
* free the cookie data itself.
*/
XGetEventData (display, &xevent->xcookie);
#endif
if (!meta_input_event_is_type (esd->display, xevent,
esd->current_event_type))
return False;
xwindow = meta_input_event_get_window (esd->display, xevent);
if (xwindow == None ||
xwindow != esd->current_event_window)
return False;
if (esd->device != meta_input_event_get_device (esd->display, xevent))
return False;
if (esd->current_event->type == xevent->type &&
esd->current_event->xany.window == xevent->xany.window)
{
esd->count += 1; esd->count += 1;
esd->last_time = xevent->xmotion.time; esd->last_time = meta_input_event_get_time (esd->display, xevent);
}
return False; return False;
} }
@ -8996,13 +9024,16 @@ check_use_this_motion_notify (MetaWindow *window,
if (window->display->grab_motion_notify_time != 0) if (window->display->grab_motion_notify_time != 0)
{ {
Time evtime;
evtime = meta_input_event_get_time (window->display, event);
/* == is really the right test, but I'm all for paranoia */ /* == is really the right test, but I'm all for paranoia */
if (window->display->grab_motion_notify_time <= if (window->display->grab_motion_notify_time <= evtime)
event->xmotion.time)
{ {
meta_topic (META_DEBUG_RESIZING, meta_topic (META_DEBUG_RESIZING,
"Arrived at event with time %u (waiting for %u), using it\n", "Arrived at event with time %u (waiting for %u), using it\n",
(unsigned int)event->xmotion.time, (unsigned int) evtime,
window->display->grab_motion_notify_time); window->display->grab_motion_notify_time);
window->display->grab_motion_notify_time = 0; window->display->grab_motion_notify_time = 0;
return TRUE; return TRUE;
@ -9011,7 +9042,11 @@ check_use_this_motion_notify (MetaWindow *window,
return FALSE; /* haven't reached the saved timestamp yet */ return FALSE; /* haven't reached the saved timestamp yet */
} }
esd.current_event = event; esd.current_event_window = meta_input_event_get_window (window->display,
event);
esd.device = device;
esd.current_event_type = MotionNotify;
esd.display = window->display;
esd.count = 0; esd.count = 0;
esd.last_time = 0; esd.last_time = 0;
@ -9059,6 +9094,10 @@ void
meta_window_handle_mouse_grab_op_event (MetaWindow *window, meta_window_handle_mouse_grab_op_event (MetaWindow *window,
XEvent *event) XEvent *event)
{ {
gdouble x_root, y_root;
guint evtype, state;
Window xroot;
#ifdef HAVE_XSYNC #ifdef HAVE_XSYNC
if (event->type == (window->display->xsync_event_base + XSyncAlarmNotify)) if (event->type == (window->display->xsync_event_base + XSyncAlarmNotify))
{ {
@ -9108,12 +9147,19 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
} }
#endif /* HAVE_XSYNC */ #endif /* HAVE_XSYNC */
switch (event->type) if (!meta_input_event_get_type (window->display, event, &evtype) ||
!meta_input_event_get_state (window->display, event, &state) ||
!meta_input_event_get_coordinates (window->display, event,
NULL, NULL, &x_root, &y_root))
return;
xroot = meta_input_event_get_root_window (window->display, event);
switch (evtype)
{ {
case ButtonRelease: case ButtonRelease:
meta_display_check_threshold_reached (window->display, meta_display_check_threshold_reached (window->display,
event->xbutton.x_root, x_root, y_root);
event->xbutton.y_root);
/* If the user was snap moving then ignore the button release /* If the user was snap moving then ignore the button release
* because they may have let go of shift before releasing the * because they may have let go of shift before releasing the
* mouse button and they almost certainly do not want a * mouse button and they almost certainly do not want a
@ -9125,17 +9171,17 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
{ {
if (window->tile_mode != META_TILE_NONE) if (window->tile_mode != META_TILE_NONE)
meta_window_tile (window); meta_window_tile (window);
else if (event->xbutton.root == window->screen->xroot) else if (xroot == window->screen->xroot)
update_move (window, event->xbutton.state & ShiftMask, update_move (window,
event->xbutton.x_root, event->xbutton.y_root); state & ShiftMask,
x_root, y_root);
} }
else if (meta_grab_op_is_resizing (window->display->grab_op)) else if (meta_grab_op_is_resizing (window->display->grab_op))
{ {
if (event->xbutton.root == window->screen->xroot) if (xroot == window->screen->xroot)
update_resize (window, update_resize (window,
event->xbutton.state & ShiftMask, state & ShiftMask,
event->xbutton.x_root, x_root, y_root,
event->xbutton.y_root,
TRUE); TRUE);
if (window->display->compositor) if (window->display->compositor)
meta_compositor_set_updates (window->display->compositor, window, TRUE); meta_compositor_set_updates (window->display->compositor, window, TRUE);
@ -9151,35 +9197,34 @@ meta_window_handle_mouse_grab_op_event (MetaWindow *window,
} }
} }
meta_display_end_grab_op (window->display, event->xbutton.time); meta_display_end_grab_op (window->display,
meta_input_event_get_time (window->display,
event));
break; break;
case MotionNotify: case MotionNotify:
meta_display_check_threshold_reached (window->display, meta_display_check_threshold_reached (window->display,
event->xmotion.x_root, x_root, y_root);
event->xmotion.y_root);
if (meta_grab_op_is_moving (window->display->grab_op)) if (meta_grab_op_is_moving (window->display->grab_op))
{ {
if (event->xmotion.root == window->screen->xroot) if (xroot == window->screen->xroot)
{ {
if (check_use_this_motion_notify (window, if (check_use_this_motion_notify (window,
event)) event))
update_move (window, update_move (window,
event->xmotion.state & ShiftMask, state & ShiftMask,
event->xmotion.x_root, x_root, y_root);
event->xmotion.y_root);
} }
} }
else if (meta_grab_op_is_resizing (window->display->grab_op)) else if (meta_grab_op_is_resizing (window->display->grab_op))
{ {
if (event->xmotion.root == window->screen->xroot) if (xroot == window->screen->xroot)
{ {
if (check_use_this_motion_notify (window, if (check_use_this_motion_notify (window,
event)) event))
update_resize (window, update_resize (window,
event->xmotion.state & ShiftMask, state & ShiftMask,
event->xmotion.x_root, x_root, y_root,
event->xmotion.y_root,
FALSE); FALSE);
} }
} }