htop/AvailableMetersPanel.c

107 lines
3.1 KiB
C
Raw Normal View History

2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
#include "AvailableMetersPanel.h"
2006-03-04 18:16:49 +00:00
#include "Settings.h"
#include "Header.h"
#include "ScreenManager.h"
#include "CPUMeter.h"
2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
#include "Panel.h"
2006-03-04 18:16:49 +00:00
#include "debug.h"
#include <assert.h>
/*{
2006-05-30 13:47:28 +00:00
typedef struct AvailableMetersPanel_ {
Panel super;
2006-03-04 18:16:49 +00:00
Settings* settings;
2006-05-30 14:00:18 +00:00
Panel* leftPanel;
Panel* rightPanel;
2006-03-04 18:16:49 +00:00
ScreenManager* scr;
2006-05-30 13:47:28 +00:00
} AvailableMetersPanel;
2006-03-04 18:16:49 +00:00
}*/
2006-05-30 13:47:28 +00:00
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr) {
AvailableMetersPanel* this = (AvailableMetersPanel*) malloc(sizeof(AvailableMetersPanel));
Panel* super = (Panel*) this;
Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
((Object*)this)->delete = AvailableMetersPanel_delete;
2006-03-04 18:16:49 +00:00
this->settings = settings;
2006-05-30 14:00:18 +00:00
this->leftPanel = leftMeters;
this->rightPanel = rightMeters;
2006-03-04 18:16:49 +00:00
this->scr = scr;
2006-05-30 13:47:28 +00:00
super->eventHandler = AvailableMetersPanel_EventHandler;
2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
Panel_setHeader(super, "Available meters");
for (int i = 1; Meter_types[i]; i++) {
MeterType* type = Meter_types[i];
2006-05-09 18:18:08 +00:00
if (type != &CPUMeter) {
2006-05-30 13:47:28 +00:00
Panel_add(super, (Object*) ListItem_new(type->uiName, i << 16));
}
}
MeterType* type = &CPUMeter;
int processors = settings->pl->processorCount;
if (processors > 1) {
2006-05-30 13:47:28 +00:00
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
for (int i = 1; i <= processors; i++) {
char buffer[50];
sprintf(buffer, "%s %d", type->uiName, i);
2006-05-30 13:47:28 +00:00
Panel_add(super, (Object*) ListItem_new(buffer, i));
}
} else {
2006-05-30 13:47:28 +00:00
Panel_add(super, (Object*) ListItem_new("CPU", 1));
2006-03-04 18:16:49 +00:00
}
return this;
}
2006-05-30 13:47:28 +00:00
void AvailableMetersPanel_delete(Object* object) {
Panel* super = (Panel*) object;
AvailableMetersPanel* this = (AvailableMetersPanel*) object;
Panel_done(super);
2006-03-04 18:16:49 +00:00
free(this);
}
static inline void AvailableMetersPanel_addHeader(Header* header, Panel* panel, MeterType* type, int param, HeaderSide side) {
Meter* meter = (Meter*) Header_addMeter(header, type, param, side);
2006-05-30 14:00:18 +00:00
Panel_add(panel, (Object*) Meter_toListItem(meter));
2006-03-04 18:16:49 +00:00
}
2006-05-30 13:47:28 +00:00
HandlerResult AvailableMetersPanel_EventHandler(Panel* super, int ch) {
AvailableMetersPanel* this = (AvailableMetersPanel*) super;
2006-03-04 18:16:49 +00:00
Header* header = this->settings->header;
2006-05-30 13:47:28 +00:00
ListItem* selected = (ListItem*) Panel_getSelected(super);
int param = selected->key & 0xff;
int type = selected->key >> 16;
2006-03-04 18:16:49 +00:00
HandlerResult result = IGNORED;
switch(ch) {
case KEY_F(5):
case 'l':
case 'L':
{
2006-05-30 14:00:18 +00:00
AvailableMetersPanel_addHeader(header, this->leftPanel, Meter_types[type], param, LEFT_HEADER);
2006-03-04 18:16:49 +00:00
result = HANDLED;
break;
}
case KEY_F(6):
case 'r':
case 'R':
{
2006-05-30 14:00:18 +00:00
AvailableMetersPanel_addHeader(header, this->rightPanel, Meter_types[type], param, RIGHT_HEADER);
2006-03-04 18:16:49 +00:00
result = HANDLED;
break;
}
}
if (result == HANDLED) {
this->settings->changed = true;
Header_calculateHeight(header);
Header_draw(header);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
}
return result;
}