diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 15:54:54 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-14 15:54:54 +0000 |
commit | 53c921965d341cfa3f14fedf862d9db666c16002 (patch) | |
tree | 2f8991006571c79a6ff91b87ef494a5a61702215 |
R6.6 is the Xorg base-lineXORG-MAINXORG-STABLE
-rw-r--r-- | LED.c | 314 | ||||
-rw-r--r-- | LED.h | 97 | ||||
-rw-r--r-- | LEDP.h | 76 | ||||
-rw-r--r-- | utils.c | 368 | ||||
-rw-r--r-- | utils.h | 307 | ||||
-rw-r--r-- | xkbbell.c | 225 | ||||
-rw-r--r-- | xkbvleds.c | 362 | ||||
-rw-r--r-- | xkbwatch.c | 283 |
8 files changed, 2032 insertions, 0 deletions
@@ -0,0 +1,314 @@ +/* $Xorg: LED.c,v 1.3 2000/08/17 19:54:51 cpqbld Exp $ */ +/************************************************************ + Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. + + Permission to use, copy, modify, and distribute this + software and its documentation for any purpose and without + fee is hereby granted, provided that the above copyright + notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting + documentation, and that the name of Silicon Graphics not be + used in advertising or publicity pertaining to distribution + of the software without specific prior written permission. + Silicon Graphics makes no representation about the suitability + of this software for any purpose. It is provided "as is" + without any express or implied warranty. + + SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH + THE USE OR PERFORMANCE OF THIS SOFTWARE. + + ********************************************************/ + +#include <X11/IntrinsicP.h> +#include <X11/StringDefs.h> +#include <X11/Xos.h> +#include <X11/Xaw/XawInit.h> +#include "LEDP.h" +#include <X11/Xmu/Converters.h> +#include <X11/Xmu/Drawing.h> +#include <stdio.h> +#include <ctype.h> + +/* needed for abs() */ +#ifndef X_NOT_STDC_ENV +#include <stdlib.h> +#else +int abs(); +#endif + +#define streq(a,b) (strcmp( (a), (b) ) == 0) + +#ifdef CRAY +#define WORD64 +#endif + +/**************************************************************** + * + * Full class record constant + * + ****************************************************************/ + +/* Private Data */ + +#define offset(field) XtOffsetOf(LEDRec, field) +static XtResource resources[] = { + {XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel), + offset(led.foreground), XtRString, XtDefaultForeground}, + {XtNon, XtCOn, XtRBoolean, sizeof(Boolean), + offset(led.on), XtRImmediate, (XtPointer)False}, + {XtNtopColor, XtCTopColor, XtRPixel, sizeof(Pixel), + offset(led.top_color), XtRString, "black"}, + {XtNbottomColor, XtCBottomColor, XtRPixel, sizeof(Pixel), + offset(led.bottom_color), XtRString, "white"}, + {XtNonColor, XtCOnColor, XtRPixel, sizeof(Pixel), + offset(led.on_color), XtRString, "green"}, + {XtNoffColor, XtCOffColor, XtRPixel, sizeof(Pixel), + offset(led.off_color), XtRString, "#005000"}, + {XtNbevel, XtCBevel, XtRDimension, sizeof(Dimension), + offset(led.bevel), XtRImmediate, (XtPointer)1}, + {XtNledWidth, XtCLedWidth, XtRDimension, sizeof(Dimension), + offset(led.led_width), XtRImmediate, (XtPointer)6}, + {XtNledHeight, XtCLedHeight, XtRDimension, sizeof(Dimension), + offset(led.led_height), XtRImmediate, (XtPointer)12} +}; +#undef offset + +static void Initialize(); +static void Resize(); +static void Realize(); +static Boolean SetValues(); +static void ClassInitialize(); +static void Destroy(); +static XtGeometryResult QueryGeometry(); + +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 + }, +/* Simple class fields initialization */ + { + /* change_sensitive */ XtInheritChangeSensitive + }, +/* LED class fields initialization */ + { + /* ignore */ 0 + } +}; +WidgetClass ledWidgetClass = (WidgetClass)&ledClassRec; +/**************************************************************** + * + * Private Procedures + * + ****************************************************************/ + +static void ClassInitialize() +{ + XawInitializeWidgetSet(); +} + +static void +GetPixmaps(lw) + LEDWidget lw; +{ + 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; + } + 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); + + 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; +} + +/* ARGSUSED */ +static void Initialize(request, new, args, num_args) + Widget request, new; + ArgList args; + Cardinal *num_args; +{ + LEDWidget lw = (LEDWidget) new; + + if (lw->core.height == 0) + 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); + GetPixmaps(lw); +} /* Initialize */ + +static void +Realize(w, mask, xswa) + Widget w; + Mask * mask; + XSetWindowAttributes * xswa; +{ + LEDWidget lw = (LEDWidget)w; + WidgetClass super = simpleWidgetClass; + 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); + return; +} + +static void +Resize(w) + Widget w; +{ + GetPixmaps((LEDWidget)w); + return; +} + +/* + * Set specified arguments into widget + */ + +static Boolean +SetValues(current, request, new, args, num_args) + Widget current, request, 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 != curlw->core.width + || curlw->core.height != curlw->core.height) { + GetPixmaps(newlw); + changed= TRUE; + } + 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 (XtWindow(newlw)!=None) + XSetWindowBackgroundPixmap(XtDisplay(newlw),XtWindow(newlw),pix); + changed= TRUE; + } + return changed; +} + +static void +Destroy(w) + Widget 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.off_pixmap!=None) { + XFreePixmap(XtDisplay(w),lw->led.off_pixmap); + lw->led.off_pixmap= None; + } + return; +} + + +static XtGeometryResult QueryGeometry(w, intended, preferred) + Widget w; + XtWidgetGeometry *intended, *preferred; +{ + 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; + else if (preferred->width == w->core.width && + preferred->height == w->core.height) + return XtGeometryNo; + else + return XtGeometryAlmost; +} @@ -0,0 +1,97 @@ +/* $Xorg: LED.h,v 1.3 2000/08/17 19:54:51 cpqbld Exp $ */ +/************************************************************ + Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. + + Permission to use, copy, modify, and distribute this + software and its documentation for any purpose and without + fee is hereby granted, provided that the above copyright + notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting + documentation, and that the name of Silicon Graphics not be + used in advertising or publicity pertaining to distribution + of the software without specific prior written permission. + Silicon Graphics makes no representation about the suitability + of this software for any purpose. It is provided "as is" + without any express or implied warranty. + + SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH + THE USE OR PERFORMANCE OF THIS SOFTWARE. + + ********************************************************/ +#ifndef _XawLED_h +#define _XawLED_h + +#include <X11/Xaw/Simple.h> + +/* Resources: + + Name Class RepType Default Value + ---- ----- ------- ------------- + background Background Pixel XtDefaultBackground + bevel Bevel Dimension 1 + bitmap Pixmap Pixmap None + border BorderColor Pixel XtDefaultForeground + borderWidth BorderWidth Dimension 1 + bottomColor BottomColor Pixel "White" + cursor Cursor Cursor None + cursorName Cursor String NULL + destroyCallback Callback XtCallbackList NULL + foreground Foreground Pixel XtDefaultForeground + height Height Dimension 10 + insensitiveBorder Insensitive Pixmap Gray + ledWidth ledWidth Dimension 6 + ledHeight ledHeight Dimension 12 + mappedWhenManaged MappedWhenManaged Boolean True + offColor OffColor Pixel #001000 + on On Boolean False + onColor OnColor Pixel Green + pointerColor Foreground Pixel XtDefaultForeground + pointerColorBackground Background Pixel XtDefaultBackground + resize Resize Boolean False + sensitive Sensitive Boolean False + topColor TopColor Pixel "black" + width Width Dimension 6 + x Position Position 0 + y Position Position 0 + +*/ + +#define XtNbevel "bevel" +#define XtNon "on" +#define XtNonColor "onColor" +#define XtNoffColor "offColor" +#define XtNtopColor "topColor" +#define XtNbottomColor "bottomColor" +#define XtNledWidth "ledWidth" +#define XtNledHeight "ledHeight" +#define XtCBevel "Bevel" +#define XtCOn "On" +#define XtCOnColor "OnColor" +#define XtCOffColor "OffColor" +#define XtCTopColor "TopColor" +#define XtCBottomColor "BottomColor" +#define XtCLedWidth "LedWidth" +#define XtCLedHeight "LedHeight" + +#ifndef _XtStringDefs_h_ +#define XtNbitmap "bitmap" +#define XtNforeground "foreground" +#define XtNresize "resize" +#define XtCResize "Resize" +#define XtCBitmap "Bitmap" +#endif + +/* Class record constants */ + +extern WidgetClass ledWidgetClass; + +typedef struct _LEDClassRec *LEDWidgetClass; +typedef struct _LEDRec *LEDWidget; + +#endif /* _XawLED_h */ @@ -0,0 +1,76 @@ +/* $Xorg: LEDP.h,v 1.3 2000/08/17 19:54:51 cpqbld Exp $ */ +/************************************************************ + Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. + + Permission to use, copy, modify, and distribute this + software and its documentation for any purpose and without + fee is hereby granted, provided that the above copyright + notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting + documentation, and that the name of Silicon Graphics not be + used in advertising or publicity pertaining to distribution + of the software without specific prior written permission. + Silicon Graphics makes no representation about the suitability + of this software for any purpose. It is provided "as is" + without any express or implied warranty. + + SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH + THE USE OR PERFORMANCE OF THIS SOFTWARE. + + ********************************************************/ +#ifndef _XawLEDP_h +#define _XawLEDP_h + +#include "LED.h" +#include <X11/Xaw/SimpleP.h> + +/* New fields for the Label widget class record */ + +typedef struct {int foo;} LEDClassPart; + +/* Full class record declaration */ +typedef struct _LEDClassRec { + CoreClassPart core_class; + SimpleClassPart simple_class; + LEDClassPart led_class; +} LEDClassRec; + +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; + + /* private state */ + Pixmap on_pixmap; + Pixmap off_pixmap; +} LEDPart; + +/**************************************************************** + * + * Full instance record declaration + * + ****************************************************************/ + +typedef struct _LEDRec { + CorePart core; + SimplePart simple; + LEDPart led; +} LEDRec; + +#endif /* _XawLEDP_h */ @@ -0,0 +1,368 @@ + + /*\ + * $Xorg: utils.c,v 1.6 2000/08/17 19:54:51 cpqbld Exp $ + * + * 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. + * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE + * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED + * WARRANTY. + * + * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT + * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN + * ADDITION TO THAT SET FORTH ABOVE. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Digital Equipment Corporation not be + * used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + \*/ + +#include "utils.h" +#include <ctype.h> +#ifndef X_NOT_STDC_ENV +#include <stdlib.h> +#else +char *malloc(); +#endif + +/***====================================================================***/ + +Opaque +uAlloc(size) + unsigned size; +{ + return((Opaque)malloc(size)); +} + +/***====================================================================***/ + +Opaque +uCalloc(n,size) + unsigned n; + unsigned size; +{ + return((Opaque)calloc(n,size)); +} + +/***====================================================================***/ + +Opaque +uRealloc(old,newSize) + Opaque old; + unsigned newSize; +{ + if (old==NULL) + return((Opaque)malloc(newSize)); + else return((Opaque)realloc((char *)old,newSize)); +} + +/***====================================================================***/ + +Opaque +uRecalloc(old,nOld,nNew,itemSize) + Opaque old; + unsigned nOld; + unsigned nNew; + unsigned itemSize; +{ +char *rtrn; + + 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); + } + } + return (Opaque)rtrn; +} + +/***====================================================================***/ + +void +uFree(ptr) + Opaque ptr; +{ + if (ptr!=(Opaque)NULL) + free((char *)ptr); + return; +} + +/***====================================================================***/ +/*** FUNCTION ENTRY TRACKING ***/ +/***====================================================================***/ + +static FILE *entryFile= stderr; + int uEntryLevel; + +Boolean +uSetEntryFile(name) + char *name; +{ + 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); + } + return(True); +} + +void +uEntry(l,s,a1,a2,a3,a4,a5,a6,a7,a8) +int l; +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ +int i; + + for (i=0;i<uEntryLevel;i++) { + putc(' ',entryFile); + } + fprintf(entryFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + uEntryLevel+= l; + return; +} + +void +uExit(l,rtVal) + int l; + char * rtVal; +{ +int i; + + uEntryLevel-= l; + if (uEntryLevel<0) uEntryLevel= 0; + for (i=0;i<uEntryLevel;i++) { + putc(' ',entryFile); + } + fprintf(entryFile,"---> 0x%p\n",rtVal); + return; +} + +/***====================================================================***/ +/*** PRINT FUNCTIONS ***/ +/***====================================================================***/ + + FILE *uDebugFile= stderr; + int uDebugIndentLevel= 0; + int uDebugIndentSize= 4; + +Boolean +uSetDebugFile(name) + char *name; +{ + 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); + } + return(True); +} + +void +uDebug(s,a1,a2,a3,a4,a5,a6,a7,a8) +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ +int i; + + for (i=(uDebugIndentLevel*uDebugIndentSize);i>0;i--) { + putc(' ',uDebugFile); + } + fprintf(uDebugFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + fflush(uDebugFile); + return; +} + +void +uDebugNOI(s,a1,a2,a3,a4,a5,a6,a7,a8) +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ + fprintf(uDebugFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + fflush(uDebugFile); + return; +} + +/***====================================================================***/ + +static FILE *errorFile= stderr; + +Boolean +uSetErrorFile(name) + char *name; +{ + 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); + } + return(True); +} + +void +uInformation(s,a1,a2,a3,a4,a5,a6,a7,a8) +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ + fprintf(errorFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + fflush(errorFile); + return; +} + +/***====================================================================***/ + +void +uAction(s,a1,a2,a3,a4,a5,a6,a7,a8) +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ + fprintf(errorFile," "); + fprintf(errorFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + fflush(errorFile); + return; +} + +/***====================================================================***/ + +void +uWarning(s,a1,a2,a3,a4,a5,a6,a7,a8) +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ + fprintf(errorFile,"Warning: "); + fprintf(errorFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + fflush(errorFile); + return; +} + +/***====================================================================***/ + +void +uError(s,a1,a2,a3,a4,a5,a6,a7,a8) +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ + fprintf(errorFile,"Error: "); + fprintf(errorFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + fflush(errorFile); + return; +} + +/***====================================================================***/ + +void +uFatalError(s,a1,a2,a3,a4,a5,a6,a7,a8) +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ + fprintf(errorFile,"Fatal Error: "); + fprintf(errorFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + fprintf(errorFile," Exiting\n"); + fflush(errorFile); + exit(1); + /* NOTREACHED */ +} + +/***====================================================================***/ + +void +uInternalError(s,a1,a2,a3,a4,a5,a6,a7,a8) +char *s; +Opaque a1,a2,a3,a4,a5,a6,a7,a8; +{ + fprintf(errorFile,"Internal error: "); + fprintf(errorFile,s,a1,a2,a3,a4,a5,a6,a7,a8); + fflush(errorFile); + return; +} + +/***====================================================================***/ + +#ifndef HAVE_STRDUP +char * +uStringDup(str) + char *str; +{ +char *rtrn; + + if (str==NULL) + return NULL; + rtrn= (char *)uAlloc(strlen(str)+1); + strcpy(rtrn,str); + return rtrn; +} +#endif + +#ifndef HAVE_STRCASECMP +int +uStrCaseCmp(str1, str2) + char *str1, *str2; +{ + 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; + } + *s = '\0'; + 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)); +} + +int +uStrCasePrefix(prefix, str) + char *prefix, *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++; + } + if (c1!='\0') + return 0; + return 1; +} + +#endif @@ -0,0 +1,307 @@ +#ifndef UTILS_H +#define UTILS_H 1 + + /*\ + * $Xorg: utils.h,v 1.3 2000/08/17 19:54:51 cpqbld Exp $ + * + * 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. + * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE + * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED + * WARRANTY. + * + * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT + * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN + * ADDITION TO THAT SET FORTH ABOVE. + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, provided + * that the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Digital Equipment Corporation not be + * used in advertising or publicity pertaining to distribution of the + * software without specific, written prior permission. + \*/ + +/***====================================================================***/ + +#include <stdio.h> +#include <X11/Xos.h> +#include <X11/Xfuncproto.h> +#include <X11/Xfuncs.h> + +_XFUNCPROTOBEGIN + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef NUL +#define NUL '\0' +#endif + +/***====================================================================***/ + +#ifndef OPAQUE_DEFINED +typedef void *Opaque; +#endif +#ifndef NullOpaque +#define NullOpaque ((Opaque)NULL) +#endif + +#ifndef BOOLEAN_DEFINED +typedef char Boolean; +#endif + +#ifndef True +#define True ((Boolean)1) +#define False ((Boolean)0) +#endif /* ndef True */ +#define booleanText(b) ((b)?"True":"False") + +#ifndef COMPARISON_DEFINED +typedef int Comparison; + +#define Greater ((Comparison)1) +#define Equal ((Comparison)0) +#define Less ((Comparison)-1) +#define CannotCompare ((Comparison)-37) +#define comparisonText(c) ((c)?((c)<0?"Less":"Greater"):"Equal") +#endif + +typedef union { + int i; + unsigned u; + void *p; + void *(*fp)(); +} Union; + +/***====================================================================***/ + +extern Opaque uAlloc( +#if NeedFunctionPrototypes + unsigned /* size */ +#endif +); +extern Opaque uCalloc( +#if NeedFunctionPrototypes + unsigned /* n */, + unsigned /* size */ +#endif +); +extern Opaque uRealloc( +#if NeedFunctionPrototypes + Opaque /* old */, + unsigned /* newSize */ +#endif +); +extern Opaque uRecalloc( +#if NeedFunctionPrototypes + Opaque /* old */, + unsigned /* nOld */, + unsigned /* nNew */, + unsigned /* newSize */ +#endif +); +extern void uFree( +#if NeedFunctionPrototypes + Opaque /* ptr */ +#endif +); + +#define uTypedAlloc(t) ((t *)uAlloc((unsigned)sizeof(t))) +#define uTypedCalloc(n,t) ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t))) +#define uTypedRealloc(pO,n,t) ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t))) +#define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t))) +#if (defined mdHasAlloca) && (mdHasAlloca) +#define uTmpAlloc(n) ((Opaque)alloca((unsigned)n)) +#define uTmpFree(p) +#else +#define uTmpAlloc(n) uAlloc(n) +#define uTmpFree(p) uFree(p) +#endif + +/***====================================================================***/ + +extern Boolean uSetErrorFile( +#if NeedFunctionPrototypes + char * /* name */ +#endif +); +extern void uInformation(); +extern void uAction(); +extern void uWarning(); +extern void uError(); +extern void uFatalError(); +extern void uInternalError(); + +/***====================================================================***/ + +#define NullString ((char *)NULL) + +#define uStringText(s) ((s)==NullString?"<NullString>":(s)) +#define uStringEqual(s1,s2) (uStringCompare(s1,s2)==Equal) +#define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0) +#define uStringCompare(s1,s2) (strcmp(s1,s2)) +#define uStrCaseEqual(s1,s2) (uStrCaseCmp(s1,s2)==0) +#ifdef HAVE_STRCASECMP +#define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2)) +#define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0) +#else +extern int uStrCaseCmp( +#if NeedFunctionPrototypes + char * /* s1 */, + char * /* s2 */ +#endif +); +extern int uStrCasePrefix( +#if NeedFunctionPrototypes + char * /* p */, + char * /* str */ +#endif +); +#endif +#ifdef HAVE_STRDUP +#define uStringDup(s1) (strdup(s1)) +#else +extern char *uStringDup( +#if NeedFunctionPrototypes + char * /* s1 */ +#endif +); +#endif + +/***====================================================================***/ + +#ifdef ASSERTIONS_ON +#define uASSERT(where,why) \ + {if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);} +#else +#define uASSERT(where,why) +#endif + +/***====================================================================***/ + +#ifndef DEBUG_VAR +#define DEBUG_VAR debugFlags +#endif + +#ifdef DEBUG_VAR_NOT_LOCAL +extern +#endif +unsigned int DEBUG_VAR; + +extern void uDebug(); +extern void uDebugNOI(); /* no indent */ +extern Boolean uSetDebugFile( +#if NeedFunctionPrototypes + char *name +#endif +); +extern FILE *uDebugFile; +extern int uDebugIndentLevel; +extern int uDebugIndentSize; +#define uDebugIndent(l) (uDebugIndentLevel+=(l)) +#define uDebugOutdent(l) (uDebugIndentLevel-=(l)) +#ifdef DEBUG_ON +#define uDEBUG(f,s) { if (DEBUG_VAR&(f)) uDebug(s);} +#define uDEBUG1(f,s,a) { if (DEBUG_VAR&(f)) uDebug(s,a);} +#define uDEBUG2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebug(s,a,b);} +#define uDEBUG3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);} +#define uDEBUG4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);} +#define uDEBUG5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);} +#define uDEBUG_NOI(f,s) { if (DEBUG_VAR&(f)) uDebug(s);} +#define uDEBUG_NOI1(f,s,a) { if (DEBUG_VAR&(f)) uDebugNOI(s,a);} +#define uDEBUG_NOI2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);} +#define uDEBUG_NOI3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);} +#define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);} +#define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);} +#else +#define uDEBUG(f,s) +#define uDEBUG1(f,s,a) +#define uDEBUG2(f,s,a,b) +#define uDEBUG3(f,s,a,b,c) +#define uDEBUG4(f,s,a,b,c,d) +#define uDEBUG5(f,s,a,b,c,d,e) +#define uDEBUG_NOI(f,s) +#define uDEBUG_NOI1(f,s,a) +#define uDEBUG_NOI2(f,s,a,b) +#define uDEBUG_NOI3(f,s,a,b,c) +#define uDEBUG_NOI4(f,s,a,b,c,d) +#define uDEBUG_NOI5(f,s,a,b,c,d,e) +#endif + +extern Boolean uSetEntryFile( +#if NeedFunctionPrototypes + char *name +#endif +); +extern void uEntry(); +extern void uExit( +#if NeedFunctionPrototypes + int l,char *rtVal +#endif +); +#ifdef ENTRY_TRACKING_ON +#define ENTRY_BIT 0x10 +#define LOW_ENTRY_BIT 0x1000 +#define ENTER (DEBUG_VAR&ENTRY_BIT) +#define FLAG(fLag) (DEBUG_VAR&(fLag)) + +extern int uEntryLevel; + +#define uENTRY(s) { if (ENTER) uEntry(1,s);} +#define uENTRY1(s,a) { if (ENTER) uEntry(1,s,a);} +#define uENTRY2(s,a,b) { if (ENTER) uEntry(1,s,a,b);} +#define uENTRY3(s,a,b,c) { if (ENTER) uEntry(1,s,a,b,c);} +#define uENTRY4(s,a,b,c,d) { if (ENTER) uEntry(1,s,a,b,c,d);} +#define uENTRY5(s,a,b,c,d,e) { if (ENTER) uEntry(1,s,a,b,c,d,e);} +#define uENTRY6(s,a,b,c,d,e,f) { if (ENTER) uEntry(1,s,a,b,c,d,e,f);} +#define uENTRY7(s,a,b,c,d,e,f,g) { if (ENTER) uEntry(1,s,a,b,c,d,e,f,g);} +#define uRETURN(v) { if (ENTER) uEntryLevel--; return(v); } +#define uVOIDRETURN { if (ENTER) uEntryLevel--; return; } + +#define uFLAG_ENTRY(w,s) { if (FLAG(w)) uEntry(0,s);} +#define uFLAG_ENTRY1(w,s,a) { if (FLAG(w)) uEntry(0,s,a);} +#define uFLAG_ENTRY2(w,s,a,b) { if (FLAG(w)) uEntry(0,s,a,b);} +#define uFLAG_ENTRY3(w,s,a,b,c) { if (FLAG(w)) uEntry(0,s,a,b,c);} +#define uFLAG_ENTRY4(w,s,a,b,c,d) { if (FLAG(w)) uEntry(0,s,a,b,c,d);} +#define uFLAG_ENTRY5(w,s,a,b,c,d,e) { if (FLAG(w)) uEntry(0,s,a,b,c,d,e);} +#define uFLAG_ENTRY6(w,s,a,b,c,d,e,f) { if (FLAG(w)) uEntry(0,s,a,b,c,d,e,f);} +#define uFLAG_ENTRY7(w,s,a,b,c,d,e,f,g) { if(FLAG(w))uEntry(0,s,a,b,c,d,e,f,g);} +#define uFLAG_RETURN(v) { return(v);} +#define uFLAG_VOIDRETURN { return; } +#else +#define uENTRY(s) +#define uENTRY1(s,a) +#define uENTRY2(s,a1,a2) +#define uENTRY3(s,a1,a2,a3) +#define uENTRY4(s,a1,a2,a3,a4) +#define uENTRY5(s,a1,a2,a3,a4,a5) +#define uENTRY6(s,a1,a2,a3,a4,a5,a6) +#define uENTRY7(s,a1,a2,a3,a4,a5,a6,a7) +#define uRETURN(v) { return(v); } +#define uVOIDRETURN { return; } + +#define uFLAG_ENTRY(f,s) +#define uFLAG_ENTRY1(f,s,a) +#define uFLAG_ENTRY2(f,s,a,b) +#define uFLAG_ENTRY3(f,s,a,b,c) +#define uFLAG_ENTRY4(f,s,a,b,c,d) +#define uFLAG_ENTRY5(f,s,a,b,c,d,e) +#define uFLAG_ENTRY6(f,s,a,b,c,d,e,g) +#define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h) +#define uFLAG_RETURN(v) { return(v);} +#define uFLAG_VOIDRETURN { return; } +#endif + +_XFUNCPROTOEND + +#endif /* UTILS_H */ + + diff --git a/xkbbell.c b/xkbbell.c new file mode 100644 index 0000000..b733ef7 --- /dev/null +++ b/xkbbell.c @@ -0,0 +1,225 @@ +/* $Xorg: xkbbell.c,v 1.4 2000/08/17 19:54:51 cpqbld Exp $ */ +/************************************************************ +Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc. + +Permission to use, copy, modify, and distribute this +software and its documentation for any purpose and without +fee is hereby granted, provided that the above copyright +notice appear in all copies and that both that copyright +notice and this permission notice appear in supporting +documentation, and that the name of Silicon Graphics not be +used in advertising or publicity pertaining to distribution +of the software without specific prior written permission. +Silicon Graphics makes no representation about the suitability +of this software for any purpose. It is provided "as is" +without any express or implied warranty. + +SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS +SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON +GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL +DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, +DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE +OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH +THE USE OR PERFORMANCE OF THIS SOFTWARE. + +********************************************************/ + +#include <stdio.h> +#include <X11/Xproto.h> +#include <X11/Xlib.h> +#include <X11/X.h> +#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; + +int +parseArgs(argc,argv) + int argc; + char *argv[]; +{ +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]; + } + } + return 1; +} + +int +main(argc,argv) + int argc; + char *argv[]; +{ +Display *dpy; +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 (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"); + } + 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!='\0') + 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"); + } +BAIL: + XCloseDisplay(dpy); + return 0; +} diff --git a/xkbvleds.c b/xkbvleds.c new file mode 100644 index 0000000..afe07a8 --- /dev/null +++ b/xkbvleds.c @@ -0,0 +1,362 @@ +/* $Xorg: xkbvleds.c,v 1.4 2000/08/17 19:54:51 cpqbld Exp $ */ +/************************************************************ + Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. + + Permission to use, copy, modify, and distribute this + software and its documentation for any purpose and without + fee is hereby granted, provided that the above copyright + notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting + documentation, and that the name of Silicon Graphics not be + used in advertising or publicity pertaining to distribution + of the software without specific prior written permission. + Silicon Graphics makes no representation about the suitability + of this software for any purpose. It is provided "as is" + without any express or implied warranty. + + SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH + THE USE OR PERFORMANCE OF THIS SOFTWARE. + + ********************************************************/ + +#include <X11/X.h> +#include <X11/Xlib.h> +#include <X11/XKBlib.h> +#include <X11/Intrinsic.h> +#include <X11/StringDefs.h> +#include <X11/Shell.h> +#include <X11/Xaw/Cardinals.h> +#include <X11/Xaw/Box.h> + +#define OPAQUE_DEFINED +#define BOOLEAN_DEFINED +#define DEBUG_VAR_NOT_LOCAL +#define DEBUG_VAR debugFlags +#include "utils.h" +#include "LED.h" + +/***====================================================================***/ + +#define YES 1 +#define NO 0 +#define DONT_CARE -1 + + Display * inDpy,*outDpy; +static unsigned long wanted,real,named,explicit,automatic,virtual; +static char * inDpyName; + int wantNamed= DONT_CARE; + int wantExplicit= DONT_CARE; + int wantAutomatic= DONT_CARE; + int wantReal= DONT_CARE; + int wantVirtual= DONT_CARE; + int evBase,errBase; + Bool synch; + Bool useUnion= True; + +/***====================================================================***/ + +static void +usage(program) + char * 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"); + uInformation(" -watch <leds> Mask of LEDs to watch\n"); + uInformation(" [-+]automatic (Don't) watch automatic LEDs\n"); + uInformation(" [-+]explicit (Don't) watch explicit LEDs\n"); + uInformation(" [-+]name (Don't) watch named LEDs\n"); + uInformation(" [-+]real (Don't) watch real LEDs\n"); + uInformation(" [-+]virtual (Don't) watch virtual LEDs\n"); + uInformation(" -intersection Watch only LEDs in all desired sets\n"); + uInformation(" -union Watch LEDs in any desired sets\n"); + uInformation("The default set of LEDs is -union +name +automatic +real\n"); + return; +} + +static Bool +parseArgs(argc,argv) + int argc; + char * argv[]; +{ +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); + } + } + } + return True; +} + +/***====================================================================***/ + +Display * +GetDisplay(program,dpyName) + char * program; + char * dpyName; +{ +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); + } + } + else if (synch) + XSynchronize(dpy,True); + return dpy; +} + +/***====================================================================***/ + +int +main(argc,argv) + 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 +}; + + 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); + 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; + } + + 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); + } + } + 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); + } +BAIL: + if (inDpy) + XCloseDisplay(inDpy); + if (outDpy!=inDpy) + XCloseDisplay(outDpy); + inDpy= outDpy= NULL; + return 0; +} diff --git a/xkbwatch.c b/xkbwatch.c new file mode 100644 index 0000000..01aa73e --- /dev/null +++ b/xkbwatch.c @@ -0,0 +1,283 @@ +/* $Xorg: xkbwatch.c,v 1.4 2000/08/17 19:54:51 cpqbld Exp $ */ +/************************************************************ + Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. + + Permission to use, copy, modify, and distribute this + software and its documentation for any purpose and without + fee is hereby granted, provided that the above copyright + notice appear in all copies and that both that copyright + notice and this permission notice appear in supporting + documentation, and that the name of Silicon Graphics not be + used in advertising or publicity pertaining to distribution + of the software without specific prior written permission. + Silicon Graphics makes no representation about the suitability + of this software for any purpose. It is provided "as is" + without any express or implied warranty. + + SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS + SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL + DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, + DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE + OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH + THE USE OR PERFORMANCE OF THIS SOFTWARE. + + ********************************************************/ + +#include <X11/X.h> +#include <X11/Xlib.h> +#include <X11/XKBlib.h> +#include <X11/Intrinsic.h> +#include <X11/StringDefs.h> +#include <X11/Shell.h> +#include <X11/Xaw/Cardinals.h> +#include <X11/Xaw/Box.h> + +#define OPAQUE_DEFINED +#define BOOLEAN_DEFINED +#define DEBUG_VAR_NOT_LOCAL +#define DEBUG_VAR debugFlags +#include "utils.h" +#include "LED.h" + +/***====================================================================***/ + + Display * inDpy,*outDpy; +static unsigned long wanted= 0xff; + int evBase,errBase; + Bool synch; + +/***====================================================================***/ + +struct _resource { + char * inDpyName; +}; + +#define offset(field) XtOffsetOf(struct _resource, field) +static XtResource app_resources[] = { + {"inputDisplay", "InputDisplay", XtRString, sizeof(char *), + offset(inDpyName), XtRString, NULL } +}; +#undef offset + +static XrmOptionDescRec options[] = { +{"-off", "*on.on", XrmoptionNoArg, "FALSE"}, +{"-on", "*on.on", XrmoptionNoArg, "TRUE"} +}; + +/***====================================================================***/ + +Display * +GetDisplay(program,dpyName) + char * program; + char * dpyName; +{ +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); + } + } + else if (synch) + XSynchronize(dpy,True); + return dpy; +} + +/***====================================================================***/ + +int +main(argc,argv) + 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 +}; + + 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); + } + 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); + } + } + 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); + } + 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); + } +BAIL: + if (inDpy) + XCloseDisplay(inDpy); + if (outDpy!=inDpy) + XCloseDisplay(outDpy); + inDpy= outDpy= NULL; + return 0; +} |