aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-05-23 04:02:11 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-05-23 04:02:11 -0700
commitce72a889e26a6add32104f3cbdacd73091b3335f (patch)
treec2634c37d072b1e4e8e03061f2389120c760183d
parentfcfb1a399529a41253ab4a1ba1fd612a77878c50 (diff)
Properly handle window resizes
-rw-r--r--bb.c19
-rw-r--r--config.def.h2
2 files changed, 11 insertions, 10 deletions
diff --git a/bb.c b/bb.c
index c9a2f19..25eea0d 100644
--- a/bb.c
+++ b/bb.c
@@ -35,6 +35,7 @@ static struct termios orig_termios;
static int termfd;
static int width, height;
static int mouse_x, mouse_y;
+static int force_redraw = 0;
typedef enum {
SORT_ALPHA = 0,
@@ -71,12 +72,13 @@ typedef struct {
} while (0)
static void _err();
-static void update_term_size(void)
+static void update_term_size(int _)
{
struct winsize sz = {0};
ioctl(termfd, TIOCGWINSZ, &sz);
width = sz.ws_col;
height = sz.ws_row;
+ force_redraw = 1;
}
static inline int clamped(int x, int low, int high)
@@ -86,11 +88,6 @@ static inline int clamped(int x, int low, int high)
return x;
}
-static void do_nothing(int _)
-{
- // Used as SIGINT handler
-}
-
static void init_term()
{
termfd = open("/dev/tty", O_RDWR);
@@ -108,7 +105,8 @@ static void init_term()
tcsetattr(termfd, TCSAFLUSH, &tios);
// xterm-specific:
writez(termfd, "\e[?1049h");
- update_term_size();
+ update_term_size(0);
+ signal(SIGWINCH, update_term_size);
// Initiate mouse tracking:
writez(termfd, "\e[?1000h\e[?1002h\e[?1015h\e[?1006h");
// hide cursor
@@ -117,6 +115,7 @@ static void init_term()
static void close_term()
{
+ signal(SIGWINCH, SIG_IGN);
// xterm-specific:
writez(termfd, "\e[?1049l");
// Show cursor:
@@ -141,7 +140,7 @@ static char bb_tmpfile[] = "/tmp/bb.XXXXXX";
static int run_cmd_on_selection(bb_state_t *state, const char *cmd)
{
pid_t child;
- sig_t old_handler = signal(SIGINT, do_nothing);
+ sig_t old_handler = signal(SIGINT, SIG_IGN);
strcpy(bb_tmpfile, "/tmp/bb.XXXXXX");
if (!mktemp(bb_tmpfile))
@@ -632,10 +631,12 @@ static void explore(char *path, int print_dir, int print_selection, char sep)
int picked, scrolloff, lazy = 0;
while (1) {
redraw:
- render(&state, lazy);
+ render(&state, lazy && !force_redraw);
+ force_redraw = 0;
lazy = 0;
skip_redraw:
scrolloff = MIN(SCROLLOFF, (height-4)/2);
+ if (force_redraw) goto redraw;
int key = term_getkey(termfd, &mouse_x, &mouse_y, KEY_DELAY);
switch (key) {
case KEY_MOUSE_LEFT: {
diff --git a/config.def.h b/config.def.h
index 324973c..f2aced1 100644
--- a/config.def.h
+++ b/config.def.h
@@ -3,9 +3,9 @@
*/
#include "keys.h"
-#define PROG_FUZZY "fzf"
#define PIPE_SELECTION_TO " printf '%s\\n' \"$@\" | "
#define AND_PAUSE " && read -n1 -p '\n\e[2m...press any key to continue...\e[0m\e[?25l'"
+
#define SCROLLOFF 5
#define NORMAL_TERM (1<<0)