From ade989962af613b24687f20f54e2dd0e37240216 Mon Sep 17 00:00:00 2001 From: Joshua T Date: Fri, 13 Aug 2021 20:14:21 -0500 Subject: [Keymap] clean up userspace, add XD75 / Keyboardio Atreus (#13121) Co-authored-by: Ryan Co-authored-by: Drashna Jaelre --- users/replicaJunction/features/.gitignore | 2 + users/replicaJunction/features/caps_word.c | 105 ++++++++++++++++++++ users/replicaJunction/features/caps_word.h | 26 +++++ users/replicaJunction/features/mouse_jiggle.c | 46 +++++++++ users/replicaJunction/features/mouse_jiggle.h | 23 +++++ users/replicaJunction/features/num_word.c | 129 +++++++++++++++++++++++++ users/replicaJunction/features/num_word.h | 27 ++++++ users/replicaJunction/features/secrets.c | 51 ++++++++++ users/replicaJunction/features/secrets.h | 30 ++++++ users/replicaJunction/features/super_alt_tab.c | 52 ++++++++++ users/replicaJunction/features/super_alt_tab.h | 27 ++++++ 11 files changed, 518 insertions(+) create mode 100644 users/replicaJunction/features/.gitignore create mode 100644 users/replicaJunction/features/caps_word.c create mode 100644 users/replicaJunction/features/caps_word.h create mode 100644 users/replicaJunction/features/mouse_jiggle.c create mode 100644 users/replicaJunction/features/mouse_jiggle.h create mode 100644 users/replicaJunction/features/num_word.c create mode 100644 users/replicaJunction/features/num_word.h create mode 100644 users/replicaJunction/features/secrets.c create mode 100644 users/replicaJunction/features/secrets.h create mode 100644 users/replicaJunction/features/super_alt_tab.c create mode 100644 users/replicaJunction/features/super_alt_tab.h (limited to 'users/replicaJunction/features') diff --git a/users/replicaJunction/features/.gitignore b/users/replicaJunction/features/.gitignore new file mode 100644 index 0000000000..9b590ee802 --- /dev/null +++ b/users/replicaJunction/features/.gitignore @@ -0,0 +1,2 @@ +# Do not include the secrets definitions +secret_definitions.h diff --git a/users/replicaJunction/features/caps_word.c b/users/replicaJunction/features/caps_word.c new file mode 100644 index 0000000000..536da81ec7 --- /dev/null +++ b/users/replicaJunction/features/caps_word.c @@ -0,0 +1,105 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "caps_word.h" + +static bool is_caps_word_on = false; + +bool is_caps_word_enabled(void) { + return is_caps_word_on; +} + +void enable_caps_word(void) { + if (is_caps_word_on) return; + is_caps_word_on = true; + tap_code(KC_CAPS); +} + +void disable_caps_word(void) { + if (!is_caps_word_on) return; + is_caps_word_on = false; + tap_code(KC_CAPS); +} + +void toggle_caps_word(void) { + if (is_caps_word_on) { + disable_caps_word(); + } + else { + enable_caps_word(); + } +} + +bool should_terminate_caps_word(uint16_t keycode, const keyrecord_t *record) { + switch (keycode) { + // Keycodes which should not disable caps word mode + case KC_A ... KC_Z: + case KC_1 ... KC_0: + case KC_MINS: + case KC_UNDS: + case KC_BSPC: + return false; + + default: + if (record->event.pressed) { + return true; + } + return false; + } + + // Should be unreachable + return false; +} + + +bool process_record_caps_word(uint16_t keycode, const keyrecord_t *record) { + // Nothing in this function acts on key release + if (!record->event.pressed) { + return true; + } + + // Handle the custom keycodes that go with this feature + if (keycode == CAPWORD) { + enable_caps_word(); + return false; + } + + // If the behavior isn't enabled and the keypress isn't a keycode to + // toggle the behavior, allow QMK to handle the keypress as usual + if (!is_caps_word_on) { + return true; + } + + // Get the base keycode of a mod or layer tap key + switch (keycode) { + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: + case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: + // Earlier return if this has not been considered tapped yet + if (record->tap.count == 0) + return true; + keycode = keycode & 0xFF; + break; + default: + break; + } + + if (should_terminate_caps_word(keycode, record)) { + disable_caps_word(); + } + + return true; +} diff --git a/users/replicaJunction/features/caps_word.h b/users/replicaJunction/features/caps_word.h new file mode 100644 index 0000000000..4182ce5829 --- /dev/null +++ b/users/replicaJunction/features/caps_word.h @@ -0,0 +1,26 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include QMK_KEYBOARD_H +#include "rj_keycodes.h" + +bool is_caps_word_enabled(void); +void enable_caps_word(void); +void disable_caps_word(void); +void toggle_caps_word(void); + +bool process_record_caps_word(uint16_t keycode, const keyrecord_t *record); diff --git a/users/replicaJunction/features/mouse_jiggle.c b/users/replicaJunction/features/mouse_jiggle.c new file mode 100644 index 0000000000..b2c451d33e --- /dev/null +++ b/users/replicaJunction/features/mouse_jiggle.c @@ -0,0 +1,46 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "mouse_jiggle.h" + +bool is_mouse_jiggle_active = false; + +void matrix_scan_mouse_jiggle(void) { + if (is_mouse_jiggle_active) { + tap_code(KC_MS_UP); + tap_code(KC_MS_DOWN); + } +} + +bool process_record_mouse_jiggle(uint16_t keycode, const keyrecord_t *record) { + if (!record->event.pressed) { + return true; + } + + if (is_mouse_jiggle_active) { + // If active, quit whenever another key is pressed + is_mouse_jiggle_active = false; + return true; + } + + if (keycode != MS_JIGL) { + return true; + } + + is_mouse_jiggle_active = true; + SEND_STRING("Mouse jiggler enabled"); + return false; +} diff --git a/users/replicaJunction/features/mouse_jiggle.h b/users/replicaJunction/features/mouse_jiggle.h new file mode 100644 index 0000000000..ba2c6e7570 --- /dev/null +++ b/users/replicaJunction/features/mouse_jiggle.h @@ -0,0 +1,23 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include QMK_KEYBOARD_H +#include "rj_keycodes.h" + +void matrix_scan_mouse_jiggle(void); + +bool process_record_mouse_jiggle(uint16_t keycode, const keyrecord_t *record); diff --git a/users/replicaJunction/features/num_word.c b/users/replicaJunction/features/num_word.c new file mode 100644 index 0000000000..4cca5c19ae --- /dev/null +++ b/users/replicaJunction/features/num_word.c @@ -0,0 +1,129 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "num_word.h" + +static uint16_t num_word_timer = 0; +static bool is_num_word_on = false; + +bool is_num_word_enabled(void) { + return is_num_word_on; +} + +void enable_num_word(void) { + if (is_num_word_on) return; + is_num_word_on = true; + layer_on(L_NUMBERS); +} + +void disable_num_word(void) { + if (!is_num_word_on) return; + is_num_word_on = false; + layer_off(L_NUMBERS); +} + +void toggle_num_word(void) { + if (is_num_word_on) { + disable_num_word(); + } + else { + enable_num_word(); + } +} + +bool should_terminate_num_word(uint16_t keycode, const keyrecord_t *record) { + switch (keycode) { + // Keycodes which should not disable num word mode. + // We could probably be more brief with these definitions by using + // a couple more ranges, but I believe "explicit is better than + // implicit" + case KC_1 ... KC_0: + case KC_EQL: + case KC_SCLN: + case KC_MINS: + case KC_DOT: + + // Numpad keycodes + case KC_P1 ... KC_P0: + case KC_PSLS ... KC_PPLS: + case KC_PDOT: + + // Misc + case KC_UNDS: + case KC_BSPC: + return false; + + default: + if (record->event.pressed) { + return true; + } + return false; + } + + // Should be unreachable + return false; +} + + +bool process_record_num_word(uint16_t keycode, const keyrecord_t *record) { + // Handle the custom keycodes that go with this feature + if (keycode == NUMWORD) { + if (record->event.pressed) { + enable_num_word(); + num_word_timer = timer_read(); + return false; + } + else { + if (timer_elapsed(num_word_timer) > TAPPING_TERM) { + // If the user held the key longer than TAPPING_TERM, + // consider it a hold, and disable the behavior on + // key release. + disable_num_word(); + return false; + } + } + } + + // Other than the custom keycodes, nothing else in this feature will + // activate if the behavior is not on, so allow QMK to handle the + // event as usual + if (!is_num_word_on) return true; + + // Nothing else acts on key release, either + if (!record->event.pressed) { + return true; + } + + // Get the base keycode of a mod or layer tap key + switch (keycode) { + case QK_MOD_TAP ... QK_MOD_TAP_MAX: + case QK_LAYER_TAP ... QK_LAYER_TAP_MAX: + case QK_TAP_DANCE ... QK_TAP_DANCE_MAX: + // Earlier return if this has not been considered tapped yet + if (record->tap.count == 0) + return true; + keycode = keycode & 0xFF; + break; + default: + break; + } + + if (should_terminate_num_word(keycode, record)) { + disable_num_word(); + } + + return true; +} diff --git a/users/replicaJunction/features/num_word.h b/users/replicaJunction/features/num_word.h new file mode 100644 index 0000000000..194c4e2e0d --- /dev/null +++ b/users/replicaJunction/features/num_word.h @@ -0,0 +1,27 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include QMK_KEYBOARD_H +#include "rj_keycodes.h" +#include "rj_layers.h" + +bool is_num_word_enabled(void); +void enable_num_word(void); +void disable_num_word(void); +void toggle_num_word(void); + +bool process_record_num_word(uint16_t keycode, const keyrecord_t *record); diff --git a/users/replicaJunction/features/secrets.c b/users/replicaJunction/features/secrets.c new file mode 100644 index 0000000000..3e1ea283dc --- /dev/null +++ b/users/replicaJunction/features/secrets.c @@ -0,0 +1,51 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +// Before you can compile with this feature, you'll need to manually +// create a file in this directory called "secret_definitions.h" +// containing the data to be added. +// +// Example implementation: +// +// #pragma once +// static const char * const secrets[] = { +// "secret1", +// "secret2", +// "secret3", +// "secret4" +// } + +#include QMK_KEYBOARD_H +#include "replicaJunction.h" +#include "secrets.h" +#include "secret_definitions.h" + +#ifndef MACRO_TIMER +# define MACRO_TIMER 5 +#endif + +bool process_record_secrets(uint16_t keycode, const keyrecord_t *record) { + switch (keycode) { + case K_SECR1 ... K_SECR4: // Secrets! Externally defined strings, not stored in repo + if (!record->event.pressed) { + clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED); + send_string_with_delay(secrets[keycode - K_SECR1], MACRO_TIMER); + } + return false; + } + + return true; +} diff --git a/users/replicaJunction/features/secrets.h b/users/replicaJunction/features/secrets.h new file mode 100644 index 0000000000..ef43962272 --- /dev/null +++ b/users/replicaJunction/features/secrets.h @@ -0,0 +1,30 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include QMK_KEYBOARD_H + +// NOTE: In some implementations of the "secrets" functionality, the +// secrets.h file is the file that actually contains secret text. +// +// This is not the case in my implementation. That file is called +// "secret_definitions.h", and it's in a local .gitignore file so it +// does not get committed. +// +// The inclusion of this file is not an error, and there is no sensitive +// text here. + +bool process_record_secrets(uint16_t keycode, const keyrecord_t *record); diff --git a/users/replicaJunction/features/super_alt_tab.c b/users/replicaJunction/features/super_alt_tab.c new file mode 100644 index 0000000000..9759898c87 --- /dev/null +++ b/users/replicaJunction/features/super_alt_tab.c @@ -0,0 +1,52 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "super_alt_tab.h" + +// https://docs.qmk.fm/#/feature_macros?id=super-alt%E2%86%AFtab + +bool is_alt_tab_active = false; +uint16_t alt_tab_timer = 0; + +void matrix_scan_super_alt_tab(void) { + if (is_alt_tab_active) { + if (timer_elapsed(alt_tab_timer) > USER_SUPER_ALT_TAB_TIMEOUT) { + unregister_code(KC_LALT); + is_alt_tab_active = false; + } + } +} + + +bool process_record_super_alt_tab(uint16_t keycode, const keyrecord_t *record) { + if (keycode != SALTTAB) { + return true; + } + + if (record->event.pressed) { + if (!is_alt_tab_active) { + is_alt_tab_active = true; + register_code(KC_LALT); + } + alt_tab_timer = timer_read(); + register_code(KC_TAB); + } + else { + unregister_code(KC_TAB); + } + + return false; +} diff --git a/users/replicaJunction/features/super_alt_tab.h b/users/replicaJunction/features/super_alt_tab.h new file mode 100644 index 0000000000..8bdf2bc22e --- /dev/null +++ b/users/replicaJunction/features/super_alt_tab.h @@ -0,0 +1,27 @@ +/* Copyright 2021 Joshua T. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once +#include QMK_KEYBOARD_H +#include "rj_keycodes.h" + +#ifndef USER_SUPER_ALT_TAB_TIMEOUT +# define USER_SUPER_ALT_TAB_TIMEOUT 500 +#endif + +void matrix_scan_super_alt_tab(void); + +bool process_record_super_alt_tab(uint16_t keycode, const keyrecord_t *record); -- cgit v1.2.3