wmail: removed superfluous continue.
[dockapps.git] / cnslock / cnslock.c
blobdf30fbac2a4abcb5950451b9a259837811e9865a
1 /* cnslock
2 * Copyright (C) 2002 Simon Hunter (lists@sprig.dyn.dhs.org)
3 * Copyright (C) 2017 Window Maker Team (wmaker-dev@googlegroups.com)
5 * cnslock is a dock application that displays the current state of the
6 * three lock keys (caps, num, and scroll)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have receive a copy of the GNU General Public License along with
19 * this program; if you still want it, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Hacked from various wm applets.
26 /* general includes */
27 #include <X11/Xlib.h>
28 #include <libdockapp/dockapp.h>
30 #include "include/kleds.h"
31 #include "graphics/caps_num_scroll.xpm"
33 /* stuff */
34 void cnslock_init(void);
35 void cnslock_update(void);
37 /* globals */
38 Pixmap led_pix;
39 Pixmap win_pix;
41 /* the main routine */
42 int main(int argc, char **argv)
44 DACallbacks eventCallbacks = {NULL, NULL, NULL, NULL, NULL, NULL,
45 cnslock_update};
47 DAParseArguments(argc, argv, NULL, 0,
48 "This is an applet that displays the various states of"
49 "the CAPS, NUM and SCROLL\nLOCK keys.",
50 "cnslock applet v" VERSION);
51 DAInitialize(NULL, "cnslock", 56, 56, argc, argv);
52 DASetCallbacks(&eventCallbacks);
53 DASetTimeout(20);
54 cnslock_init();
55 DAShow();
56 DAEventLoop();
58 return 0;
61 void cnslock_init(void)
63 int status;
64 short unsigned int w, h;
66 win_pix = DAMakePixmap();
67 XFillRectangle(DADisplay, win_pix, DAGC, 0, 0, 56, 56);
68 DAMakePixmapFromData(caps_num_scroll_xpm, &led_pix, NULL, &w, &h);
70 status = check_kleds();
72 if (status & 1)
73 XCopyArea(DADisplay, led_pix, win_pix, DAGC,
74 9, 9, 20, 26, 9, 9);
75 if (status & 2)
76 XCopyArea(DADisplay, led_pix, win_pix, DAGC,
77 32, 13, 15, 20, 32, 13);
78 if (status & 3)
79 XCopyArea(DADisplay, led_pix, win_pix, DAGC,
80 8, 38, 40, 10, 8, 38);
81 DASetPixmap(win_pix);
84 /* update caps, num, scroll lock */
85 void cnslock_update(void)
87 static int status;
88 int new_status;
89 int new_pix = 0;
91 new_status = check_kleds();
93 if ((status & 1) != (new_status & 1)) {
94 if ((new_status & 1) == 1)
95 XCopyArea(DADisplay, led_pix, win_pix, DAGC,
96 9, 9, 20, 26, 9, 9);
97 else
98 XFillRectangle(DADisplay, win_pix, DAGC, 9, 9, 20, 26);
99 new_pix = 1;
101 if ((status & 2) != (new_status & 2)) {
102 if ((new_status & 2) == 2)
103 XCopyArea(DADisplay, led_pix, win_pix, DAGC,
104 32, 13, 15, 20, 32, 13);
105 else
106 XFillRectangle(DADisplay, win_pix, DAGC,
107 32, 13, 15, 20);
108 new_pix = 1;
110 if ((status & 4) != (new_status & 4)) {
111 if ((new_status & 4) == 4)
112 XCopyArea(DADisplay, led_pix, win_pix, DAGC,
113 8, 38, 40, 10, 8, 38);
114 else
115 XFillRectangle(DADisplay, win_pix, DAGC, 8, 38, 40, 10);
116 new_pix = 1;
119 if (new_pix)
120 DASetPixmap(win_pix);
121 status = new_status;