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"
|
2018-03-20 10:46:11 +00:00
|
|
|
#include "gdksurface.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
#include "gdkprivate-x11.h"
|
2018-02-07 05:00:01 +00:00
|
|
|
#include "gdkdisplay-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>
|
|
|
|
|
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,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
guint32 start,
|
|
|
|
guint32 stop,
|
|
|
|
GdkTimeCoord ***events,
|
|
|
|
gint *n_events);
|
|
|
|
static void gdk_x11_device_core_get_state (GdkDevice *device,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
gdouble *axes,
|
|
|
|
GdkModifierType *mask);
|
2018-03-20 11:05:26 +00:00
|
|
|
static void gdk_x11_device_core_set_surface_cursor (GdkDevice *device,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkCursor *cursor);
|
|
|
|
static void gdk_x11_device_core_warp (GdkDevice *device,
|
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,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
|
|
|
GdkSurface **child_surface,
|
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,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
gboolean owner_events,
|
|
|
|
GdkEventMask event_mask,
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurface *confine_to,
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkCursor *cursor,
|
|
|
|
guint32 time_);
|
|
|
|
static void gdk_x11_device_core_ungrab (GdkDevice *device,
|
|
|
|
guint32 time_);
|
2018-03-20 11:05:26 +00:00
|
|
|
static GdkSurface * gdk_x11_device_core_surface_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);
|
|
|
|
|
|
|
|
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;
|
2018-03-20 11:05:26 +00:00
|
|
|
device_class->set_surface_cursor = gdk_x11_device_core_set_surface_cursor;
|
2010-12-21 04:59:07 +00:00
|
|
|
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;
|
2018-03-20 11:05:26 +00:00
|
|
|
device_class->surface_at_position = gdk_x11_device_core_surface_at_position;
|
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);
|
|
|
|
|
2017-11-15 17:13:31 +00:00
|
|
|
_gdk_device_add_axis (device, NULL, GDK_AXIS_X, 0, 0, 1);
|
|
|
|
_gdk_device_add_axis (device, NULL, GDK_AXIS_Y, 0, 0, 1);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2018-03-20 14:14:10 +00:00
|
|
|
impl_coord_in_surface (GdkSurface *surface,
|
2010-05-25 22:38:44 +00:00
|
|
|
int impl_x,
|
|
|
|
int impl_y)
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
if (impl_x < surface->abs_x ||
|
|
|
|
impl_x >= surface->abs_x + surface->width)
|
2010-05-25 22:38:44 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (impl_y < surface->abs_y ||
|
|
|
|
impl_y >= surface->abs_y + surface->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,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
guint32 start,
|
|
|
|
guint32 stop,
|
|
|
|
GdkTimeCoord ***events,
|
|
|
|
gint *n_events)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
XTimeCoord *xcoords;
|
|
|
|
GdkTimeCoord **coords;
|
2018-03-20 11:05:26 +00:00
|
|
|
GdkSurface *impl_surface;
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurfaceImplX11 *impl;
|
2010-05-25 22:38:44 +00:00
|
|
|
int tmp_n_events;
|
|
|
|
int i, j;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
impl_surface = _gdk_surface_get_impl_surface (surface);
|
2018-03-20 11:05:26 +00:00
|
|
|
impl = GDK_SURFACE_IMPL_X11 (impl_surface->impl);
|
2018-03-20 14:14:10 +00:00
|
|
|
xcoords = XGetMotionEvents (GDK_SURFACE_XDISPLAY (surface),
|
2018-03-20 11:05:26 +00:00
|
|
|
GDK_SURFACE_XID (impl_surface),
|
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++)
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
if (impl_coord_in_surface (surface,
|
2018-03-20 11:05:26 +00:00
|
|
|
xcoords[i].x / impl->surface_scale,
|
|
|
|
xcoords[i].y / impl->surface_scale))
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
coords[j]->time = xcoords[i].time;
|
2018-03-20 14:14:10 +00:00
|
|
|
coords[j]->axes[0] = (double)xcoords[i].x / impl->surface_scale - surface->abs_x;
|
|
|
|
coords[j]->axes[1] = (double)xcoords[i].y / impl->surface_scale - surface->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,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
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
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_surface_get_device_position_double (surface, 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
|
2018-03-20 11:05:26 +00:00
|
|
|
gdk_x11_device_core_set_surface_cursor (GdkDevice *device,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
GdkCursor *cursor)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2017-11-03 05:01:56 +00:00
|
|
|
GdkDisplay *display = gdk_device_get_display (device);
|
2010-05-25 22:38:44 +00:00
|
|
|
Cursor xcursor;
|
|
|
|
|
|
|
|
if (!cursor)
|
|
|
|
xcursor = None;
|
|
|
|
else
|
2017-11-03 05:01:56 +00:00
|
|
|
xcursor = gdk_x11_display_get_xcursor (display, cursor);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-11-03 05:01:56 +00:00
|
|
|
XDefineCursor (GDK_DISPLAY_XDISPLAY (display),
|
2018-03-20 14:14:10 +00:00
|
|
|
GDK_SURFACE_XID (surface),
|
2010-05-25 22:38:44 +00:00
|
|
|
xcursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 04:59:07 +00:00
|
|
|
gdk_x11_device_core_warp (GdkDevice *device,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2017-11-01 22:06:24 +00:00
|
|
|
GdkDisplay *display;
|
2010-05-25 22:38:44 +00:00
|
|
|
Display *xdisplay;
|
|
|
|
Window dest;
|
2017-11-17 15:37:52 +00:00
|
|
|
GdkX11Screen *screen;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-11-01 22:06:24 +00:00
|
|
|
display = gdk_device_get_display (device);
|
|
|
|
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
|
|
|
screen = GDK_X11_DISPLAY (display)->screen;
|
2017-11-09 23:40:16 +00:00
|
|
|
dest = GDK_SCREEN_XROOTWIN (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,
|
2018-03-20 11:05:26 +00:00
|
|
|
round (x * screen->surface_scale),
|
|
|
|
round (y * screen->surface_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,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
|
|
|
GdkSurface **child_surface,
|
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
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
2017-11-17 15:37:52 +00:00
|
|
|
GdkX11Screen *screen;
|
2017-11-09 23:40:16 +00:00
|
|
|
Window xwindow, w;
|
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;
|
2017-11-09 23:40:16 +00:00
|
|
|
int scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-08-08 23:45:09 +00:00
|
|
|
display = gdk_device_get_display (device);
|
2017-11-01 22:06:24 +00:00
|
|
|
screen = GDK_X11_DISPLAY (display)->screen;
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface == NULL)
|
2017-11-09 23:40:16 +00:00
|
|
|
{
|
|
|
|
xwindow = GDK_SCREEN_XROOTWIN (screen);
|
2018-03-20 11:05:26 +00:00
|
|
|
scale = screen->surface_scale;
|
2017-11-09 23:40:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
xwindow = GDK_SURFACE_XID (surface);
|
|
|
|
scale = GDK_SURFACE_IMPL_X11 (surface->impl)->surface_scale;
|
2017-11-09 23:40:16 +00:00
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2012-03-09 17:36:11 +00:00
|
|
|
if (!GDK_X11_DISPLAY (display)->trusted_client ||
|
2018-03-20 14:14:10 +00:00
|
|
|
!XQueryPointer (GDK_SURFACE_XDISPLAY (surface),
|
2017-11-09 23:40:16 +00:00
|
|
|
xwindow,
|
2012-03-09 17:36:11 +00:00
|
|
|
&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;
|
|
|
|
|
|
|
|
/* FIXME: untrusted clients not multidevice-safe */
|
2017-11-01 22:06:24 +00:00
|
|
|
xdisplay = GDK_SCREEN_XDISPLAY (screen);
|
|
|
|
xwindow = GDK_SCREEN_XROOTWIN (screen);
|
2010-12-13 22:43:10 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (child_surface)
|
|
|
|
*child_surface = gdk_x11_surface_lookup_for_display (display, xchild_window);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (root_x)
|
2017-11-09 23:40:16 +00:00
|
|
|
*root_x = (double)xroot_x / scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (root_y)
|
2017-11-09 23:40:16 +00:00
|
|
|
*root_y = (double)xroot_y / scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_x)
|
2017-11-09 23:40:16 +00:00
|
|
|
*win_x = (double)xwin_x / scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_y)
|
2017-11-09 23:40:16 +00:00
|
|
|
*win_y = (double)xwin_y / 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,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-12-21 04:59:07 +00:00
|
|
|
gboolean owner_events,
|
|
|
|
GdkEventMask event_mask,
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurface *confine_to,
|
2010-12-21 04:59:07 +00:00
|
|
|
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);
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
xwindow = GDK_SURFACE_XID (surface);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (confine_to)
|
2018-03-20 11:05:26 +00:00
|
|
|
confine_to = _gdk_surface_get_impl_surface (confine_to);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 10:40:08 +00:00
|
|
|
if (!confine_to || GDK_SURFACE_DESTROYED (confine_to))
|
2010-05-25 22:38:44 +00:00
|
|
|
xconfine_to = None;
|
|
|
|
else
|
2018-03-20 10:40:08 +00:00
|
|
|
xconfine_to = GDK_SURFACE_XID (confine_to);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-10 17:13:25 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2018-01-12 00:48:27 +00:00
|
|
|
if (GDK_DISPLAY_DEBUG_CHECK (display, NOGRABS))
|
2010-12-10 17:13:25 +00:00
|
|
|
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
|
|
|
|
{
|
2017-11-03 05:01:56 +00:00
|
|
|
xcursor = gdk_x11_display_get_xcursor (display, 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
|
|
|
}
|
|
|
|
|
2018-03-20 10:40:08 +00:00
|
|
|
static GdkSurface *
|
2018-03-20 11:05:26 +00:00
|
|
|
gdk_x11_device_core_surface_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
|
|
|
{
|
2018-03-20 10:40:08 +00:00
|
|
|
GdkSurfaceImplX11 *impl;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
Display *xdisplay;
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface;
|
2017-11-17 15:37:52 +00:00
|
|
|
GdkX11Screen *screen;
|
2010-05-25 22:38:44 +00:00
|
|
|
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);
|
2017-11-01 22:06:24 +00:00
|
|
|
screen = GDK_X11_DISPLAY (display)->screen;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* 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;
|
2017-11-05 23:36:49 +00:00
|
|
|
toplevels = gdk_x11_display_get_toplevel_windows (display);
|
2015-10-20 00:31:57 +00:00
|
|
|
for (list = toplevels; list != NULL; list = list->next)
|
2010-12-13 22:43:10 +00:00
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
surface = GDK_SURFACE (list->data);
|
|
|
|
impl = GDK_SURFACE_IMPL_X11 (surface->impl);
|
|
|
|
xwindow = GDK_SURFACE_XID (surface);
|
2013-04-04 14:22:12 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_surface_get_geometry (surface, NULL, NULL, &width, &height);
|
2018-03-20 11:05:26 +00:00
|
|
|
if (winx >= 0 && winy >= 0 && winx < width * impl->surface_scale && winy < height * impl->surface_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 &&
|
2018-06-25 22:47:40 +00:00
|
|
|
(surface = gdk_x11_surface_lookup_for_display (display, last)) != NULL)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
xwindow = last;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_x11_display_ungrab (display);
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
surface = gdk_x11_surface_lookup_for_display (display, last);
|
2013-06-20 09:40:07 +00:00
|
|
|
impl = NULL;
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface)
|
|
|
|
impl = GDK_SURFACE_IMPL_X11 (surface->impl);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_x)
|
2018-03-20 14:14:10 +00:00
|
|
|
*win_x = (surface) ? (double)xwin_x / impl->surface_scale : -1;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_y)
|
2018-03-20 14:14:10 +00:00
|
|
|
*win_y = (surface) ? (double)xwin_y / impl->surface_scale : -1;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (mask)
|
|
|
|
*mask = xmask;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
return surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|