xkbwatch.c revision 010cdda0
1/* $Xorg: xkbwatch.c,v 1.4 2000/08/17 19:54:51 cpqbld Exp $ */ 2/************************************************************ 3 Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc. 4 5 Permission to use, copy, modify, and distribute this 6 software and its documentation for any purpose and without 7 fee is hereby granted, provided that the above copyright 8 notice appear in all copies and that both that copyright 9 notice and this permission notice appear in supporting 10 documentation, and that the name of Silicon Graphics not be 11 used in advertising or publicity pertaining to distribution 12 of the software without specific prior written permission. 13 Silicon Graphics makes no representation about the suitability 14 of this software for any purpose. It is provided "as is" 15 without any express or implied warranty. 16 17 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 18 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 19 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 20 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 21 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 22 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 23 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 24 THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 26 ********************************************************/ 27/* $XFree86: xc/programs/xkbutils/xkbwatch.c,v 3.4 2001/01/17 23:46:14 dawes Exp $ */ 28 29#include <stdlib.h> 30#include <X11/X.h> 31#include <X11/Xlib.h> 32#include <X11/XKBlib.h> 33#include <X11/Intrinsic.h> 34#include <X11/StringDefs.h> 35#include <X11/Shell.h> 36#include <X11/Xaw/Cardinals.h> 37#include <X11/Xaw/Box.h> 38 39#define OPAQUE_DEFINED 40#define BOOLEAN_DEFINED 41#define DEBUG_VAR_NOT_LOCAL 42#define DEBUG_VAR debugFlags 43#include "utils.h" 44#include "LED.h" 45 46/***====================================================================***/ 47 48 Display * inDpy,*outDpy; 49 int evBase,errBase; 50 Bool synch; 51 52/***====================================================================***/ 53 54 55static XrmOptionDescRec options[] = { 56{"-off", "*on.on", XrmoptionNoArg, "FALSE"}, 57{"-on", "*on.on", XrmoptionNoArg, "TRUE"} 58}; 59 60/***====================================================================***/ 61 62int 63main(int argc, char *argv[]) 64{ 65Widget toplevel; 66XtAppContext app_con; 67Widget panel; 68Widget base[XkbNumModifiers]; 69Widget latched[XkbNumModifiers]; 70Widget locked[XkbNumModifiers]; 71Widget effective[XkbNumModifiers]; 72Widget compat[XkbNumModifiers]; 73Widget baseBox,latchBox,lockBox,effBox,compatBox; 74register int i; 75unsigned bit; 76XkbEvent ev; 77XkbStateRec state; 78static Arg hArgs[]= {{ XtNorientation, (XtArgVal)XtorientHorizontal }}; 79static Arg vArgs[]= {{ XtNorientation, (XtArgVal)XtorientVertical }}; 80static Arg onArgs[]= {{ XtNon, (XtArgVal)True }}; 81static Arg offArgs[]= {{ XtNon, (XtArgVal)False }}; 82static char * fallback_resources[] = { 83 "*Box*background: grey50", 84 "*Box*borderWidth: 0", 85 "*Box*vSpace: 1", 86 NULL 87}; 88 89 uSetEntryFile(NullString); 90 uSetDebugFile(NullString); 91 uSetErrorFile(NullString); 92 toplevel = XtOpenApplication(&app_con, "XkbWatch", 93 options, XtNumber(options), &argc, argv, 94 fallback_resources, 95 sessionShellWidgetClass, NULL, ZERO); 96 if (toplevel==NULL) { 97 uFatalError("Couldn't create application top level\n"); 98 exit(1); 99 } 100 inDpy= outDpy= XtDisplay(toplevel); 101 if (inDpy) { 102 int i1,mn,mj; 103 mj= XkbMajorVersion; 104 mn= XkbMinorVersion; 105 if (!XkbQueryExtension(inDpy,&i1,&evBase,&errBase,&mj,&mn)) { 106 uFatalError("Server doesn't support a compatible XKB\n"); 107 exit(1); 108 } 109 } 110 panel= XtCreateManagedWidget("xkbwatch",boxWidgetClass,toplevel,vArgs,1); 111 if (panel==NULL) { 112 uFatalError("Couldn't create top level box\n"); 113 exit(1); 114 } 115 baseBox= XtCreateManagedWidget("base",boxWidgetClass,panel,hArgs,1); 116 if (baseBox==NULL) 117 uFatalError("Couldn't create base modifiers box\n"); 118 latchBox= XtCreateManagedWidget("latched",boxWidgetClass,panel,hArgs,1); 119 if (latchBox==NULL) 120 uFatalError("Couldn't create latched modifiers box\n"); 121 lockBox= XtCreateManagedWidget("locked",boxWidgetClass,panel,hArgs,1); 122 if (lockBox==NULL) 123 uFatalError("Couldn't create locked modifiers box\n"); 124 effBox= XtCreateManagedWidget("effective",boxWidgetClass,panel,hArgs,1); 125 if (effBox==NULL) 126 uFatalError("Couldn't create effective modifiers box\n"); 127 compatBox= XtCreateManagedWidget("compat",boxWidgetClass,panel,hArgs,1); 128 if (compatBox==NULL) 129 uFatalError("Couldn't create compatibility state box\n"); 130 XkbSelectEvents(inDpy,XkbUseCoreKbd,XkbStateNotifyMask,XkbStateNotifyMask); 131 XkbGetState(inDpy,XkbUseCoreKbd,&state); 132 for (i=XkbNumModifiers-1,bit=0x80;i>=0;i--,bit>>=1) { 133 ArgList list; 134 char buf[30]; 135 sprintf(buf,"base%d",i); 136 if (state.base_mods&bit) list= onArgs; 137 else list= offArgs; 138 base[i]= XtCreateManagedWidget(buf,ledWidgetClass,baseBox,list,1); 139 sprintf(buf,"latched%d",i); 140 if (state.latched_mods&bit) list= onArgs; 141 else list= offArgs; 142 latched[i]= XtCreateManagedWidget(buf,ledWidgetClass,latchBox,list,1); 143 sprintf(buf,"locked%d",i); 144 if (state.locked_mods&bit) list= onArgs; 145 else list= offArgs; 146 locked[i]= XtCreateManagedWidget(buf,ledWidgetClass,lockBox,list,1); 147 sprintf(buf,"effective%d",i); 148 if (state.mods&bit) list= onArgs; 149 else list= offArgs; 150 effective[i]= XtCreateManagedWidget(buf,ledWidgetClass,effBox,list,1); 151 sprintf(buf,"compat%d",i); 152 if (state.compat_state&bit) list= onArgs; 153 else list= offArgs; 154 compat[i]= XtCreateManagedWidget(buf,ledWidgetClass,compatBox,list,1); 155 } 156 XtRealizeWidget(toplevel); 157 while (1) { 158 XtAppNextEvent(app_con,&ev.core); 159 if (ev.core.type==evBase+XkbEventCode) { 160 if (ev.any.xkb_type==XkbStateNotify) { 161 unsigned changed; 162 if (ev.state.changed&XkbModifierBaseMask) { 163 changed= ev.state.base_mods^state.base_mods; 164 state.base_mods= ev.state.base_mods; 165 for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { 166 if (changed&bit) { 167 ArgList list; 168 if (state.base_mods&bit) list= onArgs; 169 else list= offArgs; 170 XtSetValues(base[i],list,1); 171 } 172 } 173 } 174 if (ev.state.changed&XkbModifierLatchMask) { 175 changed= ev.state.latched_mods^state.latched_mods; 176 state.latched_mods= ev.state.latched_mods; 177 for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { 178 if (changed&bit) { 179 ArgList list; 180 if (state.latched_mods&bit) list= onArgs; 181 else list= offArgs; 182 XtSetValues(latched[i],list,1); 183 } 184 } 185 } 186 if (ev.state.changed&XkbModifierLockMask) { 187 changed= ev.state.locked_mods^state.locked_mods; 188 state.locked_mods= ev.state.locked_mods; 189 for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { 190 if (changed&bit) { 191 ArgList list; 192 if (state.locked_mods&bit) list= onArgs; 193 else list= offArgs; 194 XtSetValues(locked[i],list,1); 195 } 196 } 197 } 198 if (ev.state.changed&XkbModifierStateMask) { 199 changed= ev.state.mods^state.mods; 200 state.mods= ev.state.mods; 201 for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { 202 if (changed&bit) { 203 ArgList list; 204 if (state.mods&bit) list= onArgs; 205 else list= offArgs; 206 XtSetValues(effective[i],list,1); 207 } 208 } 209 } 210 if (ev.state.changed&XkbCompatStateMask) { 211 changed= ev.state.compat_state^state.compat_state; 212 state.compat_state= ev.state.compat_state; 213 for (i=0,bit=1;i<XkbNumModifiers;i++,bit<<=1) { 214 if (changed&bit) { 215 ArgList list; 216 if (state.compat_state&bit) list= onArgs; 217 else list= offArgs; 218 XtSetValues(compat[i],list,1); 219 } 220 } 221 } 222 } 223 } 224 else XtDispatchEvent(&ev.core); 225 } 226/* BAIL: */ 227 if (inDpy) 228 XCloseDisplay(inDpy); 229 if (outDpy!=inDpy) 230 XCloseDisplay(outDpy); 231 inDpy= outDpy= NULL; 232 return 0; 233} 234