Commit 09c71529 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Refactor state control variables.

parent 4e064e0d
......@@ -98,10 +98,10 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
ProcessList_printHeader(this->state->pl, Panel_getHeader(super));
}
if (reaction & HTOP_REFRESH) {
result |= REFRESH;
result |= REDRAW;
}
if (reaction & HTOP_RECALCULATE) {
result |= RECALCULATE;
result |= RESCAN;
}
if (reaction & HTOP_SAVE_SETTINGS) {
this->state->settings->changed = true;
......
......@@ -31,8 +31,8 @@ typedef enum HandlerResult_ {
HANDLED = 0x01,
IGNORED = 0x02,
BREAK_LOOP = 0x04,
REFRESH = 0x08,
RECALCULATE = 0x10,
REDRAW = 0x08,
RESCAN = 0x10,
SYNTH_KEY = 0x20,
} HandlerResult;
......
......@@ -20,8 +20,8 @@ typedef enum HandlerResult_ {
HANDLED = 0x01,
IGNORED = 0x02,
BREAK_LOOP = 0x04,
REFRESH = 0x08,
RECALCULATE = 0x10,
REDRAW = 0x08,
RESCAN = 0x10,
SYNTH_KEY = 0x20,
} HandlerResult;
......
......@@ -130,6 +130,45 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
// 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) {
bool quit = false;
int focus = 0;
......@@ -138,56 +177,24 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if (this->fuBar)
FunctionBar_draw(this->fuBar, NULL);
struct timeval tv;
double oldTime = 0.0;
int ch = ERR;
int closeTimeout = 0;
bool drawPanel = true;
bool timeToRecalculate = true;
bool doRefresh = true;
bool forceRecalculate = false;
bool timedOut = true;
bool redraw = true;
bool rescan = false;
int sortTimeout = 0;
int resetSortTimeout = 5;
while (!quit) {
int panels = this->panelCount;
if (this->header) {
gettimeofday(&tv, NULL);
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;
checkRecalculation(this, &oldTime, &sortTimeout, &redraw, &rescan, &timedOut);
}
if (drawPanel) {
for (int i = 0; i < panels; i++) {
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);
}
}
}
if (redraw) {
ScreenManager_drawPanels(this, 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) {
ch = result >> 16;
}
if (result & REFRESH) {
doRefresh = true;
if (result & REDRAW) {
//redraw = true;
sortTimeout = 0;
}
if (result & RECALCULATE) {
forceRecalculate = true;
if (result & RESCAN) {
rescan = true;
sortTimeout = 0;
}
if (result & HANDLED) {
drawPanel = true;
redraw = true;
continue;
} else if (result & BREAK_LOOP) {
quit = true;
......@@ -243,17 +250,17 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
}
if (ch == ERR) {
sortTimeout--;
if (prevCh == ch && !timeToRecalculate) {
if (prevCh == ch && !timedOut) {
closeTimeout++;
if (closeTimeout == 100) {
break;
}
} else
closeTimeout = 0;
drawPanel = false;
redraw = false;
continue;
}
drawPanel = true;
redraw = true;
switch (ch) {
case KEY_RESIZE:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment