Abstract resize handling by adding a new Htop reaction

This commit is contained in:
Christian Göttsche 2021-08-21 20:48:45 +02:00 committed by BenBE
parent b9e69223d0
commit 68f2bfea61
5 changed files with 11 additions and 5 deletions

View File

@ -388,10 +388,7 @@ Htop_Reaction Action_follow(State* st) {
static Htop_Reaction actionSetup(State* st) { static Htop_Reaction actionSetup(State* st) {
Action_runSetup(st); Action_runSetup(st);
int headerHeight = Header_calculateHeight(st->header); return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR | HTOP_RESIZE;
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;
} }
static Htop_Reaction actionLsof(State* st) { static Htop_Reaction actionLsof(State* st) {

View File

@ -30,6 +30,7 @@ typedef enum {
HTOP_QUIT = 0x10, HTOP_QUIT = 0x10,
HTOP_REDRAW_BAR = 0x20, HTOP_REDRAW_BAR = 0x20,
HTOP_UPDATE_PANELHDR = 0x40 | HTOP_REFRESH, HTOP_UPDATE_PANELHDR = 0x40 | HTOP_REFRESH,
HTOP_RESIZE = 0x80 | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR,
} Htop_Reaction; } Htop_Reaction;
struct MainPanel_; struct MainPanel_;

View File

@ -112,6 +112,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
if (reaction & HTOP_REDRAW_BAR) { if (reaction & HTOP_REDRAW_BAR) {
MainPanel_updateTreeFunctions(this, this->state->settings->treeView); MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
} }
if (reaction & HTOP_RESIZE) {
result |= RESIZE;
}
if (reaction & HTOP_UPDATE_PANELHDR) { if (reaction & HTOP_UPDATE_PANELHDR) {
result |= REDRAW; result |= REDRAW;
} }

View File

@ -26,7 +26,8 @@ typedef enum HandlerResult_ {
REFRESH = 0x08, REFRESH = 0x08,
REDRAW = 0x10, REDRAW = 0x10,
RESCAN = 0x20, RESCAN = 0x20,
SYNTH_KEY = 0x40, RESIZE = 0x40,
SYNTH_KEY = 0x80,
} HandlerResult; } HandlerResult;
#define EVENT_SET_SELECTED (-1) #define EVENT_SET_SELECTED (-1)

View File

@ -243,6 +243,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if (result & REDRAW) { if (result & REDRAW) {
force_redraw = true; force_redraw = true;
} }
if (result & RESIZE) {
ScreenManager_resize(this);
force_redraw = true;
}
if (result & RESCAN) { if (result & RESCAN) {
rescan = true; rescan = true;
sortTimeout = 0; sortTimeout = 0;