aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2023-10-17 00:55:29 +0100
committerdam <dam@gudinoff>2023-10-17 00:55:29 +0100
commit456be46bc0d4d7a0643616c269fbcb2b6f935197 (patch)
tree8743cb9a141517cd5fc6b33a36de502566bc3d13
parentbdaba41cbe7f10c750c31b66dd2696e6b6ea7436 (diff)
downloadtask-time-tracker-456be46bc0d4d7a0643616c269fbcb2b6f935197.tar.zst
task-time-tracker-456be46bc0d4d7a0643616c269fbcb2b6f935197.zip
Added prototype resize signal handler.
-rw-r--r--TUI/module.jai32
1 files changed, 28 insertions, 4 deletions
diff --git a/TUI/module.jai b/TUI/module.jai
index c1f40ce..f113c2a 100644
--- a/TUI/module.jai
+++ b/TUI/module.jai
@@ -138,14 +138,16 @@ process_input :: (thread: *Thread) -> s64 {
return 0;
}
-process_resize :: (signal : s32) #c_call {
+process_resize :: (signal_code : s32) #c_call {
new_context : Context;
push_context new_context {
- if signal != SIGWINCH return;
+ print("SIGNAL:%", signal_code);
+ if signal_code != SIGWINCH return;
+ print("RESIZE\n");
lock(*key_mutex);
defer unlock(*key_mutex);
// TODO Only signal the key_semaphore if we don't already have a Resize on the queue.
- if key_resize != Key.None continue;
+ if key_resize != Keys.None return;
key_resize = Keys.Resize;
signal(*key_semaphore);
}
@@ -167,6 +169,24 @@ get_key :: (wait_milliseconds: s32) -> Key {
}
+// TODO Rename this procedure.
+set_handler :: () {
+ sa : sigaction_t;
+ sa.sa_handler = process_resize;
+ sigemptyset(*(sa.sa_mask));
+ sa.sa_flags = SA_RESTART;
+ sigaction(SIGWINCH, *sa, null);
+}
+
+// TODO Rename this procedure.
+restore_handler :: () {
+ sa : sigaction_t;
+ sa.sa_handler = SIG_DFL;
+ sigaction(SIGWINCH, null, *sa);
+}
+
+
+
start :: () {
if initialized == true return;
dam("A");
@@ -182,18 +202,22 @@ dam("C");
dam("D");
initialized = true;
thread_start(*input_process_thread);
+ set_handler(); // TODO Move to beter place.
dam("E");
+
}
stop :: () {
if initialized == false return;
initialized = false;
+
+ restore_handler(); // TODO Move to beter place.
thread_deinit(*input_process_thread);
destroy(*key_semaphore);
OS_reset_terminal();
- // write_strings(Commands.EnterMainBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor);
+ write_strings(Commands.EnterMainBuffer, Commands.RestoreCursorPosition, Commands.ShowCursor);
}
get_str :: () -> string {