Disable terminal keyboard while unl0kr is running

This commit is contained in:
Johannes Marbach 2022-07-09 17:10:45 +02:00
parent 5e07323f00
commit 51380c7654
2 changed files with 36 additions and 4 deletions

View file

@ -5,6 +5,7 @@
- feat: Add config option to customise bullet character (#17)
- fix: Use actual screen DPI value to compute sizes and spaces
- feat: Allow shutting down the device on inactivity
- fix: Disable terminal keyboard while unl0kr is running
## 0.2.0 (2022-05-27)

View file

@ -37,6 +37,9 @@
static int current_fd = -1;
static int original_mode = KD_TEXT;
static int original_kb_mode = K_UNICODE;
/**
* Static prototypes
@ -87,14 +90,42 @@ static void close_current_terminal(void) {
void ul_terminal_prepare_current_terminal(void) {
reopen_current_terminal();
if (current_fd < 0 || ioctl(current_fd, KDSETMODE, KD_GRAPHICS) != 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not set current terminal to graphics mode");
if (current_fd < 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not prepare current terminal");
return;
}
if (ioctl(current_fd, KDGETMODE, &original_mode) != 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not get terminal mode");
}
if (ioctl(current_fd, KDSETMODE, KD_GRAPHICS) != 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not set terminal mode to graphics");
}
if (ioctl(current_fd, KDGKBMODE, &original_kb_mode) != 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not get terminal keyboard mode");
}
if (ioctl(current_fd, KDSKBMODE, K_OFF) != 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not set terminal keyboard mode to off");
}
}
void ul_terminal_reset_current_terminal(void) {
if (current_fd < 0 || ioctl(current_fd, KDSETMODE, KD_TEXT) != 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not reset current terminal to text mode");
if (current_fd < 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not reset current terminal");
return;
}
if (ioctl(current_fd, KDSETMODE, original_mode) != 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not reset terminal mode");
}
if (ioctl(current_fd, KDSKBMODE, original_kb_mode) != 0) {
ul_log(UL_LOG_LEVEL_WARNING, "Could not reset terminal keyboard mode");
}
close_current_terminal();
}