4 * (c) 1998-2004 Alexey Vyskubov <alexey@mawhrin.net>
7 #include <stdlib.h> /* malloc() */
8 #include <stdio.h> /* puts() */
10 /* X Window headers */
12 #include <X11/Xutil.h>
15 #include <X11/XKBlib.h>
17 #include <libdockapp/dockapp.h>
29 char *iconboom
= 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
41 DAProgramOption options
[] = {
43 "Icon to show for the 1st Xkb group",
44 DOString
, False
, {&icon1
}},
46 "Icon to show for the 2nd Xkb group",
47 DOString
, False
, {&icon2
}},
49 "Icon to show for the 3rd Xkb group",
50 DOString
, False
, {&icon3
}},
52 "Icon to show for the 4th Xkb group",
53 DOString
, False
, {&icon4
}},
55 "Icon to show when Xkb system goes crazy",
56 DOString
, False
, {&iconboom
}},
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",
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
,
79 sterror("Cannot XkbSelectEvents. It's your problem -- not mine.");
81 } /* Deselect all events */
83 if (False
== XkbSelectEventDetails(DADisplay
,
88 sterror("Cannot XkbSelectEventDetails. It's your problem -- not mine.");
90 } /* Select XkbStateNotify/XkbgroupLock */
92 pixmap
= DAMakePixmap();
94 update_window(pixmap
, DAGC
, state
, DADisplay
);
99 /* HELLO! HELLO! HELLO! Is that our GOOD FRIEND main loop here? */
101 XNextEvent(DADisplay
, &labuda
.core
);
102 switch (labuda
.core
.type
) {
106 switch (labuda
.core
.xbutton
.button
) {
109 puts("Button1 pressed.");
111 XkbLockGroup(DADisplay
,
117 puts("Button2 pressed.");
119 XkbLockGroup(DADisplay
,
125 puts("Button3 pressed, bye.");
127 XFreeGC(DADisplay
, DAGC
);
128 XDestroyWindow(DADisplay
, DAWindow
);
129 XCloseDisplay(DADisplay
);
133 default: /* XkbLockGroup happens : FIXME */
135 state
= labuda
.state
.group
;
137 printf("%u\n", state
);
139 if ((state
< 0) || (state
> 4))
141 update_window(pixmap
, DAGC
, state
, DADisplay
);
145 puts("."); /* XkbLockGroup happens */