From 65357c8c46154de4e4eca14075bfe5523bb5fc14 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 7 Dec 2020 10:26:01 +0100 Subject: New upstream version 3.0.3 --- ScreenManager.c | 157 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 89 insertions(+), 68 deletions(-) (limited to 'ScreenManager.c') diff --git a/ScreenManager.c b/ScreenManager.c index 92e792b..ac93721 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -1,34 +1,37 @@ /* htop - ScreenManager.c (C) 2004-2011 Hisham H. Muhammad -Released under the GNU GPL, see the COPYING file +Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ #include "ScreenManager.h" -#include "ProcessList.h" - -#include "Object.h" -#include "CRT.h" #include -#include -#include #include +#include +#include +#include "CRT.h" +#include "FunctionBar.h" +#include "Object.h" +#include "ProcessList.h" +#include "ProvideCurses.h" +#include "XUtils.h" -ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner) { + +ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const State* state, bool owner) { ScreenManager* this; this = xMalloc(sizeof(ScreenManager)); - this->x1 = x1; - this->y1 = y1; - this->x2 = x2; - this->y2 = y2; - this->orientation = orientation; + this->x1 = 0; + this->y1 = header->height; + this->x2 = 0; + this->y2 = -1; this->panels = Vector_new(Class(Panel), owner, DEFAULT_SIZE); this->panelCount = 0; this->header = header; this->settings = settings; + this->state = state; this->owner = owner; this->allowFocusChange = true; return this; @@ -44,21 +47,18 @@ inline int ScreenManager_size(ScreenManager* this) { } void ScreenManager_add(ScreenManager* this, Panel* item, int size) { - if (this->orientation == HORIZONTAL) { - int lastX = 0; - if (this->panelCount > 0) { - Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1); - lastX = last->x + last->w + 1; - } - int height = LINES - this->y1 + 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); + int lastX = 0; + if (this->panelCount > 0) { + Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1); + lastX = last->x + last->w + 1; + } + int height = LINES - this->y1 + this->y2; + if (size > 0) { + Panel_resize(item, size, height); + } else { + Panel_resize(item, COLS - this->x1 + this->x2 - lastX, height); } - // TODO: VERTICAL + Panel_move(item, lastX, this->y1); Vector_add(this->panels, item); item->needsRedraw = true; this->panelCount++; @@ -77,33 +77,35 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) { this->x2 = x2; this->y2 = y2; int panels = this->panelCount; - if (this->orientation == HORIZONTAL) { - 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); - 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); + 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); + lastX = panel->x + panel->w + 1; } - // TODO: VERTICAL + Panel* panel = (Panel*) Vector_get(this->panels, panels - 1); + Panel_resize(panel, COLS - x1 + x2 - lastX, LINES - y1 + y2); + Panel_move(panel, lastX, y1); } -static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool *rescan, bool *timedOut) { +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); + *timedOut = (newTime - *oldTime > this->settings->delay); - *rescan = *rescan || *timedOut; - if (newTime < *oldTime) *rescan = true; // clock was adjusted? + *rescan |= *timedOut; + + if (newTime < *oldTime) { + *rescan = true; // clock was adjusted? + } + if (*rescan) { *oldTime = newTime; - ProcessList_scan(pl); + ProcessList_scan(pl, this->state->pauseProcessUpdate); if (*sortTimeout == 0 || this->settings->treeView) { ProcessList_sort(pl); *sortTimeout = 1; @@ -121,15 +123,17 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) { const int nPanels = this->panelCount; for (int i = 0; i < nPanels; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - Panel_draw(panel, i == focus); - if (this->orientation == HORIZONTAL) { - mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1); - } + Panel_draw(panel, i == focus, !((panel == this->state->panel) && this->state->hideProcessSelection)); + mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1); } } -static Panel* setCurrentPanel(Panel* panel) { - FunctionBar_draw(panel->currentBar, NULL); +static Panel* setCurrentPanel(const ScreenManager* this, Panel* panel) { + FunctionBar_draw(panel->currentBar); + if (panel == this->state->panel && this->state->pauseProcessUpdate) { + FunctionBar_append("PAUSED", CRT_colors[PAUSED]); + } + return panel; } @@ -137,7 +141,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { bool quit = false; int focus = 0; - Panel* panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); + Panel* panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); double oldTime = 0.0; @@ -175,15 +179,15 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { } else { for (int i = 0; i < this->panelCount; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - if (mevent.x >= panel->x && mevent.x <= panel->x+panel->w) { + if (mevent.x >= panel->x && mevent.x <= panel->x + panel->w) { if (mevent.y == panel->y) { ch = EVENT_HEADER_CLICK(mevent.x - panel->x); break; - } else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) { + } else if (mevent.y > panel->y && mevent.y <= panel->y + panel->h) { ch = KEY_MOUSE; if (panel == panelFocus || this->allowFocusChange) { focus = i; - panelFocus = setCurrentPanel(panel); + panelFocus = setCurrentPanel(this, panel); Object* oldSelection = Panel_getSelected(panel); Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1); if (Panel_getSelected(panel) == oldSelection) { @@ -211,8 +215,9 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (closeTimeout == 100) { break; } - } else + } else { closeTimeout = 0; + } redraw = false; continue; } @@ -254,14 +259,21 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (this->panelCount < 2) { goto defaultHandler; } - if (!this->allowFocusChange) + + if (!this->allowFocusChange) { break; - tryLeft: - if (focus > 0) + } + +tryLeft: + if (focus > 0) { focus--; - panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); - if (Panel_size(panelFocus) == 0 && focus > 0) + } + + panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); + if (Panel_size(panelFocus) == 0 && focus > 0) { goto tryLeft; + } + break; case KEY_RIGHT: case KEY_CTRL('F'): @@ -269,30 +281,39 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (this->panelCount < 2) { goto defaultHandler; } - if (!this->allowFocusChange) + if (!this->allowFocusChange) { break; - tryRight: - if (focus < this->panelCount - 1) + } + +tryRight: + if (focus < this->panelCount - 1) { focus++; - panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); - if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) + } + + panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); + if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) { goto tryRight; + } + break; - case KEY_F(10): - case 'q': case 27: + case 'q': + case KEY_F(10): quit = true; continue; default: - defaultHandler: +defaultHandler: sortTimeout = resetSortTimeout; Panel_onKey(panelFocus, ch); break; } } - if (lastFocus) + if (lastFocus) { *lastFocus = panelFocus; - if (lastKey) + } + + if (lastKey) { *lastKey = ch; + } } -- cgit v1.2.3