Esempio n. 1
0
Boolean XkbEventHandler(XEvent *event)
{
    XkbEvent 		*xkbEv = (XkbEvent *) event;
    
    if (xkbEv->any.xkb_type==XkbIndicatorStateNotify)  {
	register int 		i;
	register unsigned	bit;
	for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1)
	    if ((xkbEv->indicators.changed&bit)&&(leds[i])) 
	    {
		if (xkbEv->indicators.state&bit)
		    XmToggleButtonSetState(leds[i],True,False);
		else
		    XmToggleButtonSetState(leds[i],False,False);
	    }
    }
    else if (xkbEv->any.xkb_type==XkbIndicatorMapNotify) {
	    unsigned change= xkbEv->indicators.changed;

	    if (XkbGetIndicatorMap(theDisplay,change,xkb_desc)!=Success) 
		fprintf(stderr,"Couldn't get changed indicator maps\n");
    }
      
    return True;
    
} /* XkbEventHandler */
Esempio n. 2
0
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;
}
Esempio n. 3
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)
Esempio n. 4
0
File: xkbvleds.c Progetto: aosm/X11
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);