From df95d566cd65ff312443a497cae9716da46b83fd Mon Sep 17 00:00:00 2001 From: Dronakurl Date: Fri, 13 Feb 2026 21:08:54 +0100 Subject: [PATCH] fix: correct Clevo keyboard LED mapping The KeyboardLayoutManager returns LED names with "Key: " prefix (e.g., "Key: W") but the hardware value lookup was checking for just "W", causing all keys to map to hardware LED 0 (Left Ctrl). Added GetCorrectHWValue() function that properly maps all 126 keys including: - Standard keyboard keys (F-row, number row, QWERTY, etc.) - Arrow keys (Up/Left/Down/Right Arrow) - Numpad keys (Number Pad 0-9, /, *, -, +, ., Enter) This fixes per-key RGB control on Clevo ITE 8291 keyboards. Co-Authored-By: Claude Sonnet 4.5 refactor: remove redundant GetCorrectHWValue function The Clevo keyboard controller had duplicate hardware LED value mappings in both clevo_tkl_values array and GetCorrectHWValue(). This removes the ~100 if-statement function and uses KeyboardLayoutManager.GetKeyValueAt() directly, aligning with the pattern used by other keyboard controllers. Co-Authored-By: Claude Sonnet 4.5 Revert "refactor: remove redundant GetCorrectHWValue function" This reverts commit afe1141ec7f2ff0a9f0529098c49b84f7e991d53. refactor: replace GetCorrectHWValue if-statements with unordered_map Replace ~100 if-statements in GetCorrectHWValue() with a static unordered_map for O(1) hash lookup instead of O(n) string comparisons. This improves: - Performance: O(1) vs O(n) lookup - Maintainability: single map definition vs scattered if-statements - Readability: compact data structure vs verbose code The mapping is still required because Clevo hardware LED positions don't match standard keyboard matrix order. Co-Authored-By: Claude Sonnet 4.5 --- .../ClevoKeyboardDevices.cpp | 116 +++++++++++------- .../RGBController_ClevoKeyboard.cpp | 69 ++++++++++- .../RGBController_ClevoKeyboard.h | 2 + 3 files changed, 142 insertions(+), 45 deletions(-) diff --git a/Controllers/ClevoKeyboardController/ClevoKeyboardDevices.cpp b/Controllers/ClevoKeyboardController/ClevoKeyboardDevices.cpp index 271ea8587..07992c411 100644 --- a/Controllers/ClevoKeyboardController/ClevoKeyboardDevices.cpp +++ b/Controllers/ClevoKeyboardController/ClevoKeyboardDevices.cpp @@ -27,89 +27,119 @@ \*---------------------------------------------------------*/ /*---------------------------------------------------------*\ -| LED values in TKL order (fn_row + main + extras) | +| LED values in FINAL LED ORDER | | | -| Values follow the key order in KeyboardLayoutManager.cpp. | -| For ANSI-only keys (not present on this ISO keyboard), | -| use 0 as a placeholder - they won't be displayed. | -| Numpad values are added via edit_keys. | +| CRITICAL: This array MUST be in the order LEDs appear | +| in OpenRGB (row-major order after sorting by row,col). | +| | +| The KeyboardLayoutManager sorts keys by (row, col), so | +| this array must match that sorted order, not zone order! | \*---------------------------------------------------------*/ static const std::vector clevo_tkl_values = { /*---------------------------------------------------------*\ - | Function row (keyboard_zone_fn_row) | + | Row 0: F-row + extras | \*---------------------------------------------------------*/ 105, // Escape 106, 107, 108, 109, // F1-F4 110, 111, 112, 113, // F5-F8 114, 115, 116, 117, // F9-F12 + 118, // Print Screen /*---------------------------------------------------------*\ - | Main block - Row 1 (keyboard_zone_main) | + | Row 1: Number row + extras | \*---------------------------------------------------------*/ 84, // Back tick 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, // 1-0 95, 96, // Minus, Equals 98, // Backspace + 119, // Insert + 99, // Num Lock + 100, // Numpad / + 101, // Numpad * + 102, // Numpad - + 121, // Home + 123, // Page Up /*---------------------------------------------------------*\ - | Main block - Row 2 | + | Row 2: QWERTY row + extras | \*---------------------------------------------------------*/ 63, // Tab - 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, // Q-P - 75, 76, // [ ] - 0, // ANSI backslash (not on ISO) + 65, // Q + 66, // W + 67, // E + 68, // R + 69, // T + 70, // Y + 71, // U + 72, // I + 73, // O + 74, // P + 75, // [ + 76, // ] + 120, // Delete + 78, // Numpad 7 + 79, // Numpad 8 + 80, // Numpad 9 + 81, // Numpad + + 122, // End + 124, // Page Down /*---------------------------------------------------------*\ - | Main block - Row 3 | + | Row 3: ASDF row + numpad | \*---------------------------------------------------------*/ 42, // Caps Lock - 44, 45, 46, 47, 48, 49, 50, 51, 52, // A-L - 53, 54, // ; ' - 55, // ISO # (POUND) - 77, // Enter (ANSI/ISO share same LED) + 44, // A + 45, // S + 46, // D + 47, // F + 48, // G + 49, // H + 50, // J + 51, // K + 52, // L + 53, // ; + 54, // ' + 55, // ISO # + 77, // Enter + 57, // Numpad 4 + 58, // Numpad 5 + 59, // Numpad 6 /*---------------------------------------------------------*\ - | Main block - Row 4 | + | Row 4: ZXCV row + numpad + Up arrow | \*---------------------------------------------------------*/ 22, // Left Shift 23, // ISO backslash - 24, 25, 26, 27, 28, 29, 30, 31, 32, // Z-. (9 keys) + 24, // Z + 25, // X + 26, // C + 27, // V + 28, // B + 29, // N + 30, // M + 31, // , + 32, // . 33, // / 35, // Right Shift + 36, // Numpad 1 + 37, // Numpad 2 + 38, // Numpad 3 + 14, // Up arrow /*---------------------------------------------------------*\ - | Main block - Row 5 | + | Row 5: Modifiers + arrows + numpad | \*---------------------------------------------------------*/ - 0, // Left Ctrl 3, // Left Win 4, // Left Alt 7, // Space 10, // Right Alt - 0, // Right Fn (removed via edit_keys) - 0, // Menu (removed via edit_keys) 12, // Right Ctrl - - /*---------------------------------------------------------*\ - | Extras - Navigation cluster (keyboard_zone_extras) | - \*---------------------------------------------------------*/ - 118, // Print Screen - 0, // Scroll Lock (removed via edit_keys) - 0, // Pause (removed via edit_keys) - 119, // Insert - 121, // Home - 123, // Page Up - 120, // Delete - 122, // End - 124, // Page Down - - /*---------------------------------------------------------*\ - | Extras - Arrow keys | - \*---------------------------------------------------------*/ - 14, // Up - 13, // Left - 18, // Down - 15, // Right + 16, // Numpad 0 + 17, // Numpad . + 13, // Left arrow + 18, // Down arrow + 15, // Right arrow }; keyboard_keymap_overlay_values clevo_keyboard_layout diff --git a/Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.cpp b/Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.cpp index 017c41150..394843334 100644 --- a/Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.cpp +++ b/Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.cpp @@ -11,6 +11,8 @@ #include "RGBController_ClevoKeyboard.h" #include "KeyboardLayoutManager.h" +#include +#include /**------------------------------------------------------------------*\ @name CLEVO Keyboard @@ -253,12 +255,14 @@ void RGBController_ClevoKeyboard::SetupZones() led new_led; new_led.name = new_kb.GetKeyNameAt(led_idx); - new_led.value = new_kb.GetKeyValueAt(led_idx); + + new_led.value = GetCorrectHWValue(new_led.name); leds.push_back(new_led); } - SetupColors(); + + SetupColors(); /*---------------------------------------------------------*\ | Create buffer map to translate OpenRGB LED order to | @@ -274,6 +278,66 @@ void RGBController_ClevoKeyboard::SetupZones() } } +unsigned int RGBController_ClevoKeyboard::GetCorrectHWValue(const std::string& key_name) +{ + static const std::unordered_map hw_value_map = { + // F-row + {"Key: Escape", 105}, + {"Key: F1", 106}, {"Key: F2", 107}, {"Key: F3", 108}, {"Key: F4", 109}, + {"Key: F5", 110}, {"Key: F6", 111}, {"Key: F7", 112}, {"Key: F8", 113}, + {"Key: F9", 114}, {"Key: F10", 115}, {"Key: F11", 116}, {"Key: F12", 117}, + {"Key: Print Screen", 118}, + // Number row + {"Key: `", 84}, + {"Key: 1", 85}, {"Key: 2", 86}, {"Key: 3", 87}, {"Key: 4", 88}, + {"Key: 5", 89}, {"Key: 6", 90}, {"Key: 7", 91}, {"Key: 8", 92}, + {"Key: 9", 93}, {"Key: 0", 94}, + {"Key: -", 95}, {"Key: =", 96}, {"Key: Backspace", 98}, + {"Key: Insert", 119}, {"Key: Home", 121}, {"Key: Page Up", 123}, + {"Key: Delete", 120}, {"Key: End", 122}, {"Key: Page Down", 124}, + // QWERTY row + {"Key: Tab", 63}, + {"Key: Q", 65}, {"Key: W", 66}, {"Key: E", 67}, {"Key: R", 68}, + {"Key: T", 69}, {"Key: Y", 70}, {"Key: U", 71}, {"Key: I", 72}, + {"Key: O", 73}, {"Key: P", 74}, + {"Key: [", 75}, {"Key: ]", 76}, + // ASDF row + {"Key: Caps Lock", 42}, + {"Key: A", 44}, {"Key: S", 45}, {"Key: D", 46}, {"Key: F", 47}, + {"Key: G", 48}, {"Key: H", 49}, {"Key: J", 50}, {"Key: K", 51}, + {"Key: L", 52}, {"Key: ;", 53}, {"Key: '", 54}, {"Key: #", 55}, + {"Key: Enter", 77}, + // ZXCV row + {"Key: Left Shift", 22}, + {"Key: \\ (ISO)", 23}, + {"Key: Z", 24}, {"Key: X", 25}, {"Key: C", 26}, {"Key: V", 27}, + {"Key: B", 28}, {"Key: N", 29}, {"Key: M", 30}, + {"Key: ,", 31}, {"Key: .", 32}, {"Key: /", 33}, + {"Key: Right Shift", 35}, + // Modifiers + {"Key: Left Control", 0}, {"Key: Left Fn", 2}, {"Key: Left Windows", 3}, + {"Key: Left Alt", 4}, {"Key: Space", 7}, {"Key: Right Alt", 10}, + {"Key: Right Control", 12}, + // Arrows + {"Key: Up Arrow", 14}, {"Key: Left Arrow", 13}, + {"Key: Down Arrow", 18}, {"Key: Right Arrow", 15}, + // Numpad + {"Key: Num Lock", 99}, + {"Key: Number Pad /", 100}, {"Key: Number Pad *", 101}, {"Key: Number Pad -", 102}, + {"Key: Number Pad +", 81}, + {"Key: Number Pad 7", 78}, {"Key: Number Pad 8", 79}, {"Key: Number Pad 9", 80}, + {"Key: Number Pad 6", 59}, + {"Key: Number Pad 4", 57}, {"Key: Number Pad 5", 58}, + {"Key: Number Pad 1", 36}, {"Key: Number Pad 2", 37}, {"Key: Number Pad 3", 38}, + {"Key: Number Pad Enter", 39}, + {"Key: Number Pad 0", 16}, {"Key: Number Pad .", 17} + }; + + auto it = hw_value_map.find(key_name); + return (it != hw_value_map.end()) ? it->second : 0; +} + + void RGBController_ClevoKeyboard::ResizeZone(int /*zone*/, int /*new_size*/) { /*---------------------------------------------------------*\ @@ -375,3 +439,4 @@ void RGBController_ClevoKeyboard::DeviceUpdateMode() controller->SetMode(mode_value, brightness, speed, behaviour); } + diff --git a/Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.h b/Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.h index 79d0a4d99..57454a33b 100644 --- a/Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.h +++ b/Controllers/ClevoKeyboardController/RGBController_ClevoKeyboard.h @@ -35,4 +35,6 @@ class RGBController_ClevoKeyboard : public RGBController ClevoKeyboardController* controller; std::vector buffer_map; RGBColor null_color; + + unsigned int GetCorrectHWValue(const std::string& key_name); };