Skip to content

Commit

Permalink
fix crashes during resizing
Browse files Browse the repository at this point in the history
- safeguard ncurses functions called within resize handler
- stop refresh_layout from being called while directories are loading
- resolves #20
  • Loading branch information
Ckath committed Sep 12, 2019
1 parent d7a48d4 commit 40ac0fa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
18 changes: 18 additions & 0 deletions ext/sncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ sinit_pair(short pair, short f, short b)
return r;
}

int
sendwin(void)
{
pthread_mutex_lock(&ncurses_lock);
int r = endwin();
pthread_mutex_unlock(&ncurses_lock);
return r;
}

int
srefresh(void)
{
pthread_mutex_lock(&ncurses_lock);
int r = refresh();
pthread_mutex_unlock(&ncurses_lock);
return r;
}

WINDOW *
snewwin(int nlines, int ncols, int begin_y, int begin_x)
{
Expand Down
2 changes: 2 additions & 0 deletions ext/sncurses.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <ncurses.h>

int sinit_pair(short pair, short f, short b);
int sendwin(void);
int srefresh(void);
WINDOW *snewwin(int nlines, int ncols, int begin_y, int begin_x);
int sdelwin(WINDOW *win);
int sbox(WINDOW *win, chtype verch, chtype horch);
Expand Down
9 changes: 6 additions & 3 deletions fuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,18 @@ char preview_path[PATH_MAX];
static void
handle_redraw()
{
endwin();
refresh();
sendwin();
srefresh();

/* keep the file list within resized window */
scroll_pos = items_len-1 > scroll_pos-LINES+2
? items_len-1-LINES+2 : items_len-scroll_pos < LINES+2
? 0 : scroll_pos;

refresh_layout();
extern bool items_loading;
if (!items_loading) {
refresh_layout();
}
}

static void
Expand Down

0 comments on commit 40ac0fa

Please sign in to comment.