示例#1
0
static int
KdKeybdProc(DeviceIntPtr pDevice, int onoff)
{
    Bool        ret;
    DevicePtr   pDev = (DevicePtr)pDevice;
#ifdef XKB
    XkbComponentNamesRec names;
#endif

    if (!pDev)
	return BadImplementation;

    switch (onoff)
    {
    case DEVICE_INIT:
	if (pDev != LookupKeyboardDevice())
	{
	    return !Success;
	}
#ifndef XKB
	ret = InitKeyboardDeviceStruct(pDev,
				       &kdKeySyms,
				       kdModMap,
				       KdBell, KdKbdCtrl);
#else
	memset(&names, 0, sizeof(XkbComponentNamesRec));

	if (XkbInitialMap) 
	    names.keymap = XkbInitialMap;

	XkbSetRulesDflts ("base", "pc101", "us", NULL, NULL);
	ret = XkbInitKeyboardDeviceStruct ((DeviceIntPtr) pDev,
					   &names,
					   &kdKeySyms,
					   kdModMap,
					   KdBell, KdKbdCtrl);
#endif
	if (!ret)
	    return BadImplementation;
	break;
    case DEVICE_ON:
	pDev->on = TRUE;
	pKdKeyboard = pDevice;
	if (kdKeyboardFuncs)
	    (*kdKeyboardFuncs->Init) ();
	break;
    case DEVICE_OFF:
    case DEVICE_CLOSE:
	pKdKeyboard = 0;
	if (pDev->on)
	{
	    pDev->on = FALSE;
	    if (kdKeyboardFuncs)
		(*kdKeyboardFuncs->Fini) ();
	}
	break;
    }
    return Success;
}
示例#2
0
_X_EXPORT Bool
InitKeyboardDeviceStruct(DeviceIntPtr dev, XkbRMLVOSet *rmlvo,
                         BellProcPtr bell_func, KbdCtrlProcPtr ctrl_func)
{
    int	i;
    unsigned int check;
    XkbSrvInfoPtr xkbi;
    XkbDescPtr xkb;
    XkbSrvLedInfoPtr sli;
    XkbChangesRec changes;
    XkbEventCauseRec cause;
    XkbRMLVOSet rmlvo_dflts = { NULL };

    if (dev->key || dev->kbdfeed)
	return FALSE;

    if (!rmlvo)
    {
        rmlvo = &rmlvo_dflts;
        XkbGetRulesDflts(rmlvo);
    }


    memset(&changes, 0, sizeof(changes));
    XkbSetCauseUnknown(&cause);

    dev->key = calloc(1, sizeof(*dev->key));
    if (!dev->key) {
        ErrorF("XKB: Failed to allocate key class\n");
        return FALSE;
    }
    dev->key->sourceid = dev->id;

    dev->kbdfeed = calloc(1, sizeof(*dev->kbdfeed));
    if (!dev->kbdfeed) {
        ErrorF("XKB: Failed to allocate key feedback class\n");
        goto unwind_key;
    }

    xkbi = calloc(1, sizeof(*xkbi));
    if (!xkbi) {
        ErrorF("XKB: Failed to allocate XKB info\n");
        goto unwind_kbdfeed;
    }
    dev->key->xkbInfo = xkbi;

    if (xkb_cached_map && !XkbCompareUsedRMLVO(rmlvo)) {
        XkbFreeKeyboard(xkb_cached_map, XkbAllComponentsMask, TRUE);
        xkb_cached_map = NULL;
    }

    if (xkb_cached_map)
        LogMessageVerb(X_INFO, 4, "XKB: Reusing cached keymap\n");
    else {
        xkb_cached_map = XkbCompileKeymap(dev, rmlvo);
        if (!xkb_cached_map) {
            ErrorF("XKB: Failed to compile keymap\n");
            goto unwind_info;
        }
    }

    xkb = XkbAllocKeyboard();
    if (!xkb) {
        ErrorF("XKB: Failed to allocate keyboard description\n");
        goto unwind_info;
    }

    if (!XkbCopyKeymap(xkb, xkb_cached_map)) {
        ErrorF("XKB: Failed to copy keymap\n");
        goto unwind_desc;
    }
    xkb->defined = xkb_cached_map->defined;
    xkb->flags = xkb_cached_map->flags;
    xkb->device_spec = xkb_cached_map->device_spec;
    xkbi->desc = xkb;

    if (xkb->min_key_code == 0)
        xkb->min_key_code = 8;
    if (xkb->max_key_code == 0)
        xkb->max_key_code = 255;

    i = XkbNumKeys(xkb) / 3 + 1;
    if (XkbAllocClientMap(xkb, XkbAllClientInfoMask, 0) != Success)
        goto unwind_desc;
    if (XkbAllocServerMap(xkb, XkbAllServerInfoMask, i) != Success)
        goto unwind_desc;

    xkbi->dfltPtrDelta = 1;
    xkbi->device = dev;

    XkbInitSemantics(xkb);
    XkbInitNames(xkbi);
    XkbInitRadioGroups(xkbi);

    XkbInitControls(dev, xkbi);

    XkbInitIndicatorMap(xkbi);

    XkbUpdateActions(dev, xkb->min_key_code, XkbNumKeys(xkb), &changes,
                     &check, &cause);

    InitFocusClassDeviceStruct(dev);

    xkbi->kbdProc = ctrl_func;
    dev->kbdfeed->BellProc = bell_func;
    dev->kbdfeed->CtrlProc = XkbDDXKeybdCtrlProc;

    dev->kbdfeed->ctrl = defaultKeyboardControl;
    if (dev->kbdfeed->ctrl.autoRepeat)
        xkb->ctrls->enabled_ctrls |= XkbRepeatKeysMask;

    memcpy(dev->kbdfeed->ctrl.autoRepeats, xkb->ctrls->per_key_repeat,
           XkbPerKeyBitArraySize);

    sli = XkbFindSrvLedInfo(dev, XkbDfltXIClass, XkbDfltXIId, 0);
    if (sli)
	XkbCheckIndicatorMaps(dev, sli, XkbAllIndicatorsMask);
    else
        DebugF("XKB: No indicator feedback in XkbFinishInit!\n");

    dev->kbdfeed->CtrlProc(dev,&dev->kbdfeed->ctrl);

    XkbSetRulesDflts(rmlvo);
    XkbSetRulesUsed(rmlvo);
    XkbFreeRMLVOSet(&rmlvo_dflts, FALSE);

    return TRUE;

unwind_desc:
    XkbFreeKeyboard(xkb, 0, TRUE);
unwind_info:
    free(xkbi);
    dev->key->xkbInfo = NULL;
unwind_kbdfeed:
    free(dev->kbdfeed);
    dev->kbdfeed = NULL;
unwind_key:
    free(dev->key);
    dev->key = NULL;
    return FALSE;
}
示例#3
0
int
xnestKeyboardProc(DeviceIntPtr pDev, int onoff)
{
  XModifierKeymap *modifier_keymap;
  KeySym *keymap;
  int mapWidth;
  int min_keycode, max_keycode;
  KeySymsRec keySyms;
  CARD8 modmap[MAP_LENGTH];
  int i, j;
  XKeyboardState values;

  switch (onoff)
    {
    case DEVICE_INIT: 
      modifier_keymap = XGetModifierMapping(xnestDisplay);
      XDisplayKeycodes(xnestDisplay, &min_keycode, &max_keycode);
#ifdef _XSERVER64
      {
	KeySym64 *keymap64;
	int i, len;
	keymap64 = XGetKeyboardMapping(xnestDisplay,
				     min_keycode,
				     max_keycode - min_keycode + 1,
				     &mapWidth);
	len = (max_keycode - min_keycode + 1) * mapWidth;
	keymap = (KeySym *)xalloc(len * sizeof(KeySym));
	for(i = 0; i < len; ++i)
	  keymap[i] = keymap64[i];
	XFree(keymap64);
      }
#else
      keymap = XGetKeyboardMapping(xnestDisplay, 
				   min_keycode,
				   max_keycode - min_keycode + 1,
				   &mapWidth);
#endif
      
      for (i = 0; i < MAP_LENGTH; i++)
	modmap[i] = 0;
      for (j = 0; j < 8; j++)
	for(i = 0; i < modifier_keymap->max_keypermod; i++) {
	  CARD8 keycode;
	  if ((keycode = 
	      modifier_keymap->
	        modifiermap[j * modifier_keymap->max_keypermod + i]))
	    modmap[keycode] |= 1<<j;
	}
      XFreeModifiermap(modifier_keymap);
      
      keySyms.minKeyCode = min_keycode;
      keySyms.maxKeyCode = max_keycode;
      keySyms.mapWidth = mapWidth;
      keySyms.map = keymap;

#ifdef XKB
      if (noXkbExtension) {
XkbError:
#endif
      XGetKeyboardControl(xnestDisplay, &values);

      memmove((char *) defaultKeyboardControl.autoRepeats,
             (char *) values.auto_repeats, sizeof(values.auto_repeats));

      InitKeyboardDeviceStruct(&pDev->public, &keySyms, modmap,
			       xnestBell, xnestChangeKeyboardControl);
#ifdef XKB
      } else {
	FILE *file;
	XkbConfigRtrnRec config;

	XkbComponentNamesRec names;
	char *rules, *model, *layout, *variants, *options;

	XkbDescPtr xkb;
	int op, event, error, major, minor;

	if (XkbQueryExtension(xnestDisplay, &op, &event, &error, &major, &minor) == 0) {
	  ErrorF("Unable to initialize XKEYBOARD extension.\n");
	  goto XkbError;
        }
	xkb = XkbGetKeyboard(xnestDisplay, XkbGBN_AllComponentsMask, XkbUseCoreKbd);
	if (xkb == NULL || xkb->geom == NULL) {
	  ErrorF("Couldn't get keyboard.\n");
	  goto XkbError;
	}
	XkbGetControls(xnestDisplay, XkbAllControlsMask, xkb);

	memset(&names, 0, sizeof(XkbComponentNamesRec));
	rules = XKB_DFLT_RULES_FILE;
	model = XKB_DFLT_KB_MODEL;
	layout = XKB_DFLT_KB_LAYOUT;
	variants = XKB_DFLT_KB_VARIANT;
	options = XKB_DFLT_KB_OPTIONS;
	if (XkbInitialMap) {
	  if ((names.keymap = strchr(XkbInitialMap, '/')) != NULL)
	    ++names.keymap;
	  else
	    names.keymap = XkbInitialMap;
	}

	XkbSetRulesDflts(rules, model, layout, variants, options);
	XkbInitKeyboardDeviceStruct(pDev, &names, &keySyms, modmap,
				    xnestBell, xnestChangeKeyboardControl);
	XkbDDXChangeControls(pDev, xkb->ctrls, xkb->ctrls);
	XkbFreeKeyboard(xkb, 0, False);
      }
#endif
#ifdef _XSERVER64
      xfree(keymap);
#else
      XFree(keymap);
#endif
      break;
    case DEVICE_ON: 
      xnestEventMask |= XNEST_KEYBOARD_EVENT_MASK;
      for (i = 0; i < xnestNumScreens; i++)
	XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask);
      break;
    case DEVICE_OFF: 
      xnestEventMask &= ~XNEST_KEYBOARD_EVENT_MASK;
      for (i = 0; i < xnestNumScreens; i++)
	XSelectInput(xnestDisplay, xnestDefaultWindows[i], xnestEventMask);
      break;
    case DEVICE_CLOSE: 
      break;
    }
示例#4
0
int
winKeybdProc (DeviceIntPtr pDeviceInt, int iState)
{
  KeySymsRec		keySyms;
  CARD8 		modMap[MAP_LENGTH];
  DevicePtr		pDevice = (DevicePtr) pDeviceInt;
#ifdef XKB
  XkbComponentNamesRec names;
  XkbSrvInfoPtr       xkbi;
  XkbControlsPtr      ctrl;
#endif

  switch (iState)
    {
    case DEVICE_INIT:
      winConfigKeyboard (pDeviceInt);

      winGetKeyMappings (&keySyms, modMap);

#ifdef XKB
      /* FIXME: Maybe we should use winGetKbdLeds () here? */
      defaultKeyboardControl.leds = g_winInfo.keyboard.leds;
#else
      defaultKeyboardControl.leds = g_winInfo.keyboard.leds;
#endif

#ifdef XKB
      if (g_winInfo.xkb.disable) 
	{
#endif
	  InitKeyboardDeviceStruct (pDevice,
				    &keySyms,
				    modMap,
				    winKeybdBell,
				    winKeybdCtrl);
#ifdef XKB
	} 
      else 
	{

	  if (XkbInitialMap) 
	    {
	      names.keymap = XkbInitialMap;
	      names.keycodes = NULL;
	      names.types = NULL;
	      names.compat = NULL;
	      names.symbols = NULL;
	      names.geometry = NULL;
	    } 
	  else 
	    {
	      names.keymap = g_winInfo.xkb.keymap;
	      names.keycodes = g_winInfo.xkb.keycodes;
	      names.types = g_winInfo.xkb.types;
	      names.compat = g_winInfo.xkb.compat;
	      names.symbols = g_winInfo.xkb.symbols;
	      names.geometry = g_winInfo.xkb.geometry;
	    }

	  winErrorFVerb(2, "Rules = \"%s\" Model = \"%s\" Layout = \"%s\""
		 " Variant = \"%s\" Options = \"%s\"\n",
		 g_winInfo.xkb.rules, g_winInfo.xkb.model,
		 g_winInfo.xkb.layout, g_winInfo.xkb.variant,
		 g_winInfo.xkb.options);
          
	  XkbSetRulesDflts (g_winInfo.xkb.rules, g_winInfo.xkb.model, 
			    g_winInfo.xkb.layout, g_winInfo.xkb.variant, 
			    g_winInfo.xkb.options);
	  XkbInitKeyboardDeviceStruct (pDeviceInt, &names, &keySyms,
				       modMap, winKeybdBell, winKeybdCtrl);
	}
#endif

#ifdef XKB
      if (!g_winInfo.xkb.disable)
        {  
          xkbi = pDeviceInt->key->xkbInfo;
          if (xkbi != NULL)
            {  
              ctrl = xkbi->desc->ctrls;
              ctrl->repeat_delay = g_winInfo.keyboard.delay;
              ctrl->repeat_interval = 1000/g_winInfo.keyboard.rate;
            }
          else
            {  
              winErrorFVerb (1, "winKeybdProc - Error initializing keyboard AutoRepeat (No XKB)\n");
            }
        }
#endif

      g_winInternalModeKeyStatesPtr = &(pDeviceInt->key->state);
      break;
      
    case DEVICE_ON: 
      pDevice->on = TRUE;
      g_winInternalModeKeyStatesPtr = &(pDeviceInt->key->state);
      break;

    case DEVICE_CLOSE:
    case DEVICE_OFF: 
      pDevice->on = FALSE;
      g_winInternalModeKeyStatesPtr = NULL;
      break;
    }

  return Success;
}