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