void GrabKeyRelease(unsigned int keycode, unsigned int modifiers, Win win) { int i; #if USE_XI2 XIGrabModifiers modifiers_inouts[8]; int num_modifiers; if (modifiers == AnyModifier) { num_modifiers = 1; modifiers_inouts[0].modifiers = XIAnyModifier; modifiers_inouts[0].status = 0; } else { num_modifiers = 0; for (i = 0; i < 8; i++) { if (i && !Mode.masks.mod_combos[i]) continue; modifiers_inouts[num_modifiers].modifiers = modifiers | Mode.masks.mod_combos[i]; modifiers_inouts[num_modifiers].status = 0; num_modifiers++; } } XIUngrabKeycode(disp, DEV_KBD, keycode, WinGetXwin(win), num_modifiers, modifiers_inouts); #else if (modifiers == AnyModifier) { XUngrabKey(disp, keycode, modifiers, WinGetXwin(win)); return; } for (i = 0; i < 8; i++) { if (i && !Mode.masks.mod_combos[i]) continue; XUngrabKey(disp, keycode, modifiers | Mode.masks.mod_combos[i], WinGetXwin(win)); } #endif }
static void grab_key_real (guint keycode, GdkWindow *root, gboolean grab, XIGrabModifiers *mods, int num_mods) { XIEventMask evmask; unsigned char mask[(XI_LASTEVENT + 7)/8]; memset (mask, 0, sizeof (mask)); XISetMask (mask, XI_KeyPress); XISetMask (mask, XI_KeyRelease); evmask.deviceid = XIAllMasterDevices; evmask.mask_len = sizeof (mask); evmask.mask = mask; if (grab) { XIGrabKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XIAllMasterDevices, keycode, GDK_WINDOW_XID (root), GrabModeAsync, GrabModeAsync, False, &evmask, num_mods, mods); } else { XIUngrabKeycode (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XIAllMasterDevices, keycode, GDK_WINDOW_XID (root), num_mods, mods); } }
void xfwm_device_ungrab_keycode (XfwmDevices *devices, Display *display, gint keycode, guint modifiers, Window grab_window) { #ifdef HAVE_XI2 XIGrabModifiers xi2_modifiers; #endif #ifdef HAVE_XI2 if (devices->xi2_available) { xi2_modifiers.modifiers = xi2_modifier_mask (modifiers); xi2_modifiers.status = 0; XIUngrabKeycode (display, devices->keyboard.xi2_device, keycode, grab_window, 1, &xi2_modifiers); } else #endif { XUngrabKey (display, keycode, modifiers, grab_window); } }
Bool grabKeyCtrl (XWCContext * ctx, Window w, KeyCode xKCode, int nMods, XIGrabModifiers * mods, Bool grab) { XIGrabModifiers * failMods; XIEventMask evmask; int nfailMods, i; unsigned char mask[(XI_LASTEVENT + 7) / 8]; char buf[1024]; snprintf (buf, sizeof (buf), "\t\tGrabbing keycode %d on window 0x%lX:", xKCode, w); logCtrl (buf, LOG_LVL_1, False); if (ctx == NULL) { logCtrl ("\t\t\tCannot grab key: NULL pointer to XWC context received.", LOG_LVL_NO, False); return False; } if (ctx->kbds == NULL) { logCtrl ("\t\t\tCannot grab key: NULL pointer to keyboard device list" " received.", LOG_LVL_NO, False); return False; } if (ctx->kbds->nDevs < 0 || ctx->kbds->nDevs > 127) { logCtrl ("\t\t\tCannot grab key: bad device count.", LOG_LVL_NO, False); return False; } if (ctx->kbds->devs == NULL) { logCtrl ("\t\t\tCannot grab key: NULL pointer to device array " "received.", LOG_LVL_NO, False); return False; } if (nMods < 0 || nMods > 127) { logCtrl ("\t\t\tCannot grab key: bad mods count.", LOG_LVL_NO, False); return False; } if (mods == NULL) { logCtrl ("\t\t\tCannot grab key: NULL pointer to modifiers array " "received.", LOG_LVL_NO, False); return False; } if (w == None) { logCtrl ("\t\t\tCannot grab key: No window specified.", LOG_LVL_NO, False); return False; } if (grab == False) { for (i = 0; i < ctx->kbds->nDevs; ++ i) { XIUngrabKeycode (ctx->xDpy, ctx->kbds->devs[i], xKCode, w, nMods, mods); snprintf (buf, sizeof (buf), "\t\t\tkeycode ungrabbed on device " "%d.", ctx->kbds->devs[i]); logCtrl (buf, LOG_LVL_2, True); } return True; } failMods = (XIGrabModifiers*) malloc (sizeof (XIGrabModifiers) * nMods); if (failMods == NULL) { logCtrl ("\t\t\tCannot grab key: cannot allocate array for failed " "mods.", LOG_LVL_NO, False); return False; } memcpy (failMods, mods, sizeof (XIGrabModifiers) * nMods); memset (mask, 0, sizeof (mask)); XISetMask (mask, XI_KeyRelease); XISetMask (mask, XI_KeyPress); memset (&evmask, 0, sizeof (evmask)); evmask.mask_len = sizeof (mask); evmask.mask = mask; nfailMods = 0; for (i = 0; i < ctx->kbds->nDevs && nfailMods == 0; ++ i) { nfailMods = XIGrabKeycode (ctx->xDpy, ctx->kbds->devs[i], xKCode, w, GrabModeAsync, GrabModeAsync, False, &evmask, nMods, failMods); if (nfailMods == 0) { snprintf (buf, sizeof (buf), "\t\t\tkeycode grabbed on device %d.", ctx->kbds->devs[i]); logCtrl (buf, LOG_LVL_2, True); } } if (nfailMods != 0) { for (i = 0; i < nfailMods; ++ i) { snprintf (buf, sizeof (buf), "\t\t\tModifier %x failed with error " "%d\n", failMods[i].modifiers, failMods[i].status); logCtrl (buf, LOG_LVL_NO, False); } free (failMods); return False; } snprintf (buf, sizeof (buf), "\t\t\tSuccess"); logCtrl (buf, LOG_LVL_2, True); free (failMods); return True; }