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 */
28 #include <libdockapp/dockapp.h>
30 #include "include/kleds.h"
31 #include "graphics/caps_num_scroll.xpm"
34 void cnslock_init(void);
35 void cnslock_update(void);
41 /* the main routine */
42 int main(int argc
, char **argv
)
44 DACallbacks eventCallbacks
= {NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
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
);
61 void cnslock_init(void)
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();
73 XCopyArea(DADisplay
, led_pix
, win_pix
, DAGC
,
76 XCopyArea(DADisplay
, led_pix
, win_pix
, DAGC
,
77 32, 13, 15, 20, 32, 13);
79 XCopyArea(DADisplay
, led_pix
, win_pix
, DAGC
,
80 8, 38, 40, 10, 8, 38);
84 /* update caps, num, scroll lock */
85 void cnslock_update(void)
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
,
98 XFillRectangle(DADisplay
, win_pix
, DAGC
, 9, 9, 20, 26);
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);
106 XFillRectangle(DADisplay
, win_pix
, DAGC
,
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);
115 XFillRectangle(DADisplay
, win_pix
, DAGC
, 8, 38, 40, 10);
120 DASetPixmap(win_pix
);