From: tmk Date: Wed, 13 Feb 2013 00:23:52 +0000 (+0900) Subject: Make Transparent feature available to new keymaps. X-Git-Url: https://git.friedersdorff.com/?a=commitdiff_plain;h=48e6d0848cdeac26ffab101ea2ef48e5ac60acd3;p=max%2Ftmk_keyboard.git Make Transparent feature available to new keymaps. --- diff --git a/README.md b/README.md index 072de0a3..b9238922 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Source code is available here: Features -------- -* Multi-layer keymap - Multiple keyboard layouts with layer switching. +* Multi-layer Keymap - Multiple keyboard layouts with layer switching. * Mouse key - Mouse control with keyboard * System Control Key - Power Down, Sleep, Wake Up and USB Remote Wake up * Media Control Key - Volume Down/Up, Mute, Next/Prev track, Play, Stop and etc @@ -283,8 +283,11 @@ See `common/keycode.h`. Keycode is 8bit internal code to inidicate action perfor ***In `KEYMAP` definition you need to omit prefix part `KC_` of keycode to keep keymap compact.*** For example, just use `A` instead you place `KC_A` in `KEYMAP`. Some keycodes has 4-letter short name in addition to descriptive name, you'll prefer short one in `KEYMAP`. -#### 1.1 Normal key +#### 1.0 Other key - `KC_NO` for no aciton +- `KC_TRNS` for transparent layer + +#### 1.1 Normal key - `KC_A` to `KC_Z`, `KC_1` to `KC_0` for alpha numeric key - `KC_MINS`, `KC_EQL`, `KC_GRV`, `KC_RBRC`, `KC_LBRC`, `KC_COMM`, `KC_DOT`, `KC_BSLS`, `KC_SLSH`, `KC_SCLN`, `KC_QUOT` - `KC_ESC`, `KC_TAB`, `KC_SPC`, `KC_BSPC`, `KC_ENT`, `KC_DEL`, `KC_INS` @@ -301,7 +304,7 @@ There are 8 modifiers which has discrimination between left and right. - `KC_LGUI` and `KC_RGUI` for Windows key or Command key in Mac #### 1.3 Fn key - **`KC_FNnn`** are `Fn` keys which not given any action at the beginning unlike most of keycodes has its own action. To use these keys in `KEYMAP` you need to assign action you want at first. Action of `Fn` is defined in `fn_actions[]` and index of the array is identical with number part of `KC_FNnn`. Thus `KC_FN0` designates action defined in first element of the array. ***32 `Fn` keys can be defined at most.*** +`KC_FNnn` are `Fn` keys which not given any action at the beginning unlike most of keycodes has its own action. To use these keys in `KEYMAP` you need to assign action you want at first. Action of `Fn` is defined in `fn_actions[]` and index of the array is identical with number part of `KC_FNnn`. Thus `KC_FN0` designates action defined in first element of the array. ***32 `Fn` keys can be defined at most.*** #### 1.4 Mousekey - `KC_MS_U`, `KC_MS_D`, `KC_MS_L`, `KC_MS_R` for mouse cursor @@ -359,7 +362,7 @@ This sets `default layer` into `current layer`. With this action you can return ACTION_LAYER_SET_TAP_KEY(layer, key) ACTION_LAYER_SET_TAP_TOGGLE(layer) -`Layer Bit` action XOR bits with `current layer`. `Layer Bit` action can take 0 to 8 as argument. +`Layer Bit` action XOR given bits with `current layer`. `Layer Bit` action can take 0 to 15 as argument. ACTION_LAYER_BIT(bits) ACTION_LAYER_BIT_TOGGLE(bits) @@ -659,4 +662,4 @@ Files & Directories License ------- Under `GPL` 2 or later. Some protocol files are under `Modified BSD License`. -LUFA and PJRC stack have their own license respectively. +LUFA, PJRC and V-USB stack have their own license respectively. diff --git a/common/action.c b/common/action.c index aadf5e16..710300eb 100644 --- a/common/action.c +++ b/common/action.c @@ -201,6 +201,19 @@ void action_exec(keyevent_t event) } } +static action_t get_action(key_t key) +{ + action_t action = keymap_get_action(current_layer, key.pos.row, key.pos.col); + + /* Transparently use default layer */ + if (action.code == ACTION_TRANSPARENT) { + // TODO: layer stacking + action = keymap_get_action(default_layer, key.pos.row, key.pos.col); + debug("TRNASPARENT: "); debug_hex16(action.code); debug("\n"); + } + return action; +} + static void process_action(keyrecord_t *record) { keyevent_t event = record->event; @@ -208,8 +221,7 @@ static void process_action(keyrecord_t *record) if (IS_NOEVENT(event)) { return; } - action_t action = keymap_get_action(current_layer, event.key.pos.row, event.key.pos.col); - //debug("action: "); debug_hex16(action.code); if (event.pressed) debug("d\n"); else debug("u\n"); + action_t action = get_action(event.key); debug("ACTION: "); debug_action(action); debug("\n"); switch (action.kind.id) { @@ -809,7 +821,8 @@ void layer_switch(uint8_t new_layer) bool is_tap_key(key_t key) { - action_t action = keymap_get_action(current_layer, key.pos.row, key.pos.col); + action_t action = get_action(key); + switch (action.kind.id) { case ACT_LMODS_TAP: case ACT_RMODS_TAP: diff --git a/common/action.h b/common/action.h index ac44b1a7..bb44049a 100644 --- a/common/action.h +++ b/common/action.h @@ -106,12 +106,14 @@ Keyboard Keys ------------- ACT_LMODS(0000): 0000|0000|000000|00 No action +0000|0000|000000|01 Transparent 0000|0000| keycode Key 0000|mods|000000|00 Left mods 0000|mods| keycode Key & Left mods ACT_RMODS(0001): -0001|0000|000000|00 No action +0001|0000|000000|00 No action(not used) +0001|0000|000000|01 Transparent(not used) 0001|0000| keycode Key(no used) 0001|mods|000000|00 Right mods 0001|mods| keycode Key & Right mods @@ -207,6 +209,7 @@ enum action_kind_id { /* action utility */ #define ACTION_NO 0 +#define ACTION_TRANSPARENT 1 #define ACTION(kind, param) ((kind)<<12 | (param)) #define MODS4(mods) (((mods)>>4 | (mods)) & 0x0F) diff --git a/common/keycode.h b/common/keycode.h index 4f57a588..36467999 100644 --- a/common/keycode.h +++ b/common/keycode.h @@ -28,6 +28,10 @@ along with this program. If not, see . #define IS_KEY(code) (KC_A <= (code) && (code) <= KC_EXSEL) #define IS_MOD(code) (KC_LCTRL <= (code) && (code) <= KC_RGUI) + +#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) +#define IS_SYSTEM(code) (KC_POWER <= (code) && (code) <= KC_WAKE) +#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV) #define IS_FN(code) (KC_FN0 <= (code) && (code) <= KC_FN31) #define IS_MOUSEKEY(code) (KC_MS_UP <= (code) && (code) <= KC_MS_ACCEL2) #define IS_MOUSEKEY_MOVE(code) (KC_MS_UP <= (code) && (code) <= KC_MS_RIGHT) @@ -35,10 +39,6 @@ along with this program. If not, see . #define IS_MOUSEKEY_WHEEL(code) (KC_MS_WH_UP <= (code) && (code) <= KC_MS_WH_RIGHT) #define IS_MOUSEKEY_ACCEL(code) (KC_MS_ACCEL0 <= (code) && (code) <= KC_MS_ACCEL2) -#define IS_SPECIAL(code) ((0xA5 <= (code) && (code) <= 0xDF) || (0xE8 <= (code) && (code) <= 0xFF)) -#define IS_CONSUMER(code) (KC_MUTE <= (code) && (code) <= KC_WFAV) -#define IS_SYSTEM(code) (KC_POWER <= (code) && (code) <= KC_WAKE) - #define MOD_BIT(code) (1<. #define KC_WSTP KC_WWW_STOP #define KC_WREF KC_WWW_REFRESH #define KC_WFAV KC_WWW_FAVORITES +/* Transparent */ +#define KC_TRANSPARENT 1 +#define KC_TRNS KC_TRANSPARENT + /* USB HID Keyboard/Keypad Usage(0x07) */ diff --git a/keyboard/gh60/keymap.c b/keyboard/gh60/keymap.c index 7e4f945f..39bb474c 100644 --- a/keyboard/gh60/keymap.c +++ b/keyboard/gh60/keymap.c @@ -166,12 +166,6 @@ static const uint16_t PROGMEM fn_actions[] = { action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) { uint8_t key = (pgm_read_byte(&keymaps[(layer)][(row)][(col)])); - // TODO: move to action.c ? - /* Transparently use default layer */ - if (key == KC_TRANSPARENT) { - key = (pgm_read_byte(&keymaps[(default_layer)][(row)][(col)])); - } - action_t action; switch (key) { case KC_A ... KC_EXSEL: @@ -199,7 +193,9 @@ action_t keymap_get_action(uint8_t layer, uint8_t row, uint8_t col) { action.code = ACTION_NO; } break; - case KC_NO ... KC_UNDEFINED: + case KC_TRNS: + action.code = ACTION_TRANSPARENT; + break; default: action.code = ACTION_NO; break;