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 */
27 #include <libdockapp/dockapp.h>
29 #include "include/kleds.h"
30 #include "graphics/caps_num_scroll.xpm"
33 void cnslock_init(void);
34 void cnslock_update(void);
40 /* the main routine */
41 int main(int argc
, char **argv
)
43 DACallbacks eventCallbacks
= {NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
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
);
60 void cnslock_init(void)
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();
72 XCopyArea(DADisplay
, led_pix
, win_pix
, DAGC
,
75 XCopyArea(DADisplay
, led_pix
, win_pix
, DAGC
,
76 32, 13, 15, 20, 32, 13);
78 XCopyArea(DADisplay
, led_pix
, win_pix
, DAGC
,
79 8, 38, 40, 10, 8, 38);
83 /* update caps, num, scroll lock */
84 void cnslock_update(void)
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
,
97 XFillRectangle(DADisplay
, win_pix
, DAGC
, 9, 9, 20, 26);
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);
105 XFillRectangle(DADisplay
, win_pix
, DAGC
,
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);
114 XFillRectangle(DADisplay
, win_pix
, DAGC
, 8, 38, 40, 10);
119 DASetPixmap(win_pix
);