| File: | cdk/x11/cdkdevice-core-x11.c |
| Warning: | line 668, column 40 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 | ||||
| 21 | #include "cdkx11device-core.h" | |||
| 22 | #include "cdkdeviceprivate.h" | |||
| 23 | #include "cdkdisplayprivate.h" | |||
| 24 | ||||
| 25 | #include "cdkinternals.h" | |||
| 26 | #include "cdkwindow.h" | |||
| 27 | #include "cdkprivate-x11.h" | |||
| 28 | #include "cdkasync.h" | |||
| 29 | ||||
| 30 | #include <math.h> | |||
| 31 | ||||
| 32 | /* for the use of round() */ | |||
| 33 | #include "fallback-c89.c" | |||
| 34 | ||||
| 35 | struct _CdkX11DeviceCore | |||
| 36 | { | |||
| 37 | CdkDevice parent_instance; | |||
| 38 | }; | |||
| 39 | ||||
| 40 | struct _CdkX11DeviceCoreClass | |||
| 41 | { | |||
| 42 | CdkDeviceClass parent_class; | |||
| 43 | }; | |||
| 44 | ||||
| 45 | static gboolean cdk_x11_device_core_get_history (CdkDevice *device, | |||
| 46 | CdkWindow *window, | |||
| 47 | guint32 start, | |||
| 48 | guint32 stop, | |||
| 49 | CdkTimeCoord ***events, | |||
| 50 | gint *n_events); | |||
| 51 | static void cdk_x11_device_core_get_state (CdkDevice *device, | |||
| 52 | CdkWindow *window, | |||
| 53 | gdouble *axes, | |||
| 54 | CdkModifierType *mask); | |||
| 55 | static void cdk_x11_device_core_set_window_cursor (CdkDevice *device, | |||
| 56 | CdkWindow *window, | |||
| 57 | CdkCursor *cursor); | |||
| 58 | static void cdk_x11_device_core_warp (CdkDevice *device, | |||
| 59 | CdkScreen *screen, | |||
| 60 | gdouble x, | |||
| 61 | gdouble y); | |||
| 62 | static void cdk_x11_device_core_query_state (CdkDevice *device, | |||
| 63 | CdkWindow *window, | |||
| 64 | CdkWindow **root_window, | |||
| 65 | CdkWindow **child_window, | |||
| 66 | gdouble *root_x, | |||
| 67 | gdouble *root_y, | |||
| 68 | gdouble *win_x, | |||
| 69 | gdouble *win_y, | |||
| 70 | CdkModifierType *mask); | |||
| 71 | static CdkGrabStatus cdk_x11_device_core_grab (CdkDevice *device, | |||
| 72 | CdkWindow *window, | |||
| 73 | gboolean owner_events, | |||
| 74 | CdkEventMask event_mask, | |||
| 75 | CdkWindow *confine_to, | |||
| 76 | CdkCursor *cursor, | |||
| 77 | guint32 time_); | |||
| 78 | static void cdk_x11_device_core_ungrab (CdkDevice *device, | |||
| 79 | guint32 time_); | |||
| 80 | static CdkWindow * cdk_x11_device_core_window_at_position (CdkDevice *device, | |||
| 81 | gdouble *win_x, | |||
| 82 | gdouble *win_y, | |||
| 83 | CdkModifierType *mask, | |||
| 84 | gboolean get_toplevel); | |||
| 85 | static void cdk_x11_device_core_select_window_events (CdkDevice *device, | |||
| 86 | CdkWindow *window, | |||
| 87 | CdkEventMask event_mask); | |||
| 88 | ||||
| 89 | G_DEFINE_TYPE (CdkX11DeviceCore, cdk_x11_device_core, CDK_TYPE_DEVICE)static void cdk_x11_device_core_init (CdkX11DeviceCore *self) ; static void cdk_x11_device_core_class_init (CdkX11DeviceCoreClass *klass); static GType cdk_x11_device_core_get_type_once (void ); __attribute__ ((__unused__)) static gpointer cdk_x11_device_core_parent_class = ((void*)0); static gint CdkX11DeviceCore_private_offset; static void cdk_x11_device_core_class_intern_init (gpointer klass) { cdk_x11_device_core_parent_class = g_type_class_peek_parent ( klass); if (CdkX11DeviceCore_private_offset != 0) g_type_class_adjust_private_offset (klass, &CdkX11DeviceCore_private_offset); cdk_x11_device_core_class_init ((CdkX11DeviceCoreClass*) klass); } __attribute__ ((__unused__ )) static inline gpointer cdk_x11_device_core_get_instance_private (CdkX11DeviceCore *self) { return (((gpointer) ((guint8*) (self ) + (glong) (CdkX11DeviceCore_private_offset)))); } GType cdk_x11_device_core_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_core_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_core_get_type_once (void) { GType g_define_type_id = g_type_register_static_simple ((cdk_device_get_type ()), g_intern_static_string ("CdkX11DeviceCore" ), sizeof (CdkX11DeviceCoreClass), (GClassInitFunc)(void (*)( void)) cdk_x11_device_core_class_intern_init, sizeof (CdkX11DeviceCore ), (GInstanceInitFunc)(void (*)(void)) cdk_x11_device_core_init , (GTypeFlags) 0); { {{};} } return g_define_type_id; } | |||
| 90 | ||||
| 91 | static void | |||
| 92 | cdk_x11_device_core_class_init (CdkX11DeviceCoreClass *klass) | |||
| 93 | { | |||
| 94 | CdkDeviceClass *device_class = CDK_DEVICE_CLASS (klass)((((CdkDeviceClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((klass)), ((cdk_device_get_type ())))))); | |||
| 95 | ||||
| 96 | device_class->get_history = cdk_x11_device_core_get_history; | |||
| 97 | device_class->get_state = cdk_x11_device_core_get_state; | |||
| 98 | device_class->set_window_cursor = cdk_x11_device_core_set_window_cursor; | |||
| 99 | device_class->warp = cdk_x11_device_core_warp; | |||
| 100 | device_class->query_state = cdk_x11_device_core_query_state; | |||
| 101 | device_class->grab = cdk_x11_device_core_grab; | |||
| 102 | device_class->ungrab = cdk_x11_device_core_ungrab; | |||
| 103 | device_class->window_at_position = cdk_x11_device_core_window_at_position; | |||
| 104 | device_class->select_window_events = cdk_x11_device_core_select_window_events; | |||
| 105 | } | |||
| 106 | ||||
| 107 | static void | |||
| 108 | cdk_x11_device_core_init (CdkX11DeviceCore *device_core) | |||
| 109 | { | |||
| 110 | CdkDevice *device; | |||
| 111 | ||||
| 112 | device = CDK_DEVICE (device_core)((((CdkDevice*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((device_core)), ((cdk_device_get_type ())))))); | |||
| 113 | ||||
| 114 | _cdk_device_add_axis (device, CDK_NONE((CdkAtom)((gpointer) (gulong) (0))), CDK_AXIS_X, 0, 0, 1); | |||
| 115 | _cdk_device_add_axis (device, CDK_NONE((CdkAtom)((gpointer) (gulong) (0))), CDK_AXIS_Y, 0, 0, 1); | |||
| 116 | } | |||
| 117 | ||||
| 118 | static gboolean | |||
| 119 | impl_coord_in_window (CdkWindow *window, | |||
| 120 | int impl_x, | |||
| 121 | int impl_y) | |||
| 122 | { | |||
| 123 | if (impl_x < window->abs_x || | |||
| 124 | impl_x >= window->abs_x + window->width) | |||
| 125 | return FALSE(0); | |||
| 126 | ||||
| 127 | if (impl_y < window->abs_y || | |||
| 128 | impl_y >= window->abs_y + window->height) | |||
| 129 | return FALSE(0); | |||
| 130 | ||||
| 131 | return TRUE(!(0)); | |||
| 132 | } | |||
| 133 | ||||
| 134 | static gboolean | |||
| 135 | cdk_x11_device_core_get_history (CdkDevice *device, | |||
| 136 | CdkWindow *window, | |||
| 137 | guint32 start, | |||
| 138 | guint32 stop, | |||
| 139 | CdkTimeCoord ***events, | |||
| 140 | gint *n_events) | |||
| 141 | { | |||
| 142 | XTimeCoord *xcoords; | |||
| 143 | CdkTimeCoord **coords; | |||
| 144 | CdkWindow *impl_window; | |||
| 145 | CdkWindowImplX11 *impl; | |||
| 146 | int tmp_n_events; | |||
| 147 | int i, j; | |||
| 148 | ||||
| 149 | impl_window = _cdk_window_get_impl_window (window); | |||
| 150 | impl = CDK_WINDOW_IMPL_X11 (impl_window->impl)((((CdkWindowImplX11*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((impl_window->impl)), ((cdk_window_impl_x11_get_type ())))))); | |||
| 151 | xcoords = XGetMotionEvents (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 152 | CDK_WINDOW_XID (impl_window)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((impl_window)), ((cdk_window_get_type ()) )))))->impl)), ((cdk_window_impl_x11_get_type ()))))))-> xid), | |||
| 153 | start, stop, &tmp_n_events); | |||
| 154 | if (!xcoords) | |||
| 155 | return FALSE(0); | |||
| 156 | ||||
| 157 | coords = _cdk_device_allocate_history (device, tmp_n_events); | |||
| 158 | ||||
| 159 | for (i = 0, j = 0; i < tmp_n_events; i++) | |||
| 160 | { | |||
| 161 | if (impl_coord_in_window (window, | |||
| 162 | xcoords[i].x / impl->window_scale, | |||
| 163 | xcoords[i].y / impl->window_scale)) | |||
| 164 | { | |||
| 165 | coords[j]->time = xcoords[i].time; | |||
| 166 | coords[j]->axes[0] = (double)xcoords[i].x / impl->window_scale - window->abs_x; | |||
| 167 | coords[j]->axes[1] = (double)xcoords[i].y / impl->window_scale - window->abs_y; | |||
| 168 | j++; | |||
| 169 | } | |||
| 170 | } | |||
| 171 | ||||
| 172 | XFree (xcoords); | |||
| 173 | ||||
| 174 | /* free the events we allocated too much */ | |||
| 175 | for (i = j; i < tmp_n_events; i++) | |||
| 176 | { | |||
| 177 | g_free (coords[i])(__builtin_object_size ((coords[i]), 0) != ((size_t) - 1)) ? g_free_sized (coords[i], __builtin_object_size ((coords[i]), 0)) : (g_free ) (coords[i]); | |||
| 178 | coords[i] = NULL((void*)0); | |||
| 179 | } | |||
| 180 | ||||
| 181 | tmp_n_events = j; | |||
| 182 | ||||
| 183 | if (tmp_n_events == 0) | |||
| 184 | { | |||
| 185 | cdk_device_free_history (coords, tmp_n_events); | |||
| 186 | return FALSE(0); | |||
| 187 | } | |||
| 188 | ||||
| 189 | if (n_events) | |||
| 190 | *n_events = tmp_n_events; | |||
| 191 | ||||
| 192 | if (events) | |||
| 193 | *events = coords; | |||
| 194 | else if (coords) | |||
| 195 | cdk_device_free_history (coords, tmp_n_events); | |||
| 196 | ||||
| 197 | return TRUE(!(0)); | |||
| 198 | } | |||
| 199 | ||||
| 200 | static void | |||
| 201 | cdk_x11_device_core_get_state (CdkDevice *device, | |||
| 202 | CdkWindow *window, | |||
| 203 | gdouble *axes, | |||
| 204 | CdkModifierType *mask) | |||
| 205 | { | |||
| 206 | gdouble x, y; | |||
| 207 | ||||
| 208 | cdk_window_get_device_position_double (window, device, &x, &y, mask); | |||
| 209 | ||||
| 210 | if (axes) | |||
| 211 | { | |||
| 212 | axes[0] = x; | |||
| 213 | axes[1] = y; | |||
| 214 | } | |||
| 215 | } | |||
| 216 | ||||
| 217 | static void | |||
| 218 | cdk_x11_device_core_set_window_cursor (CdkDevice *device, | |||
| 219 | CdkWindow *window, | |||
| 220 | CdkCursor *cursor) | |||
| 221 | { | |||
| 222 | Cursor xcursor; | |||
| 223 | ||||
| 224 | if (!cursor) | |||
| 225 | { | |||
| 226 | /* While a grab is active, a NULL cursor on the grab window itself | |||
| 227 | * must not strip the cursor the grab defined there: update_cursor() | |||
| 228 | * sends it when the pointer hovers cursor-less windows of the | |||
| 229 | * grabbed hierarchy, and undefining would make the server walk past | |||
| 230 | * the grab window up to its ancestors, where the window manager | |||
| 231 | * frame windows can carry a stale cursor. Grabs taken with an | |||
| 232 | * explicit cursor show that cursor regardless of the window | |||
| 233 | * attributes, so their grab window is left untouched as well. On | |||
| 234 | * any other window a NULL applies the cursor the grab was taken | |||
| 235 | * with: cursor-less windows applying their cursor while the grab | |||
| 236 | * lasts keep that image instead of walking up the window ancestors, | |||
| 237 | * where the window manager frame windows can carry a stale cursor. */ | |||
| 238 | CdkDisplay *display = cdk_device_get_display (device); | |||
| 239 | CdkDeviceGrabInfo *grab; | |||
| 240 | Cursor grab_cursor = None0L; | |||
| 241 | ||||
| 242 | grab = _cdk_display_get_last_device_grab (display, device); | |||
| 243 | if (grab != NULL((void*)0)) | |||
| 244 | { | |||
| 245 | if (window == grab->window) | |||
| 246 | return; | |||
| 247 | ||||
| 248 | grab_cursor = _cdk_x11_display_get_grab_current_cursor (display); | |||
| 249 | } | |||
| 250 | ||||
| 251 | xcursor = grab_cursor; | |||
| 252 | ||||
| 253 | /* Outside of grabs, leaving one of our own toplevels bare hands | |||
| 254 | * the cursor lookup to the server, which resolves it walking up | |||
| 255 | * the window's ancestors: the first window beyond our toplevel | |||
| 256 | * is the window manager frame, carrying whatever cursor the WM | |||
| 257 | * applied last on the side the pointer crossed. The WM stops | |||
| 258 | * receiving pointer events for as long as one of our grabs | |||
| 259 | * lasts, so that image is frozen meanwhile and can be stale by | |||
| 260 | * the time the grab ends: with the pointer parked on a resize | |||
| 261 | * border, opening a menu with the keyboard and clicking off it | |||
| 262 | * into the window makes update_cursor() strip the remembered | |||
| 263 | * image the grab applied on the following enter, and the | |||
| 264 | * frame's stale resize cursor then shows up all over the client | |||
| 265 | * area until the pointer reaches the title bar or a corner and | |||
| 266 | * the WM redefines its frame cursor. Define the theme's default | |||
| 267 | * arrow instead: it is the image the server would show walking | |||
| 268 | * past the bare toplevel anyway, and it keeps the frame windows | |||
| 269 | * out of the lookup for as long as the pointer is over our | |||
| 270 | * windows, whatever the frame carries. A theme that fails to | |||
| 271 | * provide the arrow keeps the old behavior. */ | |||
| 272 | if (xcursor == None0L && | |||
| 273 | cdk_window_get_window_type (window) == CDK_WINDOW_TOPLEVEL) | |||
| 274 | { | |||
| 275 | CdkCursor *arrow = _cdk_x11_display_get_default_arrow_cursor (display); | |||
| 276 | ||||
| 277 | if (arrow != NULL((void*)0)) | |||
| 278 | xcursor = cdk_x11_cursor_get_xcursor (arrow); | |||
| 279 | } | |||
| 280 | } | |||
| 281 | else | |||
| 282 | xcursor = cdk_x11_cursor_get_xcursor (cursor); | |||
| 283 | ||||
| 284 | XDefineCursor (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 285 | 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), | |||
| 286 | xcursor); | |||
| 287 | } | |||
| 288 | ||||
| 289 | static void | |||
| 290 | cdk_x11_device_core_warp (CdkDevice *device, | |||
| 291 | CdkScreen *screen, | |||
| 292 | gdouble x, | |||
| 293 | gdouble y) | |||
| 294 | { | |||
| 295 | Display *xdisplay; | |||
| 296 | Window dest; | |||
| 297 | ||||
| 298 | xdisplay = CDK_DISPLAY_XDISPLAY (cdk_device_get_display (device))(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((cdk_device_get_display (device))), ((cdk_x11_display_get_type ()))))))->xdisplay); | |||
| 299 | 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); | |||
| 300 | ||||
| 301 | XWarpPointer (xdisplay, None0L, dest, 0, 0, 0, 0, | |||
| 302 | round (x * CDK_X11_SCREEN (screen)((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->window_scale), | |||
| 303 | round (y * CDK_X11_SCREEN (screen)((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->window_scale)); | |||
| 304 | } | |||
| 305 | ||||
| 306 | static void | |||
| 307 | cdk_x11_device_core_query_state (CdkDevice *device G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 308 | CdkWindow *window, | |||
| 309 | CdkWindow **root_window, | |||
| 310 | CdkWindow **child_window, | |||
| 311 | gdouble *root_x, | |||
| 312 | gdouble *root_y, | |||
| 313 | gdouble *win_x, | |||
| 314 | gdouble *win_y, | |||
| 315 | CdkModifierType *mask) | |||
| 316 | { | |||
| 317 | CdkWindowImplX11 *impl = CDK_WINDOW_IMPL_X11 (window->impl)((((CdkWindowImplX11*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((window->impl)), ((cdk_window_impl_x11_get_type ())))))); | |||
| 318 | CdkDisplay *display; | |||
| 319 | CdkScreen *default_screen; | |||
| 320 | Window xroot_window, xchild_window; | |||
| 321 | int xroot_x, xroot_y, xwin_x, xwin_y; | |||
| 322 | unsigned int xmask; | |||
| 323 | ||||
| 324 | display = cdk_window_get_display (window); | |||
| 325 | default_screen = cdk_display_get_default_screen (display); | |||
| 326 | ||||
| 327 | if (!CDK_X11_DISPLAY (display)((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->trusted_client || | |||
| 328 | !XQueryPointer (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 329 | 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), | |||
| 330 | &xroot_window, | |||
| 331 | &xchild_window, | |||
| 332 | &xroot_x, &xroot_y, | |||
| 333 | &xwin_x, &xwin_y, | |||
| 334 | &xmask)) | |||
| 335 | { | |||
| 336 | XSetWindowAttributes attributes; | |||
| 337 | Display *xdisplay; | |||
| 338 | Window xwindow, w; | |||
| 339 | ||||
| 340 | /* FIXME: untrusted clients not multidevice-safe */ | |||
| 341 | xdisplay = CDK_SCREEN_XDISPLAY (default_screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((default_screen)), ((cdk_x11_screen_get_type ()))))))-> xdisplay); | |||
| 342 | xwindow = CDK_SCREEN_XROOTWIN (default_screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((default_screen)), ((cdk_x11_screen_get_type ()))))))-> xroot_window); | |||
| 343 | ||||
| 344 | w = XCreateWindow (xdisplay, xwindow, 0, 0, 1, 1, 0, | |||
| 345 | CopyFromParent0L, InputOnly2, CopyFromParent0L, | |||
| 346 | 0, &attributes); | |||
| 347 | XQueryPointer (xdisplay, w, | |||
| 348 | &xroot_window, | |||
| 349 | &xchild_window, | |||
| 350 | &xroot_x, &xroot_y, | |||
| 351 | &xwin_x, &xwin_y, | |||
| 352 | &xmask); | |||
| 353 | XDestroyWindow (xdisplay, w); | |||
| 354 | } | |||
| 355 | ||||
| 356 | if (root_window) | |||
| 357 | *root_window = cdk_x11_window_lookup_for_display (display, xroot_window); | |||
| 358 | ||||
| 359 | if (child_window) | |||
| 360 | *child_window = cdk_x11_window_lookup_for_display (display, xchild_window); | |||
| 361 | ||||
| 362 | if (root_x) | |||
| 363 | *root_x = (double)xroot_x / impl->window_scale; | |||
| 364 | ||||
| 365 | if (root_y) | |||
| 366 | *root_y = (double)xroot_y / impl->window_scale; | |||
| 367 | ||||
| 368 | if (win_x) | |||
| 369 | *win_x = (double)xwin_x / impl->window_scale; | |||
| 370 | ||||
| 371 | if (win_y) | |||
| 372 | *win_y = (double)xwin_y / impl->window_scale; | |||
| 373 | ||||
| 374 | if (mask) | |||
| 375 | *mask = xmask; | |||
| 376 | } | |||
| 377 | ||||
| 378 | static CdkGrabStatus | |||
| 379 | cdk_x11_device_core_grab (CdkDevice *device, | |||
| 380 | CdkWindow *window, | |||
| 381 | gboolean owner_events, | |||
| 382 | CdkEventMask event_mask, | |||
| 383 | CdkWindow *confine_to, | |||
| 384 | CdkCursor *cursor, | |||
| 385 | guint32 time_) | |||
| 386 | { | |||
| 387 | CdkDisplay *display; | |||
| 388 | Window xwindow, xconfine_to; | |||
| 389 | gint status; | |||
| 390 | ||||
| 391 | display = cdk_device_get_display (device); | |||
| 392 | ||||
| 393 | 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); | |||
| 394 | ||||
| 395 | if (confine_to) | |||
| 396 | confine_to = _cdk_window_get_impl_window (confine_to); | |||
| 397 | ||||
| 398 | if (!confine_to || CDK_WINDOW_DESTROYED (confine_to)(((CdkWindow *)(confine_to))->destroyed)) | |||
| 399 | xconfine_to = None0L; | |||
| 400 | else | |||
| 401 | xconfine_to = CDK_WINDOW_XID (confine_to)(((((CdkWindowImplX11*) (void *) g_type_check_instance_cast ( (GTypeInstance*) ((((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((confine_to)), ((cdk_window_get_type ())) ))))->impl)), ((cdk_window_impl_x11_get_type ()))))))-> xid); | |||
| 402 | ||||
| 403 | #ifdef G_ENABLE_DEBUG1 | |||
| 404 | if (CDK_DEBUG_CHECK (NOGRABS)(_cdk_debug_flags & CDK_DEBUG_NOGRABS)) | |||
| 405 | status = GrabSuccess0; | |||
| 406 | else | |||
| 407 | #endif | |||
| 408 | if (cdk_device_get_source (device) == CDK_SOURCE_KEYBOARD) | |||
| 409 | { | |||
| 410 | /* Device is a keyboard */ | |||
| 411 | status = XGrabKeyboard (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), | |||
| 412 | xwindow, | |||
| 413 | owner_events, | |||
| 414 | GrabModeAsync1, GrabModeAsync1, | |||
| 415 | time_); | |||
| 416 | } | |||
| 417 | else | |||
| 418 | { | |||
| 419 | Cursor xcursor; | |||
| 420 | Cursor grab_cursor = None0L; | |||
| 421 | CdkCursor *arrow; | |||
| 422 | guint xevent_mask; | |||
| 423 | gint i; | |||
| 424 | ||||
| 425 | /* Device is a pointer */ | |||
| 426 | if (!cursor) | |||
| 427 | xcursor = None0L; | |||
| 428 | else | |||
| 429 | { | |||
| 430 | _cdk_x11_cursor_update_theme (cursor); | |||
| 431 | xcursor = cdk_x11_cursor_get_xcursor (cursor); | |||
| 432 | } | |||
| 433 | ||||
| 434 | if (xcursor == None0L) | |||
| 435 | { | |||
| 436 | /* A grab without an explicit cursor makes the server display, for | |||
| 437 | * every window outside the grabbed window, the cursor of the grab | |||
| 438 | * window walking up its ancestors, and a grab window with no cursor | |||
| 439 | * of its own keeps walking up past it. The grab window here is the | |||
| 440 | * native toplevel of the application, and its ancestors are the | |||
| 441 | * window manager frame windows, whose cursor is whatever arrow | |||
| 442 | * the WM applied last on the frame side the pointer crossed; a | |||
| 443 | * stale cursor there then shows up all over the screen while the | |||
| 444 | * grab is active (e.g. menus opened with the keyboard while the | |||
| 445 | * pointer is parked outside the window). Define the theme's | |||
| 446 | * default arrow on the grab window so that does not happen, | |||
| 447 | * whatever the pointer is showing: an application cursor of this | |||
| 448 | * client, one of another client, or a cursor of the frame must | |||
| 449 | * not be pinned over the whole screen by a keyboard-driven grab. | |||
| 450 | * The arrow also matches what a click does under the grab, the | |||
| 451 | * first click on a window of another client only dismisses the | |||
| 452 | * menu. Inside the application the per-window cursors keep | |||
| 453 | * working through update_cursor(), because the cursor argument | |||
| 454 | * passed to XGrabPointer stays None. */ | |||
| 455 | arrow = _cdk_x11_display_get_default_arrow_cursor (display); | |||
| 456 | ||||
| 457 | if (arrow != NULL((void*)0)) | |||
| 458 | grab_cursor = cdk_x11_cursor_get_xcursor (arrow); | |||
| 459 | ||||
| 460 | /* A theme that fails to provide the default arrow falls back to | |||
| 461 | * freezing the exact image the pointer shows: the visible cursor | |||
| 462 | * does not change at all, the stale frame cursor does not come | |||
| 463 | * back, and the frozen image stays for as long as the grab | |||
| 464 | * lasts. */ | |||
| 465 | if (grab_cursor == None0L) | |||
| 466 | grab_cursor = _cdk_x11_display_get_current_cursor (display); | |||
| 467 | ||||
| 468 | if (grab_cursor != None0L) | |||
| 469 | XDefineCursor (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), | |||
| 470 | xwindow, | |||
| 471 | grab_cursor); | |||
| 472 | } | |||
| 473 | ||||
| 474 | xevent_mask = 0; | |||
| 475 | ||||
| 476 | for (i = 0; i < _cdk_x11_event_mask_table_size; i++) | |||
| 477 | { | |||
| 478 | if (event_mask & (1 << (i + 1))) | |||
| 479 | xevent_mask |= _cdk_x11_event_mask_table[i]; | |||
| 480 | } | |||
| 481 | ||||
| 482 | /* We don't want to set a native motion hint mask, as we're emulating motion | |||
| 483 | * hints. If we set a native one we just wouldn't get any events. | |||
| 484 | */ | |||
| 485 | xevent_mask &= ~PointerMotionHintMask(1L<<7); | |||
| 486 | ||||
| 487 | status = XGrabPointer (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), | |||
| 488 | xwindow, | |||
| 489 | owner_events, | |||
| 490 | xevent_mask, | |||
| 491 | GrabModeAsync1, GrabModeAsync1, | |||
| 492 | xconfine_to, | |||
| 493 | xcursor, | |||
| 494 | time_); | |||
| 495 | ||||
| 496 | if (status == GrabSuccess0) | |||
| 497 | { | |||
| 498 | /* Remember the cursor the grab was taken with: cursor-less windows | |||
| 499 | * applying their cursor while the grab is active keep that image | |||
| 500 | * instead of walking up the window ancestors, where the window | |||
| 501 | * manager frame windows can carry a stale cursor. A grab taken | |||
| 502 | * with an explicit cursor remembers None instead: the server | |||
| 503 | * shows that cursor regardless of the window attributes, so the | |||
| 504 | * windows applying their NULL cursor while the grab lasts are | |||
| 505 | * just left undefined. */ | |||
| 506 | _cdk_x11_display_set_grab_current_cursor (display, grab_cursor); | |||
| 507 | } | |||
| 508 | } | |||
| 509 | ||||
| 510 | _cdk_x11_display_update_grab_info (display, device, status); | |||
| 511 | ||||
| 512 | return _cdk_x11_convert_grab_status (status); | |||
| 513 | } | |||
| 514 | ||||
| 515 | static void | |||
| 516 | cdk_x11_device_core_ungrab (CdkDevice *device, | |||
| 517 | guint32 time_) | |||
| 518 | { | |||
| 519 | CdkDisplay *display; | |||
| 520 | gulong serial; | |||
| 521 | ||||
| 522 | display = cdk_device_get_display (device); | |||
| 523 | serial = NextRequest (CDK_DISPLAY_XDISPLAY (display))(((_XPrivDisplay)((((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance*) ((display)), ((cdk_x11_display_get_type()) )))))->xdisplay)))->request + 1); | |||
| 524 | ||||
| 525 | if (cdk_device_get_source (device) == CDK_SOURCE_KEYBOARD) | |||
| 526 | XUngrabKeyboard (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), time_); | |||
| 527 | else | |||
| 528 | { | |||
| 529 | XUngrabPointer (CDK_DISPLAY_XDISPLAY (display)(((((CdkX11Display*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((display)), ((cdk_x11_display_get_type()))))))->xdisplay ), time_); | |||
| 530 | _cdk_x11_display_set_grab_current_cursor (display, None0L); | |||
| 531 | } | |||
| 532 | ||||
| 533 | _cdk_x11_display_update_grab_info_ungrab (display, device, time_, serial); | |||
| 534 | } | |||
| 535 | ||||
| 536 | static CdkWindow * | |||
| 537 | cdk_x11_device_core_window_at_position (CdkDevice *device, | |||
| 538 | gdouble *win_x, | |||
| 539 | gdouble *win_y, | |||
| 540 | CdkModifierType *mask, | |||
| 541 | gboolean get_toplevel) | |||
| 542 | { | |||
| 543 | CdkWindowImplX11 *impl; | |||
| 544 | CdkDisplay *display; | |||
| 545 | CdkScreen *screen; | |||
| 546 | Display *xdisplay; | |||
| 547 | CdkWindow *window; | |||
| 548 | Window xwindow, root, child, last; | |||
| 549 | int xroot_x, xroot_y, xwin_x, xwin_y; | |||
| ||||
| 550 | unsigned int xmask; | |||
| 551 | ||||
| 552 | last = None0L; | |||
| 553 | display = cdk_device_get_display (device); | |||
| 554 | screen = cdk_display_get_default_screen (display); | |||
| 555 | ||||
| 556 | /* This function really only works if the mouse pointer is held still | |||
| 557 | * during its operation. If it moves from one leaf window to another | |||
| 558 | * than we'll end up with inaccurate values for win_x, win_y | |||
| 559 | * and the result. | |||
| 560 | */ | |||
| 561 | cdk_x11_display_grab (display); | |||
| 562 | ||||
| 563 | xdisplay = CDK_SCREEN_XDISPLAY (screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->xdisplay ); | |||
| 564 | xwindow = CDK_SCREEN_XROOTWIN (screen)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((screen)), ((cdk_x11_screen_get_type ()))))))->xroot_window ); | |||
| 565 | ||||
| 566 | 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 )) | |||
| 567 | { | |||
| 568 | XQueryPointer (xdisplay, xwindow, | |||
| 569 | &root, &child, | |||
| 570 | &xroot_x, &xroot_y, | |||
| 571 | &xwin_x, &xwin_y, | |||
| 572 | &xmask); | |||
| 573 | ||||
| 574 | if (root == xwindow) | |||
| 575 | xwindow = child; | |||
| 576 | else | |||
| 577 | xwindow = root; | |||
| 578 | } | |||
| 579 | else | |||
| 580 | { | |||
| 581 | gint width, height; | |||
| 582 | GList *toplevels, *list; | |||
| 583 | Window pointer_window; | |||
| 584 | int rootx = -1, rooty = -1; | |||
| 585 | int winx, winy; | |||
| 586 | ||||
| 587 | /* FIXME: untrusted clients case not multidevice-safe */ | |||
| 588 | pointer_window = None0L; | |||
| 589 | screen = cdk_display_get_default_screen (display); | |||
| 590 | toplevels = cdk_screen_get_toplevel_windows (screen); | |||
| 591 | for (list = toplevels; list != NULL((void*)0); list = list->next) | |||
| 592 | { | |||
| 593 | window = CDK_WINDOW (list->data)((((CdkWindow*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((list->data)), ((cdk_window_get_type ())))))); | |||
| 594 | impl = CDK_WINDOW_IMPL_X11 (window->impl)((((CdkWindowImplX11*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((window->impl)), ((cdk_window_impl_x11_get_type ())))))); | |||
| 595 | 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); | |||
| 596 | cdk_x11_display_error_trap_push (display); | |||
| 597 | XQueryPointer (xdisplay, xwindow, | |||
| 598 | &root, &child, | |||
| 599 | &rootx, &rooty, | |||
| 600 | &winx, &winy, | |||
| 601 | &xmask); | |||
| 602 | if (cdk_x11_display_error_trap_pop (display)) | |||
| 603 | continue; | |||
| 604 | if (child != None0L) | |||
| 605 | { | |||
| 606 | pointer_window = child; | |||
| 607 | break; | |||
| 608 | } | |||
| 609 | cdk_window_get_geometry (window, NULL((void*)0), NULL((void*)0), &width, &height); | |||
| 610 | if (winx >= 0 && winy >= 0 && winx < width * impl->window_scale && winy < height * impl->window_scale) | |||
| 611 | { | |||
| 612 | /* A childless toplevel, or below another window? */ | |||
| 613 | XSetWindowAttributes attributes; | |||
| 614 | Window w; | |||
| 615 | ||||
| 616 | w = XCreateWindow (xdisplay, xwindow, winx, winy, 1, 1, 0, | |||
| 617 | CopyFromParent0L, InputOnly2, CopyFromParent0L, | |||
| 618 | 0, &attributes); | |||
| 619 | XMapWindow (xdisplay, w); | |||
| 620 | XQueryPointer (xdisplay, xwindow, | |||
| 621 | &root, &child, | |||
| 622 | &rootx, &rooty, | |||
| 623 | &winx, &winy, | |||
| 624 | &xmask); | |||
| 625 | XDestroyWindow (xdisplay, w); | |||
| 626 | if (child == w) | |||
| 627 | { | |||
| 628 | pointer_window = xwindow; | |||
| 629 | break; | |||
| 630 | } | |||
| 631 | } | |||
| 632 | } | |||
| 633 | ||||
| 634 | g_list_free (toplevels); | |||
| 635 | ||||
| 636 | xwindow = pointer_window; | |||
| 637 | } | |||
| 638 | ||||
| 639 | while (xwindow) | |||
| 640 | { | |||
| 641 | last = xwindow; | |||
| 642 | cdk_x11_display_error_trap_push (display); | |||
| 643 | XQueryPointer (xdisplay, xwindow, | |||
| 644 | &root, &xwindow, | |||
| 645 | &xroot_x, &xroot_y, | |||
| 646 | &xwin_x, &xwin_y, | |||
| 647 | &xmask); | |||
| 648 | if (cdk_x11_display_error_trap_pop (display)) | |||
| 649 | break; | |||
| 650 | ||||
| 651 | if (get_toplevel && last != root && | |||
| 652 | (window = cdk_x11_window_lookup_for_display (display, last)) != NULL((void*)0) && | |||
| 653 | window->window_type != CDK_WINDOW_FOREIGN) | |||
| 654 | { | |||
| 655 | xwindow = last; | |||
| 656 | break; | |||
| 657 | } | |||
| 658 | } | |||
| 659 | ||||
| 660 | cdk_x11_display_ungrab (display); | |||
| 661 | ||||
| 662 | window = cdk_x11_window_lookup_for_display (display, last); | |||
| 663 | impl = NULL((void*)0); | |||
| 664 | if (window) | |||
| 665 | impl = CDK_WINDOW_IMPL_X11 (window->impl)((((CdkWindowImplX11*) (void *) g_type_check_instance_cast (( GTypeInstance*) ((window->impl)), ((cdk_window_impl_x11_get_type ())))))); | |||
| 666 | ||||
| 667 | if (win_x) | |||
| 668 | *win_x = (window
| |||
| ||||
| 669 | ||||
| 670 | if (win_y) | |||
| 671 | *win_y = (window) ? (double)xwin_y / impl->window_scale : -1; | |||
| 672 | ||||
| 673 | if (mask) | |||
| 674 | *mask = xmask; | |||
| 675 | ||||
| 676 | return window; | |||
| 677 | } | |||
| 678 | ||||
| 679 | static void | |||
| 680 | cdk_x11_device_core_select_window_events (CdkDevice *device G_GNUC_UNUSED__attribute__ ((__unused__)), | |||
| 681 | CdkWindow *window, | |||
| 682 | CdkEventMask event_mask) | |||
| 683 | { | |||
| 684 | CdkEventMask filter_mask, window_mask; | |||
| 685 | guint xmask = 0; | |||
| 686 | gint i; | |||
| 687 | ||||
| 688 | window_mask = cdk_window_get_events (window); | |||
| 689 | filter_mask = CDK_POINTER_MOTION_MASK | |||
| 690 | | CDK_POINTER_MOTION_HINT_MASK | |||
| 691 | | CDK_BUTTON_MOTION_MASK | |||
| 692 | | CDK_BUTTON1_MOTION_MASK | |||
| 693 | | CDK_BUTTON2_MOTION_MASK | |||
| 694 | | CDK_BUTTON3_MOTION_MASK | |||
| 695 | | CDK_BUTTON_PRESS_MASK | |||
| 696 | | CDK_BUTTON_RELEASE_MASK | |||
| 697 | | CDK_KEY_PRESS_MASK | |||
| 698 | | CDK_KEY_RELEASE_MASK | |||
| 699 | | CDK_ENTER_NOTIFY_MASK | |||
| 700 | | CDK_LEAVE_NOTIFY_MASK | |||
| 701 | | CDK_FOCUS_CHANGE_MASK | |||
| 702 | | CDK_PROXIMITY_IN_MASK | |||
| 703 | | CDK_PROXIMITY_OUT_MASK | |||
| 704 | | CDK_SCROLL_MASK; | |||
| 705 | ||||
| 706 | /* Filter out non-device events */ | |||
| 707 | event_mask &= filter_mask; | |||
| 708 | ||||
| 709 | /* Unset device events on window mask */ | |||
| 710 | window_mask &= ~filter_mask; | |||
| 711 | ||||
| 712 | /* Combine masks */ | |||
| 713 | event_mask |= window_mask; | |||
| 714 | ||||
| 715 | for (i = 0; i < _cdk_x11_event_mask_table_size; i++) | |||
| 716 | { | |||
| 717 | if (event_mask & (1 << (i + 1))) | |||
| 718 | xmask |= _cdk_x11_event_mask_table[i]; | |||
| 719 | } | |||
| 720 | ||||
| 721 | if (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) != CDK_WINDOW_XROOTWIN (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xroot_window)) | |||
| 722 | xmask |= StructureNotifyMask(1L<<17) | PropertyChangeMask(1L<<22); | |||
| 723 | ||||
| 724 | XSelectInput (CDK_WINDOW_XDISPLAY (window)(((((CdkX11Screen*) (void *) g_type_check_instance_cast ((GTypeInstance *) (((cdk_window_get_screen (window)))), ((cdk_x11_screen_get_type ()))))))->xdisplay), | |||
| 725 | 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), | |||
| 726 | xmask); | |||
| 727 | } |