5 #include "clutter-input-device-x11.h"
7 #include "clutter-debug.h"
8 #include "clutter-device-manager-private.h"
9 #include "clutter-private.h"
12 #include <X11/extensions/XInput.h>
15 typedef struct _ClutterInputDeviceClass ClutterInputDeviceX11Class;
17 /* a specific X11 input device */
18 struct _ClutterInputDeviceX11
20 ClutterInputDevice device;
24 XEventClass xevent_list[5]; /* MAX 5 event types */
40 static GParamSpec *obj_props[PROP_LAST];
42 G_DEFINE_TYPE (ClutterInputDeviceX11,
43 clutter_input_device_x11,
44 CLUTTER_TYPE_INPUT_DEVICE);
47 clutter_input_device_x11_set_property (GObject *gobject,
52 ClutterInputDeviceX11 *self = CLUTTER_INPUT_DEVICE_X11 (gobject);
57 self->is_core = g_value_get_boolean (value);
61 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
67 clutter_input_device_x11_get_property (GObject *gobject,
72 ClutterInputDeviceX11 *self = CLUTTER_INPUT_DEVICE_X11 (gobject);
77 g_value_set_boolean (value, self->is_core);
81 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
87 clutter_input_device_x11_class_init (ClutterInputDeviceX11Class *klass)
89 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
92 gobject_class->set_property = clutter_input_device_x11_set_property;
93 gobject_class->get_property = clutter_input_device_x11_get_property;
95 pspec = g_param_spec_boolean ("is-core",
97 "Whether the device is a core one",
99 CLUTTER_PARAM_READWRITE |
100 G_PARAM_CONSTRUCT_ONLY);
101 obj_props[PROP_IS_CORE] = pspec;
102 g_object_class_install_property (gobject_class, PROP_IS_CORE, pspec);
106 clutter_input_device_x11_init (ClutterInputDeviceX11 *self)
108 self->is_core = FALSE;
112 _clutter_input_device_x11_construct (ClutterInputDevice *device,
113 ClutterBackendX11 *backend)
118 ClutterInputDeviceX11 *device_x11;
119 XDevice *x_device = NULL;
123 device_x11 = CLUTTER_INPUT_DEVICE_X11 (device);
124 device_id = clutter_input_device_get_device_id (device);
126 clutter_x11_trap_x_errors ();
128 /* retrieve the X11 device */
129 x_device = XOpenDevice (backend->xdpy, device_id);
131 if (clutter_x11_untrap_x_errors () || x_device == NULL)
133 CLUTTER_NOTE (BACKEND, "Unable to open device %i", device_id);
137 device_x11->xdevice = x_device;
139 CLUTTER_NOTE (BACKEND,
140 "Registering XINPUT device with XID: %li",
141 x_device->device_id);
143 /* We must go through all the classes supported by this device and
144 * register the appropriate events we want. Each class only appears
145 * once. We need to store the types with the stage since they are
146 * created dynamically by the server. They are not device specific.
148 for (i = 0; i < x_device->num_classes; i++)
150 XInputClassInfo *xclass_info = x_device->classes + i;
151 int *button_press, *button_release, *motion_notify;
152 int *key_press, *key_release;
155 &backend->event_types[CLUTTER_X11_XINPUT_BUTTON_PRESS_EVENT];
157 &backend->event_types[CLUTTER_X11_XINPUT_BUTTON_RELEASE_EVENT];
159 &backend->event_types[CLUTTER_X11_XINPUT_MOTION_NOTIFY_EVENT];
162 &backend->event_types[CLUTTER_X11_XINPUT_KEY_PRESS_EVENT];
164 &backend->event_types[CLUTTER_X11_XINPUT_KEY_RELEASE_EVENT];
166 switch (xclass_info->input_class)
168 /* event though XInput 1.x is broken for keyboard-like devices
169 * it might still be useful to track them down; the core keyboard
170 * will handle the right events anyway
173 DeviceKeyPress (x_device,
175 device_x11->xevent_list[n_events]);
178 DeviceKeyRelease (x_device,
180 device_x11->xevent_list[n_events]);
185 DeviceButtonPress (x_device,
187 device_x11->xevent_list[n_events]);
190 DeviceButtonRelease (x_device,
192 device_x11->xevent_list[n_events]);
197 DeviceMotionNotify (x_device,
199 device_x11->xevent_list[n_events]);
205 device_x11->num_events = n_events;
206 #endif /* HAVE_XINPUT */
212 _clutter_input_device_x11_select_events (ClutterInputDevice *device,
213 ClutterBackendX11 *backend_x11,
217 ClutterInputDeviceX11 *device_x11;
219 device_x11 = CLUTTER_INPUT_DEVICE_X11 (device);
221 if (device_x11->xdevice == None || device_x11->num_events == 0)
224 XSelectExtensionEvent (backend_x11->xdpy, xwin,
225 device_x11->xevent_list,
226 device_x11->num_events);
227 #endif /* HAVE_XINPUT */