Skip to content

Commit 51a5b53

Browse files
committed
implement toggle commands
1 parent f10dec3 commit 51a5b53

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

main.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@ static void close_restricted(int fd, void *user_data) {
1515
close(fd);
1616
}
1717

18-
int main() {
18+
int main(int argc, char *argv[]) {
19+
char* cmd_tablet = "echo tablet";
20+
char* cmd_laptop = "echo laptop";
21+
22+
if (argc >= 2)
23+
cmd_tablet = cmd_laptop = argv[1];
24+
if (argc >= 3)
25+
cmd_laptop = argv[2];
26+
1927
if (geteuid()) {
2028
fprintf(stderr, "Error: this utility requires root privileges (did you forget `sudo`?)\n");
2129
return 1;
@@ -49,8 +57,9 @@ int main() {
4957
if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE) continue;
5058
struct libinput_event_switch *switch_event = libinput_event_get_switch_event(event);
5159
if (libinput_event_switch_get_switch(switch_event) != LIBINPUT_SWITCH_TABLET_MODE) continue;
52-
const char switch_on = libinput_event_switch_get_switch_state(switch_event) == LIBINPUT_SWITCH_STATE_ON;
53-
printf("%s\n", switch_on ? "TABLET" : "LAPTOP");
60+
const char tablet_mode = libinput_event_switch_get_switch_state(switch_event) == LIBINPUT_SWITCH_STATE_ON;
61+
if (!fork())
62+
exit(system(tablet_mode ? cmd_tablet : cmd_laptop));
5463
libinput_event_destroy(event);
5564
}
5665
}

0 commit comments

Comments
 (0)