Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
danil-tolkachev committed Jan 3, 2025
1 parent 70020d3 commit b9a9b88
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
5 changes: 3 additions & 2 deletions keyboards/ergohaven/ergohaven_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
}

case EH_SCR:
case EH_TXT: {
case EH_TXT:
case EH_SNP: {
static uint32_t press_timer = 0;
static pointing_mode_t prev_pointing_mode = POINTING_MODE_NORMAL;

const pointing_mode_t NEW_MODE = (keycode == EH_SCR) ? POINTING_MODE_SCROLL : POINTING_MODE_TEXT;
const pointing_mode_t NEW_MODE = (keycode == EH_SCR) ? POINTING_MODE_SCROLL : ((keycode == EH_TXT) ? POINTING_MODE_TEXT : POINTING_MODE_SNIPER);

if (record->event.pressed) {
prev_pointing_mode = pointing_mode;
Expand Down
54 changes: 34 additions & 20 deletions keyboards/ergohaven/ergohaven_pointing.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool auto_mouse_activation(report_mouse_t mouse_report) {

report_mouse_t pointing_device_task_user(report_mouse_t mrpt) {
is_mouse_active = abs(mrpt.x) > 1 || abs(mrpt.y) > 1 || abs(mrpt.h) >= 1 || abs(mrpt.v) >= 1 || mrpt.buttons;

if (pointing_mode != POINTING_MODE_NORMAL) {
accumulated_h += mrpt.x;
accumulated_v -= mrpt.y;
Expand All @@ -28,26 +29,39 @@ report_mouse_t pointing_device_task_user(report_mouse_t mrpt) {
mrpt.x = 0;
mrpt.y = 0;

if (pointing_mode == POINTING_MODE_SCROLL) {
mrpt.h = shift_x;
mrpt.v = shift_y;
} else if (pointing_mode == POINTING_MODE_TEXT) {
while (shift_x > 0) {
tap_code(KC_RIGHT);
shift_x--;
}
while (shift_x < 0) {
tap_code(KC_LEFT);
shift_x++;
}
while (shift_y > 0) {
tap_code(KC_UP);
shift_y--;
}
while (shift_y < 0) {
tap_code(KC_DOWN);
shift_y++;
}
switch (pointing_mode) {
case POINTING_MODE_SNIPER:
mrpt.x = shift_x;
mrpt.y = shift_y;
break;

case POINTING_MODE_SCROLL:
mrpt.h = shift_x;
mrpt.v = shift_y;
break;

case POINTING_MODE_TEXT:
while (shift_x > 0) {
tap_code(KC_RIGHT);
shift_x--;
}
while (shift_x < 0) {
tap_code(KC_LEFT);
shift_x++;
}
while (shift_y > 0) {
tap_code(KC_UP);
shift_y--;
}
while (shift_y < 0) {
tap_code(KC_DOWN);
shift_y++;
}
break;

default:
case POINTING_MODE_NORMAL:
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions keyboards/ergohaven/ergohaven_pointing.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

typedef enum {
POINTING_MODE_NORMAL,
POINTING_MODE_SNIPER,
POINTING_MODE_SCROLL,
POINTING_MODE_TEXT,
} pointing_mode_t;
Expand Down

0 comments on commit b9a9b88

Please sign in to comment.