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.
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.
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.
26
********************************************************/
27
/* $XFree86: xc/programs/xkbutils/xkbwatch.c,v 3.5 2001/04/01 14:00:22 tsi Exp $ */
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>
39
#define OPAQUE_DEFINED
40
#define BOOLEAN_DEFINED
41
#define DEBUG_VAR_NOT_LOCAL
42
#define DEBUG_VAR debugFlags
46
/***====================================================================***/
48
Display * inDpy,*outDpy;
52
/***====================================================================***/
55
static XrmOptionDescRec options[] = {
56
{"-off", "*on.on", XrmoptionNoArg, "FALSE"},
57
{"-on", "*on.on", XrmoptionNoArg, "TRUE"}
60
/***====================================================================***/
63
main(int argc, char *argv[])
68
Widget base[XkbNumModifiers];
69
Widget latched[XkbNumModifiers];
70
Widget locked[XkbNumModifiers];
71
Widget effective[XkbNumModifiers];
72
Widget compat[XkbNumModifiers];
73
Widget baseBox,latchBox,lockBox,effBox,compatBox;
78
static Arg hArgs[]= {{ XtNorientation, (XtArgVal)XtorientHorizontal }};
79
static Arg vArgs[]= {{ XtNorientation, (XtArgVal)XtorientVertical }};
80
static Arg onArgs[]= {{ XtNon, (XtArgVal)True }};
81
static Arg offArgs[]= {{ XtNon, (XtArgVal)False }};
82
static char * fallback_resources[] = {
83
"*Box*background: grey50",
84
"*Box*borderWidth: 0",
89
uSetEntryFile(NullString);
90
uSetDebugFile(NullString);
91
uSetErrorFile(NullString);
92
toplevel = XtOpenApplication(&app_con, "XkbWatch",
93
options, XtNumber(options), &argc, argv,
95
sessionShellWidgetClass, NULL, ZERO);
97
uFatalError("Couldn't create application top level\n");
100
inDpy= outDpy= XtDisplay(toplevel);
105
if (!XkbQueryExtension(inDpy,&i1,&evBase,&errBase,&mj,&mn)) {
106
uFatalError("Server doesn't support a compatible XKB\n");
110
panel= XtCreateManagedWidget("xkbwatch",boxWidgetClass,toplevel,vArgs,1);
112
uFatalError("Couldn't create top level box\n");
115
baseBox= XtCreateManagedWidget("base",boxWidgetClass,panel,hArgs,1);
117
uFatalError("Couldn't create base modifiers box\n");
118
latchBox= XtCreateManagedWidget("latched",boxWidgetClass,panel,hArgs,1);
120
uFatalError("Couldn't create latched modifiers box\n");
121
lockBox= XtCreateManagedWidget("locked",boxWidgetClass,panel,hArgs,1);
123
uFatalError("Couldn't create locked modifiers box\n");
124
effBox= XtCreateManagedWidget("effective",boxWidgetClass,panel,hArgs,1);
126
uFatalError("Couldn't create effective modifiers box\n");
127
compatBox= XtCreateManagedWidget("compat",boxWidgetClass,panel,hArgs,1);
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) {
135
sprintf(buf,"base%d",i);
136
if (state.base_mods&bit) list= onArgs;
138
base[i]= XtCreateManagedWidget(buf,ledWidgetClass,baseBox,list,1);
139
sprintf(buf,"latched%d",i);
140
if (state.latched_mods&bit) list= onArgs;
142
latched[i]= XtCreateManagedWidget(buf,ledWidgetClass,latchBox,list,1);
143
sprintf(buf,"locked%d",i);
144
if (state.locked_mods&bit) list= onArgs;
146
locked[i]= XtCreateManagedWidget(buf,ledWidgetClass,lockBox,list,1);
147
sprintf(buf,"effective%d",i);
148
if (state.mods&bit) list= onArgs;
150
effective[i]= XtCreateManagedWidget(buf,ledWidgetClass,effBox,list,1);
151
sprintf(buf,"compat%d",i);
152
if (state.compat_state&bit) list= onArgs;
154
compat[i]= XtCreateManagedWidget(buf,ledWidgetClass,compatBox,list,1);
156
XtRealizeWidget(toplevel);
158
XtAppNextEvent(app_con,&ev.core);
159
if (ev.core.type==evBase+XkbEventCode) {
160
if (ev.any.xkb_type==XkbStateNotify) {
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) {
168
if (state.base_mods&bit) list= onArgs;
170
XtSetValues(base[i],list,1);
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) {
180
if (state.latched_mods&bit) list= onArgs;
182
XtSetValues(latched[i],list,1);
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) {
192
if (state.locked_mods&bit) list= onArgs;
194
XtSetValues(locked[i],list,1);
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) {
204
if (state.mods&bit) list= onArgs;
206
XtSetValues(effective[i],list,1);
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) {
216
if (state.compat_state&bit) list= onArgs;
218
XtSetValues(compat[i],list,1);
224
else XtDispatchEvent(&ev.core);
228
XCloseDisplay(inDpy);
230
XCloseDisplay(outDpy);