diff --git a/keyboards/bastardkb/charybdis/3x5/keymaps/via/keymap.c b/keyboards/bastardkb/charybdis/3x5/keymaps/via/keymap.c index d701dbcd0b59..f15fe1bd683c 100644 --- a/keyboards/bastardkb/charybdis/3x5/keymaps/via/keymap.c +++ b/keyboards/bastardkb/charybdis/3x5/keymaps/via/keymap.c @@ -45,31 +45,6 @@ static uint16_t auto_pointer_layer_timer = 0; #endif // CHARYBDIS_AUTO_POINTER_LAYER_TRIGGER_THRESHOLD #endif // CHARYBDIS_AUTO_POINTER_LAYER_TRIGGER_ENABLE -enum charybdis_keymap_keycodes { -#ifdef VIA_ENABLE - POINTER_DEFAULT_DPI_FORWARD = USER00, -#else - POINTER_DEFAULT_DPI_FORWARD = SAFE_RANGE, -#endif // VIA_ENABLE - POINTER_DEFAULT_DPI_REVERSE, - POINTER_SNIPING_DPI_FORWARD, - POINTER_SNIPING_DPI_REVERSE, - SNIPING_MODE, - SNIPING_MODE_TOGGLE, - DRAGSCROLL_MODE, - DRAGSCROLL_MODE_TOGGLE, - KEYMAP_SAFE_RANGE, -}; - -#define DPI_MOD POINTER_DEFAULT_DPI_FORWARD -#define DPI_RMOD POINTER_DEFAULT_DPI_REVERSE -#define S_D_MOD POINTER_SNIPING_DPI_FORWARD -#define S_D_RMOD POINTER_SNIPING_DPI_REVERSE -#define SNIPING SNIPING_MODE -#define SNP_TOG SNIPING_MODE_TOGGLE -#define DRGSCRL DRAGSCROLL_MODE -#define DRG_TOG DRAGSCROLL_MODE_TOGGLE - #define ESC_MED LT(LAYER_MEDIA, KC_ESC) #define SPC_NAV LT(LAYER_NAVIGATION, KC_SPC) #define TAB_FUN LT(LAYER_FUNCTION, KC_TAB) @@ -233,64 +208,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; // clang-format on -/** \brief Whether SHIFT mod is enabled. */ -static bool has_shift_mod(void) { -#ifdef NO_ACTION_ONESHOT - return mod_config(get_mods()) & MOD_MASK_SHIFT; -#else - return mod_config(get_mods() | get_oneshot_mods()) & MOD_MASK_SHIFT; -#endif // NO_ACTION_ONESHOT -} - #ifdef POINTING_DEVICE_ENABLE -bool process_record_user(uint16_t keycode, keyrecord_t* record) { - switch (keycode) { - case POINTER_DEFAULT_DPI_FORWARD: - if (record->event.pressed) { - // Step backward if shifted, forward otherwise. - charybdis_cycle_pointer_default_dpi(/* forward= */ !has_shift_mod()); - } - break; - case POINTER_DEFAULT_DPI_REVERSE: - if (record->event.pressed) { - // Step forward if shifted, backward otherwise. - charybdis_cycle_pointer_default_dpi(/* forward= */ has_shift_mod()); - } - break; - case POINTER_SNIPING_DPI_FORWARD: - if (record->event.pressed) { - // Step backward if shifted, forward otherwise. - charybdis_cycle_pointer_sniping_dpi(/* forward= */ !has_shift_mod()); - } - break; - case POINTER_SNIPING_DPI_REVERSE: - if (record->event.pressed) { - // Step forward if shifted, backward otherwise. - charybdis_cycle_pointer_sniping_dpi(/* forward= */ has_shift_mod()); - } - break; - case SNIPING_MODE: - charybdis_set_pointer_sniping_enabled(record->event.pressed); - break; - case SNIPING_MODE_TOGGLE: - if (record->event.pressed) { - charybdis_set_pointer_sniping_enabled( - !charybdis_get_pointer_sniping_enabled()); - } - break; - case DRAGSCROLL_MODE: - charybdis_set_pointer_dragscroll_enabled(record->event.pressed); - break; - case DRAGSCROLL_MODE_TOGGLE: - if (record->event.pressed) { - charybdis_set_pointer_dragscroll_enabled( - !charybdis_get_pointer_dragscroll_enabled()); - } - break; - } - return true; -} - #ifdef CHARYBDIS_AUTO_POINTER_LAYER_TRIGGER_ENABLE report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { if (abs(mouse_report.x) > CHARYBDIS_AUTO_POINTER_LAYER_TRIGGER_THRESHOLD || diff --git a/keyboards/bastardkb/charybdis/4x6/keymaps/via/keymap.c b/keyboards/bastardkb/charybdis/4x6/keymaps/via/keymap.c index 9a6e7d6d7008..5cd1cceee03c 100644 --- a/keyboards/bastardkb/charybdis/4x6/keymaps/via/keymap.c +++ b/keyboards/bastardkb/charybdis/4x6/keymaps/via/keymap.c @@ -42,31 +42,6 @@ static uint16_t auto_pointer_layer_timer = 0; #endif // CHARYBDIS_AUTO_POINTER_LAYER_TRIGGER_THRESHOLD #endif // CHARYBDIS_AUTO_POINTER_LAYER_TRIGGER_ENABLE -enum charybdis_keymap_keycodes { -#ifdef VIA_ENABLE - POINTER_DEFAULT_DPI_FORWARD = USER00, -#else - POINTER_DEFAULT_DPI_FORWARD = SAFE_RANGE, -#endif // VIA_ENABLE - POINTER_DEFAULT_DPI_REVERSE, - POINTER_SNIPING_DPI_FORWARD, - POINTER_SNIPING_DPI_REVERSE, - SNIPING_MODE, - SNIPING_MODE_TOGGLE, - DRAGSCROLL_MODE, - DRAGSCROLL_MODE_TOGGLE, - KEYMAP_SAFE_RANGE, -}; - -#define DPI_MOD POINTER_DEFAULT_DPI_FORWARD -#define DPI_RMOD POINTER_DEFAULT_DPI_REVERSE -#define S_D_MOD POINTER_SNIPING_DPI_FORWARD -#define S_D_RMOD POINTER_SNIPING_DPI_REVERSE -#define SNIPING SNIPING_MODE -#define SNP_TOG SNIPING_MODE_TOGGLE -#define DRGSCRL DRAGSCROLL_MODE -#define DRG_TOG DRAGSCROLL_MODE_TOGGLE - #define LOWER MO(LAYER_LOWER) #define RAISE MO(LAYER_RAISE) #define PT_Z LT(LAYER_POINTER, KC_Z) @@ -136,64 +111,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; // clang-format on -/** /brief Whether SHIFT mod is enabled. */ -static bool has_shift_mod(void) { -#ifdef NO_ACTION_ONESHOT - return mod_config(get_mods()) & MOD_MASK_SHIFT; -#else - return mod_config(get_mods() | get_oneshot_mods()) & MOD_MASK_SHIFT; -#endif // NO_ACTION_ONESHOT -} - #ifdef POINTING_DEVICE_ENABLE -bool process_record_user(uint16_t keycode, keyrecord_t* record) { - switch (keycode) { - case POINTER_DEFAULT_DPI_FORWARD: - if (record->event.pressed) { - // Step backward if shifted, forward otherwise. - charybdis_cycle_pointer_default_dpi(/* forward= */ !has_shift_mod()); - } - break; - case POINTER_DEFAULT_DPI_REVERSE: - if (record->event.pressed) { - // Step forward if shifted, backward otherwise. - charybdis_cycle_pointer_default_dpi(/* forward= */ has_shift_mod()); - } - break; - case POINTER_SNIPING_DPI_FORWARD: - if (record->event.pressed) { - // Step backward if shifted, forward otherwise. - charybdis_cycle_pointer_sniping_dpi(/* forward= */ !has_shift_mod()); - } - break; - case POINTER_SNIPING_DPI_REVERSE: - if (record->event.pressed) { - // Step forward if shifted, backward otherwise. - charybdis_cycle_pointer_sniping_dpi(/* forward= */ has_shift_mod()); - } - break; - case SNIPING_MODE: - charybdis_set_pointer_sniping_enabled(record->event.pressed); - break; - case SNIPING_MODE_TOGGLE: - if (record->event.pressed) { - charybdis_set_pointer_sniping_enabled( - !charybdis_get_pointer_sniping_enabled()); - } - break; - case DRAGSCROLL_MODE: - charybdis_set_pointer_dragscroll_enabled(record->event.pressed); - break; - case DRAGSCROLL_MODE_TOGGLE: - if (record->event.pressed) { - charybdis_set_pointer_dragscroll_enabled( - !charybdis_get_pointer_dragscroll_enabled()); - } - break; - } - return true; -} - #ifdef CHARYBDIS_AUTO_POINTER_LAYER_TRIGGER_ENABLE report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { if (abs(mouse_report.x) > CHARYBDIS_AUTO_POINTER_LAYER_TRIGGER_THRESHOLD || diff --git a/keyboards/bastardkb/charybdis/charybdis.c b/keyboards/bastardkb/charybdis/charybdis.c index 3e7088a0580a..dcefbd9bd404 100644 --- a/keyboards/bastardkb/charybdis/charybdis.c +++ b/keyboards/bastardkb/charybdis/charybdis.c @@ -254,6 +254,17 @@ report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { return mouse_report; } +#if defined(POINTING_DEVICE_ENABLE) && !defined(NO_CHARYBDIS_KEYCODES) +/** \brief Whether SHIFT mod is enabled. */ +static bool has_shift_mod(void) { +#ifdef NO_ACTION_ONESHOT + return mod_config(get_mods()) & MOD_MASK_SHIFT; +#else + return mod_config(get_mods() | get_oneshot_mods()) & MOD_MASK_SHIFT; +#endif // NO_ACTION_ONESHOT +} +#endif // POINTING_DEVICE_ENABLE && !NO_CHARYBDIS_KEYCODES + bool process_record_kb(uint16_t keycode, keyrecord_t* record) { #ifdef CONSOLE_ENABLE dprintf( @@ -276,6 +287,53 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { if (!process_record_user(keycode, record)) { return false; } +#ifdef POINTING_DEVICE_ENABLE +#ifndef NO_CHARYBDIS_KEYCODES + switch (keycode) { + case POINTER_DEFAULT_DPI_FORWARD: + if (record->event.pressed) { + // Step backward if shifted, forward otherwise. + charybdis_cycle_pointer_default_dpi(/* forward= */ !has_shift_mod()); + } + break; + case POINTER_DEFAULT_DPI_REVERSE: + if (record->event.pressed) { + // Step forward if shifted, backward otherwise. + charybdis_cycle_pointer_default_dpi(/* forward= */ has_shift_mod()); + } + break; + case POINTER_SNIPING_DPI_FORWARD: + if (record->event.pressed) { + // Step backward if shifted, forward otherwise. + charybdis_cycle_pointer_sniping_dpi(/* forward= */ !has_shift_mod()); + } + break; + case POINTER_SNIPING_DPI_REVERSE: + if (record->event.pressed) { + // Step forward if shifted, backward otherwise. + charybdis_cycle_pointer_sniping_dpi(/* forward= */ has_shift_mod()); + } + break; + case SNIPING_MODE: + charybdis_set_pointer_sniping_enabled(record->event.pressed); + break; + case SNIPING_MODE_TOGGLE: + if (record->event.pressed) { + charybdis_set_pointer_sniping_enabled( + !charybdis_get_pointer_sniping_enabled()); + } + break; + case DRAGSCROLL_MODE: + charybdis_set_pointer_dragscroll_enabled(record->event.pressed); + break; + case DRAGSCROLL_MODE_TOGGLE: + if (record->event.pressed) { + charybdis_set_pointer_dragscroll_enabled( + !charybdis_get_pointer_dragscroll_enabled()); + } + break; + } +#endif // !NO_CHARYBDIS_KEYCODES #ifndef MOUSEKEY_ENABLE // Simulate mouse keys if full support is not enabled (reduces firmware size // while maintaining support for mouse keys). @@ -287,6 +345,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { pointing_device_send(); } #endif // !MOUSEKEY_ENABLE +#endif // POINTING_DEVICE_ENABLE return true; } diff --git a/keyboards/bastardkb/charybdis/charybdis.h b/keyboards/bastardkb/charybdis/charybdis.h index 57f3f9dee7c0..b75d152ba5ac 100644 --- a/keyboards/bastardkb/charybdis/charybdis.h +++ b/keyboards/bastardkb/charybdis/charybdis.h @@ -31,6 +31,33 @@ #ifdef POINTING_DEVICE_ENABLE #include "quantum.h" +#ifndef NO_CHARYBDIS_KEYCODES +enum charybdis_keycodes { +#ifdef VIA_ENABLE + POINTER_DEFAULT_DPI_FORWARD = USER00, +#else + POINTER_DEFAULT_DPI_FORWARD = SAFE_RANGE, +#endif // VIA_ENABLE + POINTER_DEFAULT_DPI_REVERSE, + POINTER_SNIPING_DPI_FORWARD, + POINTER_SNIPING_DPI_REVERSE, + SNIPING_MODE, + SNIPING_MODE_TOGGLE, + DRAGSCROLL_MODE, + DRAGSCROLL_MODE_TOGGLE, + CHARYBDIS_SAFE_RANGE, +}; + +#define DPI_MOD POINTER_DEFAULT_DPI_FORWARD +#define DPI_RMOD POINTER_DEFAULT_DPI_REVERSE +#define S_D_MOD POINTER_SNIPING_DPI_FORWARD +#define S_D_RMOD POINTER_SNIPING_DPI_REVERSE +#define SNIPING SNIPING_MODE +#define SNP_TOG SNIPING_MODE_TOGGLE +#define DRGSCRL DRAGSCROLL_MODE +#define DRG_TOG DRAGSCROLL_MODE_TOGGLE +#endif // !NO_CHARYBDIS_KEYCODES + /** \brief Return the current DPI value for the pointer's default mode. */ uint32_t charybdis_get_pointer_default_dpi(void); diff --git a/keyboards/bastardkb/charybdis/readme.md b/keyboards/bastardkb/charybdis/readme.md index 2c6fe8ae34b8..acd32c353a95 100644 --- a/keyboards/bastardkb/charybdis/readme.md +++ b/keyboards/bastardkb/charybdis/readme.md @@ -156,3 +156,55 @@ The acceleration factor can be further tune _via_ the ```c #define CHARYBDIS_POINTER_ACCELERATION_FACTOR 24 ``` + +### Custom keycodes + +The Charybdis firmware defines a number of keycodes to leverage its features, +namely: + +``` +#ifndef NO_CHARYBDIS_KEYCODES +enum charybdis_keycodes { + POINTER_DEFAULT_DPI_FORWARD = SAFE_RANGE, + POINTER_DEFAULT_DPI_REVERSE, + POINTER_SNIPING_DPI_FORWARD, + POINTER_SNIPING_DPI_REVERSE, + SNIPING_MODE, + SNIPING_MODE_TOGGLE, + DRAGSCROLL_MODE, + DRAGSCROLL_MODE_TOGGLE, + CHARYBDIS_SAFE_RANGE, +}; + +#define DPI_MOD POINTER_DEFAULT_DPI_FORWARD +#define DPI_RMOD POINTER_DEFAULT_DPI_REVERSE +#define S_D_MOD POINTER_SNIPING_DPI_FORWARD +#define S_D_RMOD POINTER_SNIPING_DPI_REVERSE +#define SNIPING SNIPING_MODE +#define SNP_TOG SNIPING_MODE_TOGGLE +#define DRGSCRL DRAGSCROLL_MODE +#define DRG_TOG DRAGSCROLL_MODE_TOGGLE +#endif // !NO_CHARYBDIS_KEYCODES +``` + +Users extending the keycode set themselves (either in their keymap, or in their +userspace) must start at `CHARYBDIS_SAFE_RANGE` to avoid conflicts, _eg._: + +```c +enum userspace_keycodes { +#ifndef NO_CHARYBDIS_KEYCODES + MY_FIRST_KEYCODE = CHARYBDIS_SAFE_RANGE, +#else + MY_FIRST_KEYCODE = SAFE_RANGE, +#endif // !NO_CHARYBDIS_KEYCODES + MY_SECOND_KEYCODE, + … +}; +``` + +To disable the custom keycodes, and reduce binary size, simply add a definition +in `config.h`: + +```c +#define NO_CHARYBDIS_KEYCODES +```