static void avatar_image_add_filter (EmpathyAvatarImage *avatar_image) { Display *display; Window window; gint mask; XWindowAttributes attrs; if (!running_in_x11 ()) return; mask = PropertyChangeMask; window = gdk_x11_get_default_root_xwindow (); display = gdk_x11_get_default_xdisplay (); gdk_error_trap_push (); XGetWindowAttributes (display, window, &attrs); mask |= attrs.your_event_mask; XSelectInput (display, window, mask); gdk_error_trap_pop_ignored (); gdk_window_add_filter (NULL, avatar_image_filter_func, avatar_image); }
static void add_device_presence_filter (GsdPointingDeviceManager *manager) { Display *display; XEventClass class_presence; gint xi_presence; gint op_code, event, error; if (!XQueryExtension(GDK_DISPLAY(), "XInputExtension", &op_code, &event, &error)) { return; } display = gdk_x11_get_default_xdisplay(); gdk_error_trap_push(); DevicePresence(display, xi_presence, class_presence); XSelectExtensionEvent(display, RootWindow(display, DefaultScreen(display)), &class_presence, 1); gdk_flush(); if (!gdk_error_trap_pop()) gdk_window_add_filter(NULL, device_presence_filter, manager); }
static void egg_tray_icon_send_manager_message (EggTrayIcon *icon, long message, Window window, long data1, long data2, long data3) { XClientMessageEvent ev; Display *display; ev.type = ClientMessage; ev.window = window; ev.message_type = icon->system_tray_opcode_atom; ev.format = 32; ev.data.l[0] = gdk_x11_get_server_time (GTK_WIDGET (icon)->window); ev.data.l[1] = message; ev.data.l[2] = data1; ev.data.l[3] = data2; ev.data.l[4] = data3; #if HAVE_GTK_MULTIHEAD display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (icon))); #else display = gdk_display; #endif gdk_error_trap_push (); XSendEvent (display, icon->manager_window, False, NoEventMask, (XEvent *)&ev); XSync (display, False); gdk_error_trap_pop (); }
/* title_get_window_property */ static int _title_get_window_property(Title * title, Window window, Atom property, Atom atom, unsigned long * cnt, unsigned char ** ret) { int res; Atom type; int format; unsigned long bytes; #ifdef DEBUG fprintf(stderr, "DEBUG: %s(title, window, %lu, %lu)\n", __func__, property, atom); #endif gdk_error_trap_push(); res = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(title->display), window, property, 0, G_MAXLONG, False, atom, &type, &format, cnt, &bytes, ret); if(gdk_error_trap_pop() != 0 || res != Success) return 1; if(type != atom) { if(*ret != NULL) XFree(*ret); *ret = NULL; return 1; } return 0; }
static void egg_tray_icon_send_manager_message (EggTrayIcon *icon, long message, Window window, long data1, long data2, long data3) { XClientMessageEvent ev; Display *display; ev.type = ClientMessage; ev.window = window; ev.message_type = icon->system_tray_opcode_atom; ev.format = 32; ev.data.l[0] = gdk_x11_get_server_time (GTK_WIDGET (icon)->window); ev.data.l[1] = message; ev.data.l[2] = data1; ev.data.l[3] = data2; ev.data.l[4] = data3; display = gdk_display; gdk_error_trap_push (); XSendEvent (display, icon->manager_window, False, NoEventMask, (XEvent *)&ev); XSync (display, False); gdk_error_trap_pop (); icon->ready=TRUE; }
static gboolean wm_state_set (Display *display, Window window) { gulong nitems; gulong bytes_after; gulong *prop; Atom ret_type = None; int ret_format; int result; gdk_error_trap_push (); result = XGetWindowProperty (display, window, wm_state_atom, 0, G_MAXLONG, False, wm_state_atom, &ret_type, &ret_format, &nitems, &bytes_after, (gpointer) &prop); if (gdk_error_trap_pop ()) return FALSE; if (result != Success) return FALSE; XFree (prop); if (ret_type != wm_state_atom) return FALSE; return TRUE; }
static void kill_window (WnckWindow *win) { WnckApplication *app; app = wnck_window_get_application (win); if (app) { gchar buf[257], *client_machine; int pid; pid = wnck_application_get_pid (app); client_machine = get_client_machine (wnck_application_get_xid (app)); if (client_machine && pid > 0) { if (gethostname (buf, sizeof (buf) - 1) == 0) { if (strcmp (buf, client_machine) == 0) kill (pid, 9); } } if (client_machine) g_free (client_machine); } gdk_error_trap_push (); XKillClient (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), wnck_window_get_xid (win)); gdk_display_sync (gdk_display_get_default ()); gdk_error_trap_pop_ignored (); }
static void update_wm_window (void) { Window *xwindow; Atom type; gint format; gulong nitems; gulong bytes_after; XGetWindowProperty (GDK_DISPLAY (), GDK_ROOT_WINDOW (), XInternAtom (GDK_DISPLAY (), "_NET_SUPPORTING_WM_CHECK", False), 0, G_MAXLONG, False, XA_WINDOW, &type, &format, &nitems, &bytes_after, (guchar **) &xwindow); if (type != XA_WINDOW) { wm_window = None; return; } gdk_error_trap_push (); XSelectInput (GDK_DISPLAY (), *xwindow, StructureNotifyMask | PropertyChangeMask); XSync (GDK_DISPLAY (), False); if (gdk_error_trap_pop ()) { XFree (xwindow); wm_window = None; return; } wm_window = *xwindow; XFree (xwindow); }
static gboolean drw_selection_find_existing (DrwSelection *drw_selection) { Display *xdisplay = GDK_DISPLAY_XDISPLAY(gdk_display_get_default()); Window old; gdk_error_trap_push (); old = XGetSelectionOwner (xdisplay, gdk_x11_get_xatom_by_name (SELECTION_NAME)); if (old) { XSelectInput (xdisplay, old, StructureNotifyMask); drw_selection->owner_window = gdk_x11_window_foreign_new_for_display (gdk_display_get_default (), old); } XSync (xdisplay, False); if (gdk_error_trap_pop () == 0 && drw_selection->owner_window) { gdk_window_add_filter (drw_selection->owner_window, drw_selection_filter, drw_selection); XUngrabServer (xdisplay); return TRUE; } else { if (drw_selection->owner_window) { g_object_unref (drw_selection->owner_window); drw_selection->owner_window = NULL; } return FALSE; } }
gboolean XInputUtils::onMouseLeaveNotifyEvent(GtkWidget* widget, GdkEventCrossing* event) { if(!XInputUtils::enableLeafEnterWorkaround) { return FALSE; } INPUTDBG("leave notify (mode=%d, details=%d)\n", event->mode, event->detail); /* emergency disable XInput to avoid segfaults (GTK+ 2.17) or interface non-responsiveness (GTK+ 2.18) */ if (!gtk_check_version(2, 17, 0)) { gdk_flush(); gdk_error_trap_push(); for (GList* dev_list = gdk_devices_list(); dev_list != NULL; dev_list = dev_list->next) { GdkDevice* dev = GDK_DEVICE(dev_list->data); gdk_device_set_mode(dev, GDK_MODE_DISABLED); } gdk_flush(); gdk_error_trap_pop(); } return FALSE; }
/* on_close */ static void _on_close(gpointer data) { Close * close = data; GdkDisplay * display; XEvent xev; #ifdef DEBUG fprintf(stderr, "DEBUG: %s() %u\n", __func__, close->window); #endif if(close->window == None) return; display = close->display; memset(&xev, 0, sizeof(xev)); xev.xclient.type = ClientMessage; xev.xclient.window = close->window; xev.xclient.message_type = close->atom_close; xev.xclient.format = 32; xev.xclient.data.l[0] = gdk_x11_display_get_user_time(display); xev.xclient.data.l[1] = 2; gdk_error_trap_push(); XSendEvent(GDK_DISPLAY_XDISPLAY(display), GDK_WINDOW_XID(close->root), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev); gdk_error_trap_pop(); }
gboolean XInputUtils::onMouseEnterNotifyEvent(GtkWidget* widget, GdkEventCrossing* event) { if(!XInputUtils::enableLeafEnterWorkaround) { return FALSE; } INPUTDBG("enter notify\n"); /* re-enable input devices after they've been emergency-disabled by leave_notify */ if (!gtk_check_version(2, 17, 0)) { gdk_flush(); gdk_error_trap_push(); for (GList* dev_list = gdk_devices_list(); dev_list != NULL; dev_list = dev_list->next) { GdkDevice* dev = GDK_DEVICE(dev_list->data); gdk_device_set_mode(dev, GDK_MODE_SCREEN); } gdk_flush(); gdk_error_trap_pop(); } return FALSE; }
static void avatar_image_add_filter (EmpathyAvatarImage *avatar_image) { Window window; GdkWindow *gdkwindow; gint mask; mask = PropertyChangeMask; window = GDK_ROOT_WINDOW (); gdkwindow = gdk_xid_table_lookup (window); gdk_error_trap_push (); if (gdkwindow) { XWindowAttributes attrs; XGetWindowAttributes (gdk_display, window, &attrs); mask |= attrs.your_event_mask; } XSelectInput (gdk_display, window, mask); gdk_error_trap_pop (); gdk_window_add_filter (NULL, avatar_image_filter_func, avatar_image); }
/** * g_paste_keybinding_activate: * @self: a #GPasteKeybinding instance * * Activate the keybinding * * Returns: */ G_PASTE_VISIBLE void g_paste_keybinding_activate (GPasteKeybinding *self) { g_return_if_fail (G_PASTE_IS_KEYBINDING (self)); GPasteKeybindingPrivate *priv = self->priv; g_return_if_fail (!priv->active); GPasteXcbWrapper *xcb_wrapper = priv->xcb_wrapper; xcb_connection_t *connection = (xcb_connection_t *) g_paste_xcb_wrapper_get_connection (xcb_wrapper); xcb_screen_t *screen = (xcb_screen_t *) g_paste_xcb_wrapper_get_screen (xcb_wrapper); guint keysym; g_return_if_fail (screen); /* This should never happen */ gtk_accelerator_parse (priv->binding, &keysym, (GdkModifierType *) &priv->modifiers); priv->keycodes = xcb_key_symbols_get_keycode ((xcb_key_symbols_t *) g_paste_xcb_wrapper_get_keysyms (xcb_wrapper), keysym); gdk_error_trap_push (); for (xcb_keycode_t *keycode = priv->keycodes; *keycode; ++keycode) { xcb_grab_key (connection, FALSE, screen->root, priv->modifiers, *keycode, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); } xcb_flush (connection); gdk_error_trap_pop_ignored (); priv->active = TRUE; }
// the following function is stolen from xfdesktop static void set_num_screens (gpointer num) { static Atom xa_NET_NUMBER_OF_DESKTOPS = 0; XClientMessageEvent sev; int n; if (!xa_NET_NUMBER_OF_DESKTOPS) { xa_NET_NUMBER_OF_DESKTOPS = XInternAtom (GDK_DISPLAY (), "_NET_NUMBER_OF_DESKTOPS", False); } n = GPOINTER_TO_INT (num); sev.type = ClientMessage; sev.display = GDK_DISPLAY (); sev.format = 32; sev.window = GDK_ROOT_WINDOW (); sev.message_type = xa_NET_NUMBER_OF_DESKTOPS; sev.data.l[0] = n; gdk_error_trap_push (); XSendEvent (GDK_DISPLAY (), GDK_ROOT_WINDOW (), False, SubstructureNotifyMask | SubstructureRedirectMask, (XEvent *) & sev); gdk_flush (); gdk_error_trap_pop (); }
char * na_tray_manager_get_child_title (NaTrayManager *manager, NaTrayManagerChild *child) { char *retval = NULL; #ifdef GDK_WINDOWING_X11 GdkDisplay *display; Window *child_window; Atom utf8_string, atom, type; int result; int format; gulong nitems; gulong bytes_after; gchar *val; g_return_val_if_fail (NA_IS_TRAY_MANAGER (manager), NULL); g_return_val_if_fail (GTK_IS_SOCKET (child), NULL); display = gdk_screen_get_display (manager->screen); child_window = g_object_get_data (G_OBJECT (child), "na-tray-child-window"); utf8_string = gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"); atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_NAME"); gdk_error_trap_push (); result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), *child_window, atom, 0, G_MAXLONG, False, utf8_string, &type, &format, &nitems, &bytes_after, (guchar **)&val); if (gdk_error_trap_pop () || result != Success) return NULL; if (type != utf8_string || format != 8 || nitems == 0) { if (val) XFree (val); return NULL; } if (!g_utf8_validate (val, nitems, NULL)) { XFree (val); return NULL; } retval = g_strndup (val, nitems); XFree (val); #endif return retval; }
static void cdflush(cdCtxCanvas *ctxcanvas) { (void)ctxcanvas; gdk_error_trap_push(); gdk_flush(); gdk_error_trap_pop(); }
/* Stolen from xfwm4 and modified. * FALSE on error. Call initModifiers before this. */ static gboolean grabKey(MyKey *key) { Window root; Display *dpy = GDK_DISPLAY(); static gboolean need_init = TRUE; if (need_init) { need_init = FALSE; gdk_window_add_filter(gdk_get_default_root_window(), filter_keys, NULL); } gdk_error_trap_push(); root = GDK_ROOT_WINDOW(); GRAB(key, 0); /* Here we grab all combinations of well known modifiers */ GRAB(key, ScrollLockMask); GRAB(key, NumLockMask); GRAB(key, CapsLockMask); GRAB(key, ScrollLockMask | NumLockMask); GRAB(key, ScrollLockMask | CapsLockMask); GRAB(key, CapsLockMask | NumLockMask); GRAB(key, ScrollLockMask | CapsLockMask | NumLockMask); gdk_flush(); return gdk_error_trap_pop() == Success; }
void ungrab_key (int key_code) { GdkWindow *root=gdk_get_default_root_window(); gdk_error_trap_push (); XUngrabKey (GDK_DISPLAY (), key_code, AnyModifier, (GDK_WINDOW_XID (root) ? GDK_WINDOW_XID (root) : DefaultRootWindow (GDK_DISPLAY()))); XUngrabKey (GDK_DISPLAY (), AnyKey, AnyModifier, (GDK_WINDOW_XID (root) ? GDK_WINDOW_XID (root) : DefaultRootWindow (GDK_DISPLAY()))); gdk_flush (); if (gdk_error_trap_pop ()) { gchar *error; gchar *key; key=g_strdup_printf ("%s",(XKeysymToString (XKeycodeToKeysym (GDK_DISPLAY (), key_code, 0)) != NULL)? XKeysymToString (XKeycodeToKeysym (GDK_DISPLAY (),key_code, 0)): g_strdup_printf ("%d",key_code)); error = g_strdup_printf (_("It seems that another application already has" " access to the multimedia keys.\n" "Key %s couldn't be bound.\n" "Is another daemon already running ?\n"), key); show_error(error); printf("[Sven][ERROR]:%s",error); g_free (key); g_free (error); } }
static KeyCode grab_key(char *keystring) { KeySym sym; KeyCode code; gint i; if ((sym = XStringToKeysym(keystring)) == NoSymbol) return 0; if ((code = XKeysymToKeycode(GDK_DISPLAY(), sym)) == 0) return 0; gdk_error_trap_push(); for (i = 0; i < ScreenCount(GDK_DISPLAY()); i++) { XGrabKey(GDK_DISPLAY(), code, AnyModifier, RootWindow(GDK_DISPLAY(),i), 1, GrabModeAsync, GrabModeAsync); } gdk_flush(); if (gdk_error_trap_pop()) { g_warning("Couldn't grab %s: another client may already have done so", keystring); return 0; } return code; }
static gboolean is_shift_pressed (void) { gboolean ret; XkbStateRec state; Bool status; ret = FALSE; gdk_error_trap_push (); status = XkbGetState (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XkbUseCoreKbd, &state); #if GTK_CHECK_VERSION(3,0,0) gdk_error_trap_pop_ignored (); #else gdk_error_trap_pop (); #endif if (status == Success) { ret = state.mods & ShiftMask; } return ret; }
static gint get_window_desktop (Window window) { Atom ret_type; int format; gulong nitems; gulong bytes_after; guchar *cardinals; int error; int result; int desktop; if (_net_wm_desktop == None) _net_wm_desktop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "_NET_WM_DESKTOP", False); gdk_error_trap_push (); result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), window, _net_wm_desktop, 0, G_MAXLONG, False, XA_CARDINAL, &ret_type, &format, &nitems, &bytes_after, &cardinals); error = gdk_error_trap_pop(); /* nitems < 1 will occur if the property is not set */ if (error != Success || result != Success || nitems < 1) return -1; desktop = *cardinals; XFree (cardinals); if (nitems != 1) return -1; return desktop; }
static void socket_unrealize_cb(GtkWidget *widget, gpointer data) { // Unmap and reparent any child windows that GDK does not yet know about. // (See bug 540114 comment 10.) GdkWindow* socket_window = widget->window; Display* display = GDK_DISPLAY(); // Ignore X errors that may happen if windows get destroyed (possibly // requested by the plugin) between XQueryTree and when we operate on them. gdk_error_trap_push(); Window root, parent; Window* children; unsigned int nchildren; if (!XQueryTree(display, gdk_x11_drawable_get_xid(socket_window), &root, &parent, &children, &nchildren)) return; for (unsigned int i = 0; i < nchildren; ++i) { Window child = children[i]; if (!gdk_window_lookup(child)) { // This window is not known to GDK. XUnmapWindow(display, child); XReparentWindow(display, child, DefaultRootWindow(display), 0, 0); } } if (children) XFree(children); XSync(display, False); gdk_error_trap_pop(); }
void background_info_set_background_by_drawable(BackgroundInfo* info, guint32 drawable) { gint x, y; guint border,depth, width=0, height=0; Display* dpy = gdk_x11_get_default_xdisplay(); gdk_error_trap_push(); //TODO: //we shoul use xatom_name window to set events instead of root window //because the monitors changed signal will came before root window rect changed //so the Xroot window rect maybe keep old rect in update_bg function and in Display DBus signal "PrimaryChanged" Window root; XGetGeometry(dpy, drawable, &root, &x, &y, &width, &height, &border, &depth); g_debug("[%s] width: %d, height: %d, x: %d y: %d\n", __func__, width, height, x, y); if (gdk_error_trap_pop()) { g_warning("[%s] invalid drawable %d \n", __func__, drawable); return; } g_mutex_lock(&info->m); if (info->bg != NULL) { cairo_surface_destroy(info->bg); info->bg = NULL; } info->bg = cairo_xlib_surface_create(dpy, drawable, gdk_x11_visual_get_xvisual(gdk_visual_get_system()), width, height); g_mutex_unlock(&info->m); if (gtk_widget_get_realized(info->container)) { gdk_window_invalidate_rect(gtk_widget_get_window(info->container), NULL, TRUE); } }
int main(int argc, char *argv[]) { gtk_init(NULL, NULL); gdk_error_trap_push(); QApplication a(argc, argv); QTranslator translator; translator.load("/usr/share/dde-session-ui/translations/dde-session-ui_" + QLocale::system().name()); a.installTranslator(&translator); Osd osd; // To future maintainer: add your cmd and image as followings. osd.addCmdImage("NumLockOn","numlock-enabled-symbolic"); osd.addCmdImage("NumLockOff","numlock-disabled-symbolic"); osd.addCmdImage("CapsLockOn","capslock-enabled-symbolic"); osd.addCmdImage("CapsLockOff","capslock-disabled-symbolic"); osd.addCmdImage("TouchpadOn","touchpad-enabled-symbolic"); osd.addCmdImage("TouchpadOff","touchpad-disabled-symbolic"); osd.addCmdImage("TouchpadToggle","touchpad-toggled-symbolic"); osd.addCmdImageWithText("SwitchWM3D", "wm-effect-enabled", a.translate("Osd", "Enable window effects")); osd.addCmdImageWithText("SwitchWM2D","wm-effect-disabled",a.translate("Osd", "Disable window effects")); osd.addCmdImageWithText("SwitchWMError","wm-effect-error",a.translate("Osd", "Failed to enable window effects")); osd.processParser(); if(!osd.handleBasicCmd() && !osd.handleAdditionalCmd() && !osd.handleAdditionalCmdWithText()){ return 0; } osd.show(); return a.exec(); }
static void meta_error_trap_push_internal (MetaDisplay *display, gboolean need_sync) { /* GDK resets the error handler on each push */ int (* old_error_handler) (Display *, XErrorEvent *); if (need_sync) { XSync (display->xdisplay, False); } gdk_error_trap_push (); /* old_error_handler will just be equal to x_error_handler * for nested traps */ old_error_handler = XSetErrorHandler (x_error_handler); /* Replace GDK handler, but save it so we can chain up */ if (display->error_trap_handler == NULL) { g_assert (display->error_traps == 0); display->error_trap_handler = old_error_handler; g_assert (display->error_trap_handler != x_error_handler); } display->error_traps += 1; meta_topic (META_DEBUG_ERRORS, "%d traps remain\n", display->error_traps); }
static void run_dialog (GdkDisplay *display, GdkScreen *screen, guint32 timestamp) { Atom action_atom; Atom atom; Window root; XClientMessageEvent ev; if (!display) display = gdk_display_get_default (); if (!screen) screen = gdk_display_get_default_screen (display); root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen)); action_atom = gdk_x11_get_xatom_by_name_for_display (display, "_MATE_PANEL_ACTION"); atom = gdk_x11_get_xatom_by_name_for_display (display, "_MATE_PANEL_ACTION_RUN_DIALOG"); ev.type = ClientMessage; ev.window = root; ev.message_type = action_atom; ev.format = 32; ev.data.l[0] = atom; ev.data.l[1] = timestamp; gdk_error_trap_push (); XSendEvent (gdk_x11_display_get_xdisplay (display), root, False, StructureNotifyMask, (XEvent*) &ev); gdk_flush (); gdk_error_trap_pop (); }
/* Most of the workspace manipulation code has been copied from libwnck * Copyright (C) 2001 Havoc Pennington * Copyright (C) 2005-2007 Vincent Untz */ static void _wnck_activate_workspace (Screen *screen, int new_active_space, Time timestamp) { Display *display; Window root; XEvent xev; display = DisplayOfScreen (screen); root = RootWindowOfScreen (screen); xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.display = display; xev.xclient.window = root; xev.xclient.message_type = gdk_x11_get_xatom_by_name ("_NET_CURRENT_DESKTOP"); xev.xclient.format = 32; xev.xclient.data.l[0] = new_active_space; xev.xclient.data.l[1] = timestamp; xev.xclient.data.l[2] = 0; xev.xclient.data.l[3] = 0; xev.xclient.data.l[4] = 0; gdk_error_trap_push (); XSendEvent (display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); XSync (display, False); gdk_error_trap_pop_ignored (); }
gboolean device_is_touchpad (XDevice *xdevice) { Atom realtype, prop; int realformat; unsigned long nitems, bytes_after; unsigned char *data; /* we don't check on the type being XI_TOUCHPAD here, * but having a "Synaptics Off" property should be enough */ prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Off", False); if (!prop) return FALSE; gdk_error_trap_push (); if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { gdk_error_trap_pop_ignored (); XFree (data); return TRUE; } gdk_error_trap_pop_ignored (); return FALSE; }
int XttHotkey::grab_key( int keysym, int modifier) { GdkDisplay *display = gdk_display_get_default(); int n_screens = gdk_display_get_n_screens( display); Display *dp = gdk_x11_display_get_xdisplay( display); int mode = GrabModeAsync; int keycode = XKeysymToKeycode( dp, keysym); if ( !keycode) return 0; gdk_error_trap_push(); for ( int i = 0; i < n_screens; i++) { GdkWindow *root = gdk_screen_get_root_window( gdk_display_get_screen( display, i)); Window w = gdk_x11_drawable_get_xid( root); XGrabKey( dp, keycode, modifier, w, True, mode, mode); XGrabKey( dp, keycode, modifier | LockMask, w, True, mode, mode); XGrabKey( dp, keycode, modifier | Mod2Mask, w, True, mode, mode); XGrabKey( dp, keycode, modifier | LockMask | Mod2Mask, w, True, mode, mode); } gdk_flush(); gdk_error_trap_pop(); return 1; }