From e7372d18a1a661d8c3dba9f51e1f17b5f94171a7 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Wed, 10 Jan 2024 11:17:08 +0100 Subject: New upstream version 3.3.0 --- ScreenManager.c | 84 ++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 59 insertions(+), 25 deletions(-) (limited to 'ScreenManager.c') diff --git a/ScreenManager.c b/ScreenManager.c index e4b04bd..e7e82e1 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -12,19 +12,23 @@ in the source distribution for its full text. #include #include #include +#include #include #include "CRT.h" #include "FunctionBar.h" +#include "Machine.h" #include "Macros.h" #include "Object.h" #include "Platform.h" -#include "ProcessList.h" +#include "Process.h" #include "ProvideCurses.h" +#include "Settings.h" +#include "Table.h" #include "XUtils.h" -ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const State* state, bool owner) { +ScreenManager* ScreenManager_new(Header* header, Machine* host, State* state, bool owner) { ScreenManager* this; this = xMalloc(sizeof(ScreenManager)); this->x1 = 0; @@ -34,7 +38,7 @@ ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const this->panels = Vector_new(Class(Panel), owner, DEFAULT_SIZE); this->panelCount = 0; this->header = header; - this->settings = settings; + this->host = host; this->state = state; this->allowFocusChange = true; return this; @@ -53,18 +57,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 +105,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++) { @@ -105,13 +119,13 @@ void ScreenManager_resize(ScreenManager* this) { Panel_move(panel, lastX, y1_header); } -static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut, bool *force_redraw) { - ProcessList* pl = this->header->pl; +static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut, bool* force_redraw) { + Machine* host = this->host; - Platform_gettime_realtime(&pl->realtime, &pl->realtimeMs); - double newTime = ((double)pl->realtime.tv_sec * 10) + ((double)pl->realtime.tv_usec / 100000); + Platform_gettime_realtime(&host->realtime, &host->realtimeMs); + double newTime = ((double)host->realtime.tv_sec * 10) + ((double)host->realtime.tv_usec / 100000); - *timedOut = (newTime - *oldTime > this->settings->delay); + *timedOut = (newTime - *oldTime > host->settings->delay); *rescan |= *timedOut; if (newTime < *oldTime) { @@ -121,12 +135,15 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi if (*rescan) { *oldTime = newTime; int oldUidDigits = Process_uidDigits; - if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->ss->treeView)) { - pl->needsSort = true; + if (!this->state->pauseUpdate && (*sortTimeout == 0 || host->settings->ss->treeView)) { + host->activeTable->needsSort = true; *sortTimeout = 1; } - // scan processes first - some header values are calculated there - ProcessList_scan(pl, this->state->pauseProcessUpdate); + // sample current values for system metrics and processes if not paused + Machine_scan(host); + if (!this->state->pauseUpdate) + Machine_scanTables(host); + // always update header, especially to avoid gaps in graph meters Header_updateData(this->header); // force redraw if the number of UID digits was changed @@ -136,13 +153,14 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi *redraw = true; } if (*redraw) { - ProcessList_rebuildPanel(pl); - Header_draw(this->header); + Table_rebuildPanel(host->activeTable); + if (!this->state->hideMeters) + Header_draw(this->header); } *rescan = false; } -static inline bool drawTab(int* y, int* x, int l, const char* name, bool cur) { +static inline bool drawTab(const int* y, int* x, int l, const char* name, bool cur) { attrset(CRT_colors[cur ? SCREENS_CUR_BORDER : SCREENS_OTH_BORDER]); mvaddch(*y, *x, '['); (*x)++; @@ -164,8 +182,9 @@ static inline bool drawTab(int* y, int* x, int l, const char* name, bool cur) { } static void ScreenManager_drawScreenTabs(ScreenManager* this) { - ScreenSettings** screens = this->settings->screens; - int cur = this->settings->ssIndex; + Settings* settings = this->host->settings; + ScreenSettings** screens = settings->screens; + int cur = settings->ssIndex; int l = COLS; Panel* panel = (Panel*) Vector_get(this->panels, 0); int y = panel->y - 1; @@ -177,7 +196,7 @@ static void ScreenManager_drawScreenTabs(ScreenManager* this) { } for (int s = 0; screens[s]; s++) { - bool ok = drawTab(&y, &x, l, screens[s]->name, s == cur); + bool ok = drawTab(&y, &x, l, screens[s]->heading, s == cur); if (!ok) { break; } @@ -186,7 +205,8 @@ static void ScreenManager_drawScreenTabs(ScreenManager* this) { } static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_redraw) { - if (this->settings->screenTabs) { + Settings* settings = this->host->settings; + if (settings->screenTabs) { ScreenManager_drawScreenTabs(this); } const int nPanels = this->panelCount; @@ -195,7 +215,7 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_ Panel_draw(panel, force_redraw, i == focus, - panel != (Panel*)this->state->mainPanel || !this->state->hideProcessSelection, + panel != (Panel*)this->state->mainPanel || !this->state->hideSelection, State_hideFunctionBar(this->state)); mvvline(panel->y, panel->x + panel->w, ' ', panel->h + (State_hideFunctionBar(this->state) ? 1 : 0)); } @@ -206,6 +226,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, con int focus = 0; Panel* panelFocus = (Panel*) Vector_get(this->panels, focus); + Settings* settings = this->host->settings; double oldTime = 0.0; @@ -229,6 +250,12 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, con if (redraw || force_redraw) { ScreenManager_drawPanels(this, focus, force_redraw); force_redraw = false; + if (this->host->iterationsRemaining != -1) { + if (!--this->host->iterationsRemaining) { + quit = true; + continue; + } + } } int prevCh = ch; @@ -236,7 +263,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, con HandlerResult result = IGNORED; #ifdef HAVE_GETMOUSE - if (ch == KEY_MOUSE && this->settings->enableMouse) { + if (ch == KEY_MOUSE && settings->enableMouse) { ch = ERR; MEVENT mevent; int ok = getmouse(&mevent); @@ -251,7 +278,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, con if (mevent.y == panel->y) { ch = EVENT_HEADER_CLICK(mevent.x - panel->x); break; - } else if (this->settings->screenTabs && mevent.y == panel->y - 1) { + } else if (settings->screenTabs && mevent.y == panel->y - 1) { ch = EVENT_SCREEN_TAB_CLICK(mevent.x); break; } else if (mevent.y > panel->y && mevent.y <= panel->y + panel->h) { @@ -294,12 +321,14 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey, con redraw = false; continue; } + switch (ch) { case KEY_ALT('H'): ch = KEY_LEFT; break; case KEY_ALT('J'): ch = KEY_DOWN; break; case KEY_ALT('K'): ch = KEY_UP; break; case KEY_ALT('L'): ch = KEY_RIGHT; break; } + redraw = true; if (Panel_eventHandlerFn(panelFocus)) { result = Panel_eventHandler(panelFocus, ch); @@ -375,6 +404,11 @@ tryRight: goto tryRight; } + break; + case '#': + this->state->hideMeters = !this->state->hideMeters; + ScreenManager_resize(this); + force_redraw = true; break; case 27: case 'q': -- cgit v1.2.3