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"
|
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
#include "gdkx11device-xi2.h"
|
2010-12-21 15:37:21 +00:00
|
|
|
#include "gdkdeviceprivate.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
#include "gdkintl.h"
|
2010-12-10 17:13:25 +00:00
|
|
|
#include "gdkasync.h"
|
2010-12-16 03:09:35 +00:00
|
|
|
#include "gdkprivate-x11.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-01-30 04:26:34 +00:00
|
|
|
#include <stdlib.h>
|
2010-12-21 19:17:02 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/extensions/XInput2.h>
|
|
|
|
|
2013-07-03 09:52:58 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
/* for the use of round() */
|
|
|
|
#include "fallback-c89.c"
|
2011-02-12 00:27:40 +00:00
|
|
|
|
2012-01-23 23:49:52 +00:00
|
|
|
typedef struct _ScrollValuator ScrollValuator;
|
|
|
|
|
|
|
|
struct _ScrollValuator
|
|
|
|
{
|
|
|
|
guint n_valuator : 4;
|
|
|
|
guint direction : 4;
|
2015-07-15 19:19:25 +00:00
|
|
|
guint last_value_valid : 1;
|
2012-01-23 23:49:52 +00:00
|
|
|
gdouble last_value;
|
2012-03-05 00:12:27 +00:00
|
|
|
gdouble increment;
|
2012-01-23 23:49:52 +00:00
|
|
|
};
|
|
|
|
|
2010-12-21 15:37:21 +00:00
|
|
|
struct _GdkX11DeviceXI2
|
|
|
|
{
|
|
|
|
GdkDevice parent_instance;
|
|
|
|
|
|
|
|
gint device_id;
|
2012-01-23 23:49:52 +00:00
|
|
|
GArray *scroll_valuators;
|
2015-03-02 17:19:16 +00:00
|
|
|
gdouble *last_axes;
|
2010-12-21 15:37:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GdkX11DeviceXI2Class
|
|
|
|
{
|
|
|
|
GdkDeviceClass parent_class;
|
|
|
|
};
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-02-12 00:27:40 +00:00
|
|
|
G_DEFINE_TYPE (GdkX11DeviceXI2, gdk_x11_device_xi2, GDK_TYPE_DEVICE)
|
|
|
|
|
|
|
|
|
2012-01-23 23:49:52 +00:00
|
|
|
static void gdk_x11_device_xi2_finalize (GObject *object);
|
2010-12-21 06:32:01 +00:00
|
|
|
static void gdk_x11_device_xi2_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gdk_x11_device_xi2_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gdk_x11_device_xi2_get_state (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
gdouble *axes,
|
|
|
|
GdkModifierType *mask);
|
|
|
|
static void gdk_x11_device_xi2_set_window_cursor (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkCursor *cursor);
|
|
|
|
static void gdk_x11_device_xi2_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_xi2_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 06:32:01 +00:00
|
|
|
|
|
|
|
static GdkGrabStatus gdk_x11_device_xi2_grab (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
gboolean owner_events,
|
|
|
|
GdkEventMask event_mask,
|
|
|
|
GdkWindow *confine_to,
|
|
|
|
GdkCursor *cursor,
|
|
|
|
guint32 time_);
|
|
|
|
static void gdk_x11_device_xi2_ungrab (GdkDevice *device,
|
|
|
|
guint32 time_);
|
|
|
|
|
|
|
|
static GdkWindow * gdk_x11_device_xi2_window_at_position (GdkDevice *device,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble *win_x,
|
|
|
|
gdouble *win_y,
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkModifierType *mask,
|
|
|
|
gboolean get_toplevel);
|
|
|
|
static void gdk_x11_device_xi2_select_window_events (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkEventMask event_mask);
|
|
|
|
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_DEVICE_ID
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_class_init (GdkX11DeviceXI2Class *klass)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
|
|
|
|
|
2012-01-23 23:49:52 +00:00
|
|
|
object_class->finalize = gdk_x11_device_xi2_finalize;
|
2010-12-21 06:32:01 +00:00
|
|
|
object_class->get_property = gdk_x11_device_xi2_get_property;
|
|
|
|
object_class->set_property = gdk_x11_device_xi2_set_property;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
device_class->get_state = gdk_x11_device_xi2_get_state;
|
|
|
|
device_class->set_window_cursor = gdk_x11_device_xi2_set_window_cursor;
|
|
|
|
device_class->warp = gdk_x11_device_xi2_warp;
|
|
|
|
device_class->query_state = gdk_x11_device_xi2_query_state;
|
|
|
|
device_class->grab = gdk_x11_device_xi2_grab;
|
|
|
|
device_class->ungrab = gdk_x11_device_xi2_ungrab;
|
|
|
|
device_class->window_at_position = gdk_x11_device_xi2_window_at_position;
|
|
|
|
device_class->select_window_events = gdk_x11_device_xi2_select_window_events;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
2010-12-21 06:32:01 +00:00
|
|
|
PROP_DEVICE_ID,
|
|
|
|
g_param_spec_int ("device-id",
|
2010-05-25 22:38:44 +00:00
|
|
|
P_("Device ID"),
|
|
|
|
P_("Device identifier"),
|
|
|
|
0, G_MAXINT, 0,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_init (GdkX11DeviceXI2 *device)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2012-01-23 23:49:52 +00:00
|
|
|
device->scroll_valuators = g_array_new (FALSE, FALSE, sizeof (ScrollValuator));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_x11_device_xi2_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GdkX11DeviceXI2 *device = GDK_X11_DEVICE_XI2 (object);
|
|
|
|
|
|
|
|
g_array_free (device->scroll_valuators, TRUE);
|
2015-03-02 17:19:16 +00:00
|
|
|
g_free (device->last_axes);
|
2012-01-23 23:49:52 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gdk_x11_device_xi2_parent_class)->finalize (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DEVICE_ID:
|
2010-12-21 06:32:01 +00:00
|
|
|
g_value_set_int (value, device_xi2->device_id);
|
2010-05-25 22:38:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DEVICE_ID:
|
2010-12-21 06:32:01 +00:00
|
|
|
device_xi2->device_id = g_value_get_int (value);
|
2010-05-25 22:38:44 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_get_state (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
gdouble *axes,
|
|
|
|
GdkModifierType *mask)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (axes)
|
|
|
|
{
|
2011-02-27 14:06:41 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
XIDeviceInfo *info;
|
|
|
|
gint i, j, ndevices;
|
|
|
|
|
|
|
|
display = gdk_device_get_display (device);
|
|
|
|
|
2011-11-30 05:16:43 +00:00
|
|
|
gdk_x11_display_error_trap_push (display);
|
2011-02-27 14:06:41 +00:00
|
|
|
info = XIQueryDevice (GDK_DISPLAY_XDISPLAY (display),
|
|
|
|
device_xi2->device_id, &ndevices);
|
2011-11-30 05:16:43 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-11-30 05:16:43 +00:00
|
|
|
for (i = 0, j = 0; info && i < info->num_classes; i++)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
XIAnyClassInfo *class_info = info->classes[i];
|
|
|
|
GdkAxisUse use;
|
|
|
|
gdouble value;
|
|
|
|
|
|
|
|
if (class_info->type != XIValuatorClass)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
value = ((XIValuatorClassInfo *) class_info)->value;
|
2011-04-08 14:23:39 +00:00
|
|
|
use = gdk_device_get_axis_use (device, j);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
switch (use)
|
|
|
|
{
|
|
|
|
case GDK_AXIS_X:
|
|
|
|
case GDK_AXIS_Y:
|
|
|
|
case GDK_AXIS_IGNORE:
|
2010-11-23 19:25:13 +00:00
|
|
|
if (gdk_device_get_mode (device) == GDK_MODE_WINDOW)
|
2010-05-25 22:38:44 +00:00
|
|
|
_gdk_device_translate_window_coord (device, window, j, value, &axes[j]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint root_x, root_y;
|
|
|
|
|
|
|
|
/* FIXME: Maybe root coords chaching should happen here */
|
|
|
|
gdk_window_get_origin (window, &root_x, &root_y);
|
|
|
|
_gdk_device_translate_screen_coord (device, window,
|
|
|
|
root_x, root_y,
|
|
|
|
j, value,
|
|
|
|
&axes[j]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_gdk_device_translate_axis (device, j, value, &axes[j]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
|
2011-11-30 05:16:43 +00:00
|
|
|
if (info)
|
|
|
|
XIFreeDeviceInfo (info);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mask)
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_query_state (device, window,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
|
|
|
NULL, NULL,
|
|
|
|
mask);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_set_window_cursor (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkCursor *cursor)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* Non-master devices don't have a cursor */
|
|
|
|
if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_MASTER)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (cursor)
|
2010-12-21 06:32:01 +00:00
|
|
|
XIDefineCursor (GDK_WINDOW_XDISPLAY (window),
|
|
|
|
device_xi2->device_id,
|
|
|
|
GDK_WINDOW_XID (window),
|
|
|
|
gdk_x11_cursor_get_xcursor (cursor));
|
2010-05-25 22:38:44 +00:00
|
|
|
else
|
|
|
|
XIUndefineCursor (GDK_WINDOW_XDISPLAY (window),
|
2010-12-21 06:32:01 +00:00
|
|
|
device_xi2->device_id,
|
2010-11-22 16:06:46 +00:00
|
|
|
GDK_WINDOW_XID (window));
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_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
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
|
2010-05-25 22:38:44 +00:00
|
|
|
Window dest;
|
|
|
|
|
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
|
|
|
|
|
|
|
XIWarpPointer (GDK_SCREEN_XDISPLAY (screen),
|
2010-12-21 06:32:01 +00:00
|
|
|
device_xi2->device_id,
|
2010-05-25 22:38:44 +00:00
|
|
|
None, dest,
|
2013-06-20 09:40:07 +00:00
|
|
|
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 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_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 06:32:01 +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-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
|
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;
|
|
|
|
gdouble xroot_x, xroot_y, xwin_x, xwin_y;
|
|
|
|
XIButtonState button_state;
|
|
|
|
XIModifierState mod_state;
|
|
|
|
XIGroupState group_state;
|
|
|
|
|
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
|
|
|
|
2013-05-17 12:28:04 +00:00
|
|
|
if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_SLAVE)
|
|
|
|
{
|
|
|
|
GdkDevice *master = gdk_device_get_associated_device (device);
|
|
|
|
|
|
|
|
if (master)
|
|
|
|
_gdk_device_query_state (master, window, root_window, child_window,
|
|
|
|
root_x, root_y, win_x, win_y, mask);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-09 17:36:11 +00:00
|
|
|
if (!GDK_X11_DISPLAY (display)->trusted_client ||
|
|
|
|
!XIQueryPointer (GDK_WINDOW_XDISPLAY (window),
|
|
|
|
device_xi2->device_id,
|
|
|
|
GDK_WINDOW_XID (window),
|
|
|
|
&xroot_window,
|
|
|
|
&xchild_window,
|
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
|
|
|
&button_state,
|
|
|
|
&mod_state,
|
|
|
|
&group_state))
|
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);
|
2010-12-21 06:32:01 +00:00
|
|
|
XIQueryPointer (xdisplay, device_xi2->device_id,
|
2010-12-13 22:43:10 +00:00
|
|
|
w,
|
|
|
|
&xroot_window,
|
|
|
|
&xchild_window,
|
2010-12-21 06:32:01 +00:00
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
2010-12-13 22:43:10 +00:00
|
|
|
&button_state,
|
|
|
|
&mod_state,
|
|
|
|
&group_state);
|
|
|
|
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 = 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 = 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 = 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 = xwin_y / impl->window_scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (mask)
|
2011-02-05 02:01:52 +00:00
|
|
|
*mask = _gdk_x11_device_xi2_translate_state (&mod_state, &button_state, &group_state);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-01-30 04:26:34 +00:00
|
|
|
free (button_state.mask);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GdkGrabStatus
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_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
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
|
2012-03-01 05:56:51 +00:00
|
|
|
GdkX11DeviceManagerXI2 *device_manager_xi2;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
XIEventMask mask;
|
|
|
|
Window xwindow;
|
|
|
|
Cursor xcursor;
|
2010-12-10 17:13:25 +00:00
|
|
|
gint status;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
display = gdk_device_get_display (device);
|
2015-12-16 18:20:28 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2012-03-01 05:56:51 +00:00
|
|
|
device_manager_xi2 = GDK_X11_DEVICE_MANAGER_XI2 (gdk_display_get_device_manager (display));
|
2015-12-16 18:20:28 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* FIXME: confine_to is actually unused */
|
|
|
|
|
|
|
|
xwindow = GDK_WINDOW_XID (window);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
mask.deviceid = device_xi2->device_id;
|
2012-03-01 05:56:51 +00:00
|
|
|
mask.mask = _gdk_x11_device_xi2_translate_event_mask (device_manager_xi2,
|
|
|
|
event_mask,
|
|
|
|
&mask.mask_len);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-10 17:13:25 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
2016-02-29 02:29:35 +00:00
|
|
|
if (GDK_DEBUG_CHECK (NOGRABS))
|
2010-12-10 17:13:25 +00:00
|
|
|
status = GrabSuccess;
|
|
|
|
else
|
|
|
|
#endif
|
2010-05-25 22:38:44 +00:00
|
|
|
status = XIGrabDevice (GDK_DISPLAY_XDISPLAY (display),
|
2010-12-21 06:32:01 +00:00
|
|
|
device_xi2->device_id,
|
2010-05-25 22:38:44 +00:00
|
|
|
xwindow,
|
|
|
|
time_,
|
|
|
|
xcursor,
|
|
|
|
GrabModeAsync, GrabModeAsync,
|
|
|
|
owner_events,
|
|
|
|
&mask);
|
|
|
|
|
|
|
|
g_free (mask.mask);
|
|
|
|
|
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 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_ungrab (GdkDevice *device,
|
|
|
|
guint32 time_)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
|
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-12-21 06:32:01 +00:00
|
|
|
XIUngrabDevice (GDK_DISPLAY_XDISPLAY (display), device_xi2->device_id, time_);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
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 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_window_at_position (GdkDevice *device,
|
2013-07-03 09:52:58 +00:00
|
|
|
gdouble *win_x,
|
|
|
|
gdouble *win_y,
|
2010-12-21 06:32:01 +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-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
GdkScreen *screen;
|
|
|
|
Display *xdisplay;
|
|
|
|
GdkWindow *window;
|
|
|
|
Window xwindow, root, child, last = None;
|
|
|
|
gdouble xroot_x, xroot_y, xwin_x, xwin_y;
|
2011-01-23 22:19:30 +00:00
|
|
|
XIButtonState button_state = { 0 };
|
2010-05-25 22:38:44 +00:00
|
|
|
XIModifierState mod_state;
|
|
|
|
XIGroupState group_state;
|
2015-06-30 17:04:13 +00:00
|
|
|
Bool retval;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
display = gdk_device_get_display (device);
|
|
|
|
screen = gdk_display_get_default_screen (display);
|
|
|
|
|
2015-06-30 17:04:13 +00:00
|
|
|
gdk_x11_display_error_trap_push (display);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
XIQueryPointer (xdisplay,
|
2010-12-21 06:32:01 +00:00
|
|
|
device_xi2->device_id,
|
2010-12-13 22:43:10 +00:00
|
|
|
xwindow,
|
|
|
|
&root, &child,
|
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
|
|
|
&button_state,
|
|
|
|
&mod_state,
|
|
|
|
&group_state);
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/* 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);
|
|
|
|
xwindow = GDK_WINDOW_XID (window);
|
|
|
|
|
|
|
|
/* Free previous button mask, if any */
|
|
|
|
g_free (button_state.mask);
|
|
|
|
|
2015-06-30 17:04:13 +00:00
|
|
|
retval = XIQueryPointer (xdisplay,
|
|
|
|
device_xi2->device_id,
|
|
|
|
xwindow,
|
|
|
|
&root, &child,
|
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
|
|
|
&button_state,
|
|
|
|
&mod_state,
|
|
|
|
&group_state);
|
|
|
|
if (!retval)
|
2013-04-04 14:22:12 +00:00
|
|
|
continue;
|
2015-06-30 17:04:13 +00:00
|
|
|
|
2013-04-04 14:22:12 +00:00
|
|
|
if (child != None)
|
|
|
|
{
|
|
|
|
pointer_window = child;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gdk_window_get_geometry (window, NULL, NULL, &width, &height);
|
|
|
|
if (xwin_x >= 0 && xwin_y >= 0 && xwin_x < width && xwin_y < height)
|
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;
|
2011-01-23 22:19:30 +00:00
|
|
|
|
2013-04-04 14:22:12 +00:00
|
|
|
free (button_state.mask);
|
2011-01-23 22:19:30 +00:00
|
|
|
|
2013-04-04 14:22:12 +00:00
|
|
|
w = XCreateWindow (xdisplay, xwindow, (int)xwin_x, (int)xwin_y, 1, 1, 0,
|
|
|
|
CopyFromParent, InputOnly, CopyFromParent,
|
|
|
|
0, &attributes);
|
|
|
|
XMapWindow (xdisplay, w);
|
2010-12-13 22:43:10 +00:00
|
|
|
XIQueryPointer (xdisplay,
|
2010-12-21 06:32:01 +00:00
|
|
|
device_xi2->device_id,
|
2010-12-13 22:43:10 +00:00
|
|
|
xwindow,
|
|
|
|
&root, &child,
|
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
|
|
|
&button_state,
|
|
|
|
&mod_state,
|
|
|
|
&group_state);
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (toplevels);
|
|
|
|
if (pointer_window != None)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xwindow = pointer_window;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
while (xwindow)
|
|
|
|
{
|
|
|
|
last = xwindow;
|
2011-01-30 04:26:34 +00:00
|
|
|
free (button_state.mask);
|
2011-01-23 22:19:30 +00:00
|
|
|
|
2015-06-30 17:04:13 +00:00
|
|
|
retval = XIQueryPointer (xdisplay,
|
|
|
|
device_xi2->device_id,
|
|
|
|
xwindow,
|
|
|
|
&root, &xwindow,
|
|
|
|
&xroot_x, &xroot_y,
|
|
|
|
&xwin_x, &xwin_y,
|
|
|
|
&button_state,
|
|
|
|
&mod_state,
|
|
|
|
&group_state);
|
|
|
|
if (!retval)
|
2010-12-13 22:43:10 +00:00
|
|
|
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-05-25 22:38:44 +00:00
|
|
|
GDK_WINDOW_TYPE (window) != GDK_WINDOW_FOREIGN)
|
|
|
|
{
|
|
|
|
xwindow = last;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_x11_display_ungrab (display);
|
|
|
|
|
2015-06-30 17:04:13 +00:00
|
|
|
if (gdk_x11_display_error_trap_pop (display) == 0)
|
|
|
|
{
|
|
|
|
window = gdk_x11_window_lookup_for_display (display, last);
|
|
|
|
impl = NULL;
|
|
|
|
if (window)
|
|
|
|
impl = GDK_WINDOW_IMPL_X11 (window->impl);
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
*mask = _gdk_x11_device_xi2_translate_state (&mod_state, &button_state, &group_state);
|
|
|
|
|
|
|
|
free (button_state.mask);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
window = NULL;
|
|
|
|
|
|
|
|
if (mask)
|
|
|
|
*mask = 0;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (win_x)
|
2013-07-03 09:52:58 +00:00
|
|
|
*win_x = (window) ? (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) ? (xwin_y / impl->window_scale) : -1;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-01-23 22:19:30 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_xi2_select_window_events (GdkDevice *device,
|
|
|
|
GdkWindow *window,
|
|
|
|
GdkEventMask event_mask)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceXI2 *device_xi2 = GDK_X11_DEVICE_XI2 (device);
|
2012-03-01 05:56:51 +00:00
|
|
|
GdkX11DeviceManagerXI2 *device_manager_xi2;
|
|
|
|
GdkDisplay *display;
|
2010-05-25 22:38:44 +00:00
|
|
|
XIEventMask evmask;
|
|
|
|
|
2012-03-01 05:56:51 +00:00
|
|
|
display = gdk_device_get_display (device);
|
2015-12-16 18:20:28 +00:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2012-03-01 05:56:51 +00:00
|
|
|
device_manager_xi2 = GDK_X11_DEVICE_MANAGER_XI2 (gdk_display_get_device_manager (display));
|
2015-12-16 18:20:28 +00:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
evmask.deviceid = device_xi2->device_id;
|
2012-03-01 05:56:51 +00:00
|
|
|
evmask.mask = _gdk_x11_device_xi2_translate_event_mask (device_manager_xi2,
|
|
|
|
event_mask,
|
|
|
|
&evmask.mask_len);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
XISelectEvents (GDK_WINDOW_XDISPLAY (window),
|
2010-11-22 16:06:46 +00:00
|
|
|
GDK_WINDOW_XID (window),
|
2010-05-25 22:38:44 +00:00
|
|
|
&evmask, 1);
|
|
|
|
|
|
|
|
g_free (evmask.mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
guchar *
|
2012-03-01 05:56:51 +00:00
|
|
|
_gdk_x11_device_xi2_translate_event_mask (GdkX11DeviceManagerXI2 *device_manager_xi2,
|
|
|
|
GdkEventMask event_mask,
|
|
|
|
gint *len)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
guchar *mask;
|
2012-03-01 05:56:51 +00:00
|
|
|
gint minor;
|
|
|
|
|
|
|
|
g_object_get (device_manager_xi2, "minor", &minor, NULL);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
*len = XIMaskLen (XI_LASTEVENT);
|
|
|
|
mask = g_new0 (guchar, *len);
|
|
|
|
|
|
|
|
if (event_mask & GDK_POINTER_MOTION_MASK ||
|
|
|
|
event_mask & GDK_POINTER_MOTION_HINT_MASK)
|
|
|
|
XISetMask (mask, XI_Motion);
|
|
|
|
|
|
|
|
if (event_mask & GDK_BUTTON_MOTION_MASK ||
|
|
|
|
event_mask & GDK_BUTTON1_MOTION_MASK ||
|
|
|
|
event_mask & GDK_BUTTON2_MOTION_MASK ||
|
|
|
|
event_mask & GDK_BUTTON3_MOTION_MASK)
|
|
|
|
{
|
|
|
|
XISetMask (mask, XI_ButtonPress);
|
|
|
|
XISetMask (mask, XI_ButtonRelease);
|
|
|
|
XISetMask (mask, XI_Motion);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event_mask & GDK_SCROLL_MASK)
|
|
|
|
{
|
|
|
|
XISetMask (mask, XI_ButtonPress);
|
|
|
|
XISetMask (mask, XI_ButtonRelease);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event_mask & GDK_BUTTON_PRESS_MASK)
|
|
|
|
XISetMask (mask, XI_ButtonPress);
|
|
|
|
|
|
|
|
if (event_mask & GDK_BUTTON_RELEASE_MASK)
|
|
|
|
XISetMask (mask, XI_ButtonRelease);
|
|
|
|
|
|
|
|
if (event_mask & GDK_KEY_PRESS_MASK)
|
|
|
|
XISetMask (mask, XI_KeyPress);
|
|
|
|
|
|
|
|
if (event_mask & GDK_KEY_RELEASE_MASK)
|
|
|
|
XISetMask (mask, XI_KeyRelease);
|
|
|
|
|
|
|
|
if (event_mask & GDK_ENTER_NOTIFY_MASK)
|
|
|
|
XISetMask (mask, XI_Enter);
|
|
|
|
|
|
|
|
if (event_mask & GDK_LEAVE_NOTIFY_MASK)
|
|
|
|
XISetMask (mask, XI_Leave);
|
|
|
|
|
|
|
|
if (event_mask & GDK_FOCUS_CHANGE_MASK)
|
|
|
|
{
|
|
|
|
XISetMask (mask, XI_FocusIn);
|
|
|
|
XISetMask (mask, XI_FocusOut);
|
|
|
|
}
|
|
|
|
|
2012-03-01 05:56:51 +00:00
|
|
|
#ifdef XINPUT_2_2
|
|
|
|
/* XInput 2.2 includes multitouch support */
|
|
|
|
if (minor >= 2 &&
|
|
|
|
event_mask & GDK_TOUCH_MASK)
|
|
|
|
{
|
|
|
|
XISetMask (mask, XI_TouchBegin);
|
|
|
|
XISetMask (mask, XI_TouchUpdate);
|
|
|
|
XISetMask (mask, XI_TouchEnd);
|
|
|
|
}
|
|
|
|
#endif /* XINPUT_2_2 */
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint
|
2010-12-21 06:32:01 +00:00
|
|
|
_gdk_x11_device_xi2_translate_state (XIModifierState *mods_state,
|
2011-02-05 02:01:52 +00:00
|
|
|
XIButtonState *buttons_state,
|
|
|
|
XIGroupState *group_state)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
guint state = 0;
|
|
|
|
|
|
|
|
if (mods_state)
|
2012-02-29 16:18:57 +00:00
|
|
|
state = mods_state->effective;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (buttons_state)
|
|
|
|
{
|
|
|
|
gint len, i;
|
|
|
|
|
2015-05-02 15:51:38 +00:00
|
|
|
/* We're only interested in the first 3 buttons */
|
|
|
|
len = MIN (3, buttons_state->mask_len * 8);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2015-05-02 15:51:38 +00:00
|
|
|
for (i = 1; i <= len; i++)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
if (!XIMaskIsSet (buttons_state->mask, i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
state |= GDK_BUTTON1_MASK;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
state |= GDK_BUTTON2_MASK;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
state |= GDK_BUTTON3_MASK;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-05 02:08:41 +00:00
|
|
|
if (group_state)
|
2012-02-29 16:15:10 +00:00
|
|
|
state |= (group_state->effective) << 13;
|
2011-02-05 02:08:41 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
return state;
|
|
|
|
}
|
2011-02-12 00:27:40 +00:00
|
|
|
|
2012-01-23 23:49:52 +00:00
|
|
|
void
|
|
|
|
_gdk_x11_device_xi2_add_scroll_valuator (GdkX11DeviceXI2 *device,
|
|
|
|
guint n_valuator,
|
2012-03-05 00:12:27 +00:00
|
|
|
GdkScrollDirection direction,
|
|
|
|
gdouble increment)
|
2012-01-23 23:49:52 +00:00
|
|
|
{
|
|
|
|
ScrollValuator scroll;
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_X11_DEVICE_XI2 (device));
|
|
|
|
g_return_if_fail (n_valuator < gdk_device_get_n_axes (GDK_DEVICE (device)));
|
|
|
|
|
|
|
|
scroll.n_valuator = n_valuator;
|
|
|
|
scroll.direction = direction;
|
2015-07-15 19:19:25 +00:00
|
|
|
scroll.last_value_valid = FALSE;
|
2012-03-05 00:12:27 +00:00
|
|
|
scroll.increment = increment;
|
2012-01-23 23:49:52 +00:00
|
|
|
|
|
|
|
g_array_append_val (device->scroll_valuators, scroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_gdk_x11_device_xi2_get_scroll_delta (GdkX11DeviceXI2 *device,
|
|
|
|
guint n_valuator,
|
|
|
|
gdouble valuator_value,
|
|
|
|
GdkScrollDirection *direction_ret,
|
|
|
|
gdouble *delta_ret)
|
|
|
|
{
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GDK_IS_X11_DEVICE_XI2 (device), FALSE);
|
|
|
|
g_return_val_if_fail (n_valuator < gdk_device_get_n_axes (GDK_DEVICE (device)), FALSE);
|
|
|
|
|
|
|
|
for (i = 0; i < device->scroll_valuators->len; i++)
|
|
|
|
{
|
|
|
|
ScrollValuator *scroll;
|
|
|
|
|
|
|
|
scroll = &g_array_index (device->scroll_valuators, ScrollValuator, i);
|
|
|
|
|
|
|
|
if (scroll->n_valuator == n_valuator)
|
|
|
|
{
|
|
|
|
if (direction_ret)
|
|
|
|
*direction_ret = scroll->direction;
|
|
|
|
|
|
|
|
if (delta_ret)
|
|
|
|
*delta_ret = 0;
|
|
|
|
|
2015-07-15 19:19:25 +00:00
|
|
|
if (scroll->last_value_valid)
|
|
|
|
{
|
|
|
|
if (delta_ret)
|
|
|
|
*delta_ret = (valuator_value - scroll->last_value) / scroll->increment;
|
2012-01-23 23:49:52 +00:00
|
|
|
|
2015-07-15 19:19:25 +00:00
|
|
|
scroll->last_value = valuator_value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
scroll->last_value = valuator_value;
|
|
|
|
scroll->last_value_valid = TRUE;
|
|
|
|
}
|
2012-01-23 23:49:52 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-07-15 19:19:25 +00:00
|
|
|
_gdk_device_xi2_reset_scroll_valuators (GdkX11DeviceXI2 *device)
|
2012-01-23 23:49:52 +00:00
|
|
|
{
|
2015-07-15 19:19:25 +00:00
|
|
|
guint i;
|
2012-01-23 23:49:52 +00:00
|
|
|
|
|
|
|
for (i = 0; i < device->scroll_valuators->len; i++)
|
|
|
|
{
|
|
|
|
ScrollValuator *scroll;
|
|
|
|
|
|
|
|
scroll = &g_array_index (device->scroll_valuators, ScrollValuator, i);
|
2015-07-15 19:19:25 +00:00
|
|
|
scroll->last_value_valid = FALSE;
|
2012-01-23 23:49:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:32:54 +00:00
|
|
|
void
|
|
|
|
_gdk_device_xi2_unset_scroll_valuators (GdkX11DeviceXI2 *device)
|
|
|
|
{
|
|
|
|
if (device->scroll_valuators->len > 0)
|
|
|
|
g_array_remove_range (device->scroll_valuators, 0,
|
|
|
|
device->scroll_valuators->len);
|
|
|
|
}
|
|
|
|
|
2011-07-14 15:43:59 +00:00
|
|
|
gint
|
|
|
|
_gdk_x11_device_xi2_get_id (GdkX11DeviceXI2 *device)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GDK_IS_X11_DEVICE_XI2 (device), 0);
|
|
|
|
|
|
|
|
return device->device_id;
|
|
|
|
}
|
2015-03-02 17:19:16 +00:00
|
|
|
|
|
|
|
gdouble
|
|
|
|
gdk_x11_device_xi2_get_last_axis_value (GdkX11DeviceXI2 *device,
|
|
|
|
gint n_axis)
|
|
|
|
{
|
|
|
|
if (n_axis >= gdk_device_get_n_axes (GDK_DEVICE (device)))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!device->last_axes)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return device->last_axes[n_axis];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gdk_x11_device_xi2_store_axes (GdkX11DeviceXI2 *device,
|
|
|
|
gdouble *axes,
|
|
|
|
gint n_axes)
|
|
|
|
{
|
|
|
|
g_free (device->last_axes);
|
|
|
|
|
|
|
|
if (axes && n_axes)
|
|
|
|
device->last_axes = g_memdup (axes, sizeof (gdouble) * n_axes);
|
|
|
|
else
|
|
|
|
device->last_axes = NULL;
|
|
|
|
}
|