DisplayOptionsPanel.c 3.96 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
2
3
4
5
6
/*
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.
*/
Hisham Muhammad's avatar
Hisham Muhammad committed
7

8
#include "DisplayOptionsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
9
10

#include "CheckItem.h"
11
#include "CRT.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
12

Hisham Muhammad's avatar
Hisham Muhammad committed
13
#include <assert.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
14
15
#include <stdlib.h>
#include <string.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
16
17

/*{
Hisham Muhammad's avatar
Hisham Muhammad committed
18
19
20
#include "Panel.h"
#include "Settings.h"
#include "ScreenManager.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
21

22
23
typedef struct DisplayOptionsPanel_ {
   Panel super;
Hisham Muhammad's avatar
Hisham Muhammad committed
24
25
26

   Settings* settings;
   ScreenManager* scr;
27
} DisplayOptionsPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
28
29
30

}*/

31
32
static const char* DisplayOptionsFunctions[] = {"      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "      ", "Done  ", NULL};

33
static void DisplayOptionsPanel_delete(Object* object) {
34
35
36
   Panel* super = (Panel*) object;
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
37
38
39
   free(this);
}

40
static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
41
   DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
Hisham Muhammad's avatar
Hisham Muhammad committed
42
43
   
   HandlerResult result = IGNORED;
44
   CheckItem* selected = (CheckItem*) Panel_getSelected(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
45
46
47
48
49

   switch(ch) {
   case 0x0a:
   case 0x0d:
   case KEY_ENTER:
50
   case KEY_MOUSE:
51
   case KEY_RECLICK:
Hisham Muhammad's avatar
Hisham Muhammad committed
52
   case ' ':
53
      CheckItem_set(selected, ! (CheckItem_get(selected)) );
Hisham Muhammad's avatar
Hisham Muhammad committed
54
55
56
57
58
      result = HANDLED;
   }

   if (result == HANDLED) {
      this->settings->changed = true;
Hisham Muhammad's avatar
Hisham Muhammad committed
59
60
61
      const Header* header = this->scr->header;
      Header_calculateHeight((Header*) header);
      Header_reinit((Header*) header);
Hisham Muhammad's avatar
Hisham Muhammad committed
62
63
64
65
66
67
      Header_draw(header);
      ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
   }
   return result;
}

68
69
70
71
72
73
74
75
PanelClass DisplayOptionsPanel_class = {
   .super = {
      .extends = Class(Panel),
      .delete = DisplayOptionsPanel_delete
   },
   .eventHandler = DisplayOptionsPanel_eventHandler
};

76
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
77
   DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
78
   Panel* super = (Panel*) this;
79
80
   FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
   Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
81
82
83
84
85

   this->settings = settings;
   this->scr = scr;

   Panel_setHeader(super, "Display options");
Hisham's avatar
Hisham committed
86
87
88
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Tree view"), &(settings->treeView)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Shadow other users' processes"), &(settings->shadowOtherUsers)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide kernel threads"), &(settings->hideKernelThreads)));
Hisham's avatar
Hisham committed
89
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Hide userland process threads"), &(settings->hideUserlandThreads)));
Hisham's avatar
Hisham committed
90
91
92
93
94
95
96
97
98
99
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Display threads in a different color"), &(settings->highlightThreads)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show custom thread names"), &(settings->showThreadNames)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Show program path"), &(settings->showProgramPath)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight program \"basename\""), &(settings->highlightBaseName)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Highlight large numbers in memory counters"), &(settings->highlightMegabytes)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Leave a margin around header"), &(settings->headerMargin)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)"), &(settings->detailedCPUTime)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Count CPUs from 0 instead of 1"), &(settings->countCPUsFromZero)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Update process names on every refresh"), &(settings->updateProcessNames)));
   Panel_add(super, (Object*) CheckItem_newByRef(xStrdup("Add guest time in CPU meter percentage"), &(settings->accountGuestInCPUMeter)));
100
101
   return this;
}