Skip to content

Instantly share code, notes, and snippets.

@goose121
Created December 10, 2017 01:40
Show Gist options
  • Select an option

  • Save goose121/0f79b0bc93da79d89287d849fb698120 to your computer and use it in GitHub Desktop.

Select an option

Save goose121/0f79b0bc93da79d89287d849fb698120 to your computer and use it in GitHub Desktop.
A patch to caps2esc for swaywm users to use tab as Mod3
--- caps2esc.c 2017-12-09 18:37:33.550024972 -0700
+++ /home/kah/code/caps2esc/caps2esc.c 2017-12-09 18:28:27.240021549 -0700
@@ -1,21 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <linux/input.h>
// clang-format off
const struct input_event
-esc_up = {.type = EV_KEY, .code = KEY_ESC, .value = 0},
-ctrl_up = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 0},
-capslock_up = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 0},
-esc_down = {.type = EV_KEY, .code = KEY_ESC, .value = 1},
-ctrl_down = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 1},
-capslock_down = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 1},
-esc_repeat = {.type = EV_KEY, .code = KEY_ESC, .value = 2},
-ctrl_repeat = {.type = EV_KEY, .code = KEY_LEFTCTRL, .value = 2},
-capslock_repeat = {.type = EV_KEY, .code = KEY_CAPSLOCK, .value = 2},
-syn = {.type = EV_SYN, .code = SYN_REPORT, .value = 0};
+rmeta_up = {.type = EV_KEY, .code = KEY_RIGHTMETA,.value = 0},
+tab_up = {.type = EV_KEY, .code = KEY_TAB, .value = 0},
+rmeta_down = {.type = EV_KEY, .code = KEY_RIGHTMETA,.value = 1},
+tab_down = {.type = EV_KEY, .code = KEY_TAB, .value = 1},
+rmeta_repeat = {.type = EV_KEY, .code = KEY_RIGHTMETA,.value = 2},
+tab_repeat = {.type = EV_KEY, .code = KEY_TAB, .value = 2};
// clang-format on
int equal(const struct input_event *first, const struct input_event *second) {
@@ -32,53 +27,50 @@
exit(EXIT_FAILURE);
}
+void ferr (const char *msg) {
+// fprintf(stderr, "%s\n", msg);
+}
+
int main(void) {
- int capslock_is_down = 0, esc_give_up = 0;
+ int tab_is_down = 0, suppress_tab = 0;
struct input_event input;
-
+ ferr("Started!");
setbuf(stdin, NULL), setbuf(stdout, NULL);
-
+ ferr("Bufs set!");
while (read_event(&input)) {
- if (input.type == EV_MSC && input.code == MSC_SCAN)
- continue;
-
if (input.type != EV_KEY) {
write_event(&input);
continue;
}
- if (capslock_is_down) {
- if (equal(&input, &capslock_down) ||
- equal(&input, &capslock_repeat))
- continue;
-
- if (equal(&input, &capslock_up)) {
- capslock_is_down = 0;
- if (esc_give_up) {
- esc_give_up = 0;
- write_event(&ctrl_up);
+ if (tab_is_down) {
+ ferr("tab is down!");
+ if (equal(&input, &tab_down) ||
+ equal(&input, &tab_repeat)) {
continue;
+ }
+ else if (equal(&input, &tab_up)) {
+ write_event(&rmeta_up);
+ tab_is_down = 0;
+ if (!suppress_tab) {
+ write_event(&tab_down);
+ write_event(&tab_up);
}
- write_event(&esc_down);
- write_event(&syn);
- usleep(20000);
- write_event(&esc_up);
- continue;
+ suppress_tab = 0;
}
-
- if (!esc_give_up && input.value) {
- esc_give_up = 1;
- write_event(&ctrl_down);
- write_event(&syn);
- usleep(20000);
+ else {
+ ferr("Suppressing tab!");
+ suppress_tab = 1;
+ write_event(&input);
}
- } else if (equal(&input, &capslock_down)) {
- capslock_is_down = 1;
+ } else if (equal(&input, &tab_down)) {
+ ferr("Tab pressed!");
+ write_event(&rmeta_down);
+ tab_is_down = 1;
continue;
+ } else {
+ ferr("Passing code through");
+ write_event(&input);
}
-
- if (input.code == KEY_ESC)
- input.code = KEY_CAPSLOCK;
- write_event(&input);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment