logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

super_alt_tab.c (1794B)


  1. // Copyright 2025 Christopher Courtney, aka Drashna Jael're (@drashna)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include QMK_KEYBOARD_H
  4. ASSERT_COMMUNITY_MODULES_MIN_API_VERSION(1, 0, 0);
  5. static bool is_alt_tab_active = false;
  6. static uint16_t alt_tab_timer = 0;
  7. #ifndef COMMUNITY_MODULE_SUPER_ALT_TAB_TIMEOUT
  8. # define COMMUNITY_MODULE_SUPER_ALT_TAB_TIMEOUT 1000
  9. #endif // COMMUNITY_MODULE_SUPER_ALT_TAB_TIMEOUT
  10. #ifndef COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER
  11. # define COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER MOD_LALT
  12. #endif // COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER
  13. #ifndef COMMUNITY_MODULE_SUPER_ALT_TAB_KEY
  14. # define COMMUNITY_MODULE_SUPER_ALT_TAB_KEY KC_TAB
  15. #endif // COMMUNITY_MODULE_SUPER_ALT_TAB_KEY
  16. bool process_record_super_alt_tab(uint16_t keycode, keyrecord_t *record) {
  17. if (!process_record_super_alt_tab_kb(keycode, record)) {
  18. return false;
  19. }
  20. switch (keycode) { // This will do most of the grunt work with the keycodes.
  21. case COMMUNITY_MODULE_SUPER_ALT_TAB:
  22. if (record->event.pressed) {
  23. if (!is_alt_tab_active) {
  24. is_alt_tab_active = true;
  25. register_mods(COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER);
  26. }
  27. alt_tab_timer = timer_read();
  28. register_code(COMMUNITY_MODULE_SUPER_ALT_TAB_KEY);
  29. } else {
  30. unregister_code(COMMUNITY_MODULE_SUPER_ALT_TAB_KEY);
  31. }
  32. break;
  33. }
  34. return true;
  35. }
  36. void housekeeping_task_super_alt_tab(void) {
  37. if (is_alt_tab_active) {
  38. if (timer_elapsed(alt_tab_timer) > COMMUNITY_MODULE_SUPER_ALT_TAB_TIMEOUT) {
  39. unregister_mods(COMMUNITY_MODULE_SUPER_ALT_TAB_MODIFIER);
  40. is_alt_tab_active = false;
  41. }
  42. }
  43. }