From 551e67c8231e09399484ed0e48c92f8fddc5cdb7 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Tue, 23 Jul 2019 18:47:27 +0200 Subject: [PATCH] reimplement window resizing After get_wch() was dropped from the code resizing no longer worked, so reimplement it. Use a signal handler, and call the proper ncurses functions so that the internal variables are updated. --- ncdc/include/ncdc/mainwindow.h | 1 + ncdc/src/mainwindow.c | 3 +-- ncdc/src/ncdc.c | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ncdc/include/ncdc/mainwindow.h b/ncdc/include/ncdc/mainwindow.h index 41a0b5d..6071d9e 100644 --- a/ncdc/include/ncdc/mainwindow.h +++ b/ncdc/include/ncdc/mainwindow.h @@ -27,6 +27,7 @@ struct ncdc_mainwindow_; typedef struct ncdc_mainwindow_ *ncdc_mainwindow_t; ncdc_mainwindow_t ncdc_mainwindow_new(void); +void ncdc_mainwindow_resize(ncdc_mainwindow_t n); /* holy shit stains I am lazy */ diff --git a/ncdc/src/mainwindow.c b/ncdc/src/mainwindow.c index c67fc9c..7588ea7 100644 --- a/ncdc/src/mainwindow.c +++ b/ncdc/src/mainwindow.c @@ -66,7 +66,6 @@ struct ncdc_mainwindow_ int focus; }; -static void ncdc_mainwindow_resize(ncdc_mainwindow_t n); static void ncdc_mainwindow_update_focus(ncdc_mainwindow_t n); static bool ncdc_mainwindow_callback(ncdc_input_t i, wchar_t const *s, size_t len, void *arg); @@ -154,7 +153,7 @@ ncdc_mainwindow_callback(ncdc_input_t i, wchar_t const *s, return ret; } -static void ncdc_mainwindow_resize(ncdc_mainwindow_t n) +void ncdc_mainwindow_resize(ncdc_mainwindow_t n) { n->guilds_h = LINES - 2; n->guilds_w = (COLS / 4); diff --git a/ncdc/src/ncdc.c b/ncdc/src/ncdc.c index a0b1599..61d7eb6 100644 --- a/ncdc/src/ncdc.c +++ b/ncdc/src/ncdc.c @@ -86,6 +86,19 @@ static void cleanup(void) dc_unref(mainwin); } +static void handle_winch(int sig) +{ + /* according to ncurses documentation you should call + * endwin(), followed by a refresh() to properly update + * curses + */ + endwin(); + refresh(); + clear(); + + ncdc_mainwindow_resize(mainwin); +} + static void sighandler(int sig) { exit_main(); @@ -167,6 +180,7 @@ int main(int ac, char **av) int ret = 0; signal(SIGINT, sighandler); + signal(SIGWINCH, handle_winch); if (getenv("HOME") == NULL) { fprintf(stderr, "your environment doesn't contain HOME; pls fix\n");