Skip to content

Commit 59adde3

Browse files
committed
chore: fixes and cleanup
1 parent f019701 commit 59adde3

File tree

18 files changed

+142
-58
lines changed

18 files changed

+142
-58
lines changed

.github/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SETTER COMMANDS:
3636
3737
MONITOR COMMANDS:
3838
k, keyboard print global keypresses and keyreleases
39+
l, led print led status
3940
h, help help related to monitor commands
4041
4142
EXAMPLES:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ jobs:
3131
body_path: CHANGELOG.md
3232
draft: false
3333
generate_release_notes: true
34-
files: xcore
34+
files: src/xcore
3535
append_body: true

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
*.o
2-
xcore
1+
src/*.o
2+
src/xcore

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,8 @@ This is an experimental release.
3939
- added `apply.[window_focus|window_activate|center_pointer|window_state]`
4040
- added `monitor.[key_logger]`
4141
- added all `--help|-h|h|help`, `--version|-V` and argument error messages
42+
43+
### Features
44+
45+
- Added monitor option `led`.
46+
- Moved source files to `src` directory.

Makefile

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,23 @@
1-
NAME := xcore
2-
VERCMD ?= git describe --tags 2> /dev/null
3-
VERSION := $(shell $(VERCMD) || cat VERSION)
1+
all:
2+
@make --directory=src
43

5-
CPPFLAGS += -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\"
6-
CFLAGS += -std=c11 --optimize=3 -pedantic -Wall -Wextra -I/usr/include/X11
7-
LDLIBS := -lX11 -lm -lXi
8-
9-
PREFIX ?= /usr/local
10-
BINPREFIX ?= $(PREFIX)/bin
11-
MANPREFIX ?= $(PREFIX)/share/man
12-
13-
SRC := $(wildcard *.c)
14-
OBJ := $(SRC:.c=.o)
15-
DEF := $(wildcard *.h)
16-
17-
all: $(NAME)
18-
19-
install: $(NAME)
20-
mkdir -p "$(DESTDIR)$(BINPREFIX)"
21-
cp -p $(NAME) "$(DESTDIR)$(BINPREFIX)"
4+
install:
5+
@make --directory=src install
226

237
uninstall:
24-
rm -f "$(DESTDIR)$(BINPREFIX)/$(NAME)"
8+
@make --directory=src uninstall
259

26-
debug: build
27-
debug: CFLAGS += -O0 -g
2810
debug:
29-
$(CC) -o $(NAME) $(OBJ) $(CFLAGS) $(LDLIBS)
30-
31-
$(NAME): build
32-
$(CC) -o $(NAME) $(OBJ) $(CFLAGS) $(LDLIBS)
11+
@make --directory=src debug
3312

3413
build:
35-
$(CC) -c $(shell printf "%s\n" $(strip $1) | tac)$(SRC)
14+
@make --directory=src build
3615

3716
doc:
38-
@echo Coming Soon...
17+
@make --directory=src doc
3918

4019
clean:
41-
rm -f $(OBJ) $(NAME)
20+
@make --directory=src clean
4221

4322
format:
44-
clang-format -i $(SRC) $(DEF)
45-
46-
.PHONY: clean format doc build install uninstall debug all
47-
48-
# vim:filetype=make
23+
@make --directory=src format

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.0.2-alpha
1+
v0.0.3-alpha

src/Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
VERCMD ?= git describe --tags 2> /dev/null
2+
VERSION := $(shell $(VERCMD) || cat ../VERSION)
3+
NAME := xcore
4+
5+
CPPFLAGS += -D_POSIX_C_SOURCE=200809L -DVERSION=\"$(VERSION)\"
6+
CFLAGS += -std=c11 --optimize=3 -pedantic -Wall -Wextra -I/usr/include/X11
7+
LDLIBS := -lX11 -lm -lXi
8+
9+
PREFIX ?= /usr/local
10+
BINPREFIX ?= $(PREFIX)/bin
11+
MANPREFIX ?= $(PREFIX)/share/man
12+
13+
SRC := $(wildcard *.c)
14+
OBJ := $(SRC:.c=.o)
15+
DEF := $(wildcard *.h)
16+
17+
all: $(NAME)
18+
19+
install: $(NAME)
20+
mkdir -p "$(DESTDIR)$(BINPREFIX)"
21+
cp -p $(NAME) "$(DESTDIR)$(BINPREFIX)"
22+
23+
uninstall:
24+
rm -f "$(DESTDIR)$(BINPREFIX)/$(NAME)"
25+
26+
debug: build
27+
debug: CFLAGS += -O0 -g
28+
debug:
29+
$(CC) -o $(NAME) $(OBJ) $(CFLAGS) $(LDLIBS)
30+
31+
$(NAME): build
32+
$(CC) -o $(NAME) $(OBJ) $(CFLAGS) $(LDLIBS)
33+
34+
build:
35+
$(CC) -c $(shell printf "%s\n" $(strip $1) | tac)$(SRC)
36+
37+
doc:
38+
@echo Coming Soon...
39+
40+
clean:
41+
rm -f $(OBJ) $(NAME)
42+
43+
format:
44+
clang-format -i $(SRC) $(DEF)
45+
46+
.PHONY: clean format doc build install uninstall debug all
47+
48+
# vim:filetype=make

xcore-colors.h renamed to src/colors.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* xcore-colors.h
1+
/* colors.h
22
*
33
* This is free and unencumbered software released into the public domain.
44
* For more information, please refer to <https://unlicense.org>
File renamed without changes.

xcore-logger.c renamed to src/logger.c

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* xcore-logger.c
1+
/* logger.c
22
*
33
* Copyright 2022 dharmx
44
*
@@ -16,7 +16,8 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
#include "xcore-logger.h"
19+
#include "logger.h"
20+
#define ON_OR_OFF(S) (S ? "on" : "off")
2021

2122
void
2223
init_xinput(dump_t* dump, int version[2]) {
@@ -105,4 +106,47 @@ start_key_logger(char* up, char* down, Bool only_icon, RawKeyPressMode mode) {
105106
}
106107
}
107108

109+
void
110+
display_ind_state(Bool ind_keys[2], int event_state) {
111+
typedef enum {
112+
NO_STATE = 0,
113+
CAPS_LOCK_STATE = 1,
114+
NUM_LOCK_STATE = 2,
115+
BOTH_LOCK_STATE = 3,
116+
} ind_state_t;
117+
118+
switch (event_state) {
119+
case NO_STATE: ind_keys[0] = ind_keys[1] = False; break;
120+
case CAPS_LOCK_STATE: ind_keys[0] = True; break;
121+
case NUM_LOCK_STATE: ind_keys[1] = True; break;
122+
case BOTH_LOCK_STATE: ind_keys[0] = ind_keys[1] = True; break;
123+
}
124+
125+
printf("indicators %s %s\n", ON_OR_OFF(ind_keys[0]), ON_OR_OFF(ind_keys[1]));
126+
fflush(stdout);
127+
}
128+
129+
void
130+
query_led_state(Bool ind_keys[2]) {
131+
unsigned int start_state;
132+
XkbGetIndicatorState(display, XkbUseCoreKbd, &start_state);
133+
if (ind_keys == NULL) {
134+
Bool ind_keys_once[2] = {False, False};
135+
display_ind_state(ind_keys_once, start_state);
136+
} else display_ind_state(ind_keys, start_state);
137+
}
138+
139+
void
140+
start_led_logger(Bool first) {
141+
Bool ind_keys[2] = {False, False};
142+
if (first) query_led_state(ind_keys);
143+
144+
XkbSelectEvents(display, XkbUseCoreKbd, XkbIndicatorStateNotifyMask, XkbIndicatorStateNotifyMask);
145+
XkbIndicatorNotifyEvent event;
146+
while (True) {
147+
XNextEvent(display, (XEvent*) &event);
148+
if (event.xkb_type == XkbIndicatorStateNotify) display_ind_state(ind_keys, event.state);
149+
}
150+
}
151+
108152
// vim:filetype=c

0 commit comments

Comments
 (0)