When using input devices, set the VT keyboard state with KDSKBMODE so that the VT console doesn't change the LED state

This commit is contained in:
nerdopolis 2023-12-08 10:31:41 -05:00
parent 58cc9f84e4
commit 6b79792829
4 changed files with 40 additions and 2 deletions

View file

@ -103,6 +103,7 @@ struct _ply_terminal
uint32_t is_open : 1;
uint32_t is_active : 1;
uint32_t is_unbuffered : 1;
uint32_t is_disabled : 1;
uint32_t is_watching_for_vt_changes : 1;
uint32_t should_ignore_mode_changes : 1;
};
@ -240,6 +241,11 @@ ply_terminal_set_unbuffered_input (ply_terminal_t *terminal)
ply_terminal_unlock (terminal);
terminal->is_disabled = false;
if (ply_terminal_is_vt (terminal))
ioctl (terminal->fd, KDSKBMODE, K_UNICODE);
tcgetattr (terminal->fd, &term_attributes);
if (!terminal->original_term_attributes_saved) {
@ -270,6 +276,11 @@ ply_terminal_set_buffered_input (ply_terminal_t *terminal)
{
struct termios term_attributes;
terminal->is_disabled = false;
if (ply_terminal_is_vt (terminal))
ioctl (terminal->fd, KDSKBMODE, K_UNICODE);
if (!terminal->is_unbuffered)
return true;
@ -310,6 +321,17 @@ ply_terminal_set_buffered_input (ply_terminal_t *terminal)
return true;
}
bool
ply_terminal_set_disabled_input (ply_terminal_t *terminal)
{
terminal->is_disabled = true;
if (ply_terminal_is_vt (terminal))
ioctl (terminal->fd, KDSKBMODE, K_OFF);
return true;
}
void
ply_terminal_write (ply_terminal_t *terminal,
const char *format,
@ -369,6 +391,11 @@ on_tty_input (ply_terminal_t *terminal)
{
ply_list_node_t *node;
if (terminal->is_disabled) {
ply_terminal_flush_input (terminal);
return;
}
node = ply_list_get_first_node (terminal->input_closures);
while (node != NULL) {
ply_terminal_input_closure_t *closure;

View file

@ -70,6 +70,7 @@ void ply_terminal_reset_colors (ply_terminal_t *terminal);
bool ply_terminal_set_unbuffered_input (ply_terminal_t *terminal);
bool ply_terminal_set_buffered_input (ply_terminal_t *terminal);
bool ply_terminal_set_disabled_input (ply_terminal_t *terminal);
bool ply_terminal_refresh_geometry (ply_terminal_t *terminal);
__attribute__((__format__ (__printf__, 2, 3)))

View file

@ -1719,7 +1719,12 @@ flush_head (ply_renderer_backend_t *backend,
if (backend->terminal != NULL) {
ply_terminal_set_mode (backend->terminal, PLY_TERMINAL_MODE_GRAPHICS);
ply_terminal_set_unbuffered_input (backend->terminal);
if (using_input_device (&backend->input_source)) {
ply_terminal_set_disabled_input (backend->terminal);
} else {
ply_terminal_set_unbuffered_input (backend->terminal);
}
}
pixel_buffer = head->pixel_buffer;
updated_region = ply_pixel_buffer_get_updated_areas (pixel_buffer);

View file

@ -590,7 +590,12 @@ flush_head (ply_renderer_backend_t *backend,
if (backend->terminal != NULL) {
ply_terminal_set_mode (backend->terminal, PLY_TERMINAL_MODE_GRAPHICS);
ply_terminal_set_unbuffered_input (backend->terminal);
if (using_input_device (&backend->input_source)) {
ply_terminal_set_disabled_input (backend->terminal);
} else {
ply_terminal_set_unbuffered_input (backend->terminal);
}
}
pixel_buffer = head->pixel_buffer;
updated_region = ply_pixel_buffer_get_updated_areas (pixel_buffer);