From 69f439eff387a6ecb52734e400b297a3c85f2285 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Tue, 21 Sep 2021 08:35:19 +0200 Subject: New upstream version 3.1.0 --- ScreenManager.c | 58 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 22 deletions(-) (limited to 'ScreenManager.c') diff --git a/ScreenManager.c b/ScreenManager.c index 0ab5231..914c510 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -5,6 +5,8 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ +#include "config.h" // IWYU pragma: keep + #include "ScreenManager.h" #include @@ -15,6 +17,7 @@ in the source distribution for its full text. #include "CRT.h" #include "FunctionBar.h" #include "Object.h" +#include "Platform.h" #include "ProcessList.h" #include "ProvideCurses.h" #include "XUtils.h" @@ -24,7 +27,7 @@ ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const ScreenManager* this; this = xMalloc(sizeof(ScreenManager)); this->x1 = 0; - this->y1 = header->height; + this->y1 = 0; this->x2 = 0; this->y2 = -1; this->panels = Vector_new(Class(Panel), owner, DEFAULT_SIZE); @@ -32,7 +35,6 @@ ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const this->header = header; this->settings = settings; this->state = state; - this->owner = owner; this->allowFocusChange = true; return this; } @@ -42,23 +44,23 @@ void ScreenManager_delete(ScreenManager* this) { free(this); } -inline int ScreenManager_size(ScreenManager* this) { +inline int ScreenManager_size(const ScreenManager* this) { return this->panelCount; } void ScreenManager_add(ScreenManager* this, Panel* item, int size) { int lastX = 0; if (this->panelCount > 0) { - Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1); + const Panel* last = (const Panel*) Vector_get(this->panels, this->panelCount - 1); lastX = last->x + last->w + 1; } - int height = LINES - this->y1 + this->y2; + int height = LINES - this->y1 - (this->header ? this->header->height : 0) + this->y2; if (size > 0) { Panel_resize(item, size, height); } else { Panel_resize(item, COLS - this->x1 + this->x2 - lastX, height); } - Panel_move(item, lastX, this->y1); + Panel_move(item, lastX, this->y1 + (this->header ? this->header->height : 0)); Vector_add(this->panels, item); item->needsRedraw = true; this->panelCount++; @@ -71,30 +73,26 @@ Panel* ScreenManager_remove(ScreenManager* this, int idx) { return panel; } -void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) { - this->x1 = x1; - this->y1 = y1; - this->x2 = x2; - this->y2 = y2; +void ScreenManager_resize(ScreenManager* this) { + int y1_header = this->y1 + (this->header ? this->header->height : 0); int panels = this->panelCount; int lastX = 0; for (int i = 0; i < panels - 1; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - Panel_resize(panel, panel->w, LINES - y1 + y2); - Panel_move(panel, lastX, y1); + Panel_resize(panel, panel->w, LINES - y1_header + this->y2); + Panel_move(panel, lastX, y1_header); lastX = panel->x + panel->w + 1; } Panel* panel = (Panel*) Vector_get(this->panels, panels - 1); - Panel_resize(panel, COLS - x1 + x2 - lastX, LINES - y1 + y2); - Panel_move(panel, lastX, y1); + Panel_resize(panel, COLS - this->x1 + this->x2 - lastX, LINES - y1_header + this->y2); + Panel_move(panel, lastX, y1_header); } static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut) { ProcessList* pl = this->header->pl; - struct timeval tv; - gettimeofday(&tv, NULL); - double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000); + Platform_gettime_realtime(&pl->realtime, &pl->realtimeMs); + double newTime = ((double)pl->realtime.tv_sec * 10) + ((double)pl->realtime.tv_usec / 100000); *timedOut = (newTime - *oldTime > this->settings->delay); *rescan |= *timedOut; @@ -105,7 +103,10 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi if (*rescan) { *oldTime = newTime; + // scan processes first - some header values are calculated there ProcessList_scan(pl, this->state->pauseProcessUpdate); + // always update header, especially to avoid gaps in graph meters + Header_updateData(this->header); if (!this->state->pauseProcessUpdate && (*sortTimeout == 0 || this->settings->treeView)) { ProcessList_sort(pl); *sortTimeout = 1; @@ -123,7 +124,11 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus, bool force_ const int nPanels = this->panelCount; for (int i = 0; i < nPanels; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - Panel_draw(panel, force_redraw, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection), State_hideFunctionBar(this->state)); + Panel_draw(panel, + force_redraw, + i == focus, + panel != (Panel*)this->state->mainPanel || !this->state->hideProcessSelection, + State_hideFunctionBar(this->state)); mvvline(panel->y, panel->x + panel->w, ' ', panel->h + (State_hideFunctionBar(this->state) ? 1 : 0)); } } @@ -157,10 +162,13 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { } int prevCh = ch; +#ifdef HAVE_SET_ESCDELAY set_escdelay(25); +#endif ch = getch(); HandlerResult result = IGNORED; +#ifdef HAVE_GETMOUSE if (ch == KEY_MOUSE && this->settings->enableMouse) { ch = ERR; MEVENT mevent; @@ -181,7 +189,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (panel == panelFocus || this->allowFocusChange) { focus = i; panelFocus = panel; - Object* oldSelection = Panel_getSelected(panel); + const Object* oldSelection = Panel_getSelected(panel); Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1); if (Panel_getSelected(panel) == oldSelection) { ch = KEY_RECLICK; @@ -201,8 +209,10 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { } } } +#endif if (ch == ERR) { - sortTimeout--; + if (sortTimeout > 0) + sortTimeout--; if (prevCh == ch && !timedOut) { closeTimeout++; if (closeTimeout == 100) { @@ -233,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; @@ -247,7 +261,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { switch (ch) { case KEY_RESIZE: { - ScreenManager_resize(this, this->x1, this->y1, this->x2, this->y2); + ScreenManager_resize(this); continue; } case KEY_LEFT: -- cgit v1.2.3