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>
43 int main(int argc
, char **argv
)
45 Display
*display
= NULL
;
53 if (argc
== 2 || argc
== 3) {
54 if (!(display
= XOpenDisplay(argv
[1]))) {
55 printf("Cannot open display %s\n", argv
[1]);
58 if (argc
>= 3) mask
= strtol(argv
[2], NULL
, 0);
60 printf("Usage: %s display [mask]\n", argv
[0]);
64 if (!display
&& !(display
= XOpenDisplay(NULL
))) {
65 printf("Cannot open default display\n");
69 if (!(xkb
= XkbAllocKeyboard())) {
70 printf("Cannot allocate\n");
73 if (XkbGetIndicatorMap(display
, XkbAllIndicatorsMask
, xkb
)) {
74 printf("Cannot Get Indicators\n");
77 if (XkbGetNames(display
, XkbAllNamesMask
, xkb
)) {
78 printf("Cannot Get Names\n");
81 for (i
= 0; i
< XkbNumIndicators
; i
++) {
82 if (xkb
->indicators
->phys_indicators
& (1 << i
)) {
83 printf("led %d = %d\n", i
, xkb
->indicators
->maps
[i
].flags
);
84 old
[i
] = xkb
->indicators
->maps
[i
].flags
;
85 xkb
->indicators
->maps
[i
].flags
= XkbIM_NoAutomatic
;
88 printf("XkbSetIndicatorMap = %d\n", XkbSetIndicatorMap(display
, ~0, xkb
));
89 XkbFreeKeyboard(xkb
, 0, True
);
92 if (!(xkb
= XkbAllocKeyboard())) {
93 printf("Cannot allocate\n");
96 if (XkbGetIndicatorMap(display
, XkbAllIndicatorsMask
, xkb
)) {
97 printf("Cannot Get Indicators\n");
100 for (i
= 0; i
< XkbNumIndicators
; i
++) {
101 if (xkb
->indicators
->phys_indicators
& (1 << i
))
102 printf("led %d = %d\n", i
, xkb
->indicators
->maps
[i
].flags
);
105 printf("XGetKeyboardControl = %d\n", XGetKeyboardControl(display
, &ks
));
106 printf("old mask = 0x%08lx\n", ks
.led_mask
);
107 for (i
= 0; i
< 5; i
++) {
109 kc
.led_mode
= (mask
& (1 << i
)) ? LedModeOn
: LedModeOff
;
110 printf("XChangeKeyboardControl = %d\n",
111 XChangeKeyboardControl(display
, KBLed
| KBLedMode
, &kc
));
113 printf("XGetKeyboardControl = %d\n", XGetKeyboardControl(display
, &ks
));
114 printf("new mask = 0x%08lx\n", ks
.led_mask
);
116 for (i
= 0; i
< XkbNumIndicators
; i
++)
117 if (xkb
->indicators
->phys_indicators
& (i
<< 1))
118 xkb
->indicators
->maps
[i
].flags
= old
[i
];
119 printf("XkbSetIndicatorMap = %d\n", XkbSetIndicatorMap(display
, ~0, xkb
));
121 XkbFreeKeyboard(xkb
, 0, True
);
122 XCloseDisplay(display
);