Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work for the next release. #77

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 59 additions & 69 deletions keyboards/svalboard/keymaps/keymap_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@ void mouse_mode(bool);

#if defined(POINTING_DEVICE_AUTO_MOUSE_MH_ENABLE)

#define SCROLL_DIVISOR 20
#define SCROLL_DIVISOR 80

bool mouse_mode_enabled = false;

static int _ds_l_x = 0;
static int _ds_l_y = 0;
static int _ds_r_x = 0;
static int _ds_r_y = 0;

static bool left_scroll_hold = false, right_scroll_hold = false;
static bool scroll_hold = false, scroll_toggle = false;

report_mouse_t pointing_device_task_combined_user(report_mouse_t reportMouse1, report_mouse_t reportMouse2) {
report_mouse_t ret_mouse;
if (reportMouse1.x == 0 && reportMouse1.y == 0 && reportMouse2.x == 0 && reportMouse2.y == 0)
return pointing_device_combine_reports(reportMouse1, reportMouse2);

if (global_saved_values.left_scroll || left_scroll_hold) {
if ((global_saved_values.left_scroll != scroll_hold) != scroll_toggle) {
int div_x;
int div_y;

Expand All @@ -79,7 +81,7 @@ report_mouse_t pointing_device_task_combined_user(report_mouse_t reportMouse1, r
reportMouse1.y = 0;
}

if (global_saved_values.right_scroll || right_scroll_hold) {
if ((global_saved_values.right_scroll != scroll_hold) != scroll_toggle) {
int div_x;
int div_y;

Expand All @@ -103,14 +105,7 @@ report_mouse_t pointing_device_task_combined_user(report_mouse_t reportMouse1, r
reportMouse2.y = 0;
}

if (mh_auto_buttons_timer) {
mh_auto_buttons_timer = timer_read();
} else {
mouse_mode(true);
#if defined CONSOLE_ENABLE
print("task - combined mh_auto_buttons: on\n");
#endif
}
mouse_mode(true);
ret_mouse = pointing_device_combine_reports(reportMouse1, reportMouse2);

return pointing_device_task_user(ret_mouse);
Expand All @@ -124,14 +119,7 @@ report_mouse_t pointing_device_task_user(report_mouse_t reportMouse) {
if (reportMouse.x == 0 && reportMouse.y == 0)
return reportMouse;

if (mh_auto_buttons_timer) {
mh_auto_buttons_timer = timer_read();
} else {
mouse_mode(true);
#if defined CONSOLE_ENABLE
print("user - mh_auto_buttons: on\n");
#endif
}
mouse_mode(true);

if (snipe_div != 1) {
int div_x;
Expand Down Expand Up @@ -186,8 +174,10 @@ void check_layer_67(void) {

bool in_mod_tap = false;
int8_t in_mod_tap_layer = -1;
int8_t mouse_keys_pressed = 0;
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {


// Abort additional processing if userspace code did
if (!process_record_user(keycode, record)) { return false;}
if (!in_mod_tap && !global_saved_values.disable_achordion && !process_achordion(keycode, record)) { return false; }
Expand Down Expand Up @@ -218,41 +208,48 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
uprintf("KL: kc: 0x%04X, col: %2u, row: %2u, pressed: %u, time: %5u, int: %u, count: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed, record->event.time, record->tap.interrupted, record->tap.count);
#endif

if (mh_auto_buttons_timer) {
switch (keycode) {
case KC_BTN1:
case KC_BTN2:
case KC_BTN3:
case KC_BTN4:
case KC_BTN5:
case KC_WH_U:
case KC_WH_D:
case KC_WH_R:
case KC_WH_L:
case KC_LSFT:
case KC_RSFT:
case KC_LCTL:
case KC_RCTL:
case KC_LALT:
case KC_RALT:
case KC_LGUI:
case KC_RGUI:
case SV_LEFT_SCROLL_TOGGLE:
case SV_RIGHT_SCROLL_TOGGLE:
case SV_LEFT_SCROLL_HOLD:
case SV_RIGHT_SCROLL_HOLD:
case SV_SNIPER_2:
case SV_SNIPER_3:
case SV_SNIPER_5:
case SV_RECALIBRATE_POINTER:
break;
default:
if (mouse_mode_enabled && layer_state & (1 << MH_AUTO_BUTTONS_LAYER)) {
// The keycodes below are all that are forced to drop you out of mouse mode.
// The intent is for this list to eventually become just KC_NO, and KC_TRNS
// as more functionality is exported to keybard, and those keys are removed
// from the firmmware. - ilc - 2024-10-05
#define BAD_KEYCODE_CONDITONAL (keycode == KC_NO || \
keycode == KC_TRNS || \
keycode == SV_LEFT_DPI_INC || \
keycode == SV_LEFT_DPI_DEC || \
keycode == SV_RIGHT_DPI_INC || \
keycode == SV_RIGHT_DPI_DEC || \
keycode == SV_LEFT_SCROLL_TOGGLE || \
keycode == SV_RIGHT_SCROLL_TOGGLE || \
keycode == SV_TOGGLE_ACHORDION || \
keycode == SV_MH_CHANGE_TIMEOUTS)

uint16_t layer_keycode = keymap_key_to_keycode(MH_AUTO_BUTTONS_LAYER, record->event.key);
if (BAD_KEYCODE_CONDITONAL ||
layer_keycode != keycode) {
#ifdef CONSOLE_ENABLE
uprintf("process_record - mh_auto_buttons: off\n");
uprintf("process_record - mh_auto_buttons: off\n");
#endif
if (BAD_KEYCODE_CONDITONAL) {
mouse_mode(false);
return false;
} else {
mouse_mode(false);
}
} else {
if (record->event.pressed) {
mouse_keys_pressed++;
mouse_mode(true);
} else {
// keys that are held before the mouse layer is active can mess this up.
if (mouse_keys_pressed > 0) {
mouse_keys_pressed--;
}
mouse_mode(true);
}
}
}

if (record->event.pressed) { // key pressed
switch (keycode) {
case SV_LEFT_DPI_INC:
Expand Down Expand Up @@ -312,11 +309,10 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
snipe_x *= 5;
snipe_y *= 5;
return false;
case SV_LEFT_SCROLL_HOLD:
left_scroll_hold = true;
case SV_SCROLL_HOLD:
scroll_hold = true;
return false;
case SV_RIGHT_SCROLL_HOLD:
right_scroll_hold = true;
case SV_SCROLL_TOGGLE:
return false;
case SV_OUTPUT_STATUS:
output_keyboard_info();
Expand Down Expand Up @@ -350,11 +346,11 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
snipe_x /= 5;
snipe_y /= 5;
return false;
case SV_LEFT_SCROLL_HOLD:
left_scroll_hold = false;
case SV_SCROLL_HOLD:
scroll_hold = false;
return false;
case SV_RIGHT_SCROLL_HOLD:
right_scroll_hold = false;
case SV_SCROLL_TOGGLE:
scroll_toggle ^= true;
return false;
}
}
Expand All @@ -365,16 +361,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {

#if defined MH_AUTO_BUTTONS && defined PS2_MOUSE_ENABLE && defined MOUSEKEY_ENABLE
void ps2_mouse_moved_user(report_mouse_t *mouse_report) {
if (mh_auto_buttons_timer) {
mh_auto_buttons_timer = timer_read();
} else {
if (!tp_buttons) {
mouse_mode(true);
#if defined CONSOLE_ENABLE
print("ps2 / mh_auto_buttons: on\n");
#endif
}
}
mouse_mode(true);
}
#endif

Expand All @@ -383,7 +370,7 @@ void matrix_scan_kb(void) {
achordion_task();
}

if ((mh_timer_choices[global_saved_values.mh_timer_index] >= 0) && mh_auto_buttons_timer && (timer_elapsed(mh_auto_buttons_timer) > mh_timer_choices[global_saved_values.mh_timer_index])) {
if ((mh_timer_choices[global_saved_values.mh_timer_index] >= 0) && mouse_mode_enabled && (timer_elapsed(mh_auto_buttons_timer) > mh_timer_choices[global_saved_values.mh_timer_index]) && mouse_keys_pressed == 0) {
if (!tp_buttons) {
mouse_mode(false);
#if defined CONSOLE_ENABLE
Expand All @@ -399,8 +386,11 @@ void mouse_mode(bool on) {
if (on) {
layer_on(MH_AUTO_BUTTONS_LAYER);
mh_auto_buttons_timer = timer_read();
mouse_mode_enabled = true;
} else {
layer_off(MH_AUTO_BUTTONS_LAYER);
mh_auto_buttons_timer = 0;
mouse_mode_enabled = false;
mouse_keys_pressed = 0;
}
}
4 changes: 2 additions & 2 deletions keyboards/svalboard/keymaps/keymap_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ enum my_keycodes {
SV_SNIPER_2,
SV_SNIPER_3,
SV_SNIPER_5,
SV_LEFT_SCROLL_HOLD,
SV_RIGHT_SCROLL_HOLD,
SV_SCROLL_HOLD,
SV_SCROLL_TOGGLE,
SV_OUTPUT_STATUS,
// New keycodes should go here, to avoid breaking existing keymaps - order must match vial.json
KC_NORMAL_HOLD = SAFE_RANGE,
Expand Down
22 changes: 20 additions & 2 deletions keyboards/svalboard/keymaps/vial/keymap.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there probably be a corresponding change to the default .vils?

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LAYER_COLOR(layer1_colors, HSV_ORANGE); // FUNC
LAYER_COLOR(layer2_colors, HSV_AZURE); // NAS
LAYER_COLOR(layer3_colors, HSV_CORAL); // FKEYS
LAYER_COLOR(layer4_colors, HSV_YELLOW); // use for NORMAL hold?
LAYER_COLOR(layer5_colors, HSV_PURPLE); // use for FUNC hold?
LAYER_COLOR(layer5_colors, HSV_TEAL); // use for FUNC hold?
LAYER_COLOR(layer6_colors, HSV_RED); // use for NAS hold
LAYER_COLOR(layer7_colors, HSV_RED);
LAYER_COLOR(layer8_colors, HSV_PINK);
Expand Down Expand Up @@ -77,6 +77,7 @@ enum layer {
NORMAL,
FUNC,
NAS,
BOARD_CONFIG,
MBO = MH_AUTO_BUTTONS_LAYER,
};

Expand Down Expand Up @@ -109,7 +110,7 @@ const uint16_t PROGMEM keymaps[DYNAMIC_KEYMAP_LAYER_COUNT][MATRIX_ROWS][MATRIX_C
/*L1*/ KC_HOME, KC_UP, KC_RIGHT, KC_DOWN, KC_LEFT, XXXXXXX,
/*L2*/ XXXXXXX, KC_F6, XXXXXXX, KC_F5, XXXXXXX, XXXXXXX,
/*L3*/ XXXXXXX, KC_F4, XXXXXXX, KC_F3, KC_ESC, XXXXXXX,
/*L4*/ XXXXXXX, KC_F2, XXXXXXX, KC_F1, KC_DEL, XXXXXXX,
/*L4*/ TO(BOARD_CONFIG), KC_F2, XXXXXXX, KC_F1, KC_DEL, XXXXXXX,

/* Down Pad Up Nail Knuckle DoubleDown*/
/*RT*/ MO(NAS), KC_SPACE, _______, KC_BSPC, KC_LALT, _______,
Expand All @@ -133,6 +134,23 @@ const uint16_t PROGMEM keymaps[DYNAMIC_KEYMAP_LAYER_COUNT][MATRIX_ROWS][MATRIX_C
/*LT*/ KC_LSFT, KC_ENTER, _______, KC_TAB, KC_LCTL, _______
),

[BOARD_CONFIG] = LAYOUT(
/* Center North East South West (XXX) */
/* R1 */ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, -1,
/* R2 */ KC_TRNS, RGB_VAI, KC_TRNS, RGB_VAD, KC_TRNS, -1,
/* R3 */ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, -1,
/* R4 */ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, -1,

/* L1 */ SV_OUTPUT_STATUS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, -1,
/* L2 */ SV_RIGHT_SCROLL_TOGGLE, SV_RIGHT_DPI_INC, KC_TRNS, SV_RIGHT_DPI_DEC, KC_TRNS, -1,
/* L3 */ SV_LEFT_SCROLL_TOGGLE, SV_LEFT_DPI_INC, KC_TRNS, SV_LEFT_DPI_DEC, KC_TRNS, -1,
/* L4 */ SV_MH_CHANGE_TIMEOUTS, SV_TOGGLE_ACHORDION, KC_TRNS, KC_TRNS, KC_TRNS, -1,

/* Down Pad Up Nail Knuckle Double Down */
/* RT */ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
/* LT */ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
),

[MBO] = LAYOUT(
/*Center North East South West*/
/*R1*/ KC_BTN1, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, XXXXXXX,
Expand Down
10 changes: 5 additions & 5 deletions keyboards/svalboard/keymaps/vial/vial.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,20 @@
"name": "SV_SNIPER_5"
},
{
"shortName": "Scroll\nLeft\nHold",
"shortName": "Scroll\nToggle\nHold",
"title": "Hold to make the left pointing device scroll",
"name": "SV_LEFT_SCROLL_HOLD"
"name": "SV_SCROLL_HOLD"
},
{
"shortName": "Scroll\nRight\nHold",
"shortName": "Scroll\nToggle",
"title": "Hold to make the right pointing device scroll",
"name": "SV_RIGHT_SCROLL_HOLD"
"name": "SV_SCROLL_TOGGLE"
},
{
"shortName": "Output\nStatus",
"title": "Output the current internal state of the keyboard.",
"name": "SV_OUTPUT_STATUS"
}
}
],
"layouts": {
"keymap": [
Expand Down
4 changes: 2 additions & 2 deletions keyboards/svalboard/svalboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "version.h"

saved_values_t global_saved_values;
const int16_t mh_timer_choices[3] = { 300, 500, -1 }; // -1 is infinite.
const int16_t mh_timer_choices[4] = { 300, 500, 800, -1 }; // -1 is infinite.

void write_eeprom_kb(void) {
eeconfig_update_kb_datablock(&global_saved_values);
Expand All @@ -20,7 +20,7 @@ void read_eeprom_kb(void) {
}
if (global_saved_values.version < 2) {
global_saved_values.version = 2;
global_saved_values.mh_timer_index = 2;
global_saved_values.mh_timer_index = 1;
modified = true;
}
// As we add versions, just append here.
Expand Down
2 changes: 1 addition & 1 deletion keyboards/svalboard/svalboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include "quantum.h"

extern const int16_t mh_timer_choices[3];
extern const int16_t mh_timer_choices[4];

struct saved_values {
uint8_t version; // Currently at 1, We assume all new data will be zeroed.
Expand Down