aboutsummaryrefslogtreecommitdiff
path: root/keyboards/xd004/keymaps/system_and_media/keymap.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/xd004/keymaps/system_and_media/keymap.c')
-rw-r--r--keyboards/xd004/keymaps/system_and_media/keymap.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/keyboards/xd004/keymaps/system_and_media/keymap.c b/keyboards/xd004/keymaps/system_and_media/keymap.c
new file mode 100644
index 000000000..740132639
--- /dev/null
+++ b/keyboards/xd004/keymaps/system_and_media/keymap.c
@@ -0,0 +1,61 @@
1#include QMK_KEYBOARD_H
2
3#define _BASE 0 // Base layer
4#define _SYSTEM 1 // System actions
5#define _VOLUME 2 // Volume actions
6
7#define SUPER_ALT_F4_TIMER 300 // Timeout on the super alt-f4 key
8
9/*
10 The idea of this is pretty simple: base layer has four action, two of which (the outermost)
11 are regular keystrokes on tap, and a momentary layer switch on hold, sending you to layers 1 and 2.
12
13 The other bit of customization here is the 'Super Alt F4' which does Alt-F4, and then Enter if tapped
14 again SUPER_ALT_F4_TIMER miliseconds after. This lets you Alt-F4 applications, and finally quickly
15 double-tap it to Alt-F4+Enter to shut down the PC.
16*/
17
18bool is_alt_f4_active = false;
19uint16_t alt_f4_timer = 0;
20
21enum custom_keycodes { // Make sure have the awesome keycode ready
22 SUPER_ALT_F4 = SAFE_RANGE,
23};
24
25const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
26
27 // 0: Base Layer
28 [_BASE] = LAYOUT_all(LT(_SYSTEM, KC_F5), C(G(KC_LEFT)), C(G(KC_RIGHT)), LT(_VOLUME, KC_F7)),
29
30 // 1: System actions
31 [_SYSTEM] = LAYOUT_all(_______, SUPER_ALT_F4, G(KC_D), G(KC_L)),
32
33 // 2: Volume actions
34 [_VOLUME] = LAYOUT_all(KC_MEDIA_NEXT_TRACK, KC_AUDIO_VOL_DOWN, KC_AUDIO_VOL_UP, _______),
35
36};
37
38bool process_record_user(uint16_t keycode, keyrecord_t *record) {
39 switch (keycode) { // This will do most of the grunt work with the keycodes.
40 case SUPER_ALT_F4:
41 if (record->event.pressed) {
42 if (!is_alt_f4_active) {
43 is_alt_f4_active = true;
44 tap_code_16(LALT(KC_F4); // Alt-F4
45 } else {
46 tap_code(KC_ENTER); // Tap enter
47 }
48 } else {
49 unregister_code(KC_TAB);
50 }
51 alt_f4_timer = timer_read();
52 break;
53 }
54 return true;
55}
56
57void matrix_scan_user(void) {
58 if (is_alt_f4_active && timer_elapsed(alt_f4_timer) > SUPER_ALT_F4_TIMER) {
59 is_alt_f4_active = false;
60 }
61};