From 68f2bfea619a454b5de1431689eb086cf13f5ceb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Sat, 21 Aug 2021 20:48:45 +0200 Subject: Abstract resize handling by adding a new Htop reaction --- Action.c | 5 +---- Action.h | 1 + MainPanel.c | 3 +++ Panel.h | 3 ++- ScreenManager.c | 4 ++++ 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Action.c b/Action.c index c7f4118b..802d2fc5 100644 --- a/Action.c +++ b/Action.c @@ -388,10 +388,7 @@ Htop_Reaction Action_follow(State* st) { static Htop_Reaction actionSetup(State* st) { Action_runSetup(st); - int headerHeight = Header_calculateHeight(st->header); - Panel_move((Panel*)st->mainPanel, 0, headerHeight); - Panel_resize((Panel*)st->mainPanel, COLS, LINES - headerHeight - 1); - return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; + return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR | HTOP_RESIZE; } static Htop_Reaction actionLsof(State* st) { diff --git a/Action.h b/Action.h index 4fb800f5..99e82be5 100644 --- a/Action.h +++ b/Action.h @@ -30,6 +30,7 @@ typedef enum { HTOP_QUIT = 0x10, HTOP_REDRAW_BAR = 0x20, HTOP_UPDATE_PANELHDR = 0x40 | HTOP_REFRESH, + HTOP_RESIZE = 0x80 | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR, } Htop_Reaction; struct MainPanel_; diff --git a/MainPanel.c b/MainPanel.c index 5a75af3a..21b5d1a3 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -112,6 +112,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { if (reaction & HTOP_REDRAW_BAR) { MainPanel_updateTreeFunctions(this, this->state->settings->treeView); } + if (reaction & HTOP_RESIZE) { + result |= RESIZE; + } if (reaction & HTOP_UPDATE_PANELHDR) { result |= REDRAW; } diff --git a/Panel.h b/Panel.h index 96c138d1..40080da1 100644 --- a/Panel.h +++ b/Panel.h @@ -26,7 +26,8 @@ typedef enum HandlerResult_ { REFRESH = 0x08, REDRAW = 0x10, RESCAN = 0x20, - SYNTH_KEY = 0x40, + RESIZE = 0x40, + SYNTH_KEY = 0x80, } HandlerResult; #define EVENT_SET_SELECTED (-1) diff --git a/ScreenManager.c b/ScreenManager.c index d403e24c..914c510b 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -243,6 +243,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (result & REDRAW) { force_redraw = true; } + if (result & RESIZE) { + ScreenManager_resize(this); + force_redraw = true; + } if (result & RESCAN) { rescan = true; sortTimeout = 0; -- cgit v1.2.3