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

Cleanup keymap_support.c #64

Merged
merged 7 commits into from
Aug 3, 2024
Merged
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
138 changes: 64 additions & 74 deletions keyboards/svalboard/keymaps/keymap_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "features/achordion.h"
#include "keymap_support.h"

#define PS2_MOUSE_SCROLL_BTN_MASK (1<<PS2_MOUSE_BTN_MIDDLE) // this mask disables the key for non-PS2 purposes

// in keymap.c:
#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
void pointing_device_init_user(void) {
Expand All @@ -32,8 +30,7 @@ void pointing_device_init_user(void) {
}
#endif


#if (defined MH_AUTO_BUTTONS && defined PS2_MOUSE_ENABLE && defined MOUSEKEY_ENABLE) || defined(POINTING_DEVICE_AUTO_MOUSE_MH_ENABLE)
#if (defined MH_AUTO_BUTTONS && defined PS2_MOUSE_ENABLE && defined MOUSEKEY_ENABLE) || defined(POINTING_DEVICE_AUTO_MOUSE_MH_ENABLE)

static uint16_t mh_auto_buttons_timer;
extern int tp_buttons; // mousekey button state set in action.c and used in ps2_mouse.c
Expand Down Expand Up @@ -74,7 +71,7 @@ report_mouse_t pointing_device_task_combined_user(report_mouse_t reportMouse1, r
_ds_l_x -= div_x * SCROLL_DIVISOR;
}

if (div_y != 0) {
if (div_y != 0) {
reportMouse1.v += div_y;
_ds_l_y -= div_y * SCROLL_DIVISOR;
}
Expand All @@ -98,7 +95,7 @@ report_mouse_t pointing_device_task_combined_user(report_mouse_t reportMouse1, r
_ds_r_x -= div_x * SCROLL_DIVISOR;
}

if (div_y != 0) {
if (div_y != 0) {
reportMouse2.v += div_y;
_ds_r_y -= div_y * SCROLL_DIVISOR;
}
Expand Down Expand Up @@ -152,7 +149,7 @@ report_mouse_t pointing_device_task_user(report_mouse_t reportMouse) {
snipe_x -= div_x * snipe_div;
}

if (div_y != 0) {
if (div_y != 0) {
reportMouse.y = div_y;
snipe_y -= div_y * snipe_div;
}
Expand All @@ -162,12 +159,12 @@ report_mouse_t pointing_device_task_user(report_mouse_t reportMouse) {
#endif

void mh_change_timeouts(void) {
if (sizeof(mh_timer_choices)/sizeof(int16_t) - 1 <= global_saved_values.mh_timer_index) {
if (sizeof(mh_timer_choices) / sizeof(int16_t) - 1 <= global_saved_values.mh_timer_index) {
global_saved_values.mh_timer_index = 0;
} else {
global_saved_values.mh_timer_index++;
}
uprintf("mh_timer:%d\n",mh_timer_choices[global_saved_values.mh_timer_index]);
uprintf("mh_timer:%d\n", mh_timer_choices[global_saved_values.mh_timer_index]);
write_eeprom_kb();
}

Expand Down Expand Up @@ -218,7 +215,6 @@ 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 (defined MH_AUTO_BUTTONS && defined PS2_MOUSE_ENABLE && defined MOUSEKEY_ENABLE) || defined(POINTING_DEVICE_AUTO_MOUSE_MH_ENABLE)
if (mh_auto_buttons_timer) {
switch (keycode) {
case KC_BTN1:
Expand Down Expand Up @@ -256,110 +252,109 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
}
if (record->event.pressed) { // key pressed
switch (keycode) {
case SV_LEFT_SCROLL_HOLD:
left_scroll_hold = true;
break;
case SV_RIGHT_SCROLL_HOLD:
right_scroll_hold = true;
break;
case SV_LEFT_DPI_INC:
increase_left_dpi();
return false;
case SV_LEFT_DPI_DEC:
decrease_left_dpi();
return false;
case SV_RIGHT_DPI_INC:
increase_right_dpi();
return false;
case SV_RIGHT_DPI_DEC:
decrease_right_dpi();
return false;
case SV_LEFT_SCROLL_TOGGLE:
global_saved_values.left_scroll = !global_saved_values.left_scroll;
write_eeprom_kb();
return false;
case SV_RIGHT_SCROLL_TOGGLE:
global_saved_values.right_scroll = !global_saved_values.right_scroll;
write_eeprom_kb();
return false;
case SV_RECALIBRATE_POINTER:
recalibrate_pointer();
return false;
case SV_MH_CHANGE_TIMEOUTS:
mh_change_timeouts();
return false;
case SV_CAPS_WORD:
caps_word_toggle();
return false;
case SV_TOGGLE_ACHORDION:
toggle_achordion();
return false;
case SV_TOGGLE_23_67:
layer_on(2);
layer_on(3);
check_layer_67();
break;
return false;
case SV_TOGGLE_45_67:
layer_on(4);
layer_on(5);
check_layer_67();
break;
return false;
case SV_SNIPER_2:
snipe_x *= 2;
snipe_y *= 2;
snipe_div *= 2;
break;
return false;
case SV_SNIPER_3:
snipe_div *= 3;
snipe_x *= 3;
snipe_y *= 3;
break;
return false;
case SV_SNIPER_5:
snipe_div *= 5;
snipe_x *= 5;
snipe_y *= 5;
break;
return false;
case SV_LEFT_SCROLL_HOLD:
left_scroll_hold = true;
return false;
case SV_RIGHT_SCROLL_HOLD:
right_scroll_hold = true;
return false;
case SV_OUTPUT_STATUS:
output_keyboard_info();
return false;
}
} else { // key released
switch (keycode) {
case SV_LEFT_DPI_INC:
increase_left_dpi();
break;
case SV_LEFT_DPI_DEC:
decrease_left_dpi();
break;
case SV_RIGHT_DPI_INC:
increase_right_dpi();
break;
case SV_RIGHT_DPI_DEC:
decrease_right_dpi();
break;
case SV_LEFT_SCROLL_TOGGLE:
global_saved_values.left_scroll = !global_saved_values.left_scroll;
write_eeprom_kb();
break;
case SV_RIGHT_SCROLL_TOGGLE:
global_saved_values.right_scroll = !global_saved_values.right_scroll;
write_eeprom_kb();
break;
case SV_LEFT_SCROLL_HOLD:
left_scroll_hold = false;
break;
case SV_RIGHT_SCROLL_HOLD:
right_scroll_hold = false;
break;
case SV_RECALIBRATE_POINTER:
recalibrate_pointer();
break;
case SV_MH_CHANGE_TIMEOUTS:
mh_change_timeouts();
break;
case SV_CAPS_WORD:
caps_word_toggle();
break;
case SV_TOGGLE_ACHORDION:
toggle_achordion();
break;
// These keys are all holds and require un-setting upon release.
case SV_TOGGLE_23_67:
layer_off(2);
layer_off(3);
check_layer_67();
break;
return false;
case SV_TOGGLE_45_67:
layer_off(4);
layer_off(5);
check_layer_67();
break;
return false;
case SV_SNIPER_2:
snipe_div /= 2;
snipe_x /= 2;
snipe_y /= 2;
break;
return false;
case SV_SNIPER_3:
snipe_div /= 3;
snipe_x /= 3;
snipe_y /= 3;
break;
return false;
case SV_SNIPER_5:
snipe_div /= 5;
snipe_x /= 5;
snipe_y /= 5;
break;
case SV_OUTPUT_STATUS:
output_keyboard_info();
default:
break;
return false;
case SV_LEFT_SCROLL_HOLD:
left_scroll_hold = false;
return false;
case SV_RIGHT_SCROLL_HOLD:
right_scroll_hold = false;
return false;
}
}
#endif

return process_record_user(keycode, record);
SiriusStarr marked this conversation as resolved.
Show resolved Hide resolved
};
Expand All @@ -379,9 +374,6 @@ void ps2_mouse_moved_user(report_mouse_t *mouse_report) {
}
#endif



#if (defined MH_AUTO_BUTTONS && defined PS2_MOUSE_ENABLE && defined MOUSEKEY_ENABLE) || defined(POINTING_DEVICE_AUTO_MOUSE_MH_ENABLE)
void matrix_scan_kb(void) {
if (!global_saved_values.disable_achordion) {
achordion_task();
Expand Down Expand Up @@ -410,5 +402,3 @@ void mouse_mode(bool on) {
mh_auto_buttons_timer = 0;
}
}

#endif // defined MH_AUTO_BUTTONS && defined PS2_MOUSE_ENABLE && #defined MOUSEKEY_ENABLE