From 316473d34cf13e8aab7b6c3efe4f13d0b297778f Mon Sep 17 00:00:00 2001 From: Mitsutaka Mimura Date: Tue, 24 Aug 2021 22:20:27 +0900 Subject: [PATCH 1/3] introduce keycode alias QMK's keycode has alias. I'd like to use it. --- src/ruby/lib/keyboard.rb | 71 +++++++++++++++++++++++++++++++++++++++ src/ruby/sig/keyboard.rbs | 1 + 2 files changed, 72 insertions(+) diff --git a/src/ruby/lib/keyboard.rb b/src/ruby/lib/keyboard.rb index 4a69c36b..0335689c 100644 --- a/src/ruby/lib/keyboard.rb +++ b/src/ruby/lib/keyboard.rb @@ -332,6 +332,76 @@ class Keyboard '>', '?' ] + KC_ALIASES = { + KC_ENT: :KC_ENTER, + KC_ESC: :KC_ESCAPE, + KC_BSPC: :KC_BSPACE, + KC_SPC: :KC_SPACE, + KC_MINS: :KC_MINUS, + KC_EQL: :KC_EQUAL, + KC_LBRC: :KC_LBRACKET, + KC_RBRC: :KC_RBRACKET, + KC_BSLS: :KC_BSLASH, + KC_NUHS: :KC_NONUS_HASH, + KC_SCLN: :KC_SCOLON, + KC_QUOT: :KC_QUOTE, + KC_GRV: :KC_GRAVE, + KC_ZKHK: :KC_GRAVE, + KC_COMM: :KC_COMMA, + KC_SLSH: :KC_SLASH, + KC_NUBS: :KC_NONUS_BSLASH, + KC_CLCK: :KC_CAPSLOCK, + KC_CAPS: :KC_CAPSLOCK, + KC_SLCK: :KC_SCROLLLOCK, + KC_BRMD: :KC_SCROLLLOCK, + KC_NLCK: :KC_NUMLOCK, + KC_LCTRL: :KC_LCTL, + KC_LSHIFT: :KC_LSFT, + KC_LOPT: :KC_LALT, + KC_LCMD: :KC_LGUI, + KC_LWIN: :KC_LGUI, + KC_RCTRL: :KC_RCTL, + KC_RSHIFT: :KC_RSFT, + KC_ROPT: :KC_RALT, + KC_ALGR: :KC_RALT, + KC_RCMD: :KC_RGUI, + KC_RWIN: :KC_RGUI, + KC_HAEN: :KC_LANG1, + KC_HANJ: :KC_LANG2, + KC_PSCR: :KC_PSCREEN, + KC_PAUS: :KC_PAUSE, + KC_BRK: :KC_PAUSE, + KC_BRMU: :KC_PAUSE, + KC_INS: :KC_INSERT, + KC_DEL: :KC_DELETE, + KC_PGDN: :KC_PGDOWN, + KC_RGHT: :KC_RIGHT, + KC_APP: :KC_APPLICATION, + KC_EXEC: :KC_EXECUTE, + KC_SLCT: :KC_SELECT, + KC_AGIN: :KC_AGAIN, + KC_PSTE: :KC_PASTE, + KC_ERAS: :KC_ALT_ERASE, + KC_CLR: :KC_CLEAR, + KC_PSLS: :KC_KP_SLASH, + KC_PAST: :KC_KP_ASTERISK, + KC_PMNS: :KC_KP_MINUS, + KC_PPLS: :KC_KP_PLUS, + KC_PENT: :KC_KP_ENTER, + KC_P1: :KC_KP_1, + KC_P2: :KC_KP_2, + KC_P3: :KC_KP_3, + KC_P4: :KC_KP_4, + KC_P5: :KC_KP_5, + KC_P6: :KC_KP_6, + KC_P7: :KC_KP_7, + KC_P8: :KC_KP_8, + KC_P9: :KC_KP_9, + KC_P0: :KC_KP_0, + KC_PDOT: :KC_KP_DOT, + KC_PEQL: :KC_KP_EQUAL, + XXXXXXX: :KC_NO, + } letter = nil def initialize @@ -437,6 +507,7 @@ def add_layer(name, map) cols_size = @split ? @cols.size * 2 : @cols.size map.each do |key| new_map[row_index] = Array.new(@cols.size) if col_index == 0 + key = KC_ALIASES[key] ? KC_ALIASES[key] : key keycode_index = KEYCODE.index(key) new_map[row_index][col_index] = if keycode_index keycode_index * -1 diff --git a/src/ruby/sig/keyboard.rbs b/src/ruby/sig/keyboard.rbs index af28b14e..1a9d3cb0 100644 --- a/src/ruby/sig/keyboard.rbs +++ b/src/ruby/sig/keyboard.rbs @@ -13,6 +13,7 @@ class Keyboard KEYCODE: Array[Symbol] KEYCODE_SFT: Hash[Symbol, Integer] LETTER: Array[String | Symbol | nil] + KC_ALIASES: Hash[Symbol, Symbol] @SHIFT_LETTER_OFFSET_A: Integer @SHIFT_LETTER_OFFSET_UNDS: Integer From 9973e5e48b5e45a3a0c55e9346bf8be0600fbcb4 Mon Sep 17 00:00:00 2001 From: Mitsutaka Mimura Date: Fri, 17 Sep 2021 00:23:41 +0900 Subject: [PATCH 2/3] comment out some aliases mruby/c can't allocate big Hash. So, I give up some aliases. --- src/ruby/lib/keyboard.rb | 92 ++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/ruby/lib/keyboard.rb b/src/ruby/lib/keyboard.rb index 0335689c..57aace8e 100644 --- a/src/ruby/lib/keyboard.rb +++ b/src/ruby/lib/keyboard.rb @@ -342,64 +342,64 @@ class Keyboard KC_LBRC: :KC_LBRACKET, KC_RBRC: :KC_RBRACKET, KC_BSLS: :KC_BSLASH, - KC_NUHS: :KC_NONUS_HASH, - KC_SCLN: :KC_SCOLON, + # KC_NUHS: :KC_NONUS_HASH, + # KC_SCLN: :KC_SCOLON, KC_QUOT: :KC_QUOTE, KC_GRV: :KC_GRAVE, KC_ZKHK: :KC_GRAVE, KC_COMM: :KC_COMMA, KC_SLSH: :KC_SLASH, - KC_NUBS: :KC_NONUS_BSLASH, - KC_CLCK: :KC_CAPSLOCK, + # KC_NUBS: :KC_NONUS_BSLASH, + # KC_CLCK: :KC_CAPSLOCK, KC_CAPS: :KC_CAPSLOCK, - KC_SLCK: :KC_SCROLLLOCK, - KC_BRMD: :KC_SCROLLLOCK, - KC_NLCK: :KC_NUMLOCK, - KC_LCTRL: :KC_LCTL, - KC_LSHIFT: :KC_LSFT, - KC_LOPT: :KC_LALT, - KC_LCMD: :KC_LGUI, - KC_LWIN: :KC_LGUI, - KC_RCTRL: :KC_RCTL, - KC_RSHIFT: :KC_RSFT, - KC_ROPT: :KC_RALT, - KC_ALGR: :KC_RALT, - KC_RCMD: :KC_RGUI, - KC_RWIN: :KC_RGUI, + # KC_SLCK: :KC_SCROLLLOCK, + # KC_BRMD: :KC_SCROLLLOCK, + # KC_NLCK: :KC_NUMLOCK, + # KC_LCTRL: :KC_LCTL, + # KC_LSHIFT: :KC_LSFT, + # KC_LOPT: :KC_LALT, + # KC_LCMD: :KC_LGUI, + # KC_LWIN: :KC_LGUI, + # KC_RCTRL: :KC_RCTL, + # KC_RSHIFT: :KC_RSFT, + # KC_ROPT: :KC_RALT, + # KC_ALGR: :KC_RALT, + # KC_RCMD: :KC_RGUI, + # KC_RWIN: :KC_RGUI, KC_HAEN: :KC_LANG1, KC_HANJ: :KC_LANG2, - KC_PSCR: :KC_PSCREEN, - KC_PAUS: :KC_PAUSE, - KC_BRK: :KC_PAUSE, - KC_BRMU: :KC_PAUSE, + # KC_PSCR: :KC_PSCREEN, + # KC_PAUS: :KC_PAUSE, + # KC_BRK: :KC_PAUSE, + # KC_BRMU: :KC_PAUSE, KC_INS: :KC_INSERT, KC_DEL: :KC_DELETE, KC_PGDN: :KC_PGDOWN, KC_RGHT: :KC_RIGHT, - KC_APP: :KC_APPLICATION, - KC_EXEC: :KC_EXECUTE, - KC_SLCT: :KC_SELECT, - KC_AGIN: :KC_AGAIN, - KC_PSTE: :KC_PASTE, - KC_ERAS: :KC_ALT_ERASE, - KC_CLR: :KC_CLEAR, - KC_PSLS: :KC_KP_SLASH, - KC_PAST: :KC_KP_ASTERISK, - KC_PMNS: :KC_KP_MINUS, - KC_PPLS: :KC_KP_PLUS, - KC_PENT: :KC_KP_ENTER, - KC_P1: :KC_KP_1, - KC_P2: :KC_KP_2, - KC_P3: :KC_KP_3, - KC_P4: :KC_KP_4, - KC_P5: :KC_KP_5, - KC_P6: :KC_KP_6, - KC_P7: :KC_KP_7, - KC_P8: :KC_KP_8, - KC_P9: :KC_KP_9, - KC_P0: :KC_KP_0, - KC_PDOT: :KC_KP_DOT, - KC_PEQL: :KC_KP_EQUAL, + # KC_APP: :KC_APPLICATION, + # KC_EXEC: :KC_EXECUTE, + # KC_SLCT: :KC_SELECT, + # KC_AGIN: :KC_AGAIN, + # KC_PSTE: :KC_PASTE, + # KC_ERAS: :KC_ALT_ERASE, + # KC_CLR: :KC_CLEAR, + # KC_PSLS: :KC_KP_SLASH, + # KC_PAST: :KC_KP_ASTERISK, + # KC_PMNS: :KC_KP_MINUS, + # KC_PPLS: :KC_KP_PLUS, + # KC_PENT: :KC_KP_ENTER, + # KC_P1: :KC_KP_1, + # KC_P2: :KC_KP_2, + # KC_P3: :KC_KP_3, + # KC_P4: :KC_KP_4, + # KC_P5: :KC_KP_5, + # KC_P6: :KC_KP_6, + # KC_P7: :KC_KP_7, + # KC_P8: :KC_KP_8, + # KC_P9: :KC_KP_9, + # KC_P0: :KC_KP_0, + # KC_PDOT: :KC_KP_DOT, + # KC_PEQL: :KC_KP_EQUAL, XXXXXXX: :KC_NO, } letter = nil From a11ac2c8978135669c5c1e66026758902078b513 Mon Sep 17 00:00:00 2001 From: Mitsutaka Mimura Date: Fri, 17 Sep 2021 00:24:51 +0900 Subject: [PATCH 3/3] support aliase in define_mode_key --- src/ruby/lib/keyboard.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ruby/lib/keyboard.rb b/src/ruby/lib/keyboard.rb index 57aace8e..61ca06d2 100644 --- a/src/ruby/lib/keyboard.rb +++ b/src/ruby/lib/keyboard.rb @@ -546,11 +546,12 @@ def define_mode_key(key_name, param) on_release_action = case on_release.class when Symbol # @type var on_release: Symbol - keycode_index = KEYCODE.index(on_release) + key = KC_ALIASES[on_release] ? KC_ALIASES[on_release] : on_release + keycode_index = KEYCODE.index(key) if keycode_index keycode_index * -1 - elsif KEYCODE_SFT[on_release] - (KEYCODE_SFT[on_release] + 0x100) * -1 + elsif KEYCODE_SFT[key] + (KEYCODE_SFT[key] + 0x100) * -1 end when Array # @type var on_release: Array[Symbol]