bcat.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright 2021 Jonathan Rascher
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "bcat.h"
  17. #include "quantum.h"
  18. static int8_t alt_tab_layer = -1;
  19. __attribute__((weak)) void process_record_oled(uint16_t keycode, const keyrecord_t *record) {}
  20. __attribute__((weak)) bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { return true; }
  21. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  22. process_record_oled(keycode, record);
  23. if (!process_record_keymap(keycode, record)) {
  24. return false;
  25. }
  26. switch (keycode) {
  27. /* Alt+Tab that holds Alt until current layer is released: */
  28. case MC_ALTT:
  29. if (record->event.pressed) {
  30. if (alt_tab_layer < 0) {
  31. alt_tab_layer = layer_switch_get_layer(record->event.key);
  32. register_code(KC_LALT);
  33. }
  34. register_code(KC_TAB);
  35. } else {
  36. unregister_code(KC_TAB);
  37. }
  38. return false;
  39. default:
  40. return true;
  41. }
  42. }
  43. __attribute__((weak)) layer_state_t layer_state_set_keymap(layer_state_t state) { return state; }
  44. layer_state_t layer_state_set_user(layer_state_t state) {
  45. state = layer_state_set_keymap(state);
  46. #if defined(BCAT_ORTHO_LAYERS)
  47. state = update_tri_layer_state(state, LAYER_LOWER, LAYER_RAISE, LAYER_ADJUST);
  48. #endif
  49. if (alt_tab_layer >= 0 && !layer_state_cmp(state, alt_tab_layer)) {
  50. unregister_code(KC_LALT);
  51. alt_tab_layer = -1;
  52. }
  53. return state;
  54. }