diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-01-12 18:53:47 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2013-01-12 18:53:47 -0800 |
commit | fdbff6587f29048c85772f21d3647797f96d527f (patch) | |
tree | 72d879ba629fc6fc379db86b3a7b302b7109c1d6 | |
parent | e3092ad9d9742630aa34044c7a37802ccfc6ee61 (diff) |
Convert to X.Org standard coding style
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | LED.c | 320 | ||||
-rw-r--r-- | LED.h | 5 | ||||
-rw-r--r-- | LEDP.h | 38 | ||||
-rw-r--r-- | utils.c | 250 | ||||
-rw-r--r-- | utils.h | 131 | ||||
-rw-r--r-- | xkbbell.c | 343 | ||||
-rw-r--r-- | xkbvleds.c | 501 | ||||
-rw-r--r-- | xkbwatch.c | 354 |
8 files changed, 1020 insertions, 922 deletions
@@ -53,139 +53,148 @@ #define offset(field) XtOffsetOf(LEDRec, field) static XtResource resources[] = { {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), - offset(led.foreground), XtRString, XtDefaultForeground}, + offset(led.foreground), XtRString, XtDefaultForeground}, {XtNon, XtCOn, XtRBoolean, sizeof(Boolean), - offset(led.on), XtRImmediate, (XtPointer)False}, + offset(led.on), XtRImmediate, (XtPointer) False}, {XtNtopColor, XtCTopColor, XtRPixel, sizeof(Pixel), - offset(led.top_color), XtRString, "black"}, + offset(led.top_color), XtRString, "black"}, {XtNbottomColor, XtCBottomColor, XtRPixel, sizeof(Pixel), - offset(led.bottom_color), XtRString, "white"}, + offset(led.bottom_color), XtRString, "white"}, {XtNonColor, XtCOnColor, XtRPixel, sizeof(Pixel), - offset(led.on_color), XtRString, "green"}, + offset(led.on_color), XtRString, "green"}, {XtNoffColor, XtCOffColor, XtRPixel, sizeof(Pixel), - offset(led.off_color), XtRString, "#005000"}, + offset(led.off_color), XtRString, "#005000"}, {XtNbevel, XtCBevel, XtRDimension, sizeof(Dimension), - offset(led.bevel), XtRImmediate, (XtPointer)1}, + offset(led.bevel), XtRImmediate, (XtPointer) 1}, {XtNledWidth, XtCLedWidth, XtRDimension, sizeof(Dimension), - offset(led.led_width), XtRImmediate, (XtPointer)6}, + offset(led.led_width), XtRImmediate, (XtPointer) 6}, {XtNledHeight, XtCLedHeight, XtRDimension, sizeof(Dimension), - offset(led.led_height), XtRImmediate, (XtPointer)12} + offset(led.led_height), XtRImmediate, (XtPointer) 12} }; #undef offset -static void ClassInitialize ( void ); -static void Initialize ( Widget request, Widget new, ArgList args, - Cardinal *num_args ); -static void Realize ( Widget w, Mask * mask, XSetWindowAttributes * xswa ); -static void Resize ( Widget w ); -static Boolean SetValues ( Widget current, Widget request, Widget new, - ArgList args, Cardinal *num_args ); -static void Destroy ( Widget w ); -static XtGeometryResult QueryGeometry ( Widget w, XtWidgetGeometry *intended, - XtWidgetGeometry *preferred ); +static void ClassInitialize(void); +static void Initialize(Widget request, Widget new, ArgList args, + Cardinal *num_args); +static void Realize(Widget w, Mask *mask, XSetWindowAttributes *xswa); +static void Resize(Widget w); +static Boolean SetValues(Widget current, Widget request, Widget new, + ArgList args, Cardinal *num_args); +static void Destroy(Widget w); +static XtGeometryResult QueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *preferred); LEDClassRec ledClassRec = { - { -/* core_class fields */ - /* superclass */ (WidgetClass) &simpleClassRec, - /* class_name */ "LED", - /* widget_size */ sizeof(LEDRec), - /* class_initialize */ ClassInitialize, - /* class_part_initialize */ NULL, - /* class_inited */ FALSE, - /* initialize */ Initialize, - /* initialize_hook */ NULL, - /* realize */ Realize, - /* actions */ NULL, - /* num_actions */ 0, - /* resources */ resources, - /* num_resources */ XtNumber(resources), - /* xrm_class */ NULLQUARK, - /* compress_motion */ TRUE, - /* compress_exposure */ TRUE, - /* compress_enterleave */ TRUE, - /* visible_interest */ FALSE, - /* destroy */ Destroy, - /* resize */ Resize, - /* expose */ XtInheritExpose, - /* set_values */ SetValues, - /* set_values_hook */ NULL, - /* set_values_almost */ XtInheritSetValuesAlmost, - /* get_values_hook */ NULL, - /* accept_focus */ NULL, - /* version */ XtVersion, - /* callback_private */ NULL, - /* tm_table */ NULL, - /* query_geometry */ QueryGeometry, - /* display_accelerator */ XtInheritDisplayAccelerator, - /* extension */ NULL - }, + { +/* core_class fields */ + /* superclass */ (WidgetClass) & simpleClassRec, + /* class_name */ "LED", + /* widget_size */ sizeof(LEDRec), + /* class_initialize */ ClassInitialize, + /* class_part_initialize */ NULL, + /* class_inited */ FALSE, + /* initialize */ Initialize, + /* initialize_hook */ NULL, + /* realize */ Realize, + /* actions */ NULL, + /* num_actions */ 0, + /* resources */ resources, + /* num_resources */ XtNumber(resources), + /* xrm_class */ NULLQUARK, + /* compress_motion */ TRUE, + /* compress_exposure */ TRUE, + /* compress_enterleave */ TRUE, + /* visible_interest */ FALSE, + /* destroy */ Destroy, + /* resize */ Resize, + /* expose */ XtInheritExpose, + /* set_values */ SetValues, + /* set_values_hook */ NULL, + /* set_values_almost */ XtInheritSetValuesAlmost, + /* get_values_hook */ NULL, + /* accept_focus */ NULL, + /* version */ XtVersion, + /* callback_private */ NULL, + /* tm_table */ NULL, + /* query_geometry */ QueryGeometry, + /* display_accelerator */ XtInheritDisplayAccelerator, + /* extension */ NULL + }, /* Simple class fields initialization */ - { - /* change_sensitive */ XtInheritChangeSensitive - }, + { + /* change_sensitive */ XtInheritChangeSensitive + }, /* LED class fields initialization */ - { - /* ignore */ 0 - } + { + /* ignore */ 0 + } }; -WidgetClass ledWidgetClass = (WidgetClass)&ledClassRec; +WidgetClass ledWidgetClass = (WidgetClass) &ledClassRec; + /**************************************************************** * * Private Procedures * ****************************************************************/ -static void +static void ClassInitialize(void) { XawInitializeWidgetSet(); } -static void +static void GetPixmaps(LEDWidget lw) { - XGCValues values; - GC gc; - Display * dpy; - Window root; - Pixmap pix,on_pixmap,off_pixmap; - Dimension bevel,width,height; + XGCValues values; + GC gc; + Display *dpy; + Window root; + Pixmap pix, on_pixmap, off_pixmap; + Dimension bevel, width, height; - dpy= XtDisplay((Widget)lw); - root= RootWindowOfScreen(XtScreen((Widget)lw)); - if (lw->led.on_pixmap!=None) { - XFreePixmap(dpy,lw->led.on_pixmap); - lw->led.on_pixmap= None; + dpy = XtDisplay((Widget) lw); + root = RootWindowOfScreen(XtScreen((Widget) lw)); + if (lw->led.on_pixmap != None) { + XFreePixmap(dpy, lw->led.on_pixmap); + lw->led.on_pixmap = None; } - if (lw->led.off_pixmap!=None) { - XFreePixmap(dpy,lw->led.off_pixmap); - lw->led.off_pixmap= None; + if (lw->led.off_pixmap != None) { + XFreePixmap(dpy, lw->led.off_pixmap); + lw->led.off_pixmap = None; } - lw->led.on_pixmap= on_pixmap= XCreatePixmap(dpy,root, - lw->core.width,lw->core.height,lw->core.depth); - lw->led.off_pixmap= off_pixmap= XCreatePixmap(dpy,root, - lw->core.width,lw->core.height,lw->core.depth); + lw->led.on_pixmap = on_pixmap = + XCreatePixmap(dpy, root, lw->core.width, lw->core.height, + lw->core.depth); + lw->led.off_pixmap = off_pixmap = + XCreatePixmap(dpy, root, lw->core.width, lw->core.height, + lw->core.depth); - values.foreground = lw->led.top_color; - gc= XCreateGC(dpy,lw->led.on_pixmap,(unsigned)GCForeground,&values); - bevel= lw->led.bevel; - width= lw->core.width; - height= lw->core.height; - XFillRectangle(dpy,on_pixmap,gc,0,0,width,height); - XFillRectangle(dpy,off_pixmap,gc,0,0,width,height); - XSetForeground(dpy,gc,lw->led.bottom_color); - XFillRectangle(dpy,on_pixmap,gc,bevel,bevel,width-bevel,height-bevel); - XFillRectangle(dpy,off_pixmap,gc,bevel,bevel,width-bevel,height-bevel); - XSetForeground(dpy,gc,lw->led.on_color); - XFillRectangle(dpy,on_pixmap,gc,bevel,bevel,width-2*bevel,height-2*bevel); - XSetForeground(dpy,gc,lw->led.off_color); - XFillRectangle(dpy,off_pixmap,gc,bevel,bevel,width-2*bevel,height-2*bevel); - XFreeGC(dpy,gc); - if (lw->led.on) pix= on_pixmap; - else pix= off_pixmap; - if (XtWindow((Widget)lw)!=None) - XSetWindowBackgroundPixmap(dpy,XtWindow((Widget)lw),pix); + values.foreground = lw->led.top_color; + gc = XCreateGC(dpy, lw->led.on_pixmap, (unsigned) GCForeground, &values); + bevel = lw->led.bevel; + width = lw->core.width; + height = lw->core.height; + XFillRectangle(dpy, on_pixmap, gc, 0, 0, width, height); + XFillRectangle(dpy, off_pixmap, gc, 0, 0, width, height); + XSetForeground(dpy, gc, lw->led.bottom_color); + XFillRectangle(dpy, on_pixmap, gc, bevel, bevel, width - bevel, + height - bevel); + XFillRectangle(dpy, off_pixmap, gc, bevel, bevel, width - bevel, + height - bevel); + XSetForeground(dpy, gc, lw->led.on_color); + XFillRectangle(dpy, on_pixmap, gc, bevel, bevel, width - 2 * bevel, + height - 2 * bevel); + XSetForeground(dpy, gc, lw->led.off_color); + XFillRectangle(dpy, off_pixmap, gc, bevel, bevel, width - 2 * bevel, + height - 2 * bevel); + XFreeGC(dpy, gc); + if (lw->led.on) + pix = on_pixmap; + else + pix = off_pixmap; + if (XtWindow((Widget) lw) != None) + XSetWindowBackgroundPixmap(dpy, XtWindow((Widget) lw), pix); return; } @@ -199,32 +208,34 @@ Initialize(Widget request, Widget new, ArgList args, Cardinal *num_args) lw->core.height = lw->led.led_height; if (lw->core.width == 0) lw->core.width = lw->led.led_width; - lw->core.border_width= 0; - if (lw->led.bevel==0) - lw->led.bevel= 1; - lw->led.on_pixmap= lw->led.off_pixmap= None; - (*XtClass(new)->core_class.resize) ((Widget)lw); + lw->core.border_width = 0; + if (lw->led.bevel == 0) + lw->led.bevel = 1; + lw->led.on_pixmap = lw->led.off_pixmap = None; + (*XtClass(new)->core_class.resize) ((Widget) lw); GetPixmaps(lw); -} /* Initialize */ +} /* Initialize */ static void Realize(Widget w, Mask *mask, XSetWindowAttributes *xswa) { - LEDWidget lw = (LEDWidget)w; + LEDWidget lw = (LEDWidget) w; WidgetClass super = simpleWidgetClass; - Pixmap pix; + Pixmap pix; - (*super->core_class.realize)(w,mask,xswa); - if (lw->led.on) pix= lw->led.on_pixmap; - else pix= lw->led.off_pixmap; - XSetWindowBackgroundPixmap(XtDisplay(w),XtWindow(w),pix); + (*super->core_class.realize) (w, mask, xswa); + if (lw->led.on) + pix = lw->led.on_pixmap; + else + pix = lw->led.off_pixmap; + XSetWindowBackgroundPixmap(XtDisplay(w), XtWindow(w), pix); return; } -static void +static void Resize(Widget w) { - GetPixmaps((LEDWidget)w); + GetPixmaps((LEDWidget) w); return; } @@ -232,71 +243,72 @@ Resize(Widget w) * Set specified arguments into widget */ -static Boolean -SetValues(Widget current, Widget request, Widget new, - ArgList args, Cardinal *num_args) +static Boolean +SetValues(Widget current, Widget request, Widget new, + ArgList args, Cardinal *num_args) { LEDWidget curlw = (LEDWidget) current; LEDWidget newlw = (LEDWidget) new; Boolean changed; - changed= FALSE; - if (curlw->led.foreground != newlw->led.foreground - || curlw->core.background_pixel != newlw->core.background_pixel - || curlw->led.on_color != newlw->led.on_color - || curlw->led.off_color != newlw->led.off_color - || curlw->core.width != newlw->core.width - || curlw->core.height != newlw->core.height) { - GetPixmaps(newlw); - changed= TRUE; + changed = FALSE; + if (curlw->led.foreground != newlw->led.foreground + || curlw->core.background_pixel != newlw->core.background_pixel + || curlw->led.on_color != newlw->led.on_color + || curlw->led.off_color != newlw->led.off_color + || curlw->core.width != newlw->core.width + || curlw->core.height != newlw->core.height) { + GetPixmaps(newlw); + changed = TRUE; } - if (curlw->led.on!=newlw->led.on) { - Pixmap pix; + if (curlw->led.on != newlw->led.on) { + Pixmap pix; - if (newlw->led.on) pix= newlw->led.on_pixmap; - else pix= newlw->led.off_pixmap; + if (newlw->led.on) + pix = newlw->led.on_pixmap; + else + pix = newlw->led.off_pixmap; - if (XtWindow(newlw)!=None) - XSetWindowBackgroundPixmap(XtDisplay(newlw),XtWindow(newlw),pix); - changed= TRUE; + if (XtWindow(newlw) != None) + XSetWindowBackgroundPixmap(XtDisplay(newlw), XtWindow(newlw), pix); + changed = TRUE; } return changed; } -static void +static void Destroy(Widget w) { - LEDWidget lw = (LEDWidget)w; + LEDWidget lw = (LEDWidget) w; - if (lw->led.on_pixmap!=None) { - XFreePixmap(XtDisplay(w),lw->led.on_pixmap); - lw->led.on_pixmap= None; + if (lw->led.on_pixmap != None) { + XFreePixmap(XtDisplay(w), lw->led.on_pixmap); + lw->led.on_pixmap = None; } - if (lw->led.off_pixmap!=None) { - XFreePixmap(XtDisplay(w),lw->led.off_pixmap); - lw->led.off_pixmap= None; + if (lw->led.off_pixmap != None) { + XFreePixmap(XtDisplay(w), lw->led.off_pixmap); + lw->led.off_pixmap = None; } return; } - -static XtGeometryResult -QueryGeometry(Widget w, XtWidgetGeometry *intended, - XtWidgetGeometry *preferred) +static XtGeometryResult +QueryGeometry(Widget w, XtWidgetGeometry *intended, + XtWidgetGeometry *preferred) { - LEDWidget lw = (LEDWidget)w; + LEDWidget lw = (LEDWidget) w; preferred->request_mode = CWWidth | CWHeight; preferred->width = lw->led.led_height; preferred->height = lw->led.led_width; - if ( ((intended->request_mode & (CWWidth | CWHeight)) - == (CWWidth | CWHeight)) && - intended->width == preferred->width && - intended->height == preferred->height) - return XtGeometryYes; + if (((intended->request_mode & (CWWidth | CWHeight)) + == (CWWidth | CWHeight)) && + intended->width == preferred->width && + intended->height == preferred->height) + return XtGeometryYes; else if (preferred->width == w->core.width && - preferred->height == w->core.height) - return XtGeometryNo; + preferred->height == w->core.height) + return XtGeometryNo; else - return XtGeometryAlmost; + return XtGeometryAlmost; } @@ -92,6 +92,7 @@ extern WidgetClass ledWidgetClass; typedef struct _LEDClassRec *LEDWidgetClass; -typedef struct _LEDRec *LEDWidget; -#endif /* _XawLED_h */ +typedef struct _LEDRec *LEDWidget; + +#endif /* _XawLED_h */ @@ -32,13 +32,15 @@ /* New fields for the Label widget class record */ -typedef struct {int foo;} LEDClassPart; +typedef struct { + int foo; +} LEDClassPart; /* Full class record declaration */ typedef struct _LEDClassRec { - CoreClassPart core_class; - SimpleClassPart simple_class; - LEDClassPart led_class; + CoreClassPart core_class; + SimpleClassPart simple_class; + LEDClassPart led_class; } LEDClassRec; extern LEDClassRec ledClassRec; @@ -46,18 +48,18 @@ extern LEDClassRec ledClassRec; /* New fields for the LED widget record */ typedef struct { /* resources */ - Pixel foreground; - Pixel on_color; - Pixel off_color; - Pixel top_color; - Pixel bottom_color; - Dimension bevel; - Dimension led_width; - Dimension led_height; - Boolean on; + Pixel foreground; + Pixel on_color; + Pixel off_color; + Pixel top_color; + Pixel bottom_color; + Dimension bevel; + Dimension led_width; + Dimension led_height; + Boolean on; /* private state */ - Pixmap on_pixmap; + Pixmap on_pixmap; Pixmap off_pixmap; } LEDPart; @@ -68,9 +70,9 @@ typedef struct { ****************************************************************/ typedef struct _LEDRec { - CorePart core; - SimplePart simple; - LEDPart led; + CorePart core; + SimplePart simple; + LEDPart led; } LEDRec; -#endif /* _XawLEDP_h */ +#endif /* _XawLEDP_h */ @@ -2,10 +2,10 @@ /*\ * $Xorg: utils.c,v 1.6 2000/08/17 19:54:51 cpqbld Exp $ * - * COPYRIGHT 1990 - * DIGITAL EQUIPMENT CORPORATION - * MAYNARD, MASSACHUSETTS - * ALL RIGHTS RESERVED. + * COPYRIGHT 1990 + * DIGITAL EQUIPMENT CORPORATION + * MAYNARD, MASSACHUSETTS + * ALL RIGHTS RESERVED. * * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. @@ -38,7 +38,7 @@ unsigned int debugFlags; Opaque uAlloc(unsigned size) { - return((Opaque)malloc(size)); + return ((Opaque) malloc(size)); } /***====================================================================***/ @@ -46,7 +46,7 @@ uAlloc(unsigned size) Opaque uCalloc(unsigned n, unsigned size) { - return((Opaque)calloc(n,size)); + return ((Opaque) calloc(n, size)); } /***====================================================================***/ @@ -54,9 +54,10 @@ uCalloc(unsigned n, unsigned size) Opaque uRealloc(Opaque old, unsigned newSize) { - if (old==NULL) - return((Opaque)malloc(newSize)); - else return((Opaque)realloc((char *)old,newSize)); + if (old == NULL) + return ((Opaque) malloc(newSize)); + else + return ((Opaque) realloc((char *) old, newSize)); } /***====================================================================***/ @@ -64,17 +65,17 @@ uRealloc(Opaque old, unsigned newSize) Opaque uRecalloc(Opaque old, unsigned nOld, unsigned nNew, unsigned itemSize) { -char *rtrn; + char *rtrn; - if (old==NULL) - rtrn= (char *)calloc(nNew,itemSize); + if (old == NULL) + rtrn = (char *) calloc(nNew, itemSize); else { - rtrn= (char *)realloc((char *)old,nNew*itemSize); - if ((rtrn)&&(nNew>nOld)) { - bzero(&rtrn[nOld*itemSize],(nNew-nOld)*itemSize); - } + rtrn = (char *) realloc((char *) old, nNew * itemSize); + if ((rtrn) && (nNew > nOld)) { + bzero(&rtrn[nOld * itemSize], (nNew - nOld) * itemSize); + } } - return (Opaque)rtrn; + return (Opaque) rtrn; } /***====================================================================***/ @@ -82,8 +83,8 @@ char *rtrn; void uFree(Opaque ptr) { - if (ptr!=(Opaque)NULL) - free((char *)ptr); + if (ptr != (Opaque) NULL) + free((char *) ptr); return; } @@ -91,37 +92,40 @@ uFree(Opaque ptr) /*** FUNCTION ENTRY TRACKING ***/ /***====================================================================***/ -static FILE *entryFile= NULL; - int uEntryLevel; +static FILE *entryFile = NULL; + +int uEntryLevel; Boolean uSetEntryFile(char *name) { - if ((entryFile!=NULL)&&(entryFile!=stderr)) { - fprintf(entryFile,"switching to %s\n",name?name:"stderr"); - fclose(entryFile); + if ((entryFile != NULL) && (entryFile != stderr)) { + fprintf(entryFile, "switching to %s\n", name ? name : "stderr"); + fclose(entryFile); } - if (name!=NullString) entryFile= fopen(name,"w"); - else entryFile= stderr; - if (entryFile==NULL) { - entryFile= stderr; - return(False); + if (name != NullString) + entryFile = fopen(name, "w"); + else + entryFile = stderr; + if (entryFile == NULL) { + entryFile = stderr; + return (False); } - return(True); + return (True); } void -uEntry(int l, char *s,...) +uEntry(int l, char *s, ...) { -int i; -va_list ap; + int i; + va_list ap; va_start(ap, s); - for (i=0;i<uEntryLevel;i++) { - putc(' ',entryFile); + for (i = 0; i < uEntryLevel; i++) { + putc(' ', entryFile); } - vfprintf(entryFile,s,ap); - uEntryLevel+= l; + vfprintf(entryFile, s, ap); + uEntryLevel += l; va_end(ap); return; } @@ -129,14 +133,15 @@ va_list ap; void uExit(int l, char *rtVal) { -int i; + int i; - uEntryLevel-= l; - if (uEntryLevel<0) uEntryLevel= 0; - for (i=0;i<uEntryLevel;i++) { - putc(' ',entryFile); + uEntryLevel -= l; + if (uEntryLevel < 0) + uEntryLevel = 0; + for (i = 0; i < uEntryLevel; i++) { + putc(' ', entryFile); } - fprintf(entryFile,"---> 0x%p\n",rtVal); + fprintf(entryFile, "---> 0x%p\n", rtVal); return; } @@ -144,49 +149,51 @@ int i; /*** PRINT FUNCTIONS ***/ /***====================================================================***/ - FILE *uDebugFile= NULL; - int uDebugIndentLevel= 0; - int uDebugIndentSize= 4; +FILE *uDebugFile = NULL; +int uDebugIndentLevel = 0; +int uDebugIndentSize = 4; Boolean uSetDebugFile(char *name) { - if ((uDebugFile!=NULL)&&(uDebugFile!=stderr)) { - fprintf(uDebugFile,"switching to %s\n",name?name:"stderr"); - fclose(uDebugFile); + if ((uDebugFile != NULL) && (uDebugFile != stderr)) { + fprintf(uDebugFile, "switching to %s\n", name ? name : "stderr"); + fclose(uDebugFile); } - if (name!=NullString) uDebugFile= fopen(name,"w"); - else uDebugFile= stderr; - if (uDebugFile==NULL) { - uDebugFile= stderr; - return(False); + if (name != NullString) + uDebugFile = fopen(name, "w"); + else + uDebugFile = stderr; + if (uDebugFile == NULL) { + uDebugFile = stderr; + return (False); } - return(True); + return (True); } void -uDebug(char *s,...) +uDebug(char *s, ...) { -int i; -va_list ap; + int i; + va_list ap; va_start(ap, s); - for (i=(uDebugIndentLevel*uDebugIndentSize);i>0;i--) { - putc(' ',uDebugFile); + for (i = (uDebugIndentLevel * uDebugIndentSize); i > 0; i--) { + putc(' ', uDebugFile); } - vfprintf(uDebugFile,s,ap); + vfprintf(uDebugFile, s, ap); fflush(uDebugFile); va_end(ap); return; } void -uDebugNOI(char *s,...) +uDebugNOI(char *s, ...) { -va_list ap; + va_list ap; va_start(ap, s); - vfprintf(uDebugFile,s,ap); + vfprintf(uDebugFile, s, ap); fflush(uDebugFile); va_end(ap); return; @@ -194,31 +201,33 @@ va_list ap; /***====================================================================***/ -static FILE *errorFile= NULL; +static FILE *errorFile = NULL; Boolean uSetErrorFile(char *name) { - if ((errorFile!=NULL)&&(errorFile!=stderr)) { - fprintf(errorFile,"switching to %s\n",name?name:"stderr"); - fclose(errorFile); + if ((errorFile != NULL) && (errorFile != stderr)) { + fprintf(errorFile, "switching to %s\n", name ? name : "stderr"); + fclose(errorFile); } - if (name!=NullString) errorFile= fopen(name,"w"); - else errorFile= stderr; - if (errorFile==NULL) { - errorFile= stderr; - return(False); + if (name != NullString) + errorFile = fopen(name, "w"); + else + errorFile = stderr; + if (errorFile == NULL) { + errorFile = stderr; + return (False); } - return(True); + return (True); } void -uInformation(char *s,...) +uInformation(char *s, ...) { va_list ap; va_start(ap, s); - vfprintf(errorFile,s,ap); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -227,13 +236,13 @@ uInformation(char *s,...) /***====================================================================***/ void -uAction(char *s,...) +uAction(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile," "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, " "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -242,13 +251,13 @@ uAction(char *s,...) /***====================================================================***/ void -uWarning(char *s,...) +uWarning(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Warning: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Warning: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -257,13 +266,13 @@ uWarning(char *s,...) /***====================================================================***/ void -uError(char *s,...) +uError(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Error: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Error: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -272,14 +281,14 @@ uError(char *s,...) /***====================================================================***/ void -uFatalError(char *s,...) +uFatalError(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Fatal Error: "); - vfprintf(errorFile,s,ap); - fprintf(errorFile," Exiting\n"); + fprintf(errorFile, "Fatal Error: "); + vfprintf(errorFile, s, ap); + fprintf(errorFile, " Exiting\n"); fflush(errorFile); va_end(ap); exit(1); @@ -289,13 +298,13 @@ uFatalError(char *s,...) /***====================================================================***/ void -uInternalError(char *s,...) +uInternalError(char *s, ...) { va_list ap; va_start(ap, s); - fprintf(errorFile,"Internal error: "); - vfprintf(errorFile,s,ap); + fprintf(errorFile, "Internal error: "); + vfprintf(errorFile, s, ap); fflush(errorFile); va_end(ap); return; @@ -307,12 +316,12 @@ uInternalError(char *s,...) char * uStringDup(char *str) { -char *rtrn; + char *rtrn; - if (str==NULL) - return NULL; - rtrn= (char *)uAlloc(strlen(str)+1); - strcpy(rtrn,str); + if (str == NULL) + return NULL; + rtrn = (char *) uAlloc(strlen(str) + 1); + strcpy(rtrn, str); return rtrn; } #endif @@ -321,24 +330,25 @@ char *rtrn; int uStrCaseCmp(char *str1, char *str2) { - char buf1[512],buf2[512]; + char buf1[512], buf2[512]; char c, *s; + register int n; - for (n=0, s = buf1; (c = *str1++); n++) { - if (isupper(c)) - c = tolower(c); - if (n>510) - break; - *s++ = c; + for (n = 0, s = buf1; (c = *str1++); n++) { + if (isupper(c)) + c = tolower(c); + if (n > 510) + break; + *s++ = c; } *s = '\0'; - for (n=0, s = buf2; (c = *str2++); n++) { - if (isupper(c)) - c = tolower(c); - if (n>510) - break; - *s++ = c; + for (n = 0, s = buf2; (c = *str2++); n++) { + if (isupper(c)) + c = tolower(c); + if (n > 510) + break; + *s++ = c; } *s = '\0'; return (strcmp(buf1, buf2)); @@ -349,15 +359,19 @@ uStrCasePrefix(char *prefix, char *str) { char c1; char c2; - while (((c1=*prefix)!='\0')&&((c2=*str)!='\0')) { - if (isupper(c1)) c1= tolower(c1); - if (isupper(c2)) c2= tolower(c2); - if (c1!=c2) - return 0; - prefix++; str++; + + while (((c1 = *prefix) != '\0') && ((c2 = *str) != '\0')) { + if (isupper(c1)) + c1 = tolower(c1); + if (isupper(c2)) + c2 = tolower(c2); + if (c1 != c2) + return 0; + prefix++; + str++; } - if (c1!='\0') - return 0; + if (c1 != '\0') + return 0; return 1; } @@ -4,10 +4,10 @@ /*\ * $Xorg: utils.h,v 1.3 2000/08/17 19:54:51 cpqbld Exp $ * - * COPYRIGHT 1990 - * DIGITAL EQUIPMENT CORPORATION - * MAYNARD, MASSACHUSETTS - * ALL RIGHTS RESERVED. + * COPYRIGHT 1990 + * DIGITAL EQUIPMENT CORPORATION + * MAYNARD, MASSACHUSETTS + * ALL RIGHTS RESERVED. * * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. @@ -40,7 +40,6 @@ _XFUNCPROTOBEGIN - #ifndef NUL #define NUL '\0' #endif @@ -48,24 +47,24 @@ _XFUNCPROTOBEGIN /***====================================================================***/ #ifndef OPAQUE_DEFINED -typedef void *Opaque; +typedef void *Opaque; #endif #ifndef NullOpaque #define NullOpaque ((Opaque)NULL) #endif #ifndef BOOLEAN_DEFINED -typedef char Boolean; +typedef char Boolean; #endif #ifndef True #define True ((Boolean)1) #define False ((Boolean)0) -#endif /* ndef True */ +#endif /* ndef True */ #define booleanText(b) ((b)?"True":"False") #ifndef COMPARISON_DEFINED -typedef int Comparison; +typedef int Comparison; #define Greater ((Comparison)1) #define Equal ((Comparison)0) @@ -76,35 +75,29 @@ typedef int Comparison; #ifdef notyet typedef union { - int i; - unsigned u; - void *p; - void *(*fp)(); + int i; + unsigned u; + void *p; + void *(*fp) (); } Union; #endif /***====================================================================***/ -extern Opaque uAlloc( - unsigned /* size */ -); -extern Opaque uCalloc( - unsigned /* n */, - unsigned /* size */ -); -extern Opaque uRealloc( - Opaque /* old */, - unsigned /* newSize */ -); -extern Opaque uRecalloc( - Opaque /* old */, - unsigned /* nOld */, - unsigned /* nNew */, - unsigned /* newSize */ -); -extern void uFree( - Opaque /* ptr */ -); +extern Opaque uAlloc(unsigned /* size */); + +extern Opaque uCalloc(unsigned /* n */, + unsigned /* size */); + +extern Opaque uRealloc(Opaque /* old */, + unsigned /* newSize */); + +extern Opaque uRecalloc(Opaque /* old */, + unsigned /* nOld */, + unsigned /* nNew */, + unsigned /* newSize */); + +extern void uFree(Opaque /* ptr */); #define uTypedAlloc(t) ((t *)uAlloc((unsigned)sizeof(t))) #define uTypedCalloc(n,t) ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t))) @@ -120,13 +113,13 @@ extern void uFree( /***====================================================================***/ -extern Boolean uSetErrorFile ( char *name ); -extern void uInformation ( char *s, ...); -extern void uAction ( char *s, ... ); -extern void uWarning ( char *s, ... ); -extern void uError ( char *s, ... ); -extern void uFatalError(char *s,...); -extern void uInternalError ( char *s, ... ); +extern Boolean uSetErrorFile(char *name); +extern void uInformation(char *s, ...); +extern void uAction(char *s, ...); +extern void uWarning(char *s, ...); +extern void uError(char *s, ...); +extern void uFatalError(char *s, ...); +extern void uInternalError(char *s, ...); /***====================================================================***/ @@ -141,21 +134,16 @@ extern void uInternalError ( char *s, ... ); #define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2)) #define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0) #else -extern int uStrCaseCmp( - char * /* s1 */, - char * /* s2 */ -); -extern int uStrCasePrefix( - char * /* p */, - char * /* str */ -); +extern int uStrCaseCmp(char * /* s1 */, + char * /* s2 */); + +extern int uStrCasePrefix(char * /* p */, + char * /* str */); #endif #ifdef HAVE_STRDUP #define uStringDup(s1) (strdup(s1)) #else -extern char *uStringDup( - char * /* s1 */ -); +extern char *uStringDup(char * /* s1 */); #endif /***====================================================================***/ @@ -174,16 +162,16 @@ extern char *uStringDup( #endif extern -unsigned int DEBUG_VAR; - -extern void uDebug( char *s, ... ); -extern void uDebugNOI( char *s, ... ); /* no indent */ -extern Boolean uSetDebugFile( - char *name -); -extern FILE *uDebugFile; -extern int uDebugIndentLevel; -extern int uDebugIndentSize; +unsigned int DEBUG_VAR; + +extern void uDebug(char *s, ...); +extern void uDebugNOI(char *s, ...); /* no indent */ +extern Boolean uSetDebugFile(char *name); + +extern FILE *uDebugFile; +extern int uDebugIndentLevel; +extern int uDebugIndentSize; + #define uDebugIndent(l) (uDebugIndentLevel+=(l)) #define uDebugOutdent(l) (uDebugIndentLevel-=(l)) #ifdef DEBUG_ON @@ -214,15 +202,13 @@ extern int uDebugIndentSize; #define uDEBUG_NOI5(f,s,a,b,c,d,e) #endif -extern Boolean uSetEntryFile( - char *name -); -extern void uEntry(int l, char *s, ... ); -extern void uExit( - int l,char *rtVal -); +extern Boolean uSetEntryFile(char *name); + +extern void uEntry(int l, char *s, ...); +extern void uExit(int l, char *rtVal); + +extern int uEntryLevel; -extern int uEntryLevel; #ifdef ENTRY_TRACKING_ON #define ENTRY_BIT 0x10 #define LOW_ENTRY_BIT 0x1000 @@ -272,10 +258,7 @@ extern int uEntryLevel; #define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h) #define uFLAG_RETURN(v) { return(v);} #define uFLAG_VOIDRETURN { return; } -#endif +#endif _XFUNCPROTOEND - -#endif /* UTILS_H */ - - +#endif /* UTILS_H */ @@ -34,113 +34,118 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <X11/XKBlib.h> #include <X11/extensions/XI.h> -static char *dpyName = NULL; -static int volume = 0; -static int devSpec = XkbUseCoreKbd; -static int class= -1; -static int id= -1; -static char * bellName; -static Atom nameAtom = None; -static int synch= 0; -static int win = None; -static int force = 0; -static int nobeep = 0; +static char *dpyName = NULL; +static int volume = 0; +static int devSpec = XkbUseCoreKbd; +static int class = -1; +static int id = -1; +static char *bellName; +static Atom nameAtom = None; +static int synch = 0; +static int win = None; +static int force = 0; +static int nobeep = 0; static int parseArgs(int argc, char *argv[]) { -int i; + int i; - for (i=1;i<argc;i++) { - if ( strcmp(argv[i],"-display")==0 ) { - if ( ++i<argc ) dpyName= argv[i]; - else { - fprintf(stderr,"Must specify a display with -display option\n"); - return 0; - } - } - else if ((strcmp(argv[i],"-help")==0) || (strcmp(argv[i],"-usage")==0)){ - return 0; - } - else if ( strcmp(argv[i],"-synch")==0 ) { - synch= 1; - } - else if ( strcmp(argv[i],"-force")==0 ) { - force= 1; - } - else if ( strcmp(argv[i],"-nobeep")==0 ) { - nobeep= 1; - } - else if ( strcmp(argv[i],"-dev")==0 ) { - if ( ++i<argc ) { - if (sscanf(argv[i]," %i ",&devSpec)!=1) { - fprintf(stderr,"Device ID must be an integer\n"); - return 0; - } - } - else { - fprintf(stderr,"Must specify a device ID with -dev option\n"); - return 0; - } - } - else if ( strcmp(argv[i],"-kf")==0 ) { - if ( ++i<argc ) { - if (sscanf(argv[i]," %i ",&id)!=1) { - fprintf(stderr,"Keyboard feedback ID must be an integer\n"); - return 0; - } - class= KbdFeedbackClass; - } - else { - fprintf(stderr,"Must specify a keyboard feedback ID for -kf\n"); - return 0; - } - } - else if ( strcmp(argv[i],"-bf")==0 ) { - if ( ++i<argc ) { - if (sscanf(argv[i]," %i ",&id)!=1) { - fprintf(stderr,"Bell feedback ID must be an integer\n"); - return 0; - } - class= BellFeedbackClass; - } - else { - fprintf(stderr,"Must specify a bell feedback ID for -bf\n"); - return 0; - } - } - else if ( strcmp(argv[i],"-v")==0 ) { - if ( ++i<argc ) { - if ((sscanf(argv[i]," %i ",&volume)!=1)|| - (volume<-100)||(volume>100)) { - fprintf(stderr,"Volume must be in the range -100..100\n"); - return 0; - } - } - else { - fprintf(stderr,"Must specify volume for -v\n"); - return 0; - } - } - else if ( strcmp(argv[i],"-w")==0 ) { - if ( ++i<argc ) { - if (sscanf(argv[i]," %i ",&win)!=1) { - fprintf(stderr,"Must specify a numeric window ID\n"); - return 0; - } - } - else { - fprintf(stderr,"Must specify a window ID for -w\n"); - return 0; - } - } - else { - if ( i<argc-1 ) { - fprintf(stderr,"Bell name must be the last argument\n"); - return 0; - } - bellName= argv[i]; - } + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-display") == 0) { + if (++i < argc) + dpyName = argv[i]; + else { + fprintf(stderr, + "Must specify a display with -display option\n"); + return 0; + } + } + else if ((strcmp(argv[i], "-help") == 0) || + (strcmp(argv[i], "-usage") == 0)) { + return 0; + } + else if (strcmp(argv[i], "-synch") == 0) { + synch = 1; + } + else if (strcmp(argv[i], "-force") == 0) { + force = 1; + } + else if (strcmp(argv[i], "-nobeep") == 0) { + nobeep = 1; + } + else if (strcmp(argv[i], "-dev") == 0) { + if (++i < argc) { + if (sscanf(argv[i], " %i ", &devSpec) != 1) { + fprintf(stderr, "Device ID must be an integer\n"); + return 0; + } + } + else { + fprintf(stderr, "Must specify a device ID with -dev option\n"); + return 0; + } + } + else if (strcmp(argv[i], "-kf") == 0) { + if (++i < argc) { + if (sscanf(argv[i], " %i ", &id) != 1) { + fprintf(stderr, + "Keyboard feedback ID must be an integer\n"); + return 0; + } + class = KbdFeedbackClass; + } + else { + fprintf(stderr, + "Must specify a keyboard feedback ID for -kf\n"); + return 0; + } + } + else if (strcmp(argv[i], "-bf") == 0) { + if (++i < argc) { + if (sscanf(argv[i], " %i ", &id) != 1) { + fprintf(stderr, "Bell feedback ID must be an integer\n"); + return 0; + } + class = BellFeedbackClass; + } + else { + fprintf(stderr, "Must specify a bell feedback ID for -bf\n"); + return 0; + } + } + else if (strcmp(argv[i], "-v") == 0) { + if (++i < argc) { + if ((sscanf(argv[i], " %i ", &volume) != 1) || + (volume < -100) || (volume > 100)) { + fprintf(stderr, "Volume must be in the range -100..100\n"); + return 0; + } + } + else { + fprintf(stderr, "Must specify volume for -v\n"); + return 0; + } + } + else if (strcmp(argv[i], "-w") == 0) { + if (++i < argc) { + if (sscanf(argv[i], " %i ", &win) != 1) { + fprintf(stderr, "Must specify a numeric window ID\n"); + return 0; + } + } + else { + fprintf(stderr, "Must specify a window ID for -w\n"); + return 0; + } + } + else { + if (i < argc - 1) { + fprintf(stderr, "Bell name must be the last argument\n"); + return 0; + } + bellName = argv[i]; + } } return 1; } @@ -148,74 +153,90 @@ int i; int main(int argc, char *argv[]) { -Display *dpy; -int i1,i2,i3,i4,i5; + Display *dpy; - - if (!parseArgs(argc,argv)) { - fprintf(stderr,"Usage: %s [ <options> ] <name>\n",argv[0]); - fprintf(stderr,"Where legal options are:\n"); - fprintf(stderr,"-help print this message\n"); - fprintf(stderr,"-usage print this message\n"); - fprintf(stderr,"-display <dpy> specifies display to use\n"); - fprintf(stderr,"-synch turn on synchronization\n"); - fprintf(stderr,"-dev <id> specifies device to use\n"); - fprintf(stderr,"-force force audible bell\n"); - fprintf(stderr,"-nobeep suppress server bell, event only\n"); - fprintf(stderr,"-bf <id> specifies bell feedback to use\n"); - fprintf(stderr,"-kf <id> specifies keyboard feedback to use\n"); - fprintf(stderr,"-v <volume> specifies volume to use\n"); - fprintf(stderr,"-w <id> specifies window to use\n"); - fprintf(stderr,"If neither device nor feedback are specified, %s uses the\n",argv[0]); - fprintf(stderr,"default values for the core keyboard device.\n"); - return 1; + int i1, i2, i3, i4, i5; + + if (!parseArgs(argc, argv)) { + fprintf(stderr, "Usage: %s [ <options> ] <name>\n", argv[0]); + fprintf(stderr, "Where legal options are:\n"); + fprintf(stderr, "-help print this message\n"); + fprintf(stderr, "-usage print this message\n"); + fprintf(stderr, "-display <dpy> specifies display to use\n"); + fprintf(stderr, "-synch turn on synchronization\n"); + fprintf(stderr, "-dev <id> specifies device to use\n"); + fprintf(stderr, "-force force audible bell\n"); + fprintf(stderr, + "-nobeep suppress server bell, event only\n"); + fprintf(stderr, "-bf <id> specifies bell feedback to use\n"); + fprintf(stderr, + "-kf <id> specifies keyboard feedback to use\n"); + fprintf(stderr, "-v <volume> specifies volume to use\n"); + fprintf(stderr, "-w <id> specifies window to use\n"); + fprintf(stderr, + "If neither device nor feedback are specified, %s uses the\n", + argv[0]); + fprintf(stderr, "default values for the core keyboard device.\n"); + return 1; } dpy = XOpenDisplay(dpyName); - if ( !dpy ) { - fprintf(stderr,"Couldn't open display \"%s\"\n",XDisplayName(dpyName)); - return 1; + if (!dpy) { + fprintf(stderr, "Couldn't open display \"%s\"\n", + XDisplayName(dpyName)); + return 1; } if (synch) - XSynchronize(dpy,1); - i1= XkbMajorVersion; - i2= XkbMinorVersion; - if ( !XkbLibraryVersion(&i1,&i2) ) { - fprintf(stderr,"Warning! X library built with XKB version %d.%02d\n", - i1,i2); - fprintf(stderr," but %s was built with %d.%02d\n",argv[0], - XkbMajorVersion,XkbMinorVersion); - fprintf(stderr," Trying anyway\n"); + XSynchronize(dpy, 1); + i1 = XkbMajorVersion; + i2 = XkbMinorVersion; + if (!XkbLibraryVersion(&i1, &i2)) { + fprintf(stderr, "Warning! X library built with XKB version %d.%02d\n", + i1, i2); + fprintf(stderr, " but %s was built with %d.%02d\n", argv[0], + XkbMajorVersion, XkbMinorVersion); + fprintf(stderr, " Trying anyway\n"); } - if ( !XkbQueryExtension(dpy,&i1,&i2,&i3,&i4,&i5)>0 ) { - if ((i4!=0)||(i5!=0)) - fprintf(stderr,"server supports incompatible XKB version %d.%02d\n", - i4,i5); - else fprintf(stderr,"XkbQueryExtension failed\n"); - fprintf(stderr,"Trying anyway\n"); + if (!XkbQueryExtension(dpy, &i1, &i2, &i3, &i4, &i5) > 0) { + if ((i4 != 0) || (i5 != 0)) + fprintf(stderr, + "server supports incompatible XKB version %d.%02d\n", i4, + i5); + else + fprintf(stderr, "XkbQueryExtension failed\n"); + fprintf(stderr, "Trying anyway\n"); } - if (force && (nameAtom!=None)) - fprintf(stderr,"Warning! Name ignored for forced bell requests\n"); - if (bellName!=NULL) - nameAtom = XInternAtom(dpy,bellName,0); - if ((devSpec==XkbUseCoreKbd)&&(class<0)) { - Bool ok; - if (force) ok= XkbForceBell(dpy,volume); - else if (nobeep) ok= XkbBellEvent(dpy,win,volume,nameAtom); - else ok= XkbBell(dpy,win,volume,nameAtom); - if (!ok) - fprintf(stderr,"XkbBell request failed\n"); + if (force && (nameAtom != None)) + fprintf(stderr, "Warning! Name ignored for forced bell requests\n"); + if (bellName != NULL) + nameAtom = XInternAtom(dpy, bellName, 0); + if ((devSpec == XkbUseCoreKbd) && (class < 0)) { + Bool ok; + + if (force) + ok = XkbForceBell(dpy, volume); + else if (nobeep) + ok = XkbBellEvent(dpy, win, volume, nameAtom); + else + ok = XkbBell(dpy, win, volume, nameAtom); + if (!ok) + fprintf(stderr, "XkbBell request failed\n"); } else { - Bool ok; - if (class<0) class= KbdFeedbackClass; - if (id<0) id= 0; - if (force) - ok= XkbForceDeviceBell(dpy,devSpec,class,id,volume); - else if (nobeep) - ok= XkbDeviceBellEvent(dpy,win,devSpec,class,id,volume,nameAtom); - else ok= XkbDeviceBell(dpy,win,devSpec,class,id,volume,nameAtom); - if (!ok) - fprintf(stderr,"XkbDeviceBell request failed\n"); + Bool ok; + + if (class < 0) + class = KbdFeedbackClass; + if (id < 0) + id = 0; + if (force) + ok = XkbForceDeviceBell(dpy, devSpec, class, id, volume); + else if (nobeep) + ok = XkbDeviceBellEvent(dpy, win, devSpec, class, id, volume, + nameAtom); + else + ok = XkbDeviceBell(dpy, win, devSpec, class, id, volume, nameAtom); + if (!ok) + fprintf(stderr, "XkbDeviceBell request failed\n"); } /* BAIL: */ XCloseDisplay(dpy); @@ -49,24 +49,24 @@ #define NO 0 #define DONT_CARE -1 -static Display * inDpy,*outDpy; -static unsigned long wanted,real,named,explicit,automatic,virtual; -static char * inDpyName; -static int wantNamed= DONT_CARE; -static int wantExplicit= DONT_CARE; -static int wantAutomatic= DONT_CARE; -static int wantReal= DONT_CARE; -static int wantVirtual= DONT_CARE; -static int evBase,errBase; -static Bool synch; -static Bool useUnion= True; +static Display *inDpy, *outDpy; +static unsigned long wanted, real, named, explicit, automatic, virtual; +static char *inDpyName; +static int wantNamed = DONT_CARE; +static int wantExplicit = DONT_CARE; +static int wantAutomatic = DONT_CARE; +static int wantReal = DONT_CARE; +static int wantVirtual = DONT_CARE; +static int evBase, errBase; +static Bool synch; +static Bool useUnion = True; /***====================================================================***/ static void usage(char *program) { - uInformation("Usage: %s <options>\n",program); + uInformation("Usage: %s <options>\n", program); uInformation("Legal options include the usual X toolkit options plus:\n"); uInformation(" -help Print this message\n"); uInformation(" -indpy <name> Name of display to watch\n"); @@ -85,66 +85,70 @@ usage(char *program) static Bool parseArgs(int argc, char *argv[]) { -register int i; + register int i; - for (i=1;i<argc;i++) { - if (uStrCaseEqual(argv[i],"-indpy")) { - if (i<argc-1) inDpyName= argv[++i]; - else { - uWarning("No name specified for input display\n"); - uAction("Ignoring trailing -indpy argument\n"); - } - } - else if (uStrCaseEqual(argv[i],"-watch")) { - if (i<argc-1) { - int tmp; - if (sscanf(argv[++i],"%i",&tmp)!=1) { - uWarning("Set of LEDs must be specified as an integer\n"); - uAction("Ignoring bogus value \"%s\" for -watch flag\n", - argv[i]); - } - else wanted= tmp; - } - else { - uWarning("Didn't specify any LEDs to watch\n"); - uAction("Ignoring trailing -watch argument\n"); - } - } - else if (uStrCaseEqual(argv[i],"-union")) { - useUnion= True; - } - else if (uStrCaseEqual(argv[i],"-intersection")) { - useUnion= False; - } - else if (uStrCaseEqual(argv[i],"-help")) { - usage(argv[0]); - exit(0); - } - else if ((argv[i][0]=='+')||(argv[i][0]=='-')) { - Bool onoff; - int * which; - onoff= (argv[i][0]=='+'); - which= NULL; - if (uStrCaseEqual(&argv[i][1],"name")) - which= &wantNamed; - else if (uStrCaseEqual(&argv[i][1],"explicit")) - which= &wantExplicit; - else if (uStrCaseEqual(&argv[i][1],"automatic")) - which= &wantAutomatic; - else if (uStrCaseEqual(&argv[i][1],"real")) - which= &wantReal; - else if (uStrCaseEqual(&argv[i][1],"virtual")) - which= &wantVirtual; - if (which!=NULL) { - if (*which!=DONT_CARE) { - uWarning("Multiple settings for [+-]%s\n",&argv[i][1]); - uAction("Using %c%s, ignoring %c%s\n", - (onoff?'+':'-'),&argv[i][1], - (onoff?'-':'+'),&argv[i][1]); - } - *which= (onoff?YES:NO); - } - } + for (i = 1; i < argc; i++) { + if (uStrCaseEqual(argv[i], "-indpy")) { + if (i < argc - 1) + inDpyName = argv[++i]; + else { + uWarning("No name specified for input display\n"); + uAction("Ignoring trailing -indpy argument\n"); + } + } + else if (uStrCaseEqual(argv[i], "-watch")) { + if (i < argc - 1) { + int tmp; + + if (sscanf(argv[++i], "%i", &tmp) != 1) { + uWarning("Set of LEDs must be specified as an integer\n"); + uAction("Ignoring bogus value \"%s\" for -watch flag\n", + argv[i]); + } + else + wanted = tmp; + } + else { + uWarning("Didn't specify any LEDs to watch\n"); + uAction("Ignoring trailing -watch argument\n"); + } + } + else if (uStrCaseEqual(argv[i], "-union")) { + useUnion = True; + } + else if (uStrCaseEqual(argv[i], "-intersection")) { + useUnion = False; + } + else if (uStrCaseEqual(argv[i], "-help")) { + usage(argv[0]); + exit(0); + } + else if ((argv[i][0] == '+') || (argv[i][0] == '-')) { + Bool onoff; + int *which; + + onoff = (argv[i][0] == '+'); + which = NULL; + if (uStrCaseEqual(&argv[i][1], "name")) + which = &wantNamed; + else if (uStrCaseEqual(&argv[i][1], "explicit")) + which = &wantExplicit; + else if (uStrCaseEqual(&argv[i][1], "automatic")) + which = &wantAutomatic; + else if (uStrCaseEqual(&argv[i][1], "real")) + which = &wantReal; + else if (uStrCaseEqual(&argv[i][1], "virtual")) + which = &wantVirtual; + if (which != NULL) { + if (*which != DONT_CARE) { + uWarning("Multiple settings for [+-]%s\n", &argv[i][1]); + uAction("Using %c%s, ignoring %c%s\n", + (onoff ? '+' : '-'), &argv[i][1], + (onoff ? '-' : '+'), &argv[i][1]); + } + *which = (onoff ? YES : NO); + } + } } return True; } @@ -154,38 +158,38 @@ register int i; static Display * GetDisplay(char *program, char *dpyName) { -int mjr,mnr,error; -Display * dpy; + int mjr, mnr, error; + Display *dpy; - mjr= XkbMajorVersion; - mnr= XkbMinorVersion; - dpy= XkbOpenDisplay(dpyName,&evBase,&errBase,&mjr,&mnr,&error); - if (dpy==NULL) { - switch (error) { - case XkbOD_BadLibraryVersion: - uInformation("%s was compiled with XKB version %d.%02d\n", - program,XkbMajorVersion,XkbMinorVersion); - uError("X library supports incompatible version %d.%02d\n", - mjr,mnr); - break; - case XkbOD_ConnectionRefused: - uError("Cannot open display \"%s\"\n",dpyName); - break; - case XkbOD_NonXkbServer: - uError("XKB extension not present on %s\n",dpyName); - break; - case XkbOD_BadServerVersion: - uInformation("%s was compiled with XKB version %d.%02d\n", - program,XkbMajorVersion,XkbMinorVersion); - uError("Server %s uses incompatible version %d.%02d\n", - dpyName,mjr,mnr); - break; - default: - uInternalError("Unknown error %d from XkbOpenDisplay\n",error); - } + mjr = XkbMajorVersion; + mnr = XkbMinorVersion; + dpy = XkbOpenDisplay(dpyName, &evBase, &errBase, &mjr, &mnr, &error); + if (dpy == NULL) { + switch (error) { + case XkbOD_BadLibraryVersion: + uInformation("%s was compiled with XKB version %d.%02d\n", + program, XkbMajorVersion, XkbMinorVersion); + uError("X library supports incompatible version %d.%02d\n", + mjr, mnr); + break; + case XkbOD_ConnectionRefused: + uError("Cannot open display \"%s\"\n", dpyName); + break; + case XkbOD_NonXkbServer: + uError("XKB extension not present on %s\n", dpyName); + break; + case XkbOD_BadServerVersion: + uInformation("%s was compiled with XKB version %d.%02d\n", + program, XkbMajorVersion, XkbMinorVersion); + uError("Server %s uses incompatible version %d.%02d\n", + dpyName, mjr, mnr); + break; + default: + uInternalError("Unknown error %d from XkbOpenDisplay\n", error); + } } else if (synch) - XSynchronize(dpy,True); + XSynchronize(dpy, True); return dpy; } @@ -194,167 +198,190 @@ Display * dpy; 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 -}; + 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; + 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 ((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; + 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; + outDpy = XtDisplay(toplevel); + if (inDpyName != NULL) { + inDpy = GetDisplay(argv[0], inDpyName); + if (!inDpy) + return 1; } else { - inDpy= outDpy; + 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; - } + 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; + 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; + 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; + 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); - if (useUnion) - wanted|= real|virtual|named|automatic|explicit; - else wanted&= real&virtual&named&automatic&explicit; + 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); + if (useUnion) + wanted |= real | virtual | named | automatic | explicit; + else + wanted &= real & virtual & named & automatic & explicit; } - else xkb= NULL; - if (wanted==0) { - uError("No indicator maps match the selected criteria\n"); - uAction("Exiting\n"); - return 1; + else + xkb = NULL; + if (wanted == 0) { + uError("No indicator maps match the selected criteria\n"); + uAction("Exiting\n"); + return 1; } - XkbSelectEvents(inDpy,XkbUseCoreKbd,XkbIndicatorStateNotifyMask, - XkbIndicatorStateNotifyMask); - XkbGetIndicatorState(inDpy,XkbUseCoreKbd,&n); - bit= (1<<(XkbNumIndicators-1)); - for (i=XkbNumIndicators-1;i>=0;i--,bit>>=1) { - if (wanted&bit) { - char buf[12]; - ArgList list; + XkbSelectEvents(inDpy, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, + XkbIndicatorStateNotifyMask); + XkbGetIndicatorState(inDpy, XkbUseCoreKbd, &n); + bit = (1 << (XkbNumIndicators - 1)); + for (i = XkbNumIndicators - 1; i >= 0; i--, bit >>= 1) { + if (wanted & bit) { + char buf[12]; + ArgList list; - sprintf(buf,"led%d",i+1); - if (n&bit) list= onArgs; - else list= offArgs; - leds[i]= XtCreateManagedWidget(buf,ledWidgetClass,panel,list,1); - } + sprintf(buf, "led%d", i + 1); + if (n & bit) + list = onArgs; + else + list = offArgs; + leds[i] = + XtCreateManagedWidget(buf, ledWidgetClass, panel, list, 1); + } } XtRealizeWidget(toplevel); while (1) { - XtAppNextEvent(app_con,&ev.core); - if (ev.core.type==evBase+XkbEventCode) { - if (ev.any.xkb_type==XkbIndicatorStateNotify) { - for (i=0,bit=1;i<XkbNumIndicators;i++,bit<<=1) { - if ((ev.indicators.changed&bit)&&(leds[i])) { - ArgList list; - if (ev.indicators.state&bit) list= onArgs; - else list= offArgs; - XtSetValues(leds[i],list,1); - } - } - } - } - else XtDispatchEvent(&ev.core); + XtAppNextEvent(app_con, &ev.core); + if (ev.core.type == evBase + XkbEventCode) { + if (ev.any.xkb_type == XkbIndicatorStateNotify) { + for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) { + if ((ev.indicators.changed & bit) && (leds[i])) { + ArgList list; + + if (ev.indicators.state & bit) + list = onArgs; + else + list = offArgs; + XtSetValues(leds[i], list, 1); + } + } + } + } + else + XtDispatchEvent(&ev.core); } /* BAIL: */ - if (inDpy) - XCloseDisplay(inDpy); - if (outDpy!=inDpy) - XCloseDisplay(outDpy); - inDpy= outDpy= NULL; + if (inDpy) + XCloseDisplay(inDpy); + if (outDpy != inDpy) + XCloseDisplay(outDpy); + inDpy = outDpy = NULL; return 0; } @@ -45,15 +45,14 @@ /***====================================================================***/ -static Display * inDpy,*outDpy; -static int evBase,errBase; +static Display *inDpy, *outDpy; +static int evBase, errBase; /***====================================================================***/ - static XrmOptionDescRec options[] = { -{"-off", "*on.on", XrmoptionNoArg, "FALSE"}, -{"-on", "*on.on", XrmoptionNoArg, "TRUE"} + {"-off", "*on.on", XrmoptionNoArg, "FALSE"}, + {"-on", "*on.on", XrmoptionNoArg, "TRUE"} }; /***====================================================================***/ @@ -61,172 +60,211 @@ static XrmOptionDescRec options[] = { int main(int argc, char *argv[]) { -Widget toplevel; -XtAppContext app_con; -Widget panel; -Widget base[XkbNumModifiers]; -Widget latched[XkbNumModifiers]; -Widget locked[XkbNumModifiers]; -Widget effective[XkbNumModifiers]; -Widget compat[XkbNumModifiers]; -Widget baseBox,latchBox,lockBox,effBox,compatBox; -register int i; -unsigned bit; -XkbEvent ev; -XkbStateRec state; -static Arg hArgs[]= {{ XtNorientation, (XtArgVal)XtorientHorizontal }}; -static Arg vArgs[]= {{ XtNorientation, (XtArgVal)XtorientVertical }}; -static Arg onArgs[]= {{ XtNon, (XtArgVal)True }}; -static Arg offArgs[]= {{ XtNon, (XtArgVal)False }}; -static char * fallback_resources[] = { - "*Box*background: grey50", - "*Box*borderWidth: 0", - "*Box*vSpace: 1", - NULL -}; + Widget toplevel; + XtAppContext app_con; + Widget panel; + Widget base[XkbNumModifiers]; + Widget latched[XkbNumModifiers]; + Widget locked[XkbNumModifiers]; + Widget effective[XkbNumModifiers]; + Widget compat[XkbNumModifiers]; + Widget baseBox, latchBox, lockBox, effBox, compatBox; + register int i; + unsigned bit; + XkbEvent ev; + XkbStateRec state; + static Arg hArgs[] = { {XtNorientation, (XtArgVal) XtorientHorizontal} }; + static Arg vArgs[] = { {XtNorientation, (XtArgVal) XtorientVertical} }; + static Arg onArgs[] = { {XtNon, (XtArgVal) True} }; + static Arg offArgs[] = { {XtNon, (XtArgVal) False} }; + static char *fallback_resources[] = { + "*Box*background: grey50", + "*Box*borderWidth: 0", + "*Box*vSpace: 1", + NULL + }; uSetEntryFile(NullString); uSetDebugFile(NullString); uSetErrorFile(NullString); toplevel = XtOpenApplication(&app_con, "XkbWatch", - options, XtNumber(options), &argc, argv, - fallback_resources, - sessionShellWidgetClass, NULL, ZERO); - if (toplevel==NULL) { - uFatalError("Couldn't create application top level\n"); - exit(1); + options, XtNumber(options), &argc, argv, + fallback_resources, + sessionShellWidgetClass, NULL, ZERO); + if (toplevel == NULL) { + uFatalError("Couldn't create application top level\n"); + exit(1); } - inDpy= outDpy= XtDisplay(toplevel); + inDpy = outDpy = XtDisplay(toplevel); if (inDpy) { - int i1,mn,mj; - mj= XkbMajorVersion; - mn= XkbMinorVersion; - if (!XkbQueryExtension(inDpy,&i1,&evBase,&errBase,&mj,&mn)) { - uFatalError("Server doesn't support a compatible XKB\n"); - exit(1); - } + int i1, mn, mj; + + mj = XkbMajorVersion; + mn = XkbMinorVersion; + if (!XkbQueryExtension(inDpy, &i1, &evBase, &errBase, &mj, &mn)) { + uFatalError("Server doesn't support a compatible XKB\n"); + exit(1); + } } - panel= XtCreateManagedWidget("xkbwatch",boxWidgetClass,toplevel,vArgs,1); - if (panel==NULL) { - uFatalError("Couldn't create top level box\n"); - exit(1); + panel = + XtCreateManagedWidget("xkbwatch", boxWidgetClass, toplevel, vArgs, 1); + if (panel == NULL) { + uFatalError("Couldn't create top level box\n"); + exit(1); } - baseBox= XtCreateManagedWidget("base",boxWidgetClass,panel,hArgs,1); - if (baseBox==NULL) - uFatalError("Couldn't create base modifiers box\n"); - latchBox= XtCreateManagedWidget("latched",boxWidgetClass,panel,hArgs,1); - if (latchBox==NULL) - uFatalError("Couldn't create latched modifiers box\n"); - lockBox= XtCreateManagedWidget("locked",boxWidgetClass,panel,hArgs,1); - if (lockBox==NULL) - uFatalError("Couldn't create locked modifiers box\n"); - effBox= XtCreateManagedWidget("effective",boxWidgetClass,panel,hArgs,1); - if (effBox==NULL) - uFatalError("Couldn't create effective modifiers box\n"); - compatBox= XtCreateManagedWidget("compat",boxWidgetClass,panel,hArgs,1); - if (compatBox==NULL) - uFatalError("Couldn't create compatibility state box\n"); - XkbSelectEvents(inDpy,XkbUseCoreKbd,XkbStateNotifyMask,XkbStateNotifyMask); - XkbGetState(inDpy,XkbUseCoreKbd,&state); - for (i=XkbNumModifiers-1,bit=0x80;i>=0;i--,bit>>=1) { - ArgList list; - char buf[30]; - sprintf(buf,"base%d",i); - if (state.base_mods&bit) list= onArgs; - else list= offArgs; - base[i]= XtCreateManagedWidget(buf,ledWidgetClass,baseBox,list,1); - sprintf(buf,"latched%d",i); - if (state.latched_mods&bit) list= onArgs; - else list= offArgs; - latched[i]= XtCreateManagedWidget(buf,ledWidgetClass,latchBox,list,1); - sprintf(buf,"locked%d",i); - if (state.locked_mods&bit) list= onArgs; - else list= offArgs; - locked[i]= XtCreateManagedWidget(buf,ledWidgetClass,lockBox,list,1); - sprintf(buf,"effective%d",i); - if (state.mods&bit) list= onArgs; - else list= offArgs; - effective[i]= XtCreateManagedWidget(buf,ledWidgetClass,effBox,list,1); - sprintf(buf,"compat%d",i); - if (state.compat_state&bit) list= onArgs; - else list= offArgs; - compat[i]= XtCreateManagedWidget(buf,ledWidgetClass,compatBox,list,1); + baseBox = XtCreateManagedWidget("base", boxWidgetClass, panel, hArgs, 1); + if (baseBox == NULL) + uFatalError("Couldn't create base modifiers box\n"); + latchBox = + XtCreateManagedWidget("latched", boxWidgetClass, panel, hArgs, 1); + if (latchBox == NULL) + uFatalError("Couldn't create latched modifiers box\n"); + lockBox = XtCreateManagedWidget("locked", boxWidgetClass, panel, hArgs, 1); + if (lockBox == NULL) + uFatalError("Couldn't create locked modifiers box\n"); + effBox = + XtCreateManagedWidget("effective", boxWidgetClass, panel, hArgs, 1); + if (effBox == NULL) + uFatalError("Couldn't create effective modifiers box\n"); + compatBox = + XtCreateManagedWidget("compat", boxWidgetClass, panel, hArgs, 1); + if (compatBox == NULL) + uFatalError("Couldn't create compatibility state box\n"); + XkbSelectEvents(inDpy, XkbUseCoreKbd, XkbStateNotifyMask, + XkbStateNotifyMask); + XkbGetState(inDpy, XkbUseCoreKbd, &state); + for (i = XkbNumModifiers - 1, bit = 0x80; i >= 0; i--, bit >>= 1) { + ArgList list; + + char buf[30]; + + sprintf(buf, "base%d", i); + if (state.base_mods & bit) + list = onArgs; + else + list = offArgs; + base[i] = XtCreateManagedWidget(buf, ledWidgetClass, baseBox, list, 1); + sprintf(buf, "latched%d", i); + if (state.latched_mods & bit) + list = onArgs; + else + list = offArgs; + latched[i] = + XtCreateManagedWidget(buf, ledWidgetClass, latchBox, list, 1); + sprintf(buf, "locked%d", i); + if (state.locked_mods & bit) + list = onArgs; + else + list = offArgs; + locked[i] = + XtCreateManagedWidget(buf, ledWidgetClass, lockBox, list, 1); + sprintf(buf, "effective%d", i); + if (state.mods & bit) + list = onArgs; + else + list = offArgs; + effective[i] = + XtCreateManagedWidget(buf, ledWidgetClass, effBox, list, 1); + sprintf(buf, "compat%d", i); + if (state.compat_state & bit) + list = onArgs; + else + list = offArgs; + compat[i] = + XtCreateManagedWidget(buf, ledWidgetClass, compatBox, list, 1); } XtRealizeWidget(toplevel); while (1) { - XtAppNextEvent(app_con,&ev.core); - if (ev.core.type==evBase+XkbEventCode) { - if (ev.any.xkb_type==XkbStateNotify) { - unsigned changed; - if (ev.state.changed&XkbModifierBaseMask) { - changed= ev.state.base_mods^state.base_mods; - state.base_mods= ev.state.base_mods; - for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { - if (changed&bit) { - ArgList list; - if (state.base_mods&bit) list= onArgs; - else list= offArgs; - XtSetValues(base[i],list,1); - } - } - } - if (ev.state.changed&XkbModifierLatchMask) { - changed= ev.state.latched_mods^state.latched_mods; - state.latched_mods= ev.state.latched_mods; - for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { - if (changed&bit) { - ArgList list; - if (state.latched_mods&bit) list= onArgs; - else list= offArgs; - XtSetValues(latched[i],list,1); - } - } - } - if (ev.state.changed&XkbModifierLockMask) { - changed= ev.state.locked_mods^state.locked_mods; - state.locked_mods= ev.state.locked_mods; - for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { - if (changed&bit) { - ArgList list; - if (state.locked_mods&bit) list= onArgs; - else list= offArgs; - XtSetValues(locked[i],list,1); - } - } - } - if (ev.state.changed&XkbModifierStateMask) { - changed= ev.state.mods^state.mods; - state.mods= ev.state.mods; - for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { - if (changed&bit) { - ArgList list; - if (state.mods&bit) list= onArgs; - else list= offArgs; - XtSetValues(effective[i],list,1); - } - } - } - if (ev.state.changed&XkbCompatStateMask) { - changed= ev.state.compat_state^state.compat_state; - state.compat_state= ev.state.compat_state; - for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { - if (changed&bit) { - ArgList list; - if (state.compat_state&bit) list= onArgs; - else list= offArgs; - XtSetValues(compat[i],list,1); - } - } - } - } - } - else XtDispatchEvent(&ev.core); + XtAppNextEvent(app_con, &ev.core); + if (ev.core.type == evBase + XkbEventCode) { + if (ev.any.xkb_type == XkbStateNotify) { + unsigned changed; + + if (ev.state.changed & XkbModifierBaseMask) { + changed = ev.state.base_mods ^ state.base_mods; + state.base_mods = ev.state.base_mods; + for (i = 0, bit = 1; i < XkbNumModifiers; i++, bit <<= 1) { + if (changed & bit) { + ArgList list; + + if (state.base_mods & bit) + list = onArgs; + else + list = offArgs; + XtSetValues(base[i], list, 1); + } + } + } + if (ev.state.changed & XkbModifierLatchMask) { + changed = ev.state.latched_mods ^ state.latched_mods; + state.latched_mods = ev.state.latched_mods; + for (i = 0, bit = 1; i < XkbNumModifiers; i++, bit <<= 1) { + if (changed & bit) { + ArgList list; + + if (state.latched_mods & bit) + list = onArgs; + else + list = offArgs; + XtSetValues(latched[i], list, 1); + } + } + } + if (ev.state.changed & XkbModifierLockMask) { + changed = ev.state.locked_mods ^ state.locked_mods; + state.locked_mods = ev.state.locked_mods; + for (i = 0, bit = 1; i < XkbNumModifiers; i++, bit <<= 1) { + if (changed & bit) { + ArgList list; + + if (state.locked_mods & bit) + list = onArgs; + else + list = offArgs; + XtSetValues(locked[i], list, 1); + } + } + } + if (ev.state.changed & XkbModifierStateMask) { + changed = ev.state.mods ^ state.mods; + state.mods = ev.state.mods; + for (i = 0, bit = 1; i < XkbNumModifiers; i++, bit <<= 1) { + if (changed & bit) { + ArgList list; + + if (state.mods & bit) + list = onArgs; + else + list = offArgs; + XtSetValues(effective[i], list, 1); + } + } + } + if (ev.state.changed & XkbCompatStateMask) { + changed = ev.state.compat_state ^ state.compat_state; + state.compat_state = ev.state.compat_state; + for (i = 0, bit = 1; i < XkbNumModifiers; i++, bit <<= 1) { + if (changed & bit) { + ArgList list; + + if (state.compat_state & bit) + list = onArgs; + else + list = offArgs; + XtSetValues(compat[i], list, 1); + } + } + } + } + } + else + XtDispatchEvent(&ev.core); } /* BAIL: */ - if (inDpy) - XCloseDisplay(inDpy); - if (outDpy!=inDpy) - XCloseDisplay(outDpy); - inDpy= outDpy= NULL; + if (inDpy) + XCloseDisplay(inDpy); + if (outDpy != inDpy) + XCloseDisplay(outDpy); + inDpy = outDpy = NULL; return 0; } |