diff options
Diffstat (limited to 'keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c')
-rw-r--r-- | keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c new file mode 100644 index 000000000..7784bc855 --- /dev/null +++ b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c | |||
@@ -0,0 +1,66 @@ | |||
1 | /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | ||
2 | * Copyright 2019 Sunjun Kim | ||
3 | * Copyright 2020 Ploopy Corporation | ||
4 | * | ||
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation, either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | #include QMK_KEYBOARD_H | ||
19 | |||
20 | // used for tracking the state | ||
21 | bool is_drag_scroll = false; | ||
22 | |||
23 | enum custom_keycodes { | ||
24 | DRAG_SCROLL = PLOOPY_SAFE_RANGE, | ||
25 | }; | ||
26 | |||
27 | bool process_record_user(uint16_t keycode, keyrecord_t *record) { | ||
28 | switch (keycode) { | ||
29 | case DRAG_SCROLL: | ||
30 | if (record->event.pressed) { | ||
31 | // this toggles the state each time you tap it | ||
32 | is_drag_scroll ^= 1; | ||
33 | } | ||
34 | break; | ||
35 | } | ||
36 | return true; | ||
37 | } | ||
38 | |||
39 | // The real magic is here. | ||
40 | // This function is called to translate the processed sensor movement | ||
41 | // from the mouse sensor and translates it into x and y movement for | ||
42 | // the mouse report. Normally. So if "drag scroll" is toggled on, | ||
43 | // moving the ball scrolls instead. You could remove the x or y here | ||
44 | // to only scroll in one direction, if you wanted, as well. In fact, | ||
45 | // there is no reason that you need to send this to the mouse report. | ||
46 | // You could have it register a key, instead. | ||
47 | void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { | ||
48 | if (is_drag_scroll) { | ||
49 | mouse_report->h = x; | ||
50 | mouse_report->v = y; | ||
51 | } else { | ||
52 | mouse_report->x = x; | ||
53 | mouse_report->y = y; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | ||
58 | [0] = LAYOUT( /* Base */ | ||
59 | KC_BTN1, KC_BTN3, KC_BTN2, | ||
60 | KC_BTN4, LT(1, KC_BTN5) | ||
61 | ), | ||
62 | [1] = LAYOUT( | ||
63 | DRAG_SCROLL, _______, _______, | ||
64 | _______, _______ | ||
65 | ) | ||
66 | }; | ||