Skip to content

Commit

Permalink
Fix crash at startup on terminal resize (#469)
Browse files Browse the repository at this point in the history
do actual screen resize only when we are fully running

in addition: do not treat terminal resize as a key press
  • Loading branch information
zcsahok authored Feb 18, 2025
1 parent 73afaeb commit 1f422f2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/globalvars.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ extern bool demode;
extern bool ctcomp;
extern bool show_time;
extern bool use_rxvt;
extern bool tlf_initialized;
extern bool time_master;
extern bool noautocq;
extern bool no_arrows;
Expand Down
4 changes: 4 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ int portnum = 0;

bool use_rxvt = false;
bool use_xterm = false;
bool tlf_initialized = false; // true: everything has been set up

int tlfcolors[8][2] = { {COLOR_BLACK, COLOR_WHITE},
{COLOR_GREEN, COLOR_YELLOW},
Expand Down Expand Up @@ -1140,6 +1141,9 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}

tlf_initialized = true;


/* now start logging !! Does never return */
logit();

Expand Down
35 changes: 25 additions & 10 deletions src/ui_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ int key_kPRV3 = 0;
int key_kNXT5 = 0;
int key_kPRV5 = 0;

pthread_mutex_t panel_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_mutex_t panel_mutex = PTHREAD_MUTEX_INITIALIZER;

static int getkey(int wait);
static const bool WAIT = true;
static const bool NO_WAIT = false;

static int getkey(bool wait);
static int onechar(void);
void resize_layout(void);

Expand Down Expand Up @@ -125,32 +128,41 @@ void lookup_keys() {
*
*/
int key_get() {
return getkey(1);
return getkey(WAIT);
}

/** key_poll return next key from terminal if there is one
*
*/
int key_poll() {
return getkey(0);
return getkey(NO_WAIT);
}


/* helper function to set 'nodelay' mode according to 'wait'
* parameter and then ask for the next character
* leaves 'nodelay' afterwards always as FALSE (meaning: wait for
* character
* in both ('wait' and 'no-wait') mode terminal resizes are handled,
* but no KEY_RESIZE is returned.
*/
static int getkey(int wait) {
int x = 0;
static int getkey(bool wait) {

nodelay(stdscr, wait ? FALSE : TRUE);

x = onechar();
bool done = !wait;
int x;
do {
x = onechar();

if (x == KEY_RESIZE) {
resize_layout();
}
if (x == KEY_RESIZE) {
resize_layout();
x = 0; // do not propagate KEY_RESIZE to caller
} else {
done = true;
}

} while (!done);

nodelay(stdscr, FALSE);

Expand Down Expand Up @@ -337,6 +349,9 @@ static int onechar(void) {
*/
void resize_layout(void) {
getmaxyx(stdscr, ymax, xmax);
if (!tlf_initialized) {
return; // only update terminal size
}
clear_display();
clusterinfo();
refresh_splitlayout();
Expand Down
2 changes: 2 additions & 0 deletions test/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ char pr_hostaddress[48] = "111.222.111.222";
char *config_file = NULL;
int portnum = 0;

bool tlf_initialized = false;

bool use_rxvt = false;
int use_xterm = 0;
int tlfcolors[8][2] = { {COLOR_BLACK, COLOR_WHITE},
Expand Down

0 comments on commit 1f422f2

Please sign in to comment.