keymap.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // used for tracking the state
  20. bool is_drag_scroll = false;
  21. enum custom_keycodes {
  22. DRAG_SCROLL = PLOOPY_SAFE_RANGE,
  23. };
  24. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  25. switch (keycode) {
  26. case DRAG_SCROLL:
  27. if (record->event.pressed) {
  28. // this toggles the state each time you tap it
  29. is_drag_scroll ^= 1;
  30. }
  31. break;
  32. }
  33. return true;
  34. }
  35. // The real magic is here.
  36. // This function is called to translate the processed sensor movement
  37. // from the mouse sensor and translates it into x and y movement for
  38. // the mouse report. Normally. So if "drag scroll" is toggled on,
  39. // moving the ball scrolls instead. You could remove the x or y here
  40. // to only scroll in one direction, if you wanted, as well. In fact,
  41. // there is no reason that you need to send this to the mouse report.
  42. // You could have it register a key, instead.
  43. void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) {
  44. if (is_drag_scroll) {
  45. mouse_report->h = x;
  46. mouse_report->v = y;
  47. } else {
  48. mouse_report->x = x;
  49. mouse_report->y = y;
  50. }
  51. }
  52. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  53. [0] = LAYOUT( /* Base */
  54. KC_BTN1, KC_BTN3, KC_BTN2,
  55. KC_BTN4, LT(1, KC_BTN5)
  56. ),
  57. [1] = LAYOUT(
  58. DRAG_SCROLL, _______, _______,
  59. _______, _______
  60. )
  61. };