Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
10 * fmt consists of uppercase or lowercase 'c' for caps lock and/or 'n' for num
11 * lock, each optionally followed by '?', in the order of indicators desired.
12 * If followed by '?', the letter with case preserved is included in the output
13 * if the corresponding indicator is on. Otherwise, the letter is always
14 * included, lowercase when off and uppercase when on.
17 keyboard_indicators(const char *fmt
)
22 int togglecase
, isset
;
25 if (!(dpy
= XOpenDisplay(NULL
))) {
26 warn("XOpenDisplay: Failed to open display");
29 XGetKeyboardControl(dpy
, &state
);
32 fmtlen
= strnlen(fmt
, 4);
33 for (i
= n
= 0; i
< fmtlen
; i
++) {
34 key
= tolower(fmt
[i
]);
35 if (key
!= 'c' && key
!= 'n') {
38 togglecase
= (i
+ 1 >= fmtlen
|| fmt
[i
+ 1] != '?');
39 isset
= (state
.led_mask
& (1 << (key
== 'n')));
41 buf
[n
++] = isset
? toupper(key
) : key
;