int main(int, char **) { Display *display = 0; int opcode = -1; int xkbEventBase = -1; int xkbErrorBase = -1; int xkblibMajor = XkbMajorVersion; int xkblibMinor = XkbMinorVersion; XkbQueryExtension(display, &opcode, &xkbEventBase, &xkbErrorBase, &xkblibMajor, &xkblibMinor); int keycode = 0; unsigned int state = 0; KeySym keySym; unsigned int consumedModifiers; XkbLookupKeySym(display, keycode, state, &consumedModifiers, &keySym); XkbDescPtr xkbDesc = XkbGetMap(display, XkbAllClientInfoMask, XkbUseCoreKbd); int w = XkbKeyGroupsWidth(xkbDesc, keycode); keySym = XkbKeySym(xkbDesc, keycode, w-1); XkbFreeClientMap(xkbDesc, XkbAllClientInfoMask, true); state = XkbPCF_GrabsUseXKBStateMask; (void) XkbSetPerClientControls(display, state, &state); return 0; }
static XkbFileInfo * input_pad_xkb_get_file_info (InputPadGtkWindow *window) { Display *xdisplay = GDK_WINDOW_XDISPLAY (gtk_widget_get_window (GTK_WIDGET (window))); XkbFileInfo *xkb_info; xkb_info = g_new0 (XkbFileInfo, 1); xkb_info->type = XkmKeymapFile; xkb_info->xkb = XkbGetMap (xdisplay, XkbAllMapComponentsMask, XkbUseCoreKbd); if (xkb_info->xkb == NULL) { g_warning ("Could not get XKB map"); } if (XkbGetNames (xdisplay, XkbAllNamesMask, xkb_info->xkb) !=Success) { g_warning ("Could not get XKB names"); } if (XkbGetGeometry (xdisplay, xkb_info->xkb) !=Success) { g_warning ("Could not get geometry"); return NULL; } if (XkbChangeKbdDisplay (xdisplay, xkb_info) !=Success) { g_warning ("Could not get display"); return NULL; } return xkb_info; }
static XkbDescPtr accessx_status_applet_get_xkb_desc(AccessxStatusApplet* sapplet) { Display* display; if (sapplet->xkb == NULL) { int ir, reason_return; char* display_name = getenv("DISPLAY"); display = XkbOpenDisplay(display_name, &xkb_base_event_type, &ir, NULL, NULL, &reason_return); g_assert(display); /* TODO: change error message below to something user-viewable */ if (display == NULL) { g_warning("Xkb extension could not be initialized! (error code %x)", reason_return); } else { sapplet->xkb = XkbGetMap(display, XkbAllComponentsMask, XkbUseCoreKbd); } g_assert(sapplet->xkb); if (sapplet->xkb == NULL) { g_warning("Xkb keyboard description not available!"); } sapplet->xkb_display = display; } return sapplet->xkb; }
static XkbDescPtr get_xkb (ClutterKeymapX11 *keymap_x11) { ClutterBackendX11 *backend_x11 = CLUTTER_BACKEND_X11 (keymap_x11->backend); if (keymap_x11->max_keycode == 0) XDisplayKeycodes (backend_x11->xdpy, &keymap_x11->min_keycode, &keymap_x11->max_keycode); if (keymap_x11->xkb_desc == NULL) { int flags = XkbKeySymsMask | XkbKeyTypesMask | XkbModifierMapMask | XkbVirtualModsMask; keymap_x11->xkb_desc = XkbGetMap (backend_x11->xdpy, flags, XkbUseCoreKbd); if (G_UNLIKELY (keymap_x11->xkb_desc == NULL)) { g_error ("Failed to get the keymap from XKB"); return NULL; } flags = XkbGroupNamesMask | XkbVirtualModNamesMask; XkbGetNames (backend_x11->xdpy, flags, keymap_x11->xkb_desc); update_modmap (backend_x11->xdpy, keymap_x11); } else if (keymap_x11->xkb_map_serial != backend_x11->keymap_serial) { int flags = XkbKeySymsMask | XkbKeyTypesMask | XkbModifierMapMask | XkbVirtualModsMask; CLUTTER_NOTE (BACKEND, "Updating XKB keymap"); XkbGetUpdatedMap (backend_x11->xdpy, flags, keymap_x11->xkb_desc); flags = XkbGroupNamesMask | XkbVirtualModNamesMask; XkbGetNames (backend_x11->xdpy, flags, keymap_x11->xkb_desc); update_modmap (backend_x11->xdpy, keymap_x11); keymap_x11->xkb_map_serial = backend_x11->keymap_serial; } if (keymap_x11->num_lock_mask == 0) keymap_x11->num_lock_mask = XkbKeysymToModifiers (backend_x11->xdpy, XK_Num_Lock); if (keymap_x11->scroll_lock_mask == 0) keymap_x11->scroll_lock_mask = XkbKeysymToModifiers (backend_x11->xdpy, XK_Scroll_Lock); return keymap_x11->xkb_desc; }
int freerdp_keyboard_load_map_from_xkbfile(void* display, RDP_SCANCODE x11_keycode_to_rdp_scancode[256]) { int i, j; boolean found; XkbDescPtr xkb; boolean status = false; if (display && (xkb = XkbGetMap(display, 0, XkbUseCoreKbd))) { if (XkbGetNames(display, XkbKeyNamesMask, xkb) == Success) { char xkb_keyname[5] = { 42, 42, 42, 42, 0 }; /* end-of-string at index 5 */ for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) { found = false; memcpy(xkb_keyname, xkb->names->keys[i].name, 4); if (strlen(xkb_keyname) < 1) continue; for (j = 0; j < ARRAY_SIZE(XKB_KEY_NAME_SCANCODE_TABLE); j++) { if (!strcmp(xkb_keyname, XKB_KEY_NAME_SCANCODE_TABLE[j].xkb_keyname)) { DEBUG_KBD("%4s: keycode: 0x%02X -> rdp scancode: 0x%04X", xkb_keyname, i, XKB_KEY_NAME_SCANCODE_TABLE[j].rdp_scancode); if (found) { DEBUG_KBD("Internal error! duplicate key %s!", xkb_keyname); } x11_keycode_to_rdp_scancode[i] = XKB_KEY_NAME_SCANCODE_TABLE[j].rdp_scancode; found = true; } } if (!found) { DEBUG_KBD("%4s: keycode: 0x%02X -> no RDP scancode found", xkb_keyname, i); } } status = true; } XkbFreeKeyboard(xkb, 0, 1); } return status; }
void XWindowsKeyState::init(Display* display, bool useXKB) { XGetKeyboardControl(m_display, &m_keyboardState); #if HAVE_XKB_EXTENSION if (useXKB) { m_xkb = XkbGetMap(m_display, XkbKeyActionsMask | XkbKeyBehaviorsMask | XkbAllClientInfoMask, XkbUseCoreKbd); } else { m_xkb = NULL; } #endif setActiveGroup(kGroupPollAndSet); }
int init_keycodes_from_xkb(void *dpy, RdpKeycodes x_keycode_to_rdp_keycode) { int ret = 0; XkbDescPtr xkb; if (dpy && (xkb = XkbGetMap(dpy, 0, XkbUseCoreKbd))) { if (XkbGetNames(dpy, XkbKeyNamesMask, xkb) == Success) { char buf[5] = {42, 42, 42, 42, 0}; /* end-of-string at pos 5 */ int i, j; memset(x_keycode_to_rdp_keycode, 0, sizeof(x_keycode_to_rdp_keycode)); for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) { memcpy(buf, xkb->names->keys[i].name, 4); /* TODO: Use more efficient search ... but it is so fast that it doesn't matter */ j = sizeof(virtualKeyboard) / sizeof(virtualKeyboard[0]) - 1; while (j >= 0) { if (virtualKeyboard[j].x_keyname && !strcmp(buf, virtualKeyboard[j].x_keyname)) break; j--; } if (j >= 0) { DEBUG_KBD("X key code %3d has keyname %-4s -> RDP keycode %d/%d", i, buf, virtualKeyboard[j].extended, virtualKeyboard[j].scancode); x_keycode_to_rdp_keycode[i].extended = virtualKeyboard[j].extended; x_keycode_to_rdp_keycode[i].keycode = virtualKeyboard[j].scancode; #ifdef WITH_DEBUG_KBD x_keycode_to_rdp_keycode[i].keyname = virtualKeyboard[j].x_keyname; #endif } else DEBUG_KBD("X key code %3d has keyname %-4s -> ??? - not found", i, buf); } ret = 1; } XkbFreeKeyboard(xkb, 0, 1); } return ret; }
void _XkbReloadDpy(Display *dpy) { XkbInfoPtr xkbi; XkbDescRec *desc; unsigned oldDeviceID; if (_XkbUnavailable(dpy)) return; xkbi = dpy->xkb_info; LockDisplay(dpy); if (xkbi->desc) { oldDeviceID= xkbi->desc->device_spec; XkbFreeKeyboard(xkbi->desc,XkbAllComponentsMask,True); xkbi->desc= NULL; xkbi->flags&= ~(XkbMapPending|XkbXlibNewKeyboard); xkbi->changes.changed= 0; } else oldDeviceID= XkbUseCoreKbd; UnlockDisplay(dpy); desc = XkbGetMap(dpy,XkbAllClientInfoMask,XkbUseCoreKbd); if (!desc) return; LockDisplay(dpy); xkbi->desc = desc; UnlockDisplay(dpy); if (desc->device_spec!=oldDeviceID) { /* transfer(?) event masks here */ #ifdef NOTYET unsigned oldEvents; oldEvents= xkbi->selected_events; XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify, XkbAllMapComponentsMask,XkbAllClientInfoMask); LockDisplay(dpy); xkbi->selected_events= oldEvents; UnlockDisplay(dpy); #endif } return; }
static gboolean replace_map_keysym (DEControllerPrivateData *priv, KeyCode keycode, KeySym keysym) { #ifdef HAVE_XKB Display *dpy = spi_get_display (); XkbDescPtr desc; if (!(desc = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd))) { fprintf (stderr, "ERROR getting map\n"); } XFlush (dpy); XSync (dpy, False); if (desc && desc->map) { gint offset = desc->map->key_sym_map[keycode].offset; desc->map->syms[offset] = keysym; } else { fprintf (stderr, "Error changing key map: empty server structure\n"); } XkbSetMap (dpy, XkbAllMapComponentsMask, desc); /** * FIXME: the use of XkbChangeMap, and the reuse of the priv->xkb_desc structure, * would be far preferable. * HOWEVER it does not seem to work using XFree 4.3. **/ /* XkbChangeMap (dpy, priv->xkb_desc, priv->changes); */ XFlush (dpy); XSync (dpy, False); XkbFreeKeyboard (desc, 0, TRUE); return TRUE; #else return FALSE; #endif }
static int check_for_evdev(void) { SDL_SysWMinfo info; XkbDescPtr desc = NULL; int has_evdev = 0; char *keycodes = NULL; SDL_VERSION(&info.version); if (!SDL_GetWMInfo(&info)) { return 0; } desc = XkbGetMap(info.info.x11.display, XkbGBN_AllComponentsMask, XkbUseCoreKbd); if (desc && (XkbGetNames(info.info.x11.display, XkbKeycodesNameMask, desc) == Success)) { keycodes = XGetAtomName(info.info.x11.display, desc->names->keycodes); if (keycodes == NULL) { fprintf(stderr, "could not lookup keycode name\n"); } else if (strstart(keycodes, "evdev", NULL)) { has_evdev = 1; } else if (!strstart(keycodes, "xfree86", NULL)) { fprintf(stderr, "unknown keycodes `%s', please report to " "[email protected]\n", keycodes); } } if (desc) { XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True); } if (keycodes) { XFree(keycodes); } return has_evdev; }
static int _XkbLoadDpy(Display *dpy) { XkbInfoPtr xkbi; unsigned query,oldEvents; XkbDescRec *desc; if (!XkbUseExtension(dpy,NULL,NULL)) return 0; xkbi = dpy->xkb_info; query = XkbAllClientInfoMask; desc = XkbGetMap(dpy,query,XkbUseCoreKbd); if (!desc) { #ifdef DEBUG fprintf(stderr,"Warning! XkbGetMap failed!\n"); #endif return 0; } LockDisplay(dpy); xkbi->desc = desc; UnlockDisplay(dpy); oldEvents= xkbi->selected_events; if (!(xkbi->xlib_ctrls&XkbLC_IgnoreNewKeyboards)) { XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbNewKeyboardNotify, XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask, XkbNKN_KeycodesMask|XkbNKN_DeviceIDMask); } XkbSelectEventDetails(dpy,xkbi->desc->device_spec,XkbMapNotify, XkbAllClientInfoMask,XkbAllClientInfoMask); LockDisplay(dpy); xkbi->selected_events= oldEvents; UnlockDisplay(dpy); return 1; }
unsigned XkbReadFromServer(Display *dpy,unsigned need,unsigned want,XkbFileInfo *result) { unsigned which= need|want; unsigned tmp = 0; if ((result==NULL)||(dpy==NULL)) return which; if (which&XkmSymbolsMask) tmp= XkbAllMapComponentsMask; else if (which&XkmTypesMask) tmp= XkbKeyTypesMask; if (result->xkb==NULL) { result->xkb= XkbGetMap(dpy,tmp,XkbUseCoreKbd); if (!result->xkb) return which; else which&= ~(XkmSymbolsMask|XkmTypesMask|XkmVirtualModsMask); } else if ((tmp)&&(XkbGetUpdatedMap(dpy,tmp,result->xkb)==Success)) which&= ~(XkmSymbolsMask|XkmTypesMask|XkmVirtualModsMask); if (which&XkmIndicatorsMask) { if (XkbGetIndicatorMap(dpy,XkbAllIndicatorsMask,result->xkb)==Success) which&= ~XkmIndicatorsMask; } if (which&XkmCompatMapMask) { if (XkbGetCompatMap(dpy,XkbAllCompatMask,result->xkb)==Success) which&= ~XkmCompatMapMask; } if (which&XkmGeometryMask) { if (XkbGetGeometry(dpy,result->xkb)==Success) which&= ~XkmGeometryMask; } XkbGetNames(dpy,XkbAllNamesMask,result->xkb); return which; }
// Create key code translation tables // static void createKeyTables(void) { int scancode, key; memset(_glfw.x11.publicKeys, -1, sizeof(_glfw.x11.publicKeys)); if (_glfw.x11.xkb.available) { // Use XKB to determine physical key locations independently of the current // keyboard layout char name[XkbKeyNameLength + 1]; XkbDescPtr desc = XkbGetMap(_glfw.x11.display, 0, XkbUseCoreKbd); XkbGetNames(_glfw.x11.display, XkbKeyNamesMask, desc); // Find the X11 key code -> GLFW key code mapping for (scancode = desc->min_key_code; scancode <= desc->max_key_code; scancode++) { memcpy(name, desc->names->keys[scancode].name, XkbKeyNameLength); name[XkbKeyNameLength] = '\0'; // Map the key name to a GLFW key code. Note: We only map printable // keys here, and we use the US keyboard layout. The rest of the // keys (function keys) are mapped using traditional KeySym // translations. if (strcmp(name, "TLDE") == 0) key = GLFW_KEY_GRAVE_ACCENT; else if (strcmp(name, "AE01") == 0) key = GLFW_KEY_1; else if (strcmp(name, "AE02") == 0) key = GLFW_KEY_2; else if (strcmp(name, "AE03") == 0) key = GLFW_KEY_3; else if (strcmp(name, "AE04") == 0) key = GLFW_KEY_4; else if (strcmp(name, "AE05") == 0) key = GLFW_KEY_5; else if (strcmp(name, "AE06") == 0) key = GLFW_KEY_6; else if (strcmp(name, "AE07") == 0) key = GLFW_KEY_7; else if (strcmp(name, "AE08") == 0) key = GLFW_KEY_8; else if (strcmp(name, "AE09") == 0) key = GLFW_KEY_9; else if (strcmp(name, "AE10") == 0) key = GLFW_KEY_0; else if (strcmp(name, "AE11") == 0) key = GLFW_KEY_MINUS; else if (strcmp(name, "AE12") == 0) key = GLFW_KEY_EQUAL; else if (strcmp(name, "AD01") == 0) key = GLFW_KEY_Q; else if (strcmp(name, "AD02") == 0) key = GLFW_KEY_W; else if (strcmp(name, "AD03") == 0) key = GLFW_KEY_E; else if (strcmp(name, "AD04") == 0) key = GLFW_KEY_R; else if (strcmp(name, "AD05") == 0) key = GLFW_KEY_T; else if (strcmp(name, "AD06") == 0) key = GLFW_KEY_Y; else if (strcmp(name, "AD07") == 0) key = GLFW_KEY_U; else if (strcmp(name, "AD08") == 0) key = GLFW_KEY_I; else if (strcmp(name, "AD09") == 0) key = GLFW_KEY_O; else if (strcmp(name, "AD10") == 0) key = GLFW_KEY_P; else if (strcmp(name, "AD11") == 0) key = GLFW_KEY_LEFT_BRACKET; else if (strcmp(name, "AD12") == 0) key = GLFW_KEY_RIGHT_BRACKET; else if (strcmp(name, "AC01") == 0) key = GLFW_KEY_A; else if (strcmp(name, "AC02") == 0) key = GLFW_KEY_S; else if (strcmp(name, "AC03") == 0) key = GLFW_KEY_D; else if (strcmp(name, "AC04") == 0) key = GLFW_KEY_F; else if (strcmp(name, "AC05") == 0) key = GLFW_KEY_G; else if (strcmp(name, "AC06") == 0) key = GLFW_KEY_H; else if (strcmp(name, "AC07") == 0) key = GLFW_KEY_J; else if (strcmp(name, "AC08") == 0) key = GLFW_KEY_K; else if (strcmp(name, "AC09") == 0) key = GLFW_KEY_L; else if (strcmp(name, "AC10") == 0) key = GLFW_KEY_SEMICOLON; else if (strcmp(name, "AC11") == 0) key = GLFW_KEY_APOSTROPHE; else if (strcmp(name, "AB01") == 0) key = GLFW_KEY_Z; else if (strcmp(name, "AB02") == 0) key = GLFW_KEY_X; else if (strcmp(name, "AB03") == 0) key = GLFW_KEY_C; else if (strcmp(name, "AB04") == 0) key = GLFW_KEY_V; else if (strcmp(name, "AB05") == 0) key = GLFW_KEY_B; else if (strcmp(name, "AB06") == 0) key = GLFW_KEY_N; else if (strcmp(name, "AB07") == 0) key = GLFW_KEY_M; else if (strcmp(name, "AB08") == 0) key = GLFW_KEY_COMMA; else if (strcmp(name, "AB09") == 0) key = GLFW_KEY_PERIOD; else if (strcmp(name, "AB10") == 0) key = GLFW_KEY_SLASH; else if (strcmp(name, "BKSL") == 0) key = GLFW_KEY_BACKSLASH; else if (strcmp(name, "LSGT") == 0) key = GLFW_KEY_WORLD_1; else key = GLFW_KEY_UNKNOWN; if ((scancode >= 0) && (scancode < 256)) _glfw.x11.publicKeys[scancode] = key; } XkbFreeNames(desc, XkbKeyNamesMask, True); XkbFreeClientMap(desc, 0, True); } // Translate the un-translated key codes using traditional X11 KeySym // lookups for (scancode = 0; scancode < 256; scancode++) { if (_glfw.x11.publicKeys[scancode] < 0) _glfw.x11.publicKeys[scancode] = translateKeyCode(scancode); } }
int main(int argc, char *argv[]) { Widget toplevel; XtAppContext app_con; Widget panel; Widget leds[XkbNumIndicators]; register int i; unsigned bit; unsigned n; XkbDescPtr xkb; XkbEvent ev; static Arg boxArgs[]= {{ XtNorientation, (XtArgVal)XtorientHorizontal }}; static Arg onArgs[]= {{ XtNon, (XtArgVal)True }}; static Arg offArgs[]= {{ XtNon, (XtArgVal)False }}; static char * fallback_resources[] = { "*Box*background: grey40", NULL }; uSetEntryFile(NullString); uSetDebugFile(NullString); uSetErrorFile(NullString); bzero(leds,XkbNumIndicators*sizeof(Widget)); toplevel = XtOpenApplication(&app_con, "XkbLEDPanel", NULL, 0, &argc, argv, fallback_resources, sessionShellWidgetClass, NULL, ZERO); if (toplevel==NULL) { uFatalError("Couldn't create application top level\n"); return 1; } if ((argc>1)&&(!parseArgs(argc,argv))) { usage(argv[0]); return 1; } if ((wanted==0)&&(wantNamed==DONT_CARE)&&(wantExplicit==DONT_CARE)&& (wantAutomatic==DONT_CARE)&&(wantReal==DONT_CARE)) { wantNamed= YES; wantReal= YES; wantAutomatic= YES; } outDpy= XtDisplay(toplevel); if (inDpyName!=NULL) { inDpy= GetDisplay(argv[0],inDpyName); if (!inDpy) return 1; } else { inDpy= outDpy; } if (inDpy) { int i1,mn,mj; mj= XkbMajorVersion; mn= XkbMinorVersion; if (!XkbLibraryVersion(&mj,&mn)) { uInformation("%s was compiled with XKB version %d.%02d\n", argv[0],XkbMajorVersion,XkbMinorVersion); uError("X library supports incompatible version %d.%02d\n", mj,mn); } if (!XkbQueryExtension(inDpy,&i1,&evBase,&errBase,&mj,&mn)) { uFatalError("Server doesn't support a compatible XKB\n"); return 1; } } else { uFatalError("No input display\n"); return 1; } panel= XtCreateManagedWidget("xkbleds",boxWidgetClass,toplevel,boxArgs,1); if (panel==NULL) { uFatalError("Couldn't create list of leds\n"); return 1; } real= virtual= named= explicit= automatic= 0; if (wantReal || wantNamed || wantAutomatic || wantExplicit || wantVirtual) { register int i,bit; xkb= XkbGetMap(inDpy,0,XkbUseCoreKbd); if (!xkb) { uFatalError("Couldn't read keymap\n"); return 1; } if (XkbGetIndicatorMap(inDpy,XkbAllIndicatorsMask,xkb)!=Success) { uFatalError("Couldn't read indicator map\n"); return 1; } if (XkbGetNames(inDpy,XkbAllNamesMask,xkb)!=Success) { uFatalError("Couldn't read indicator names\n"); return 1; } for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { XkbIndicatorMapPtr map= &xkb->indicators->maps[i]; if (xkb->names->indicators[i]!=None) named|= bit; if (xkb->indicators->phys_indicators&bit) real|= bit; if ((((map->which_groups!=0)&&(map->groups!=0))|| ((map->which_mods!=0)&& ((map->mods.real_mods!=0)||(map->mods.vmods!=0)))|| (map->ctrls!=0))&& ((map->flags&XkbIM_NoAutomatic)==0)) { automatic|= bit; } else explicit|= bit; } virtual= ~real; if (wantReal==NO) real= ~real; else if (wantReal==DONT_CARE) real= (useUnion?0:~0); if (wantVirtual==NO) virtual= ~virtual; else if (wantVirtual==DONT_CARE) virtual= (useUnion?0:~0); if (wantNamed==NO) named= ~named; else if (wantNamed==DONT_CARE) named= (useUnion?0:~0); if (wantAutomatic==NO) automatic= ~automatic; else if (wantAutomatic==DONT_CARE) automatic= (useUnion?0:~0); if (wantExplicit==NO) explicit= ~explicit; else if (wantExplicit==DONT_CARE) explicit= (useUnion?0:~0);
Boolean InitXkb(Display *theDisplay) { int i,opcode,errorBase,major,minor; XkbDescPtr xkb; unsigned int bit; unsigned int real,virtual,named,explicit,automatic; char *name; if (!XkbQueryExtension(theDisplay, &opcode, &xkbEventBase, &errorBase, &major, &minor)) return False; if (!XkbUseExtension(theDisplay,&major,&minor)) return False; XkbSelectEvents(theDisplay, XkbUseCoreKbd, XkbIndicatorStateNotifyMask|XkbIndicatorMapNotifyMask, XkbIndicatorStateNotifyMask|XkbIndicatorMapNotifyMask); XtSetEventDispatcher(theDisplay, xkbEventBase+XkbEventCode, XkbEventHandler); xkb=XkbGetMap(theDisplay,0,XkbUseCoreKbd); real=virtual=named=explicit=automatic=0; if (!xkb) { fprintf(stderr,"Couldn't get keymap\n"); return False; } if (XkbGetIndicatorMap(theDisplay,XkbAllIndicatorsMask,xkb)!=Success) { fprintf(stderr,"Couldn't read indicator map\n"); XkbFreeKeyboard(xkb,XkbAllComponentsMask,True); return False; } real=virtual=named=explicit=automatic=0; if (XkbGetNames(theDisplay,XkbIndicatorNamesMask,xkb)!=Success) { fprintf(stderr,"Couldn't read indicator names\n"); XkbFreeKeyboard(xkb,XkbAllComponentsMask,True); return False; } real=virtual=named=explicit=automatic=0; for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { XkbIndicatorMapPtr map= &xkb->indicators->maps[i]; name = NULL; if (xkb->names->indicators[i]!=None) { named|= bit; name = XGetAtomName(theDisplay,xkb->names->indicators[i]); } if (name != NULL) { ledAtoms[i] = xkb->names->indicators[i]; ledNames[i] = XmStringCreate(name,XmSTRING_DEFAULT_CHARSET); } else { char temp[12]; sprintf(temp,"led%d\0",i+1); ledAtoms[i] = None; ledNames[i] = XmStringCreate(temp,XmSTRING_DEFAULT_CHARSET); } if (xkb->indicators->phys_indicators&bit) real|= bit; if ((((map->which_groups!=0)&&(map->groups!=0))|| ((map->which_mods!=0)&& ((map->mods.real_mods!=0)||(map->mods.vmods!=0)))|| (map->ctrls!=0))&& ((map->flags&XkbIM_NoAutomatic)==0)) { automatic|= bit; } else explicit|= bit; } virtual = ~real; if (options.useUnion) { if ((options.wantReal==NO) || (options.wantReal==DONT_CARE)) real = 0; if ((options.wantVirtual==NO) || (options.wantVirtual==DONT_CARE)) virtual = 0; if ((options.wantNamed==NO) || (options.wantNamed==DONT_CARE)) named = 0; if ((options.wantAutomatic==NO) || (options.wantAutomatic==DONT_CARE)) automatic = 0; if ((options.wantExplicit==NO) || (options.wantExplicit==DONT_CARE)) explicit = 0; options.wanted |= real|virtual|named|automatic|explicit; } else { if (options.wanted == DONT_CARE)
/* Grab or ungrab then keyval and modifiers combination, grabbing all key * combinations yielding the same key values. * Includes ignorable modifiers using grab_ungrab_with_ignorable_modifiers. */ static gboolean grab_ungrab (GdkWindow *rootwin, uint keyval, uint modifiers, gboolean grab) { int k; GdkKeymap *map; GdkKeymapKey *keys; gint n_keys; GdkModifierType add_modifiers; XkbDescPtr xmap; gboolean success = FALSE; xmap = XkbGetMap(GDK_WINDOW_XDISPLAY(rootwin), XkbAllClientInfoMask, XkbUseCoreKbd); map = gdk_keymap_get_default(); gdk_keymap_get_entries_for_keyval(map, keyval, &keys, &n_keys); if (n_keys == 0) return FALSE; for (k = 0; k < n_keys; k++) { /* NOTE: We only bind for the first group, * so regardless of current keyboard layout, it will * grab the key from the default Layout. */ if (keys[k].group != WE_ONLY_USE_ONE_GROUP) { continue; } add_modifiers = FinallyGetModifiersForKeycode(xmap, keys[k].keycode, keys[k].group, keys[k].level); if (add_modifiers == MODIFIERS_ERROR) { continue; } TRACE (g_print("grab/ungrab keycode: %d, lev: %d, grp: %d, ", keys[k].keycode, keys[k].level, keys[k].group)); TRACE (g_print("modifiers: 0x%x (consumed: 0x%x)\n", add_modifiers | modifiers, add_modifiers)); if (grab_ungrab_with_ignorable_modifiers(rootwin, keys[k].keycode, add_modifiers | modifiers, grab)) { success = TRUE; } else { /* When grabbing, break on error */ if (grab && !success) { break; } } } g_free(keys); XkbFreeClientMap(xmap, 0, TRUE); return success; }
static void spi_controller_register_with_devices (SpiDEController *controller) { DEControllerPrivateData *priv; int event_base, error_base, major_version, minor_version; priv = controller->priv; if (XTestQueryExtension (spi_get_display(), &event_base, &error_base, &major_version, &minor_version)) { XTestGrabControl (spi_get_display (), True); } /* calls to device-specific implementations and routines go here */ /* register with: keyboard hardware code handler */ /* register with: (translated) keystroke handler */ priv->have_xkb = XkbQueryExtension (spi_get_display (), &priv->xkb_major_extension_opcode, &priv->xkb_base_event_code, &priv->xkb_base_error_code, NULL, NULL); if (priv->have_xkb) { gint i; guint64 reserved = 0; priv->xkb_desc = XkbGetMap (spi_get_display (), XkbKeySymsMask, XkbUseCoreKbd); XkbSelectEvents (spi_get_display (), XkbUseCoreKbd, XkbStateNotifyMask, XkbStateNotifyMask); _numlock_physical_mask = XkbKeysymToModifiers (spi_get_display (), XK_Num_Lock); for (i = priv->xkb_desc->max_key_code; i >= priv->xkb_desc->min_key_code; --i) { if (priv->xkb_desc->map->key_sym_map[i].kt_index[0] == XkbOneLevelIndex) { if (XkbKeycodeToKeysym (spi_get_display (), i, 0, 0) != 0) { /* don't use this one if there's a grab client! */ /* Runtime errors are generated from these functions, * that are then quashed. Equivalent to: * try * {Blah} * except * {;} */ spi_x_error_trap (); XGrabKey (spi_get_display (), i, 0, spi_get_root_window (), TRUE, GrabModeSync, GrabModeSync); XSync (spi_get_display (), TRUE); XUngrabKey (spi_get_display (), i, 0, spi_get_root_window ()); if (!spi_x_error_release ()) { reserved = i; break; } } } } if (reserved) { priv->reserved_keycode = reserved; priv->reserved_keysym = XkbKeycodeToKeysym (spi_get_display (), reserved, 0, 0); } else { priv->reserved_keycode = XKeysymToKeycode (spi_get_display (), XK_numbersign); priv->reserved_keysym = XK_numbersign; } #ifdef SPI_RESERVED_DEBUG unsigned sym = 0; sym = XKeycodeToKeysym (spi_get_display (), reserved, 0); fprintf (stderr, "%x\n", sym); fprintf (stderr, "setting the reserved keycode to %d (%s)\n", reserved, XKeysymToString (XKeycodeToKeysym (spi_get_display (), reserved, 0))); #endif } spi_set_filter (global_filter_fn, controller); spi_set_events (KeyPressMask | KeyReleaseMask); x_default_error_handler = XSetErrorHandler (_spi_controller_device_error_handler); }