Skip to content

Instantly share code, notes, and snippets.

@antifuchs
Created April 2, 2023 22:08
Show Gist options
  • Save antifuchs/760ba90a82b22a057e32a3e994425a7c to your computer and use it in GitHub Desktop.
Save antifuchs/760ba90a82b22a057e32a3e994425a7c to your computer and use it in GitHub Desktop.
My ploopy configuration with some back/forward helpers & ad-hoc and permanent drag-scrolling support
/* Copyright 2023 Andreas Fuchs <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#define DYNAMIC_KEYMAP_LAYER_COUNT 8
/* defaults to 1600 DPI */
#define PLOOPY_DPI_OPTIONS \
{ 1200, 1700, 2400 }
#define PLOOPY_DPI_DEFAULT 1
/* Drag scrolling - invert V axis, set to a fixed amount of DPI */
#define PLOOPY_DRAGSCROLL_INVERT
#define PLOOPY_DRAGSCROLL_FIXED
#define PLOOPY_DRAGSCROLL_DPI 200
/* Number of points scrolled after which a click-scroll-release counts as
"active while held". Scroll further than that in any direction & releasing
the button deactivates drag scrolling.
This number is pretty small to let us discern between "accidental"
nudges of the ball when I meant to activate the mode, vs. small
amount of scroll. */
#define BOINKOR_PLOOPY_RELEASE_ADHOC_DISTANCE 5
/* Copyright 2023 Andreas Fuchs <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include QMK_KEYBOARD_H
extern bool is_drag_scroll;
uint16_t overall_scroll_distance = 0;
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
/* Base */
KC_BTN1, KC_BTN3, KC_BTN2, MO(1), DRAG_SCROLL),
[1] = LAYOUT(
/* current-tab-based nav */
LCMD(KC_LEFT_BRACKET), LCMD(KC_W), LCMD(KC_RIGHT_BRACKET), _______,
MO(2)),
[2] = LAYOUT(
/* tab-bar nav */
LCMD(LSFT(KC_LEFT_BRACKET)), _______, LCMD(LSFT(KC_RIGHT_BRACKET)),
_______, _______),
[3] = LAYOUT(_______, _______, _______, _______, _______),
/* unused layers */
[4] = LAYOUT(_______, _______, _______, _______, _______),
[5] = LAYOUT(_______, _______, _______, _______, _______),
[6] = LAYOUT(_______, _______, _______, _______, _______),
[7] = LAYOUT(_______, _______, _______, _______, _______),
};
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
/* Specially handle l/r clicks on drag-scrolling (stop scrolling & reset DPI)
*/
if (is_drag_scroll && (keycode == KC_BTN1 || keycode == KC_BTN2)) {
is_drag_scroll = false;
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
return false;
}
if (is_drag_scroll && keycode == DRAG_SCROLL && !record->event.pressed &&
overall_scroll_distance > BOINKOR_PLOOPY_RELEASE_ADHOC_DISTANCE) {
/* If we scrolled further than that distance while holding the
button pressed, it's an adhoc scroll & we clear the
drag-scroll state. */
is_drag_scroll = false;
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
return false;
}
return true;
}
report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) {
if (is_drag_scroll) {
overall_scroll_distance += abs(mouse_report.v) + abs(mouse_report.h);
} else {
overall_scroll_distance = 0;
}
return mouse_report;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment