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 "gdkx11devicemanager-xi2.h"
|
|
|
|
#include "gdkx11device-xi2.h"
|
2010-10-15 02:05:51 +00:00
|
|
|
|
2010-12-13 19:05:59 +00:00
|
|
|
#include "gdkdeviceprivate.h"
|
2016-04-09 19:20:07 +00:00
|
|
|
#include "gdkdevicetoolprivate.h"
|
2010-12-13 19:05:59 +00:00
|
|
|
#include "gdkdisplayprivate.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
#include "gdkeventtranslator.h"
|
2020-04-07 17:12:58 +00:00
|
|
|
#include "gdkkeys-x11.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-21 16:27:27 +00:00
|
|
|
#include "gdkintl.h"
|
|
|
|
#include "gdkkeysyms.h"
|
2012-03-01 05:56:51 +00:00
|
|
|
#include "gdkinternals.h"
|
2015-11-26 18:53:36 +00:00
|
|
|
#include "gdkseatdefaultprivate.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 19:17:02 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <X11/extensions/XInput2.h>
|
2014-11-18 13:25:51 +00:00
|
|
|
#include <X11/Xatom.h>
|
2010-12-21 19:17:02 +00:00
|
|
|
|
2010-10-15 02:05:51 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
#ifdef G_ENABLE_DEBUG
|
|
|
|
static const char notify_modes[][19] = {
|
|
|
|
"NotifyNormal",
|
|
|
|
"NotifyGrab",
|
|
|
|
"NotifyUngrab",
|
|
|
|
"NotifyWhileGrabbed"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char notify_details[][23] = {
|
|
|
|
"NotifyAncestor",
|
|
|
|
"NotifyVirtual",
|
|
|
|
"NotifyInferior",
|
|
|
|
"NotifyNonlinear",
|
|
|
|
"NotifyNonlinearVirtual",
|
|
|
|
"NotifyPointer",
|
|
|
|
"NotifyPointerRoot",
|
|
|
|
"NotifyDetailNone"
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define HAS_FOCUS(toplevel) \
|
|
|
|
((toplevel)->has_focus || (toplevel)->has_pointer_focus)
|
|
|
|
|
2018-12-14 03:58:19 +00:00
|
|
|
static const char *wacom_type_atoms[] = {
|
|
|
|
"STYLUS",
|
|
|
|
"CURSOR",
|
|
|
|
"ERASER",
|
|
|
|
"PAD",
|
|
|
|
"TOUCH"
|
|
|
|
};
|
|
|
|
#define N_WACOM_TYPE_ATOMS G_N_ELEMENTS (wacom_type_atoms)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
WACOM_TYPE_STYLUS,
|
|
|
|
WACOM_TYPE_CURSOR,
|
|
|
|
WACOM_TYPE_ERASER,
|
|
|
|
WACOM_TYPE_PAD,
|
|
|
|
WACOM_TYPE_TOUCH,
|
|
|
|
};
|
|
|
|
|
2010-12-21 16:27:27 +00:00
|
|
|
struct _GdkX11DeviceManagerXI2
|
|
|
|
{
|
2019-05-14 22:18:38 +00:00
|
|
|
GObject parent_object;
|
2010-12-21 16:27:27 +00:00
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
GdkDisplay *display;
|
2010-12-21 16:27:27 +00:00
|
|
|
GHashTable *id_table;
|
|
|
|
|
2011-01-16 13:47:59 +00:00
|
|
|
GList *devices;
|
2010-12-21 16:27:27 +00:00
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
int opcode;
|
|
|
|
int major;
|
|
|
|
int minor;
|
2010-12-21 16:27:27 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GdkX11DeviceManagerXI2Class
|
|
|
|
{
|
2019-05-14 22:18:38 +00:00
|
|
|
GObjectClass parent_class;
|
2010-12-21 16:27:27 +00:00
|
|
|
};
|
|
|
|
|
2011-02-12 00:27:40 +00:00
|
|
|
static void gdk_x11_device_manager_xi2_event_translator_init (GdkEventTranslatorIface *iface);
|
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GdkX11DeviceManagerXI2, gdk_x11_device_manager_xi2, G_TYPE_OBJECT,
|
2011-02-12 00:27:40 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GDK_TYPE_EVENT_TRANSLATOR,
|
|
|
|
gdk_x11_device_manager_xi2_event_translator_init))
|
|
|
|
|
2010-12-21 16:27:27 +00:00
|
|
|
static void gdk_x11_device_manager_xi2_constructed (GObject *object);
|
|
|
|
static void gdk_x11_device_manager_xi2_dispose (GObject *object);
|
|
|
|
static void gdk_x11_device_manager_xi2_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gdk_x11_device_manager_xi2_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
static GdkEvent * gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
|
|
|
|
GdkDisplay *display,
|
|
|
|
const XEvent *xevent);
|
2010-12-21 06:32:01 +00:00
|
|
|
static GdkEventMask gdk_x11_device_manager_xi2_get_handled_events (GdkEventTranslator *translator);
|
2018-03-20 11:05:26 +00:00
|
|
|
static void gdk_x11_device_manager_xi2_select_surface_events (GdkEventTranslator *translator,
|
2010-12-21 06:32:01 +00:00
|
|
|
Window window,
|
|
|
|
GdkEventMask event_mask);
|
2018-03-20 14:14:10 +00:00
|
|
|
static GdkSurface * gdk_x11_device_manager_xi2_get_surface (GdkEventTranslator *translator,
|
2017-12-12 23:39:32 +00:00
|
|
|
const XEvent *xevent);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 16:27:27 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2019-05-14 22:18:38 +00:00
|
|
|
PROP_DISPLAY,
|
2011-12-24 13:33:24 +00:00
|
|
|
PROP_OPCODE,
|
|
|
|
PROP_MAJOR,
|
|
|
|
PROP_MINOR
|
2010-12-21 16:27:27 +00:00
|
|
|
};
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_manager_xi2_class_init (GdkX11DeviceManagerXI2Class *klass)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
object_class->constructed = gdk_x11_device_manager_xi2_constructed;
|
|
|
|
object_class->dispose = gdk_x11_device_manager_xi2_dispose;
|
2010-12-21 16:27:27 +00:00
|
|
|
object_class->set_property = gdk_x11_device_manager_xi2_set_property;
|
|
|
|
object_class->get_property = gdk_x11_device_manager_xi2_get_property;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_DISPLAY,
|
|
|
|
g_param_spec_object ("display",
|
|
|
|
"Display",
|
|
|
|
"Display for the device manager",
|
|
|
|
GDK_TYPE_DISPLAY,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2010-12-21 16:27:27 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_OPCODE,
|
|
|
|
g_param_spec_int ("opcode",
|
|
|
|
P_("Opcode"),
|
|
|
|
P_("Opcode for XInput2 requests"),
|
|
|
|
0, G_MAXINT, 0,
|
2017-11-18 02:38:08 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2011-12-24 13:33:24 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MAJOR,
|
|
|
|
g_param_spec_int ("major",
|
|
|
|
P_("Major"),
|
|
|
|
P_("Major version number"),
|
|
|
|
0, G_MAXINT, 0,
|
2017-11-18 02:38:08 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2011-12-24 13:33:24 +00:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MINOR,
|
|
|
|
g_param_spec_int ("minor",
|
|
|
|
P_("Minor"),
|
|
|
|
P_("Minor version number"),
|
|
|
|
0, G_MAXINT, 0,
|
2017-11-18 02:38:08 +00:00
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_manager_xi2_init (GdkX11DeviceManagerXI2 *device_manager)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
device_manager->id_table = g_hash_table_new_full (g_direct_hash,
|
|
|
|
g_direct_equal,
|
|
|
|
NULL,
|
|
|
|
(GDestroyNotify) g_object_unref);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-11-25 13:23:25 +00:00
|
|
|
_gdk_x11_device_manager_xi2_select_events (GdkX11DeviceManagerXI2 *device_manager,
|
|
|
|
Window xwindow,
|
|
|
|
XIEventMask *event_mask)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
Display *xdisplay;
|
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
display = device_manager->display;
|
2010-05-25 22:38:44 +00:00
|
|
|
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
|
|
|
|
|
|
|
XISelectEvents (xdisplay, xwindow, event_mask, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
translate_valuator_class (GdkDisplay *display,
|
|
|
|
GdkDevice *device,
|
2012-03-01 05:56:51 +00:00
|
|
|
Atom valuator_label,
|
|
|
|
gdouble min,
|
|
|
|
gdouble max,
|
|
|
|
gdouble resolution)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
static gboolean initialized = FALSE;
|
|
|
|
static Atom label_atoms [GDK_AXIS_LAST] = { 0 };
|
|
|
|
GdkAxisUse use = GDK_AXIS_IGNORE;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (!initialized)
|
|
|
|
{
|
|
|
|
label_atoms [GDK_AXIS_X] = gdk_x11_get_xatom_by_name_for_display (display, "Abs X");
|
|
|
|
label_atoms [GDK_AXIS_Y] = gdk_x11_get_xatom_by_name_for_display (display, "Abs Y");
|
|
|
|
label_atoms [GDK_AXIS_PRESSURE] = gdk_x11_get_xatom_by_name_for_display (display, "Abs Pressure");
|
|
|
|
label_atoms [GDK_AXIS_XTILT] = gdk_x11_get_xatom_by_name_for_display (display, "Abs Tilt X");
|
|
|
|
label_atoms [GDK_AXIS_YTILT] = gdk_x11_get_xatom_by_name_for_display (display, "Abs Tilt Y");
|
|
|
|
label_atoms [GDK_AXIS_WHEEL] = gdk_x11_get_xatom_by_name_for_display (display, "Abs Wheel");
|
|
|
|
initialized = TRUE;
|
|
|
|
}
|
|
|
|
|
2011-06-15 01:56:50 +00:00
|
|
|
for (i = GDK_AXIS_IGNORE; i < GDK_AXIS_LAST; i++)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2012-03-01 05:56:51 +00:00
|
|
|
if (label_atoms[i] == valuator_label)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
use = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-09 19:26:04 +00:00
|
|
|
_gdk_device_add_axis (device, use, min, max, resolution);
|
|
|
|
GDK_DISPLAY_NOTE (display, INPUT,
|
|
|
|
{
|
|
|
|
const char *label;
|
|
|
|
|
|
|
|
if (valuator_label != None)
|
|
|
|
label = gdk_x11_get_xatom_name_for_display (display, valuator_label);
|
|
|
|
else
|
|
|
|
label = NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2020-06-09 19:26:04 +00:00
|
|
|
g_message ("\n\taxis: %s %s", label, use == GDK_AXIS_IGNORE ? "(ignored)" : "(used)");
|
|
|
|
});
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
translate_device_classes (GdkDisplay *display,
|
|
|
|
GdkDevice *device,
|
|
|
|
XIAnyClassInfo **classes,
|
|
|
|
guint n_classes)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (device));
|
|
|
|
|
|
|
|
for (i = 0; i < n_classes; i++)
|
|
|
|
{
|
|
|
|
XIAnyClassInfo *class_info = classes[i];
|
|
|
|
|
|
|
|
switch (class_info->type)
|
|
|
|
{
|
|
|
|
case XIKeyClass:
|
|
|
|
{
|
2020-06-09 19:05:55 +00:00
|
|
|
/* Not used */
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XIValuatorClass:
|
2012-03-01 05:56:51 +00:00
|
|
|
{
|
|
|
|
XIValuatorClassInfo *valuator_info = (XIValuatorClassInfo *) class_info;
|
|
|
|
translate_valuator_class (display, device,
|
|
|
|
valuator_info->label,
|
|
|
|
valuator_info->min,
|
|
|
|
valuator_info->max,
|
|
|
|
valuator_info->resolution);
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
break;
|
2012-01-23 23:49:52 +00:00
|
|
|
#ifdef XINPUT_2_2
|
|
|
|
case XIScrollClass:
|
|
|
|
{
|
|
|
|
XIScrollClassInfo *scroll_info = (XIScrollClassInfo *) class_info;
|
|
|
|
GdkScrollDirection direction;
|
|
|
|
|
|
|
|
if (scroll_info->scroll_type == XIScrollTypeVertical)
|
|
|
|
direction = GDK_SCROLL_DOWN;
|
|
|
|
else
|
|
|
|
direction = GDK_SCROLL_RIGHT;
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, INPUT,
|
2012-03-05 00:12:27 +00:00
|
|
|
g_message ("\n\tscroll valuator %d: %s, increment %f",
|
2012-03-03 03:53:03 +00:00
|
|
|
scroll_info->number,
|
|
|
|
scroll_info->scroll_type == XIScrollTypeVertical
|
|
|
|
? "vertical"
|
2012-03-05 00:12:27 +00:00
|
|
|
: "horizontal",
|
|
|
|
scroll_info->increment));
|
2012-03-03 03:53:03 +00:00
|
|
|
|
2012-01-23 23:49:52 +00:00
|
|
|
_gdk_x11_device_xi2_add_scroll_valuator (GDK_X11_DEVICE_XI2 (device),
|
|
|
|
scroll_info->number,
|
2012-03-05 00:12:27 +00:00
|
|
|
direction,
|
|
|
|
scroll_info->increment);
|
2012-01-23 23:49:52 +00:00
|
|
|
}
|
2020-03-06 07:32:21 +00:00
|
|
|
break;
|
2012-01-23 23:49:52 +00:00
|
|
|
#endif /* XINPUT_2_2 */
|
2010-05-25 22:38:44 +00:00
|
|
|
default:
|
|
|
|
/* Ignore */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (device));
|
|
|
|
}
|
|
|
|
|
2012-03-01 03:00:18 +00:00
|
|
|
static gboolean
|
|
|
|
is_touch_device (XIAnyClassInfo **classes,
|
|
|
|
guint n_classes,
|
2012-02-29 05:44:51 +00:00
|
|
|
GdkInputSource *device_type,
|
2020-07-24 13:54:49 +00:00
|
|
|
int *num_touches)
|
2012-03-01 03:00:18 +00:00
|
|
|
{
|
|
|
|
#ifdef XINPUT_2_2
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < n_classes; i++)
|
|
|
|
{
|
|
|
|
XITouchClassInfo *class = (XITouchClassInfo *) classes[i];
|
|
|
|
|
|
|
|
if (class->type != XITouchClass)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (class->num_touches > 0)
|
|
|
|
{
|
|
|
|
if (class->mode == XIDirectTouch)
|
|
|
|
*device_type = GDK_SOURCE_TOUCHSCREEN;
|
|
|
|
else if (class->mode == XIDependentTouch)
|
|
|
|
*device_type = GDK_SOURCE_TOUCHPAD;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
2012-02-29 05:44:51 +00:00
|
|
|
*num_touches = class->num_touches;
|
|
|
|
|
2012-03-01 03:00:18 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-10-30 13:10:19 +00:00
|
|
|
static gboolean
|
|
|
|
has_abs_axes (GdkDisplay *display,
|
|
|
|
XIAnyClassInfo **classes,
|
|
|
|
guint n_classes)
|
|
|
|
{
|
|
|
|
gboolean has_x = FALSE, has_y = FALSE;
|
|
|
|
Atom abs_x, abs_y;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
abs_x = gdk_x11_get_xatom_by_name_for_display (display, "Abs X");
|
|
|
|
abs_y = gdk_x11_get_xatom_by_name_for_display (display, "Abs Y");
|
|
|
|
|
|
|
|
for (i = 0; i < n_classes; i++)
|
|
|
|
{
|
|
|
|
XIValuatorClassInfo *class = (XIValuatorClassInfo *) classes[i];
|
|
|
|
|
|
|
|
if (class->type != XIValuatorClass)
|
|
|
|
continue;
|
|
|
|
if (class->mode != XIModeAbsolute)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (class->label == abs_x)
|
|
|
|
has_x = TRUE;
|
|
|
|
else if (class->label == abs_y)
|
|
|
|
has_y = TRUE;
|
|
|
|
|
|
|
|
if (has_x && has_y)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (has_x && has_y);
|
|
|
|
}
|
|
|
|
|
2014-11-18 13:25:51 +00:00
|
|
|
static gboolean
|
|
|
|
get_device_ids (GdkDisplay *display,
|
|
|
|
XIDeviceInfo *info,
|
|
|
|
gchar **vendor_id,
|
|
|
|
gchar **product_id)
|
|
|
|
{
|
|
|
|
gulong nitems, bytes_after;
|
|
|
|
guint32 *data;
|
|
|
|
int rc, format;
|
2015-06-30 14:28:59 +00:00
|
|
|
Atom prop, type;
|
2014-11-18 13:25:51 +00:00
|
|
|
|
|
|
|
gdk_x11_display_error_trap_push (display);
|
|
|
|
|
2015-06-30 14:28:59 +00:00
|
|
|
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (display), "Device Product ID", True);
|
|
|
|
|
|
|
|
if (prop == None)
|
2016-08-29 19:49:24 +00:00
|
|
|
{
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
|
|
|
return 0;
|
|
|
|
}
|
2015-06-30 14:28:59 +00:00
|
|
|
|
2014-11-18 13:25:51 +00:00
|
|
|
rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display),
|
2015-06-30 14:28:59 +00:00
|
|
|
info->deviceid, prop,
|
2014-11-18 13:25:51 +00:00
|
|
|
0, 2, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
|
|
|
|
(guchar **) &data);
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
|
|
|
|
|
|
|
if (rc != Success || type != XA_INTEGER || format != 32 || nitems != 2)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (vendor_id)
|
|
|
|
*vendor_id = g_strdup_printf ("%.4x", data[0]);
|
|
|
|
if (product_id)
|
|
|
|
*product_id = g_strdup_printf ("%.4x", data[1]);
|
|
|
|
|
|
|
|
XFree (data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-02-01 11:08:04 +00:00
|
|
|
static gboolean
|
2018-03-16 07:40:40 +00:00
|
|
|
has_bool_prop (GdkDisplay *display,
|
|
|
|
XIDeviceInfo *info,
|
|
|
|
const char *prop_name)
|
2015-02-01 11:08:04 +00:00
|
|
|
{
|
|
|
|
gulong nitems, bytes_after;
|
|
|
|
guint32 *data;
|
|
|
|
int rc, format;
|
|
|
|
Atom type;
|
|
|
|
|
|
|
|
gdk_x11_display_error_trap_push (display);
|
|
|
|
|
|
|
|
rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display),
|
|
|
|
info->deviceid,
|
2018-03-16 07:40:40 +00:00
|
|
|
gdk_x11_get_xatom_by_name_for_display (display, prop_name),
|
2015-02-01 11:08:04 +00:00
|
|
|
0, 1, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
|
|
|
|
(guchar **) &data);
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
|
|
|
|
|
|
|
if (rc != Success || type != XA_INTEGER || format != 8 || nitems != 1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
XFree (data);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2018-03-16 07:40:40 +00:00
|
|
|
static gboolean
|
|
|
|
is_touchpad_device (GdkDisplay *display,
|
|
|
|
XIDeviceInfo *info)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Touchpads are heuristically recognized via XI properties that the various
|
|
|
|
* Xorg drivers expose:
|
|
|
|
* libinput: libinput Tapping Enabled
|
|
|
|
* synaptics: Synaptics Off
|
|
|
|
* cmt: Raw Touch Passthrough
|
|
|
|
*/
|
|
|
|
return has_bool_prop (display, info, "libinput Tapping Enabled") ||
|
|
|
|
has_bool_prop (display, info, "Synaptics Off") ||
|
|
|
|
has_bool_prop (display, info, "Raw Touch Passthrough");
|
|
|
|
}
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
static GdkDevice *
|
2017-11-25 13:23:25 +00:00
|
|
|
create_device (GdkX11DeviceManagerXI2 *device_manager,
|
|
|
|
GdkDisplay *display,
|
|
|
|
XIDeviceInfo *dev)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkInputSource input_source;
|
2012-03-01 03:00:18 +00:00
|
|
|
GdkInputSource touch_source;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDeviceType type;
|
|
|
|
GdkDevice *device;
|
2020-07-24 13:54:49 +00:00
|
|
|
int num_touches = 0;
|
2014-11-18 13:25:51 +00:00
|
|
|
gchar *vendor_id = NULL, *product_id = NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (dev->use == XIMasterKeyboard || dev->use == XISlaveKeyboard)
|
|
|
|
input_source = GDK_SOURCE_KEYBOARD;
|
2015-02-01 11:08:04 +00:00
|
|
|
else if (is_touchpad_device (display, dev))
|
|
|
|
input_source = GDK_SOURCE_TOUCHPAD;
|
2012-03-01 03:00:18 +00:00
|
|
|
else if (dev->use == XISlavePointer &&
|
2012-02-29 05:44:51 +00:00
|
|
|
is_touch_device (dev->classes, dev->num_classes, &touch_source, &num_touches))
|
2012-03-01 03:00:18 +00:00
|
|
|
input_source = touch_source;
|
2010-05-25 22:38:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *tmp_name;
|
|
|
|
|
|
|
|
tmp_name = g_ascii_strdown (dev->name, -1);
|
|
|
|
|
2020-06-22 21:19:35 +00:00
|
|
|
if (strstr (tmp_name, "cursor"))
|
2010-05-25 22:38:44 +00:00
|
|
|
input_source = GDK_SOURCE_CURSOR;
|
2017-06-27 21:21:05 +00:00
|
|
|
else if (strstr (tmp_name, " pad"))
|
|
|
|
input_source = GDK_SOURCE_TABLET_PAD;
|
2010-05-25 22:38:44 +00:00
|
|
|
else if (strstr (tmp_name, "wacom") ||
|
2020-06-22 21:19:35 +00:00
|
|
|
strstr (tmp_name, "pen") ||
|
|
|
|
strstr (tmp_name, "eraser"))
|
2010-05-25 22:38:44 +00:00
|
|
|
input_source = GDK_SOURCE_PEN;
|
2015-11-13 16:14:34 +00:00
|
|
|
else if (!strstr (tmp_name, "mouse") &&
|
2015-11-17 14:36:08 +00:00
|
|
|
!strstr (tmp_name, "pointer") &&
|
2016-01-12 08:29:00 +00:00
|
|
|
!strstr (tmp_name, "qemu usb tablet") &&
|
2016-02-25 02:59:44 +00:00
|
|
|
!strstr (tmp_name, "spice vdagent tablet") &&
|
2016-03-08 13:18:06 +00:00
|
|
|
!strstr (tmp_name, "virtualbox usb tablet") &&
|
2015-11-13 16:14:34 +00:00
|
|
|
has_abs_axes (display, dev->classes, dev->num_classes))
|
2015-10-30 13:10:19 +00:00
|
|
|
input_source = GDK_SOURCE_TOUCHSCREEN;
|
2016-06-01 10:58:43 +00:00
|
|
|
else if (strstr (tmp_name, "trackpoint") ||
|
|
|
|
strstr (tmp_name, "dualpoint stick"))
|
|
|
|
input_source = GDK_SOURCE_TRACKPOINT;
|
2010-05-25 22:38:44 +00:00
|
|
|
else
|
|
|
|
input_source = GDK_SOURCE_MOUSE;
|
|
|
|
|
|
|
|
g_free (tmp_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (dev->use)
|
|
|
|
{
|
|
|
|
case XIMasterKeyboard:
|
|
|
|
case XIMasterPointer:
|
2020-06-18 18:22:20 +00:00
|
|
|
type = GDK_DEVICE_TYPE_LOGICAL;
|
2010-05-25 22:38:44 +00:00
|
|
|
break;
|
|
|
|
case XISlaveKeyboard:
|
|
|
|
case XISlavePointer:
|
2020-06-18 18:22:20 +00:00
|
|
|
type = GDK_DEVICE_TYPE_PHYSICAL;
|
2010-05-25 22:38:44 +00:00
|
|
|
break;
|
|
|
|
case XIFloatingSlave:
|
|
|
|
default:
|
|
|
|
type = GDK_DEVICE_TYPE_FLOATING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, INPUT,
|
2012-02-29 05:44:51 +00:00
|
|
|
({
|
2020-06-18 18:22:20 +00:00
|
|
|
const gchar *type_names[] = { "logical", "physical", "floating" };
|
2017-03-19 13:24:54 +00:00
|
|
|
const gchar *source_names[] = { "mouse", "pen", "eraser", "cursor", "keyboard", "direct touch", "indirect touch", "trackpoint", "pad" };
|
2020-02-24 18:35:27 +00:00
|
|
|
g_message ("input device:\n\tname: %s\n\ttype: %s\n\tsource: %s\n\thas cursor: %d\n\ttouches: %d",
|
2012-02-29 05:44:51 +00:00
|
|
|
dev->name,
|
|
|
|
type_names[type],
|
|
|
|
source_names[input_source],
|
|
|
|
dev->use == XIMasterPointer,
|
|
|
|
num_touches);
|
|
|
|
}));
|
|
|
|
|
2014-11-18 13:25:51 +00:00
|
|
|
if (dev->use != XIMasterKeyboard &&
|
|
|
|
dev->use != XIMasterPointer)
|
|
|
|
get_device_ids (display, dev, &vendor_id, &product_id);
|
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
device = g_object_new (GDK_TYPE_X11_DEVICE_XI2,
|
2010-05-25 22:38:44 +00:00
|
|
|
"name", dev->name,
|
|
|
|
"type", type,
|
2020-02-24 18:35:27 +00:00
|
|
|
"source", input_source,
|
2010-05-25 22:38:44 +00:00
|
|
|
"has-cursor", (dev->use == XIMasterPointer),
|
|
|
|
"display", display,
|
|
|
|
"device-id", dev->deviceid,
|
2014-11-18 13:25:51 +00:00
|
|
|
"vendor-id", vendor_id,
|
|
|
|
"product-id", product_id,
|
2016-02-25 13:25:50 +00:00
|
|
|
"num-touches", num_touches,
|
2010-05-25 22:38:44 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
translate_device_classes (display, device, dev->classes, dev->num_classes);
|
2014-11-18 13:25:51 +00:00
|
|
|
g_free (vendor_id);
|
|
|
|
g_free (product_id);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2015-11-26 18:53:36 +00:00
|
|
|
static void
|
|
|
|
ensure_seat_for_device_pair (GdkX11DeviceManagerXI2 *device_manager,
|
|
|
|
GdkDevice *device1,
|
|
|
|
GdkDevice *device2)
|
|
|
|
{
|
|
|
|
GdkDevice *pointer, *keyboard;
|
|
|
|
GdkDisplay *display;
|
|
|
|
GdkSeat *seat;
|
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
display = device_manager->display;
|
2015-11-26 18:53:36 +00:00
|
|
|
seat = gdk_device_get_seat (device1);
|
|
|
|
|
|
|
|
if (!seat)
|
|
|
|
{
|
|
|
|
if (gdk_device_get_source (device1) == GDK_SOURCE_KEYBOARD)
|
|
|
|
{
|
|
|
|
keyboard = device1;
|
|
|
|
pointer = device2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pointer = device1;
|
|
|
|
keyboard = device2;
|
|
|
|
}
|
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
seat = gdk_seat_default_new_for_logical_pair (pointer, keyboard);
|
2015-11-26 18:53:36 +00:00
|
|
|
gdk_display_add_seat (display, seat);
|
|
|
|
g_object_unref (seat);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
static GdkDevice *
|
2010-12-21 06:32:01 +00:00
|
|
|
add_device (GdkX11DeviceManagerXI2 *device_manager,
|
|
|
|
XIDeviceInfo *dev,
|
|
|
|
gboolean emit_signal)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
GdkDevice *device;
|
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
display = device_manager->display;
|
2017-11-25 13:23:25 +00:00
|
|
|
device = create_device (device_manager, display, dev);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
g_hash_table_replace (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (dev->deviceid),
|
2010-09-19 02:57:36 +00:00
|
|
|
g_object_ref (device));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-01-16 13:47:59 +00:00
|
|
|
device_manager->devices = g_list_append (device_manager->devices, device);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (emit_signal)
|
2010-12-13 11:20:34 +00:00
|
|
|
{
|
|
|
|
if (dev->use == XISlavePointer || dev->use == XISlaveKeyboard)
|
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
GdkDevice *logical;
|
2015-11-26 18:53:36 +00:00
|
|
|
GdkSeat *seat;
|
2010-12-13 11:20:34 +00:00
|
|
|
|
|
|
|
/* The device manager is already constructed, then
|
|
|
|
* keep the hierarchy coherent for the added device.
|
|
|
|
*/
|
2020-06-18 18:22:20 +00:00
|
|
|
logical = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (dev->attachment));
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
_gdk_device_set_associated_device (device, logical);
|
|
|
|
_gdk_device_add_physical_device (logical, device);
|
2015-11-26 18:53:36 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
seat = gdk_device_get_seat (logical);
|
|
|
|
gdk_seat_default_add_physical_device (GDK_SEAT_DEFAULT (seat), device);
|
2010-12-13 11:20:34 +00:00
|
|
|
}
|
2015-11-26 18:53:36 +00:00
|
|
|
else if (dev->use == XIMasterPointer || dev->use == XIMasterKeyboard)
|
|
|
|
{
|
|
|
|
GdkDevice *relative;
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2015-11-26 18:53:36 +00:00
|
|
|
relative = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (dev->attachment));
|
|
|
|
|
|
|
|
if (relative)
|
|
|
|
{
|
|
|
|
_gdk_device_set_associated_device (device, relative);
|
|
|
|
_gdk_device_set_associated_device (relative, device);
|
|
|
|
ensure_seat_for_device_pair (device_manager, device, relative);
|
|
|
|
}
|
|
|
|
}
|
2010-12-13 11:20:34 +00:00
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2015-11-26 18:53:36 +00:00
|
|
|
static void
|
|
|
|
detach_from_seat (GdkDevice *device)
|
|
|
|
{
|
|
|
|
GdkSeat *seat = gdk_device_get_seat (device);
|
|
|
|
|
|
|
|
if (!seat)
|
|
|
|
return;
|
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_LOGICAL)
|
2015-11-26 18:53:36 +00:00
|
|
|
gdk_display_remove_seat (gdk_device_get_display (device), seat);
|
2020-06-18 18:22:20 +00:00
|
|
|
else if (gdk_device_get_device_type (device) == GDK_DEVICE_TYPE_PHYSICAL)
|
|
|
|
gdk_seat_default_remove_physical_device (GDK_SEAT_DEFAULT (seat), device);
|
2015-11-26 18:53:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
remove_device (GdkX11DeviceManagerXI2 *device_manager,
|
2020-07-24 13:54:49 +00:00
|
|
|
int device_id)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDevice *device;
|
|
|
|
|
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (device_id));
|
|
|
|
|
|
|
|
if (device)
|
|
|
|
{
|
2015-11-26 18:53:36 +00:00
|
|
|
detach_from_seat (device);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
g_hash_table_remove (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (device_id));
|
2020-01-27 00:02:29 +00:00
|
|
|
|
|
|
|
device_manager->devices = g_list_remove (device_manager->devices, device);
|
|
|
|
g_object_run_dispose (G_OBJECT (device));
|
|
|
|
g_object_unref (device);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-06-18 18:22:20 +00:00
|
|
|
relate_logical_devices (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceManagerXI2 *device_manager;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDevice *device, *relative;
|
|
|
|
|
|
|
|
device_manager = user_data;
|
|
|
|
device = g_hash_table_lookup (device_manager->id_table, key);
|
|
|
|
relative = g_hash_table_lookup (device_manager->id_table, value);
|
|
|
|
|
|
|
|
_gdk_device_set_associated_device (device, relative);
|
|
|
|
_gdk_device_set_associated_device (relative, device);
|
2015-11-26 18:53:36 +00:00
|
|
|
ensure_seat_for_device_pair (device_manager, device, relative);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2010-12-13 11:20:34 +00:00
|
|
|
static void
|
2020-06-18 18:22:20 +00:00
|
|
|
relate_physical_devices (gpointer key,
|
|
|
|
gpointer value,
|
|
|
|
gpointer user_data)
|
2010-12-13 11:20:34 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceManagerXI2 *device_manager;
|
2020-06-18 18:22:20 +00:00
|
|
|
GdkDevice *physical, *logical;
|
2015-11-26 18:53:36 +00:00
|
|
|
GdkSeat *seat;
|
2010-12-13 11:20:34 +00:00
|
|
|
|
|
|
|
device_manager = user_data;
|
2020-06-18 18:22:20 +00:00
|
|
|
physical = g_hash_table_lookup (device_manager->id_table, key);
|
|
|
|
logical = g_hash_table_lookup (device_manager->id_table, value);
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
_gdk_device_set_associated_device (physical, logical);
|
|
|
|
_gdk_device_add_physical_device (logical, physical);
|
2015-11-26 18:53:36 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
seat = gdk_device_get_seat (logical);
|
|
|
|
gdk_seat_default_add_physical_device (GDK_SEAT_DEFAULT (seat), physical);
|
2010-12-13 11:20:34 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_manager_xi2_constructed (GObject *object)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceManagerXI2 *device_manager;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDisplay *display;
|
2020-06-18 18:22:20 +00:00
|
|
|
GHashTable *logical_devices, *physical_devices;
|
2010-05-25 22:38:44 +00:00
|
|
|
Display *xdisplay;
|
|
|
|
XIDeviceInfo *info, *dev;
|
|
|
|
int ndevices, i;
|
|
|
|
XIEventMask event_mask;
|
|
|
|
unsigned char mask[2] = { 0 };
|
|
|
|
|
2013-06-29 23:21:28 +00:00
|
|
|
G_OBJECT_CLASS (gdk_x11_device_manager_xi2_parent_class)->constructed (object);
|
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
device_manager = GDK_X11_DEVICE_MANAGER_XI2 (object);
|
2019-05-14 22:18:38 +00:00
|
|
|
display = device_manager->display;
|
2010-05-25 22:38:44 +00:00
|
|
|
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2011-12-24 13:33:24 +00:00
|
|
|
g_assert (device_manager->major == 2);
|
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
logical_devices = g_hash_table_new (NULL, NULL);
|
|
|
|
physical_devices = g_hash_table_new (NULL, NULL);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
info = XIQueryDevice (xdisplay, XIAllDevices, &ndevices);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* Initialize devices list */
|
|
|
|
for (i = 0; i < ndevices; i++)
|
|
|
|
{
|
|
|
|
dev = &info[i];
|
2011-09-06 17:22:59 +00:00
|
|
|
|
|
|
|
if (!dev->enabled)
|
|
|
|
continue;
|
|
|
|
|
2011-01-23 23:50:09 +00:00
|
|
|
add_device (device_manager, dev, FALSE);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (dev->use == XIMasterPointer ||
|
|
|
|
dev->use == XIMasterKeyboard)
|
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
g_hash_table_insert (logical_devices,
|
2010-12-13 11:20:34 +00:00
|
|
|
GINT_TO_POINTER (dev->deviceid),
|
|
|
|
GINT_TO_POINTER (dev->attachment));
|
|
|
|
}
|
|
|
|
else if (dev->use == XISlavePointer ||
|
|
|
|
dev->use == XISlaveKeyboard)
|
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
g_hash_table_insert (physical_devices,
|
2010-05-25 22:38:44 +00:00
|
|
|
GINT_TO_POINTER (dev->deviceid),
|
|
|
|
GINT_TO_POINTER (dev->attachment));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
XIFreeDeviceInfo (info);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* Stablish relationships between devices */
|
2020-06-18 18:22:20 +00:00
|
|
|
g_hash_table_foreach (logical_devices, relate_logical_devices, object);
|
|
|
|
g_hash_table_destroy (logical_devices);
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
g_hash_table_foreach (physical_devices, relate_physical_devices, object);
|
|
|
|
g_hash_table_destroy (physical_devices);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* Connect to hierarchy change events */
|
|
|
|
XISetMask (mask, XI_HierarchyChanged);
|
|
|
|
XISetMask (mask, XI_DeviceChanged);
|
2015-01-06 13:56:02 +00:00
|
|
|
XISetMask (mask, XI_PropertyEvent);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
event_mask.deviceid = XIAllDevices;
|
|
|
|
event_mask.mask_len = sizeof (mask);
|
|
|
|
event_mask.mask = mask;
|
|
|
|
|
2017-11-25 13:23:25 +00:00
|
|
|
_gdk_x11_device_manager_xi2_select_events (device_manager,
|
2017-11-09 23:40:16 +00:00
|
|
|
GDK_DISPLAY_XROOTWIN (display),
|
2010-12-21 06:32:01 +00:00
|
|
|
&event_mask);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_manager_xi2_dispose (GObject *object)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceManagerXI2 *device_manager;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
device_manager = GDK_X11_DEVICE_MANAGER_XI2 (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-01-16 13:47:59 +00:00
|
|
|
g_list_free_full (device_manager->devices, g_object_unref);
|
|
|
|
device_manager->devices = NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
if (device_manager->id_table)
|
2010-09-19 02:57:36 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
g_hash_table_destroy (device_manager->id_table);
|
|
|
|
device_manager->id_table = NULL;
|
2010-09-19 02:57:36 +00:00
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
G_OBJECT_CLASS (gdk_x11_device_manager_xi2_parent_class)->dispose (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2010-12-21 16:27:27 +00:00
|
|
|
static void
|
|
|
|
gdk_x11_device_manager_xi2_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkX11DeviceManagerXI2 *device_manager;
|
|
|
|
|
|
|
|
device_manager = GDK_X11_DEVICE_MANAGER_XI2 (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2019-05-14 22:18:38 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
device_manager->display = g_value_get_object (value);
|
|
|
|
break;
|
2010-12-21 16:27:27 +00:00
|
|
|
case PROP_OPCODE:
|
|
|
|
device_manager->opcode = g_value_get_int (value);
|
|
|
|
break;
|
2011-12-24 13:33:24 +00:00
|
|
|
case PROP_MAJOR:
|
|
|
|
device_manager->major = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_MINOR:
|
|
|
|
device_manager->minor = g_value_get_int (value);
|
|
|
|
break;
|
2010-12-21 16:27:27 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_x11_device_manager_xi2_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GdkX11DeviceManagerXI2 *device_manager;
|
|
|
|
|
|
|
|
device_manager = GDK_X11_DEVICE_MANAGER_XI2 (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2019-05-14 22:18:38 +00:00
|
|
|
case PROP_DISPLAY:
|
|
|
|
g_value_set_object (value, device_manager->display);
|
|
|
|
break;
|
2010-12-21 16:27:27 +00:00
|
|
|
case PROP_OPCODE:
|
|
|
|
g_value_set_int (value, device_manager->opcode);
|
|
|
|
break;
|
2011-12-24 13:33:24 +00:00
|
|
|
case PROP_MAJOR:
|
|
|
|
g_value_set_int (value, device_manager->major);
|
|
|
|
break;
|
|
|
|
case PROP_MINOR:
|
|
|
|
g_value_set_int (value, device_manager->minor);
|
|
|
|
break;
|
2010-12-21 16:27:27 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_manager_xi2_event_translator_init (GdkEventTranslatorIface *iface)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
iface->translate_event = gdk_x11_device_manager_xi2_translate_event;
|
|
|
|
iface->get_handled_events = gdk_x11_device_manager_xi2_get_handled_events;
|
2018-03-20 11:05:26 +00:00
|
|
|
iface->select_surface_events = gdk_x11_device_manager_xi2_select_surface_events;
|
2018-03-20 14:14:10 +00:00
|
|
|
iface->get_surface = gdk_x11_device_manager_xi2_get_surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
handle_hierarchy_changed (GdkX11DeviceManagerXI2 *device_manager,
|
|
|
|
XIHierarchyEvent *ev)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-13 11:20:34 +00:00
|
|
|
GdkDisplay *display;
|
|
|
|
Display *xdisplay;
|
|
|
|
XIDeviceInfo *info;
|
|
|
|
int ndevices;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
display = device_manager->display;
|
2010-12-13 11:20:34 +00:00
|
|
|
xdisplay = GDK_DISPLAY_XDISPLAY (display);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
for (i = 0; i < ev->num_info; i++)
|
|
|
|
{
|
|
|
|
if (ev->info[i].flags & XIDeviceEnabled)
|
|
|
|
{
|
2011-11-30 05:16:43 +00:00
|
|
|
gdk_x11_display_error_trap_push (display);
|
2010-12-21 06:32:01 +00:00
|
|
|
info = XIQueryDevice (xdisplay, ev->info[i].deviceid, &ndevices);
|
2011-11-30 05:16:43 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
|
|
|
if (info)
|
|
|
|
{
|
|
|
|
add_device (device_manager, &info[0], TRUE);
|
|
|
|
XIFreeDeviceInfo (info);
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
else if (ev->info[i].flags & XIDeviceDisabled)
|
|
|
|
remove_device (device_manager, ev->info[i].deviceid);
|
2010-12-13 11:20:34 +00:00
|
|
|
else if (ev->info[i].flags & XISlaveAttached ||
|
|
|
|
ev->info[i].flags & XISlaveDetached)
|
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
GdkDevice *logical, *physical;
|
2015-11-26 18:53:36 +00:00
|
|
|
GdkSeat *seat;
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
physical = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (ev->info[i].deviceid));
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
if (!physical)
|
2011-12-18 17:56:51 +00:00
|
|
|
continue;
|
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
/* Remove old logical device info */
|
|
|
|
logical = gdk_device_get_associated_device (physical);
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
if (logical != NULL)
|
2010-12-13 11:20:34 +00:00
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
_gdk_device_remove_physical_device (logical, physical);
|
|
|
|
_gdk_device_set_associated_device (physical, NULL);
|
2010-12-13 11:20:34 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
seat = gdk_device_get_seat (logical);
|
|
|
|
gdk_seat_default_remove_physical_device (GDK_SEAT_DEFAULT (seat), physical);
|
2010-12-13 11:20:34 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
/* Add new logical device if it's an attachment event */
|
2010-12-13 11:20:34 +00:00
|
|
|
if (ev->info[i].flags & XISlaveAttached)
|
|
|
|
{
|
2011-11-30 05:16:43 +00:00
|
|
|
gdk_x11_display_error_trap_push (display);
|
2010-12-21 06:32:01 +00:00
|
|
|
info = XIQueryDevice (xdisplay, ev->info[i].deviceid, &ndevices);
|
2011-11-30 05:16:43 +00:00
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
|
|
|
if (info)
|
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
logical = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (info->attachment));
|
2011-11-30 05:16:43 +00:00
|
|
|
XIFreeDeviceInfo (info);
|
2011-12-18 17:56:51 +00:00
|
|
|
}
|
2011-11-30 05:16:43 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
if (logical != NULL)
|
2011-12-18 17:56:51 +00:00
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
_gdk_device_set_associated_device (physical, logical);
|
|
|
|
_gdk_device_add_physical_device (logical, physical);
|
2011-11-30 05:16:43 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
seat = gdk_device_get_seat (logical);
|
|
|
|
gdk_seat_default_add_physical_device (GDK_SEAT_DEFAULT (seat), physical);
|
2011-11-30 05:16:43 +00:00
|
|
|
}
|
2010-12-13 11:20:34 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-21 06:32:01 +00:00
|
|
|
handle_device_changed (GdkX11DeviceManagerXI2 *device_manager,
|
|
|
|
XIDeviceChangedEvent *ev)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
2015-07-15 19:19:25 +00:00
|
|
|
GdkDevice *device, *source_device;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
display = device_manager->display;
|
2010-05-25 22:38:44 +00:00
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (ev->deviceid));
|
2015-07-15 19:19:25 +00:00
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (ev->sourceid));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-12-18 17:56:51 +00:00
|
|
|
if (device)
|
|
|
|
{
|
|
|
|
_gdk_device_reset_axes (device);
|
2013-09-27 17:32:54 +00:00
|
|
|
_gdk_device_xi2_unset_scroll_valuators ((GdkX11DeviceXI2 *) device);
|
2015-03-02 17:19:16 +00:00
|
|
|
gdk_x11_device_xi2_store_axes (GDK_X11_DEVICE_XI2 (device), NULL, 0);
|
2011-12-18 17:56:51 +00:00
|
|
|
translate_device_classes (display, device, ev->classes, ev->num_classes);
|
2010-12-15 01:34:42 +00:00
|
|
|
|
2011-12-18 17:56:51 +00:00
|
|
|
g_signal_emit_by_name (G_OBJECT (device), "changed");
|
|
|
|
}
|
2015-07-15 19:19:25 +00:00
|
|
|
|
|
|
|
if (source_device)
|
|
|
|
_gdk_device_xi2_reset_scroll_valuators (GDK_X11_DEVICE_XI2 (source_device));
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 12:07:12 +00:00
|
|
|
static gboolean
|
|
|
|
device_get_tool_serial_and_id (GdkDevice *device,
|
|
|
|
guint *serial_id,
|
|
|
|
guint *id)
|
2015-01-06 13:56:02 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
gulong nitems, bytes_after;
|
|
|
|
guint32 *data;
|
|
|
|
int rc, format;
|
|
|
|
Atom type;
|
|
|
|
|
|
|
|
display = gdk_device_get_display (device);
|
|
|
|
|
|
|
|
gdk_x11_display_error_trap_push (display);
|
|
|
|
|
|
|
|
rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display),
|
|
|
|
gdk_x11_device_get_id (device),
|
|
|
|
gdk_x11_get_xatom_by_name_for_display (display, "Wacom Serial IDs"),
|
2017-08-17 12:07:12 +00:00
|
|
|
0, 5, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
|
2015-01-06 13:56:02 +00:00
|
|
|
(guchar **) &data);
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
|
|
|
|
|
|
|
if (rc != Success)
|
2017-08-17 12:07:12 +00:00
|
|
|
return FALSE;
|
2015-01-06 13:56:02 +00:00
|
|
|
|
2017-08-17 12:07:12 +00:00
|
|
|
if (type == XA_INTEGER && format == 32)
|
|
|
|
{
|
|
|
|
if (nitems >= 4)
|
|
|
|
*serial_id = data[3];
|
|
|
|
if (nitems >= 5)
|
|
|
|
*id = data[4];
|
|
|
|
}
|
2015-01-06 13:56:02 +00:00
|
|
|
|
|
|
|
XFree (data);
|
|
|
|
|
2017-08-17 12:07:12 +00:00
|
|
|
return TRUE;
|
2015-01-06 13:56:02 +00:00
|
|
|
}
|
|
|
|
|
2018-12-14 03:58:19 +00:00
|
|
|
static GdkDeviceToolType
|
|
|
|
device_get_tool_type (GdkDevice *device)
|
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
|
|
|
gulong nitems, bytes_after;
|
|
|
|
guint32 *data;
|
|
|
|
int rc, format;
|
|
|
|
Atom type;
|
|
|
|
Atom device_type;
|
|
|
|
Atom types[N_WACOM_TYPE_ATOMS];
|
|
|
|
GdkDeviceToolType tool_type = GDK_DEVICE_TOOL_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
display = gdk_device_get_display (device);
|
|
|
|
gdk_x11_display_error_trap_push (display);
|
|
|
|
|
|
|
|
rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display),
|
|
|
|
gdk_x11_device_get_id (device),
|
|
|
|
gdk_x11_get_xatom_by_name_for_display (display, "Wacom Tool Type"),
|
|
|
|
0, 1, False, XA_ATOM, &type, &format, &nitems, &bytes_after,
|
|
|
|
(guchar **) &data);
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
|
|
|
|
|
|
|
if (rc != Success)
|
|
|
|
return GDK_DEVICE_TOOL_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
if (type != XA_ATOM || format != 32 || nitems != 1)
|
|
|
|
{
|
|
|
|
XFree (data);
|
|
|
|
return GDK_DEVICE_TOOL_TYPE_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_type = *data;
|
|
|
|
XFree (data);
|
|
|
|
|
|
|
|
if (device_type == 0)
|
|
|
|
return GDK_DEVICE_TOOL_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
gdk_x11_display_error_trap_push (display);
|
|
|
|
rc = XInternAtoms (GDK_DISPLAY_XDISPLAY (display),
|
|
|
|
(char **) wacom_type_atoms,
|
|
|
|
N_WACOM_TYPE_ATOMS,
|
|
|
|
False,
|
|
|
|
types);
|
|
|
|
gdk_x11_display_error_trap_pop_ignored (display);
|
|
|
|
|
|
|
|
if (rc == 0)
|
|
|
|
return GDK_DEVICE_TOOL_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
if (device_type == types[WACOM_TYPE_STYLUS])
|
|
|
|
tool_type = GDK_DEVICE_TOOL_TYPE_PEN;
|
|
|
|
else if (device_type == types[WACOM_TYPE_CURSOR])
|
|
|
|
tool_type = GDK_DEVICE_TOOL_TYPE_MOUSE;
|
|
|
|
else if (device_type == types[WACOM_TYPE_ERASER])
|
|
|
|
tool_type = GDK_DEVICE_TOOL_TYPE_ERASER;
|
|
|
|
else if (device_type == types[WACOM_TYPE_TOUCH])
|
|
|
|
tool_type = GDK_DEVICE_TOOL_TYPE_UNKNOWN;
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
2015-01-06 13:56:02 +00:00
|
|
|
static void
|
|
|
|
handle_property_change (GdkX11DeviceManagerXI2 *device_manager,
|
|
|
|
XIPropertyEvent *ev)
|
|
|
|
{
|
|
|
|
GdkDevice *device;
|
|
|
|
|
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (ev->deviceid));
|
|
|
|
|
2017-12-16 01:24:12 +00:00
|
|
|
if (device != NULL &&
|
|
|
|
ev->property == gdk_x11_get_xatom_by_name_for_display (gdk_device_get_display (device), "Wacom Serial IDs"))
|
2015-01-06 13:56:02 +00:00
|
|
|
{
|
|
|
|
GdkDeviceTool *tool = NULL;
|
2017-08-17 12:07:12 +00:00
|
|
|
guint serial_id = 0, tool_id = 0;
|
2015-01-06 13:56:02 +00:00
|
|
|
GdkSeat *seat;
|
|
|
|
|
2017-08-17 12:07:12 +00:00
|
|
|
if (ev->what != XIPropertyDeleted &&
|
|
|
|
device_get_tool_serial_and_id (device, &serial_id, &tool_id))
|
2015-01-06 13:56:02 +00:00
|
|
|
{
|
|
|
|
seat = gdk_device_get_seat (device);
|
2018-12-14 05:28:29 +00:00
|
|
|
tool = gdk_seat_get_tool (seat, serial_id, tool_id);
|
2015-01-06 13:56:02 +00:00
|
|
|
|
|
|
|
if (!tool && serial_id > 0)
|
|
|
|
{
|
2018-12-14 03:58:19 +00:00
|
|
|
GdkDeviceToolType tool_type;
|
|
|
|
|
|
|
|
tool_type = device_get_tool_type (device);
|
2018-12-14 04:57:26 +00:00
|
|
|
if (tool_type != GDK_DEVICE_TOOL_TYPE_UNKNOWN)
|
|
|
|
{
|
|
|
|
tool = gdk_device_tool_new (serial_id, tool_id, tool_type, 0);
|
|
|
|
gdk_seat_default_add_tool (GDK_SEAT_DEFAULT (seat), tool);
|
|
|
|
}
|
2015-01-06 13:56:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gdk_device_update_tool (device, tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
static GdkCrossingMode
|
2020-07-24 13:54:49 +00:00
|
|
|
translate_crossing_mode (int mode)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
switch (mode)
|
|
|
|
{
|
2013-12-04 11:34:31 +00:00
|
|
|
case XINotifyNormal:
|
2010-05-25 22:38:44 +00:00
|
|
|
return GDK_CROSSING_NORMAL;
|
2013-12-04 11:34:31 +00:00
|
|
|
case XINotifyGrab:
|
|
|
|
case XINotifyPassiveGrab:
|
2010-05-25 22:38:44 +00:00
|
|
|
return GDK_CROSSING_GRAB;
|
2013-12-04 11:34:31 +00:00
|
|
|
case XINotifyUngrab:
|
|
|
|
case XINotifyPassiveUngrab:
|
2010-05-25 22:38:44 +00:00
|
|
|
return GDK_CROSSING_UNGRAB;
|
2013-12-04 11:34:31 +00:00
|
|
|
case XINotifyWhileGrabbed:
|
|
|
|
/* Fall through, unexpected in pointer crossing events */
|
2010-05-25 22:38:44 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2017-10-24 16:13:45 +00:00
|
|
|
return GDK_CROSSING_NORMAL;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkNotifyType
|
2020-07-24 13:54:49 +00:00
|
|
|
translate_notify_type (int detail)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
switch (detail)
|
|
|
|
{
|
|
|
|
case NotifyInferior:
|
|
|
|
return GDK_NOTIFY_INFERIOR;
|
|
|
|
case NotifyAncestor:
|
|
|
|
return GDK_NOTIFY_ANCESTOR;
|
|
|
|
case NotifyVirtual:
|
|
|
|
return GDK_NOTIFY_VIRTUAL;
|
|
|
|
case NotifyNonlinear:
|
|
|
|
return GDK_NOTIFY_NONLINEAR;
|
|
|
|
case NotifyNonlinearVirtual:
|
|
|
|
return GDK_NOTIFY_NONLINEAR_VIRTUAL;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2017-10-24 16:26:08 +00:00
|
|
|
return GDK_NOTIFY_UNKNOWN;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_user_time (GdkEvent *event)
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
guint32 time;
|
|
|
|
|
2020-02-18 03:11:56 +00:00
|
|
|
surface = gdk_event_get_surface (event);
|
2018-03-20 14:14:10 +00:00
|
|
|
g_return_if_fail (GDK_IS_SURFACE (surface));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
time = gdk_event_get_time (event);
|
|
|
|
|
|
|
|
/* If an event doesn't have a valid timestamp, we shouldn't use it
|
|
|
|
* to update the latest user interaction time.
|
|
|
|
*/
|
|
|
|
if (time != GDK_CURRENT_TIME)
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_x11_surface_set_user_time (surface, time);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gdouble *
|
|
|
|
translate_axes (GdkDevice *device,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface,
|
2010-05-25 22:38:44 +00:00
|
|
|
XIValuatorState *valuators)
|
|
|
|
{
|
|
|
|
guint n_axes, i;
|
|
|
|
gdouble *axes;
|
2011-01-23 23:50:09 +00:00
|
|
|
gdouble *vals;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-07-14 09:26:00 +00:00
|
|
|
n_axes = gdk_device_get_n_axes (device);
|
2010-05-25 22:38:44 +00:00
|
|
|
axes = g_new0 (gdouble, n_axes);
|
|
|
|
vals = valuators->values;
|
|
|
|
|
2015-03-02 17:19:16 +00:00
|
|
|
for (i = 0; i < MIN (valuators->mask_len * 8, n_axes); i++)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkAxisUse use;
|
|
|
|
gdouble val;
|
|
|
|
|
|
|
|
if (!XIMaskIsSet (valuators->mask, i))
|
2015-03-02 17:19:16 +00:00
|
|
|
{
|
|
|
|
axes[i] = gdk_x11_device_xi2_get_last_axis_value (GDK_X11_DEVICE_XI2 (device), i);
|
|
|
|
continue;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2011-04-08 14:23:39 +00:00
|
|
|
use = gdk_device_get_axis_use (device, i);
|
2010-05-25 22:38:44 +00:00
|
|
|
val = *vals++;
|
|
|
|
|
2017-10-06 19:19:42 +00:00
|
|
|
switch ((guint) use)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
case GDK_AXIS_X:
|
|
|
|
case GDK_AXIS_Y:
|
|
|
|
{
|
|
|
|
if (use == GDK_AXIS_X)
|
|
|
|
axes[i] = x;
|
|
|
|
else
|
|
|
|
axes[i] = y;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_gdk_device_translate_axis (device, i, val, &axes[i]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-02 17:19:16 +00:00
|
|
|
gdk_x11_device_xi2_store_axes (GDK_X11_DEVICE_XI2 (device), axes, n_axes);
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
return axes;
|
|
|
|
}
|
|
|
|
|
2012-10-19 17:33:31 +00:00
|
|
|
static gboolean
|
2018-03-20 11:05:26 +00:00
|
|
|
get_event_surface (GdkEventTranslator *translator,
|
2012-10-19 17:33:31 +00:00
|
|
|
XIEvent *ev,
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface **surface_p)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDisplay *display;
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface = NULL;
|
2012-10-19 17:33:31 +00:00
|
|
|
gboolean should_have_window = TRUE;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
display = GDK_X11_DEVICE_MANAGER_XI2 (translator)->display;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
switch (ev->evtype)
|
|
|
|
{
|
|
|
|
case XI_KeyPress:
|
|
|
|
case XI_KeyRelease:
|
|
|
|
case XI_ButtonPress:
|
|
|
|
case XI_ButtonRelease:
|
|
|
|
case XI_Motion:
|
2012-03-01 05:56:51 +00:00
|
|
|
#ifdef XINPUT_2_2
|
|
|
|
case XI_TouchUpdate:
|
|
|
|
case XI_TouchBegin:
|
|
|
|
case XI_TouchEnd:
|
|
|
|
#endif /* XINPUT_2_2 */
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
surface = gdk_x11_surface_lookup_for_display (display, xev->event);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
/* Apply keyboard grabs to non-native windows */
|
|
|
|
if (ev->evtype == XI_KeyPress || ev->evtype == XI_KeyRelease)
|
|
|
|
{
|
|
|
|
GdkDeviceGrabInfo *info;
|
|
|
|
GdkDevice *device;
|
|
|
|
gulong serial;
|
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
device = g_hash_table_lookup (GDK_X11_DEVICE_MANAGER_XI2 (translator)->id_table,
|
2010-05-25 22:38:44 +00:00
|
|
|
GUINT_TO_POINTER (((XIDeviceEvent *) ev)->deviceid));
|
|
|
|
|
2010-12-13 19:05:59 +00:00
|
|
|
serial = _gdk_display_get_next_serial (display);
|
2010-05-25 22:38:44 +00:00
|
|
|
info = _gdk_display_has_device_grab (display, device, serial);
|
|
|
|
|
2019-03-23 04:14:00 +00:00
|
|
|
if (info && !info->owner_events)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
/* Report key event against grab surface */
|
|
|
|
surface = info->surface;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XI_Enter:
|
|
|
|
case XI_Leave:
|
|
|
|
case XI_FocusIn:
|
|
|
|
case XI_FocusOut:
|
|
|
|
{
|
|
|
|
XIEnterEvent *xev = (XIEnterEvent *) ev;
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
surface = gdk_x11_surface_lookup_for_display (display, xev->event);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-10-19 17:33:31 +00:00
|
|
|
default:
|
|
|
|
should_have_window = FALSE;
|
|
|
|
break;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
*surface_p = surface;
|
2012-10-19 17:33:31 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (should_have_window && !surface)
|
2012-10-19 17:33:31 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 23:49:52 +00:00
|
|
|
static gboolean
|
|
|
|
scroll_valuators_changed (GdkX11DeviceXI2 *device,
|
|
|
|
XIValuatorState *valuators,
|
|
|
|
gdouble *dx,
|
|
|
|
gdouble *dy)
|
|
|
|
{
|
2012-04-20 21:24:45 +00:00
|
|
|
gboolean has_scroll_valuators = FALSE;
|
2012-01-23 23:49:52 +00:00
|
|
|
GdkScrollDirection direction;
|
|
|
|
guint n_axes, i, n_val;
|
|
|
|
gdouble *vals;
|
|
|
|
|
|
|
|
n_axes = gdk_device_get_n_axes (GDK_DEVICE (device));
|
|
|
|
vals = valuators->values;
|
|
|
|
*dx = *dy = 0;
|
|
|
|
n_val = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < MIN (valuators->mask_len * 8, n_axes); i++)
|
|
|
|
{
|
|
|
|
gdouble delta;
|
|
|
|
|
|
|
|
if (!XIMaskIsSet (valuators->mask, i))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (_gdk_x11_device_xi2_get_scroll_delta (device, i, vals[n_val],
|
|
|
|
&direction, &delta))
|
|
|
|
{
|
|
|
|
has_scroll_valuators = TRUE;
|
|
|
|
|
|
|
|
if (direction == GDK_SCROLL_UP ||
|
|
|
|
direction == GDK_SCROLL_DOWN)
|
|
|
|
*dy = delta;
|
|
|
|
else
|
|
|
|
*dx = delta;
|
|
|
|
}
|
|
|
|
|
|
|
|
n_val++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return has_scroll_valuators;
|
|
|
|
}
|
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
/* We only care about focus events that indicate that _this_
|
2019-08-25 12:52:24 +00:00
|
|
|
* surface (not an ancestor or child) got or lost the focus
|
2019-05-14 22:18:38 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
_gdk_device_manager_xi2_handle_focus (GdkSurface *surface,
|
|
|
|
Window original,
|
|
|
|
GdkDevice *device,
|
|
|
|
GdkDevice *source_device,
|
|
|
|
gboolean focus_in,
|
|
|
|
int detail,
|
|
|
|
int mode)
|
|
|
|
{
|
|
|
|
GdkToplevelX11 *toplevel;
|
|
|
|
GdkX11Screen *x11_screen;
|
|
|
|
gboolean had_focus;
|
|
|
|
|
|
|
|
g_return_if_fail (GDK_IS_SURFACE (surface));
|
|
|
|
g_return_if_fail (GDK_IS_DEVICE (device));
|
|
|
|
g_return_if_fail (source_device == NULL || GDK_IS_DEVICE (source_device));
|
|
|
|
|
|
|
|
GDK_DISPLAY_NOTE (gdk_surface_get_display (surface), EVENTS,
|
|
|
|
g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
|
|
|
|
GDK_SURFACE_XID (surface),
|
|
|
|
notify_details[detail],
|
|
|
|
notify_modes[mode]));
|
|
|
|
|
|
|
|
toplevel = _gdk_x11_surface_get_toplevel (surface);
|
|
|
|
|
|
|
|
if (!toplevel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (toplevel->focus_window == original)
|
|
|
|
return;
|
|
|
|
|
|
|
|
had_focus = HAS_FOCUS (toplevel);
|
|
|
|
x11_screen = GDK_X11_SCREEN (GDK_SURFACE_SCREEN (surface));
|
|
|
|
|
|
|
|
switch (detail)
|
|
|
|
{
|
|
|
|
case NotifyAncestor:
|
|
|
|
case NotifyVirtual:
|
|
|
|
/* When the focus moves from an ancestor of the window to
|
|
|
|
* the window or a descendent of the window, *and* the
|
|
|
|
* pointer is inside the window, then we were previously
|
|
|
|
* receiving keystroke events in the has_pointer_focus
|
|
|
|
* case and are now receiving them in the
|
|
|
|
* has_focus_window case.
|
|
|
|
*/
|
|
|
|
if (toplevel->has_pointer &&
|
|
|
|
!x11_screen->wmspec_check_window &&
|
|
|
|
mode != NotifyGrab &&
|
|
|
|
mode != XINotifyPassiveGrab &&
|
|
|
|
mode != XINotifyPassiveUngrab &&
|
|
|
|
mode != NotifyUngrab)
|
|
|
|
toplevel->has_pointer_focus = (focus_in) ? FALSE : TRUE;
|
|
|
|
G_GNUC_FALLTHROUGH;
|
|
|
|
|
|
|
|
case NotifyNonlinear:
|
|
|
|
case NotifyNonlinearVirtual:
|
|
|
|
if (mode != NotifyGrab &&
|
|
|
|
mode != XINotifyPassiveGrab &&
|
|
|
|
mode != XINotifyPassiveUngrab &&
|
|
|
|
mode != NotifyUngrab)
|
|
|
|
toplevel->has_focus_window = (focus_in) ? TRUE : FALSE;
|
|
|
|
/* We pretend that the focus moves to the grab
|
|
|
|
* window, so we pay attention to NotifyGrab
|
|
|
|
* NotifyUngrab, and ignore NotifyWhileGrabbed
|
|
|
|
*/
|
|
|
|
if (mode != NotifyWhileGrabbed)
|
|
|
|
toplevel->has_focus = (focus_in) ? TRUE : FALSE;
|
|
|
|
break;
|
|
|
|
case NotifyPointer:
|
|
|
|
/* The X server sends NotifyPointer/NotifyGrab,
|
|
|
|
* but the pointer focus is ignored while a
|
|
|
|
* grab is in effect
|
|
|
|
*/
|
|
|
|
if (!x11_screen->wmspec_check_window &&
|
|
|
|
mode != NotifyGrab &&
|
|
|
|
mode != XINotifyPassiveGrab &&
|
|
|
|
mode != XINotifyPassiveUngrab &&
|
|
|
|
mode != NotifyUngrab)
|
|
|
|
toplevel->has_pointer_focus = (focus_in) ? TRUE : FALSE;
|
|
|
|
break;
|
|
|
|
case NotifyInferior:
|
|
|
|
case NotifyPointerRoot:
|
|
|
|
case NotifyDetailNone:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HAS_FOCUS (toplevel) != had_focus)
|
|
|
|
{
|
|
|
|
GdkEvent *event;
|
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_focus_event_new (surface, device, source_device, focus_in);
|
2019-05-14 22:18:38 +00:00
|
|
|
gdk_display_put_event (gdk_surface_get_display (surface), event);
|
2020-02-15 20:07:24 +00:00
|
|
|
gdk_event_unref (event);
|
2019-05-14 22:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
static GdkEvent *
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
|
|
|
|
GdkDisplay *display,
|
2017-12-12 23:39:32 +00:00
|
|
|
const XEvent *xevent)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-21 06:32:01 +00:00
|
|
|
GdkX11DeviceManagerXI2 *device_manager;
|
2017-12-12 23:39:32 +00:00
|
|
|
const XGenericEventCookie *cookie;
|
2015-12-14 19:24:40 +00:00
|
|
|
GdkDevice *device, *source_device;
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface;
|
2019-04-22 01:14:46 +00:00
|
|
|
GdkX11Surface *impl;
|
2013-06-20 09:40:07 +00:00
|
|
|
int scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
XIEvent *ev;
|
2020-02-15 17:09:31 +00:00
|
|
|
GdkEvent *event;
|
|
|
|
|
|
|
|
event = NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-21 06:32:01 +00:00
|
|
|
device_manager = (GdkX11DeviceManagerXI2 *) translator;
|
2010-05-25 22:38:44 +00:00
|
|
|
cookie = &xevent->xcookie;
|
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
if (xevent->type != GenericEvent ||
|
|
|
|
cookie->extension != device_manager->opcode)
|
2020-02-15 17:09:31 +00:00
|
|
|
return event;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
ev = (XIEvent *) cookie->data;
|
|
|
|
|
2011-07-15 16:33:44 +00:00
|
|
|
if (!ev)
|
2020-02-15 17:09:31 +00:00
|
|
|
return NULL;
|
2011-07-15 16:33:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (!get_event_surface (translator, ev, &surface))
|
2020-02-15 17:09:31 +00:00
|
|
|
return NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface && GDK_SURFACE_DESTROYED (surface))
|
2020-02-15 17:09:31 +00:00
|
|
|
return NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2013-06-20 09:40:07 +00:00
|
|
|
scale = 1;
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface)
|
2013-06-20 09:40:07 +00:00
|
|
|
{
|
2019-04-22 01:14:46 +00:00
|
|
|
impl = GDK_X11_SURFACE (surface);
|
2018-03-20 11:05:26 +00:00
|
|
|
scale = impl->surface_scale;
|
2013-06-20 09:40:07 +00:00
|
|
|
}
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
if (ev->evtype == XI_Motion ||
|
|
|
|
ev->evtype == XI_ButtonRelease)
|
|
|
|
{
|
2010-12-15 22:55:04 +00:00
|
|
|
if (_gdk_x11_moveresize_handle_event (xevent))
|
2020-02-15 17:09:31 +00:00
|
|
|
return NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (ev->evtype)
|
|
|
|
{
|
|
|
|
case XI_HierarchyChanged:
|
|
|
|
handle_hierarchy_changed (device_manager,
|
|
|
|
(XIHierarchyEvent *) ev);
|
|
|
|
break;
|
|
|
|
case XI_DeviceChanged:
|
|
|
|
handle_device_changed (device_manager,
|
|
|
|
(XIDeviceChangedEvent *) ev);
|
|
|
|
break;
|
2015-01-06 13:56:02 +00:00
|
|
|
case XI_PropertyEvent:
|
|
|
|
handle_property_change (device_manager,
|
|
|
|
(XIPropertyEvent *) ev);
|
|
|
|
break;
|
2010-05-25 22:38:44 +00:00
|
|
|
case XI_KeyPress:
|
|
|
|
case XI_KeyRelease:
|
|
|
|
{
|
|
|
|
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
|
2017-12-15 12:44:58 +00:00
|
|
|
GdkKeymap *keymap = gdk_display_get_keymap (display);
|
2020-03-21 14:25:06 +00:00
|
|
|
GdkModifierType consumed, state, orig_state;
|
2020-04-05 18:40:55 +00:00
|
|
|
int layout, level;
|
2020-02-15 17:09:31 +00:00
|
|
|
guint keyval;
|
2020-04-05 18:40:55 +00:00
|
|
|
GdkTranslatedKey translated;
|
|
|
|
GdkTranslatedKey no_lock;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2014-06-29 21:59:38 +00:00
|
|
|
g_message ("key %s:\twindow %ld\n"
|
|
|
|
"\tdevice:%u\n"
|
|
|
|
"\tsource device:%u\n"
|
|
|
|
"\tkey number: %u\n",
|
|
|
|
(ev->evtype == XI_KeyPress) ? "press" : "release",
|
|
|
|
xev->event,
|
|
|
|
xev->deviceid,
|
|
|
|
xev->sourceid,
|
|
|
|
xev->detail));
|
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->deviceid));
|
|
|
|
|
2010-12-13 01:12:43 +00:00
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->sourceid));
|
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
keyval = GDK_KEY_VoidSymbol;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
gdk_keymap_translate_keyboard_state (keymap,
|
2020-02-15 17:09:31 +00:00
|
|
|
xev->detail,
|
|
|
|
state,
|
|
|
|
xev->group.effective,
|
|
|
|
&keyval,
|
2020-04-05 18:40:55 +00:00
|
|
|
&layout, &level, &consumed);
|
2020-03-21 14:25:06 +00:00
|
|
|
orig_state = state;
|
2020-02-15 17:09:31 +00:00
|
|
|
state &= ~consumed;
|
2010-12-16 04:49:31 +00:00
|
|
|
_gdk_x11_keymap_add_virt_mods (keymap, &state);
|
2020-03-21 14:25:06 +00:00
|
|
|
state |= orig_state;
|
2020-02-15 17:09:31 +00:00
|
|
|
|
2020-04-05 18:40:55 +00:00
|
|
|
translated.keyval = keyval;
|
|
|
|
translated.consumed = consumed;
|
|
|
|
translated.layout = layout;
|
|
|
|
translated.level = level;
|
|
|
|
|
|
|
|
if (orig_state & GDK_LOCK_MASK)
|
|
|
|
{
|
|
|
|
orig_state &= ~GDK_LOCK_MASK;
|
|
|
|
|
|
|
|
gdk_keymap_translate_keyboard_state (keymap,
|
|
|
|
xev->detail,
|
|
|
|
orig_state,
|
|
|
|
xev->group.effective,
|
|
|
|
&keyval,
|
|
|
|
&layout, &level, &consumed);
|
|
|
|
|
|
|
|
no_lock.keyval = keyval;
|
|
|
|
no_lock.consumed = consumed;
|
|
|
|
no_lock.layout = layout;
|
|
|
|
no_lock.level = level;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
no_lock = translated;
|
|
|
|
}
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_key_event_new (xev->evtype == XI_KeyPress
|
2020-02-15 17:09:31 +00:00
|
|
|
? GDK_KEY_PRESS
|
|
|
|
: GDK_KEY_RELEASE,
|
|
|
|
surface,
|
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
xev->time,
|
|
|
|
xev->detail,
|
2020-04-05 18:40:55 +00:00
|
|
|
state,
|
|
|
|
gdk_x11_keymap_key_is_modifier (keymap, xev->detail),
|
|
|
|
&translated,
|
|
|
|
&no_lock);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (ev->evtype == XI_KeyPress)
|
|
|
|
set_user_time (event);
|
|
|
|
|
|
|
|
/* FIXME: emulate autorepeat on key
|
|
|
|
* release? XI2 seems attached to Xkb.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case XI_ButtonPress:
|
|
|
|
case XI_ButtonRelease:
|
|
|
|
{
|
|
|
|
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
|
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2014-06-29 21:58:56 +00:00
|
|
|
g_message ("button %s:\twindow %ld\n"
|
|
|
|
"\tdevice:%u\n"
|
|
|
|
"\tsource device:%u\n"
|
|
|
|
"\tbutton number: %u\n"
|
2013-11-16 23:14:06 +00:00
|
|
|
"\tx,y: %.2f %.2f",
|
|
|
|
(ev->evtype == XI_ButtonPress) ? "press" : "release",
|
2014-06-29 21:58:56 +00:00
|
|
|
xev->event,
|
|
|
|
xev->deviceid,
|
|
|
|
xev->sourceid,
|
|
|
|
xev->detail,
|
2013-11-16 23:14:06 +00:00
|
|
|
xev->event_x, xev->event_y));
|
|
|
|
|
2017-09-15 11:21:25 +00:00
|
|
|
#ifdef XINPUT_2_2
|
|
|
|
if (xev->flags & XIPointerEmulated)
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
|
2012-01-23 23:49:52 +00:00
|
|
|
if (ev->evtype == XI_ButtonRelease &&
|
2012-03-01 05:56:51 +00:00
|
|
|
(xev->detail >= 4 && xev->detail <= 7))
|
2012-01-23 23:49:52 +00:00
|
|
|
return FALSE;
|
|
|
|
else if (ev->evtype == XI_ButtonPress &&
|
|
|
|
(xev->detail >= 4 && xev->detail <= 7))
|
2012-03-01 05:56:51 +00:00
|
|
|
{
|
2020-02-15 17:09:31 +00:00
|
|
|
GdkScrollDirection direction;
|
|
|
|
|
2012-03-01 05:56:51 +00:00
|
|
|
/* Button presses of button 4-7 are scroll events */
|
|
|
|
|
|
|
|
if (xev->detail == 4)
|
2020-02-15 17:09:31 +00:00
|
|
|
direction = GDK_SCROLL_UP;
|
2012-03-01 05:56:51 +00:00
|
|
|
else if (xev->detail == 5)
|
2020-02-15 17:09:31 +00:00
|
|
|
direction = GDK_SCROLL_DOWN;
|
2012-03-01 05:56:51 +00:00
|
|
|
else if (xev->detail == 6)
|
2020-02-15 17:09:31 +00:00
|
|
|
direction = GDK_SCROLL_LEFT;
|
2012-03-01 05:56:51 +00:00
|
|
|
else
|
2020-02-15 17:09:31 +00:00
|
|
|
direction = GDK_SCROLL_RIGHT;
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2015-12-14 19:24:40 +00:00
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->deviceid));
|
2012-03-01 05:56:51 +00:00
|
|
|
|
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->sourceid));
|
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_scroll_event_new_discrete (surface,
|
2020-02-15 17:09:31 +00:00
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
NULL,
|
|
|
|
xev->time,
|
|
|
|
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
|
|
|
|
direction,
|
|
|
|
FALSE);
|
|
|
|
|
2012-03-01 05:56:51 +00:00
|
|
|
}
|
|
|
|
else
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2020-02-15 17:09:31 +00:00
|
|
|
double x, y;
|
|
|
|
double *axes;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2015-12-14 19:24:40 +00:00
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->deviceid));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-13 01:12:43 +00:00
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->sourceid));
|
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
axes = translate_axes (device,
|
2020-02-18 03:11:56 +00:00
|
|
|
(double) xev->event_x / scale,
|
|
|
|
(double) xev->event_y / scale,
|
|
|
|
surface,
|
2020-02-15 17:09:31 +00:00
|
|
|
&xev->valuators);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2020-02-24 18:35:27 +00:00
|
|
|
x = (double) xev->event_x / scale;
|
|
|
|
y = (double) xev->event_y / scale;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_button_event_new (ev->evtype == XI_ButtonPress
|
2020-02-15 17:09:31 +00:00
|
|
|
? GDK_BUTTON_PRESS
|
|
|
|
: GDK_BUTTON_RELEASE,
|
|
|
|
surface,
|
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
source_device->last_tool,
|
|
|
|
xev->time,
|
|
|
|
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
|
|
|
|
xev->detail,
|
|
|
|
x, y,
|
|
|
|
axes);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2011-04-11 16:13:44 +00:00
|
|
|
if (ev->evtype == XI_ButtonPress)
|
|
|
|
set_user_time (event);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
case XI_Motion:
|
|
|
|
{
|
|
|
|
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
|
2012-01-23 23:49:52 +00:00
|
|
|
gdouble delta_x, delta_y;
|
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
double x, y;
|
|
|
|
double *axes;
|
|
|
|
|
2017-09-15 11:21:25 +00:00
|
|
|
#ifdef XINPUT_2_2
|
|
|
|
if (xev->flags & XIPointerEmulated)
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
|
2012-01-23 23:49:52 +00:00
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->sourceid));
|
2012-04-20 21:34:08 +00:00
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->deviceid));
|
2012-01-23 23:49:52 +00:00
|
|
|
|
2012-04-20 21:34:08 +00:00
|
|
|
/* When scrolling, X might send events twice here; once with both the
|
|
|
|
* device and the source device set to the physical device, and once
|
2020-06-18 18:22:20 +00:00
|
|
|
* with the device set to the logical device.
|
|
|
|
*
|
2012-04-20 21:34:08 +00:00
|
|
|
* Since we are only interested in the latter, and
|
|
|
|
* scroll_valuators_changed() updates the valuator cache for the
|
|
|
|
* source device, we need to explicitly ignore the first event in
|
|
|
|
* order to get the correct delta for the second.
|
|
|
|
*/
|
2020-06-18 18:22:20 +00:00
|
|
|
if (gdk_device_get_device_type (device) != GDK_DEVICE_TYPE_PHYSICAL &&
|
2012-04-20 21:34:08 +00:00
|
|
|
scroll_valuators_changed (GDK_X11_DEVICE_XI2 (source_device),
|
2012-01-23 23:49:52 +00:00
|
|
|
&xev->valuators, &delta_x, &delta_y))
|
|
|
|
{
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2017-09-15 11:21:25 +00:00
|
|
|
g_message ("smooth scroll: \n\tdevice: %u\n\tsource device: %u\n\twindow %ld\n\tdeltas: %f %f",
|
2012-04-22 16:50:29 +00:00
|
|
|
xev->deviceid, xev->sourceid,
|
2012-03-02 14:55:55 +00:00
|
|
|
xev->event, delta_x, delta_y));
|
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_scroll_event_new (surface,
|
2020-02-15 17:09:31 +00:00
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
NULL,
|
|
|
|
xev->time,
|
|
|
|
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
|
|
|
|
delta_x,
|
|
|
|
delta_y,
|
|
|
|
delta_x == 0.0 && delta_y == 0.0);
|
2012-01-23 23:49:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
axes = translate_axes (device,
|
2020-02-18 03:11:56 +00:00
|
|
|
(double) xev->event_x / scale,
|
|
|
|
(double) xev->event_y / scale,
|
|
|
|
surface,
|
2020-02-15 17:09:31 +00:00
|
|
|
&xev->valuators);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2020-02-24 18:35:27 +00:00
|
|
|
x = (double) xev->event_x / scale;
|
|
|
|
y = (double) xev->event_y / scale;
|
2020-02-15 17:09:31 +00:00
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_motion_event_new (surface,
|
2020-02-15 17:09:31 +00:00
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
source_device->last_tool,
|
|
|
|
xev->time,
|
|
|
|
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
|
|
|
|
x, y,
|
|
|
|
axes);
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-03-01 05:56:51 +00:00
|
|
|
|
|
|
|
#ifdef XINPUT_2_2
|
|
|
|
case XI_TouchBegin:
|
|
|
|
case XI_TouchEnd:
|
|
|
|
{
|
|
|
|
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
|
2020-02-15 17:09:31 +00:00
|
|
|
GdkModifierType state;
|
|
|
|
|
|
|
|
double x, y;
|
|
|
|
double *axes;
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2013-04-11 13:29:11 +00:00
|
|
|
g_message ("touch %s:\twindow %ld\n\ttouch id: %u\n\tpointer emulating: %s",
|
2012-02-29 05:44:51 +00:00
|
|
|
ev->evtype == XI_TouchBegin ? "begin" : "end",
|
|
|
|
xev->event,
|
|
|
|
xev->detail,
|
2013-04-11 13:29:11 +00:00
|
|
|
xev->flags & XITouchEmulatingPointer ? "true" : "false"));
|
2012-02-29 05:44:51 +00:00
|
|
|
|
2015-12-14 19:24:40 +00:00
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->deviceid));
|
2012-03-01 05:56:51 +00:00
|
|
|
|
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->sourceid));
|
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
|
|
|
|
if (ev->evtype == XI_TouchBegin)
|
|
|
|
state |= GDK_BUTTON1_MASK;
|
|
|
|
|
|
|
|
axes = translate_axes (device,
|
2020-02-18 03:11:56 +00:00
|
|
|
(double) xev->event_x / scale,
|
|
|
|
(double) xev->event_y / scale,
|
|
|
|
surface,
|
2020-02-15 17:09:31 +00:00
|
|
|
&xev->valuators);
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2020-02-24 18:35:27 +00:00
|
|
|
x = (double) xev->event_x / scale;
|
|
|
|
y = (double) xev->event_y / scale;
|
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_touch_event_new (ev->evtype == XI_TouchBegin
|
2020-02-15 17:09:31 +00:00
|
|
|
? GDK_TOUCH_BEGIN
|
|
|
|
: GDK_TOUCH_END,
|
|
|
|
GUINT_TO_POINTER (xev->detail),
|
|
|
|
surface,
|
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
xev->time,
|
|
|
|
state,
|
|
|
|
x, y,
|
|
|
|
axes,
|
|
|
|
xev->flags & XITouchEmulatingPointer);
|
2012-03-01 05:56:51 +00:00
|
|
|
|
|
|
|
if (ev->evtype == XI_TouchBegin)
|
|
|
|
set_user_time (event);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case XI_TouchUpdate:
|
|
|
|
{
|
|
|
|
XIDeviceEvent *xev = (XIDeviceEvent *) ev;
|
2020-02-15 17:09:31 +00:00
|
|
|
GdkModifierType state;
|
|
|
|
|
|
|
|
double x, y;
|
|
|
|
double *axes;
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2013-04-11 13:29:11 +00:00
|
|
|
g_message ("touch update:\twindow %ld\n\ttouch id: %u\n\tpointer emulating: %s",
|
2012-02-29 05:44:51 +00:00
|
|
|
xev->event,
|
|
|
|
xev->detail,
|
2013-04-11 13:29:11 +00:00
|
|
|
xev->flags & XITouchEmulatingPointer ? "true" : "false"));
|
2012-02-29 05:44:51 +00:00
|
|
|
|
2015-12-14 19:24:40 +00:00
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (xev->deviceid));
|
2012-03-01 05:56:51 +00:00
|
|
|
|
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->sourceid));
|
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
|
|
|
|
state |= GDK_BUTTON1_MASK;
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
axes = translate_axes (device,
|
2020-02-18 03:11:56 +00:00
|
|
|
(double) xev->event_x / scale,
|
|
|
|
(double) xev->event_y / scale,
|
|
|
|
surface,
|
2020-02-15 17:09:31 +00:00
|
|
|
&xev->valuators);
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2020-02-24 18:35:27 +00:00
|
|
|
x = (double) xev->event_x / scale;
|
|
|
|
y = (double) xev->event_y / scale;
|
2020-02-15 17:09:31 +00:00
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_touch_event_new (GDK_TOUCH_UPDATE,
|
2020-02-15 17:09:31 +00:00
|
|
|
GUINT_TO_POINTER (xev->detail),
|
|
|
|
surface,
|
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
xev->time,
|
|
|
|
state,
|
|
|
|
x, y,
|
|
|
|
axes,
|
|
|
|
xev->flags & XITouchEmulatingPointer);
|
2012-03-01 05:56:51 +00:00
|
|
|
}
|
|
|
|
break;
|
2012-03-02 14:55:55 +00:00
|
|
|
#endif /* XINPUT_2_2 */
|
2012-03-01 05:56:51 +00:00
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
case XI_Enter:
|
|
|
|
case XI_Leave:
|
|
|
|
{
|
|
|
|
XIEnterEvent *xev = (XIEnterEvent *) ev;
|
2020-07-09 14:53:47 +00:00
|
|
|
GdkModifierType state;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2018-01-12 00:48:27 +00:00
|
|
|
GDK_DISPLAY_NOTE (display, EVENTS,
|
2013-11-16 23:14:06 +00:00
|
|
|
g_message ("%s notify:\twindow %ld\n\tsubwindow:%ld\n"
|
|
|
|
"\tdevice: %u\n\tsource device: %u\n"
|
|
|
|
"\tnotify type: %u\n\tcrossing mode: %u",
|
|
|
|
(ev->evtype == XI_Enter) ? "enter" : "leave",
|
|
|
|
xev->event, xev->child,
|
|
|
|
xev->deviceid, xev->sourceid,
|
|
|
|
xev->detail, xev->mode));
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (xev->deviceid));
|
|
|
|
|
2010-12-13 01:12:43 +00:00
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->sourceid));
|
2013-03-28 13:57:00 +00:00
|
|
|
|
2020-07-09 14:53:47 +00:00
|
|
|
state = _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group);
|
|
|
|
|
|
|
|
/* Ignore normal crossing events while there is an implicit grab.
|
|
|
|
* We will receive a crossing event with one of the other details if
|
|
|
|
* the implicit grab were finished (eg. releasing the button outside
|
|
|
|
* the window triggers a XINotifyUngrab leave).
|
|
|
|
*/
|
|
|
|
if (xev->mode == XINotifyNormal &&
|
|
|
|
(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK |
|
|
|
|
GDK_BUTTON4_MASK | GDK_BUTTON5_MASK)))
|
|
|
|
break;
|
|
|
|
|
2013-11-18 21:12:18 +00:00
|
|
|
if (ev->evtype == XI_Enter &&
|
|
|
|
xev->detail != XINotifyInferior && xev->mode != XINotifyPassiveUngrab &&
|
2020-03-08 20:38:03 +00:00
|
|
|
GDK_IS_TOPLEVEL (surface))
|
2013-03-28 13:57:00 +00:00
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
if (gdk_device_get_device_type (source_device) != GDK_DEVICE_TYPE_LOGICAL)
|
2015-07-15 19:19:25 +00:00
|
|
|
_gdk_device_xi2_reset_scroll_valuators (GDK_X11_DEVICE_XI2 (source_device));
|
2013-11-16 22:32:58 +00:00
|
|
|
else
|
|
|
|
{
|
2020-06-18 18:22:20 +00:00
|
|
|
GList *physical_devices, *l;
|
2013-03-28 13:57:00 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
physical_devices = gdk_device_list_physical_devices (source_device);
|
2013-03-28 13:57:00 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
for (l = physical_devices; l; l = l->next)
|
2015-07-15 19:19:25 +00:00
|
|
|
_gdk_device_xi2_reset_scroll_valuators (GDK_X11_DEVICE_XI2 (l->data));
|
2013-03-28 13:57:00 +00:00
|
|
|
|
2020-06-18 18:22:20 +00:00
|
|
|
g_list_free (physical_devices);
|
2013-11-16 22:32:58 +00:00
|
|
|
}
|
2013-03-28 13:57:00 +00:00
|
|
|
}
|
2010-12-13 01:12:43 +00:00
|
|
|
|
Restructure the GdkEvent type hierarchy
GdkEvent has been a "I-can't-believe-this-is-not-OOP" type for ages,
using a union of sub-types. This has always been problematic when it
comes to implementing accessor functions: either you get generic API
that takes a GdkEvent and uses a massive switch() to determine which
event types have the data you're looking for; or you create namespaced
accessors, but break language bindings horribly, as boxed types cannot
have derived types.
The recent conversion of GskRenderNode (which had similar issues) to
GTypeInstance, and the fact that GdkEvent is now a completely opaque
type, provide us with the chance of moving GdkEvent to GTypeInstance,
and have sub-types for GdkEvent.
The change from boxed type to GTypeInstance is pretty small, all things
considered, but ends up cascading to a larger commit, as we still have
backends and code in GTK trying to access GdkEvent structures directly.
Additionally, the naming of the public getter functions requires
renaming all the data structures to conform to the namespace/type-name
pattern.
2020-04-16 16:23:36 +00:00
|
|
|
event = gdk_crossing_event_new (ev->evtype == XI_Enter
|
2020-02-15 17:09:31 +00:00
|
|
|
? GDK_ENTER_NOTIFY
|
|
|
|
: GDK_LEAVE_NOTIFY,
|
|
|
|
surface,
|
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
xev->time,
|
2020-07-09 14:53:47 +00:00
|
|
|
state,
|
2020-02-15 17:09:31 +00:00
|
|
|
(double) xev->event_x / scale,
|
|
|
|
(double) xev->event_y / scale,
|
|
|
|
translate_crossing_mode (xev->mode),
|
|
|
|
translate_notify_type (xev->detail));
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case XI_FocusIn:
|
|
|
|
case XI_FocusOut:
|
|
|
|
{
|
2018-03-20 14:14:10 +00:00
|
|
|
if (surface)
|
2013-01-30 20:11:59 +00:00
|
|
|
{
|
|
|
|
XIEnterEvent *xev = (XIEnterEvent *) ev;
|
2010-06-07 13:30:37 +00:00
|
|
|
|
2013-01-30 20:11:59 +00:00
|
|
|
device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GINT_TO_POINTER (xev->deviceid));
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2013-01-30 20:11:59 +00:00
|
|
|
source_device = g_hash_table_lookup (device_manager->id_table,
|
|
|
|
GUINT_TO_POINTER (xev->sourceid));
|
2010-12-13 01:12:43 +00:00
|
|
|
|
2019-05-14 22:18:38 +00:00
|
|
|
_gdk_device_manager_xi2_handle_focus (surface,
|
|
|
|
xev->event,
|
|
|
|
device,
|
|
|
|
source_device,
|
|
|
|
(ev->evtype == XI_FocusIn) ? TRUE : FALSE,
|
|
|
|
xev->detail,
|
|
|
|
xev->mode);
|
2013-01-30 20:11:59 +00:00
|
|
|
}
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
2011-06-15 01:59:55 +00:00
|
|
|
break;
|
2010-05-25 22:38:44 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-02-15 17:09:31 +00:00
|
|
|
return event;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GdkEventMask
|
2010-12-21 06:32:01 +00:00
|
|
|
gdk_x11_device_manager_xi2_get_handled_events (GdkEventTranslator *translator)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
return (GDK_KEY_PRESS_MASK |
|
|
|
|
GDK_KEY_RELEASE_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK |
|
|
|
|
GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_SCROLL_MASK |
|
|
|
|
GDK_ENTER_NOTIFY_MASK |
|
|
|
|
GDK_LEAVE_NOTIFY_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK |
|
|
|
|
GDK_BUTTON1_MOTION_MASK |
|
|
|
|
GDK_BUTTON2_MOTION_MASK |
|
|
|
|
GDK_BUTTON3_MOTION_MASK |
|
|
|
|
GDK_BUTTON_MOTION_MASK |
|
2012-03-01 05:56:51 +00:00
|
|
|
GDK_FOCUS_CHANGE_MASK |
|
|
|
|
GDK_TOUCH_MASK);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2018-03-20 11:05:26 +00:00
|
|
|
gdk_x11_device_manager_xi2_select_surface_events (GdkEventTranslator *translator,
|
2010-12-21 06:32:01 +00:00
|
|
|
Window window,
|
|
|
|
GdkEventMask evmask)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
XIEventMask event_mask;
|
|
|
|
|
|
|
|
event_mask.deviceid = XIAllMasterDevices;
|
2017-11-25 13:23:25 +00:00
|
|
|
event_mask.mask = _gdk_x11_device_xi2_translate_event_mask (GDK_X11_DEVICE_MANAGER_XI2 (translator),
|
2012-03-01 05:56:51 +00:00
|
|
|
evmask,
|
|
|
|
&event_mask.mask_len);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2017-11-25 13:23:25 +00:00
|
|
|
_gdk_x11_device_manager_xi2_select_events (GDK_X11_DEVICE_MANAGER_XI2 (translator), window, &event_mask);
|
2010-05-25 22:38:44 +00:00
|
|
|
g_free (event_mask.mask);
|
|
|
|
}
|
2011-02-12 00:27:40 +00:00
|
|
|
|
2018-03-20 10:40:08 +00:00
|
|
|
static GdkSurface *
|
2018-03-20 14:14:10 +00:00
|
|
|
gdk_x11_device_manager_xi2_get_surface (GdkEventTranslator *translator,
|
|
|
|
const XEvent *xevent)
|
2011-05-18 19:32:22 +00:00
|
|
|
{
|
|
|
|
GdkX11DeviceManagerXI2 *device_manager;
|
|
|
|
XIEvent *ev;
|
2018-03-20 14:14:10 +00:00
|
|
|
GdkSurface *surface = NULL;
|
2011-05-18 19:32:22 +00:00
|
|
|
|
|
|
|
device_manager = (GdkX11DeviceManagerXI2 *) translator;
|
|
|
|
|
|
|
|
if (xevent->type != GenericEvent ||
|
|
|
|
xevent->xcookie.extension != device_manager->opcode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ev = (XIEvent *) xevent->xcookie.data;
|
2013-05-16 14:34:05 +00:00
|
|
|
if (!ev)
|
|
|
|
return NULL;
|
2011-05-18 19:32:22 +00:00
|
|
|
|
2018-03-20 14:14:10 +00:00
|
|
|
get_event_surface (translator, ev, &surface);
|
|
|
|
return surface;
|
2011-05-18 19:32:22 +00:00
|
|
|
}
|
|
|
|
|
2011-07-14 15:49:44 +00:00
|
|
|
GdkDevice *
|
|
|
|
_gdk_x11_device_manager_xi2_lookup (GdkX11DeviceManagerXI2 *device_manager_xi2,
|
2020-07-24 13:54:49 +00:00
|
|
|
int device_id)
|
2011-07-14 15:49:44 +00:00
|
|
|
{
|
|
|
|
return g_hash_table_lookup (device_manager_xi2->id_table,
|
|
|
|
GINT_TO_POINTER (device_id));
|
|
|
|
}
|