]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/xserver.git/blob - hw/dmx/examples/xled.c
Imported Upstream version 1.11.4
[glsdk/xserver.git] / hw / dmx / examples / xled.c
1 /*
2  * Copyright 2003 Red Hat Inc., Durham, North Carolina.
3  *
4  * All Rights Reserved.
5  *
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:
13  *
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.
17  *
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
25  * SOFTWARE.
26  */
28 /*
29  * Authors:
30  *   Rickard E. (Rik) Faith <faith@redhat.com>
31  *
32  */
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <X11/Xlib.h>
38 #include <X11/XKBlib.h>
39 #include <X11/extensions/XKB.h>
40 #include <X11/extensions/XKBstr.h>
41 #include <sys/time.h>
43 int main(int argc, char **argv)
44 {
45     Display              *display = NULL;
46     int                  mask     = 0;
47     unsigned             i;
48     XKeyboardState       ks;
49     XKeyboardControl     kc;
50     XkbDescPtr           xkb;
51     int                  old[32];
53     if (argc == 2 || argc == 3) {
54         if (!(display = XOpenDisplay(argv[1]))) {
55             printf("Cannot open display %s\n", argv[1]);
56             return -1;
57         }
58         if (argc >= 3) mask = strtol(argv[2], NULL, 0);
59     } else {
60         printf("Usage: %s display [mask]\n", argv[0]);
61         return -1;
62     }
64     if (!display && !(display = XOpenDisplay(NULL))) {
65         printf("Cannot open default display\n");
66         return -1;
67     }
69     if (!(xkb = XkbAllocKeyboard())) {
70         printf("Cannot allocate\n");
71         return -1;
72     }
73     if (XkbGetIndicatorMap(display, XkbAllIndicatorsMask, xkb)) {
74         printf("Cannot Get Indicators\n");
75         return -1;
76     }
77     if (XkbGetNames(display, XkbAllNamesMask, xkb)) {
78         printf("Cannot Get Names\n");
79         return -1;
80     }
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;
86         }
87     }
88     printf("XkbSetIndicatorMap = %d\n", XkbSetIndicatorMap(display, ~0, xkb));
89     XkbFreeKeyboard(xkb, 0, True);
91     
92     if (!(xkb = XkbAllocKeyboard())) {
93         printf("Cannot allocate\n");
94         return -1;
95     }
96     if (XkbGetIndicatorMap(display, XkbAllIndicatorsMask, xkb)) {
97         printf("Cannot Get Indicators\n");
98         return -1;
99     }
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);
103     }
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++) {
108         kc.led      = i + 1;
109         kc.led_mode = (mask & (1 << i)) ? LedModeOn : LedModeOff;
110         printf("XChangeKeyboardControl = %d\n",
111                XChangeKeyboardControl(display, KBLed | KBLedMode, &kc));
112     }
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);
123     return 0;