wmmoonclock: fix multiple definitions of some global variables.
[dockapps.git] / fookb / fookb.c
blob1aefbff678edea9dac7e4cedf7f09e8b2921fa8e
1 /*
2 * fookb.c
4 * (c) 1998-2004 Alexey Vyskubov <alexey@mawhrin.net>
5 */
7 #include <stdlib.h> /* malloc() */
8 #include <stdio.h> /* puts() */
10 /* X Window headers */
11 #include <X11/Xlib.h>
12 #include <X11/Xutil.h>
14 /* XKB fun */
15 #include <X11/XKBlib.h>
17 #include <libdockapp/dockapp.h>
19 /* My own fun */
20 #include "fookb.h"
21 #include "images.h"
22 #include "sound.h"
23 #include "opts.h"
25 char *icon1 = NULL;
26 char *icon2 = NULL;
27 char *icon3 = NULL;
28 char *icon4 = NULL;
29 char *iconboom = NULL;
30 char *display = NULL;
32 #define sterror(x) (void)printf("Strange error, please report! %s:%d, %s\n",\
33 __FILE__, __LINE__, x)
35 int main(int argc, register char *argv[])
37 XkbEvent labuda; /* Xkb event. X event will be labuda.core */
38 int state = 0; /* We suppose that latin keyboard is the
39 primal state FIXME */
40 Pixmap pixmap;
41 DAProgramOption options[] = {
42 {NULL, "--icon1",
43 "Icon to show for the 1st Xkb group",
44 DOString, False, {&icon1}},
45 {NULL, "--icon2",
46 "Icon to show for the 2nd Xkb group",
47 DOString, False, {&icon2}},
48 {NULL, "--icon3",
49 "Icon to show for the 3rd Xkb group",
50 DOString, False, {&icon3}},
51 {NULL, "--icon4",
52 "Icon to show for the 4th Xkb group",
53 DOString, False, {&icon4}},
54 {NULL, "--iconboom",
55 "Icon to show when Xkb system goes crazy",
56 DOString, False, {&iconboom}},
57 {"-d", "--display",
58 "X display to use (normally not needed)",
59 DOString, False, {&display}},
63 DAParseArguments(argc, argv, options, 6,
64 "XKB state indicator for Window Maker",
65 PACKAGE_STRING);
67 DAOpenDisplay(display, argc, argv);
68 read_images(DADisplay); /* Let's read icon images */
69 DACreateIcon(PACKAGE_NAME, get_width(), get_height(), argc, argv);
70 XSelectInput(DADisplay, DAWindow, ButtonPressMask);
72 /* We would like receive the only Xkb event: XkbStateNotify. And only
73 * when XkbLockGroup happens. */
75 if (False == XkbSelectEvents(DADisplay,
76 XkbUseCoreKbd,
77 XkbAllEventsMask,
78 0)) {
79 sterror("Cannot XkbSelectEvents. It's your problem -- not mine.");
80 exit(EXIT_FAILURE);
81 } /* Deselect all events */
83 if (False == XkbSelectEventDetails(DADisplay,
84 XkbUseCoreKbd,
85 XkbStateNotify,
86 XkbAllEventsMask,
87 XkbGroupLockMask)) {
88 sterror("Cannot XkbSelectEventDetails. It's your problem -- not mine.");
89 exit(EXIT_FAILURE);
90 } /* Select XkbStateNotify/XkbgroupLock */
92 pixmap = DAMakePixmap();
94 update_window(pixmap, DAGC, state, DADisplay);
95 DASetPixmap(pixmap);
97 DAShow();
99 /* HELLO! HELLO! HELLO! Is that our GOOD FRIEND main loop here? */
100 while (1) {
101 XNextEvent(DADisplay, &labuda.core);
102 switch (labuda.core.type) {
104 case ButtonPress:
106 switch (labuda.core.xbutton.button) {
107 case Button1:
108 #ifdef DEBUG
109 puts("Button1 pressed.");
110 #endif
111 XkbLockGroup(DADisplay,
112 XkbUseCoreKbd,
113 (state + 1) % 4);
114 break;
115 case Button2:
116 #ifdef DEBUG
117 puts("Button2 pressed.");
118 #endif
119 XkbLockGroup(DADisplay,
120 XkbUseCoreKbd,
121 (state + 3) % 4);
122 break;
123 case Button3:
124 #ifdef DEBUG
125 puts("Button3 pressed, bye.");
126 #endif
127 XFreeGC(DADisplay, DAGC);
128 XDestroyWindow(DADisplay, DAWindow);
129 XCloseDisplay(DADisplay);
130 exit(0);
132 break;
133 default: /* XkbLockGroup happens : FIXME */
134 drip();
135 state = labuda.state.group;
136 #ifdef DEBUG
137 printf("%u\n", state);
138 #endif
139 if ((state < 0) || (state > 4))
140 state = 4;
141 update_window(pixmap, DAGC, state, DADisplay);
142 DASetPixmap(pixmap);
144 #ifdef DEBUG
145 puts("."); /* XkbLockGroup happens */
146 #endif