2010-05-25 22:38:44 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
* Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-25 22:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-07-03 09:52:58 +00:00
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
#include "gdkx11device-core.h"
|
2010-12-21 15:37:21 +00:00
|
|
|
#include "gdkdeviceprivate.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
|
2010-11-22 23:55:39 +00:00
|
|
|
#include "gdkinternals.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
#include "gdkwindow.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
#include "gdkprivate-x11.h"
|
2010-12-10 17:13:25 +00:00
|
|
|
#include "gdkasync.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2013-07-03 09:52:58 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
/* for the use of round() */
|
|
|
|
#include "fallback-c89.c"
|
|
|
|
|
2010-12-21 15:37:21 +00:00
|
|
|
struct _GdkX11DeviceCore
|
|
|
|
{
|
|
|
|
GdkDevice parent_instance;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GdkX11DeviceCoreClass
|
|
|
|
{
|
|
|
|
GdkDeviceClass parent_class;
|
|
|
|
};
|
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
static gboolean gdk_x11_device_core_get_history (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
guint32 start,
|
|
|
|
guint32 stop,
|
|
|
|
GdkTimeCoord ***events,
|
|
|
|
gint *n_events);
|
|
|
|
static void gdk_x11_device_core_get_state (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
gdouble *axes,
|
|
|
|
GdkModifierType *mask);
|
|
|
|
static void gdk_x11_device_core_set_window_cursor (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkCursor *cursor);
|
|
|
|
static void gdk_x11_device_core_warp (GdkDevice *device,
|
|
|
|
GdkScreen *screen,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble x,
|
|
|
|
gdouble y);
|
2012-03-09 12:20:41 +00:00
|
|
|
static void gdk_x11_device_core_query_state (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkWindow **root_window,
|
|
|
|
GdkWindow **child_window,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble *root_x,
|
|
|
|
gdouble *root_y,
|
|
|
|
gdouble *win_x,
|
|
|
|
gdouble *win_y,
|
2012-03-09 12:20:41 +00:00
|
|
|
GdkModifierType *mask);
|
2010-12-21 04:59:07 +00:00
|
|
|
static GdkGrabStatus gdk_x11_device_core_grab (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
gboolean owner_events,
|
|
|
|
GdkEventMask event_mask,
|
|
|
|
GdkWindow *confine_to,
|
|
|
|
GdkCursor *cursor,
|
|
|
|
guint32 time_);
|
|
|
|
static void gdk_x11_device_core_ungrab (GdkDevice *device,
|
|
|
|
guint32 time_);
|
|
|
|
static GdkWindow * gdk_x11_device_core_window_at_position (GdkDevice *device,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble *win_x,
|
|
|
|
gdouble *win_y,
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkModifierType *mask,
|
|
|
|
gboolean get_toplevel);
|
|
|
|
static void gdk_x11_device_core_select_window_events (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkEventMask event_mask);
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GdkX11DeviceCore, gdk_x11_device_core, GDK_TYPE_DEVICE)
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_class_init (GdkX11DeviceCoreClass *klass)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
|
|
|
|
|
2010-12-21 04:59:07 +00:00
|
|
|
device_class->get_history = gdk_x11_device_core_get_history;
|
|
|
|
device_class->get_state = gdk_x11_device_core_get_state;
|
|
|
|
device_class->set_window_cursor = gdk_x11_device_core_set_window_cursor;
|
|
|
|
device_class->warp = gdk_x11_device_core_warp;
|
|
|
|
device_class->query_state = gdk_x11_device_core_query_state;
|
|
|
|
device_class->grab = gdk_x11_device_core_grab;
|
|
|
|
device_class->ungrab = gdk_x11_device_core_ungrab;
|
|
|
|
device_class->window_at_position = gdk_x11_device_core_window_at_position;
|
|
|
|
device_class->select_window_events = gdk_x11_device_core_select_window_events;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_init (GdkX11DeviceCore *device_core)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDevice *device;
|
|
|
|
|
|
|
|
device = GDK_DEVICE (device_core);
|
|
|
|
|
|
|
|
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
|
|
|
|
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
impl_coord_in_window (GdkWindow *window,
|
|
|
|
int impl_x,
|
|
|
|
int impl_y)
|
|
|
|
{
|
2010-11-22 23:55:39 +00:00
|
|
|
if (impl_x < window->abs_x ||
|
2010-11-22 23:56:33 +00:00
|
|
|
impl_x >= window->abs_x + window->width)
|
2010-05-25 22:38:44 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2010-11-22 23:55:39 +00:00
|
|
|
if (impl_y < window->abs_y ||
|
2010-11-22 23:56:33 +00:00
|
|
|
impl_y >= window->abs_y + window->height)
|
2010-05-25 22:38:44 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_get_history (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
guint32 start,
|
|
|
|
guint32 stop,
|
|
|
|
GdkTimeCoord ***events,
|
|
|
|
gint *n_events)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
XTimeCoord *xcoords;
|
|
|
|
GdkTimeCoord **coords;
|
|
|
|
GdkWindow *impl_window;
|
2013-06-20 09:40:07 +00:00
|
|
|
GdkWindowImplX11 *impl;
|
2010-05-25 22:38:44 +00:00
|
|
|
int tmp_n_events;
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
impl_window = _gdk_window_get_impl_window (window);
|
2013-06-20 09:40:07 +00:00
|
|
|
impl = GDK_WINDOW_IMPL_X11 (impl_window->impl);
|
2010-10-05 23:22:45 +00:00
|
|
|
xcoords = XGetMotionEvents (GDK_WINDOW_XDISPLAY (window),
|
|
|
|
GDK_WINDOW_XID (impl_window),
|
2010-05-25 22:38:44 +00:00
|
|
|
start, stop, &tmp_n_events);
|
|
|
|
if (!xcoords)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
coords = _gdk_device_allocate_history (device, tmp_n_events);
|
|
|
|
|
|
|
|
for (i = 0, j = 0; i < tmp_n_events; i++)
|
|
|
|
{
|
2013-06-20 09:40:07 +00:00
|
|
|
if (impl_coord_in_window (window,
|
|
|
|
xcoords[i].x / impl->window_scale,
|
|
|
|
xcoords[i].y / impl->window_scale))
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
coords[j]->time = xcoords[i].time;
|
2013-06-20 09:40:07 +00:00
|
|
|
coords[j]->axes[0] = (double)xcoords[i].x / impl->window_scale - window->abs_x;
|
|
|
|
coords[j]->axes[1] = (double)xcoords[i].y / impl->window_scale - window->abs_y;
|
2010-05-25 22:38:44 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree (xcoords);
|
|
|
|
|
|
|
|
/* free the events we allocated too much */
|
|
|
|
for (i = j; i < tmp_n_events; i++)
|
|
|
|
{
|
|
|
|
g_free (coords[i]);
|
|
|
|
coords[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_n_events = j;
|
|
|
|
|
|
|
|
if (tmp_n_events == 0)
|
|
|
|
{
|
|
|
|
gdk_device_free_history (coords, tmp_n_events);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n_events)
|
|
|
|
*n_events = tmp_n_events;
|
|
|
|
|
|
|
|
if (events)
|
|
|
|
*events = coords;
|
|
|
|
else if (coords)
|
|
|
|
gdk_device_free_history (coords, tmp_n_events);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_get_state (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
gdouble *axes,
|
|
|
|
GdkModifierType *mask)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble x, y;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2013-07-03 09:52:58 +00:00
|
|
|
gdk_window_get_device_position_double (window, device, &x, &y, mask);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (axes)
|
|
|
|
{
|
2013-07-03 09:52:58 +00:00
|
|
|
axes[0] = x;
|
|
|
|
axes[1] = y;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_set_window_cursor (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkCursor *cursor)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
Cursor xcursor;
|
|
|
|
|
|
|
|
if (!cursor)
|
|
|
|
xcursor = None;
|
|
|
|
else
|
2010-12-20 00:56:07 +00:00
|
|
|
xcursor = gdk_x11_cursor_get_xcursor (cursor);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
XDefineCursor (GDK_WINDOW_XDISPLAY (window),
|
|
|
|
GDK_WINDOW_XID (window),
|
|
|
|
xcursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_warp (GdkDevice *device,
|
|
|
|
GdkScreen *screen,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
Display *xdisplay;
|
|
|
|
Window dest;
|
|
|
|
|
|
|
|
xdisplay = GDK_DISPLAY_XDISPLAY (gdk_device_get_display (device));
|
2010-11-22 16:06:46 +00:00
|
|
|
dest = GDK_WINDOW_XID (gdk_screen_get_root_window (screen));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2013-06-20 09:40:07 +00:00
|
|
|
XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0,
|
2013-07-03 09:52:58 +00:00
|
|
|
round (x * GDK_X11_SCREEN (screen)->window_scale),
|
|
|
|
round (y * GDK_X11_SCREEN (screen)->window_scale));
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 12:20:41 +00:00
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_query_state (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkWindow **root_window,
|
|
|
|
GdkWindow **child_window,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble *root_x,
|
|
|
|
gdouble *root_y,
|
|
|
|
gdouble *win_x,
|
|
|
|
gdouble *win_y,
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkModifierType *mask)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2013-06-20 09:40:07 +00:00
|
|
|
GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (window->impl);
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDisplay *display;
|
2010-12-13 22:43:10 +00:00
|
|
|
GdkScreen *default_screen;
|
2010-05-25 22:38:44 +00:00
|
|
|
Window xroot_window, xchild_window;
|
|
|
|
int xroot_x, xroot_y, xwin_x, xwin_y;
|
|
|
|
unsigned int xmask;
|
|
|
|
|
2010-08-29 00:08:47 +00:00
|
|
|
display = gdk_window_get_display (window);
|
2010-12-13 22:43:10 +00:00
|
|
|
default_screen = gdk_display_get_default_screen (display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2012-03-09 17:36:11 +00:00
|
|
|
if (!GDK_X11_DISPLAY (display)->trusted_client ||
|
|
|
|
!XQueryPointer (GDK_WINDOW_XDISPLAY (window),
|
|
|
|
GDK_WINDOW_XID (window),
|
|
|
|
&xroot_window,
|
|
|
|
&xchild_window,
|
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
|
|
|
&xmask))
|
2010-12-13 22:43:10 +00:00
|
|
|
{
|
|
|
|
XSetWindowAttributes attributes;
|
|
|
|
Display *xdisplay;
|
|
|
|
Window xwindow, w;
|
|
|
|
|
|
|
|
/* FIXME: untrusted clients not multidevice-safe */
|
|
|
|
xdisplay = GDK_SCREEN_XDISPLAY (default_screen);
|
|
|
|
xwindow = GDK_SCREEN_XROOTWIN (default_screen);
|
|
|
|
|
|
|
|
w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0,
|
|
|
|
CopyFromParent, InputOnly, CopyFromParent,
|
|
|
|
0, &attributes);
|
|
|
|
XQueryPointer (xdisplay, w,
|
|
|
|
&xroot_window,
|
|
|
|
&xchild_window,
|
2010-12-21 04:59:07 +00:00
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
2010-12-13 22:43:10 +00:00
|
|
|
&xmask);
|
|
|
|
XDestroyWindow (xdisplay, w);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (root_window)
|
2010-12-15 06:39:30 +00:00
|
|
|
*root_window = gdk_x11_window_lookup_for_display (display, xroot_window);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (child_window)
|
2010-12-15 06:39:30 +00:00
|
|
|
*child_window = gdk_x11_window_lookup_for_display (display, xchild_window);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (root_x)
|
2013-07-03 09:52:58 +00:00
|
|
|
*root_x = (double)xroot_x / impl->window_scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (root_y)
|
2013-07-03 09:52:58 +00:00
|
|
|
*root_y = (double)xroot_y / impl->window_scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_x)
|
2013-07-03 09:52:58 +00:00
|
|
|
*win_x = (double)xwin_x / impl->window_scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_y)
|
2013-07-03 09:52:58 +00:00
|
|
|
*win_y = (double)xwin_y / impl->window_scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (mask)
|
|
|
|
*mask = xmask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkGrabStatus
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_grab (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
gboolean owner_events,
|
|
|
|
GdkEventMask event_mask,
|
|
|
|
GdkWindow *confine_to,
|
|
|
|
GdkCursor *cursor,
|
|
|
|
guint32 time_)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
Window xwindow, xconfine_to;
|
2010-12-10 17:13:25 +00:00
|
|
|
gint status;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
display = gdk_device_get_display (device);
|
|
|
|
|
|
|
|
xwindow = GDK_WINDOW_XID (window);
|
|
|
|
|
|
|
|
if (confine_to)
|
|
|
|
confine_to = _gdk_window_get_impl_window (confine_to);
|
|
|
|
|
|
|
|
if (!confine_to || GDK_WINDOW_DESTROYED (confine_to))
|
|
|
|
xconfine_to = None;
|
|
|
|
else
|
|
|
|
xconfine_to = GDK_WINDOW_XID (confine_to);
|
|
|
|
|
2010-12-10 17:13:25 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
if (_gdk_debug_flags & GDK_DEBUG_NOGRABS)
|
|
|
|
status = GrabSuccess;
|
|
|
|
else
|
|
|
|
#endif
|
2010-11-23 19:25:13 +00:00
|
|
|
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
/* Device is a keyboard */
|
|
|
|
status = XGrabKeyboard (GDK_DISPLAY_XDISPLAY (display),
|
|
|
|
xwindow,
|
|
|
|
owner_events,
|
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
time_);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Cursor xcursor;
|
|
|
|
guint xevent_mask;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
/* Device is a pointer */
|
|
|
|
if (!cursor)
|
|
|
|
xcursor = None;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_gdk_x11_cursor_update_theme (cursor);
|
2010-12-20 00:56:07 +00:00
|
|
|
xcursor = gdk_x11_cursor_get_xcursor (cursor);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
xevent_mask = 0;
|
|
|
|
|
2010-12-15 22:32:29 +00:00
|
|
|
for (i = 0; i < _gdk_x11_event_mask_table_size; i++)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
if (event_mask & (1 << (i + 1)))
|
2010-12-15 22:32:29 +00:00
|
|
|
xevent_mask |= _gdk_x11_event_mask_table[i];
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We don't want to set a native motion hint mask, as we're emulating motion
|
|
|
|
* hints. If we set a native one we just wouldn't get any events.
|
|
|
|
*/
|
|
|
|
xevent_mask &= ~PointerMotionHintMask;
|
|
|
|
|
|
|
|
status = XGrabPointer (GDK_DISPLAY_XDISPLAY (display),
|
|
|
|
xwindow,
|
|
|
|
owner_events,
|
|
|
|
xevent_mask,
|
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
xconfine_to,
|
|
|
|
xcursor,
|
|
|
|
time_);
|
|
|
|
}
|
|
|
|
|
2010-12-10 17:13:25 +00:00
|
|
|
_gdk_x11_display_update_grab_info (display, device, status);
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
return _gdk_x11_convert_grab_status (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_ungrab (GdkDevice *device,
|
|
|
|
guint32 time_)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
2010-12-10 17:13:25 +00:00
|
|
|
gulong serial;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
display = gdk_device_get_display (device);
|
2010-12-10 17:13:25 +00:00
|
|
|
serial = NextRequest (GDK_DISPLAY_XDISPLAY (display));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-11-23 19:25:13 +00:00
|
|
|
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
|
2010-05-25 22:38:44 +00:00
|
|
|
XUngrabKeyboard (GDK_DISPLAY_XDISPLAY (display), time_);
|
|
|
|
else
|
|
|
|
XUngrabPointer (GDK_DISPLAY_XDISPLAY (display), time_);
|
2010-12-10 17:13:25 +00:00
|
|
|
|
|
|
|
_gdk_x11_display_update_grab_info_ungrab (display, device, time_, serial);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GdkWindow *
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_window_at_position (GdkDevice *device,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble *win_x,
|
|
|
|
gdouble *win_y,
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkModifierType *mask,
|
|
|
|
gboolean get_toplevel)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2013-06-20 09:40:07 +00:00
|
|
|
GdkWindowImplX11 *impl;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
GdkScreen *screen;
|
|
|
|
Display *xdisplay;
|
|
|
|
GdkWindow *window;
|
|
|
|
Window xwindow, root, child, last;
|
|
|
|
int xroot_x, xroot_y, xwin_x, xwin_y;
|
|
|
|
unsigned int xmask;
|
|
|
|
|
|
|
|
last = None;
|
|
|
|
display = gdk_device_get_display (device);
|
|
|
|
screen = gdk_display_get_default_screen (display);
|
|
|
|
|
|
|
|
/* This function really only works if the mouse pointer is held still
|
|
|
|
* during its operation. If it moves from one leaf window to another
|
|
|
|
* than we'll end up with inaccurate values for win_x, win_y
|
|
|
|
* and the result.
|
|
|
|
*/
|
|
|
|
gdk_x11_display_grab (display);
|
|
|
|
|
|
|
|
xdisplay = GDK_SCREEN_XDISPLAY (screen);
|
|
|
|
xwindow = GDK_SCREEN_XROOTWIN (screen);
|
|
|
|
|
2010-12-20 18:20:10 +00:00
|
|
|
if (G_LIKELY (GDK_X11_DISPLAY (display)->trusted_client))
|
2010-12-13 22:43:10 +00:00
|
|
|
{
|
|
|
|
XQueryPointer (xdisplay, xwindow,
|
|
|
|
&root, &child,
|
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
|
|
|
&xmask);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-13 22:43:10 +00:00
|
|
|
if (root == xwindow)
|
|
|
|
xwindow = child;
|
|
|
|
else
|
|
|
|
xwindow = root;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
else
|
2010-12-13 22:43:10 +00:00
|
|
|
{
|
2013-04-04 14:22:12 +00:00
|
|
|
gint width, height;
|
2010-12-13 22:43:10 +00:00
|
|
|
GList *toplevels, *list;
|
2015-05-31 01:17:45 +00:00
|
|
|
Window pointer_window;
|
2010-12-13 22:43:10 +00:00
|
|
|
int rootx = -1, rooty = -1;
|
|
|
|
int winx, winy;
|
|
|
|
|
|
|
|
/* FIXME: untrusted clients case not multidevice-safe */
|
|
|
|
pointer_window = None;
|
2015-10-22 03:45:48 +00:00
|
|
|
screen = gdk_display_get_default_screen (display);
|
2013-04-04 14:22:12 +00:00
|
|
|
toplevels = gdk_screen_get_toplevel_windows (screen);
|
2015-10-20 00:31:57 +00:00
|
|
|
for (list = toplevels; list != NULL; list = list->next)
|
2010-12-13 22:43:10 +00:00
|
|
|
{
|
2013-04-04 14:22:12 +00:00
|
|
|
window = GDK_WINDOW (list->data);
|
2013-06-20 09:40:07 +00:00
|
|
|
impl = GDK_WINDOW_IMPL_X11 (window->impl);
|
2013-04-04 14:22:12 +00:00
|
|
|
xwindow = GDK_WINDOW_XID (window);
|
|
|
|
gdk_x11_display_error_trap_push (display);
|
|
|
|
XQueryPointer (xdisplay, xwindow,
|
|
|
|
&root, &child,
|
|
|
|
&rootx, &rooty,
|
|
|
|
&winx, &winy,
|
|
|
|
&xmask);
|
|
|
|
if (gdk_x11_display_error_trap_pop (display))
|
|
|
|
continue;
|
|
|
|
if (child != None)
|
|
|
|
{
|
|
|
|
pointer_window = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gdk_window_get_geometry (window, NULL, NULL, &width, &height);
|
2013-06-20 09:40:07 +00:00
|
|
|
if (winx >= 0 && winy >= 0 && winx < width * impl->window_scale && winy < height * impl->window_scale)
|
2010-12-13 22:43:10 +00:00
|
|
|
{
|
2013-04-04 14:22:12 +00:00
|
|
|
/* A childless toplevel, or below another window? */
|
|
|
|
XSetWindowAttributes attributes;
|
|
|
|
Window w;
|
|
|
|
|
|
|
|
w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0,
|
|
|
|
CopyFromParent, InputOnly, CopyFromParent,
|
|
|
|
0, &attributes);
|
|
|
|
XMapWindow (xdisplay, w);
|
2010-12-13 22:43:10 +00:00
|
|
|
XQueryPointer (xdisplay, xwindow,
|
2010-12-21 04:59:07 +00:00
|
|
|
&root, &child,
|
|
|
|
&rootx, &rooty,
|
|
|
|
&winx, &winy,
|
|
|
|
&xmask);
|
2013-04-04 14:22:12 +00:00
|
|
|
XDestroyWindow (xdisplay, w);
|
|
|
|
if (child == w)
|
2010-12-13 22:43:10 +00:00
|
|
|
{
|
2013-04-04 14:22:12 +00:00
|
|
|
pointer_window = xwindow;
|
2010-12-13 22:43:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 14:22:12 +00:00
|
|
|
g_list_free (toplevels);
|
|
|
|
|
2010-12-13 22:43:10 +00:00
|
|
|
xwindow = pointer_window;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
while (xwindow)
|
|
|
|
{
|
|
|
|
last = xwindow;
|
2010-12-13 22:43:10 +00:00
|
|
|
gdk_x11_display_error_trap_push (display);
|
2010-05-25 22:38:44 +00:00
|
|
|
XQueryPointer (xdisplay, xwindow,
|
|
|
|
&root, &xwindow,
|
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
|
|
|
&xmask);
|
2010-12-13 22:43:10 +00:00
|
|
|
if (gdk_x11_display_error_trap_pop (display))
|
|
|
|
break;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (get_toplevel && last != root &&
|
2010-12-15 06:39:30 +00:00
|
|
|
(window = gdk_x11_window_lookup_for_display (display, last)) != NULL &&
|
2010-11-22 23:55:39 +00:00
|
|
|
window->window_type != GDK_WINDOW_FOREIGN)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
xwindow = last;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_x11_display_ungrab (display);
|
|
|
|
|
2010-12-15 06:39:30 +00:00
|
|
|
window = gdk_x11_window_lookup_for_display (display, last);
|
2013-06-20 09:40:07 +00:00
|
|
|
impl = NULL;
|
|
|
|
if (window)
|
|
|
|
impl = GDK_WINDOW_IMPL_X11 (window->impl);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_x)
|
2013-07-03 09:52:58 +00:00
|
|
|
*win_x = (window) ? (double)xwin_x / impl->window_scale : -1;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_y)
|
2013-07-03 09:52:58 +00:00
|
|
|
*win_y = (window) ? (double)xwin_y / impl->window_scale : -1;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (mask)
|
|
|
|
*mask = xmask;
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_select_window_events (GdkDevice *device,
|
2014-08-14 04:10:23 +00:00
|
|
|
GdkWindow *window,
|
|
|
|
GdkEventMask event_mask)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkEventMask filter_mask, window_mask;
|
|
|
|
guint xmask = 0;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
window_mask = gdk_window_get_events (window);
|
2014-08-14 04:10:23 +00:00
|
|
|
filter_mask = GDK_POINTER_MOTION_MASK
|
|
|
|
| GDK_POINTER_MOTION_HINT_MASK
|
|
|
|
| GDK_BUTTON_MOTION_MASK
|
|
|
|
| GDK_BUTTON1_MOTION_MASK
|
|
|
|
| GDK_BUTTON2_MOTION_MASK
|
|
|
|
| GDK_BUTTON3_MOTION_MASK
|
|
|
|
| GDK_BUTTON_PRESS_MASK
|
|
|
|
| GDK_BUTTON_RELEASE_MASK
|
|
|
|
| GDK_KEY_PRESS_MASK
|
|
|
|
| GDK_KEY_RELEASE_MASK
|
|
|
|
| GDK_ENTER_NOTIFY_MASK
|
|
|
|
| GDK_LEAVE_NOTIFY_MASK
|
|
|
|
| GDK_FOCUS_CHANGE_MASK
|
|
|
|
| GDK_PROXIMITY_IN_MASK
|
|
|
|
| GDK_PROXIMITY_OUT_MASK
|
|
|
|
| GDK_SCROLL_MASK;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* Filter out non-device events */
|
|
|
|
event_mask &= filter_mask;
|
|
|
|
|
|
|
|
/* Unset device events on window mask */
|
2014-08-14 04:10:23 +00:00
|
|
|
window_mask &= ~filter_mask;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* Combine masks */
|
|
|
|
event_mask |= window_mask;
|
|
|
|
|
2010-12-15 22:32:29 +00:00
|
|
|
for (i = 0; i < _gdk_x11_event_mask_table_size; i++)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
if (event_mask & (1 << (i + 1)))
|
2010-12-15 22:32:29 +00:00
|
|
|
xmask |= _gdk_x11_event_mask_table[i];
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (GDK_WINDOW_XID (window) != GDK_WINDOW_XROOTWIN (window))
|
|
|
|
xmask |= StructureNotifyMask | PropertyChangeMask;
|
|
|
|
|
|
|
|
XSelectInput (GDK_WINDOW_XDISPLAY (window),
|
2010-11-22 16:06:46 +00:00
|
|
|
GDK_WINDOW_XID (window),
|
2010-05-25 22:38:44 +00:00
|
|
|
xmask);
|
|
|
|
}
|