From d5fae3a6f96d44a432350d5f487204a962c5f9bc Mon Sep 17 00:00:00 2001 From: Grayson Carr <734415+gtg465x@users.noreply.github.com> Date: Wed, 6 Oct 2021 11:36:04 -0400 Subject: [PATCH] Updated Keychron Q1 user keymap (#14666) * Updated Keychron Q1 user keymap - Added Caps Lock indicator - Mission Control and Launchpad custom keycodes are now defined using the VIA user keycodes range so they can be labeled properly in VIA * Only use VIA keycode range if VIA is enabled * Reformatted led_indexes enum to match layout * Feature: When the Fn layer is active, RGB lighting turns off for keys that are not assigned * Fixes * Cleanup: Updated method signature of rgb_matrix_set_color_by_keycode to more closely match rgb_matrix_set_color * Fixed int sizing for keycodes --- .../q1/rev_0100/keymaps/gtg465x/README.md | 17 +++++ .../q1/rev_0100/keymaps/gtg465x/config.h | 8 ++- .../q1/rev_0100/keymaps/gtg465x/keymap.c | 28 +++++--- .../q1/rev_0100/keymaps/gtg465x/keymap_user.h | 28 ++++++++ .../keymaps/gtg465x/rgb_matrix_user.c | 71 +++++++++++++++++++ .../keymaps/gtg465x/rgb_matrix_user.h | 24 +++++++ .../q1/rev_0100/keymaps/gtg465x/rules.mk | 4 ++ 7 files changed, 169 insertions(+), 11 deletions(-) create mode 100644 keyboards/keychron/q1/rev_0100/keymaps/gtg465x/keymap_user.h create mode 100644 keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rgb_matrix_user.c create mode 100644 keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rgb_matrix_user.h diff --git a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/README.md b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/README.md index c10416e690c..c2d5799bb8b 100644 --- a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/README.md +++ b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/README.md @@ -2,3 +2,20 @@ - On macOS, F3 opens Mission Control and F4 opens Launchpad without needing to configure shortcuts in System Preferences - RGB lighting turns off when the computer sleeps +- Caps Lock and alpha keys turn red to indicate when Caps Lock is on +- When the Fn layer is active, RGB lighting turns off for keys that are not assigned + +## Changelog + +### 10/3/2021 - 1.0.3 + +- Feature: When the Fn layer is active, RGB lighting turns off for keys that are not assigned + +### 10/1/2021 - 1.0.2 + +- Added Caps Lock indicator (my implementation is different, but this was inspired by mkillewald) +- Mission Control and Launchpad custom keycodes are now defined using the VIA user keycodes range so they can be labeled properly in VIA + +### 9/28/2021 - 1.0.1 + +- Initial release diff --git a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/config.h b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/config.h index 3a20f0b0085..5ac05d04c12 100644 --- a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/config.h +++ b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/config.h @@ -16,6 +16,10 @@ #pragma once - /* RGB Matrix Configuration */ -#define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended +#ifdef RGB_MATRIX_ENABLE +# define RGB_DISABLE_WHEN_USB_SUSPENDED +# define CAPS_LOCK_INDICATOR_COLOR RGB_RED +# define CAPS_LOCK_INDICATOR_LIGHT_ALPHAS +# define FN_LAYER_TRANSPARENT_KEYS_OFF +#endif diff --git a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/keymap.c b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/keymap.c index 79ef0bf86bd..7f806f6b457 100644 --- a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/keymap.c +++ b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/keymap.c @@ -15,18 +15,20 @@ */ #include QMK_KEYBOARD_H +#include "keymap_user.h" +#ifdef RGB_MATRIX_ENABLE +# include "rgb_matrix_user.h" +#endif - -enum layers{ - MAC_BASE, - MAC_FN, - WIN_BASE, - WIN_FN -}; +// clang-format off enum custom_keycodes { - KC_MISSION_CONTROL = SAFE_RANGE, - KC_LAUNCHPAD +#ifdef VIA_ENABLE + KC_MISSION_CONTROL = USER00, +#else + KC_MISSION_CONTROL = SAFE_RANGE, +#endif + KC_LAUNCHPAD }; #define KC_MCTL KC_MISSION_CONTROL @@ -70,6 +72,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; +// clang-format on + +void matrix_init_user(void) { +#ifdef RGB_MATRIX_ENABLE + rgb_matrix_init_user(); +#endif +} + bool process_record_user(uint16_t keycode, keyrecord_t *record) { switch (keycode) { case KC_MISSION_CONTROL: diff --git a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/keymap_user.h b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/keymap_user.h new file mode 100644 index 00000000000..728114d556f --- /dev/null +++ b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/keymap_user.h @@ -0,0 +1,28 @@ +/* Copyright 2021 @ Grayson Carr + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +// clang-format off + +enum layers { + MAC_BASE, + MAC_FN, + WIN_BASE, + WIN_FN +}; + +// clang-format on diff --git a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rgb_matrix_user.c b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rgb_matrix_user.c new file mode 100644 index 00000000000..9bc7231ece0 --- /dev/null +++ b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rgb_matrix_user.c @@ -0,0 +1,71 @@ +/* Copyright 2021 @ Grayson Carr + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include QMK_KEYBOARD_H +#include "rgb_matrix_user.h" +#include "keymap_user.h" + +keypos_t led_index_key_position[DRIVER_LED_TOTAL]; + +void rgb_matrix_init_user(void) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + for (uint8_t col = 0; col < MATRIX_COLS; col++) { + uint8_t led_index = g_led_config.matrix_co[row][col]; + if (led_index != NO_LED) { + led_index_key_position[led_index] = (keypos_t){.row = row, .col = col}; + } + } + } +} + +void rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) { + uint8_t current_layer = get_highest_layer(layer_state); + switch (current_layer) { + case MAC_BASE: + case WIN_BASE: +#ifdef CAPS_LOCK_INDICATOR_COLOR + if (host_keyboard_led_state().caps_lock) { + rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_caps_lock_indicator, CAPS_LOCK_INDICATOR_COLOR); + } +#endif + break; + case MAC_FN: + case WIN_FN: +#ifdef FN_LAYER_TRANSPARENT_KEYS_OFF + rgb_matrix_set_color_by_keycode(led_min, led_max, current_layer, is_transparent, RGB_OFF); +#endif + break; + } +} + +void rgb_matrix_set_color_by_keycode(uint8_t led_min, uint8_t led_max, uint8_t layer, bool (*is_keycode)(uint16_t), uint8_t red, uint8_t green, uint8_t blue) { + for (uint8_t i = led_min; i < led_max; i++) { + uint16_t keycode = keymap_key_to_keycode(layer, led_index_key_position[i]); + if ((*is_keycode)(keycode)) { + rgb_matrix_set_color(i, red, green, blue); + } + } +} + +bool is_caps_lock_indicator(uint16_t keycode) { +#ifdef CAPS_LOCK_INDICATOR_LIGHT_ALPHAS + return (KC_A <= keycode && keycode <= KC_Z) || keycode == KC_CAPS; +#else + return keycode == KC_CAPS; +#endif +} + +bool is_transparent(uint16_t keycode) { return keycode == KC_TRNS; } diff --git a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rgb_matrix_user.h b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rgb_matrix_user.h new file mode 100644 index 00000000000..dead4541676 --- /dev/null +++ b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rgb_matrix_user.h @@ -0,0 +1,24 @@ +/* Copyright 2021 @ Grayson Carr + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +void rgb_matrix_init_user(void); + +void rgb_matrix_set_color_by_keycode(uint8_t led_min, uint8_t led_max, uint8_t layer, bool (*is_keycode)(uint16_t), uint8_t red, uint8_t green, uint8_t blue); + +bool is_caps_lock_indicator(uint16_t keycode); +bool is_transparent(uint16_t keycode); diff --git a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rules.mk b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rules.mk index 96d2d189b2e..42ba38028d2 100644 --- a/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rules.mk +++ b/keyboards/keychron/q1/rev_0100/keymaps/gtg465x/rules.mk @@ -1,2 +1,6 @@ VIA_ENABLE = yes MOUSEKEY_ENABLE = no + +ifeq ($(strip $(RGB_MATRIX_ENABLE)), yes) + SRC += rgb_matrix_user.c +endif