Skip to content

Commit

Permalink
Allow app window switching to work like app switching by holding RSE
Browse files Browse the repository at this point in the history
  • Loading branch information
rhruiz committed Jan 15, 2025
1 parent 3f12211 commit 5b67382
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
6 changes: 2 additions & 4 deletions users/rhruiz/layouts/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ typedef enum custom_keycodes {
KC_LAY1,
KC_OLBR, // oled brightness
KC_NOS,
// window switcher
KC_CTAB,
// os independent nav keys
NV_START,
NV_WSWT = NV_START, // window switcher key
NV_SCTP, // scroll to bottom
NV_SCTP = NV_START, // scroll to bottom
NV_SCBT, // scroll to top
NV_EOL,
NV_BOL,
Expand All @@ -43,6 +40,7 @@ typedef enum custom_keycodes {
NV_1MOD, // main modifier (cmd on mac, ctrl on linux/windows)
NV_2MOD, // ctrl on mac, gui on linux/windows
NV_END = NV_2MOD,
KC_CTAB, // window switcher
NV_NWIN, // next window
USER_SAFE_RANGE
} rhruiz_keycodes;
Expand Down
24 changes: 10 additions & 14 deletions users/rhruiz/nav_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#include "rhruiz.h"

uint16_t copy_paste_timer;
bool is_window_switcher_active;
uint8_t window_switcher_mod = 0;

const uint16_t nav_keys[][NUM_NAV_KEYS_OSES] PROGMEM = {
[NV_NWIN - NV_START] = {KC_GRV, KC_GRV},
[NV_NWIN - NV_START] = {LCMD(KC_GRV), LALT(KC_GRV)},
[KC_CTAB - NV_START] = {LCMD(KC_TAB), LALT(KC_TAB)},
[NV_SCTP - NV_START] = {LCMD(KC_UP), LGUI(KC_HOME)},
[NV_SCBT - NV_START] = {LCMD(KC_DOWN), LGUI(KC_END)},
[NV_EOL - NV_START] = {LCMD(KC_RIGHT), KC_END},
Expand All @@ -21,7 +22,6 @@ const uint16_t nav_keys[][NUM_NAV_KEYS_OSES] PROGMEM = {
[NV_PSTE - NV_START] = {LCMD(KC_V), LCTL(KC_V)},
[NV_SCSH - NV_START] = {SCMD(KC_3), KC_PSCR},
[NV_WSCH - NV_START] = {SCMD(KC_4), SGUI(KC_S)},
[NV_WSWT - NV_START] = {KC_LGUI, KC_LALT},
[NV_1MOD - NV_START] = {KC_LGUI, KC_LCTL},
[NV_2MOD - NV_START] = {KC_LCTL, KC_LGUI},
};
Expand Down Expand Up @@ -65,21 +65,20 @@ void perform_nav_key(uint16_t keycode, keyrecord_t *record) {
handler(nav_keycode);
}

void window_switcher(keyrecord_t *record, uint16_t keycode) {
void window_switcher(uint16_t keycode, keyrecord_t *record) {
void (*handler)(uint16_t) = record->event.pressed ? register_code16 : unregister_code16;

if (record->event.pressed) {
is_window_switcher_active = true;
handler(get_nav_code(NV_WSWT));
register_mods(window_switcher_mod = QK_MODS_GET_MODS(keycode));
}

handler(keycode);
handler(QK_MODS_GET_BASIC_KEYCODE(keycode));
}

layer_state_t default_layer_state_set_user_nav(layer_state_t state) {
if (state < FIRST_NON_BASE_LAYER && is_window_switcher_active) {
unregister_code16(get_nav_code(NV_WSWT));
is_window_switcher_active = false;
if (state < FIRST_NON_BASE_LAYER && window_switcher_mod != 0) {
unregister_mods(window_switcher_mod);
window_switcher_mod = 0;
}

return state;
Expand Down Expand Up @@ -116,11 +115,8 @@ bool process_record_os_enabled_homerowmod(uint16_t keycode, keyrecord_t *record)
bool process_record_nav(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_CTAB:
window_switcher(record, KC_TAB);
break;

case NV_NWIN:
window_switcher(record, KC_GRV);
window_switcher(get_nav_code(keycode), record);
break;

case NV_START ... NV_END:
Expand Down

0 comments on commit 5b67382

Please sign in to comment.