logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

layer_lock.h (3338B)


  1. // Copyright 2022-2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @file layer_lock.h
  16. * @brief Layer Lock, a key to stay in the current layer.
  17. *
  18. * Overview
  19. * --------
  20. *
  21. * Layers are often accessed by holding a button, e.g. with a momentary layer
  22. * switch `MO(layer)` or layer tap `LT(layer, key)` key. But you may sometimes
  23. * want to "lock" or "toggle" the layer so that it stays on without having to
  24. * hold down a button. One way to do that is with a tap-toggle `TT` layer key,
  25. * but here is an alternative.
  26. *
  27. * This library implements a "Layer Lock key". When tapped, it "locks" the
  28. * highest layer to stay active, assuming the layer was activated by one of the
  29. * following keys:
  30. *
  31. * * `MO(layer)` momentary layer switch
  32. * * `LT(layer, key)` layer tap
  33. * * `OSL(layer)` one-shot layer
  34. * * `TT(layer)` layer tap toggle
  35. * * `LM(layer, mod)` layer-mod key (the layer is locked, but not the mods)
  36. *
  37. * Tapping the Layer Lock key again unlocks and turns off the layer.
  38. *
  39. * @note When a layer is "locked", other layer keys such as `TO(layer)` or
  40. * manually calling `layer_off(layer)` will override and unlock the layer.
  41. *
  42. * Configuration
  43. * -------------
  44. *
  45. * Optionally, a timeout may be defined so that Layer Lock disables
  46. * automatically if not keys are pressed for `LAYER_LOCK_IDLE_TIMEOUT`
  47. * milliseconds. Define `LAYER_LOCK_IDLE_TIMEOUT` in your config.h, for instance
  48. *
  49. * #define LAYER_LOCK_IDLE_TIMEOUT 60000 // Turn off after 60 seconds.
  50. *
  51. * For full documentation, see
  52. * <https://getreuer.info/posts/keyboards/layer-lock>
  53. */
  54. #pragma once
  55. #include <stdint.h>
  56. #include <stdbool.h>
  57. #include "action_layer.h"
  58. #include "action_util.h"
  59. /** Returns true if `layer` is currently locked. */
  60. bool is_layer_locked(uint8_t layer);
  61. /** Locks and turns on `layer`. */
  62. void layer_lock_on(uint8_t layer);
  63. /** Unlocks and turns off `layer`. */
  64. void layer_lock_off(uint8_t layer);
  65. /** Unlocks and turns off all locked layers. */
  66. void layer_lock_all_off(void);
  67. /** Toggles whether `layer` is locked. */
  68. void layer_lock_invert(uint8_t layer);
  69. /**
  70. * Optional callback that gets called when a layer is locked or unlocked.
  71. *
  72. * This is useful to represent the current lock state, e.g. by setting an LED or
  73. * playing a sound. In your keymap, define
  74. *
  75. * void layer_lock_set_user(layer_state_t locked_layers) {
  76. * // Do something like `set_led(is_layer_locked(NAV));`
  77. * }
  78. *
  79. * @param locked_layers Bitfield in which the kth bit represents whether the
  80. * kth layer is on.
  81. */
  82. bool layer_lock_set_kb(layer_state_t locked_layers);
  83. bool layer_lock_set_user(layer_state_t locked_layers);
  84. /** Handle various background tasks */
  85. void layer_lock_task(void);
  86. /** Update any configured timeouts */
  87. void layer_lock_activity_trigger(void);