From 15fe50d272a5f548c7b9a0b8e79794fe1caf31bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6ttsche?= Date: Thu, 20 Oct 2022 15:03:17 +0200 Subject: Toggle the header meters with pound key Show/hide the header meters with the pound ('#') key. Useful in cases where the header is too large and occupies essential parts of the screen, especially in settings (see #1108). It is only stored as a runtime state, not a persistent setting; to remove the header permanently one can delete all active meters. --- Action.c | 7 +++++++ Action.h | 1 + CommandLine.c | 1 + Panel.c | 3 +++ ScreenManager.c | 26 +++++++++++++++++++++----- ScreenManager.h | 4 ++-- 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/Action.c b/Action.c index 1007be2f..00a69c4a 100644 --- a/Action.c +++ b/Action.c @@ -245,6 +245,11 @@ static Htop_Reaction actionToggleTreeView(State* st) { return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; } +static Htop_Reaction actionToggleHideMeters(State* st) { + st->hideMeters = !st->hideMeters; + return HTOP_RESIZE | HTOP_KEEP_FOLLOWING; +} + static Htop_Reaction actionExpandOrCollapseAllBranches(State* st) { ScreenSettings* ss = st->settings->ss; if (!ss->treeView) { @@ -514,6 +519,7 @@ static const struct { bool roInactive; const char* info; } helpLeft[] = { + { .key = " #: ", .roInactive = false, .info = "hide/show header meters" }, { .key = " Tab: ", .roInactive = false, .info = "switch to next screen tab" }, { .key = " Arrows: ", .roInactive = false, .info = "scroll process list" }, { .key = " Digits: ", .roInactive = false, .info = "incremental PID search" }, @@ -740,6 +746,7 @@ static Htop_Reaction actionShowCommandScreen(State* st) { void Action_setBindings(Htop_Action* keys) { keys[' '] = actionTag; + keys['#'] = actionToggleHideMeters; keys['*'] = actionExpandOrCollapseAllBranches; keys['+'] = actionExpandOrCollapse; keys[','] = actionSetSortColumn; diff --git a/Action.h b/Action.h index 06af1886..09b68bd7 100644 --- a/Action.h +++ b/Action.h @@ -43,6 +43,7 @@ typedef struct State_ { Header* header; bool pauseProcessUpdate; bool hideProcessSelection; + bool hideMeters; } State; static inline bool State_hideFunctionBar(const State* st) { diff --git a/CommandLine.c b/CommandLine.c index 5e72cbf0..70b6d957 100644 --- a/CommandLine.c +++ b/CommandLine.c @@ -371,6 +371,7 @@ int CommandLine_run(const char* name, int argc, char** argv) { .header = header, .pauseProcessUpdate = false, .hideProcessSelection = false, + .hideMeters = false, }; MainPanel_setState(panel, &state); diff --git a/Panel.c b/Panel.c index 4ea03f66..8a4d0aec 100644 --- a/Panel.c +++ b/Panel.c @@ -443,6 +443,9 @@ bool Panel_onKey(Panel* this, int key) { HandlerResult Panel_selectByTyping(Panel* this, int ch) { int size = Panel_size(this); + if (ch == '#') + return IGNORED; + if (!this->eventHandlerState) this->eventHandlerState = xCalloc(100, sizeof(char)); char* buffer = this->eventHandlerState; diff --git a/ScreenManager.c b/ScreenManager.c index e4b04bd3..b2cbf8c8 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -24,7 +24,7 @@ in the source distribution for its full text. #include "XUtils.h" -ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const State* state, bool owner) { +ScreenManager* ScreenManager_new(Header* header, const Settings* settings, State* state, bool owner) { ScreenManager* this; this = xMalloc(sizeof(ScreenManager)); this->x1 = 0; @@ -53,18 +53,28 @@ void ScreenManager_add(ScreenManager* this, Panel* item, int size) { ScreenManager_insert(this, item, size, Vector_size(this->panels)); } +static int header_height(const ScreenManager* this) { + if (this->state->hideMeters) + return 0; + + if (this->header) + return this->header->height; + + return 0; +} + void ScreenManager_insert(ScreenManager* this, Panel* item, int size, int idx) { int lastX = 0; if (idx > 0) { const Panel* last = (const Panel*) Vector_get(this->panels, idx - 1); lastX = last->x + last->w + 1; } - int height = LINES - this->y1 - (this->header ? this->header->height : 0) + this->y2; + int height = LINES - this->y1 - header_height(this) + this->y2; if (size <= 0) { size = COLS - this->x1 + this->x2 - lastX; } Panel_resize(item, size, height); - Panel_move(item, lastX, this->y1 + (this->header ? this->header->height : 0)); + Panel_move(item, lastX, this->y1 + header_height(this)); if (idx < this->panelCount) { for (int i = idx + 1; i <= this->panelCount; i++) { Panel* p = (Panel*) Vector_get(this->panels, i); @@ -91,7 +101,7 @@ Panel* ScreenManager_remove(ScreenManager* this, int idx) { } void ScreenManager_resize(ScreenManager* this) { - int y1_header = this->y1 + (this->header ? this->header->height : 0); + int y1_header = this->y1 + header_height(this); int panels = this->panelCount; int lastX = 0; for (int i = 0; i < panels - 1; i++) { @@ -137,7 +147,8 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi } if (*redraw) { ProcessList_rebuildPanel(pl); - Header_draw(this->header); + if (!this->state->hideMeters) + Header_draw(this->header); } *rescan = false; } @@ -375,6 +386,11 @@ tryRight: goto tryRight; } + break; + case '#': + this->state->hideMeters = !this->state->hideMeters; + ScreenManager_resize(this); + force_redraw = true; break; case 27: case 'q': diff --git a/ScreenManager.h b/ScreenManager.h index 978b524b..d08a9413 100644 --- a/ScreenManager.h +++ b/ScreenManager.h @@ -26,11 +26,11 @@ typedef struct ScreenManager_ { int panelCount; Header* header; const Settings* settings; - const State* state; + State* state; bool allowFocusChange; } ScreenManager; -ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const State* state, bool owner); +ScreenManager* ScreenManager_new(Header* header, const Settings* settings, State* state, bool owner); void ScreenManager_delete(ScreenManager* this); -- cgit v1.2.3