-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeyboard_lock.c
61 lines (51 loc) · 1.37 KB
/
keyboard_lock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2024 Christopher Courtney, aka Drashna Jael're (@drashna) <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
#include "keyboard_lock.h"
#include "quantum.h"
ASSERT_COMMUNITY_MODULES_MIN_API_VERSION(0, 1, 0);
static host_driver_t *host_driver = 0;
static bool host_driver_disabled = false;
/**
* @brief Mount/Umount the keyboard USB driver
*/
void set_keyboard_lock(bool status) {
if (!status && !host_get_driver()) {
host_set_driver(host_driver);
} else if (status && host_get_driver()) {
host_driver = host_get_driver();
clear_keyboard();
host_set_driver(0);
} else if (status) {
clear_keyboard();
}
host_driver_disabled = status;
}
/**
* @brief Get the keyboard lock status
*
* @return true
* @return false
*/
bool get_keyboard_lock(void) {
return host_driver_disabled;
}
/**
* @brief Toggles the keyboard lock status
*
*/
void toggle_keyboard_lock(void) {
set_keyboard_lock(!host_driver_disabled);
}
bool process_record_keyboard_lock(uint16_t keycode, keyrecord_t *record) {
if (!process_record_keyboard_lock_kb(keycode, record)) {
return false;
}
if (record->event.pressed) {
switch (keycode) {
case CM_KEYBOARD_LOCK_TOGGLE:
toggle_keyboard_lock();
break;
}
}
return true;
}