| File: | cdk/x11/cdkdevice-xi2.c |
| Warning: | line 796, column 33 The left operand of '/' is a garbage value |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* CDK - The GIMP Drawing Kit | |||
| 2 | * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org> | |||
| 3 | * | |||
| 4 | * This library is free software; you can redistribute it and/or | |||
| 5 | * modify it under the terms of the GNU Lesser General Public | |||
| 6 | * License as published by the Free Software Foundation; either | |||
| 7 | * version 2 of the License, or (at your option) any later version. | |||
| 8 | * | |||
| 9 | * This library is distributed in the hope that it will be useful, | |||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
| 12 | * Lesser General Public License for more details. | |||
| 13 | * | |||
| 14 | * You should have received a copy of the GNU Lesser General Public | |||
| 15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | |||
| 16 | */ | |||
| 17 | ||||
| 18 | #include "config.h" | |||
| 19 | ||||
| 20 | #include "cdkx11device-xi2.h" | |||
| 21 | #include "cdkdeviceprivate.h" | |||
| 22 | #include "cdkdisplayprivate.h" | |||
| 23 | ||||
| 24 | #include "cdkintl.h" | |||
| 25 | #include "cdkasync.h" | |||
| 26 | #include "cdkprivate-x11.h" | |||
| 27 | ||||
| 28 | #include <stdlib.h> | |||
| 29 | #include <X11/Xlib.h> | |||
| 30 | #include <X11/Xutil.h> | |||
| 31 | #include <X11/extensions/XInput2.h> | |||
| 32 | ||||
| 33 | #include <math.h> | |||
| 34 | ||||
| 35 | /* for the use of round() */ | |||
| 36 | #include "fallback-c89.c" | |||
| 37 | ||||
| 38 | typedef struct _ScrollValuator ScrollValuator; | |||
| 39 | ||||
| 40 | struct _ScrollValuator | |||
| 41 | { | |||
| 42 | guint n_valuator : 4; | |||
| 43 | guint direction : 4; | |||
| 44 | guint last_value_valid : 1; | |||
| 45 | gdouble last_value; | |||
| 46 | gdouble increment; | |||
| 47 | }; | |||
| 48 | ||||
| 49 | struct _CdkX11DeviceXI2 | |||
| 50 | { | |||
| 51 | CdkDevice parent_instance; | |||
| 52 | ||||
| 53 | gint device_id; | |||
| 54 | GArray *scroll_valuators; | |||
| 55 | gdouble *last_axes; | |||
| 56 | }; | |||
| 57 | ||||
| 58 | struct _CdkX11DeviceXI2Class | |||
| 59 | { | |||
| 60 | CdkDeviceClass parent_class; | |||
| 61 | }; | |||
| 62 | ||||
| 63 | G_DEFINE_TYPE (CdkX11DeviceXI2, cdk_x11_device_xi2, CDK_TYPE_DEVICE)static void cdk_x11_device_xi2_init (CdkX11DeviceXI2 *self); static void cdk_x11_device_xi2_class_init (CdkX11DeviceXI2Class *klass ); static GType cdk_x11_device_xi2_get_type_once (void); __attribute__ ((__unused__)) static gpointer cdk_x11_device_xi2_parent_class = ((void*)0); static gint CdkX11DeviceXI2_private_offset; static void cdk_x11_device_xi2_class_intern_init (gpointer klass) { cdk_x11_device_xi2_parent_class = g_type_class_peek_parent ( klass); if (CdkX11DeviceXI2_private_offset != 0) g_type_class_adjust_private_offset (klass, &CdkX11DeviceXI2_private_offset); cdk_x11_device_xi2_class_init ((CdkX11DeviceXI2Class*) klass); } __attribute__ ((__unused__ )) static inline gpointer cdk_x11_device_xi2_get_instance_private (CdkX11DeviceXI2 *self) { return (((gpointer) ((guint8*) (self ) + (glong) (CdkX11DeviceXI2_private_offset)))); } GType cdk_x11_device_xi2_get_type (void) { static GType static_g_define_type_id = 0; if ((__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer), "Expression evaluates to false"); (void) ( 0 ? (gpointer) * (&static_g_define_type_id) : ((void*)0)) ; (!(__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id ) == sizeof (gpointer), "Expression evaluates to false"); __typeof__ (*(&static_g_define_type_id)) gapg_temp_newval; __typeof__ ((&static_g_define_type_id)) gapg_temp_atomic = (&static_g_define_type_id ); __atomic_load (gapg_temp_atomic, &gapg_temp_newval, 5) ; gapg_temp_newval; })) && g_once_init_enter_pointer ( &static_g_define_type_id)); })) ) { GType g_define_type_id = cdk_x11_device_xi2_get_type_once (); (__extension__ ({ _Static_assert (sizeof *(&static_g_define_type_id) == sizeof (gpointer) , "Expression evaluates to false"); 0 ? (void) (*(&static_g_define_type_id ) = (g_define_type_id)) : (void) 0; g_once_init_leave_pointer ((&static_g_define_type_id), (gpointer) (guintptr) (g_define_type_id )); })) ; } return static_g_define_type_id; } __attribute__ ( (__noinline__)) static GType cdk_x11_device_xi2_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((cdk_device_get_type ()), g_intern_static_string ("CdkX11DeviceXI2" ), sizeof (CdkX11DeviceXI2Class), (GClassInitFunc)(void (*)(void )) cdk_x11_device_xi2_class_intern_init, sizeof (CdkX11DeviceXI2 ), (GInstanceInitFunc)(void (*)(void)) cdk_x11_device_xi2_init , (GTypeFlags) 0); { {{};} } return g_define_type_id; } | |||
| 64 | ||||
| 65 | ||||
| 66 | static void cdk_x11_device_xi2_finalize (GObject *object); | |||
| 67 | static void cdk_x11_device_xi2_get_property (GObject *object, | |||
| 68 | guint prop_id, | |||
| 69 | GValue *value, | |||
| 70 | GParamSpec *pspec); | |||
| 71 | static void cdk_x11_device_xi2_set_property (GObject *object, | |||
| 72 | guint prop_id, | |||
| 73 | const GValue *value, | |||
| 74 | GParamSpec *pspec); | |||
| 75 | ||||
| 76 | static void cdk_x11_device_xi2_get_state (CdkDevice *device, | |||
| 77 | CdkWindow *window, | |||
| 78 | gdouble *axes, | |||
| 79 | CdkModifierType *mask); | |||
| 80 | static void cdk_x11_device_xi2_set_window_cursor (CdkDevice *device, | |||
| 81 | CdkWindow *window, | |||
| 82 | CdkCursor *cursor); | |||
| 83 | static void cdk_x11_device_xi2_warp (CdkDevice *device, | |||
| 84 | CdkScreen *screen, | |||
| 85 | gdouble x, | |||
| 86 | gdouble y); | |||
| 87 | static void cdk_x11_device_xi2_query_state (CdkDevice *device, | |||
| 88 | CdkWindow *window, | |||
| 89 | CdkWindow **root_window, | |||
| 90 | CdkWindow **child_window, | |||
| 91 | gdouble *root_x, | |||
| 92 | gdouble *root_y, | |||
| 93 | gdouble *win_x, | |||
| 94 | gdouble *win_y, | |||
| 95 | CdkModifierType *mask); | |||
| 96 | ||||
| 97 | static CdkGrabStatus cdk_x11_device_xi2_grab (CdkDevice *device, | |||
| 98 | CdkWindow *window, | |||
| 99 | gboolean owner_events, | |||
| 100 | CdkEventMask event_mask, | |||
| 101 | CdkWindow *confine_to, | |||
| 102 | CdkCursor *cursor, | |||
| 103 | guint32 time_); | |||
| 104 | static void cdk_x11_device_xi2_ungrab (CdkDevice *device, | |||
| 105 | guint32 time_); | |||
| 106 | ||||
| 107 | static CdkWindow * cdk_x11_device_xi2_window_at_position (CdkDevice *device, | |||
| 108 | gdouble *win_x, | |||
| 109 | gdouble *win_y, | |||
| 110 | CdkModifierType *mask, | |||
| 111 | gboolean get_toplevel); | |||
| 112 | static void cdk_x11_device_xi2_select_window_events (CdkDevice *device, | |||
| 113 | CdkWindow *window, | |||
| 114 | CdkEventMask event_mask); | |||
| 115 | ||||
| 116 | ||||
| 117 | enum { | |||
| 118 | PROP_0, | |||
| 119 | PROP_DEVICE_ID | |||
| 120 | }; | |||
| 121 | ||||
| 122 | static void | |||
| 123 | cdk_x11_device_xi2_class_init (CdkX11DeviceXI2Class *klass) | |||
| 124 | { | |||
| 125 | GObjectClass *object_class = G_OBJECT_CLASS (klass)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), (((GType) ((20) << (2)))))))); | |||
| 126 | CdkDeviceClass *device_class = CDK_DEVICE_CLASS (klass)((((CdkDeviceClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), ((cdk_device_get_type ())))))); | |||
| 127 | ||||
| 128 | object_class->finalize = cdk_x11_device_xi2_finalize; | |||
| 129 | object_class->get_property = cdk_x11_device_xi2_get_property; | |||
| 130 | object_class->set_property = cdk_x11_device_xi2_set_property; | |||
| 131 | ||||
| 132 | device_class->get_state = cdk_x11_device_xi2_get_state; | |||
| 133 | device_class->set_window_cursor = cdk_x11_device_xi2_set_window_cursor; | |||
| 134 | device_class->warp = cdk_x11_device_xi2_warp; | |||
| 135 | device_class->query_state = cdk_x11_device_xi2_query_state; | |||
| 136 | device_class->grab = cdk_x11_device_xi2_grab; | |||
| 137 | device_class->ungrab = cdk_x11_device_xi2_ungrab; | |||
| 138 | device_class->window_at_position = cdk_x11_device_xi2_window_at_position; | |||
| 139 | device_class->select_window_events = cdk_x11_device_xi2_select_window_events; | |||
| 140 | ||||
| 141 | g_object_class_install_property (object_class, | |||
| 142 | PROP_DEVICE_ID, | |||
| 143 | g_param_spec_int ("device-id", | |||
| 144 | P_("Device ID")dgettext("ctk30" "-properties","Device ID"), | |||
| 145 | P_("Device identifier")dgettext("ctk30" "-properties","Device identifier"), | |||
| 146 | 0, G_MAXINT2147483647, 0, | |||
| 147 | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); | |||
| 148 | } | |||
| 149 | ||||
| 150 | static void | |||
| 151 | cdk_x11_device_xi2_init (CdkX11DeviceXI2 *device) | |||
| 152 | { | |||
| 153 | device->scroll_valuators = g_array_new (FALSE(0), FALSE(0), sizeof (ScrollValuator)); | |||
| 154 | } | |||
| 155 | ||||
| 156 | static void | |||
| 157 | cdk_x11_device_xi2_finalize (GObject *object) | |||
| 158 | { | |||
| 159 | CdkX11DeviceXI2 *device = CDK_X11_DEVICE_XI2 (object)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 160 | ||||
| 161 | g_array_free (device->scroll_valuators, TRUE(!(0))); | |||
| 162 | g_free (device->last_axes)(__builtin_object_size ((device->last_axes), 0) != ((size_t ) - 1)) ? g_free_sized (device->last_axes, __builtin_object_size ((device->last_axes), 0)) : (g_free) (device->last_axes ); | |||
| 163 | ||||
| 164 | G_OBJECT_CLASS (cdk_x11_device_xi2_parent_class)((((GObjectClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((cdk_x11_device_xi2_parent_class)), (((GType) ((20) << (2))))))))->finalize (object); | |||
| 165 | } | |||
| 166 | ||||
| 167 | static void | |||
| 168 | cdk_x11_device_xi2_get_property (GObject *object, | |||
| 169 | guint prop_id, | |||
| 170 | GValue *value, | |||
| 171 | GParamSpec *pspec) | |||
| 172 | { | |||
| 173 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (object)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 174 | ||||
| 175 | switch (prop_id) | |||
| 176 | { | |||
| 177 | case PROP_DEVICE_ID: | |||
| 178 | g_value_set_int (value, device_xi2->device_id); | |||
| 179 | break; | |||
| 180 | default: | |||
| 181 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "cdkdevice-xi2.c", 181, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); | |||
| 182 | break; | |||
| 183 | } | |||
| 184 | } | |||
| 185 | ||||
| 186 | static void | |||
| 187 | cdk_x11_device_xi2_set_property (GObject *object, | |||
| 188 | guint prop_id, | |||
| 189 | const GValue *value, | |||
| 190 | GParamSpec *pspec) | |||
| 191 | { | |||
| 192 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (object)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 193 | ||||
| 194 | switch (prop_id) | |||
| 195 | { | |||
| 196 | case PROP_DEVICE_ID: | |||
| 197 | device_xi2->device_id = g_value_get_int (value); | |||
| 198 | break; | |||
| 199 | default: | |||
| 200 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec)do { GObject *_glib__object = (GObject*) ((object)); GParamSpec *_glib__pspec = (GParamSpec*) ((pspec)); guint _glib__property_id = ((prop_id)); g_warning ("%s:%d: invalid %s id %u for \"%s\" of type '%s' in '%s'" , "cdkdevice-xi2.c", 200, ("property"), _glib__property_id, _glib__pspec ->name, g_type_name ((((((GTypeClass*) (((GTypeInstance*) ( _glib__pspec))->g_class))->g_type)))), (g_type_name ((( (((GTypeClass*) (((GTypeInstance*) (_glib__object))->g_class ))->g_type)))))); } while (0); | |||
| 201 | break; | |||
| 202 | } | |||
| 203 | } | |||
| 204 | ||||
| 205 | static void | |||
| 206 | cdk_x11_device_xi2_get_state (CdkDevice *device, | |||
| 207 | CdkWindow *window, | |||
| 208 | gdouble *axes, | |||
| 209 | CdkModifierType *mask) | |||
| 210 | { | |||
| 211 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (device)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 212 | ||||
| 213 | if (axes) | |||
| 214 | { | |||
| 215 | CdkDisplay *display; | |||
| 216 | XIDeviceInfo *info; | |||
| 217 | gint i, j, ndevices; | |||
| 218 | ||||
| 219 | display = cdk_device_get_display (device); | |||
| 220 | ||||
| 221 | cdk_x11_display_error_trap_push (display); | |||
| 222 | info = XIQueryDevice (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), | |||
| 223 | device_xi2->device_id, &ndevices); | |||
| 224 | cdk_x11_display_error_trap_pop_ignored (display); | |||
| 225 | ||||
| 226 | for (i = 0, j = 0; info && i < info->num_classes; i++) | |||
| 227 | { | |||
| 228 | XIAnyClassInfo *class_info = info->classes[i]; | |||
| 229 | CdkAxisUse use; | |||
| 230 | gdouble value; | |||
| 231 | ||||
| 232 | if (class_info->type != XIValuatorClass2) | |||
| 233 | continue; | |||
| 234 | ||||
| 235 | value = ((XIValuatorClassInfo *) class_info)->value; | |||
| 236 | use = cdk_device_get_axis_use (device, j); | |||
| 237 | ||||
| 238 | switch (use) | |||
| 239 | { | |||
| 240 | case CDK_AXIS_X: | |||
| 241 | case CDK_AXIS_Y: | |||
| 242 | case CDK_AXIS_IGNORE: | |||
| 243 | if (cdk_device_get_mode (device) == CDK_MODE_WINDOW) | |||
| 244 | _cdk_device_translate_window_coord (device, window, j, value, &axes[j]); | |||
| 245 | else | |||
| 246 | { | |||
| 247 | gint root_x, root_y; | |||
| 248 | ||||
| 249 | /* FIXME: Maybe root coords chaching should happen here */ | |||
| 250 | cdk_window_get_origin (window, &root_x, &root_y); | |||
| 251 | _cdk_device_translate_screen_coord (device, window, | |||
| 252 | root_x, root_y, | |||
| 253 | j, value, | |||
| 254 | &axes[j]); | |||
| 255 | } | |||
| 256 | break; | |||
| 257 | default: | |||
| 258 | _cdk_device_translate_axis (device, j, value, &axes[j]); | |||
| 259 | break; | |||
| 260 | } | |||
| 261 | ||||
| 262 | j++; | |||
| 263 | } | |||
| 264 | ||||
| 265 | if (info) | |||
| 266 | XIFreeDeviceInfo (info); | |||
| 267 | } | |||
| 268 | ||||
| 269 | if (mask) | |||
| 270 | cdk_x11_device_xi2_query_state (device, window, | |||
| 271 | NULL((void*)0), NULL((void*)0), | |||
| 272 | NULL((void*)0), NULL((void*)0), | |||
| 273 | NULL((void*)0), NULL((void*)0), | |||
| 274 | mask); | |||
| 275 | } | |||
| 276 | ||||
| 277 | static void | |||
| 278 | cdk_x11_device_xi2_set_window_cursor (CdkDevice *device, | |||
| 279 | CdkWindow *window, | |||
| 280 | CdkCursor *cursor) | |||
| 281 | { | |||
| 282 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (device)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 283 | ||||
| 284 | /* Non-master devices don't have a cursor */ | |||
| 285 | if (cdk_device_get_device_type (device) != CDK_DEVICE_TYPE_MASTER) | |||
| 286 | return; | |||
| 287 | ||||
| 288 | if (cursor) | |||
| 289 | XIDefineCursor (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 290 | device_xi2->device_id, | |||
| 291 | CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid), | |||
| 292 | cdk_x11_cursor_get_xcursor (cursor)); | |||
| 293 | else | |||
| 294 | { | |||
| 295 | /* While a grab is active, a NULL cursor on the grab window itself | |||
| 296 | * must not strip the cursor the grab defined there: update_cursor() | |||
| 297 | * sends it when the pointer hovers cursor-less windows of the | |||
| 298 | * grabbed hierarchy, and undefining would make the server walk past | |||
| 299 | * the grab window up to its ancestors, where the window manager | |||
| 300 | * frame windows can carry a stale cursor. Grabs taken with an | |||
| 301 | * explicit cursor show that cursor regardless of the window | |||
| 302 | * attributes, so their grab window is left untouched as well. On | |||
| 303 | * any other window a NULL applies the cursor the grab was taken | |||
| 304 | * with: cursor-less windows applying their cursor while the grab | |||
| 305 | * lasts keep that image instead of walking up the window ancestors, | |||
| 306 | * where the window manager frame windows can carry a stale cursor. */ | |||
| 307 | CdkDisplay *display = cdk_device_get_display (device); | |||
| 308 | CdkDeviceGrabInfo *grab; | |||
| 309 | Cursor grab_cursor = None0L; | |||
| 310 | ||||
| 311 | grab = _cdk_display_get_last_device_grab (display, device); | |||
| 312 | if (grab != NULL((void*)0)) | |||
| 313 | { | |||
| 314 | if (window == grab->window) | |||
| 315 | return; | |||
| 316 | ||||
| 317 | grab_cursor = _cdk_x11_display_get_grab_current_cursor (display); | |||
| 318 | } | |||
| 319 | ||||
| 320 | if (grab_cursor != None0L) | |||
| 321 | XIDefineCursor (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 322 | device_xi2->device_id, | |||
| 323 | CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid), | |||
| 324 | grab_cursor); | |||
| 325 | else if (cdk_window_get_window_type (window) == CDK_WINDOW_TOPLEVEL) | |||
| 326 | { | |||
| 327 | /* Outside of grabs, leaving one of our own toplevels bare hands | |||
| 328 | * the cursor lookup to the server, which resolves it walking up | |||
| 329 | * the window's ancestors: the first window beyond our toplevel | |||
| 330 | * is the window manager frame, carrying whatever cursor the WM | |||
| 331 | * applied last on the side the pointer crossed. The WM stops | |||
| 332 | * receiving pointer events for as long as one of our grabs | |||
| 333 | * lasts, so that image is frozen meanwhile and can be stale by | |||
| 334 | * the time the grab ends: with the pointer parked on a resize | |||
| 335 | * border, opening a menu with the keyboard and clicking off it | |||
| 336 | * into the window makes update_cursor() strip the remembered | |||
| 337 | * image the grab applied on the following enter, and the | |||
| 338 | * frame's stale resize cursor then shows up all over the client | |||
| 339 | * area until the pointer reaches the title bar or a corner and | |||
| 340 | * the WM redefines its frame cursor. Define the theme's default | |||
| 341 | * arrow instead: it is the image the server would show walking | |||
| 342 | * past the bare toplevel anyway, and it keeps the frame windows | |||
| 343 | * out of the lookup for as long as the pointer is over our | |||
| 344 | * windows, whatever the frame carries. A theme that fails to | |||
| 345 | * provide the arrow keeps the old behavior. */ | |||
| 346 | CdkCursor *arrow = _cdk_x11_display_get_default_arrow_cursor (display); | |||
| 347 | ||||
| 348 | if (arrow != NULL((void*)0)) | |||
| 349 | XIDefineCursor (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 350 | device_xi2->device_id, | |||
| 351 | CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid), | |||
| 352 | cdk_x11_cursor_get_xcursor (arrow)); | |||
| 353 | else | |||
| 354 | XIUndefineCursor (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 355 | device_xi2->device_id, | |||
| 356 | CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid)); | |||
| 357 | } | |||
| 358 | else | |||
| 359 | XIUndefineCursor (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 360 | device_xi2->device_id, | |||
| 361 | CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid)); | |||
| 362 | } | |||
| 363 | } | |||
| 364 | ||||
| 365 | static void | |||
| 366 | cdk_x11_device_xi2_warp (CdkDevice *device, | |||
| 367 | CdkScreen *screen, | |||
| 368 | gdouble x, | |||
| 369 | gdouble y) | |||
| 370 | { | |||
| 371 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (device)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 372 | Window dest; | |||
| 373 | ||||
| 374 | dest = CDK_WINDOW_XID (cdk_screen_get_root_window (screen))(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((cdk_screen_get_root_window (screen))), ( (cdk_window_get_type ()))))))->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid); | |||
| 375 | ||||
| 376 | XIWarpPointer (CDK_SCREEN_XDISPLAY (screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->xdisplay ), | |||
| 377 | device_xi2->device_id, | |||
| 378 | None0L, dest, | |||
| 379 | 0, 0, 0, 0, | |||
| 380 | round (x * CDK_X11_SCREEN(screen)((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->window_scale), | |||
| 381 | round (y * CDK_X11_SCREEN(screen)((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->window_scale)); | |||
| 382 | } | |||
| 383 | ||||
| 384 | static void | |||
| 385 | cdk_x11_device_xi2_query_state (CdkDevice *device, | |||
| 386 | CdkWindow *window, | |||
| 387 | CdkWindow **root_window, | |||
| 388 | CdkWindow **child_window, | |||
| 389 | gdouble *root_x, | |||
| 390 | gdouble *root_y, | |||
| 391 | gdouble *win_x, | |||
| 392 | gdouble *win_y, | |||
| 393 | CdkModifierType *mask) | |||
| 394 | { | |||
| 395 | CdkWindowImplX11 *impl = CDK_WINDOW_IMPL_X11 (window->impl)((((CdkWindowImplX11*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((window->impl)), ((cdk_window_impl_x11_get_type ())))))); | |||
| 396 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (device)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 397 | CdkDisplay *display; | |||
| 398 | CdkScreen *default_screen; | |||
| 399 | Window xroot_window, xchild_window; | |||
| 400 | gdouble xroot_x, xroot_y, xwin_x, xwin_y; | |||
| 401 | XIButtonState button_state; | |||
| 402 | XIModifierState mod_state; | |||
| 403 | XIGroupState group_state; | |||
| 404 | ||||
| 405 | display = cdk_window_get_display (window); | |||
| 406 | default_screen = cdk_display_get_default_screen (display); | |||
| 407 | ||||
| 408 | if (cdk_device_get_device_type (device) == CDK_DEVICE_TYPE_SLAVE) | |||
| 409 | { | |||
| 410 | CdkDevice *master = cdk_device_get_associated_device (device); | |||
| 411 | ||||
| 412 | if (master) | |||
| 413 | _cdk_device_query_state (master, window, root_window, child_window, | |||
| 414 | root_x, root_y, win_x, win_y, mask); | |||
| 415 | return; | |||
| 416 | } | |||
| 417 | ||||
| 418 | if (!CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->trusted_client || | |||
| 419 | !XIQueryPointer (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 420 | device_xi2->device_id, | |||
| 421 | CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid), | |||
| 422 | &xroot_window, | |||
| 423 | &xchild_window, | |||
| 424 | &xroot_x, &xroot_y, | |||
| 425 | &xwin_x, &xwin_y, | |||
| 426 | &button_state, | |||
| 427 | &mod_state, | |||
| 428 | &group_state)) | |||
| 429 | { | |||
| 430 | XSetWindowAttributes attributes; | |||
| 431 | Display *xdisplay; | |||
| 432 | Window xwindow, w; | |||
| 433 | ||||
| 434 | /* FIXME: untrusted clients not multidevice-safe */ | |||
| 435 | xdisplay = CDK_SCREEN_XDISPLAY (default_screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((default_screen)), ((cdk_x11_screen_get_type ()))))))-> xdisplay); | |||
| 436 | xwindow = CDK_SCREEN_XROOTWIN (default_screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((default_screen)), ((cdk_x11_screen_get_type ()))))))-> xroot_window); | |||
| 437 | ||||
| 438 | w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0, | |||
| 439 | CopyFromParent0L, InputOnly2, CopyFromParent0L, | |||
| 440 | 0, &attributes); | |||
| 441 | XIQueryPointer (xdisplay, device_xi2->device_id, | |||
| 442 | w, | |||
| 443 | &xroot_window, | |||
| 444 | &xchild_window, | |||
| 445 | &xroot_x, &xroot_y, | |||
| 446 | &xwin_x, &xwin_y, | |||
| 447 | &button_state, | |||
| 448 | &mod_state, | |||
| 449 | &group_state); | |||
| 450 | XDestroyWindow (xdisplay, w); | |||
| 451 | } | |||
| 452 | ||||
| 453 | if (root_window) | |||
| 454 | *root_window = cdk_x11_window_lookup_for_display (display, xroot_window); | |||
| 455 | ||||
| 456 | if (child_window) | |||
| 457 | *child_window = cdk_x11_window_lookup_for_display (display, xchild_window); | |||
| 458 | ||||
| 459 | if (root_x) | |||
| 460 | *root_x = xroot_x / impl->window_scale; | |||
| 461 | ||||
| 462 | if (root_y) | |||
| 463 | *root_y = xroot_y / impl->window_scale; | |||
| 464 | ||||
| 465 | if (win_x) | |||
| 466 | *win_x = xwin_x / impl->window_scale; | |||
| 467 | ||||
| 468 | if (win_y) | |||
| 469 | *win_y = xwin_y / impl->window_scale; | |||
| 470 | ||||
| 471 | if (mask) | |||
| 472 | *mask = _cdk_x11_device_xi2_translate_state (&mod_state, &button_state, &group_state); | |||
| 473 | ||||
| 474 | free (button_state.mask); | |||
| 475 | } | |||
| 476 | ||||
| 477 | static CdkGrabStatus | |||
| 478 | cdk_x11_device_xi2_grab (CdkDevice *device, | |||
| 479 | CdkWindow *window, | |||
| 480 | gboolean owner_events, | |||
| 481 | CdkEventMask event_mask, | |||
| 482 | CdkWindow *confine_to G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 483 | CdkCursor *cursor, | |||
| 484 | guint32 time_) | |||
| 485 | { | |||
| 486 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (device)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 487 | CdkX11DeviceManagerXI2 *device_manager_xi2; | |||
| 488 | CdkDisplay *display; | |||
| 489 | XIEventMask mask; | |||
| 490 | Window xwindow; | |||
| 491 | Cursor xcursor; | |||
| 492 | Cursor grab_cursor = None0L; | |||
| 493 | CdkCursor *arrow; | |||
| 494 | gint status; | |||
| 495 | ||||
| 496 | display = cdk_device_get_display (device); | |||
| 497 | G_GNUC_BEGIN_IGNORE_DEPRECATIONSclang diagnostic push
clang diagnostic ignored "-Wdeprecated-declarations" ; | |||
| 498 | device_manager_xi2 = CDK_X11_DEVICE_MANAGER_XI2 (cdk_display_get_device_manager (display))((((CdkX11DeviceManagerXI2*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((cdk_display_get_device_manager (display) )), ((cdk_x11_device_manager_xi2_get_type ())))))); | |||
| 499 | G_GNUC_END_IGNORE_DEPRECATIONSclang diagnostic pop ; | |||
| 500 | ||||
| 501 | /* FIXME: confine_to is actually unused */ | |||
| 502 | ||||
| 503 | xwindow = CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid); | |||
| 504 | ||||
| 505 | if (!cursor) | |||
| 506 | xcursor = None0L; | |||
| 507 | else | |||
| 508 | { | |||
| 509 | _cdk_x11_cursor_update_theme (cursor); | |||
| 510 | xcursor = cdk_x11_cursor_get_xcursor (cursor); | |||
| 511 | } | |||
| 512 | ||||
| 513 | if (xcursor == None0L && | |||
| 514 | cdk_device_get_source (device) != CDK_SOURCE_KEYBOARD) | |||
| 515 | { | |||
| 516 | /* A grab without an explicit cursor makes the server display, for | |||
| 517 | * every window outside the grabbed window, the cursor of the grab | |||
| 518 | * window walking up its ancestors, and a grab window with no cursor | |||
| 519 | * of its own keeps walking up past it. The grab window here is the | |||
| 520 | * native toplevel of the application, and its ancestors are the | |||
| 521 | * window manager frame windows, whose cursor is whatever arrow the | |||
| 522 | * WM applied last on the frame side the pointer crossed; a stale | |||
| 523 | * cursor there then shows up all over the screen while the grab is | |||
| 524 | * active (e.g. menus opened with the keyboard while the pointer is | |||
| 525 | * parked outside the window). Define the theme's default arrow on | |||
| 526 | * the grab window so that does not happen, whatever the pointer is | |||
| 527 | * showing: an application cursor of this client, one of another | |||
| 528 | * client, or a cursor of the frame must not be pinned over the | |||
| 529 | * whole screen by a keyboard-driven grab. The arrow also matches | |||
| 530 | * what a click does under the grab, the first click on a window of | |||
| 531 | * another client only dismisses the menu. Inside the application | |||
| 532 | * the per-window cursors keep working through update_cursor(), | |||
| 533 | * because the cursor argument passed to XIGrabDevice stays None. */ | |||
| 534 | arrow = _cdk_x11_display_get_default_arrow_cursor (display); | |||
| 535 | ||||
| 536 | if (arrow != NULL((void*)0)) | |||
| 537 | grab_cursor = cdk_x11_cursor_get_xcursor (arrow); | |||
| 538 | ||||
| 539 | /* A theme that fails to provide the default arrow falls back to | |||
| 540 | * freezing the exact image the pointer shows: the visible cursor | |||
| 541 | * does not change at all, the stale frame cursor does not come | |||
| 542 | * back, and the frozen image stays for as long as the grab | |||
| 543 | * lasts. */ | |||
| 544 | if (grab_cursor == None0L) | |||
| 545 | grab_cursor = _cdk_x11_display_get_current_cursor (display); | |||
| 546 | ||||
| 547 | if (grab_cursor != None0L) | |||
| 548 | XIDefineCursor (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), | |||
| 549 | device_xi2->device_id, | |||
| 550 | xwindow, | |||
| 551 | grab_cursor); | |||
| 552 | } | |||
| 553 | ||||
| 554 | mask.deviceid = device_xi2->device_id; | |||
| 555 | mask.mask = _cdk_x11_device_xi2_translate_event_mask (device_manager_xi2, | |||
| 556 | event_mask, | |||
| 557 | &mask.mask_len); | |||
| 558 | ||||
| 559 | #ifdef G_ENABLE_DEBUG1 | |||
| 560 | if (CDK_DEBUG_CHECK (NOGRABS)(_cdk_debug_flags & CDK_DEBUG_NOGRABS)) | |||
| 561 | status = GrabSuccess0; | |||
| 562 | else | |||
| 563 | #endif | |||
| 564 | status = XIGrabDevice (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), | |||
| 565 | device_xi2->device_id, | |||
| 566 | xwindow, | |||
| 567 | time_, | |||
| 568 | xcursor, | |||
| 569 | GrabModeAsync1, GrabModeAsync1, | |||
| 570 | owner_events, | |||
| 571 | &mask); | |||
| 572 | ||||
| 573 | if (status == GrabSuccess0 && | |||
| 574 | cdk_device_get_source (device) != CDK_SOURCE_KEYBOARD) | |||
| 575 | { | |||
| 576 | /* Remember the cursor the grab was taken with: cursor-less windows | |||
| 577 | * applying their cursor while the grab is active keep that image | |||
| 578 | * instead of walking up the window ancestors, where the window | |||
| 579 | * manager frame windows can carry a stale cursor. A grab taken | |||
| 580 | * with an explicit cursor remembers None instead: the server shows | |||
| 581 | * that cursor regardless of the window attributes, so the windows | |||
| 582 | * applying their NULL cursor while the grab lasts are just left | |||
| 583 | * undefined. */ | |||
| 584 | _cdk_x11_display_set_grab_current_cursor (display, grab_cursor); | |||
| 585 | } | |||
| 586 | ||||
| 587 | g_free (mask.mask)(__builtin_object_size ((mask.mask), 0) != ((size_t) - 1)) ? g_free_sized (mask.mask, __builtin_object_size ((mask.mask), 0)) : (g_free ) (mask.mask); | |||
| 588 | ||||
| 589 | _cdk_x11_display_update_grab_info (display, device, status); | |||
| 590 | ||||
| 591 | return _cdk_x11_convert_grab_status (status); | |||
| 592 | } | |||
| 593 | ||||
| 594 | static void | |||
| 595 | cdk_x11_device_xi2_ungrab (CdkDevice *device, | |||
| 596 | guint32 time_) | |||
| 597 | { | |||
| 598 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (device)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 599 | CdkDisplay *display; | |||
| 600 | gulong serial; | |||
| 601 | ||||
| 602 | display = cdk_device_get_display (device); | |||
| 603 | serial = NextRequest (CDK_DISPLAY_XDISPLAY (display))(((_XPrivDisplay)((((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((display)), ((cdk_x11_display_get_type()) )))))->xdisplay)))->request + 1); | |||
| 604 | ||||
| 605 | XIUngrabDevice (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), device_xi2->device_id, time_); | |||
| 606 | ||||
| 607 | /* The device being ungrabbed can be a keyboard: releasing a keyboard grab | |||
| 608 | * while the pointer grab of the device pair is still active must not erase | |||
| 609 | * the image the pointer grab remembered, or the cursor-less windows of the | |||
| 610 | * grabbed hierarchy applying their cursor for the rest of the grab are | |||
| 611 | * undefined instead and walk up the window ancestors, where the window | |||
| 612 | * manager frame windows can carry a stale cursor. The core backend only | |||
| 613 | * clears on pointer ungrabs too, and the XI2 grab only remembers the | |||
| 614 | * cursor on non-keyboard devices. */ | |||
| 615 | if (cdk_device_get_source (device) != CDK_SOURCE_KEYBOARD) | |||
| 616 | _cdk_x11_display_set_grab_current_cursor (display, None0L); | |||
| 617 | ||||
| 618 | _cdk_x11_display_update_grab_info_ungrab (display, device, time_, serial); | |||
| 619 | } | |||
| 620 | ||||
| 621 | static CdkWindow * | |||
| 622 | cdk_x11_device_xi2_window_at_position (CdkDevice *device, | |||
| 623 | gdouble *win_x, | |||
| 624 | gdouble *win_y, | |||
| 625 | CdkModifierType *mask, | |||
| 626 | gboolean get_toplevel) | |||
| 627 | { | |||
| 628 | CdkWindowImplX11 *impl; | |||
| 629 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (device)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 630 | CdkDisplay *display; | |||
| 631 | CdkScreen *screen; | |||
| 632 | Display *xdisplay; | |||
| 633 | CdkWindow *window; | |||
| 634 | Window xwindow, root, child, last = None0L; | |||
| 635 | gdouble xroot_x, xroot_y, xwin_x, xwin_y; | |||
| ||||
| 636 | XIButtonState button_state = { 0 }; | |||
| 637 | XIModifierState mod_state; | |||
| 638 | XIGroupState group_state; | |||
| 639 | Boolint retval; | |||
| 640 | ||||
| 641 | display = cdk_device_get_display (device); | |||
| 642 | screen = cdk_display_get_default_screen (display); | |||
| 643 | ||||
| 644 | cdk_x11_display_error_trap_push (display); | |||
| 645 | ||||
| 646 | /* This function really only works if the mouse pointer is held still | |||
| 647 | * during its operation. If it moves from one leaf window to another | |||
| 648 | * than we'll end up with inaccurate values for win_x, win_y | |||
| 649 | * and the result. | |||
| 650 | */ | |||
| 651 | cdk_x11_display_grab (display); | |||
| 652 | ||||
| 653 | xdisplay = CDK_SCREEN_XDISPLAY (screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->xdisplay ); | |||
| 654 | xwindow = CDK_SCREEN_XROOTWIN (screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->xroot_window ); | |||
| 655 | ||||
| 656 | if (G_LIKELY (CDK_X11_DISPLAY (display)->trusted_client)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->trusted_client )) | |||
| 657 | { | |||
| 658 | XIQueryPointer (xdisplay, | |||
| 659 | device_xi2->device_id, | |||
| 660 | xwindow, | |||
| 661 | &root, &child, | |||
| 662 | &xroot_x, &xroot_y, | |||
| 663 | &xwin_x, &xwin_y, | |||
| 664 | &button_state, | |||
| 665 | &mod_state, | |||
| 666 | &group_state); | |||
| 667 | ||||
| 668 | if (root == xwindow) | |||
| 669 | xwindow = child; | |||
| 670 | else | |||
| 671 | xwindow = root; | |||
| 672 | } | |||
| 673 | else | |||
| 674 | { | |||
| 675 | gint width, height; | |||
| 676 | GList *toplevels, *list; | |||
| 677 | Window pointer_window; | |||
| 678 | ||||
| 679 | /* FIXME: untrusted clients case not multidevice-safe */ | |||
| 680 | pointer_window = None0L; | |||
| 681 | ||||
| 682 | screen = cdk_display_get_default_screen (display); | |||
| 683 | toplevels = cdk_screen_get_toplevel_windows (screen); | |||
| 684 | for (list = toplevels; list != NULL((void*)0); list = list->next) | |||
| 685 | { | |||
| 686 | window = CDK_WINDOW (list->data)((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((list->data)), ((cdk_window_get_type ())))))); | |||
| 687 | xwindow = CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid); | |||
| 688 | ||||
| 689 | /* Free previous button mask, if any */ | |||
| 690 | g_free (button_state.mask)(__builtin_object_size ((button_state.mask), 0) != ((size_t) - 1)) ? g_free_sized (button_state.mask, __builtin_object_size ((button_state.mask), 0)) : (g_free) (button_state.mask); | |||
| 691 | ||||
| 692 | retval = XIQueryPointer (xdisplay, | |||
| 693 | device_xi2->device_id, | |||
| 694 | xwindow, | |||
| 695 | &root, &child, | |||
| 696 | &xroot_x, &xroot_y, | |||
| 697 | &xwin_x, &xwin_y, | |||
| 698 | &button_state, | |||
| 699 | &mod_state, | |||
| 700 | &group_state); | |||
| 701 | if (!retval) | |||
| 702 | continue; | |||
| 703 | ||||
| 704 | if (child != None0L) | |||
| 705 | { | |||
| 706 | pointer_window = child; | |||
| 707 | break; | |||
| 708 | } | |||
| 709 | cdk_window_get_geometry (window, NULL((void*)0), NULL((void*)0), &width, &height); | |||
| 710 | if (xwin_x >= 0 && xwin_y >= 0 && xwin_x < width && xwin_y < height) | |||
| 711 | { | |||
| 712 | /* A childless toplevel, or below another window? */ | |||
| 713 | XSetWindowAttributes attributes; | |||
| 714 | Window w; | |||
| 715 | ||||
| 716 | free (button_state.mask); | |||
| 717 | ||||
| 718 | w = XCreateWindow (xdisplay, xwindow, (int)xwin_x, (int)xwin_y, 1, 1, 0, | |||
| 719 | CopyFromParent0L, InputOnly2, CopyFromParent0L, | |||
| 720 | 0, &attributes); | |||
| 721 | XMapWindow (xdisplay, w); | |||
| 722 | XIQueryPointer (xdisplay, | |||
| 723 | device_xi2->device_id, | |||
| 724 | xwindow, | |||
| 725 | &root, &child, | |||
| 726 | &xroot_x, &xroot_y, | |||
| 727 | &xwin_x, &xwin_y, | |||
| 728 | &button_state, | |||
| 729 | &mod_state, | |||
| 730 | &group_state); | |||
| 731 | XDestroyWindow (xdisplay, w); | |||
| 732 | if (child == w) | |||
| 733 | { | |||
| 734 | pointer_window = xwindow; | |||
| 735 | break; | |||
| 736 | } | |||
| 737 | } | |||
| 738 | ||||
| 739 | g_list_free (toplevels); | |||
| 740 | if (pointer_window != None0L) | |||
| 741 | break; | |||
| 742 | } | |||
| 743 | ||||
| 744 | xwindow = pointer_window; | |||
| 745 | } | |||
| 746 | ||||
| 747 | while (xwindow) | |||
| 748 | { | |||
| 749 | last = xwindow; | |||
| 750 | free (button_state.mask); | |||
| 751 | ||||
| 752 | retval = XIQueryPointer (xdisplay, | |||
| 753 | device_xi2->device_id, | |||
| 754 | xwindow, | |||
| 755 | &root, &xwindow, | |||
| 756 | &xroot_x, &xroot_y, | |||
| 757 | &xwin_x, &xwin_y, | |||
| 758 | &button_state, | |||
| 759 | &mod_state, | |||
| 760 | &group_state); | |||
| 761 | if (!retval) | |||
| 762 | break; | |||
| 763 | ||||
| 764 | if (get_toplevel && last != root && | |||
| 765 | (window = cdk_x11_window_lookup_for_display (display, last)) != NULL((void*)0) && | |||
| 766 | CDK_WINDOW_TYPE (window)((((CdkWindow *)(window)))->window_type) != CDK_WINDOW_FOREIGN) | |||
| 767 | { | |||
| 768 | xwindow = last; | |||
| 769 | break; | |||
| 770 | } | |||
| 771 | } | |||
| 772 | ||||
| 773 | cdk_x11_display_ungrab (display); | |||
| 774 | ||||
| 775 | if (cdk_x11_display_error_trap_pop (display) == 0) | |||
| 776 | { | |||
| 777 | window = cdk_x11_window_lookup_for_display (display, last); | |||
| 778 | impl = NULL((void*)0); | |||
| 779 | if (window) | |||
| 780 | impl = CDK_WINDOW_IMPL_X11 (window->impl)((((CdkWindowImplX11*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((window->impl)), ((cdk_window_impl_x11_get_type ())))))); | |||
| 781 | ||||
| 782 | if (mask) | |||
| 783 | *mask = _cdk_x11_device_xi2_translate_state (&mod_state, &button_state, &group_state); | |||
| 784 | ||||
| 785 | free (button_state.mask); | |||
| 786 | } | |||
| 787 | else | |||
| 788 | { | |||
| 789 | window = NULL((void*)0); | |||
| 790 | ||||
| 791 | if (mask) | |||
| 792 | *mask = 0; | |||
| 793 | } | |||
| 794 | ||||
| 795 | if (win_x) | |||
| 796 | *win_x = (window
| |||
| ||||
| 797 | ||||
| 798 | if (win_y) | |||
| 799 | *win_y = (window) ? (xwin_y / impl->window_scale) : -1; | |||
| 800 | ||||
| 801 | ||||
| 802 | return window; | |||
| 803 | } | |||
| 804 | ||||
| 805 | static void | |||
| 806 | cdk_x11_device_xi2_select_window_events (CdkDevice *device, | |||
| 807 | CdkWindow *window, | |||
| 808 | CdkEventMask event_mask) | |||
| 809 | { | |||
| 810 | CdkX11DeviceXI2 *device_xi2 = CDK_X11_DEVICE_XI2 (device)((((CdkX11DeviceXI2*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_x11_device_xi2_get_type ())))))); | |||
| 811 | CdkX11DeviceManagerXI2 *device_manager_xi2; | |||
| 812 | CdkDisplay *display; | |||
| 813 | XIEventMask evmask; | |||
| 814 | ||||
| 815 | display = cdk_device_get_display (device); | |||
| 816 | G_GNUC_BEGIN_IGNORE_DEPRECATIONSclang diagnostic push
clang diagnostic ignored "-Wdeprecated-declarations" ; | |||
| 817 | device_manager_xi2 = CDK_X11_DEVICE_MANAGER_XI2 (cdk_display_get_device_manager (display))((((CdkX11DeviceManagerXI2*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((cdk_display_get_device_manager (display) )), ((cdk_x11_device_manager_xi2_get_type ())))))); | |||
| 818 | G_GNUC_END_IGNORE_DEPRECATIONSclang diagnostic pop ; | |||
| 819 | ||||
| 820 | evmask.deviceid = device_xi2->device_id; | |||
| 821 | evmask.mask = _cdk_x11_device_xi2_translate_event_mask (device_manager_xi2, | |||
| 822 | event_mask, | |||
| 823 | &evmask.mask_len); | |||
| 824 | ||||
| 825 | XISelectEvents (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 826 | CDK_WINDOW_XID (window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((window)), ((cdk_window_get_type ())))))) ->impl)), ((cdk_window_impl_x11_get_type ()))))))->xid), | |||
| 827 | &evmask, 1); | |||
| 828 | ||||
| 829 | g_free (evmask.mask)(__builtin_object_size ((evmask.mask), 0) != ((size_t) - 1)) ? g_free_sized (evmask.mask, __builtin_object_size ((evmask.mask ), 0)) : (g_free) (evmask.mask); | |||
| 830 | } | |||
| 831 | ||||
| 832 | guchar * | |||
| 833 | _cdk_x11_device_xi2_translate_event_mask (CdkX11DeviceManagerXI2 *device_manager_xi2, | |||
| 834 | CdkEventMask event_mask, | |||
| 835 | gint *len) | |||
| 836 | { | |||
| 837 | guchar *mask; | |||
| 838 | gint minor; | |||
| 839 | ||||
| 840 | g_object_get (device_manager_xi2, "minor", &minor, NULL((void*)0)); | |||
| 841 | ||||
| 842 | *len = XIMaskLen (XI_LASTEVENT)(((32) >> 3) + 1); | |||
| 843 | mask = g_new0 (guchar, *len)((guchar *) g_malloc0_n ((*len), sizeof (guchar))); | |||
| 844 | ||||
| 845 | if (event_mask & CDK_POINTER_MOTION_MASK || | |||
| 846 | event_mask & CDK_POINTER_MOTION_HINT_MASK) | |||
| 847 | XISetMask (mask, XI_Motion)(((unsigned char*)(mask))[(6)>>3] |= (1 << ((6) & 7))); | |||
| 848 | ||||
| 849 | if (event_mask & CDK_BUTTON_MOTION_MASK || | |||
| 850 | event_mask & CDK_BUTTON1_MOTION_MASK || | |||
| 851 | event_mask & CDK_BUTTON2_MOTION_MASK || | |||
| 852 | event_mask & CDK_BUTTON3_MOTION_MASK) | |||
| 853 | { | |||
| 854 | XISetMask (mask, XI_ButtonPress)(((unsigned char*)(mask))[(4)>>3] |= (1 << ((4) & 7))); | |||
| 855 | XISetMask (mask, XI_ButtonRelease)(((unsigned char*)(mask))[(5)>>3] |= (1 << ((5) & 7))); | |||
| 856 | XISetMask (mask, XI_Motion)(((unsigned char*)(mask))[(6)>>3] |= (1 << ((6) & 7))); | |||
| 857 | } | |||
| 858 | ||||
| 859 | if (event_mask & CDK_SCROLL_MASK) | |||
| 860 | { | |||
| 861 | XISetMask (mask, XI_ButtonPress)(((unsigned char*)(mask))[(4)>>3] |= (1 << ((4) & 7))); | |||
| 862 | XISetMask (mask, XI_ButtonRelease)(((unsigned char*)(mask))[(5)>>3] |= (1 << ((5) & 7))); | |||
| 863 | } | |||
| 864 | ||||
| 865 | if (event_mask & CDK_BUTTON_PRESS_MASK) | |||
| 866 | XISetMask (mask, XI_ButtonPress)(((unsigned char*)(mask))[(4)>>3] |= (1 << ((4) & 7))); | |||
| 867 | ||||
| 868 | if (event_mask & CDK_BUTTON_RELEASE_MASK) | |||
| 869 | XISetMask (mask, XI_ButtonRelease)(((unsigned char*)(mask))[(5)>>3] |= (1 << ((5) & 7))); | |||
| 870 | ||||
| 871 | if (event_mask & CDK_KEY_PRESS_MASK) | |||
| 872 | XISetMask (mask, XI_KeyPress)(((unsigned char*)(mask))[(2)>>3] |= (1 << ((2) & 7))); | |||
| 873 | ||||
| 874 | if (event_mask & CDK_KEY_RELEASE_MASK) | |||
| 875 | XISetMask (mask, XI_KeyRelease)(((unsigned char*)(mask))[(3)>>3] |= (1 << ((3) & 7))); | |||
| 876 | ||||
| 877 | if (event_mask & CDK_ENTER_NOTIFY_MASK) | |||
| 878 | XISetMask (mask, XI_Enter)(((unsigned char*)(mask))[(7)>>3] |= (1 << ((7) & 7))); | |||
| 879 | ||||
| 880 | if (event_mask & CDK_LEAVE_NOTIFY_MASK) | |||
| 881 | XISetMask (mask, XI_Leave)(((unsigned char*)(mask))[(8)>>3] |= (1 << ((8) & 7))); | |||
| 882 | ||||
| 883 | if (event_mask & CDK_FOCUS_CHANGE_MASK) | |||
| 884 | { | |||
| 885 | XISetMask (mask, XI_FocusIn)(((unsigned char*)(mask))[(9)>>3] |= (1 << ((9) & 7))); | |||
| 886 | XISetMask (mask, XI_FocusOut)(((unsigned char*)(mask))[(10)>>3] |= (1 << ((10) & 7))); | |||
| 887 | } | |||
| 888 | ||||
| 889 | #ifdef XINPUT_2_21 | |||
| 890 | /* XInput 2.2 includes multitouch support */ | |||
| 891 | if (minor >= 2 && | |||
| 892 | event_mask & CDK_TOUCH_MASK) | |||
| 893 | { | |||
| 894 | XISetMask (mask, XI_TouchBegin)(((unsigned char*)(mask))[(18)>>3] |= (1 << ((18) & 7))); | |||
| 895 | XISetMask (mask, XI_TouchUpdate)(((unsigned char*)(mask))[(19)>>3] |= (1 << ((19) & 7))); | |||
| 896 | XISetMask (mask, XI_TouchEnd)(((unsigned char*)(mask))[(20)>>3] |= (1 << ((20) & 7))); | |||
| 897 | } | |||
| 898 | #endif /* XINPUT_2_2 */ | |||
| 899 | ||||
| 900 | return mask; | |||
| 901 | } | |||
| 902 | ||||
| 903 | guint | |||
| 904 | _cdk_x11_device_xi2_translate_state (XIModifierState *mods_state, | |||
| 905 | XIButtonState *buttons_state, | |||
| 906 | XIGroupState *group_state) | |||
| 907 | { | |||
| 908 | guint state = 0; | |||
| 909 | ||||
| 910 | if (mods_state) | |||
| 911 | state = mods_state->effective; | |||
| 912 | ||||
| 913 | if (buttons_state) | |||
| 914 | { | |||
| 915 | gint len, i; | |||
| 916 | ||||
| 917 | /* We're only interested in the first 3 buttons */ | |||
| 918 | len = MIN (3, buttons_state->mask_len * 8)(((3) < (buttons_state->mask_len * 8)) ? (3) : (buttons_state ->mask_len * 8)); | |||
| 919 | ||||
| 920 | for (i = 1; i <= len; i++) | |||
| 921 | { | |||
| 922 | if (!XIMaskIsSet (buttons_state->mask, i)(((unsigned char*)(buttons_state->mask))[(i)>>3] & (1 << ((i) & 7)))) | |||
| 923 | continue; | |||
| 924 | ||||
| 925 | switch (i) | |||
| 926 | { | |||
| 927 | case 1: | |||
| 928 | state |= CDK_BUTTON1_MASK; | |||
| 929 | break; | |||
| 930 | case 2: | |||
| 931 | state |= CDK_BUTTON2_MASK; | |||
| 932 | break; | |||
| 933 | case 3: | |||
| 934 | state |= CDK_BUTTON3_MASK; | |||
| 935 | break; | |||
| 936 | default: | |||
| 937 | break; | |||
| 938 | } | |||
| 939 | } | |||
| 940 | } | |||
| 941 | ||||
| 942 | if (group_state) | |||
| 943 | state |= (group_state->effective) << 13; | |||
| 944 | ||||
| 945 | return state; | |||
| 946 | } | |||
| 947 | ||||
| 948 | void | |||
| 949 | _cdk_x11_device_xi2_add_scroll_valuator (CdkX11DeviceXI2 *device, | |||
| 950 | guint n_valuator, | |||
| 951 | CdkScrollDirection direction, | |||
| 952 | gdouble increment) | |||
| 953 | { | |||
| 954 | ScrollValuator scroll; | |||
| 955 | ||||
| 956 | g_return_if_fail (CDK_IS_X11_DEVICE_XI2 (device))do { if (((((__extension__ ({ GTypeInstance *_inst = (GTypeInstance *) ((device)); GType _t = ((cdk_x11_device_xi2_get_type ())); gboolean _r; if (!_inst) _r = (0); else if (_inst->g_class && _inst->g_class->g_type == _t) _r = (!(0)); else _r = g_type_check_instance_is_a (_inst, _t); _r; })))))) { } else { g_return_if_fail_warning ("Cdk", ((const char*) (__func__ )), "CDK_IS_X11_DEVICE_XI2 (device)"); return; } } while (0); | |||
| 957 | g_return_if_fail (n_valuator < cdk_device_get_n_axes (CDK_DEVICE (device)))do { if ((n_valuator < cdk_device_get_n_axes (((((CdkDevice *) (void *) g_type_check_instance_cast ((GTypeInstance*) ((device )), ((cdk_device_get_type ()))))))))) { } else { g_return_if_fail_warning ("Cdk", ((const char*) (__func__)), "n_valuator < cdk_device_get_n_axes (CDK_DEVICE (device))" ); return; } } while (0); | |||
| 958 | ||||
| 959 | scroll.n_valuator = n_valuator; | |||
| 960 | scroll.direction = direction; | |||
| 961 | scroll.last_value_valid = FALSE(0); | |||
| 962 | scroll.increment = increment; | |||
| 963 | ||||
| 964 | g_array_append_val (device->scroll_valuators, scroll)g_array_append_vals (device->scroll_valuators, &(scroll ), 1); | |||
| 965 | } | |||
| 966 | ||||
| 967 | gboolean | |||
| 968 | _cdk_x11_device_xi2_get_scroll_delta (CdkX11DeviceXI2 *device, | |||
| 969 | guint n_valuator, | |||
| 970 | gdouble valuator_value, | |||
| 971 | CdkScrollDirection *direction_ret, | |||
| 972 | gdouble *delta_ret) | |||
| 973 | { | |||
| 974 | guint i; | |||
| 975 | ||||
| 976 | g_return_val_if_fail (CDK_IS_X11_DEVICE_XI2 (device), FALSE)do { if (((((__extension__ ({ GTypeInstance *_inst = (GTypeInstance *) ((device)); GType _t = ((cdk_x11_device_xi2_get_type ())); gboolean _r; if (!_inst) _r = (0); else if (_inst->g_class && _inst->g_class->g_type == _t) _r = (!(0)); else _r = g_type_check_instance_is_a (_inst, _t); _r; })))))) { } else { g_return_if_fail_warning ("Cdk", ((const char*) (__func__ )), "CDK_IS_X11_DEVICE_XI2 (device)"); return ((0)); } } while (0); | |||
| 977 | g_return_val_if_fail (n_valuator < cdk_device_get_n_axes (CDK_DEVICE (device)), FALSE)do { if ((n_valuator < cdk_device_get_n_axes (((((CdkDevice *) (void *) g_type_check_instance_cast ((GTypeInstance*) ((device )), ((cdk_device_get_type ()))))))))) { } else { g_return_if_fail_warning ("Cdk", ((const char*) (__func__)), "n_valuator < cdk_device_get_n_axes (CDK_DEVICE (device))" ); return ((0)); } } while (0); | |||
| 978 | ||||
| 979 | for (i = 0; i < device->scroll_valuators->len; i++) | |||
| 980 | { | |||
| 981 | ScrollValuator *scroll; | |||
| 982 | ||||
| 983 | scroll = &g_array_index (device->scroll_valuators, ScrollValuator, i)(((ScrollValuator*) (void *) (device->scroll_valuators)-> data) [(i)]); | |||
| 984 | ||||
| 985 | if (scroll->n_valuator == n_valuator) | |||
| 986 | { | |||
| 987 | if (direction_ret) | |||
| 988 | *direction_ret = scroll->direction; | |||
| 989 | ||||
| 990 | if (delta_ret) | |||
| 991 | *delta_ret = 0; | |||
| 992 | ||||
| 993 | if (scroll->last_value_valid) | |||
| 994 | { | |||
| 995 | if (delta_ret) | |||
| 996 | *delta_ret = (valuator_value - scroll->last_value) / scroll->increment; | |||
| 997 | ||||
| 998 | scroll->last_value = valuator_value; | |||
| 999 | } | |||
| 1000 | else | |||
| 1001 | { | |||
| 1002 | scroll->last_value = valuator_value; | |||
| 1003 | scroll->last_value_valid = TRUE(!(0)); | |||
| 1004 | } | |||
| 1005 | ||||
| 1006 | return TRUE(!(0)); | |||
| 1007 | } | |||
| 1008 | } | |||
| 1009 | ||||
| 1010 | return FALSE(0); | |||
| 1011 | } | |||
| 1012 | ||||
| 1013 | void | |||
| 1014 | _cdk_device_xi2_reset_scroll_valuators (CdkX11DeviceXI2 *device) | |||
| 1015 | { | |||
| 1016 | guint i; | |||
| 1017 | ||||
| 1018 | for (i = 0; i < device->scroll_valuators->len; i++) | |||
| 1019 | { | |||
| 1020 | ScrollValuator *scroll; | |||
| 1021 | ||||
| 1022 | scroll = &g_array_index (device->scroll_valuators, ScrollValuator, i)(((ScrollValuator*) (void *) (device->scroll_valuators)-> data) [(i)]); | |||
| 1023 | scroll->last_value_valid = FALSE(0); | |||
| 1024 | } | |||
| 1025 | } | |||
| 1026 | ||||
| 1027 | void | |||
| 1028 | _cdk_device_xi2_unset_scroll_valuators (CdkX11DeviceXI2 *device) | |||
| 1029 | { | |||
| 1030 | if (device->scroll_valuators->len > 0) | |||
| 1031 | g_array_remove_range (device->scroll_valuators, 0, | |||
| 1032 | device->scroll_valuators->len); | |||
| 1033 | } | |||
| 1034 | ||||
| 1035 | gint | |||
| 1036 | _cdk_x11_device_xi2_get_id (CdkX11DeviceXI2 *device) | |||
| 1037 | { | |||
| 1038 | g_return_val_if_fail (CDK_IS_X11_DEVICE_XI2 (device), 0)do { if (((((__extension__ ({ GTypeInstance *_inst = (GTypeInstance *) ((device)); GType _t = ((cdk_x11_device_xi2_get_type ())); gboolean _r; if (!_inst) _r = (0); else if (_inst->g_class && _inst->g_class->g_type == _t) _r = (!(0)); else _r = g_type_check_instance_is_a (_inst, _t); _r; })))))) { } else { g_return_if_fail_warning ("Cdk", ((const char*) (__func__ )), "CDK_IS_X11_DEVICE_XI2 (device)"); return (0); } } while ( 0); | |||
| 1039 | ||||
| 1040 | return device->device_id; | |||
| 1041 | } | |||
| 1042 | ||||
| 1043 | gdouble | |||
| 1044 | cdk_x11_device_xi2_get_last_axis_value (CdkX11DeviceXI2 *device, | |||
| 1045 | gint n_axis) | |||
| 1046 | { | |||
| 1047 | if (n_axis >= cdk_device_get_n_axes (CDK_DEVICE (device)((((CdkDevice*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device)), ((cdk_device_get_type ())))))))) | |||
| 1048 | return 0; | |||
| 1049 | ||||
| 1050 | if (!device->last_axes) | |||
| 1051 | return 0; | |||
| 1052 | ||||
| 1053 | return device->last_axes[n_axis]; | |||
| 1054 | } | |||
| 1055 | ||||
| 1056 | void | |||
| 1057 | cdk_x11_device_xi2_store_axes (CdkX11DeviceXI2 *device, | |||
| 1058 | gdouble *axes, | |||
| 1059 | gint n_axes) | |||
| 1060 | { | |||
| 1061 | g_free (device->last_axes)(__builtin_object_size ((device->last_axes), 0) != ((size_t ) - 1)) ? g_free_sized (device->last_axes, __builtin_object_size ((device->last_axes), 0)) : (g_free) (device->last_axes ); | |||
| 1062 | ||||
| 1063 | if (axes && n_axes) | |||
| 1064 | device->last_axes = g_memdup2 (axes, sizeof (gdouble) * n_axes); | |||
| 1065 | else | |||
| 1066 | device->last_axes = NULL((void*)0); | |||
| 1067 | } |