2 * Copyright 2003 Red Hat Inc., Durham, North Carolina.
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation on the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * Rickard E. (Rik) Faith <faith@redhat.com>
38 #include <X11/XKBlib.h>
39 #include <X11/extensions/XKB.h>
40 #include <X11/extensions/XKBstr.h>
44 main(int argc
, char **argv
)
46 Display
*display
= NULL
;
54 if (argc
== 2 || argc
== 3) {
55 if (!(display
= XOpenDisplay(argv
[1]))) {
56 printf("Cannot open display %s\n", argv
[1]);
60 mask
= strtol(argv
[2], NULL
, 0);
63 printf("Usage: %s display [mask]\n", argv
[0]);
67 if (!display
&& !(display
= XOpenDisplay(NULL
))) {
68 printf("Cannot open default display\n");
72 if (!(xkb
= XkbAllocKeyboard())) {
73 printf("Cannot allocate\n");
76 if (XkbGetIndicatorMap(display
, XkbAllIndicatorsMask
, xkb
)) {
77 printf("Cannot Get Indicators\n");
80 if (XkbGetNames(display
, XkbAllNamesMask
, xkb
)) {
81 printf("Cannot Get Names\n");
84 for (i
= 0; i
< XkbNumIndicators
; i
++) {
85 if (xkb
->indicators
->phys_indicators
& (1 << i
)) {
86 printf("led %d = %d\n", i
, xkb
->indicators
->maps
[i
].flags
);
87 old
[i
] = xkb
->indicators
->maps
[i
].flags
;
88 xkb
->indicators
->maps
[i
].flags
= XkbIM_NoAutomatic
;
91 printf("XkbSetIndicatorMap = %d\n", XkbSetIndicatorMap(display
, ~0, xkb
));
92 XkbFreeKeyboard(xkb
, 0, True
);
94 if (!(xkb
= XkbAllocKeyboard())) {
95 printf("Cannot allocate\n");
98 if (XkbGetIndicatorMap(display
, XkbAllIndicatorsMask
, xkb
)) {
99 printf("Cannot Get Indicators\n");
102 for (i
= 0; i
< XkbNumIndicators
; i
++) {
103 if (xkb
->indicators
->phys_indicators
& (1 << i
))
104 printf("led %d = %d\n", i
, xkb
->indicators
->maps
[i
].flags
);
107 printf("XGetKeyboardControl = %d\n", XGetKeyboardControl(display
, &ks
));
108 printf("old mask = 0x%08lx\n", ks
.led_mask
);
109 for (i
= 0; i
< 5; i
++) {
111 kc
.led_mode
= (mask
& (1 << i
)) ? LedModeOn
: LedModeOff
;
112 printf("XChangeKeyboardControl = %d\n",
113 XChangeKeyboardControl(display
, KBLed
| KBLedMode
, &kc
));
115 printf("XGetKeyboardControl = %d\n", XGetKeyboardControl(display
, &ks
));
116 printf("new mask = 0x%08lx\n", ks
.led_mask
);
118 for (i
= 0; i
< XkbNumIndicators
; i
++)
119 if (xkb
->indicators
->phys_indicators
& (i
<< 1))
120 xkb
->indicators
->maps
[i
].flags
= old
[i
];
121 printf("XkbSetIndicatorMap = %d\n", XkbSetIndicatorMap(display
, ~0, xkb
));
123 XkbFreeKeyboard(xkb
, 0, True
);
124 XCloseDisplay(display
);