diff options
Diffstat (limited to 'TUI/unix.jai')
| -rw-r--r-- | TUI/unix.jai | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/TUI/unix.jai b/TUI/unix.jai index 7ff1e72..fb79f86 100644 --- a/TUI/unix.jai +++ b/TUI/unix.jai @@ -133,6 +133,39 @@ initial_tio_mode: Terminal_IO_Mode; raw_tio_mode: Terminal_IO_Mode; +//////////////////////////////////////////////////////////////////////////////// +// Resize detection +resize_mutex : Mutex; +was_resized : bool; + +resize_handler :: (signal_code : s32) #c_call { + new_context : Context; + push_context new_context { + print("SIGNAL:%", signal_code); + if signal_code != SIGWINCH then return; + if was_resized == true then return; + print("RESIZE\n"); + lock(*resize_mutex); + defer unlock(*resize_mutex); + was_resized = true; + } +} + +prepare_resize_handler :: () { + sa : sigaction_t; + sa.sa_handler = resize_handler; + sigemptyset(*(sa.sa_mask)); + sa.sa_flags = SA_RESTART; + sigaction(SIGWINCH, *sa, null); +} + +restore_resize_handler :: () { + sa : sigaction_t; + sa.sa_handler = SIG_DFL; + sigaction(SIGWINCH, null, *sa); +} + +//////////////////////////////////////////////////////////////////////////////// #scope_export @@ -154,9 +187,8 @@ OS_prepare_terminal :: () { } OS_reset_terminal :: () { - tcsetattr(STDIN_FILENO, 0, *initial_tio_mode); // TODO Log on error. - restore_resize_handler(); + tcsetattr(STDIN_FILENO, 0, *initial_tio_mode); // TODO Log on error. } OS_read_input :: (buffer: *u8, bytes_to_read: s64) -> bytes_read: s64, error: bool = false, error_message: string = "" { @@ -176,39 +208,9 @@ OS_wait_for_input :: (timeout_milliseconds: s32) -> is_input_available: bool { return ifx poll_return > 0 then true else false; } -resize_mutex : Mutex; -was_resized : bool; - OS_was_terminal_resized :: () -> bool { lock(*resize_mutex); defer unlock(*resize_mutex); defer was_resized = false; return was_resized; } - -resize_handler :: (signal_code : s32) #c_call { - new_context : Context; - push_context new_context { - print("SIGNAL:%", signal_code); - if signal_code != SIGWINCH then return; - if was_resized == true then return; - print("RESIZE\n"); - lock(*resize_mutex); - defer unlock(*resize_mutex); - was_resized = true; - } -} - -prepare_resize_handler :: () { - sa : sigaction_t; - sa.sa_handler = resize_handler; - sigemptyset(*(sa.sa_mask)); - sa.sa_flags = SA_RESTART; - sigaction(SIGWINCH, *sa, null); -} - -restore_resize_handler :: () { - sa : sigaction_t; - sa.sa_handler = SIG_DFL; - sigaction(SIGWINCH, null, *sa); -} |
