diff options
-rw-r--r-- | docs/custom_quantum_functions.md | 7 | ||||
-rw-r--r-- | docs/feature_layers.md | 15 | ||||
-rw-r--r-- | quantum/quantum.h | 7 | ||||
-rw-r--r-- | users/konstantin/konstantin.h | 3 |
4 files changed, 18 insertions, 14 deletions
diff --git a/docs/custom_quantum_functions.md b/docs/custom_quantum_functions.md index 6eb144af7..e15126c42 100644 --- a/docs/custom_quantum_functions.md +++ b/docs/custom_quantum_functions.md | |||
@@ -319,7 +319,7 @@ This runs code every time that the layers get changed. This can be useful for l | |||
319 | 319 | ||
320 | ### Example `layer_state_set_*` Implementation | 320 | ### Example `layer_state_set_*` Implementation |
321 | 321 | ||
322 | This example shows how to set the [RGB Underglow](feature_rgblight.md) lights based on the layer, using the Planck as an example | 322 | This example shows how to set the [RGB Underglow](feature_rgblight.md) lights based on the layer, using the Planck as an example. |
323 | 323 | ||
324 | ```c | 324 | ```c |
325 | layer_state_t layer_state_set_user(layer_state_t state) { | 325 | layer_state_t layer_state_set_user(layer_state_t state) { |
@@ -343,6 +343,11 @@ layer_state_t layer_state_set_user(layer_state_t state) { | |||
343 | return state; | 343 | return state; |
344 | } | 344 | } |
345 | ``` | 345 | ``` |
346 | |||
347 | Use the `IS_LAYER_ON_STATE(state, layer)` and `IS_LAYER_OFF_STATE(state, layer)` macros to check the status of a particular layer. | ||
348 | |||
349 | Outside of `layer_state_set_*` functions, you can use the `IS_LAYER_ON(layer)` and `IS_LAYER_OFF(layer)` macros to check global layer state. | ||
350 | |||
346 | ### `layer_state_set_*` Function Documentation | 351 | ### `layer_state_set_*` Function Documentation |
347 | 352 | ||
348 | * Keyboard/Revision: `layer_state_t layer_state_set_kb(layer_state_t state)` | 353 | * Keyboard/Revision: `layer_state_t layer_state_set_kb(layer_state_t state)` |
diff --git a/docs/feature_layers.md b/docs/feature_layers.md index d3ee747e6..3f62cfc80 100644 --- a/docs/feature_layers.md +++ b/docs/feature_layers.md | |||
@@ -74,10 +74,9 @@ There are a number of functions (and variables) related to how you can use or ma | |||
74 | | [`update_tri_layer(x, y, z)`](ref_functions.md#update_tri_layerx-y-z) | Checks if layers `x` and `y` are both on, and sets `z` based on that (on if both on, otherwise off). | | 74 | | [`update_tri_layer(x, y, z)`](ref_functions.md#update_tri_layerx-y-z) | Checks if layers `x` and `y` are both on, and sets `z` based on that (on if both on, otherwise off). | |
75 | | [`update_tri_layer_state(state, x, y, z)`](ref_functions.md#update_tri_layer_statestate-x-y-z) | Does the same as `update_tri_layer(x, y, z)`, but from `layer_state_set_*` functions. | | 75 | | [`update_tri_layer_state(state, x, y, z)`](ref_functions.md#update_tri_layer_statestate-x-y-z) | Does the same as `update_tri_layer(x, y, z)`, but from `layer_state_set_*` functions. | |
76 | 76 | ||
77 | In addition to the functions that you can call, there are a number of callback functions that get called every time the layer changes. This passes the layer state to the function, where it can be read or modified. | ||
77 | 78 | ||
78 | In additional to the functions that you can call, there are a number of callback functions that get called every time the layer changes. This passed the layer state to the function, which can be read or modified. | 79 | |Callback |Description | |
79 | |||
80 | |Callbacks |Description | | ||
81 | |-----------------------------------------------------|----------------------------------------------------------------------------------------| | 80 | |-----------------------------------------------------|----------------------------------------------------------------------------------------| |
82 | | `layer_state_set_kb(layer_state_t state)` | Callback for layer functions, for keyboard. | | 81 | | `layer_state_set_kb(layer_state_t state)` | Callback for layer functions, for keyboard. | |
83 | | `layer_state_set_user(layer_state_t state)` | Callback for layer functions, for users. | | 82 | | `layer_state_set_user(layer_state_t state)` | Callback for layer functions, for users. | |
@@ -86,9 +85,9 @@ In additional to the functions that you can call, there are a number of callback | |||
86 | 85 | ||
87 | ?> For additional details on how you can use these callbacks, check out the [Layer Change Code](custom_quantum_functions.md#layer-change-code) document. | 86 | ?> For additional details on how you can use these callbacks, check out the [Layer Change Code](custom_quantum_functions.md#layer-change-code) document. |
88 | 87 | ||
89 | |Check functions |Description | | 88 | It is also possible to check the state of a particular layer using the following functions and macros. |
90 | |-------------------------------------------|------------------------------------------------------------------------------| | ||
91 | | `layer_state_cmp(cmp_layer_state, layer)` | This checks the `cmp_layer_state` to see if the specific `layer` is enabled. This is meant for use with the layer callbacks. | | ||
92 | | `layer_state_is(layer)` | This checks the layer state to see if the specific `layer` is enabled. (calls `layer_state_cmp` for the global layer state). | | ||
93 | 89 | ||
94 | !> There is `IS_LAYER_ON(layer)` as well, however the `layer_state_cmp` function has some additional handling to ensure that on layer 0 that it returns the correct value. Otherwise, if you check to see if layer 0 is on, you may get an incorrect value returned. | 90 | |Function |Description |Aliases |
91 | |---------------------------------|-------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------| | ||
92 | | `layer_state_is(layer)` | Checks if the specified `layer` is enabled globally. | `IS_LAYER_ON(layer)`, `IS_LAYER_OFF(layer)` | | ||
93 | | `layer_state_cmp(state, layer)` | Checks `state` to see if the specified `layer` is enabled. Intended for use in layer callbacks. | `IS_LAYER_ON_STATE(state, layer)`, `IS_LAYER_OFF_STATE(state, layer)` | | ||
diff --git a/quantum/quantum.h b/quantum/quantum.h index 17d1d41cc..51deac0cd 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
@@ -249,8 +249,11 @@ void set_single_persistent_default_layer(uint8_t default_layer); | |||
249 | 249 | ||
250 | void tap_random_base64(void); | 250 | void tap_random_base64(void); |
251 | 251 | ||
252 | #define IS_LAYER_ON(layer) (layer_state & (1UL << (layer))) | 252 | #define IS_LAYER_ON(layer) layer_state_is(layer) |
253 | #define IS_LAYER_OFF(layer) (~layer_state & (1UL << (layer))) | 253 | #define IS_LAYER_OFF(layer) !layer_state_is(layer) |
254 | |||
255 | #define IS_LAYER_ON_STATE(state, layer) layer_state_cmp(state, layer) | ||
256 | #define IS_LAYER_OFF_STATE(state, layer) !layer_state_cmp(state, layer) | ||
254 | 257 | ||
255 | void matrix_init_kb(void); | 258 | void matrix_init_kb(void); |
256 | void matrix_scan_kb(void); | 259 | void matrix_scan_kb(void); |
diff --git a/users/konstantin/konstantin.h b/users/konstantin/konstantin.h index 72a161623..249b3fe15 100644 --- a/users/konstantin/konstantin.h +++ b/users/konstantin/konstantin.h | |||
@@ -48,9 +48,6 @@ | |||
48 | #define LCT_CPS LCTL_T(KC_CAPS) | 48 | #define LCT_CPS LCTL_T(KC_CAPS) |
49 | #define RSF_SLS RSFT_T(KC_SLSH) | 49 | #define RSF_SLS RSFT_T(KC_SLSH) |
50 | 50 | ||
51 | #define IS_LAYER_ON_STATE(state, layer) ( (state) & (1UL << (layer))) | ||
52 | #define IS_LAYER_OFF_STATE(state, layer) (~(state) & (1UL << (layer))) | ||
53 | |||
54 | // Clear mods, perform action, restore mods | 51 | // Clear mods, perform action, restore mods |
55 | #define CLEAN_MODS(action) { \ | 52 | #define CLEAN_MODS(action) { \ |
56 | uint8_t mods = get_mods(); \ | 53 | uint8_t mods = get_mods(); \ |