keymap.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  25. [0] = LAYOUT(/* Base */
  26. C(KC_C), KC_BTN1, KC_BTN3, KC_BTN2, C(KC_V), KC_BTN4, KC_BTN5, DPI_CONFIG)
  27. };
  28. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  29. switch (keycode) {
  30. case DRAG_SCROLL:
  31. if (record->event.pressed) {
  32. // this toggles the state each time you tap it
  33. is_drag_scroll ^= 1;
  34. }
  35. break;
  36. }
  37. return true;
  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. }