Add key to pause process list updates

This commit is contained in:
Christian Göttsche 2020-10-05 15:14:54 +02:00 committed by cgzones
parent fc301b7447
commit b47bc667a2
17 changed files with 103 additions and 46 deletions

View File

@ -37,7 +37,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
Settings* settings = st->settings; Settings* settings = st->settings;
int y = panel->y; int y = panel->y;
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, false); ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, st, false);
scr->allowFocusChange = false; scr->allowFocusChange = false;
ScreenManager_add(scr, list, x - 1); ScreenManager_add(scr, list, x - 1);
ScreenManager_add(scr, panel, -1); ScreenManager_add(scr, panel, -1);
@ -73,17 +73,17 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
// ---------------------------------------- // ----------------------------------------
static void Action_runSetup(Settings* settings, Header* header, ProcessList* pl) { static void Action_runSetup(State* st) {
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true); ScreenManager* scr = ScreenManager_new(0, st->header->height, 0, -1, HORIZONTAL, st->header, st->settings, st, true);
CategoriesPanel* panelCategories = CategoriesPanel_new(scr, settings, header, pl); CategoriesPanel* panelCategories = CategoriesPanel_new(scr, st->settings, st->header, st->pl);
ScreenManager_add(scr, (Panel*) panelCategories, 16); ScreenManager_add(scr, (Panel*) panelCategories, 16);
CategoriesPanel_makeMetersPage(panelCategories); CategoriesPanel_makeMetersPage(panelCategories);
Panel* panelFocus; Panel* panelFocus;
int ch; int ch;
ScreenManager_run(scr, &panelFocus, &ch); ScreenManager_run(scr, &panelFocus, &ch);
ScreenManager_delete(scr); ScreenManager_delete(scr);
if (settings->changed) { if (st->settings->changed) {
Header_writeBackToSettings(header); Header_writeBackToSettings(st->header);
} }
} }
@ -168,6 +168,8 @@ static Htop_Reaction sortBy(State* st) {
reaction |= Action_setSortKey(st->settings, field->key); reaction |= Action_setSortKey(st->settings, field->key);
} }
Object_delete(sortPanel); Object_delete(sortPanel);
if (st->pauseProcessUpdate)
ProcessList_sort(st->pl);
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
} }
@ -346,7 +348,7 @@ Htop_Reaction Action_follow(State* st) {
} }
static Htop_Reaction actionSetup(State* st) { static Htop_Reaction actionSetup(State* st) {
Action_runSetup(st->settings, st->header, st->pl); Action_runSetup(st);
// TODO: shouldn't need this, colors should be dynamic // TODO: shouldn't need this, colors should be dynamic
int headerHeight = Header_calculateHeight(st->header); int headerHeight = Header_calculateHeight(st->header);
Panel_move(st->panel, 0, headerHeight); Panel_move(st->panel, 0, headerHeight);
@ -392,6 +394,11 @@ static Htop_Reaction actionRedraw(ATTR_UNUSED State *st) {
return HTOP_REFRESH | HTOP_REDRAW_BAR; return HTOP_REFRESH | HTOP_REDRAW_BAR;
} }
static Htop_Reaction actionTogglePauseProcessUpdate(State *st) {
st->pauseProcessUpdate = !st->pauseProcessUpdate;
return HTOP_REFRESH | HTOP_REDRAW_BAR;
}
static const struct { const char* key; const char* info; } helpLeft[] = { static const struct { const char* key; const char* info; } helpLeft[] = {
{ .key = " Arrows: ", .info = "scroll process list" }, { .key = " Arrows: ", .info = "scroll process list" },
{ .key = " Digits: ", .info = "incremental PID search" }, { .key = " Digits: ", .info = "incremental PID search" },
@ -399,6 +406,7 @@ static const struct { const char* key; const char* info; } helpLeft[] = {
{ .key = " F4 \\: ",.info = "incremental name filtering" }, { .key = " F4 \\: ",.info = "incremental name filtering" },
{ .key = " F5 t: ", .info = "tree view" }, { .key = " F5 t: ", .info = "tree view" },
{ .key = " p: ", .info = "toggle program path" }, { .key = " p: ", .info = "toggle program path" },
{ .key = " Z: ", .info = "pause/resume process updates" },
{ .key = " u: ", .info = "show processes of a single user" }, { .key = " u: ", .info = "show processes of a single user" },
{ .key = " H: ", .info = "hide/show user process threads" }, { .key = " H: ", .info = "hide/show user process threads" },
{ .key = " K: ", .info = "hide/show kernel threads" }, { .key = " K: ", .info = "hide/show kernel threads" },
@ -491,12 +499,12 @@ static Htop_Reaction actionHelp(State* st) {
for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); } for (int i = 0; helpLeft[i].key; i++) { mvaddstr(9+i, 0, helpLeft[i].key); }
for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); } for (int i = 0; helpRight[i].key; i++) { mvaddstr(9+i, 40, helpRight[i].key); }
attrset(CRT_colors[PROCESS_THREAD]); attrset(CRT_colors[PROCESS_THREAD]);
mvaddstr(16, 32, "threads"); mvaddstr(17, 32, "threads");
mvaddstr(17, 26, "threads"); mvaddstr(18, 26, "threads");
attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[DEFAULT_COLOR]);
attrset(CRT_colors[HELP_BOLD]); attrset(CRT_colors[HELP_BOLD]);
mvaddstr(23,0, "Press any key to return."); mvaddstr(24,0, "Press any key to return.");
attrset(CRT_colors[DEFAULT_COLOR]); attrset(CRT_colors[DEFAULT_COLOR]);
refresh(); refresh();
CRT_readKey(); CRT_readKey();
@ -596,4 +604,5 @@ void Action_setBindings(Htop_Action* keys) {
keys['c'] = actionTagAllChildren; keys['c'] = actionTagAllChildren;
keys['e'] = actionShowEnvScreen; keys['e'] = actionShowEnvScreen;
keys['w'] = actionShowCommandScreen; keys['w'] = actionShowCommandScreen;
keys['Z'] = actionTogglePauseProcessUpdate;
} }

View File

@ -30,6 +30,7 @@ typedef struct State_ {
ProcessList* pl; ProcessList* pl;
Panel* panel; Panel* panel;
Header* header; Header* header;
bool pauseProcessUpdate;
} State; } State;
typedef Htop_Reaction (*Htop_Action)(State* st); typedef Htop_Reaction (*Htop_Action)(State* st);

View File

@ -160,7 +160,7 @@ static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) {
Panel* super = (Panel*) this; Panel* super = (Panel*) this;
FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : ""); FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : "");
FunctionBar_draw(super->currentBar, NULL); FunctionBar_draw(super->currentBar);
int oldSelected = Panel_getSelectedIndex(super); int oldSelected = Panel_getSelectedIndex(super);
Panel_prune(super); Panel_prune(super);

View File

@ -29,7 +29,7 @@ static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, c
Panel_add(panel, (Object*) Meter_toListItem(meter, false)); Panel_add(panel, (Object*) Meter_toListItem(meter, false));
Panel_setSelected(panel, Panel_size(panel) - 1); Panel_setSelected(panel, Panel_size(panel) - 1);
MetersPanel_setMoving((MetersPanel*)panel, true); MetersPanel_setMoving((MetersPanel*)panel, true);
FunctionBar_draw(panel->currentBar, NULL); FunctionBar_draw(panel->currentBar);
} }
static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) { static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {

8
CRT.c
View File

@ -87,6 +87,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White), [PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White),
[FAILED_SEARCH] = ColorPair(Red,Cyan), [FAILED_SEARCH] = ColorPair(Red,Cyan),
[PAUSED] = A_BOLD | ColorPair(Yellow,Cyan),
[UPTIME] = A_BOLD | ColorPair(Cyan,Black), [UPTIME] = A_BOLD | ColorPair(Cyan,Black),
[BATTERY] = A_BOLD | ColorPair(Cyan,Black), [BATTERY] = A_BOLD | ColorPair(Cyan,Black),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black),
@ -162,6 +163,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = A_REVERSE, [PANEL_SELECTION_FOLLOW] = A_REVERSE,
[PANEL_SELECTION_UNFOCUS] = A_BOLD, [PANEL_SELECTION_UNFOCUS] = A_BOLD,
[FAILED_SEARCH] = A_REVERSE | A_BOLD, [FAILED_SEARCH] = A_REVERSE | A_BOLD,
[PAUSED] = A_BOLD | A_REVERSE,
[UPTIME] = A_BOLD, [UPTIME] = A_BOLD,
[BATTERY] = A_BOLD, [BATTERY] = A_BOLD,
[LARGE_NUMBER] = A_BOLD, [LARGE_NUMBER] = A_BOLD,
@ -237,6 +239,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,White), [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,White),
[FAILED_SEARCH] = ColorPair(Red,Cyan), [FAILED_SEARCH] = ColorPair(Red,Cyan),
[PAUSED] = A_BOLD | ColorPair(Yellow,Cyan),
[UPTIME] = ColorPair(Yellow,White), [UPTIME] = ColorPair(Yellow,White),
[BATTERY] = ColorPair(Yellow,White), [BATTERY] = ColorPair(Yellow,White),
[LARGE_NUMBER] = ColorPair(Red,White), [LARGE_NUMBER] = ColorPair(Red,White),
@ -312,6 +315,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,Black), [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,Black),
[FAILED_SEARCH] = ColorPair(Red,Cyan), [FAILED_SEARCH] = ColorPair(Red,Cyan),
[PAUSED] = A_BOLD | ColorPair(Yellow,Cyan),
[UPTIME] = ColorPair(Yellow,Black), [UPTIME] = ColorPair(Yellow,Black),
[BATTERY] = ColorPair(Yellow,Black), [BATTERY] = ColorPair(Yellow,Black),
[LARGE_NUMBER] = ColorPair(Red,Black), [LARGE_NUMBER] = ColorPair(Red,Black),
@ -387,6 +391,7 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow,Blue), [PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow,Blue),
[FAILED_SEARCH] = ColorPair(Red,Cyan), [FAILED_SEARCH] = ColorPair(Red,Cyan),
[PAUSED] = A_BOLD | ColorPair(Yellow,Cyan),
[UPTIME] = A_BOLD | ColorPair(Yellow,Blue), [UPTIME] = A_BOLD | ColorPair(Yellow,Blue),
[BATTERY] = A_BOLD | ColorPair(Yellow,Blue), [BATTERY] = A_BOLD | ColorPair(Yellow,Blue),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red,Blue), [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Blue),
@ -461,7 +466,8 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = {
[PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan),
[PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow),
[PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White), [PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White),
[FAILED_SEARCH] = ColorPair(Red,Cyan), [FAILED_SEARCH] = ColorPair(Red,Green),
[PAUSED] = A_BOLD | ColorPair(Yellow,Green),
[UPTIME] = ColorPair(Green,Black), [UPTIME] = ColorPair(Green,Black),
[BATTERY] = ColorPair(Green,Black), [BATTERY] = ColorPair(Green,Black),
[LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black),

1
CRT.h
View File

@ -43,6 +43,7 @@ typedef enum ColorElements_ {
FUNCTION_BAR, FUNCTION_BAR,
FUNCTION_KEY, FUNCTION_KEY,
FAILED_SEARCH, FAILED_SEARCH,
PAUSED,
PANEL_HEADER_FOCUS, PANEL_HEADER_FOCUS,
PANEL_HEADER_UNFOCUS, PANEL_HEADER_UNFOCUS,
PANEL_SELECTION_FOCUS, PANEL_SELECTION_FOCUS,

View File

@ -68,7 +68,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) {
clear(); clear();
Panel* menu = (Panel*) Vector_get(this->scr->panels, 0); Panel* menu = (Panel*) Vector_get(this->scr->panels, 0);
Header_draw(header); Header_draw(header);
FunctionBar_draw(super->currentBar, NULL); FunctionBar_draw(super->currentBar);
RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]); RichString_setAttr(&(super->header), CRT_colors[PANEL_HEADER_FOCUS]);
RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]); RichString_setAttr(&(menu->header), CRT_colors[PANEL_HEADER_UNFOCUS]);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2); ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);

View File

@ -24,6 +24,8 @@ static int FunctionBar_FEvents[] = {KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_
static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL}; static const char* const FunctionBar_EnterEscKeys[] = {"Enter", "Esc", NULL};
static const int FunctionBar_EnterEscEvents[] = {13, 27}; static const int FunctionBar_EnterEscEvents[] = {13, 27};
static int currentLen = 0;
FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) { FunctionBar* FunctionBar_newEnterEsc(const char* enter, const char* esc) {
const char* functions[] = {enter, esc, NULL}; const char* functions[] = {enter, esc, NULL};
return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents); return FunctionBar_new(functions, FunctionBar_EnterEscKeys, FunctionBar_EnterEscEvents);
@ -53,7 +55,7 @@ FunctionBar* FunctionBar_new(const char* const* functions, const char* const* ke
this->staticData = true; this->staticData = true;
this->keys.constKeys = FunctionBar_FKeys; this->keys.constKeys = FunctionBar_FKeys;
this->events = FunctionBar_FEvents; this->events = FunctionBar_FEvents;
this->size = 10; this->size = ARRAYSIZE(FunctionBar_FEvents);
} }
return this; return this;
} }
@ -83,11 +85,11 @@ void FunctionBar_setLabel(FunctionBar* this, int event, const char* text) {
} }
} }
void FunctionBar_draw(const FunctionBar* this, char* buffer) { void FunctionBar_draw(const FunctionBar* this) {
FunctionBar_drawAttr(this, buffer, CRT_colors[FUNCTION_BAR]); FunctionBar_drawExtra(this, NULL, -1, false);
} }
void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) { void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor) {
attrset(CRT_colors[FUNCTION_BAR]); attrset(CRT_colors[FUNCTION_BAR]);
mvhline(LINES-1, 0, ' ', COLS); mvhline(LINES-1, 0, ' ', COLS);
int x = 0; int x = 0;
@ -99,15 +101,36 @@ void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr) {
mvaddstr(LINES-1, x, this->functions[i]); mvaddstr(LINES-1, x, this->functions[i]);
x += strlen(this->functions[i]); x += strlen(this->functions[i]);
} }
if (buffer) { if (buffer) {
if (attr == -1)
attrset(CRT_colors[FUNCTION_BAR]);
else
attrset(attr); attrset(attr);
mvaddstr(LINES-1, x, buffer); mvaddstr(LINES-1, x, buffer);
CRT_cursorX = x + strlen(buffer); attrset(CRT_colors[RESET_COLOR]);
x += strlen(buffer);
}
if (setCursor) {
CRT_cursorX = x;
curs_set(1); curs_set(1);
} else { } else {
curs_set(0); curs_set(0);
} }
currentLen = x;
}
void FunctionBar_append(const char* buffer, int attr) {
if (attr == -1)
attrset(CRT_colors[FUNCTION_BAR]);
else
attrset(attr);
mvaddstr(LINES-1, currentLen, buffer);
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
currentLen += strlen(buffer);
} }
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) { int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos) {

View File

@ -28,9 +28,11 @@ void FunctionBar_delete(FunctionBar* this);
void FunctionBar_setLabel(FunctionBar* this, int event, const char* text); void FunctionBar_setLabel(FunctionBar* this, int event, const char* text);
void FunctionBar_draw(const FunctionBar* this, char* buffer); void FunctionBar_draw(const FunctionBar* this);
void FunctionBar_drawAttr(const FunctionBar* this, char* buffer, int attr); void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor);
void FunctionBar_append(const char* buffer, int attr);
int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos); int FunctionBar_synthesizeEvent(const FunctionBar* this, int pos);

View File

@ -95,10 +95,11 @@ static bool search(IncMode* mode, Panel* panel, IncMode_GetPanelValue getPanelVa
break; break;
} }
} }
if (found)
FunctionBar_draw(mode->bar, mode->buffer); FunctionBar_drawExtra(mode->bar,
else mode->buffer,
FunctionBar_drawAttr(mode->bar, mode->buffer, CRT_colors[FAILED_SEARCH]); found ? -1 : CRT_colors[FAILED_SEARCH],
true);
return found; return found;
} }
@ -177,7 +178,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue
} }
this->active = NULL; this->active = NULL;
Panel_setDefaultBar(panel); Panel_setDefaultBar(panel);
FunctionBar_draw(this->defaultBar, NULL); FunctionBar_draw(this->defaultBar);
doSearch = false; doSearch = false;
} }
if (doSearch) { if (doSearch) {
@ -198,15 +199,15 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
void IncSet_activate(IncSet* this, IncType type, Panel* panel) { void IncSet_activate(IncSet* this, IncType type, Panel* panel) {
this->active = &(this->modes[type]); this->active = &(this->modes[type]);
FunctionBar_draw(this->active->bar, this->active->buffer); FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true);
panel->currentBar = this->active->bar; panel->currentBar = this->active->bar;
} }
void IncSet_drawBar(IncSet* this) { void IncSet_drawBar(const IncSet* this) {
if (this->active) { if (this->active) {
FunctionBar_draw(this->active->bar, this->active->buffer); FunctionBar_drawExtra(this->active->bar, this->active->buffer, -1, true);
} else { } else {
FunctionBar_draw(this->defaultBar, NULL); FunctionBar_draw(this->defaultBar);
} }
} }

View File

@ -54,7 +54,7 @@ const char* IncSet_getListItemValue(Panel* panel, int i);
void IncSet_activate(IncSet* this, IncType type, Panel* panel); void IncSet_activate(IncSet* this, IncType type, Panel* panel);
void IncSet_drawBar(IncSet* this); void IncSet_drawBar(const IncSet* this);
int IncSet_synthesizeEvent(IncSet* this, int x); int IncSet_synthesizeEvent(IncSet* this, int x);

View File

@ -92,6 +92,8 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
if (reaction & HTOP_REDRAW_BAR) { if (reaction & HTOP_REDRAW_BAR) {
MainPanel_updateTreeFunctions(this, this->state->settings->treeView); MainPanel_updateTreeFunctions(this, this->state->settings->treeView);
IncSet_drawBar(this->inc); IncSet_drawBar(this->inc);
if (this->state->pauseProcessUpdate)
FunctionBar_append("PAUSED", CRT_colors[PAUSED]);
} }
if (reaction & HTOP_UPDATE_PANELHDR) { if (reaction & HTOP_UPDATE_PANELHDR) {
ProcessList_printHeader(this->state->pl, Panel_getHeader(super)); ProcessList_printHeader(this->state->pl, Panel_getHeader(super));

View File

@ -55,7 +55,7 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) {
Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]); Panel_setSelectionColor(super, CRT_colors[PANEL_SELECTION_FOLLOW]);
super->currentBar = Meters_movingBar; super->currentBar = Meters_movingBar;
} }
FunctionBar_draw(this->super.currentBar, NULL); FunctionBar_draw(this->super.currentBar);
} }
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) { static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {

View File

@ -6,10 +6,12 @@ in the source distribution for its full text.
*/ */
#include "ScreenManager.h" #include "ScreenManager.h"
#include "CRT.h"
#include "MainPanel.h"
#include "Object.h"
#include "ProcessList.h" #include "ProcessList.h"
#include "Object.h"
#include "CRT.h"
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
@ -17,7 +19,7 @@ in the source distribution for its full text.
#include <stdbool.h> #include <stdbool.h>
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, bool owner) { ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, const State* state, bool owner) {
ScreenManager* this; ScreenManager* this;
this = xMalloc(sizeof(ScreenManager)); this = xMalloc(sizeof(ScreenManager));
this->x1 = x1; this->x1 = x1;
@ -29,6 +31,7 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
this->panelCount = 0; this->panelCount = 0;
this->header = header; this->header = header;
this->settings = settings; this->settings = settings;
this->state = state;
this->owner = owner; this->owner = owner;
this->allowFocusChange = true; this->allowFocusChange = true;
return this; return this;
@ -101,7 +104,7 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi
*timedOut = (newTime - *oldTime > this->settings->delay); *timedOut = (newTime - *oldTime > this->settings->delay);
*rescan = *rescan || *timedOut; *rescan = *rescan || *timedOut;
if (newTime < *oldTime) *rescan = true; // clock was adjusted? if (newTime < *oldTime) *rescan = true; // clock was adjusted?
if (*rescan) { if (*rescan && !this->state->pauseProcessUpdate) {
*oldTime = newTime; *oldTime = newTime;
ProcessList_scan(pl); ProcessList_scan(pl);
if (*sortTimeout == 0 || this->settings->treeView) { if (*sortTimeout == 0 || this->settings->treeView) {
@ -128,8 +131,11 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
} }
} }
static Panel* setCurrentPanel(Panel* panel) { static Panel* setCurrentPanel(const ScreenManager* this, Panel* panel) {
FunctionBar_draw(panel->currentBar, NULL); FunctionBar_draw(panel->currentBar);
if (panel == this->state->panel && this->state->pauseProcessUpdate)
FunctionBar_append("PAUSED", CRT_colors[PAUSED]);
return panel; return panel;
} }
@ -137,7 +143,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
bool quit = false; bool quit = false;
int focus = 0; 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; double oldTime = 0.0;
@ -183,7 +189,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
ch = KEY_MOUSE; ch = KEY_MOUSE;
if (panel == panelFocus || this->allowFocusChange) { if (panel == panelFocus || this->allowFocusChange) {
focus = i; focus = i;
panelFocus = setCurrentPanel(panel); panelFocus = setCurrentPanel(this, panel);
Object* oldSelection = Panel_getSelected(panel); Object* oldSelection = Panel_getSelected(panel);
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1); Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
if (Panel_getSelected(panel) == oldSelection) { if (Panel_getSelected(panel) == oldSelection) {
@ -259,7 +265,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
tryLeft: tryLeft:
if (focus > 0) if (focus > 0)
focus--; focus--;
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus));
if (Panel_size(panelFocus) == 0 && focus > 0) if (Panel_size(panelFocus) == 0 && focus > 0)
goto tryLeft; goto tryLeft;
break; break;
@ -274,7 +280,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
tryRight: tryRight:
if (focus < this->panelCount - 1) if (focus < this->panelCount - 1)
focus++; focus++;
panelFocus = setCurrentPanel((Panel*) Vector_get(this->panels, focus)); panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus));
if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1)
goto tryRight; goto tryRight;
break; break;

View File

@ -7,9 +7,10 @@ Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "Action.h"
#include "Header.h" #include "Header.h"
#include "Settings.h"
#include "Panel.h" #include "Panel.h"
#include "Settings.h"
#include "Vector.h" #include "Vector.h"
typedef enum Orientation_ { typedef enum Orientation_ {
@ -27,11 +28,12 @@ typedef struct ScreenManager_ {
int panelCount; int panelCount;
Header* header; Header* header;
const Settings* settings; const Settings* settings;
const State* state;
bool owner; bool owner;
bool allowFocusChange; bool allowFocusChange;
} ScreenManager; } ScreenManager;
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, bool owner); ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, const State* state, bool owner);
void ScreenManager_delete(ScreenManager* this); void ScreenManager_delete(ScreenManager* this);

View File

@ -209,6 +209,9 @@ userspace processes in the process list. (This is a toggle key.)
.B p .B p
Show full paths to running programs, where applicable. (This is a toggle key.) Show full paths to running programs, where applicable. (This is a toggle key.)
.TP .TP
.B Z
Pause/resume process updates.
.TP
.B Ctrl-L .B Ctrl-L
Refresh: redraw screen and recalculate values. Refresh: redraw screen and recalculate values.
.TP .TP

3
htop.c
View File

@ -283,6 +283,7 @@ int main(int argc, char** argv) {
.pl = pl, .pl = pl,
.panel = (Panel*) panel, .panel = (Panel*) panel,
.header = header, .header = header,
.pauseProcessUpdate = false,
}; };
MainPanel_setState(panel, &state); MainPanel_setState(panel, &state);
@ -290,7 +291,7 @@ int main(int argc, char** argv) {
setCommFilter(&state, &(flags.commFilter)); setCommFilter(&state, &(flags.commFilter));
} }
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, true); ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, &state, true);
ScreenManager_add(scr, (Panel*) panel, -1); ScreenManager_add(scr, (Panel*) panel, -1);
ProcessList_scan(pl); ProcessList_scan(pl);