Skip to content

Commit 04feeaa

Browse files
committed
Clean hook codes
1 parent 0ca106d commit 04feeaa

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

common/action_layer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static void default_layer_state_set(uint32_t state)
2222
debug("default_layer_state: ");
2323
default_layer_debug(); debug(" to ");
2424
default_layer_state = state;
25+
hook_default_layer_change(default_layer_state);
2526
default_layer_debug(); debug("\n");
2627
clear_keyboard_but_mods(); // To avoid stuck keys
2728
}

common/hook.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,31 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
#include "hook.h"
2020

2121
/* -------------------------------------------------
22-
* Definitions of hardware-independent default hooks
22+
* Definitions of default hooks
2323
* ------------------------------------------------- */
2424

25-
/* Called on layer state change event. */
26-
/* Default behaviour: do nothing. */
2725
__attribute__((weak))
28-
void hook_layer_change(uint8_t layer_state) {
29-
(void)layer_state;
26+
void hook_keyboard_loop(void) {}
27+
28+
__attribute__((weak))
29+
void hook_matrix_change(keyevent_t event) {
30+
(void)event;
3031
}
3132

32-
/* Called periodically from the matrix scan loop (very often!) */
33-
/* Default behaviour: do nothing. */
3433
__attribute__((weak))
35-
void hook_keyboard_loop(void) {}
34+
void hook_default_layer_change(uint8_t layer_state) {
35+
(void)layer_state;
36+
}
3637

37-
/* Called on matrix state change event (every keypress => often!) */
38-
/* Default behaviour: do nothing. */
3938
__attribute__((weak))
40-
void hook_matrix_change(keyevent_t event) {
41-
(void)event;
39+
void hook_layer_change(uint8_t layer_state) {
40+
(void)layer_state;
4241
}
4342

44-
/* Called on indicator LED update event (when reported from host). */
45-
/* Default behaviour: calls led_set (for compatibility). */
4643
__attribute__((weak))
4744
void hook_keyboard_leds_change(uint8_t led_status) {
4845
keyboard_set_leds(led_status);
4946
}
5047

51-
/* Called once, on checking the bootmagic combos. */
52-
/* Default behaviour: do nothing. */
5348
__attribute__((weak))
54-
void hook_bootmagic(void) {
55-
/* An example: */
56-
// #include "bootmagic.h"
57-
// #include "keymap.h"
58-
// if(bootmagic_scan_keycode(KC_W)) {
59-
// // do something
60-
// }
61-
}
49+
void hook_bootmagic(void) {}

common/hook.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2222
#include "led.h"
2323

2424
/* -------------------------------------
25-
* Hardware / one-off hooks
25+
* Protocol hooks
2626
* ------------------------------------- */
2727

28-
/* Called once, before initialising USB. */
28+
/* Called once, very early stage of initialization, just after processor startup. */
2929
/* Default behaviour: do nothing. */
3030
void hook_early_init(void);
3131

32-
/* Called once, after USB is connected and keyboard initialised. */
32+
/* Called once, very last stage of initialization, just before keyboard loop. */
3333
/* Default behaviour: do nothing. */
3434
void hook_late_init(void);
3535

@@ -47,12 +47,9 @@ void hook_usb_suspend_loop(void);
4747
* the "normal" indicator LED status by default. */
4848
void hook_usb_wakeup(void);
4949

50-
/* Called once, on checking the bootmagic combos. */
51-
/* Default behaviour: do nothing. */
52-
void hook_bootmagic(void);
5350

5451
/* -------------------------------------
55-
* Keyboard / periodic hooks
52+
* Keyboard hooks
5653
* ------------------------------------- */
5754

5855
/* Called periodically from the keyboard loop (very often!) */
@@ -63,12 +60,21 @@ void hook_keyboard_loop(void);
6360
/* Default behaviour: do nothing. */
6461
void hook_matrix_change(keyevent_t event);
6562

63+
/* Called on default layer state change event. */
64+
/* Default behaviour: do nothing. */
65+
void hook_default_layer_change(uint32_t default_layer_state);
66+
6667
/* Called on layer state change event. */
6768
/* Default behaviour: do nothing. */
68-
void hook_layer_change(uint8_t layer_state);
69+
void hook_layer_change(uint32_t layer_state);
6970

7071
/* Called on indicator LED update event (when reported from host). */
71-
/* Default behaviour: calls keyboard_set_leds (for compatibility). */
72+
/* Default behaviour: calls keyboard_set_leds. */
7273
void hook_keyboard_leds_change(uint8_t led_status);
7374

75+
/* Called once, on checking the bootmagic combos. */
76+
/* Default behaviour: do nothing. */
77+
void hook_bootmagic(void);
78+
79+
7480
#endif /* _HOOKS_H_ */

0 commit comments

Comments
 (0)