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.
This commit is contained in:
Florian Stinglmayr 2019-07-23 18:47:27 +02:00
parent 318c874dc6
commit 551e67c823
3 changed files with 16 additions and 2 deletions

View File

@ -27,6 +27,7 @@ struct ncdc_mainwindow_;
typedef struct ncdc_mainwindow_ *ncdc_mainwindow_t; typedef struct ncdc_mainwindow_ *ncdc_mainwindow_t;
ncdc_mainwindow_t ncdc_mainwindow_new(void); ncdc_mainwindow_t ncdc_mainwindow_new(void);
void ncdc_mainwindow_resize(ncdc_mainwindow_t n);
/* holy shit stains I am lazy /* holy shit stains I am lazy
*/ */

View File

@ -66,7 +66,6 @@ struct ncdc_mainwindow_
int focus; int focus;
}; };
static void ncdc_mainwindow_resize(ncdc_mainwindow_t n);
static void ncdc_mainwindow_update_focus(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, static bool ncdc_mainwindow_callback(ncdc_input_t i, wchar_t const *s,
size_t len, void *arg); size_t len, void *arg);
@ -154,7 +153,7 @@ ncdc_mainwindow_callback(ncdc_input_t i, wchar_t const *s,
return ret; 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_h = LINES - 2;
n->guilds_w = (COLS / 4); n->guilds_w = (COLS / 4);

View File

@ -86,6 +86,19 @@ static void cleanup(void)
dc_unref(mainwin); 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) static void sighandler(int sig)
{ {
exit_main(); exit_main();
@ -167,6 +180,7 @@ int main(int ac, char **av)
int ret = 0; int ret = 0;
signal(SIGINT, sighandler); signal(SIGINT, sighandler);
signal(SIGWINCH, handle_winch);
if (getenv("HOME") == NULL) { if (getenv("HOME") == NULL) {
fprintf(stderr, "your environment doesn't contain HOME; pls fix\n"); fprintf(stderr, "your environment doesn't contain HOME; pls fix\n");