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

Add support for alternative keyboard layouts #200

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
#define NUM_SCREENS 2 // Will be more in the future
#define CONFIG_MODE_TIMEOUT 300000000 // 5 minutes into the future

#define NUM_LAYOUTS 3 // number of supported layouts in keyboard.c

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define CURRENT_BOARD_IS_ACTIVE_OUTPUT (global_state.active_output == global_state.board_role)

Expand Down
12 changes: 12 additions & 0 deletions src/include/user_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,15 @@
* */

#define ENFORCE_KEYBOARD_BOOT_PROTOCOL 0

/**================================================== *
* ============= Keyboard Layout =================== *
* ================================================== *
*
* KEYBOARD_LAYOUT: [0, 1] - 0 QWERTY
* 1 Dvorak
* 2 Colemak
*
* */

#define KEYBOARD_LAYOUT 0
52 changes: 42 additions & 10 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,38 @@

#include "main.h"

/* ==================================================== *
* Map hotkeys to alternative layouts
* { QWERTY, Dvorak, Colemak, ... }
* ==================================================== */

const uint8_t MAPPED_KEY_A[NUM_LAYOUTS] = {HID_KEY_A, HID_KEY_A, HID_KEY_A};
const uint8_t MAPPED_KEY_B[NUM_LAYOUTS] = {HID_KEY_B, HID_KEY_N, HID_KEY_B};
const uint8_t MAPPED_KEY_C[NUM_LAYOUTS] = {HID_KEY_C, HID_KEY_I, HID_KEY_C};
const uint8_t MAPPED_KEY_D[NUM_LAYOUTS] = {HID_KEY_D, HID_KEY_H, HID_KEY_G};
const uint8_t MAPPED_KEY_E[NUM_LAYOUTS] = {HID_KEY_E, HID_KEY_D, HID_KEY_K};
const uint8_t MAPPED_KEY_F[NUM_LAYOUTS] = {HID_KEY_F, HID_KEY_Y, HID_KEY_E};
const uint8_t MAPPED_KEY_G[NUM_LAYOUTS] = {HID_KEY_G, HID_KEY_U, HID_KEY_T};
const uint8_t MAPPED_KEY_H[NUM_LAYOUTS] = {HID_KEY_H, HID_KEY_J, HID_KEY_H};
const uint8_t MAPPED_KEY_I[NUM_LAYOUTS] = {HID_KEY_I, HID_KEY_G, HID_KEY_L};
const uint8_t MAPPED_KEY_J[NUM_LAYOUTS] = {HID_KEY_J, HID_KEY_C, HID_KEY_Y};
const uint8_t MAPPED_KEY_K[NUM_LAYOUTS] = {HID_KEY_K, HID_KEY_V, HID_KEY_N};
const uint8_t MAPPED_KEY_L[NUM_LAYOUTS] = {HID_KEY_L, HID_KEY_P, HID_KEY_U};
const uint8_t MAPPED_KEY_M[NUM_LAYOUTS] = {HID_KEY_M, HID_KEY_M, HID_KEY_M};
const uint8_t MAPPED_KEY_N[NUM_LAYOUTS] = {HID_KEY_N, HID_KEY_L, HID_KEY_J};
const uint8_t MAPPED_KEY_O[NUM_LAYOUTS] = {HID_KEY_O, HID_KEY_S, HID_KEY_SEMICOLON};
const uint8_t MAPPED_KEY_P[NUM_LAYOUTS] = {HID_KEY_P, HID_KEY_R, HID_KEY_R};
const uint8_t MAPPED_KEY_Q[NUM_LAYOUTS] = {HID_KEY_Q, HID_KEY_X, HID_KEY_Q};
const uint8_t MAPPED_KEY_R[NUM_LAYOUTS] = {HID_KEY_R, HID_KEY_O, HID_KEY_S};
const uint8_t MAPPED_KEY_S[NUM_LAYOUTS] = {HID_KEY_S, HID_KEY_SEMICOLON, HID_KEY_D};
const uint8_t MAPPED_KEY_T[NUM_LAYOUTS] = {HID_KEY_T, HID_KEY_K, HID_KEY_F};
const uint8_t MAPPED_KEY_U[NUM_LAYOUTS] = {HID_KEY_U, HID_KEY_F, HID_KEY_I};
const uint8_t MAPPED_KEY_V[NUM_LAYOUTS] = {HID_KEY_V, HID_KEY_PERIOD, HID_KEY_V};
const uint8_t MAPPED_KEY_W[NUM_LAYOUTS] = {HID_KEY_W, HID_KEY_COMMA, HID_KEY_W};
const uint8_t MAPPED_KEY_X[NUM_LAYOUTS] = {HID_KEY_X, HID_KEY_B, HID_KEY_X};
const uint8_t MAPPED_KEY_Y[NUM_LAYOUTS] = {HID_KEY_Y, HID_KEY_T, HID_KEY_O};
const uint8_t MAPPED_KEY_Z[NUM_LAYOUTS] = {HID_KEY_Z, HID_KEY_SLASH, HID_KEY_Z};

/* ==================================================== *
* Hotkeys to trigger actions via the keyboard.
* ==================================================== */
Expand All @@ -39,70 +71,70 @@ hotkey_combo_t hotkeys[] = {

/* Switch lock */
{.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
.keys = {HID_KEY_K},
.keys = {MAPPED_KEY_K[KEYBOARD_LAYOUT]},
.key_count = 1,
.acknowledge = true,
.action_handler = &switchlock_hotkey_handler},

/* Screen lock */
{.modifier = KEYBOARD_MODIFIER_RIGHTCTRL,
.keys = {HID_KEY_L},
.keys = {MAPPED_KEY_L[KEYBOARD_LAYOUT]},
.key_count = 1,
.acknowledge = true,
.action_handler = &screenlock_hotkey_handler},

/* Toggle gaming mode */
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_G},
.keys = {MAPPED_KEY_G[KEYBOARD_LAYOUT]},
.key_count = 1,
.acknowledge = true,
.action_handler = &toggle_gaming_mode_handler},

/* Enable screensaver for active output */
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_S},
.keys = {MAPPED_KEY_S[KEYBOARD_LAYOUT]},
.key_count = 1,
.acknowledge = true,
.action_handler = &enable_screensaver_hotkey_handler},

/* Disable screensaver for active output */
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_X},
.keys = {MAPPED_KEY_X[KEYBOARD_LAYOUT]},
.key_count = 1,
.acknowledge = true,
.action_handler = &disable_screensaver_hotkey_handler},

/* Erase stored config */
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_F12, HID_KEY_D},
.keys = {HID_KEY_F12, MAPPED_KEY_D[KEYBOARD_LAYOUT]},
.key_count = 2,
.acknowledge = true,
.action_handler = &wipe_config_hotkey_handler},

/* Record switch y coordinate */
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_F12, HID_KEY_Y},
.keys = {HID_KEY_F12, MAPPED_KEY_Y[KEYBOARD_LAYOUT]},
.key_count = 2,
.acknowledge = true,
.action_handler = &screen_border_hotkey_handler},

/* Switch to configuration mode */
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_C, HID_KEY_O},
.keys = {MAPPED_KEY_C[KEYBOARD_LAYOUT], MAPPED_KEY_O[KEYBOARD_LAYOUT]},
.key_count = 2,
.acknowledge = true,
.action_handler = &config_enable_hotkey_handler},

/* Hold down left shift + right shift + F12 + A ==> firmware upgrade mode for board A (kbd) */
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
.keys = {HID_KEY_A},
.keys = {MAPPED_KEY_A[KEYBOARD_LAYOUT]},
.key_count = 1,
.acknowledge = true,
.action_handler = &fw_upgrade_hotkey_handler_A},

/* Hold down left shift + right shift + F12 + B ==> firmware upgrade mode for board B (mouse) */
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
.keys = {HID_KEY_B},
.keys = {MAPPED_KEY_B[KEYBOARD_LAYOUT]},
.key_count = 1,
.acknowledge = true,
.action_handler = &fw_upgrade_hotkey_handler_B}};
Expand Down