Add option to hide the Function Bar

Support three settings:
  - Always show Function Bar
  - Always hide the Function Bar, except in Infoscreens (Env/Locks...)
    and when editing the search and filter mode
  - Hide the Function Bar on ESC until the next user input

Closes: #439
This commit is contained in:
Christian Göttsche 2020-12-28 23:26:14 +01:00 committed by cgzones
parent 24c5ca9ddf
commit a3cced9fb6
10 changed files with 36 additions and 17 deletions

View File

@ -325,7 +325,7 @@ static Htop_Reaction actionKill(State* st) {
if (sgn) { if (sgn) {
if (sgn->key != 0) { if (sgn->key != 0) {
Panel_setHeader(st->panel, "Sending..."); Panel_setHeader(st->panel, "Sending...");
Panel_draw(st->panel, false, true, true); Panel_draw(st->panel, false, true, true, State_hideFunctionBar(st));
refresh(); refresh();
MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL); MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL);
napms(500); napms(500);

View File

@ -41,6 +41,10 @@ typedef struct State_ {
bool hideProcessSelection; bool hideProcessSelection;
} State; } State;
static inline bool State_hideFunctionBar(const State* st) {
return st->settings->hideFunctionBar == 2 || (st->settings->hideFunctionBar == 1 && st->hideProcessSelection);
}
typedef Htop_Reaction (*Htop_Action)(State* st); typedef Htop_Reaction (*Htop_Action)(State* st);
Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess); Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess);

View File

@ -124,6 +124,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
Panel_add(super, (Object*) NumberItem_newByRef("Update interval (in seconds)", &(settings->delay), -1, 1, 255)); Panel_add(super, (Object*) NumberItem_newByRef("Update interval (in seconds)", &(settings->delay), -1, 1, 255));
Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges))); Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges)));
Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24*60*60)); Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24*60*60));
Panel_add(super, (Object*) NumberItem_newByRef("Hide Function Bar (0 - off, 1 - on ESC until next input, 2 - permanently)", &(settings->hideFunctionBar), 0, 0, 2));
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity))); Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
#endif #endif

View File

@ -56,7 +56,7 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) {
mvhline(0, 0, ' ', COLS); mvhline(0, 0, ' ', COLS);
mvwprintw(stdscr, 0, 0, title); mvwprintw(stdscr, 0, 0, title);
attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[DEFAULT_COLOR]);
Panel_draw(this->display, true, true, true); Panel_draw(this->display, true, true, true, false);
IncSet_drawBar(this->inc); IncSet_drawBar(this->inc);
} }
@ -89,7 +89,7 @@ void InfoScreen_run(InfoScreen* this) {
bool looping = true; bool looping = true;
while (looping) { while (looping) {
Panel_draw(panel, false, true, true); Panel_draw(panel, false, true, true, false);
IncSet_drawBar(this->inc); IncSet_drawBar(this->inc);
if (this->inc->active) { if (this->inc->active) {

View File

@ -51,6 +51,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
Htop_Reaction reaction = HTOP_OK; Htop_Reaction reaction = HTOP_OK;
/* reset on every normal key */
if (ch != ERR && ch != KEY_RESIZE) if (ch != ERR && ch != KEY_RESIZE)
this->state->hideProcessSelection = false; this->state->hideProcessSelection = false;
@ -160,8 +161,13 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Ar
return ok; return ok;
} }
static void MainPanel_drawFunctionBar(Panel* super) { static void MainPanel_drawFunctionBar(Panel* super, bool hideFunctionBar) {
MainPanel* this = (MainPanel*) super; MainPanel* this = (MainPanel*) super;
// Do not hide active search and filter bar.
if (hideFunctionBar && !this->inc->active)
return;
IncSet_drawBar(this->inc); IncSet_drawBar(this->inc);
if (this->state->pauseProcessUpdate) { if (this->state->pauseProcessUpdate) {
FunctionBar_append("PAUSED", CRT_colors[PAUSED]); FunctionBar_append("PAUSED", CRT_colors[PAUSED]);

View File

@ -208,7 +208,7 @@ void Panel_splice(Panel* this, Vector* from) {
this->needsRedraw = true; this->needsRedraw = true;
} }
void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelected) { void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelected, bool hideFunctionBar) {
assert (this != NULL); assert (this != NULL);
int size = Vector_size(this->items); int size = Vector_size(this->items);
@ -217,6 +217,9 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect
int x = this->x; int x = this->x;
int h = this->h; int h = this->h;
if (hideFunctionBar)
h++;
const int header_attr = focus const int header_attr = focus
? CRT_colors[PANEL_HEADER_FOCUS] ? CRT_colors[PANEL_HEADER_FOCUS]
: CRT_colors[PANEL_HEADER_UNFOCUS]; : CRT_colors[PANEL_HEADER_UNFOCUS];
@ -319,8 +322,8 @@ void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelect
if (focus && (this->needsRedraw || force_redraw || !this->wasFocus)) { if (focus && (this->needsRedraw || force_redraw || !this->wasFocus)) {
if (Panel_drawFunctionBarFn(this)) if (Panel_drawFunctionBarFn(this))
Panel_drawFunctionBar(this); Panel_drawFunctionBar(this, hideFunctionBar);
else else if (!hideFunctionBar)
FunctionBar_draw(this->currentBar); FunctionBar_draw(this->currentBar);
} }

18
Panel.h
View File

@ -36,7 +36,7 @@ typedef enum HandlerResult_ {
#define EVENT_HEADER_CLICK_GET_X(ev_) ((ev_) + 10000) #define EVENT_HEADER_CLICK_GET_X(ev_) ((ev_) + 10000)
typedef HandlerResult (*Panel_EventHandler)(Panel*, int); typedef HandlerResult (*Panel_EventHandler)(Panel*, int);
typedef void (*Panel_DrawFunctionBar)(Panel*); typedef void (*Panel_DrawFunctionBar)(Panel*, bool);
typedef void (*Panel_PrintHeader)(Panel*); typedef void (*Panel_PrintHeader)(Panel*);
typedef struct PanelClass_ { typedef struct PanelClass_ {
@ -46,13 +46,13 @@ typedef struct PanelClass_ {
const Panel_PrintHeader printHeader; const Panel_PrintHeader printHeader;
} PanelClass; } PanelClass;
#define As_Panel(this_) ((const PanelClass*)((this_)->super.klass)) #define As_Panel(this_) ((const PanelClass*)((this_)->super.klass))
#define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler #define Panel_eventHandlerFn(this_) As_Panel(this_)->eventHandler
#define Panel_eventHandler(this_, ev_) (assert(As_Panel(this_)->eventHandler), As_Panel(this_)->eventHandler((Panel*)(this_), ev_)) #define Panel_eventHandler(this_, ev_) (assert(As_Panel(this_)->eventHandler), As_Panel(this_)->eventHandler((Panel*)(this_), ev_))
#define Panel_drawFunctionBarFn(this_) As_Panel(this_)->drawFunctionBar #define Panel_drawFunctionBarFn(this_) As_Panel(this_)->drawFunctionBar
#define Panel_drawFunctionBar(this_) (assert(As_Panel(this_)->drawFunctionBar), As_Panel(this_)->drawFunctionBar((Panel*)(this_))) #define Panel_drawFunctionBar(this_, hideFB_) (assert(As_Panel(this_)->drawFunctionBar), As_Panel(this_)->drawFunctionBar((Panel*)(this_), hideFB_))
#define Panel_printHeaderFn(this_) As_Panel(this_)->printHeader #define Panel_printHeaderFn(this_) As_Panel(this_)->printHeader
#define Panel_printHeader(this_) (assert(As_Panel(this_)->printHeader), As_Panel(this_)->printHeader((Panel*)(this_))) #define Panel_printHeader(this_) (assert(As_Panel(this_)->printHeader), As_Panel(this_)->printHeader((Panel*)(this_)))
struct Panel_ { struct Panel_ {
Object super; Object super;
@ -118,7 +118,7 @@ int Panel_size(Panel* this);
void Panel_setSelected(Panel* this, int selected); void Panel_setSelected(Panel* this, int selected);
void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelected); void Panel_draw(Panel* this, bool force_redraw, bool focus, bool highlightSelected, bool hideFunctionBar);
void Panel_splice(Panel* this, Vector* from); void Panel_splice(Panel* this, Vector* from);

View File

@ -123,7 +123,7 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_
const int nPanels = this->panelCount; const int nPanels = this->panelCount;
for (int i = 0; i < nPanels; i++) { for (int i = 0; i < nPanels; i++) {
Panel* panel = (Panel*) Vector_get(this->panels, i); Panel* panel = (Panel*) Vector_get(this->panels, i);
Panel_draw(panel, force_redraw, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection)); Panel_draw(panel, force_redraw, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection), State_hideFunctionBar(this->state));
mvvline(panel->y, panel->x + panel->w, ' ', panel->h); mvvline(panel->y, panel->x + panel->w, ' ', panel->h);
} }
} }

View File

@ -221,6 +221,8 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo
} else if (String_eq(option[0], "right_meter_modes")) { } else if (String_eq(option[0], "right_meter_modes")) {
Settings_readMeterModes(this, option[1], 1); Settings_readMeterModes(this, option[1], 1);
didReadMeters = true; didReadMeters = true;
} else if (String_eq(option[0], "hide_function_bar")) {
this->hideFunctionBar = atoi(option[1]);
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
} else if (String_eq(option[0], "topology_affinity")) { } else if (String_eq(option[0], "topology_affinity")) {
this->topologyAffinity = !!atoi(option[1]); this->topologyAffinity = !!atoi(option[1]);
@ -315,6 +317,7 @@ bool Settings_write(Settings* this) {
fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0); fprintf(fd, "left_meter_modes="); writeMeterModes(this, fd, 0);
fprintf(fd, "right_meters="); writeMeters(this, fd, 1); fprintf(fd, "right_meters="); writeMeters(this, fd, 1);
fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1); fprintf(fd, "right_meter_modes="); writeMeterModes(this, fd, 1);
fprintf(fd, "hide_function_bar=%d\n", (int) this->hideFunctionBar);
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
fprintf(fd, "topology_affinity=%d\n", (int) this->topologyAffinity); fprintf(fd, "topology_affinity=%d\n", (int) this->topologyAffinity);
#endif #endif
@ -352,6 +355,7 @@ Settings* Settings_new(int initialCpuCount) {
this->findCommInCmdline = true; this->findCommInCmdline = true;
this->stripExeFromCmdline = true; this->stripExeFromCmdline = true;
this->showMergedCommand = false; this->showMergedCommand = false;
this->hideFunctionBar = 0;
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
this->topologyAffinity = false; this->topologyAffinity = false;
#endif #endif

View File

@ -64,6 +64,7 @@ typedef struct Settings_ {
bool accountGuestInCPUMeter; bool accountGuestInCPUMeter;
bool headerMargin; bool headerMargin;
bool enableMouse; bool enableMouse;
int hideFunctionBar; // 0 - off, 1 - on ESC until next input, 2 - permanently
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
bool topologyAffinity; bool topologyAffinity;
#endif #endif