blob: 7e02b2310056a0141768e719903fc016c7d51a52 [file] [log] [blame]
Hisham Muhammad84281bd2011-12-26 21:35:57 +00001/*
2htop - DisplayOptionsPanel.c
3(C) 2004-2011 Hisham H. Muhammad
Daniel Lange079c2ab2020-10-05 09:51:32 +02004Released under the GNU GPLv2, see the COPYING file
Hisham Muhammad84281bd2011-12-26 21:35:57 +00005in the source distribution for its full text.
6*/
Hisham Muhammadd6231ba2006-03-04 18:16:49 +00007
Benny Baumann0f526292020-09-19 13:55:23 +02008#include "config.h" // IWYU pragma: keep
9
Hisham Muhammadc2cdcd02006-05-30 13:47:28 +000010#include "DisplayOptionsPanel.h"
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000011
Benny Baumann0f526292020-09-19 13:55:23 +020012#include <stdbool.h>
Hisham Muhammad84281bd2011-12-26 21:35:57 +000013#include <stdlib.h>
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000014
Benny Baumannc6f04a92020-09-19 20:22:34 +020015#include "CRT.h"
Benny Baumann0f526292020-09-19 13:55:23 +020016#include "FunctionBar.h"
17#include "Header.h"
18#include "Object.h"
Christian Göttsche267014c2020-11-21 21:40:08 +010019#include "OptionItem.h"
Benny Baumann0f526292020-09-19 13:55:23 +020020#include "ProvideCurses.h"
Benny Baumannc6f04a92020-09-19 20:22:34 +020021
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000022
Richardd5faf642017-07-22 21:41:19 -050023static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
Hisham Muhammadd0c72c32015-03-23 15:26:56 -030024
Hisham Muhammadda23c8c2008-03-09 08:58:38 +000025static void DisplayOptionsPanel_delete(Object* object) {
Hisham Muhammadc2cdcd02006-05-30 13:47:28 +000026 Panel* super = (Panel*) object;
27 DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
28 Panel_done(super);
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000029 free(this);
30}
31
Hisham Muhammadda23c8c2008-03-09 08:58:38 +000032static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
Hisham Muhammadc2cdcd02006-05-30 13:47:28 +000033 DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
MartinJM7858ee62019-07-12 22:01:29 +020034
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000035 HandlerResult result = IGNORED;
Christian Göttsche267014c2020-11-21 21:40:08 +010036 OptionItem* selected = (OptionItem*) Panel_getSelected(super);
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000037
Christian Göttsche267014c2020-11-21 21:40:08 +010038 switch (ch) {
39 case '\n':
40 case '\r':
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000041 case KEY_ENTER:
Hisham Muhammad15ab0ad2008-05-07 23:01:45 +000042 case KEY_MOUSE:
Hisham Muhammadf6c31ee2015-08-27 18:42:35 -030043 case KEY_RECLICK:
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000044 case ' ':
Christian Göttsche267014c2020-11-21 21:40:08 +010045 switch (OptionItem_kind(selected)) {
46 case OPTION_ITEM_CHECK:
47 CheckItem_toggle((CheckItem*)selected);
48 result = HANDLED;
49 break;
50 case OPTION_ITEM_NUMBER:
51 NumberItem_toggle((NumberItem*)selected);
52 result = HANDLED;
53 break;
54 }
55 break;
56 case '-':
57 if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
58 NumberItem_decrease((NumberItem*)selected);
59 result = HANDLED;
60 }
61 break;
62 case '+':
63 if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
64 NumberItem_increase((NumberItem*)selected);
65 result = HANDLED;
66 }
67 break;
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000068 }
69
70 if (result == HANDLED) {
71 this->settings->changed = true;
Christian Göttsche18b1e9f2020-09-23 14:15:51 +020072 Header* header = this->scr->header;
73 Header_calculateHeight(header);
74 Header_reinit(header);
Hisham Muhammadd6231ba2006-03-04 18:16:49 +000075 Header_draw(header);
76 ScreenManager_resize(this->scr, this->scr->x1, header->height, this->scr->x2, this->scr->y2);
77 }
78 return result;
79}
80
Christian Göttscheba282cf2020-10-05 13:19:50 +020081const PanelClass DisplayOptionsPanel_class = {
Hisham Muhammad00b324b2012-12-05 15:12:20 +000082 .super = {
83 .extends = Class(Panel),
84 .delete = DisplayOptionsPanel_delete
85 },
86 .eventHandler = DisplayOptionsPanel_eventHandler
87};
88
Hisham Muhammadda23c8c2008-03-09 08:58:38 +000089DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
Hisham Muhammad00b324b2012-12-05 15:12:20 +000090 DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
Hisham Muhammadda23c8c2008-03-09 08:58:38 +000091 Panel* super = (Panel*) this;
Hisham Muhammadd0c72c32015-03-23 15:26:56 -030092 FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
Christian Göttsche267014c2020-11-21 21:40:08 +010093 Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
Hisham Muhammadda23c8c2008-03-09 08:58:38 +000094
95 this->settings = settings;
96 this->scr = scr;
Hisham Muhammadda23c8c2008-03-09 08:58:38 +000097
98 Panel_setHeader(super, "Display options");
Christian Göttsche267014c2020-11-21 21:40:08 +010099 Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->treeView)));
Hisham Muhammade8c69942020-12-17 19:08:56 -0300100 Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->treeViewAlwaysByPID)));
Christian Göttsche267014c2020-11-21 21:40:08 +0100101 Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers)));
102 Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads)));
103 Panel_add(super, (Object*) CheckItem_newByRef("Hide userland process threads", &(settings->hideUserlandThreads)));
104 Panel_add(super, (Object*) CheckItem_newByRef("Display threads in a different color", &(settings->highlightThreads)));
105 Panel_add(super, (Object*) CheckItem_newByRef("Show custom thread names", &(settings->showThreadNames)));
106 Panel_add(super, (Object*) CheckItem_newByRef("Show program path", &(settings->showProgramPath)));
107 Panel_add(super, (Object*) CheckItem_newByRef("Highlight program \"basename\"", &(settings->highlightBaseName)));
108 Panel_add(super, (Object*) CheckItem_newByRef("Merge exe, comm and cmdline in Command", &(settings->showMergedCommand)));
109 Panel_add(super, (Object*) CheckItem_newByRef("- Try to find comm in cmdline (when Command is merged)", &(settings->findCommInCmdline)));
110 Panel_add(super, (Object*) CheckItem_newByRef("- Try to strip exe from cmdline (when Command is merged)", &(settings->stripExeFromCmdline)));
111 Panel_add(super, (Object*) CheckItem_newByRef("Highlight large numbers in memory counters", &(settings->highlightMegabytes)));
112 Panel_add(super, (Object*) CheckItem_newByRef("Leave a margin around header", &(settings->headerMargin)));
113 Panel_add(super, (Object*) CheckItem_newByRef("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)", &(settings->detailedCPUTime)));
114 Panel_add(super, (Object*) CheckItem_newByRef("Count CPUs from 1 instead of 0", &(settings->countCPUsFromOne)));
115 Panel_add(super, (Object*) CheckItem_newByRef("Update process names on every refresh", &(settings->updateProcessNames)));
116 Panel_add(super, (Object*) CheckItem_newByRef("Add guest time in CPU meter percentage", &(settings->accountGuestInCPUMeter)));
117 Panel_add(super, (Object*) CheckItem_newByRef("Also show CPU percentage numerically", &(settings->showCPUUsage)));
118 Panel_add(super, (Object*) CheckItem_newByRef("Also show CPU frequency", &(settings->showCPUFrequency)));
Christian Göttscheb76eaf12020-12-01 13:59:19 +0100119 #ifdef HAVE_SENSORS_SENSORS_H
120 Panel_add(super, (Object*) CheckItem_newByRef("Also show CPU temperature (requires libsensors)", &(settings->showCPUTemperature)));
Christian Göttsche267014c2020-11-21 21:40:08 +0100121 Panel_add(super, (Object*) CheckItem_newByRef("- Show temperature in degree Fahrenheit instead of Celsius", &(settings->degreeFahrenheit)));
Christian Göttsche1b225cd2020-09-10 19:56:33 +0200122 #endif
Christian Göttsche267014c2020-11-21 21:40:08 +0100123 Panel_add(super, (Object*) CheckItem_newByRef("Enable the mouse", &(settings->enableMouse)));
124 Panel_add(super, (Object*) NumberItem_newByRef("Update interval (in seconds)", &(settings->delay), -1, 1, 255));
125 Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges)));
126 Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24*60*60));
Daniel Langeb3500ac2021-01-11 13:50:34 +0100127 Panel_add(super, (Object*) NumberItem_newByRef("Hide main function bar (0 - off, 1 - on ESC until next input, 2 - permanently)", &(settings->hideFunctionBar), 0, 0, 2));
Nathan Scott728b04b2020-08-26 10:15:00 +1000128 #ifdef HAVE_LIBHWLOC
Christian Göttsche267014c2020-11-21 21:40:08 +0100129 Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
Nathan Scott728b04b2020-08-26 10:15:00 +1000130 #endif
Hisham Muhammadda23c8c2008-03-09 08:58:38 +0000131 return this;
132}