mirror of https://github.com/xzeldon/htop.git
Refactor state control variables.
This commit is contained in:
parent
4e064e0db7
commit
09c7152990
|
@ -98,10 +98,10 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||||
ProcessList_printHeader(this->state->pl, Panel_getHeader(super));
|
ProcessList_printHeader(this->state->pl, Panel_getHeader(super));
|
||||||
}
|
}
|
||||||
if (reaction & HTOP_REFRESH) {
|
if (reaction & HTOP_REFRESH) {
|
||||||
result |= REFRESH;
|
result |= REDRAW;
|
||||||
}
|
}
|
||||||
if (reaction & HTOP_RECALCULATE) {
|
if (reaction & HTOP_RECALCULATE) {
|
||||||
result |= RECALCULATE;
|
result |= RESCAN;
|
||||||
}
|
}
|
||||||
if (reaction & HTOP_SAVE_SETTINGS) {
|
if (reaction & HTOP_SAVE_SETTINGS) {
|
||||||
this->state->settings->changed = true;
|
this->state->settings->changed = true;
|
||||||
|
|
4
Panel.c
4
Panel.c
|
@ -31,8 +31,8 @@ typedef enum HandlerResult_ {
|
||||||
HANDLED = 0x01,
|
HANDLED = 0x01,
|
||||||
IGNORED = 0x02,
|
IGNORED = 0x02,
|
||||||
BREAK_LOOP = 0x04,
|
BREAK_LOOP = 0x04,
|
||||||
REFRESH = 0x08,
|
REDRAW = 0x08,
|
||||||
RECALCULATE = 0x10,
|
RESCAN = 0x10,
|
||||||
SYNTH_KEY = 0x20,
|
SYNTH_KEY = 0x20,
|
||||||
} HandlerResult;
|
} HandlerResult;
|
||||||
|
|
||||||
|
|
4
Panel.h
4
Panel.h
|
@ -20,8 +20,8 @@ typedef enum HandlerResult_ {
|
||||||
HANDLED = 0x01,
|
HANDLED = 0x01,
|
||||||
IGNORED = 0x02,
|
IGNORED = 0x02,
|
||||||
BREAK_LOOP = 0x04,
|
BREAK_LOOP = 0x04,
|
||||||
REFRESH = 0x08,
|
REDRAW = 0x08,
|
||||||
RECALCULATE = 0x10,
|
RESCAN = 0x10,
|
||||||
SYNTH_KEY = 0x20,
|
SYNTH_KEY = 0x20,
|
||||||
} HandlerResult;
|
} HandlerResult;
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,45 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
|
||||||
// TODO: VERTICAL
|
// TODO: VERTICAL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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?
|
||||||
|
if (*rescan) {
|
||||||
|
*oldTime = newTime;
|
||||||
|
ProcessList_scan(pl);
|
||||||
|
if (*sortTimeout == 0 || this->settings->treeView) {
|
||||||
|
ProcessList_sort(pl);
|
||||||
|
*sortTimeout = 1;
|
||||||
|
}
|
||||||
|
*redraw = true;
|
||||||
|
}
|
||||||
|
if (*redraw) {
|
||||||
|
//pl->incFilter = IncSet_filter(inc);
|
||||||
|
ProcessList_rebuildPanel(pl);
|
||||||
|
Header_draw(this->header);
|
||||||
|
}
|
||||||
|
*rescan = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
||||||
|
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 (i < nPanels) {
|
||||||
|
if (this->orientation == HORIZONTAL) {
|
||||||
|
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
bool quit = false;
|
bool quit = false;
|
||||||
int focus = 0;
|
int focus = 0;
|
||||||
|
@ -138,56 +177,24 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
if (this->fuBar)
|
if (this->fuBar)
|
||||||
FunctionBar_draw(this->fuBar, NULL);
|
FunctionBar_draw(this->fuBar, NULL);
|
||||||
|
|
||||||
struct timeval tv;
|
|
||||||
double oldTime = 0.0;
|
double oldTime = 0.0;
|
||||||
|
|
||||||
int ch = ERR;
|
int ch = ERR;
|
||||||
int closeTimeout = 0;
|
int closeTimeout = 0;
|
||||||
|
|
||||||
bool drawPanel = true;
|
bool timedOut = true;
|
||||||
bool timeToRecalculate = true;
|
bool redraw = true;
|
||||||
bool doRefresh = true;
|
bool rescan = false;
|
||||||
bool forceRecalculate = false;
|
|
||||||
int sortTimeout = 0;
|
int sortTimeout = 0;
|
||||||
int resetSortTimeout = 5;
|
int resetSortTimeout = 5;
|
||||||
|
|
||||||
while (!quit) {
|
while (!quit) {
|
||||||
int panels = this->panelCount;
|
|
||||||
if (this->header) {
|
if (this->header) {
|
||||||
gettimeofday(&tv, NULL);
|
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
|
||||||
double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
|
|
||||||
timeToRecalculate = (newTime - oldTime > this->settings->delay);
|
|
||||||
if (newTime < oldTime) timeToRecalculate = true; // clock was adjusted?
|
|
||||||
if (doRefresh) {
|
|
||||||
if (timeToRecalculate || forceRecalculate) {
|
|
||||||
ProcessList_scan(this->header->pl);
|
|
||||||
}
|
|
||||||
if (sortTimeout == 0 || this->settings->treeView) {
|
|
||||||
ProcessList_sort(this->header->pl);
|
|
||||||
sortTimeout = 1;
|
|
||||||
}
|
|
||||||
//this->header->pl->incFilter = IncSet_filter(inc);
|
|
||||||
ProcessList_rebuildPanel(this->header->pl);
|
|
||||||
drawPanel = true;
|
|
||||||
}
|
|
||||||
if (timeToRecalculate || forceRecalculate) {
|
|
||||||
Header_draw(this->header);
|
|
||||||
oldTime = newTime;
|
|
||||||
forceRecalculate = false;
|
|
||||||
}
|
|
||||||
doRefresh = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (drawPanel) {
|
if (redraw) {
|
||||||
for (int i = 0; i < panels; i++) {
|
ScreenManager_drawPanels(this, focus);
|
||||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
|
||||||
Panel_draw(panel, i == focus);
|
|
||||||
if (i < panels) {
|
|
||||||
if (this->orientation == HORIZONTAL) {
|
|
||||||
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionBar* bar = (FunctionBar*) Vector_get(this->fuBars, focus);
|
FunctionBar* bar = (FunctionBar*) Vector_get(this->fuBars, focus);
|
||||||
|
@ -225,16 +232,16 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
if (result & SYNTH_KEY) {
|
if (result & SYNTH_KEY) {
|
||||||
ch = result >> 16;
|
ch = result >> 16;
|
||||||
}
|
}
|
||||||
if (result & REFRESH) {
|
if (result & REDRAW) {
|
||||||
doRefresh = true;
|
//redraw = true;
|
||||||
sortTimeout = 0;
|
sortTimeout = 0;
|
||||||
}
|
}
|
||||||
if (result & RECALCULATE) {
|
if (result & RESCAN) {
|
||||||
forceRecalculate = true;
|
rescan = true;
|
||||||
sortTimeout = 0;
|
sortTimeout = 0;
|
||||||
}
|
}
|
||||||
if (result & HANDLED) {
|
if (result & HANDLED) {
|
||||||
drawPanel = true;
|
redraw = true;
|
||||||
continue;
|
continue;
|
||||||
} else if (result & BREAK_LOOP) {
|
} else if (result & BREAK_LOOP) {
|
||||||
quit = true;
|
quit = true;
|
||||||
|
@ -243,17 +250,17 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
}
|
}
|
||||||
if (ch == ERR) {
|
if (ch == ERR) {
|
||||||
sortTimeout--;
|
sortTimeout--;
|
||||||
if (prevCh == ch && !timeToRecalculate) {
|
if (prevCh == ch && !timedOut) {
|
||||||
closeTimeout++;
|
closeTimeout++;
|
||||||
if (closeTimeout == 100) {
|
if (closeTimeout == 100) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
closeTimeout = 0;
|
closeTimeout = 0;
|
||||||
drawPanel = false;
|
redraw = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
drawPanel = true;
|
redraw = true;
|
||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
|
|
Loading…
Reference in New Issue