mirror of
https://github.com/jmwtsn/qmk_firmware.git
synced 2026-06-03 19:53:31 -03:00
Guard remapping logic with MAGIC_ENABLE (#25537)
* Only perform key and mod remapping in keycode_config() and mod_config() when MAGIC_ENABLE is defined. * If not set, these functions now return the original keycode or modifier unchanged. * Reduces firmware size, and unnecessary code when MAGIC_ENABLE is not enabled. * Removed space saving suggestion with magic functions from squeezing AVR documentation
This commit is contained in:
@@ -87,26 +87,6 @@ Or if you're not using layers at all, you can outright remove the functionality
|
|||||||
#define NO_ACTION_LAYER
|
#define NO_ACTION_LAYER
|
||||||
```
|
```
|
||||||
|
|
||||||
## Magic Functions
|
|
||||||
|
|
||||||
There are two `__attribute__ ((weak))` placeholder functions available to customize magic keycodes. If you are not using that feature to swap keycodes, such as backslash with backspace, add the following to your `keymap.c` or user space code:
|
|
||||||
```c
|
|
||||||
#ifndef MAGIC_ENABLE
|
|
||||||
uint16_t keycode_config(uint16_t keycode) {
|
|
||||||
return keycode;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
```
|
|
||||||
Likewise, if you are not using magic keycodes to swap modifiers, such as Control with GUI, add the following to your `keymap.c` or user space code:
|
|
||||||
```c
|
|
||||||
#ifndef MAGIC_ENABLE
|
|
||||||
uint8_t mod_config(uint8_t mod) {
|
|
||||||
return mod;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
```
|
|
||||||
Both of them will overwrite the placeholder functions with a simple return statement to reduce firmware size.
|
|
||||||
|
|
||||||
## OLED tweaks
|
## OLED tweaks
|
||||||
|
|
||||||
One place you can save a bunch of space here is by not using `sprintf` or `snprintf`. This function call takes up ~1.5kB of firmware space, and can be rewritten. For instance, WPM uses this a lot.
|
One place you can save a bunch of space here is by not using `sprintf` or `snprintf`. This function call takes up ~1.5kB of firmware space, and can be rewritten. For instance, WPM uses this a lot.
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ keymap_config_t keymap_config;
|
|||||||
* and will return the corrected keycode, when appropriate.
|
* and will return the corrected keycode, when appropriate.
|
||||||
*/
|
*/
|
||||||
__attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
|
__attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
|
||||||
|
#ifdef MAGIC_ENABLE
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case KC_CAPS_LOCK:
|
case KC_CAPS_LOCK:
|
||||||
case KC_LOCKING_CAPS_LOCK:
|
case KC_LOCKING_CAPS_LOCK:
|
||||||
@@ -115,6 +116,9 @@ __attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
|
|||||||
default:
|
default:
|
||||||
return keycode;
|
return keycode;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
return keycode;
|
||||||
|
#endif // MAGIC_ENABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
/** \brief mod_config
|
/** \brief mod_config
|
||||||
@@ -124,6 +128,7 @@ __attribute__((weak)) uint16_t keycode_config(uint16_t keycode) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
__attribute__((weak)) uint8_t mod_config(uint8_t mod) {
|
__attribute__((weak)) uint8_t mod_config(uint8_t mod) {
|
||||||
|
#ifdef MAGIC_ENABLE
|
||||||
/**
|
/**
|
||||||
* Note: This function is for the 5-bit packed mods, NOT the full 8-bit mods.
|
* Note: This function is for the 5-bit packed mods, NOT the full 8-bit mods.
|
||||||
* More info about the mods can be seen in modifiers.h.
|
* More info about the mods can be seen in modifiers.h.
|
||||||
@@ -161,5 +166,6 @@ __attribute__((weak)) uint8_t mod_config(uint8_t mod) {
|
|||||||
mod &= ~MOD_RGUI;
|
mod &= ~MOD_RGUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // MAGIC_ENABLE
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user