Commit d2acffa5 authored by Hisham Muhammad's avatar Hisham Muhammad
Browse files

Merge branch 'wip' of https://github.com/hishamhm/htop into freebsd

Conflicts:
	htop.c
	unsupported/Platform.h
parents c29e53c5 50000d80
...@@ -52,9 +52,9 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { ...@@ -52,9 +52,9 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
if (result == HANDLED) { if (result == HANDLED) {
this->settings->changed = true; this->settings->changed = true;
Header* header = this->settings->header; const Header* header = this->scr->header;
Header_calculateHeight(header); Header_calculateHeight((Header*) header);
Header_reinit(header); Header_reinit((Header*) header);
Header_draw(header); Header_draw(header);
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);
} }
...@@ -78,18 +78,18 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* ...@@ -78,18 +78,18 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
this->scr = scr; this->scr = scr;
Panel_setHeader(super, "Display options"); Panel_setHeader(super, "Display options");
Panel_add(super, (Object*) CheckItem_new(strdup("Tree view"), &(settings->pl->treeView), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Tree view"), &(settings->treeView), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Shadow other users' processes"), &(settings->pl->shadowOtherUsers), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Shadow other users' processes"), &(settings->shadowOtherUsers), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Hide kernel threads"), &(settings->pl->hideKernelThreads), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Hide kernel threads"), &(settings->hideKernelThreads), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->pl->hideUserlandThreads), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Hide userland threads"), &(settings->hideUserlandThreads), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->pl->highlightThreads), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Display threads in a different color"), &(settings->highlightThreads), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->pl->showThreadNames), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Show custom thread names"), &(settings->showThreadNames), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->pl->highlightBaseName), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Highlight program \"basename\""), &(settings->highlightBaseName), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->pl->highlightMegabytes), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->header->margin), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Leave a margin around header"), &(settings->headerMargin), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->pl->detailedCPUTime), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->pl->countCPUsFromZero), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Update process names on every refresh"), &(settings->pl->updateProcessNames), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Update process names on every refresh"), &(settings->updateProcessNames), false));
Panel_add(super, (Object*) CheckItem_new(strdup("Add guest time in CPU meter percentage"), &(settings->pl->accountGuestInCPUMeter), false)); Panel_add(super, (Object*) CheckItem_new(strdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter), false));
return this; return this;
} }
...@@ -17,21 +17,17 @@ in the source distribution for its full text. ...@@ -17,21 +17,17 @@ in the source distribution for its full text.
#include <stdlib.h> #include <stdlib.h>
/*{ /*{
#include "ProcessList.h"
#include "Meter.h" #include "Meter.h"
#include "Settings.h"
typedef enum HeaderSide_ { #include "Vector.h"
LEFT_HEADER,
RIGHT_HEADER
} HeaderSide;
typedef struct Header_ { typedef struct Header_ {
Vector* leftMeters; Vector** columns;
Vector* rightMeters; Settings* settings;
ProcessList* pl; struct ProcessList_* pl;
int height; int nrColumns;
int pad; int pad;
bool margin; int height;
} Header; } Header;
}*/ }*/
...@@ -40,25 +36,43 @@ typedef struct Header_ { ...@@ -40,25 +36,43 @@ typedef struct Header_ {
#define MAX(a,b) ((a)>(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b))
#endif #endif
Header* Header_new(ProcessList* pl) { #ifndef Header_forEachColumn
#define Header_forEachColumn(this_, i_) for (int i_=0; i_ < this->nrColumns; i_++)
#endif
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns) {
Header* this = calloc(1, sizeof(Header)); Header* this = calloc(1, sizeof(Header));
this->leftMeters = Vector_new(Class(Meter), true, DEFAULT_SIZE); this->columns = calloc(nrColumns, sizeof(Vector*));
this->rightMeters = Vector_new(Class(Meter), true, DEFAULT_SIZE); this->settings = settings;
this->margin = true;
this->pl = pl; this->pl = pl;
this->nrColumns = nrColumns;
Header_forEachColumn(this, i) {
this->columns[i] = Vector_new(Class(Meter), true, DEFAULT_SIZE);
}
return this; return this;
} }
void Header_delete(Header* this) { void Header_delete(Header* this) {
Vector_delete(this->leftMeters); Header_forEachColumn(this, i) {
Vector_delete(this->rightMeters); Vector_delete(this->columns[i]);
}
free(this->columns);
free(this); free(this);
} }
void Header_createMeter(Header* this, char* name, HeaderSide side) { void Header_populateFromSettings(Header* this) {
Vector* meters = side == LEFT_HEADER Header_forEachColumn(this, col) {
? this->leftMeters MeterColumnSettings* colSettings = &this->settings->columns[col];
: this->rightMeters; for (int i = 0; i < colSettings->len; i++) {
Header_addMeterByName(this, colSettings->names[i], col);
Header_setMode(this, i, colSettings->modes[i], col);
}
}
Header_calculateHeight(this);
}
MeterModeId Header_addMeterByName(Header* this, char* name, int column) {
Vector* meters = this->columns[column];
char* paren = strchr(name, '('); char* paren = strchr(name, '(');
int param = 0; int param = 0;
...@@ -67,18 +81,20 @@ void Header_createMeter(Header* this, char* name, HeaderSide side) { ...@@ -67,18 +81,20 @@ void Header_createMeter(Header* this, char* name, HeaderSide side) {
if (!ok) param = 0; if (!ok) param = 0;
*paren = '\0'; *paren = '\0';
} }
MeterModeId mode = TEXT_METERMODE;
for (MeterClass** type = Platform_meterTypes; *type; type++) { for (MeterClass** type = Platform_meterTypes; *type; type++) {
if (String_eq(name, (*type)->name)) { if (String_eq(name, (*type)->name)) {
Vector_add(meters, Meter_new(this->pl, param, *type)); Meter* meter = Meter_new(this->pl, param, *type);
Vector_add(meters, meter);
mode = meter->mode;
break; break;
} }
} }
return mode;
} }
void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) { void Header_setMode(Header* this, int i, MeterModeId mode, int column) {
Vector* meters = side == LEFT_HEADER Vector* meters = this->columns[column];
? this->leftMeters
: this->rightMeters;
if (i >= Vector_size(meters)) if (i >= Vector_size(meters))
return; return;
...@@ -86,28 +102,21 @@ void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) { ...@@ -86,28 +102,21 @@ void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side) {
Meter_setMode(meter, mode); Meter_setMode(meter, mode);
} }
Meter* Header_addMeter(Header* this, MeterClass* type, int param, HeaderSide side) { Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column) {
Vector* meters = side == LEFT_HEADER Vector* meters = this->columns[column];
? this->leftMeters
: this->rightMeters;
Meter* meter = Meter_new(this->pl, param, type); Meter* meter = Meter_new(this->pl, param, type);
Vector_add(meters, meter); Vector_add(meters, meter);
return meter; return meter;
} }
int Header_size(Header* this, HeaderSide side) { int Header_size(Header* this, int column) {
Vector* meters = side == LEFT_HEADER Vector* meters = this->columns[column];
? this->leftMeters
: this->rightMeters;
return Vector_size(meters); return Vector_size(meters);
} }
char* Header_readMeterName(Header* this, int i, HeaderSide side) { char* Header_readMeterName(Header* this, int i, int column) {
Vector* meters = side == LEFT_HEADER Vector* meters = this->columns[column];
? this->leftMeters
: this->rightMeters;
Meter* meter = (Meter*) Vector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
int nameLen = strlen(Meter_name(meter)); int nameLen = strlen(Meter_name(meter));
...@@ -121,25 +130,20 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side) { ...@@ -121,25 +130,20 @@ char* Header_readMeterName(Header* this, int i, HeaderSide side) {
return name; return name;
} }
MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side) { MeterModeId Header_readMeterMode(Header* this, int i, int column) {
Vector* meters = side == LEFT_HEADER Vector* meters = this->columns[column];
? this->leftMeters
: this->rightMeters;
Meter* meter = (Meter*) Vector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
return meter->mode; return meter->mode;
} }
void Header_reinit(Header* this) { void Header_reinit(Header* this) {
for (int i = 0; i < Vector_size(this->leftMeters); i++) { Header_forEachColumn(this, col) {
Meter* meter = (Meter*) Vector_get(this->leftMeters, i); for (int i = 0; i < Vector_size(this->columns[col]); i++) {
if (Meter_initFn(meter)) Meter* meter = (Meter*) Vector_get(this->columns[col], i);
Meter_init(meter); if (Meter_initFn(meter))
} Meter_init(meter);
for (int i = 0; i < Vector_size(this->rightMeters); i++) { }
Meter* meter = (Meter*) Vector_get(this->rightMeters, i);
if (Meter_initFn(meter))
Meter_init(meter);
} }
} }
...@@ -150,32 +154,34 @@ void Header_draw(const Header* this) { ...@@ -150,32 +154,34 @@ void Header_draw(const Header* this) {
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
mvhline(y, 0, ' ', COLS); mvhline(y, 0, ' ', COLS);
} }
for (int y = (pad / 2), i = 0; i < Vector_size(this->leftMeters); i++) { int width = COLS / this->nrColumns - (pad * this->nrColumns - 1) - 1;
Meter* meter = (Meter*) Vector_get(this->leftMeters, i); int x = pad;
meter->draw(meter, pad, y, COLS / 2 - (pad * 2 - 1) - 1);
y += meter->h; Header_forEachColumn(this, col) {
} Vector* meters = this->columns[col];
for (int y = (pad / 2), i = 0; i < Vector_size(this->rightMeters); i++) { for (int y = (pad / 2), i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) Vector_get(this->rightMeters, i); Meter* meter = (Meter*) Vector_get(meters, i);
meter->draw(meter, COLS / 2 + pad, y, COLS / 2 - (pad * 2 - 1) - 1); meter->draw(meter, x, y, width);
y += meter->h; y += meter->h;
}
x += width + pad;
} }
} }
int Header_calculateHeight(Header* this) { int Header_calculateHeight(Header* this) {
int pad = this->margin ? 2 : 0; int pad = this->settings->headerMargin ? 2 : 0;
int leftHeight = pad; int maxHeight = pad;
int rightHeight = pad;
Header_forEachColumn(this, col) {
for (int i = 0; i < Vector_size(this->leftMeters); i++) { Vector* meters = this->columns[col];
Meter* meter = (Meter*) Vector_get(this->leftMeters, i); int height = pad;
leftHeight += meter->h; for (int i = 0; i < Vector_size(meters); i++) {
} Meter* meter = (Meter*) Vector_get(meters, i);
for (int i = 0; i < Vector_size(this->rightMeters); i++) { height += meter->h;
Meter* meter = (Meter*) Vector_get(this->rightMeters, i); }
rightHeight += meter->h; maxHeight = MAX(maxHeight, height);
} }
this->height = maxHeight;
this->pad = pad; this->pad = pad;
this->height = MAX(leftHeight, rightHeight); return maxHeight;
return this->height;
} }
...@@ -9,21 +9,17 @@ Released under the GNU GPL, see the COPYING file ...@@ -9,21 +9,17 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#include "ProcessList.h"
#include "Meter.h" #include "Meter.h"
#include "Settings.h"
typedef enum HeaderSide_ { #include "Vector.h"
LEFT_HEADER,
RIGHT_HEADER
} HeaderSide;
typedef struct Header_ { typedef struct Header_ {
Vector* leftMeters; Vector** columns;
Vector* rightMeters; Settings* settings;
ProcessList* pl; struct ProcessList_* pl;
int height; int nrColumns;
int pad; int pad;
bool margin; int height;
} Header; } Header;
...@@ -31,21 +27,27 @@ typedef struct Header_ { ...@@ -31,21 +27,27 @@ typedef struct Header_ {
#define MAX(a,b) ((a)>(b)?(a):(b)) #define MAX(a,b) ((a)>(b)?(a):(b))
#endif #endif
Header* Header_new(ProcessList* pl); #ifndef Header_forEachColumn
#define Header_forEachColumn(this_, i_) for (int i_=0; i_ < this->nrColumns; i_++)
#endif
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
void Header_delete(Header* this); void Header_delete(Header* this);
void Header_createMeter(Header* this, char* name, HeaderSide side); void Header_populateFromSettings(Header* this);
MeterModeId Header_addMeterByName(Header* this, char* name, int column);
void Header_setMode(Header* this, int i, MeterModeId mode, HeaderSide side); void Header_setMode(Header* this, int i, MeterModeId mode, int column);
Meter* Header_addMeter(Header* this, MeterClass* type, int param, HeaderSide side); Meter* Header_addMeterByClass(Header* this, MeterClass* type, int param, int column);
int Header_size(Header* this, HeaderSide side); int Header_size(Header* this, int column);
char* Header_readMeterName(Header* this, int i, HeaderSide side); char* Header_readMeterName(Header* this, int i, int column);
MeterModeId Header_readMeterMode(Header* this, int i, HeaderSide side); MeterModeId Header_readMeterMode(Header* this, int i, int column);
void Header_reinit(Header* this); void Header_reinit(Header* this);
......
...@@ -22,6 +22,7 @@ typedef struct ListItem_ { ...@@ -22,6 +22,7 @@ typedef struct ListItem_ {
Object super; Object super;
char* value; char* value;
int key; int key;
bool moving;
} ListItem; } ListItem;
}*/ }*/
...@@ -33,14 +34,19 @@ static void ListItem_delete(Object* cast) { ...@@ -33,14 +34,19 @@ static void ListItem_delete(Object* cast) {
} }
static void ListItem_display(Object* cast, RichString* out) { static void ListItem_display(Object* cast, RichString* out) {
ListItem* this = (ListItem*)cast; ListItem* const this = (ListItem*)cast;
assert (this != NULL); assert (this != NULL);
/* /*
int len = strlen(this->value)+1; int len = strlen(this->value)+1;
char buffer[len+1]; char buffer[len+1];
snprintf(buffer, len, "%s", this->value); snprintf(buffer, len, "%s", this->value);
*/ */
RichString_write(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/); if (this->moving) {
RichString_write(out, CRT_colors[DEFAULT_COLOR], CRT_utf8 ? "↕ " : "+ ");
} else {
RichString_prune(out);
}
RichString_append(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/);
} }
ObjectClass ListItem_class = { ObjectClass ListItem_class = {
...@@ -53,6 +59,7 @@ ListItem* ListItem_new(const char* value, int key) { ...@@ -53,6 +59,7 @@ ListItem* ListItem_new(const char* value, int key) {
ListItem* this = AllocThis(ListItem); ListItem* this = AllocThis(ListItem);
this->value = strdup(value); this->value = strdup(value);
this->key = key; this->key = key;
this->moving = false;
return this; return this;
} }
......
...@@ -15,6 +15,7 @@ typedef struct ListItem_ { ...@@ -15,6 +15,7 @@ typedef struct ListItem_ {
Object super; Object super;
char* value; char* value;
int key; int key;
bool moving;
} ListItem; } ListItem;
......
...@@ -65,6 +65,7 @@ MeterClass LoadAverageMeter_class = { ...@@ -65,6 +65,7 @@ MeterClass LoadAverageMeter_class = {
.attributes = LoadAverageMeter_attributes, .attributes = LoadAverageMeter_attributes,
.name = "LoadAverage", .name = "LoadAverage",
.uiName = "Load average", .uiName = "Load average",
.description = "Load averages: 15 minutes, 5 minutes, 1 minute",
.caption = "Load average: " .caption = "Load average: "
}; };
...@@ -80,5 +81,6 @@ MeterClass LoadMeter_class = { ...@@ -80,5 +81,6 @@ MeterClass LoadMeter_class = {
.attributes = LoadMeter_attributes, .attributes = LoadMeter_attributes,
.name = "Load", .name = "Load",
.uiName = "Load", .uiName = "Load",
.description = "Load: average of ready processes in the last minute",
.caption = "Load: " .caption = "Load: "
}; };
...@@ -12,11 +12,11 @@ applications_DATA = htop.desktop ...@@ -12,11 +12,11 @@ applications_DATA = htop.desktop
pixmapdir = $(datadir)/pixmaps pixmapdir = $(datadir)/pixmaps
pixmap_DATA = htop.png pixmap_DATA = htop.png
htop_CFLAGS = -pedantic -Wall -Wextra -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(my_htop_platform)" htop_CFLAGS = -pedantic -Wall $(wextra_flag) -std=c99 -rdynamic -D_XOPEN_SOURCE_EXTENDED -DSYSCONFDIR=\"$(sysconfdir)\" -I"$(my_htop_platform)"
AM_CPPFLAGS = -DNDEBUG AM_CPPFLAGS = -DNDEBUG
myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \ myhtopsources = AvailableMetersPanel.c CategoriesPanel.c CheckItem.c \
ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c \ ClockMeter.c ColorsPanel.c ColumnsPanel.c CPUMeter.c CRT.c MainPanel.c \
DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \ DisplayOptionsPanel.c FunctionBar.c Hashtable.c Header.c htop.c ListItem.c \
LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \ LoadAverageMeter.c MemoryMeter.c Meter.c MetersPanel.c Object.c Panel.c \
BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \ BatteryMeter.c Process.c ProcessList.c RichString.c ScreenManager.c Settings.c \
...@@ -26,7 +26,7 @@ HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c ...@@ -26,7 +26,7 @@ HostnameMeter.c OpenFilesScreen.c Affinity.c IncSet.c Action.c
myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \ myhtopheaders = AvailableColumnsPanel.h AvailableMetersPanel.h \
CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \ CategoriesPanel.h CheckItem.h ClockMeter.h ColorsPanel.h ColumnsPanel.h \
CPUMeter.h CRT.h DisplayOptionsPanel.h FunctionBar.h \ CPUMeter.h CRT.h MainPanel.h DisplayOptionsPanel.h FunctionBar.h \
Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \ Hashtable.h Header.h htop.h ListItem.h LoadAverageMeter.h MemoryMeter.h \
BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \ BatteryMeter.h Meter.h MetersPanel.h Object.h Panel.h ProcessList.h RichString.h \
ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \ ScreenManager.h Settings.h SignalsPanel.h String.h SwapMeter.h TasksMeter.h \
...@@ -50,11 +50,13 @@ freebsd/FreeBSDCRT.h ...@@ -50,11 +50,13 @@ freebsd/FreeBSDCRT.h
endif endif
if HTOP_UNSUPPORTED if HTOP_UNSUPPORTED
myhtopplatsources = unsupported/Platform.c unsupported/UnsupportedProcessList.c \ myhtopplatsources = unsupported/Platform.c \
unsupported/UnsupportedCRT.c unsupported/UnsupportedProcess.c unsupported/UnsupportedProcessList.c \
unsupported/UnsupportedCRT.c unsupported/Battery.c
myhtopplatheaders = unsupported/Platform.h unsupported/UnsupportedProcessList.h \ myhtopplatheaders = unsupported/Platform.h \
unsupported/UnsupportedCRT.h unsupported/UnsupportedProcess.h unsupported/UnsupportedProcessList.h \
unsupported/UnsupportedCRT.h unsupported/Battery.h
endif endif
SUFFIXES = .h SUFFIXES = .h
......
...@@ -8,7 +8,7 @@ in the source distribution for its full text. ...@@ -8,7 +8,7 @@ in the source distribution for its full text.
#include "MemoryMeter.h" #include "MemoryMeter.h"
#include "CRT.h" #include "CRT.h"
#include "ProcessList.h" #include "Platform.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
...@@ -25,15 +25,8 @@ int MemoryMeter_attributes[] = { ...@@ -25,15 +25,8 @@ int MemoryMeter_attributes[] = {
}; };
static void MemoryMeter_setValues(Meter* this, char* buffer, int size) { static void MemoryMeter_setValues(Meter* this, char* buffer, int size) {
long int usedMem = this->pl->usedMem; Platform_setMemoryValues(this);
long int buffersMem = this->pl->buffersMem; snprintf(buffer, size, "%ld/%ldMB", (long int) this->values[0] / 1024, (long int) this->total / 1024);
long int cachedMem = this->pl->cachedMem;
usedMem -= buffersMem + cachedMem;
this->total = this->pl->totalMem;
this->values[0] = usedMem;
this->values[1] = buffersMem;
this->values[2] = cachedMem;
snprintf(buffer, size, "%ld/%ldMB", (long int) usedMem / 1024, (long int) this->total / 1024);
} }
static void MemoryMeter_display(Object* cast, RichString* out) { static void MemoryMeter_display(Object* cast, RichString* out) {
...@@ -69,7 +62,7 @@ MeterClass MemoryMeter_class = { ...@@ -69,7 +62,7 @@ MeterClass MemoryMeter_class = {
.maxItems = 3, .maxItems = 3,
.total = 100.0, .total = 100.0,
.attributes = MemoryMeter_attributes, .attributes = MemoryMeter_attributes,
"Memory", .name = "Memory",
"Memory", .uiName = "Memory",
"Mem" .caption = "Mem"
}; };
...@@ -21,11 +21,14 @@ in the source distribution for its full text. ...@@ -21,11 +21,14 @@ in the source distribution for its full text.
#include <assert.h> #include <assert.h>
#include <sys/time.h> #include <sys/time.h>
#define METER_BUFFER_LEN 128 #define METER_BUFFER_LEN 256
#define GRAPH_DELAY (DEFAULT_DELAY/2)
/*{ /*{
#include "ListItem.h" #include "ListItem.h"
#include "ProcessList.h"
#include <sys/time.h>
typedef struct Meter_ Meter; typedef struct Meter_ Meter;
...@@ -48,6 +51,7 @@ typedef struct MeterClass_ { ...@@ -48,6 +51,7 @@ typedef struct MeterClass_ {
const char* name; const char* name;
const char* uiName; const char* uiName;
const char* caption; const char* caption;
const char* description;
const char maxItems; const char maxItems;
char curItems; char curItems;
} MeterClass; } MeterClass;
...@@ -77,7 +81,7 @@ struct Meter_ { ...@@ -77,7 +81,7 @@ struct Meter_ {
int param; int param;
void* drawData; void* drawData;
int h; int h;
ProcessList* pl; struct ProcessList_* pl;
double* values; double* values;
double total; double total;
}; };
...@@ -117,7 +121,7 @@ MeterClass Meter_class = { ...@@ -117,7 +121,7 @@ MeterClass Meter_class = {
} }
}; };
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type) { Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type) {
Meter* this = calloc(1, sizeof(Meter)); Meter* this = calloc(1, sizeof(Meter));
Object_setClass(this, type); Object_setClass(this, type);
this->h = 1; this->h = 1;
...@@ -302,30 +306,46 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { ...@@ -302,30 +306,46 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) {
/* ---------- GraphMeterMode ---------- */ /* ---------- GraphMeterMode ---------- */
#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0) static const char* GraphMeterMode_dotsUtf8[5][5] = {
{ /*00*/"⠀", /*01*/"⢀", /*02*/"⢠", /*03*/"⢰", /*04*/ "⢸" },
{ /*10*/"⡀", /*11*/"⣀", /*12*/"⣠", /*13*/"⣰", /*14*/ "⣸" },
{ /*20*/"⡄", /*21*/"⣄", /*22*/"⣤", /*23*/"⣴", /*24*/ "⣼" },
{ /*30*/"⡆", /*31*/"⣆", /*32*/"⣦", /*33*/"⣶", /*34*/ "⣾" },
{ /*40*/"⡇", /*41*/"⣇", /*42*/"⣧", /*43*/"⣷", /*44*/ "⣿" },
};
static int GraphMeterMode_colors[21] = { static const char* GraphMeterMode_dotsAscii[5][5] = {
GRAPH_1, GRAPH_1, GRAPH_1, { /*00*/" ", /*01*/".", /*02*/".", /*03*/":", /*04*/ ":" },
GRAPH_2, GRAPH_2, GRAPH_2, { /*10*/"⡀", /*11*/".", /*12*/".", /*13*/":", /*14*/ ":" },
GRAPH_3, GRAPH_3, GRAPH_3, { /*20*/".", /*21*/".", /*22*/".", /*23*/":", /*24*/ ":" },
GRAPH_4, GRAPH_4, GRAPH_4, { /*30*/":", /*31*/":", /*32*/":", /*33*/":", /*34*/ ":" },
GRAPH_5, GRAPH_5, GRAPH_6, { /*40*/":", /*41*/":", /*42*/":", /*43*/":", /*44*/ ":" },
GRAPH_7, GRAPH_7, GRAPH_7,
GRAPH_8, GRAPH_8, GRAPH_9
}; };
static const char* GraphMeterMode_characters = "^`'-.,_~'`-.,_~'`-.,_"; static const char* (*GraphMeterMode_dots)[5];
static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
if (!this->drawData) this->drawData = calloc(1, sizeof(GraphData)); if (!this->drawData) this->drawData = calloc(1, sizeof(GraphData));
GraphData* data = (GraphData*) this->drawData; GraphData* data = (GraphData*) this->drawData;
const int nValues = METER_BUFFER_LEN; const int nValues = METER_BUFFER_LEN;
if (CRT_utf8) {
GraphMeterMode_dots = GraphMeterMode_dotsUtf8;
} else {
GraphMeterMode_dots = GraphMeterMode_dotsAscii;
}
attrset(CRT_colors[METER_TEXT]);
int captionLen = 3;
mvaddnstr(y, x, this->caption, captionLen);
x += captionLen;
w -= captionLen;
struct timeval now; struct timeval now;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (!timercmp(&now, &(data->time), <)) { if (!timercmp(&now, &(data->time), <)) {
struct timeval delay = { .tv_sec = (int)(DEFAULT_DELAY/10), .tv_usec = (DEFAULT_DELAY-((int)(DEFAULT_DELAY/10)*10)) * 100000 }; struct timeval delay = { .tv_sec = (int)(CRT_delay/10), .tv_usec = (CRT_delay-((int)(CRT_delay/10)*10)) * 100000 };
timeradd(&now, &delay, &(data->time)); timeradd(&now, &delay, &(data->time));
for (int i = 0; i < nValues - 1; i++) for (int i = 0; i < nValues - 1; i++)
...@@ -342,18 +362,26 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { ...@@ -342,18 +362,26 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) {
data->values[nValues - 1] = value; data->values[nValues - 1] = value;
} }
for (int i = nValues - w, k = 0; i < nValues; i++, k++) { for (int i = nValues - (w*2) + 2, k = 0; i < nValues; i+=2, k++) {
double value = data->values[i]; const double dot = (1.0 / 16);
DrawDot( CRT_colors[DEFAULT_COLOR], y, ' ' ); int v1 = data->values[i] / dot;
DrawDot( CRT_colors[DEFAULT_COLOR], y+1, ' ' ); int v2 = data->values[i+1] / dot;
DrawDot( CRT_colors[DEFAULT_COLOR], y+2, ' ' );
double threshold = 1.00; if (v1 == 0) v1 = 1;
for (int j = 0; j < 21; j++, threshold -= 0.05) if (v2 == 0) v2 = 1;
if (value >= threshold) {
DrawDot(CRT_colors[GraphMeterMode_colors[j]], y+(j/7.0), GraphMeterMode_characters[j]); int level = 12;
break; int colorIdx = GRAPH_1;
} for (int line = 0; line < 4; line++) {
int line1 = MIN(4, MAX(0, v1 - level));
int line2 = MIN(4, MAX(0, v2 - level));
attrset(CRT_colors[colorIdx]);
mvaddstr(y+line, x+k, GraphMeterMode_dots[line1][line2]);
colorIdx = GRAPH_2;
level -= 4;
}
} }
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
} }
...@@ -372,18 +400,22 @@ static const char* LEDMeterMode_digitsUtf8[3][10] = { ...@@ -372,18 +400,22 @@ static const char* LEDMeterMode_digitsUtf8[3][10] = {
{ "└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘"}, { "└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘"},
}; };
static const char* (*LEDMeterMode_digits)[10];
static void LEDMeterMode_drawDigit(int x, int y, int n) { static void LEDMeterMode_drawDigit(int x, int y, int n) {
if (CRT_utf8) { for (int i = 0; i < 3; i++)
for (int i = 0; i < 3; i++) mvaddstr(y+i, x, LEDMeterMode_digits[i][n]);
mvaddstr(y+i, x, LEDMeterMode_digitsUtf8[i][n]);
} else {
for (int i = 0; i < 3; i++)
mvaddstr(y+i, x, LEDMeterMode_digitsAscii[i][n]);
}
} }
static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { static void LEDMeterMode_draw(Meter* this, int x, int y, int w) {
(void) w; (void) w;
if (CRT_utf8) {
LEDMeterMode_digits = LEDMeterMode_digitsUtf8;
} else {
LEDMeterMode_digits = LEDMeterMode_digitsAscii;
}
char buffer[METER_BUFFER_LEN]; char buffer[METER_BUFFER_LEN];
Meter_setValues(this, buffer, METER_BUFFER_LEN - 1); Meter_setValues(this, buffer, METER_BUFFER_LEN - 1);
...@@ -423,7 +455,7 @@ static MeterMode TextMeterMode = { ...@@ -423,7 +455,7 @@ static MeterMode TextMeterMode = {
static MeterMode GraphMeterMode = { static MeterMode GraphMeterMode = {
.uiName = "Graph", .uiName = "Graph",
.h = 3, .h = 4,
.draw = GraphMeterMode_draw, .draw = GraphMeterMode_draw,
}; };
......
...@@ -9,10 +9,13 @@ Released under the GNU GPL, see the COPYING file ...@@ -9,10 +9,13 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#define METER_BUFFER_LEN 128 #define METER_BUFFER_LEN 256
#define GRAPH_DELAY (DEFAULT_DELAY/2)
#include "ListItem.h" #include "ListItem.h"
#include "ProcessList.h"
#include <sys/time.h>
typedef struct Meter_ Meter; typedef struct Meter_ Meter;
...@@ -35,6 +38,7 @@ typedef struct MeterClass_ { ...@@ -35,6 +38,7 @@ typedef struct MeterClass_ {
const char* name; const char* name;
const char* uiName; const char* uiName;
const char* caption; const char* caption;
const char* description;
const char maxItems; const char maxItems;
char curItems; char curItems;
} MeterClass; } MeterClass;
...@@ -64,7 +68,7 @@ struct Meter_ { ...@@ -64,7 +68,7 @@ struct Meter_ {
int param; int param;
void* drawData; void* drawData;
int h; int h;
ProcessList* pl; struct ProcessList_* pl;
double* values; double* values;
double total; double total;
}; };
...@@ -99,7 +103,7 @@ typedef struct GraphData_ { ...@@ -99,7 +103,7 @@ typedef struct GraphData_ {
extern MeterClass Meter_class; extern MeterClass Meter_class;
Meter* Meter_new(ProcessList* pl, int param, MeterClass* type); Meter* Meter_new(struct ProcessList_* pl, int param, MeterClass* type);
void Meter_delete(Object* cast); void Meter_delete(Object* cast);
...@@ -115,8 +119,6 @@ ListItem* Meter_toListItem(Meter* this); ...@@ -115,8 +119,6 @@ ListItem* Meter_toListItem(Meter* this);
/* ---------- GraphMeterMode ---------- */ /* ---------- GraphMeterMode ---------- */
#define DrawDot(a,y,c) do { attrset(a); mvaddch(y, x+k, c); } while(0)
/* ---------- LEDMeterMode ---------- */ /* ---------- LEDMeterMode ---------- */
extern MeterMode* Meter_modes[]; extern MeterMode* Meter_modes[];
......
...@@ -15,13 +15,18 @@ in the source distribution for its full text. ...@@ -15,13 +15,18 @@ in the source distribution for its full text.
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
typedef struct MetersPanel_ { typedef struct MetersPanel_ MetersPanel;
struct MetersPanel_ {
Panel super; Panel super;
Settings* settings; Settings* settings;
Vector* meters; Vector* meters;
ScreenManager* scr; ScreenManager* scr;
} MetersPanel; MetersPanel* leftNeighbor;
MetersPanel* rightNeighbor;
bool moving;
};
}*/ }*/
...@@ -32,16 +37,46 @@ static void MetersPanel_delete(Object* object) { ...@@ -32,16 +37,46 @@ static void MetersPanel_delete(Object* object) {
free(this); free(this);
} }
static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) {
Panel* super = (Panel*) this;
if (this->moving) {
this->moving = false;
((ListItem*)Panel_getSelected(super))->moving = false;
if (neighbor) {
if (selected < Vector_size(this->meters)) {
Meter* meter = (Meter*) Vector_take(this->meters, selected);
Panel_remove(super, selected);
Vector_insert(neighbor->meters, selected, meter);
Panel_insert(&(neighbor->super), selected, (Object*) Meter_toListItem(meter));
Panel_setSelected(&(neighbor->super), selected);
neighbor->moving = true;
((ListItem*)Panel_getSelected((Panel*)neighbor))->moving = true;
return true;
}
}
}
return false;
}
static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
MetersPanel* this = (MetersPanel*) super; MetersPanel* this = (MetersPanel*) super;
int selected = Panel_getSelectedIndex(super); int selected = Panel_getSelectedIndex(super);
HandlerResult result = IGNORED; HandlerResult result = IGNORED;
bool sideMove = false;
switch(ch) { switch(ch) {
case 0x0a: case 0x0a:
case 0x0d: case 0x0d:
case KEY_ENTER: case KEY_ENTER:
{
this->moving = !(this->moving);
((ListItem*)Panel_getSelected(super))->moving = this->moving;
result = HANDLED;
break;
}
case ' ':
case KEY_F(4): case KEY_F(4):
case 't': case 't':
{ {
...@@ -53,6 +88,13 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { ...@@ -53,6 +88,13 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
result = HANDLED; result = HANDLED;
break; break;
} }
case KEY_UP:
{
if (!this->moving) {
break;
}
/* else fallthrough */
}
case KEY_F(7): case KEY_F(7):
case '[': case '[':
case '-': case '-':
...@@ -62,6 +104,13 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { ...@@ -62,6 +104,13 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
result = HANDLED; result = HANDLED;
break; break;
} }
case KEY_DOWN:
{
if (!this->moving) {
break;
}
/* else fallthrough */
}
case KEY_F(8): case KEY_F(8):
case ']': case ']':
case '+': case '+':
...@@ -71,6 +120,18 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { ...@@ -71,6 +120,18 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
result = HANDLED; result = HANDLED;
break; break;
} }
case KEY_RIGHT:
{
sideMove = moveToNeighbor(this, this->rightNeighbor, selected);
// don't set HANDLED; let ScreenManager handle focus.
break;
}
case KEY_LEFT:
{
sideMove = moveToNeighbor(this, this->leftNeighbor, selected);
// don't set HANDLED; let ScreenManager handle focus.
break;
}
case KEY_F(9): case KEY_F(9):
case KEY_DC: case KEY_DC:
{ {
...@@ -82,8 +143,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) { ...@@ -82,8 +143,8 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
break; break;
} }
} }
if (result == HANDLED) { if (result == HANDLED || sideMove) {
Header* header = this->settings->header; Header* header = (Header*) this->scr->header;
this->settings->changed = true; this->settings->changed = true;
Header_calculateHeight(header); Header_calculateHeight(header);
Header_draw(header); Header_draw(header);
...@@ -108,6 +169,9 @@ MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* met ...@@ -108,6 +169,9 @@ MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* met
this->settings = settings; this->settings = settings;
this->meters = meters; this->meters = meters;
this->scr = scr; this->scr = scr;
this->moving = false;
this->rightNeighbor = NULL;
this->leftNeighbor = NULL;
Panel_setHeader(super, header); Panel_setHeader(super, header);
for (int i = 0; i < Vector_size(meters); i++) { for (int i = 0; i < Vector_size(meters); i++) {
Meter* meter = (Meter*) Vector_get(meters, i); Meter* meter = (Meter*) Vector_get(meters, i);
......
...@@ -13,13 +13,18 @@ in the source distribution for its full text. ...@@ -13,13 +13,18 @@ in the source distribution for its full text.
#include "Settings.h" #include "Settings.h"
#include "ScreenManager.h" #include "ScreenManager.h"
typedef struct MetersPanel_ { typedef struct MetersPanel_ MetersPanel;
struct MetersPanel_ {
Panel super; Panel super;
Settings* settings; Settings* settings;
Vector* meters; Vector* meters;
ScreenManager* scr; ScreenManager* scr;
} MetersPanel; MetersPanel* leftNeighbor;
MetersPanel* rightNeighbor;
bool moving;
};
extern PanelClass MetersPanel_class; extern PanelClass MetersPanel_class;
......
...@@ -28,9 +28,12 @@ in the source distribution for its full text. ...@@ -28,9 +28,12 @@ in the source distribution for its full text.
typedef struct Panel_ Panel; typedef struct Panel_ Panel;
typedef enum HandlerResult_ { typedef enum HandlerResult_ {
HANDLED, HANDLED = 0x01,
IGNORED, IGNORED = 0x02,
BREAK_LOOP BREAK_LOOP = 0x04,
REFRESH = 0x08,
RECALCULATE = 0x10,
SYNTH_KEY = 0x20,
} HandlerResult; } HandlerResult;
#define EVENT_SETSELECTED -1 #define EVENT_SETSELECTED -1
...@@ -54,7 +57,7 @@ struct Panel_ { ...@@ -54,7 +57,7 @@ struct Panel_ {
Vector* items; Vector* items;
int selected; int selected;
int oldSelected; int oldSelected;
char* eventHandlerBuffer; void* eventHandlerState;
int scrollV; int scrollV;
short scrollH; short scrollH;
bool needsRedraw; bool needsRedraw;
...@@ -102,7 +105,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool ...@@ -102,7 +105,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool
this->y = y; this->y = y;
this->w = w; this->w = w;
this->h = h; this->h = h;
this->eventHandlerBuffer = NULL; this->eventHandlerState = NULL;
this->items = Vector_new(type, owner, DEFAULT_SIZE); this->items = Vector_new(type, owner, DEFAULT_SIZE);
this->scrollV = 0; this->scrollV = 0;
this->scrollH = 0; this->scrollH = 0;
...@@ -114,7 +117,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool ...@@ -114,7 +117,7 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool
void Panel_done(Panel* this) { void Panel_done(Panel* this) {
assert (this != NULL); assert (this != NULL);
free(this->eventHandlerBuffer); free(this->eventHandlerState);
Vector_delete(this->items); Vector_delete(this->items);
RichString_end(this->header); RichString_end(this->header);
} }
...@@ -246,30 +249,11 @@ void Panel_setSelected(Panel* this, int selected) { ...@@ -246,30 +249,11 @@ void Panel_setSelected(Panel* this, int selected) {
void Panel_draw(Panel* this, bool focus) { void Panel_draw(Panel* this, bool focus) {
assert (this != NULL); assert (this != NULL);
int itemCount = Vector_size(this->items); int size = Vector_size(this->items);
int scrollH = this->scrollH; int scrollH = this->scrollH;
int y = this->y; int x = this->x; int y = this->y;
int first = this->scrollV; int x = this->x;
if (itemCount > this->h && first > itemCount - this->h) { int h = this->h;
first = itemCount - this->h;
this->scrollV = first;
}
int last = MIN(itemCount, first + MIN(itemCount, this->h));
if (this->selected < first) {
first = this->selected;
this->scrollV = first;
this->needsRedraw = true;
}
if (this->selected >= last) {
last = MIN(itemCount, this->selected + 1);
first = last - this->h;
this->scrollV = first;
this->needsRedraw = true;
}
if (first < 0)
first = 0;
if (last > itemCount)
last = itemCount;
int headerLen = RichString_sizeVal(this->header); int headerLen = RichString_sizeVal(this->header);
if (headerLen > 0) { if (headerLen > 0) {
...@@ -285,14 +269,34 @@ void Panel_draw(Panel* this, bool focus) { ...@@ -285,14 +269,34 @@ void Panel_draw(Panel* this, bool focus) {
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
y++; y++;
} }
// ensure scroll area is on screen
if (this->scrollV < 0) {
this->scrollV = 0;
this->needsRedraw = true;
} else if (this->scrollV >= size) {
this->scrollV = MAX(size - 1, 0);
this->needsRedraw = true;
}
// ensure selection is on screen
if (this->selected < this->scrollV) {
this->scrollV = this->selected;
this->needsRedraw = true;
} else if (this->selected >= this->scrollV + h) {
this->scrollV = this->selected - h + 1;
this->needsRedraw = true;
}
int first = this->scrollV;
int upTo = MIN(first + h, size);
int highlight = focus int highlight = focus
? CRT_colors[PANEL_HIGHLIGHT_FOCUS] ? CRT_colors[PANEL_HIGHLIGHT_FOCUS]
: CRT_colors[PANEL_HIGHLIGHT_UNFOCUS]; : CRT_colors[PANEL_HIGHLIGHT_UNFOCUS];
if (this->needsRedraw) { if (this->needsRedraw) {
int line = 0;
for(int i = first, j = 0; j < this->h && i < last; i++, j++) { for(int i = first; line < h && i < upTo; i++) {
Object* itemObj = Vector_get(this->items, i); Object* itemObj = Vector_get(this->items, i);
assert(itemObj); if(!itemObj) continue; assert(itemObj); if(!itemObj) continue;
RichString_begin(item); RichString_begin(item);
...@@ -304,15 +308,18 @@ void Panel_draw(Panel* this, bool focus) { ...@@ -304,15 +308,18 @@ void Panel_draw(Panel* this, bool focus) {
attrset(highlight); attrset(highlight);
RichString_setAttr(&item, highlight); RichString_setAttr(&item, highlight);
} }
mvhline(y + j, x, ' ', this->w); mvhline(y + line, x, ' ', this->w);
if (amt > 0) if (amt > 0)
RichString_printoffnVal(item, y+j, x, scrollH, amt); RichString_printoffnVal(item, y + line, x, scrollH, amt);
if (selected) if (selected)
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
RichString_end(item); RichString_end(item);
line++;
}
while (line < h) {
mvhline(y + line, x, ' ', this->w);
line++;
} }
for (int i = y + (last - first); i < y + this->h; i++)
mvhline(i, x+0, ' ', this->w);
this->needsRedraw = false; this->needsRedraw = false;
} else { } else {
...@@ -325,15 +332,15 @@ void Panel_draw(Panel* this, bool focus) { ...@@ -325,15 +332,15 @@ void Panel_draw(Panel* this, bool focus) {
RichString_begin(new); RichString_begin(new);
Object_display(newObj, &new); Object_display(newObj, &new);
int newLen = RichString_sizeVal(new); int newLen = RichString_sizeVal(new);
mvhline(y+ this->oldSelected - this->scrollV, x+0, ' ', this->w); mvhline(y+ this->oldSelected - first, x+0, ' ', this->w);
if (scrollH < oldLen) if (scrollH < oldLen)
RichString_printoffnVal(old, y+this->oldSelected - this->scrollV, x, RichString_printoffnVal(old, y+this->oldSelected - first, x,
scrollH, MIN(oldLen - scrollH, this->w)); scrollH, MIN(oldLen - scrollH, this->w));
attrset(highlight); attrset(highlight);
mvhline(y+this->selected - this->scrollV, x+0, ' ', this->w); mvhline(y+this->selected - first, x+0, ' ', this->w);
RichString_setAttr(&new, highlight); RichString_setAttr(&new, highlight);
if (scrollH < newLen) if (scrollH < newLen)
RichString_printoffnVal(new, y+this->selected - this->scrollV, x, RichString_printoffnVal(new, y+this->selected - first, x,
scrollH, MIN(newLen - scrollH, this->w)); scrollH, MIN(newLen - scrollH, this->w));
attrset(CRT_colors[RESET_COLOR]); attrset(CRT_colors[RESET_COLOR]);
RichString_end(new); RichString_end(new);
...@@ -345,38 +352,26 @@ void Panel_draw(Panel* this, bool focus) { ...@@ -345,38 +352,26 @@ void Panel_draw(Panel* this, bool focus) {
bool Panel_onKey(Panel* this, int key) { bool Panel_onKey(Panel* this, int key) {
assert (this != NULL); assert (this != NULL);
int size = Vector_size(this->items);
switch (key) { switch (key) {
case KEY_DOWN: case KEY_DOWN:
case KEY_CTRLN: case KEY_CTRLN:
if (this->selected + 1 < Vector_size(this->items)) this->selected++;
this->selected++; break;
return true;
case KEY_UP: case KEY_UP:
case KEY_CTRLP: case KEY_CTRLP:
if (this->selected > 0) this->selected--;
this->selected--; break;
return true;
#ifdef KEY_C_DOWN #ifdef KEY_C_DOWN
case KEY_C_DOWN: case KEY_C_DOWN:
if (this->selected + 1 < Vector_size(this->items)) { this->selected++;
this->selected++; break;
if (this->scrollV < Vector_size(this->items) - this->h) {
this->scrollV++;
this->needsRedraw = true;
}
}
return true;
#endif #endif
#ifdef KEY_C_UP #ifdef KEY_C_UP
case KEY_C_UP: case KEY_C_UP:
if (this->selected > 0) { this->selected--;
this->selected--; break;
if (this->scrollV > 0) {
this->scrollV--;
this->needsRedraw = true;
}
}
return true;
#endif #endif
case KEY_LEFT: case KEY_LEFT:
case KEY_CTRLB: case KEY_CTRLB:
...@@ -384,71 +379,74 @@ bool Panel_onKey(Panel* this, int key) { ...@@ -384,71 +379,74 @@ bool Panel_onKey(Panel* this, int key) {
this->scrollH -= CRT_scrollHAmount; this->scrollH -= CRT_scrollHAmount;
this->needsRedraw = true; this->needsRedraw = true;
} }
return true; break;
case KEY_RIGHT: case KEY_RIGHT:
case KEY_CTRLF: case KEY_CTRLF:
this->scrollH += CRT_scrollHAmount; this->scrollH += CRT_scrollHAmount;
this->needsRedraw = true; this->needsRedraw = true;
return true; break;
case KEY_PPAGE: case KEY_PPAGE:
this->selected -= (this->h - 1); this->selected -= (this->h - 1);
this->scrollV -= (this->h - 1); this->scrollV -= (this->h - 1);
if (this->selected < 0)
this->selected = 0;
if (this->scrollV < 0)
this->scrollV = 0;
this->needsRedraw = true; this->needsRedraw = true;
return true; break;
case KEY_NPAGE: case KEY_NPAGE:
this->selected += (this->h - 1); this->selected += (this->h - 1);
int size = Vector_size(this->items);
if (this->selected < 0)
this->selected = 0;
if (this->selected >= size)
this->selected = size - 1;
this->scrollV += (this->h - 1); this->scrollV += (this->h - 1);
if (this->scrollV >= MAX(0, size - this->h))
this->scrollV = MAX(0, size - this->h - 1);
this->needsRedraw = true; this->needsRedraw = true;
return true; break;
case KEY_HOME: case KEY_HOME:
this->selected = 0; this->selected = 0;
return true; break;
case KEY_END: case KEY_END:
this->selected = Vector_size(this->items) - 1; this->selected = size - 1;
return true; break;
default:
return false;
}
// ensure selection within bounds
if (this->selected < 0) {
this->selected = 0;
this->needsRedraw = true;
} else if (this->selected >= size) {
this->selected = size - 1;
this->needsRedraw = true;
} }
return false; return true;
} }
HandlerResult Panel_selectByTyping(Panel* this, int ch) { HandlerResult Panel_selectByTyping(Panel* this, int ch) {
int size = Panel_size(this); int size = Panel_size(this);
if (!this->eventHandlerBuffer) if (!this->eventHandlerState)
this->eventHandlerBuffer = calloc(100, 1); this->eventHandlerState = calloc(100, 1);
char* buffer = this->eventHandlerState;
if (isalnum(ch)) { if (isalnum(ch)) {
int len = strlen(this->eventHandlerBuffer); int len = strlen(buffer);
if (len < 99) { if (len < 99) {
this->eventHandlerBuffer[len] = ch; buffer[len] = ch;
this->eventHandlerBuffer[len+1] = '\0'; buffer[len+1] = '\0';
} }
for (int try = 0; try < 2; try++) { for (int try = 0; try < 2; try++) {
len = strlen(this->eventHandlerBuffer); len = strlen(buffer);
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
char* cur = ((ListItem*) Panel_get(this, i))->value; char* cur = ((ListItem*) Panel_get(this, i))->value;
while (*cur == ' ') cur++; while (*cur == ' ') cur++;
if (strncasecmp(cur, this->eventHandlerBuffer, len) == 0) { if (strncasecmp(cur, buffer, len) == 0) {
Panel_setSelected(this, i); Panel_setSelected(this, i);
return HANDLED; return HANDLED;
} }
} }
this->eventHandlerBuffer[0] = ch; // if current word did not match,
this->eventHandlerBuffer[1] = '\0'; // retry considering the character the start of a new word.
buffer[0] = ch;
buffer[1] = '\0';
} }
return HANDLED; return HANDLED;
} else if (ch != ERR) { } else if (ch != ERR) {
this->eventHandlerBuffer[0] = '\0'; buffer[0] = '\0';
} }
if (ch == 13) { if (ch == 13) {
return BREAK_LOOP; return BREAK_LOOP;
......
...@@ -17,9 +17,12 @@ in the source distribution for its full text. ...@@ -17,9 +17,12 @@ in the source distribution for its full text.
typedef struct Panel_ Panel; typedef struct Panel_ Panel;
typedef enum HandlerResult_ { typedef enum HandlerResult_ {
HANDLED, HANDLED = 0x01,
IGNORED, IGNORED = 0x02,
BREAK_LOOP BREAK_LOOP = 0x04,
REFRESH = 0x08,
RECALCULATE = 0x10,
SYNTH_KEY = 0x20,
} HandlerResult; } HandlerResult;
#define EVENT_SETSELECTED -1 #define EVENT_SETSELECTED -1
...@@ -43,7 +46,7 @@ struct Panel_ { ...@@ -43,7 +46,7 @@ struct Panel_ {
Vector* items; Vector* items;
int selected; int selected;
int oldSelected; int oldSelected;
char* eventHandlerBuffer; void* eventHandlerState;
int scrollV; int scrollV;
short scrollH; short scrollH;
bool needsRedraw; bool needsRedraw;
......
This diff is collapsed.
...@@ -9,9 +9,6 @@ Released under the GNU GPL, see the COPYING file ...@@ -9,9 +9,6 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text. in the source distribution for its full text.
*/ */
#ifdef HAVE_LIBHWLOC
#endif
// On Linux, this works only with glibc 2.1+. On earlier versions // On Linux, this works only with glibc 2.1+. On earlier versions
// the behavior is similar to have a hardcoded page size. // the behavior is similar to have a hardcoded page size.
#ifndef PAGE_SIZE #ifndef PAGE_SIZE
...@@ -20,7 +17,6 @@ in the source distribution for its full text. ...@@ -20,7 +17,6 @@ in the source distribution for its full text.
#define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K ) #define PAGE_SIZE_KB ( PAGE_SIZE / ONE_K )
#include "Object.h" #include "Object.h"
#include "Affinity.h"
#include <sys/types.h> #include <sys/types.h>
...@@ -67,12 +63,10 @@ typedef enum ProcessField_ { ...@@ -67,12 +63,10 @@ typedef enum ProcessField_ {
LAST_PROCESSFIELD LAST_PROCESSFIELD
} ProcessField; } ProcessField;
struct ProcessList_;
typedef struct Process_ { typedef struct Process_ {
Object super; Object super;
struct ProcessList_ *pl; struct Settings_* settings;
pid_t pid; pid_t pid;
char* comm; char* comm;
...@@ -112,10 +106,10 @@ typedef struct Process_ { ...@@ -112,10 +106,10 @@ typedef struct Process_ {
unsigned long long io_read_bytes; unsigned long long io_read_bytes;
unsigned long long io_write_bytes; unsigned long long io_write_bytes;
unsigned long long io_cancelled_write_bytes; unsigned long long io_cancelled_write_bytes;
double io_rate_read_bps;
unsigned long long io_rate_read_time; unsigned long long io_rate_read_time;
double io_rate_write_bps;
unsigned long long io_rate_write_time; unsigned long long io_rate_write_time;
double io_rate_read_bps;
double io_rate_write_bps;
#endif #endif
int processor; int processor;
...@@ -171,12 +165,18 @@ typedef struct Process_ { ...@@ -171,12 +165,18 @@ typedef struct Process_ {
} Process; } Process;
typedef struct ProcessFieldData_ {
const char* name;
const char* title;
const char* description;
int flags;
} ProcessFieldData;
extern const char *Process_fieldNames[]; void Process_writeField(Process* this, RichString* str, ProcessField field);
long Process_compare(const void* v1, const void* v2);
extern const int Process_fieldFlags[];
extern const char *Process_fieldTitles[]; extern ProcessFieldData Process_fields[];
void Process_setupColumnWidths(); void Process_setupColumnWidths();
...@@ -189,11 +189,13 @@ void Process_setupColumnWidths(); ...@@ -189,11 +189,13 @@ void Process_setupColumnWidths();
#define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K) #define ONE_DECIMAL_M (ONE_DECIMAL_K * ONE_DECIMAL_K)
#define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K) #define ONE_DECIMAL_G (ONE_DECIMAL_M * ONE_DECIMAL_K)
void Process_delete(Object* cast); void Process_writeDefaultField(Process* this, RichString* str, ProcessField field);
void Process_done(Process* this);
extern ObjectClass Process_class; extern ObjectClass Process_class;
Process* Process_new(struct ProcessList_ *pl); void Process_init(Process* this, struct Settings_* settings);
void Process_toggleTag(Process* this); void Process_toggleTag(Process* this);
...@@ -201,24 +203,10 @@ bool Process_setPriority(Process* this, int priority); ...@@ -201,24 +203,10 @@ bool Process_setPriority(Process* this, int priority);
bool Process_changePriorityBy(Process* this, size_t delta); bool Process_changePriorityBy(Process* this, size_t delta);
#ifdef HAVE_LIBHWLOC
Affinity* Process_getAffinity(Process* this);
bool Process_setAffinity(Process* this, Affinity* affinity);
#elif HAVE_NATIVE_AFFINITY
Affinity* Process_getAffinity(Process* this);
bool Process_setAffinity(Process* this, Affinity* affinity);
#endif
void Process_sendSignal(Process* this, size_t sgn); void Process_sendSignal(Process* this, size_t sgn);
long Process_pidCompare(const void* v1, const void* v2); long Process_pidCompare(const void* v1, const void* v2);
long Process_compare(const void* v1, const void* v2); long Process_defaultCompare(const void* v1, const void* v2);
#endif #endif
...@@ -19,6 +19,7 @@ in the source distribution for its full text. ...@@ -19,6 +19,7 @@ in the source distribution for its full text.
#include "UsersTable.h" #include "UsersTable.h"
#include "Panel.h" #include "Panel.h"
#include "Process.h" #include "Process.h"
#include "Settings.h"
#ifndef MAX_NAME #ifndef MAX_NAME
#define MAX_NAME 128 #define MAX_NAME 128
...@@ -28,51 +29,9 @@ in the source distribution for its full text. ...@@ -28,51 +29,9 @@ in the source distribution for its full text.
#define MAX_READ 2048 #define MAX_READ 2048
#endif #endif
#ifndef ProcessList_cpuId
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu) : (cpu)+1)
#endif
typedef enum TreeStr_ {
TREE_STR_HORZ,
TREE_STR_VERT,
TREE_STR_RTEE,
TREE_STR_BEND,
TREE_STR_TEND,
TREE_STR_OPEN,
TREE_STR_SHUT,
TREE_STR_COUNT
} TreeStr;
typedef struct CPUData_ {
unsigned long long int totalTime;
unsigned long long int userTime;
unsigned long long int systemTime;
unsigned long long int systemAllTime;
unsigned long long int idleAllTime;
unsigned long long int idleTime;
unsigned long long int niceTime;
unsigned long long int ioWaitTime;
unsigned long long int irqTime;
unsigned long long int softIrqTime;
unsigned long long int stealTime;
unsigned long long int guestTime;
unsigned long long int totalPeriod;
unsigned long long int userPeriod;
unsigned long long int systemPeriod;
unsigned long long int systemAllPeriod;
unsigned long long int idleAllPeriod;
unsigned long long int idlePeriod;
unsigned long long int nicePeriod;
unsigned long long int ioWaitPeriod;
unsigned long long int irqPeriod;
unsigned long long int softIrqPeriod;
unsigned long long int stealPeriod;
unsigned long long int guestPeriod;
} CPUData;
typedef struct ProcessList_ { typedef struct ProcessList_ {
const char **treeStr; Settings* settings;
Vector* processes; Vector* processes;
Vector* processes2; Vector* processes2;
Hashtable* processTable; Hashtable* processTable;
...@@ -84,90 +43,33 @@ typedef struct ProcessList_ { ...@@ -84,90 +43,33 @@ typedef struct ProcessList_ {
const char* incFilter; const char* incFilter;
Hashtable* pidWhiteList; Hashtable* pidWhiteList;
int cpuCount;
int totalTasks;
int userlandThreads;
int kernelThreads;
int runningTasks;
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
hwloc_topology_t topology; hwloc_topology_t topology;
bool topologyOk; bool topologyOk;
#endif #endif
CPUData* cpus;
int cpuCount;
unsigned long long int totalMem;
unsigned long long int usedMem;
unsigned long long int freeMem;
unsigned long long int sharedMem;
unsigned long long int buffersMem;
unsigned long long int cachedMem;
unsigned long long int totalSwap;
unsigned long long int usedSwap;
unsigned long long int freeSwap;
int flags;
ProcessField* fields;
ProcessField sortKey;
int direction;
bool hideThreads;
bool shadowOtherUsers;
bool showThreadNames;
bool showingThreadNames;
bool hideKernelThreads;
bool hideUserlandThreads;
bool treeView;
bool highlightBaseName;
bool highlightMegabytes;
bool highlightThreads;
bool detailedCPUTime;
bool countCPUsFromZero;
bool updateProcessNames;
bool accountGuestInCPUMeter;
bool userOnly;
} ProcessList; } ProcessList;
ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList); ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* pl); void ProcessList_delete(ProcessList* pl);
void ProcessList_scan(ProcessList* pl); void ProcessList_scan(ProcessList* pl);
}*/ }*/
static ProcessField defaultHeaders[] = { PID, USER, PRIORITY, NICE, M_SIZE, M_RESIDENT, M_SHARE, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId) {
const char *ProcessList_treeStrAscii[TREE_STR_COUNT] = {
"-", // TREE_STR_HORZ
"|", // TREE_STR_VERT
"`", // TREE_STR_RTEE
"`", // TREE_STR_BEND
",", // TREE_STR_TEND
"+", // TREE_STR_OPEN
"-", // TREE_STR_SHUT
};
const char *ProcessList_treeStrUtf8[TREE_STR_COUNT] = {
"\xe2\x94\x80", // TREE_STR_HORZ ─
"\xe2\x94\x82", // TREE_STR_VERT │
"\xe2\x94\x9c", // TREE_STR_RTEE ├
"\xe2\x94\x94", // TREE_STR_BEND └
"\xe2\x94\x8c", // TREE_STR_TEND ┌
"+", // TREE_STR_OPEN +
"\xe2\x94\x80", // TREE_STR_SHUT ─
};
ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtable* pidWhiteList) {
this->processes = Vector_new(Class(Process), true, DEFAULT_SIZE); this->processes = Vector_new(Class(Process), true, DEFAULT_SIZE);
this->processTable = Hashtable_new(140, false); this->processTable = Hashtable_new(140, false);
this->usersTable = usersTable; this->usersTable = usersTable;
this->pidWhiteList = pidWhiteList; this->pidWhiteList = pidWhiteList;
this->userId = userId;
// tree-view auxiliary buffers // tree-view auxiliary buffers
this->processes2 = Vector_new(Class(Process), true, DEFAULT_SIZE); this->processes2 = Vector_new(Class(Process), true, DEFAULT_SIZE);
// set later by platform-specific code // set later by platform-specific code
this->cpuCount = 0; this->cpuCount = 0;
this->cpus = NULL;
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
this->topologyOk = false; this->topologyOk = false;
...@@ -180,35 +82,8 @@ ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtab ...@@ -180,35 +82,8 @@ ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtab
} }
#endif #endif
this->fields = calloc(LAST_PROCESSFIELD+1, sizeof(ProcessField));
// TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects).
this->flags = 0;
for (int i = 0; defaultHeaders[i]; i++) {
this->fields[i] = defaultHeaders[i];
this->flags |= Process_fieldFlags[defaultHeaders[i]];
}
this->sortKey = PERCENT_CPU;
this->direction = 1;
this->hideThreads = false;
this->shadowOtherUsers = false;
this->showThreadNames = false;
this->showingThreadNames = false;
this->hideKernelThreads = false;
this->hideUserlandThreads = false;
this->treeView = false;
this->highlightBaseName = false;
this->highlightMegabytes = false;
this->detailedCPUTime = false;
this->countCPUsFromZero = false;
this->updateProcessNames = false;
this->treeStr = NULL;
this->following = -1; this->following = -1;
if (CRT_utf8)
this->treeStr = CRT_utf8 ? ProcessList_treeStrUtf8 : ProcessList_treeStrAscii;
return this; return this;
} }
...@@ -216,27 +91,19 @@ void ProcessList_done(ProcessList* this) { ...@@ -216,27 +91,19 @@ void ProcessList_done(ProcessList* this) {
Hashtable_delete(this->processTable); Hashtable_delete(this->processTable);
Vector_delete(this->processes); Vector_delete(this->processes);
Vector_delete(this->processes2); Vector_delete(this->processes2);
free(this->cpus);
free(this->fields);
} }
void ProcessList_setPanel(ProcessList* this, Panel* panel) { void ProcessList_setPanel(ProcessList* this, Panel* panel) {
this->panel = panel; this->panel = panel;
} }
void ProcessList_invertSortOrder(ProcessList* this) {
if (this->direction == 1)
this->direction = -1;
else
this->direction = 1;
}
void ProcessList_printHeader(ProcessList* this, RichString* header) { void ProcessList_printHeader(ProcessList* this, RichString* header) {
RichString_prune(header); RichString_prune(header);
ProcessField* fields = this->fields; ProcessField* fields = this->settings->fields;
for (int i = 0; fields[i]; i++) { for (int i = 0; fields[i]; i++) {
const char* field = Process_fieldTitles[fields[i]]; const char* field = Process_fields[fields[i]].title;
if (!this->treeView && this->sortKey == fields[i]) if (!field) field = "- ";
if (!this->settings->treeView && this->settings->sortKey == fields[i])
RichString_append(header, CRT_colors[PANEL_HIGHLIGHT_FOCUS], field); RichString_append(header, CRT_colors[PANEL_HIGHLIGHT_FOCUS], field);
else else
RichString_append(header, CRT_colors[PANEL_HEADER_FOCUS], field); RichString_append(header, CRT_colors[PANEL_HEADER_FOCUS], field);
...@@ -308,19 +175,19 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i ...@@ -308,19 +175,19 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i
} }
void ProcessList_sort(ProcessList* this) { void ProcessList_sort(ProcessList* this) {
if (!this->treeView) { if (!this->settings->treeView) {
Vector_insertionSort(this->processes); Vector_insertionSort(this->processes);
} else { } else {
// Save settings // Save settings
int direction = this->direction; int direction = this->settings->direction;
int sortKey = this->sortKey; int sortKey = this->settings->sortKey;
// Sort by PID // Sort by PID
this->sortKey = PID; this->settings->sortKey = PID;
this->direction = 1; this->settings->direction = 1;
Vector_quickSort(this->processes); Vector_quickSort(this->processes);
// Restore settings // Restore settings
this->sortKey = sortKey; this->settings->sortKey = sortKey;
this->direction = direction; this->settings->direction = direction;
// Take PID 1 as root and add to the new listing // Take PID 1 as root and add to the new listing
int vsize = Vector_size(this->processes); int vsize = Vector_size(this->processes);
Process* init = (Process*) (Vector_take(this->processes, 0)); Process* init = (Process*) (Vector_take(this->processes, 0));
...@@ -351,10 +218,12 @@ void ProcessList_sort(ProcessList* this) { ...@@ -351,10 +218,12 @@ void ProcessList_sort(ProcessList* this) {
ProcessField ProcessList_keyAt(ProcessList* this, int at) { ProcessField ProcessList_keyAt(ProcessList* this, int at) {
int x = 0; int x = 0;
ProcessField* fields = this->fields; ProcessField* fields = this->settings->fields;
ProcessField field; ProcessField field;
for (int i = 0; (field = fields[i]); i++) { for (int i = 0; (field = fields[i]); i++) {
int len = strlen(Process_fieldTitles[field]); const char* title = Process_fields[field].title;
if (!title) title = "- ";
int len = strlen(title);
if (at >= x && at <= x + len) { if (at >= x && at <= x + len) {
return field; return field;
} }
...@@ -371,17 +240,11 @@ void ProcessList_expandTree(ProcessList* this) { ...@@ -371,17 +240,11 @@ void ProcessList_expandTree(ProcessList* this) {
} }
} }
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, const char* incFilter) { void ProcessList_rebuildPanel(ProcessList* this) {
if (!flags) { const char* incFilter = this->incFilter;
following = this->following;
incFilter = this->incFilter;
} else {
this->following = following;
this->incFilter = incFilter;
}
int currPos = Panel_getSelectedIndex(this->panel); int currPos = Panel_getSelectedIndex(this->panel);
pid_t currPid = following != -1 ? following : 0; pid_t currPid = this->following != -1 ? this->following : 0;
int currScrollV = this->panel->scrollV; int currScrollV = this->panel->scrollV;
Panel_prune(this->panel); Panel_prune(this->panel);
...@@ -392,14 +255,14 @@ void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, cons ...@@ -392,14 +255,14 @@ void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, cons
Process* p = ProcessList_get(this, i); Process* p = ProcessList_get(this, i);
if ( (!p->show) if ( (!p->show)
|| (this->userOnly && (p->st_uid != this->userId)) || (this->userId != (uid_t) -1 && (p->st_uid != this->userId))
|| (incFilter && !(String_contains_i(p->comm, incFilter))) || (incFilter && !(String_contains_i(p->comm, incFilter)))
|| (this->pidWhiteList && !Hashtable_get(this->pidWhiteList, p->pid)) ) || (this->pidWhiteList && !Hashtable_get(this->pidWhiteList, p->pid)) )
hidden = true; hidden = true;
if (!hidden) { if (!hidden) {
Panel_set(this->panel, idx, (Object*)p); Panel_set(this->panel, idx, (Object*)p);
if ((following == -1 && idx == currPos) || (following != -1 && p->pid == currPid)) { if ((this->following == -1 && idx == currPos) || (this->following != -1 && p->pid == currPid)) {
Panel_setSelected(this->panel, idx); Panel_setSelected(this->panel, idx);
this->panel->scrollV = currScrollV; this->panel->scrollV = currScrollV;
} }
......
...@@ -14,6 +14,7 @@ in the source distribution for its full text. ...@@ -14,6 +14,7 @@ in the source distribution for its full text.
#include "UsersTable.h" #include "UsersTable.h"
#include "Panel.h" #include "Panel.h"
#include "Process.h" #include "Process.h"
#include "Settings.h"
#ifndef MAX_NAME #ifndef MAX_NAME
#define MAX_NAME 128 #define MAX_NAME 128
...@@ -23,51 +24,9 @@ in the source distribution for its full text. ...@@ -23,51 +24,9 @@ in the source distribution for its full text.
#define MAX_READ 2048 #define MAX_READ 2048
#endif #endif
#ifndef ProcessList_cpuId
#define ProcessList_cpuId(pl, cpu) ((pl)->countCPUsFromZero ? (cpu) : (cpu)+1)
#endif
typedef enum TreeStr_ {
TREE_STR_HORZ,
TREE_STR_VERT,
TREE_STR_RTEE,
TREE_STR_BEND,
TREE_STR_TEND,
TREE_STR_OPEN,
TREE_STR_SHUT,
TREE_STR_COUNT
} TreeStr;
typedef struct CPUData_ {
unsigned long long int totalTime;
unsigned long long int userTime;
unsigned long long int systemTime;
unsigned long long int systemAllTime;
unsigned long long int idleAllTime;
unsigned long long int idleTime;
unsigned long long int niceTime;
unsigned long long int ioWaitTime;
unsigned long long int irqTime;
unsigned long long int softIrqTime;
unsigned long long int stealTime;
unsigned long long int guestTime;
unsigned long long int totalPeriod;
unsigned long long int userPeriod;
unsigned long long int systemPeriod;
unsigned long long int systemAllPeriod;
unsigned long long int idleAllPeriod;
unsigned long long int idlePeriod;
unsigned long long int nicePeriod;
unsigned long long int ioWaitPeriod;
unsigned long long int irqPeriod;
unsigned long long int softIrqPeriod;
unsigned long long int stealPeriod;
unsigned long long int guestPeriod;
} CPUData;
typedef struct ProcessList_ { typedef struct ProcessList_ {
const char **treeStr; Settings* settings;
Vector* processes; Vector* processes;
Vector* processes2; Vector* processes2;
Hashtable* processTable; Hashtable* processTable;
...@@ -79,67 +38,26 @@ typedef struct ProcessList_ { ...@@ -79,67 +38,26 @@ typedef struct ProcessList_ {
const char* incFilter; const char* incFilter;
Hashtable* pidWhiteList; Hashtable* pidWhiteList;
int cpuCount;
int totalTasks;
int userlandThreads;
int kernelThreads;
int runningTasks;
#ifdef HAVE_LIBHWLOC #ifdef HAVE_LIBHWLOC
hwloc_topology_t topology; hwloc_topology_t topology;
bool topologyOk; bool topologyOk;
#endif #endif
CPUData* cpus;
int cpuCount;
unsigned long long int totalMem;
unsigned long long int usedMem;
unsigned long long int freeMem;
unsigned long long int sharedMem;
unsigned long long int buffersMem;
unsigned long long int cachedMem;
unsigned long long int totalSwap;
unsigned long long int usedSwap;
unsigned long long int freeSwap;
int flags;
ProcessField* fields;
ProcessField sortKey;
int direction;
bool hideThreads;
bool shadowOtherUsers;
bool showThreadNames;
bool showingThreadNames;
bool hideKernelThreads;
bool hideUserlandThreads;
bool treeView;
bool highlightBaseName;
bool highlightMegabytes;
bool highlightThreads;
bool detailedCPUTime;
bool countCPUsFromZero;
bool updateProcessNames;
bool accountGuestInCPUMeter;
bool userOnly;
} ProcessList; } ProcessList;
ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList); ProcessList* ProcessList_new(UsersTable* ut, Hashtable* pidWhiteList, uid_t userId);
void ProcessList_delete(ProcessList* pl); void ProcessList_delete(ProcessList* pl);
void ProcessList_scan(ProcessList* pl); void ProcessList_scan(ProcessList* pl);
extern const char *ProcessList_treeStrAscii[TREE_STR_COUNT]; ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtable* pidWhiteList, uid_t userId);
extern const char *ProcessList_treeStrUtf8[TREE_STR_COUNT];
ProcessList* ProcessList_init(ProcessList* this, UsersTable* usersTable, Hashtable* pidWhiteList);
void ProcessList_done(ProcessList* this); void ProcessList_done(ProcessList* this);
void ProcessList_setPanel(ProcessList* this, Panel* panel); void ProcessList_setPanel(ProcessList* this, Panel* panel);
void ProcessList_invertSortOrder(ProcessList* this);
void ProcessList_printHeader(ProcessList* this, RichString* header); void ProcessList_printHeader(ProcessList* this, RichString* header);
void ProcessList_add(ProcessList* this, Process* p); void ProcessList_add(ProcessList* this, Process* p);
...@@ -156,7 +74,7 @@ ProcessField ProcessList_keyAt(ProcessList* this, int at); ...@@ -156,7 +74,7 @@ ProcessField ProcessList_keyAt(ProcessList* this, int at);
void ProcessList_expandTree(ProcessList* this); void ProcessList_expandTree(ProcessList* this);
void ProcessList_rebuildPanel(ProcessList* this, bool flags, int following, const char* incFilter); void ProcessList_rebuildPanel(ProcessList* this);
#endif #endif
...@@ -6,8 +6,8 @@ in the source distribution for its full text. ...@@ -6,8 +6,8 @@ in the source distribution for its full text.
*/ */
#include "ScreenManager.h" #include "ScreenManager.h"
#include "ProcessList.h"
#include "Panel.h"
#include "Object.h" #include "Object.h"
#include <assert.h> #include <assert.h>
...@@ -19,6 +19,8 @@ in the source distribution for its full text. ...@@ -19,6 +19,8 @@ in the source distribution for its full text.
#include "FunctionBar.h" #include "FunctionBar.h"
#include "Vector.h" #include "Vector.h"
#include "Header.h" #include "Header.h"
#include "Settings.h"
#include "Panel.h"
typedef enum Orientation_ { typedef enum Orientation_ {
VERTICAL, VERTICAL,
...@@ -36,14 +38,14 @@ typedef struct ScreenManager_ { ...@@ -36,14 +38,14 @@ typedef struct ScreenManager_ {
int panelCount; int panelCount;
const FunctionBar* fuBar; const FunctionBar* fuBar;
const Header* header; const Header* header;
time_t lastScan; const Settings* settings;
bool owner; bool owner;
bool allowFocusChange; bool allowFocusChange;
} ScreenManager; } ScreenManager;
}*/ }*/
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, bool owner) { ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner) {
ScreenManager* this; ScreenManager* this;
this = malloc(sizeof(ScreenManager)); this = malloc(sizeof(ScreenManager));
this->x1 = x1; this->x1 = x1;
...@@ -56,6 +58,7 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori ...@@ -56,6 +58,7 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
this->fuBars = Vector_new(Class(FunctionBar), true, DEFAULT_SIZE); this->fuBars = Vector_new(Class(FunctionBar), true, DEFAULT_SIZE);
this->panelCount = 0; this->panelCount = 0;
this->header = header; this->header = header;
this->settings = settings;
this->owner = owner; this->owner = owner;
this->allowFocusChange = true; this->allowFocusChange = true;
return this; return this;
...@@ -78,10 +81,11 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int ...@@ -78,10 +81,11 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int
Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1); Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1);
lastX = last->x + last->w + 1; lastX = last->x + last->w + 1;
} }
int height = LINES - this->y1 + this->y2;
if (size > 0) { if (size > 0) {
Panel_resize(item, size, LINES-this->y1+this->y2); Panel_resize(item, size, height);
} else { } else {
Panel_resize(item, COLS-this->x1+this->x2-lastX, LINES-this->y1+this->y2); Panel_resize(item, COLS-this->x1+this->x2-lastX, height);
} }
Panel_move(item, lastX, this->y1); Panel_move(item, lastX, this->y1);
} }
...@@ -111,16 +115,19 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) { ...@@ -111,16 +115,19 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
this->x2 = x2; this->x2 = x2;
this->y2 = y2; this->y2 = y2;
int panels = this->panelCount; int panels = this->panelCount;
int lastX = 0; if (this->orientation == HORIZONTAL) {
for (int i = 0; i < panels - 1; i++) { int lastX = 0;
Panel* panel = (Panel*) Vector_get(this->panels, i); for (int i = 0; i < panels - 1; i++) {
Panel_resize(panel, panel->w, LINES-y1+y2); 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);
Panel_move(panel, lastX, y1); Panel_move(panel, lastX, y1);
lastX = panel->x + panel->w + 1;
} }
Panel* panel = (Panel*) Vector_get(this->panels, panels-1); // TODO: VERTICAL
Panel_resize(panel, COLS-x1+x2-lastX, LINES-y1+y2);
Panel_move(panel, lastX, y1);
} }
void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...@@ -130,39 +137,68 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { ...@@ -130,39 +137,68 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
Panel* panelFocus = (Panel*) Vector_get(this->panels, focus); Panel* panelFocus = (Panel*) Vector_get(this->panels, focus);
if (this->fuBar) if (this->fuBar)
FunctionBar_draw(this->fuBar, NULL); FunctionBar_draw(this->fuBar, NULL);
this->lastScan = 0;
int ch = 0; 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;
int sortTimeout = 0;
int resetSortTimeout = 5;
while (!quit) { while (!quit) {
int panels = this->panelCount; int panels = this->panelCount;
if (this->header) { if (this->header) {
time_t now = time(NULL); gettimeofday(&tv, NULL);
if (now > this->lastScan) { double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000);
ProcessList_scan(this->header->pl); timeToRecalculate = (newTime - oldTime > this->settings->delay);
ProcessList_sort(this->header->pl); if (newTime < oldTime) timeToRecalculate = true; // clock was adjusted?
this->lastScan = now; 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;
} }
Header_draw(this->header); doRefresh = true;
ProcessList_rebuildPanel(this->header->pl, false, false, NULL);
} }
for (int i = 0; i < panels; i++) {
Panel* panel = (Panel*) Vector_get(this->panels, i); if (drawPanel) {
Panel_draw(panel, i == focus); for (int i = 0; i < panels; i++) {
if (i < panels) { Panel* panel = (Panel*) Vector_get(this->panels, i);
if (this->orientation == HORIZONTAL) { Panel_draw(panel, i == focus);
mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1); 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);
if (bar) if (bar)
this->fuBar = bar; this->fuBar = bar;
if (this->fuBar) if (this->fuBar)
FunctionBar_draw(this->fuBar, NULL); FunctionBar_draw(this->fuBar, NULL);
int prevCh = ch;
ch = getch(); ch = getch();
if (ch == KEY_MOUSE) { if (ch == KEY_MOUSE) {
MEVENT mevent; MEVENT mevent;
int ok = getmouse(&mevent); int ok = getmouse(&mevent);
...@@ -184,20 +220,42 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { ...@@ -184,20 +220,42 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
} }
} }
} }
if (Panel_eventHandlerFn(panelFocus)) { if (Panel_eventHandlerFn(panelFocus)) {
HandlerResult result = Panel_eventHandler(panelFocus, ch); HandlerResult result = Panel_eventHandler(panelFocus, ch);
if (result == HANDLED) { if (result & SYNTH_KEY) {
ch = result >> 16;
}
if (result & REFRESH) {
doRefresh = true;
sortTimeout = 0;
}
if (result & RECALCULATE) {
forceRecalculate = true;
sortTimeout = 0;
}
if (result & HANDLED) {
drawPanel = true;
continue; continue;
} else if (result == BREAK_LOOP) { } else if (result & BREAK_LOOP) {
quit = true; quit = true;
continue; continue;
} }
} }
if (ch == ERR) {
sortTimeout--;
if (prevCh == ch && !timeToRecalculate) {
closeTimeout++;
if (closeTimeout == 100) {
break;
}
} else
closeTimeout = 0;
drawPanel = false;
continue;
}
drawPanel = true;
switch (ch) { switch (ch) {
case ERR:
continue;
case KEY_RESIZE: case KEY_RESIZE:
{ {
ScreenManager_resize(this, this->x1, this->y1, this->x2, this->y2); ScreenManager_resize(this, this->x1, this->y1, this->x2, this->y2);
...@@ -232,11 +290,14 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { ...@@ -232,11 +290,14 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
quit = true; quit = true;
continue; continue;
default: default:
sortTimeout = resetSortTimeout;
Panel_onKey(panelFocus, ch); Panel_onKey(panelFocus, ch);
break; break;
} }
} }
*lastFocus = panelFocus; if (lastFocus)
*lastKey = ch; *lastFocus = panelFocus;
if (lastKey)
*lastKey = ch;
} }
...@@ -12,6 +12,8 @@ in the source distribution for its full text. ...@@ -12,6 +12,8 @@ in the source distribution for its full text.
#include "FunctionBar.h" #include "FunctionBar.h"
#include "Vector.h" #include "Vector.h"
#include "Header.h" #include "Header.h"
#include "Settings.h"
#include "Panel.h"
typedef enum Orientation_ { typedef enum Orientation_ {
VERTICAL, VERTICAL,
...@@ -29,13 +31,13 @@ typedef struct ScreenManager_ { ...@@ -29,13 +31,13 @@ typedef struct ScreenManager_ {
int panelCount; int panelCount;
const FunctionBar* fuBar; const FunctionBar* fuBar;
const Header* header; const Header* header;
time_t lastScan; const Settings* settings;
bool owner; bool owner;
bool allowFocusChange; bool allowFocusChange;
} ScreenManager; } ScreenManager;
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, bool owner); ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, const Header* header, const Settings* settings, bool owner);
void ScreenManager_delete(ScreenManager* this); void ScreenManager_delete(ScreenManager* this);
......
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