-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder.c
59 lines (55 loc) · 1.4 KB
/
encoder.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include QMK_KEYBOARD_H
#include "keymap.h"
// Scrolling with PageUp and PgDn.
void encoder_scroll_page(bool clockwise) {
if (clockwise) {
tap_code(KC_PGUP);
} else {
tap_code(KC_PGDN);
}
}
// Volume control.
void encoder_volume(bool clockwise) {
if (clockwise) {
tap_code(KC_VOLU);
} else {
tap_code(KC_VOLD);
}
}
void encoder_tab_windows(bool clockwise) {
if (clockwise) {
if (!is_gui_tab_active) {
is_gui_tab_active = true;
register_code(KC_LGUI);
}
gui_alt_timer = timer_read();
tap_code16(KC_TAB);
} else {
if (!is_gui_tab_active) {
is_gui_tab_active = true;
register_code(KC_LGUI);
}
gui_alt_timer = timer_read();
tap_code16(S(KC_TAB));
}
}
bool encoder_update_user(uint8_t index, bool clockwise) {
if (index == 0) {
switch (biton32(layer_state)) {
default:
if (get_mods() & MOD_MASK_GUI || oneshot_mod_state & MOD_MASK_GUI) {
encoder_tab_windows(clockwise);
} else {
encoder_scroll_page(clockwise);
}
break;
}
} else if (index == 1) {
switch (biton32(layer_state)) {
default:
encoder_volume(clockwise);
break;
}
}
return false;
}