示例#1
0
/* FIXME: add more languages, then copy to x11kbd.c */
int kbd_arch_get_host_mapping(void)
{

    int n;
    int maps[KBD_MAPPING_NUM] = {
        KBD_MAPPING_US, KBD_MAPPING_UK, KBD_MAPPING_DE, KBD_MAPPING_DA,
        KBD_MAPPING_NO, KBD_MAPPING_FI, KBD_MAPPING_IT };
    char str[KBD_MAPPING_NUM][3] = {
        "us", "uk", "de", "da", "no", "fi", "it"};

    Display* _display;
    char* displayName = "";
    _display = XOpenDisplay(displayName);

    XkbDescRec* _kbdDescPtr = XkbAllocKeyboard();
    XkbGetNames(_display, XkbSymbolsNameMask, _kbdDescPtr);
    Atom symName = _kbdDescPtr -> names -> symbols;
    char* layoutString = XGetAtomName(_display, symName);

    XCloseDisplay(_display);
    char *p = layoutString;

    if (memcmp(p, "pc+", 3) == 0) {
        p += 3;
        if (p && (strlen(p) > 1)) {
            for (n = 1; n < KBD_MAPPING_NUM; n++) {
                if (memcmp(p, str[n], 2) == 0) {
                    return maps[n];
                }
            }
        }
    }
    return KBD_MAPPING_US;
}
示例#2
0
int main(void) {
    int evCode, errRet, rsnRet;
    int maj = XkbMajorVersion;
    int min = XkbMinorVersion;

    Display* disp = XkbOpenDisplay("", &evCode, &errRet, &maj, &min, &rsnRet);

    // State
    XkbStatePtr state = calloc(1, sizeof(XkbStateRec));
    XkbGetState(disp, 0x100, state);

    // Names
    XkbDescPtr desc = XkbAllocKeyboard();
    XkbGetNames(disp, XkbSymbolsNameMask, desc);

    Atom symNameAtom = desc->names->symbols;
    char* layouts = XGetAtomName(disp, symNameAtom);

    printf("%s\n", getActiveLayout(layouts, state->group));

    unsigned int mask = XkbStateNotifyMask;
    XkbSelectEvents(disp, XkbUseCoreKbd, mask, mask);

    XkbEvent event;
    while (1) {
        XNextEvent(disp, &event.core);
        if (event.state.changed & 0x90)
            printf("%s\n", getActiveLayout(layouts, event.state.group));
    }
}
示例#3
0
// 0 - Success
int xkbleds_init()
{
  KeyCode keys[NUM_LEDS];
  XkbDescPtr xkb;
  char *ind_name = NULL;
  int j, mask;
  int idx[NUM_LEDS];/* NUM, CAPS, SCROLL: indicator index, for XKB */
    
// open X display
  d = XOpenDisplay(NULL);
  if (!d)
    return 1;
// get keycodes
  for(i = 0; i < NUM_LEDS; i++)
    keys[i] = XKeysymToKeycode(d, key_syms[i]);
// get the keyboard
  xkb = XkbAllocKeyboard();
  if(!xkb){
    XCloseDisplay(d);
    return 1;
  }

  if(XkbGetNames(d, XkbIndicatorNamesMask, xkb) != Success){
    XkbFreeKeyboard(xkb, 0, True);
    XCloseDisplay(d);
    return 1;
  }
// get masks and indexes of indicators
  for(i = 0; i < XkbNumIndicators; i++) {
    if(xkb->names->indicators[i])
      ind_name = XGetAtomName(d, xkb->names->indicators[i]);
    for(j = 0; j < NUM_LEDS; j++){
      if(ind_name && !strcmp(lock_names[j], ind_name)){
	     if(XkbGetNamedIndicator(d, xkb->names->indicators[i], &mask,
				NULL, NULL, NULL) == True){
            masks[j] = 1 << mask;
            idx[j] = mask;
         } else {
            XkbFreeKeyboard(xkb, 0, True);
            XCloseDisplay(d);
            return 1;
         }
      }
    }
    if(ind_name){
      free(ind_name);
      ind_name = NULL;
    }
  }
// cleanup
  XkbFreeKeyboard(xkb, 0, True);
  XCloseDisplay(d);
  return 0;
}
示例#4
0
char* xkbGetGroup(char* buf, int len) {
	int  xkbEventType, xkbError, reason_rtrn, mjr, mnr;
	char *display_name;
	XkbStateRec xkbstate;

	static Display *dpy = NULL;
	static XkbDescPtr xkbdesc = NULL;

	/* Lets begin */
	if (!dpy) {
		display_name = NULL;
		mjr = XkbMajorVersion;
		mnr = XkbMinorVersion;
		dpy = XkbOpenDisplay(display_name, &xkbEventType, &xkbError,
				&mjr, &mnr, &reason_rtrn);
	}

	if (dpy == NULL) {
		strcpy(buf, "?");
		return buf;
	}

	if ( Success != XkbGetState(dpy, XkbUseCoreKbd, &xkbstate) ) {
		strcpy(buf, "?");
		return buf;
	}

	if (!xkbdesc)
		xkbdesc = XkbAllocKeyboard();

	if (!xkbdesc) {
		strcpy(buf, "?");
		return buf;
	}

	/* get the names of the layout */
	if ( Success == XkbGetNames(dpy, 1<<12, xkbdesc)) {
		Atom iatoms[4];
		char *iatomnames[4];
		int i, j;

		for (i = 0, j = 0; i < 4; i++)
			if (xkbdesc->names->groups[i] != None)
				iatoms[j++] = xkbdesc->names->groups[i];

		if (XGetAtomNames(dpy, iatoms, j, iatomnames))
			buf = strndup(iatomnames[xkbstate.locked_group], len);
	}

	return buf;
}
示例#5
0
kbrate* xkbset_repeatrate(Display *dpy, int delay, int interval) {
  kbrate* kb_bak = malloc(sizeof(kbrate));
  XkbDescPtr xkb = XkbAllocKeyboard();
  if (!xkb){return;}
  XkbGetControls(dpy, XkbRepeatKeysMask, xkb);
  kb_bak->delay = xkb->ctrls->repeat_delay;
  kb_bak->interval = xkb->ctrls->repeat_interval;
  xkb->ctrls->repeat_delay = delay;
  xkb->ctrls->repeat_interval = interval;
  XkbSetControls(dpy, XkbRepeatKeysMask, xkb);
  // Need to call GetControls again to reload into the server?
  XkbGetControls(dpy, XkbRepeatKeysMask, xkb);
  return kb_bak;
}
示例#6
0
文件: fbxkb.c 项目: kba/fbxkb
/* gets vital info to switch xkb language groups */
static void
get_group_info()
{
    XkbDescRec *kbd_desc_ptr;
    XkbStateRec xkb_state;
    int i;

    ENTER;
    kbd_desc_ptr = XkbAllocKeyboard();
    if (!kbd_desc_ptr) {
        ERR("can't alloc kbd info\n");
        exit(1);
    }
    //kbd_desc_ptr->dpy = GDK_DISPLAY();
    if (XkbGetControls(dpy, XkbAllControlsMask, kbd_desc_ptr) !=
            Success) {
        ERR("can't get Xkb controls\n");
        goto out;
    }
    ngroups = kbd_desc_ptr->ctrls->num_groups;
    if (ngroups < 1) {
        ERR("No keyboard group found\n");
        goto out;
    }
    if (XkbGetState(dpy, XkbUseCoreKbd, &xkb_state) != Success) {
        ERR("can't get Xkb state\n");
        goto out;
    }
    cur_group = xkb_state.group;
    DBG("cur_group = %d ngroups = %d\n", cur_group, ngroups);
    if (XkbGetNames(dpy, XkbGroupNamesMask, kbd_desc_ptr) != Success) {
        ERR("Can't get group names\n");
        goto out;
    }
    for (i = 0; i < ngroups; i++) {
        if (!(group[i].name = XGetAtomName(dpy, kbd_desc_ptr->names->groups[i]))) {
            ERR("Can't get name of group #%d\n", i);
            goto out;
        }
        group[i].flag = default_flag;
        DBG("group[%d].name=%s\n", i, group[i].name);
    }

    get_group_flags(kbd_desc_ptr);

out:
    XkbFreeKeyboard(kbd_desc_ptr, 0, True);
}
示例#7
0
int
xkblayoutSetup() {

	// Turn off ignoring xkb extension, force its use
	XkbIgnoreExtension(False);

	char *dispName = "";
	int eventCode;
	int errorReturn;
	int majorVer = XkbMajorVersion;
	int minorVer = XkbMinorVersion;
	int reasonReturn;
	
	dpy = XkbOpenDisplay(dispName, &eventCode, &errorReturn, &majorVer, &minorVer, &reasonReturn);
	kbdDescPtr = XkbAllocKeyboard();

	return 0;
}
static
void set_repeatrate(int delay, double rate)
{
	if( !X11Helper::xkbSupported(NULL) ) {
		kError() << "Failed to set keyboard repeat rate: xkb is not supported";
		return;
	}

	XkbDescPtr xkb = XkbAllocKeyboard();
	if (xkb) {
		Display* dpy = QX11Info::display();
		int res = XkbGetControls(dpy, XkbRepeatKeysMask, xkb);
		xkb->ctrls->repeat_delay = delay;
		xkb->ctrls->repeat_interval = (int)floor(1000/rate + 0.5);
		res = XkbSetControls(dpy, XkbRepeatKeysMask, xkb);
                XkbFreeKeyboard(xkb, 0, true);
		return;
	}
}
示例#9
0
XKeyboard::XKeyboard()
  : _display(0), _deviceId(XkbUseCoreKbd)
{

  XkbIgnoreExtension(False);

  char* displayName = strdup("");
  int eventCode;
  int errorReturn;
  int major = XkbMajorVersion;
  int minor = XkbMinorVersion;
  int reasonReturn;
  _display = XkbOpenDisplay(displayName, &eventCode, &errorReturn, &major,
      &minor, &reasonReturn);
  switch (reasonReturn) {
    case XkbOD_BadLibraryVersion:
      throw X11Exception("Bad XKB library version.");
      break;
    case XkbOD_ConnectionRefused:
      throw X11Exception("Connection to X server refused.");
      break;
    case XkbOD_BadServerVersion:
      throw X11Exception("Bad X11 server version.");
      break;
    case XkbOD_NonXkbServer:
      throw X11Exception("XKB not present.");
      break;
    case XkbOD_Success:
      break;
  }

  _kbdDescPtr = XkbAllocKeyboard();
  if (_kbdDescPtr == NULL) {
    XCloseDisplay(_display);
    throw X11Exception("Failed to get keyboard description.");
  }

  _kbdDescPtr->dpy = _display;
  if (_deviceId != XkbUseCoreKbd) {
    _kbdDescPtr->device_spec = _deviceId;
  }
}
示例#10
0
void set_repeatrate(int delay, double rate)
{
#if HAVE_XKB
  Display* dpy = qt_xdisplay();
  int xkbmajor = XkbMajorVersion, xkbminor = XkbMinorVersion;
  int xkbopcode, xkbevent, xkberror;

  if (XkbQueryExtension(dpy, &xkbopcode, &xkbevent, &xkberror, &xkbmajor,
				&xkbminor)) {
     XkbDescPtr xkb = XkbAllocKeyboard();
     if (xkb) {
        int res = XkbGetControls(dpy, XkbRepeatKeysMask, xkb);
        xkb->ctrls->repeat_delay = delay;
        xkb->ctrls->repeat_interval = (int)floor(1000/rate + 0.5);
        res = XkbSetControls(dpy, XkbRepeatKeysMask, xkb);
        return;
     }
  }
#endif
  // Fallback: use the xset utility.

  // Unfortunately xset does only support int parameters, so
  // really slow repeat rates cannot be supported this way.
  // (the FSG Accessibility standard requires support for repeat rates
  // of several seconds per character)
  int r;
  if (rate < 1)
     r = 1;
  else
     r = (int)floor(rate + 0.5);

  QString exe = KGlobal::dirs()->findExe("xset");
  if (exe.isEmpty())
    return;

  KProcess p;
  p << exe << "r" << "rate" << QString::number(delay) << QString::number(r);
  
  p.start(KProcess::Block);
}
示例#11
0
文件: skb.c 项目: polachok/skb
int
main(int argc, char *argv[]){
    Display *dpy;
    XkbDescPtr kb;
    int ngroups = 0;
    char **groups;
    int active = 0;
    int old = -1;
    int i;

    if(!(dpy = XOpenDisplay(0)))
	eprint("skb: cannot open display\n");

    if (!(kb = XkbAllocKeyboard()))
	eprint("skb: XkbAllocKeyboard()\n");

    ngroups = get_gr_num(dpy, kb);

    groups = malloc(sizeof(char*)*ngroups);
    for (i = 0; i < ngroups; i++)
	    groups[i] = malloc(MAXGROUPLENGTH); 
    
    get_gr_names(dpy, kb, ngroups, groups);
    enable_gr_events(dpy);
    for(;;) {
        active = get_active_gr(dpy);
        if(active != old) {
            puts(groups[active]);
	    fflush(stdout);
            old = active;
        }
	if(argc > 1)
	    break;
	wait_gr_event(dpy);
    };
    return 0;
}
示例#12
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;
}
static void
xfce_accessibility_helper_set_xkb (XfceAccessibilityHelper *helper,
                                   gulong                   mask)
{

    XkbDescPtr xkb;
    gint       delay, interval, time_to_max;
    gint       max_speed, curve;

    gdk_error_trap_push ();

    /* allocate */
    xkb = XkbAllocKeyboard ();
    if (G_LIKELY (xkb))
    {
        /* we always change this, so add it to the mask */
        SET_FLAG (mask, XkbControlsEnabledMask);

        /* if setting sticky keys, we set expiration too */
        if (HAS_FLAG (mask, XkbStickyKeysMask) ||
                HAS_FLAG (mask, XkbSlowKeysMask) ||
                HAS_FLAG (mask, XkbBounceKeysMask) ||
                HAS_FLAG (mask, XkbMouseKeysMask) ||
                HAS_FLAG (mask, XkbAccessXKeysMask))
          SET_FLAG (mask, XkbAccessXTimeoutMask);

        /* add the mouse keys values mask if needed */
        if (HAS_FLAG (mask, XkbMouseKeysMask))
            SET_FLAG (mask, XkbMouseKeysAccelMask);

        /* load the xkb controls into the structure */
        XkbGetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), mask, xkb);

        /* AccessXKeys */
        if (HAS_FLAG (mask, XkbAccessXKeysMask))
        {
            if (xfconf_channel_get_bool (helper->channel, "/AccessXKeys", FALSE))
            {
                SET_FLAG (xkb->ctrls->enabled_ctrls, XkbAccessXKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbAccessXKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbAccessXKeysMask);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "AccessXKeys enabled");
            }
            else
            {
                UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbAccessXKeysMask);
                SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbAccessXKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbAccessXKeysMask);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "AccessXKeys disabled");
            }
        }

        /* Sticky keys */
        if (HAS_FLAG (mask, XkbStickyKeysMask))
        {
            if (xfconf_channel_get_bool (helper->channel, "/StickyKeys", FALSE))
            {
                SET_FLAG (xkb->ctrls->enabled_ctrls, XkbStickyKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbStickyKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbStickyKeysMask);

                if (xfconf_channel_get_bool (helper->channel, "/StickyKeys/LatchToLock", FALSE))
                    SET_FLAG (xkb->ctrls->ax_options, XkbAX_LatchToLockMask);
                else
                    UNSET_FLAG (xkb->ctrls->ax_options, XkbAX_LatchToLockMask);

                if (xfconf_channel_get_bool (helper->channel, "/StickyKeys/TwoKeysDisable", FALSE))
                    SET_FLAG (xkb->ctrls->ax_options, XkbAX_TwoKeysMask);
                else
                    UNSET_FLAG (xkb->ctrls->ax_options, XkbAX_TwoKeysMask);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "stickykeys enabled (ax_options=%d)",
                                xkb->ctrls->ax_options);
            }
            else
            {
                UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbStickyKeysMask);
                SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbStickyKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbStickyKeysMask);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "stickykeys disabled");
            }
        }

        /* Slow keys */
        if (HAS_FLAG (mask, XkbSlowKeysMask))
        {
            if (xfconf_channel_get_bool (helper->channel, "/SlowKeys", FALSE))
            {
                SET_FLAG (xkb->ctrls->enabled_ctrls, XkbSlowKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbSlowKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbSlowKeysMask);

                delay = xfconf_channel_get_int (helper->channel, "/SlowKeys/Delay", 100);
                xkb->ctrls->slow_keys_delay = CLAMP (delay, 1, G_MAXUSHORT);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "slowkeys enabled (delay=%d)",
                                xkb->ctrls->slow_keys_delay);
            }
            else
            {
                UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbSlowKeysMask);
                SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbSlowKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbSlowKeysMask);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "slowkeys disabled");
            }
        }

        /* Bounce keys */
        if (HAS_FLAG (mask, XkbBounceKeysMask))
        {
            if (xfconf_channel_get_bool (helper->channel, "/BounceKeys", FALSE))
            {
                SET_FLAG (xkb->ctrls->enabled_ctrls, XkbBounceKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbBounceKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbBounceKeysMask);

                delay = xfconf_channel_get_int (helper->channel, "/BounceKeys/Delay", 100);
                xkb->ctrls->debounce_delay = CLAMP (delay, 1, G_MAXUSHORT);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "bouncekeys enabled (delay=%d)",
                                xkb->ctrls->debounce_delay);
            }
            else
            {
                UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbBounceKeysMask);
                SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbBounceKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbBounceKeysMask);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "bouncekeys disabled");
            }
        }

        /* Mouse keys */
        if (HAS_FLAG (mask, XkbMouseKeysMask))
        {
            if (xfconf_channel_get_bool (helper->channel, "/MouseKeys", FALSE))
            {
                SET_FLAG (xkb->ctrls->enabled_ctrls, XkbMouseKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbMouseKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbMouseKeysMask);

                /* get values */
                delay = xfconf_channel_get_int (helper->channel, "/MouseKeys/Delay", 160);
                interval = xfconf_channel_get_int (helper->channel, "/MouseKeys/Interval", 20);
                time_to_max = xfconf_channel_get_int (helper->channel, "/MouseKeys/TimeToMax", 3000);
                max_speed = xfconf_channel_get_int (helper->channel, "/MouseKeys/MaxSpeed", 1000);
                curve = xfconf_channel_get_int (helper->channel, "/MouseKeys/Curve", 0);

                /* calculate maximum speed and to to reach it */
                interval = CLAMP (interval, 1, G_MAXUSHORT);
                max_speed = (max_speed * interval) / 1000;
                time_to_max = (time_to_max + interval / 2) / interval;

                /* set new values, clamp to limits */
                xkb->ctrls->mk_delay = CLAMP (delay, 1, G_MAXUSHORT);
                xkb->ctrls->mk_interval = interval;
                xkb->ctrls->mk_time_to_max = CLAMP (time_to_max, 1, G_MAXUSHORT);
                xkb->ctrls->mk_max_speed = CLAMP (max_speed, 1, G_MAXUSHORT);
                xkb->ctrls->mk_curve = CLAMP (curve, -1000, 1000);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "mousekeys enabled (delay=%d, interval=%d, "
                                "time_to_max=%d, max_speed=%d, curve=%d)",
                                xkb->ctrls->mk_delay, xkb->ctrls->mk_interval,
                                xkb->ctrls->mk_time_to_max, xkb->ctrls->mk_max_speed,
                                xkb->ctrls->mk_curve);
            }
            else
            {
                UNSET_FLAG (xkb->ctrls->enabled_ctrls, XkbMouseKeysMask);
                SET_FLAG (xkb->ctrls->axt_ctrls_mask, XkbMouseKeysMask);
                UNSET_FLAG (xkb->ctrls->axt_ctrls_values, XkbMouseKeysMask);
                UNSET_FLAG (mask, XkbMouseKeysAccelMask);

                xfsettings_dbg (XFSD_DEBUG_ACCESSIBILITY, "mousekeys disabled");
            }
        }

        /* set the modified controls */
        if (!XkbSetControls (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), mask, xkb))
            g_message ("Setting the xkb controls failed");

        /* free the structure */
        XkbFreeControls (xkb, mask, True);
        XFree (xkb);
    }
    else
    {
        /* warning */
        g_critical ("XkbAllocKeyboard() returned a null pointer");
    }

    if (gdk_error_trap_pop () != 0)
       g_critical ("Failed to set keyboard controls");
}
示例#14
0
文件: xkbInit.c 项目: narenas/nx-libs
void
XkbInitDevice(DeviceIntPtr pXDev)
{
int			i;
XkbSrvInfoPtr		xkbi;
XkbChangesRec		changes;
SrvXkmInfo		file;
unsigned		check;
XkbEventCauseRec	cause;

    file.dev= pXDev;
    file.file=NULL;
    bzero(&file.xkbinfo,sizeof(XkbFileInfo));
    bzero(&changes,sizeof(XkbChangesRec));
    if (XkbAutoLoad && (XkbInitialMap!=NULL)) {
	if ((file.file=XkbDDXOpenConfigFile(XkbInitialMap,NULL,0))!=NULL) {
	    XkmReadFile(file.file,0,XkmKeymapLegal,&file.xkbinfo);
	    if (file.xkbinfo.xkb==NULL) {
		LogMessage(X_ERROR,
				"Error loading keymap file %s (%s in %s)\n"
				"\treverting to defaults\n",
				XkbInitialMap, _XkbErrMessages[_XkbErrCode],
				(_XkbErrLocation?_XkbErrLocation:"unknown"));
		fclose(file.file);
		file.file= NULL;
		bzero(&file.xkbinfo,sizeof(XkbFileInfo));
	    }
	    else {
		if (_XkbInitFileInfo!=NULL) {
		    XkbDescPtr	tmp;
		    if ((tmp=_XkbInitFileInfo->xkb)!=NULL) {
			XkbFreeKeyboard(tmp,XkbAllComponentsMask,True);
			_XkbInitFileInfo->xkb= NULL;
		    }
		}
		_XkbInitFileInfo= &file.xkbinfo;
	    }
	}
	else {
	    LogMessage(X_ERROR, "Error opening keymap file %s, reverting to defaults\n",
	    	    XkbInitialMap);
	}
    }
    pXDev->key->xkbInfo= xkbi= _XkbTypedCalloc(1,XkbSrvInfoRec);
    if ( xkbi ) {
	XkbDescPtr	xkb;
	if ((_XkbInitFileInfo!=NULL)&&(_XkbInitFileInfo->xkb!=NULL)) {
	    file.xkbinfo= *_XkbInitFileInfo;
	    xkbi->desc= _XkbInitFileInfo->xkb;
	    _XkbInitFileInfo= NULL;
	}
	else {
	    xkbi->desc= XkbAllocKeyboard();
	    if (!xkbi->desc)
		FatalError("Couldn't allocate keyboard description\n");
	    xkbi->desc->min_key_code = pXDev->key->curKeySyms.minKeyCode;
	    xkbi->desc->max_key_code = pXDev->key->curKeySyms.maxKeyCode;
	}
	xkb= xkbi->desc;
	if (xkb->min_key_code == 0)
	    xkb->min_key_code = pXDev->key->curKeySyms.minKeyCode;
	if (xkb->max_key_code == 0)
	    xkb->max_key_code = pXDev->key->curKeySyms.maxKeyCode;
	if ((pXDev->key->curKeySyms.minKeyCode!=xkbi->desc->min_key_code)||
	    (pXDev->key->curKeySyms.maxKeyCode!=xkbi->desc->max_key_code)) {
	    /* 12/9/95 (ef) -- XXX! Maybe we should try to fix up one or */
	    /*                 the other here, but for now just complain */
	    /*                 can't just update the core range without */
	    /*                 reallocating the KeySymsRec (pain)       */
	    ErrorF("Internal Error!! XKB and core keymap have different range\n");
	}
	if (XkbAllocClientMap(xkb,XkbAllClientInfoMask,0)!=Success)
	    FatalError("Couldn't allocate client map in XkbInitDevice\n");
	i= XkbNumKeys(xkb)/3+1;
	if (XkbAllocServerMap(xkb,XkbAllServerInfoMask,i)!=Success)
	    FatalError("Couldn't allocate server map in XkbInitDevice\n");

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

	file.xkbinfo.xkb= xkb;
	XkbInitSemantics(xkb,&file);
	XkbInitNames(xkbi,&file);
	XkbInitRadioGroups(xkbi,&file);

	/* 12/31/94 (ef) -- XXX! Should check if state loaded from file */
	bzero(&xkbi->state,sizeof(XkbStateRec));

	XkbInitControls(pXDev,xkbi,&file);

	if (file.xkbinfo.defined&XkmSymbolsMask)
	   memcpy(pXDev->key->modifierMap,xkb->map->modmap,xkb->max_key_code+1);
	else
	   memcpy(xkb->map->modmap,pXDev->key->modifierMap,xkb->max_key_code+1);

	XkbInitIndicatorMap(xkbi,&file);

	XkbDDXInitDevice(pXDev);

	if (!(file.xkbinfo.defined&XkmSymbolsMask)) {
	    XkbUpdateKeyTypesFromCore(pXDev,xkb->min_key_code,XkbNumKeys(xkb),
								&changes);
	}
	else {
	    XkbUpdateCoreDescription(pXDev,True);
	}
	XkbSetCauseUnknown(&cause);
	XkbUpdateActions(pXDev,xkb->min_key_code, XkbNumKeys(xkb),&changes,
								&check,&cause);
        /* For sanity.  The first time the connection
         * is opened, the client side min and max are set
         * using QueryMinMaxKeyCodes() which grabs them 
	 * from pXDev.
	 */
	pXDev->key->curKeySyms.minKeyCode = xkb->min_key_code;
	pXDev->key->curKeySyms.maxKeyCode = xkb->max_key_code;
    }
    if (file.file!=NULL)
	fclose(file.file);
    return;
}