GdkGrabStatus gdk_keyboard_grab (GdkWindow * window, gboolean owner_events, guint32 time) { gint return_val; unsigned long serial; GdkDisplay *display; GdkDisplayX11 *display_x11; GdkWindow *native; g_return_val_if_fail (window != NULL, 0); g_return_val_if_fail (GDK_IS_WINDOW (window), 0); native = gdk_window_get_toplevel (window); /* TODO: What do we do for offscreens and children? We need to proxy the grab somehow */ if (!GDK_IS_WINDOW_IMPL_X11 (GDK_WINDOW_OBJECT (native)->impl)) return GDK_GRAB_SUCCESS; display = GDK_WINDOW_DISPLAY (native); display_x11 = GDK_DISPLAY_X11 (display); serial = NextRequest (GDK_WINDOW_XDISPLAY (native)); if (!GDK_WINDOW_DESTROYED (native)) { #ifdef G_ENABLE_DEBUG if (_gdk_debug_flags & GDK_DEBUG_NOGRABS) return_val = GrabSuccess; else #endif return_val = XGrabKeyboard (GDK_WINDOW_XDISPLAY (native), GDK_WINDOW_XID (native), owner_events, GrabModeAsync, GrabModeAsync, time); if (G_UNLIKELY (!display_x11->trusted_client && return_val == AlreadyGrabbed)) /* we can't grab the keyboard, but we can do a GTK-local grab */ return_val = GrabSuccess; } else return_val = AlreadyGrabbed; if (return_val == GrabSuccess) _gdk_display_set_has_keyboard_grab (display, window, native, owner_events, serial, time); return gdk_x11_convert_grab_status (return_val); }
void _gdk_xid_table_remove (GdkDisplay *display, XID xid) { GdkDisplayX11 *display_x11; g_return_if_fail (GDK_IS_DISPLAY (display)); display_x11 = GDK_DISPLAY_X11 (display); if (display_x11->xid_ht) g_hash_table_remove (display_x11->xid_ht, &xid); }
static Atom lookup_cached_xatom (GdkDisplay *display, GdkAtom atom) { GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); if (ATOM_TO_INDEX (atom) < G_N_ELEMENTS (xatoms_offset) - N_CUSTOM_PREDEFINED) return ATOM_TO_INDEX (atom); if (display_x11->atom_from_virtual) return GPOINTER_TO_UINT (g_hash_table_lookup (display_x11->atom_from_virtual, GDK_ATOM_TO_POINTER (atom))); return None; }
/** * gdk_xid_table_lookup_for_display: * @display: the #GdkDisplay. * @xid: an X id. * * Returns the GDK object associated with the given X id. * * Returns: a GDK object associated with the given X id. * * Since: 2.2 */ gpointer gdk_xid_table_lookup_for_display (GdkDisplay *display, XID xid) { GdkDisplayX11 *display_x11; gpointer data = NULL; g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); display_x11 = GDK_DISPLAY_X11 (display); if (display_x11->xid_ht) data = g_hash_table_lookup (display_x11->xid_ht, &xid); return data; }
/** * gdk_x11_xatom_to_atom_for_display: * @display: A #GdkDisplay * @xatom: an X atom * * Convert from an X atom for a #GdkDisplay to the corresponding * #GdkAtom. * * Return value: the corresponding #GdkAtom. * * Since: 2.2 **/ GdkAtom gdk_x11_xatom_to_atom_for_display (GdkDisplay *display, Atom xatom) { GdkDisplayX11 *display_x11; GdkAtom virtual_atom = GDK_NONE; g_return_val_if_fail (GDK_IS_DISPLAY (display), GDK_NONE); if (xatom == None) return GDK_NONE; if (display->closed) return GDK_NONE; display_x11 = GDK_DISPLAY_X11 (display); if (xatom < G_N_ELEMENTS (xatoms_offset) - N_CUSTOM_PREDEFINED) return INDEX_TO_ATOM (xatom); if (display_x11->atom_to_virtual) virtual_atom = GDK_POINTER_TO_ATOM (g_hash_table_lookup (display_x11->atom_to_virtual, GUINT_TO_POINTER (xatom))); if (!virtual_atom) { /* If this atom doesn't exist, we'll die with an X error unless * we take precautions */ char *name; gdk_error_trap_push (); name = XGetAtomName (GDK_DISPLAY_XDISPLAY (display), xatom); if (gdk_error_trap_pop ()) { g_warning (G_STRLOC " invalid X atom: %ld", xatom); } else { virtual_atom = gdk_atom_intern (name, FALSE); XFree (name); insert_atom_pair (display, virtual_atom, xatom); } } return virtual_atom; }
void _gdk_xid_table_insert (GdkDisplay *display, XID *xid, gpointer data) { GdkDisplayX11 *display_x11; g_return_if_fail (xid != NULL); g_return_if_fail (GDK_IS_DISPLAY (display)); display_x11 = GDK_DISPLAY_X11 (display); if (!display_x11->xid_ht) display_x11->xid_ht = g_hash_table_new ((GHashFunc) gdk_xid_hash, (GEqualFunc) gdk_xid_equal); g_hash_table_insert (display_x11->xid_ht, xid, data); }
static void insert_atom_pair (GdkDisplay *display, GdkAtom virtual_atom, Atom xatom) { GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display); if (!display_x11->atom_from_virtual) { display_x11->atom_from_virtual = g_hash_table_new (g_direct_hash, NULL); display_x11->atom_to_virtual = g_hash_table_new (g_direct_hash, NULL); } g_hash_table_insert (display_x11->atom_from_virtual, GDK_ATOM_TO_POINTER (virtual_atom), GUINT_TO_POINTER (xatom)); g_hash_table_insert (display_x11->atom_to_virtual, GUINT_TO_POINTER (xatom), GDK_ATOM_TO_POINTER (virtual_atom)); }
GdkGrabStatus _gdk_windowing_pointer_grab (GdkWindow *window, GdkWindow *native, gboolean owner_events, GdkEventMask event_mask, GdkWindow *confine_to, GdkCursor *cursor, guint32 time) { gint return_val; GdkCursorPrivate *cursor_private; GdkDisplayX11 *display_x11; guint xevent_mask; Window xwindow; Window xconfine_to; Cursor xcursor; int i; if (confine_to) confine_to = _gdk_window_get_impl_window (confine_to); display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (native)); cursor_private = (GdkCursorPrivate*) cursor; xwindow = GDK_WINDOW_XID (native); if (!confine_to || GDK_WINDOW_DESTROYED (confine_to)) xconfine_to = None; else xconfine_to = GDK_WINDOW_XID (confine_to); if (!cursor) xcursor = None; else { _gdk_x11_cursor_update_theme (cursor); xcursor = cursor_private->xcursor; } xevent_mask = 0; for (i = 0; i < _gdk_nenvent_masks; i++) { if (event_mask & (1 << (i + 1))) xevent_mask |= _gdk_event_mask_table[i]; } /* We don't want to set a native motion hint mask, as we're emulating motion * hints. If we set a native one we just wouldn't get any events. */ xevent_mask &= ~PointerMotionHintMask; return_val = _gdk_input_grab_pointer (window, native, owner_events, event_mask, confine_to, time); if (return_val == GrabSuccess || G_UNLIKELY (!display_x11->trusted_client && return_val == AlreadyGrabbed)) { if (!GDK_WINDOW_DESTROYED (native)) { #ifdef G_ENABLE_DEBUG if (_gdk_debug_flags & GDK_DEBUG_NOGRABS) return_val = GrabSuccess; else #endif return_val = XGrabPointer (GDK_WINDOW_XDISPLAY (native), xwindow, owner_events, xevent_mask, GrabModeAsync, GrabModeAsync, xconfine_to, xcursor, time); } else return_val = AlreadyGrabbed; } if (return_val == GrabSuccess) _gdk_x11_roundtrip_async (GDK_DISPLAY_OBJECT (display_x11), has_pointer_grab_callback, NULL); return gdk_x11_convert_grab_status (return_val); }
gboolean gdk_get_use_xshm (void) { return GDK_DISPLAY_X11 (gdk_display_get_default ())->use_xshm; }
gboolean _gdk_x11_have_render (GdkDisplay *display) { Display *xdisplay = GDK_DISPLAY_XDISPLAY (display); GdkDisplayX11 *x11display = GDK_DISPLAY_X11 (display); if (x11display->have_render == GDK_UNKNOWN) { int event_base, error_base; x11display->have_render = XRenderQueryExtension (xdisplay, &event_base, &error_base) ? GDK_YES : GDK_NO; if (x11display->have_render == GDK_YES) { /* * Sun advertises RENDER, but fails to support 32-bit pixmaps. * That is just no good. Therefore, we check all screens * for proper support. */ int screen; for (screen = 0; screen < ScreenCount (xdisplay); screen++) { int count; int *depths = XListDepths (xdisplay, screen, &count); gboolean has_8 = FALSE, has_32 = FALSE; if (depths) { int i; for (i = 0; i < count; i++) { if (depths[i] == 8) has_8 = TRUE; else if (depths[i] == 32) has_32 = TRUE; } XFree (depths); } /* At this point, we might have a false positive; * buggy versions of Xinerama only report depths for * which there is an associated visual; so we actually * go ahead and try create pixmaps. */ if (!(has_8 && has_32)) { gdk_error_trap_push (); if (!has_8) try_pixmap (xdisplay, screen, 8); if (!has_32) try_pixmap (xdisplay, screen, 32); XSync (xdisplay, False); if (gdk_error_trap_pop () == 0) { has_8 = TRUE; has_32 = TRUE; } } if (!(has_8 && has_32)) { g_warning ("The X server advertises that RENDER support is present,\n" "but fails to supply the necessary pixmap support. In\n" "other words, it is buggy."); x11display->have_render = GDK_NO; break; } } } } return x11display->have_render == GDK_YES; }