htop/DisplayOptionsPanel.c

100 lines
3.9 KiB
C
Raw Normal View History

2011-12-26 21:35:57 +00:00
/*
htop - DisplayOptionsPanel.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 "DisplayOptionsPanel.h"
2006-03-04 18:16:49 +00:00
#include "CheckItem.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>
#include <string.h>
2006-03-04 18:16:49 +00:00
/*{
2011-12-26 21:35:57 +00:00
#include "Panel.h"
#include "Settings.h"
#include "ScreenManager.h"
2006-03-04 18:16:49 +00:00
2006-05-30 13:47:28 +00:00
typedef struct DisplayOptionsPanel_ {
Panel super;
2006-03-04 18:16:49 +00:00
Settings* settings;
ScreenManager* scr;
2006-05-30 13:47:28 +00:00
} DisplayOptionsPanel;
2006-03-04 18:16:49 +00:00
}*/
2015-03-23 18:26:56 +00:00
static const char* DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
static void DisplayOptionsPanel_delete(Object* object) {
2006-05-30 13:47:28 +00:00
Panel* super = (Panel*) object;
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
Panel_done(super);
2006-03-04 18:16:49 +00:00
free(this);
}
static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
2006-05-30 13:47:28 +00:00
DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
2006-03-04 18:16:49 +00:00
HandlerResult result = IGNORED;
2006-05-30 13:47:28 +00:00
CheckItem* selected = (CheckItem*) Panel_getSelected(super);
2006-03-04 18:16:49 +00:00
switch(ch) {
case 0x0a:
case 0x0d:
case KEY_ENTER:
2008-05-07 23:01:45 +00:00
case KEY_MOUSE:
2006-03-04 18:16:49 +00:00
case ' ':
CheckItem_set(selected, ! (CheckItem_get(selected)) );
2006-03-04 18:16:49 +00:00
result = HANDLED;
}
if (result == HANDLED) {
this->settings->changed = true;
const Header* header = this->scr->header;
Header_calculateHeight((Header*) header);
Header_reinit((Header*) header);
2006-03-04 18:16:49 +00:00
Header_draw(header);
ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
}
return result;
}
PanelClass DisplayOptionsPanel_class = {
.super = {
.extends = Class(Panel),
.delete = DisplayOptionsPanel_delete
},
.eventHandler = DisplayOptionsPanel_eventHandler
};
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
Panel* super = (Panel*) this;
2015-03-23 18:26:56 +00:00
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
this->settings = settings;
this->scr = scr;
Panel_setHeader(super, "Display options");
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Tree view"), &(settings->treeView)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Shadow other users' processes"), &(settings->shadowOtherUsers)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Hide kernel threads"), &(settings->hideKernelThreads)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Hide userland threads"), &(settings->hideUserlandThreads)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Display threads in a different color"), &(settings->highlightThreads)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Show custom thread names"), &(settings->showThreadNames)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Show program path"), &(settings->showProgramPath)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Highlight program \"basename\""), &(settings->highlightBaseName)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Leave a margin around header"), &(settings->headerMargin)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Update process names on every refresh"), &(settings->updateProcessNames)));
Panel_add(super, (Object*) CheckItem_newByRef(strdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter)));
return this;
}