summaryrefslogtreecommitdiff
path: root/modules/qmk
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2025-03-20 15:12:46 -0700
committerGitHub <noreply@github.com>2025-03-21 09:12:46 +1100
commita958276a764af481f5626cafb2f0c6ec00894ff2 (patch)
treefec3e541b50e3603f45e3728ab6c7d44c79017f5 /modules/qmk
parent7fd12c2b98f00b7e70bfc70a74654a23c2b04d16 (diff)
Add Super Alt-Tab macro example as module (#24970)
* Add Super Alt-Tab macro example as module * Make module more configurable * remove unneeded comments Co-authored-by: jack <jack@pngu.org> * Update modules/qmk/super_alt_tab/super_alt_tab.c Co-authored-by: Nick Brassel <nick@tzarc.org> --------- Co-authored-by: jack <jack@pngu.org> Co-authored-by: Nick Brassel <nick@tzarc.org>
Diffstat (limited to 'modules/qmk')
-rw-r--r--modules/qmk/super_alt_tab/qmk_module.json10
-rw-r--r--modules/qmk/super_alt_tab/super_alt_tab.c50
2 files changed, 60 insertions, 0 deletions
diff --git a/modules/qmk/super_alt_tab/qmk_module.json b/modules/qmk/super_alt_tab/qmk_module.json
new file mode 100644
index 0000000000..002f7fb69e
--- /dev/null
+++ b/modules/qmk/super_alt_tab/qmk_module.json
@@ -0,0 +1,10 @@
1{
2 "module_name": "Super Alt Tab",
3 "maintainer": "QMK Maintainers",
4 "keycodes": [
5 {
6 "key": "COMMUNITY_MODULE_SUPER_ALT_TAB",
7 "aliases": ["CM_S_AT"]
8 }
9 ]
10}
diff --git a/modules/qmk/super_alt_tab/super_alt_tab.c b/modules/qmk/super_alt_tab/super_alt_tab.c
new file mode 100644
index 0000000000..dfeb4b5773
--- /dev/null
+++ b/modules/qmk/super_alt_tab/super_alt_tab.c
@@ -0,0 +1,50 @@
1// Copyright 2025 Christopher Courtney, aka Drashna Jael're (@drashna)
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#include QMK_KEYBOARD_H
5
6ASSERT_COMMUNITY_MODULES_MIN_API_VERSION(1, 0, 0);
7
8static bool is_alt_tab_active = false;
9static uint16_t alt_tab_timer = 0;
10
11#ifndef COMMUNITY_MODULE_SUPER_ALT_TAB_TIMEOUT
12# define COMMUNITY_MODULE_SUPER_ALT_TAB_TIMEOUT 1000
13#endif // COMMUNITY_MODULE_SUPER_ALT_TAB_TIMEOUT
14#ifndef COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER
15# define COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER MOD_LALT
16#endif // COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER
17#ifndef COMMUNITY_MODULE_SUPER_ALT_TAB_KEY
18# define COMMUNITY_MODULE_SUPER_ALT_TAB_KEY KC_TAB
19#endif // COMMUNITY_MODULE_SUPER_ALT_TAB_KEY
20
21bool process_record_super_alt_tab(uint16_t keycode, keyrecord_t *record) {
22 if (!process_record_super_alt_tab_kb(keycode, record)) {
23 return false;
24 }
25
26 switch (keycode) { // This will do most of the grunt work with the keycodes.
27 case COMMUNITY_MODULE_SUPER_ALT_TAB:
28 if (record->event.pressed) {
29 if (!is_alt_tab_active) {
30 is_alt_tab_active = true;
31 register_mods(COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER);
32 }
33 alt_tab_timer = timer_read();
34 register_code(COMMUNITY_MODULE_SUPER_ALT_TAB_KEY);
35 } else {
36 unregister_code(COMMUNITY_MODULE_SUPER_ALT_TAB_KEY);
37 }
38 break;
39 }
40 return true;
41}
42
43void housekeeping_task_super_alt_tab(void) {
44 if (is_alt_tab_active) {
45 if (timer_elapsed(alt_tab_timer) > COMMUNITY_MODULE_SUPER_ALT_TAB_TIMEOUT) {
46 unregister_mods(COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER);
47 is_alt_tab_active = false;
48 }
49 }
50}