2011-12-26 21:35:57 +00:00
|
|
|
/*
|
|
|
|
htop - AvailableMetersPanel.c
|
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
|
|
|
Released under the GNU GPL, see the COPYING file
|
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
#include "AvailableMetersPanel.h"
|
2015-02-03 21:32:07 +00:00
|
|
|
#include "MetersPanel.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "CPUMeter.h"
|
|
|
|
#include "Header.h"
|
|
|
|
#include "ListItem.h"
|
2014-11-27 21:18:14 +00:00
|
|
|
#include "Platform.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
#include <assert.h>
|
2011-12-26 21:35:57 +00:00
|
|
|
#include <stdlib.h>
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
/*{
|
2011-12-26 21:35:57 +00:00
|
|
|
#include "Settings.h"
|
|
|
|
#include "Panel.h"
|
|
|
|
#include "ScreenManager.h"
|
2015-01-22 01:27:31 +00:00
|
|
|
#include "ProcessList.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
typedef struct AvailableMetersPanel_ {
|
|
|
|
Panel super;
|
2015-01-22 01:27:31 +00:00
|
|
|
ScreenManager* scr;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
Settings* settings;
|
2015-01-22 01:27:31 +00:00
|
|
|
Header* header;
|
2006-05-30 14:00:18 +00:00
|
|
|
Panel* leftPanel;
|
|
|
|
Panel* rightPanel;
|
2006-05-30 13:47:28 +00:00
|
|
|
} AvailableMetersPanel;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
}*/
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void AvailableMetersPanel_delete(Object* object) {
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel* super = (Panel*) object;
|
|
|
|
AvailableMetersPanel* this = (AvailableMetersPanel*) object;
|
|
|
|
Panel_done(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
static inline void AvailableMetersPanel_addMeter(Header* header, Panel* panel, MeterClass* type, int param, int column) {
|
|
|
|
Meter* meter = (Meter*) Header_addMeterByClass(header, type, param, column);
|
2015-03-17 02:01:21 +00:00
|
|
|
Panel_add(panel, (Object*) Meter_toListItem(meter, false));
|
2015-02-03 21:32:07 +00:00
|
|
|
Panel_setSelected(panel, Panel_size(panel) - 1);
|
|
|
|
((MetersPanel*)panel)->moving = true;
|
|
|
|
((ListItem*)Panel_getSelected(panel))->moving = true;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static HandlerResult AvailableMetersPanel_eventHandler(Panel* super, int ch) {
|
2006-05-30 13:47:28 +00:00
|
|
|
AvailableMetersPanel* this = (AvailableMetersPanel*) super;
|
2015-01-22 01:27:31 +00:00
|
|
|
Header* header = this->header;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
ListItem* selected = (ListItem*) Panel_getSelected(super);
|
2006-04-10 20:40:38 +00:00
|
|
|
int param = selected->key & 0xff;
|
|
|
|
int type = selected->key >> 16;
|
2006-03-04 18:16:49 +00:00
|
|
|
HandlerResult result = IGNORED;
|
2015-02-03 21:32:07 +00:00
|
|
|
bool update = false;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
switch(ch) {
|
|
|
|
case KEY_F(5):
|
|
|
|
case 'l':
|
|
|
|
case 'L':
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
AvailableMetersPanel_addMeter(header, this->leftPanel, Platform_meterTypes[type], param, 0);
|
2006-03-04 18:16:49 +00:00
|
|
|
result = HANDLED;
|
2015-02-03 21:32:07 +00:00
|
|
|
update = true;
|
2006-03-04 18:16:49 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-02-03 21:32:07 +00:00
|
|
|
case 0x0a:
|
|
|
|
case 0x0d:
|
|
|
|
case KEY_ENTER:
|
2006-03-04 18:16:49 +00:00
|
|
|
case KEY_F(6):
|
|
|
|
case 'r':
|
|
|
|
case 'R':
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
AvailableMetersPanel_addMeter(header, this->rightPanel, Platform_meterTypes[type], param, 1);
|
2015-02-03 21:32:07 +00:00
|
|
|
result = (KEY_LEFT << 16) | SYNTH_KEY;
|
|
|
|
update = true;
|
2006-03-04 18:16:49 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-02-03 21:32:07 +00:00
|
|
|
if (update) {
|
2006-03-04 18:16:49 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
PanelClass AvailableMetersPanel_class = {
|
|
|
|
.super = {
|
|
|
|
.extends = Class(Panel),
|
|
|
|
.delete = AvailableMetersPanel_delete
|
|
|
|
},
|
|
|
|
.eventHandler = AvailableMetersPanel_eventHandler
|
|
|
|
};
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
AvailableMetersPanel* AvailableMetersPanel_new(Settings* settings, Header* header, Panel* leftMeters, Panel* rightMeters, ScreenManager* scr, ProcessList* pl) {
|
2012-12-05 15:12:20 +00:00
|
|
|
AvailableMetersPanel* this = AllocThis(AvailableMetersPanel);
|
2008-03-09 08:58:38 +00:00
|
|
|
Panel* super = (Panel*) this;
|
2012-12-05 15:12:20 +00:00
|
|
|
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
|
2008-03-09 08:58:38 +00:00
|
|
|
|
|
|
|
this->settings = settings;
|
2015-01-22 01:27:31 +00:00
|
|
|
this->header = header;
|
2008-03-09 08:58:38 +00:00
|
|
|
this->leftPanel = leftMeters;
|
|
|
|
this->rightPanel = rightMeters;
|
|
|
|
this->scr = scr;
|
|
|
|
|
|
|
|
Panel_setHeader(super, "Available meters");
|
2014-11-27 21:18:14 +00:00
|
|
|
for (int i = 1; Platform_meterTypes[i]; i++) {
|
|
|
|
MeterClass* type = Platform_meterTypes[i];
|
2012-12-05 15:12:20 +00:00
|
|
|
if (type != &CPUMeter_class) {
|
2015-02-03 21:31:44 +00:00
|
|
|
const char* label = type->description ? type->description : type->uiName;
|
|
|
|
Panel_add(super, (Object*) ListItem_new(label, i << 16));
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
}
|
2012-12-05 15:12:20 +00:00
|
|
|
MeterClass* type = &CPUMeter_class;
|
2015-01-22 01:27:31 +00:00
|
|
|
int cpus = pl->cpuCount;
|
2010-08-24 23:20:38 +00:00
|
|
|
if (cpus > 1) {
|
2008-03-09 08:58:38 +00:00
|
|
|
Panel_add(super, (Object*) ListItem_new("CPU average", 0));
|
2010-08-24 23:20:38 +00:00
|
|
|
for (int i = 1; i <= cpus; i++) {
|
2008-03-09 08:58:38 +00:00
|
|
|
char buffer[50];
|
|
|
|
sprintf(buffer, "%s %d", type->uiName, i);
|
|
|
|
Panel_add(super, (Object*) ListItem_new(buffer, i));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Panel_add(super, (Object*) ListItem_new("CPU", 1));
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|