| Hisham Muhammad | 84281bd | 2011-12-26 21:35:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | htop - DisplayOptionsPanel.c |
| 3 | (C) 2004-2011 Hisham H. Muhammad |
| Daniel Lange | 079c2ab | 2020-10-05 09:51:32 +0200 | [diff] [blame] | 4 | Released under the GNU GPLv2, see the COPYING file |
| Hisham Muhammad | 84281bd | 2011-12-26 21:35:57 +0000 | [diff] [blame] | 5 | in the source distribution for its full text. |
| 6 | */ |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 7 | |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 8 | #include "config.h" // IWYU pragma: keep |
| 9 | |
| Hisham Muhammad | c2cdcd0 | 2006-05-30 13:47:28 +0000 | [diff] [blame] | 10 | #include "DisplayOptionsPanel.h" |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 11 | |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 12 | #include <stdbool.h> |
| Hisham Muhammad | 84281bd | 2011-12-26 21:35:57 +0000 | [diff] [blame] | 13 | #include <stdlib.h> |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 14 | |
| Benny Baumann | c6f04a9 | 2020-09-19 20:22:34 +0200 | [diff] [blame] | 15 | #include "CRT.h" |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 16 | #include "FunctionBar.h" |
| 17 | #include "Header.h" |
| 18 | #include "Object.h" |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 19 | #include "OptionItem.h" |
| Benny Baumann | 0f52629 | 2020-09-19 13:55:23 +0200 | [diff] [blame] | 20 | #include "ProvideCurses.h" |
| Benny Baumann | c6f04a9 | 2020-09-19 20:22:34 +0200 | [diff] [blame] | 21 | |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 22 | |
| Richard | d5faf64 | 2017-07-22 21:41:19 -0500 | [diff] [blame] | 23 | static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; |
| Hisham Muhammad | d0c72c3 | 2015-03-23 15:26:56 -0300 | [diff] [blame] | 24 | |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 25 | static void DisplayOptionsPanel_delete(Object* object) { |
| Hisham Muhammad | c2cdcd0 | 2006-05-30 13:47:28 +0000 | [diff] [blame] | 26 | Panel* super = (Panel*) object; |
| 27 | DisplayOptionsPanel* this = (DisplayOptionsPanel*) object; |
| 28 | Panel_done(super); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 29 | free(this); |
| 30 | } |
| 31 | |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 32 | static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { |
| Hisham Muhammad | c2cdcd0 | 2006-05-30 13:47:28 +0000 | [diff] [blame] | 33 | DisplayOptionsPanel* this = (DisplayOptionsPanel*) super; |
| MartinJM | 7858ee6 | 2019-07-12 22:01:29 +0200 | [diff] [blame] | 34 | |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 35 | HandlerResult result = IGNORED; |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 36 | OptionItem* selected = (OptionItem*) Panel_getSelected(super); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 37 | |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 38 | switch (ch) { |
| 39 | case '\n': |
| 40 | case '\r': |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 41 | case KEY_ENTER: |
| Hisham Muhammad | 15ab0ad | 2008-05-07 23:01:45 +0000 | [diff] [blame] | 42 | case KEY_MOUSE: |
| Hisham Muhammad | f6c31ee | 2015-08-27 18:42:35 -0300 | [diff] [blame] | 43 | case KEY_RECLICK: |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 44 | case ' ': |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 45 | 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 Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | if (result == HANDLED) { |
| 71 | this->settings->changed = true; |
| Christian Göttsche | 18b1e9f | 2020-09-23 14:15:51 +0200 | [diff] [blame] | 72 | Header* header = this->scr->header; |
| 73 | Header_calculateHeight(header); |
| 74 | Header_reinit(header); |
| Hisham Muhammad | d6231ba | 2006-03-04 18:16:49 +0000 | [diff] [blame] | 75 | 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öttsche | ba282cf | 2020-10-05 13:19:50 +0200 | [diff] [blame] | 81 | const PanelClass DisplayOptionsPanel_class = { |
| Hisham Muhammad | 00b324b | 2012-12-05 15:12:20 +0000 | [diff] [blame] | 82 | .super = { |
| 83 | .extends = Class(Panel), |
| 84 | .delete = DisplayOptionsPanel_delete |
| 85 | }, |
| 86 | .eventHandler = DisplayOptionsPanel_eventHandler |
| 87 | }; |
| 88 | |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 89 | DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) { |
| Hisham Muhammad | 00b324b | 2012-12-05 15:12:20 +0000 | [diff] [blame] | 90 | DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel); |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 91 | Panel* super = (Panel*) this; |
| Hisham Muhammad | d0c72c3 | 2015-03-23 15:26:56 -0300 | [diff] [blame] | 92 | FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL); |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 93 | Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar); |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 94 | |
| 95 | this->settings = settings; |
| 96 | this->scr = scr; |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 97 | |
| 98 | Panel_setHeader(super, "Display options"); |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 99 | Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->treeView))); |
| Hisham Muhammad | e8c6994 | 2020-12-17 19:08:56 -0300 | [diff] [blame] | 100 | Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->treeViewAlwaysByPID))); |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 101 | 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öttsche | b76eaf1 | 2020-12-01 13:59:19 +0100 | [diff] [blame] | 119 | #ifdef HAVE_SENSORS_SENSORS_H |
| 120 | Panel_add(super, (Object*) CheckItem_newByRef("Also show CPU temperature (requires libsensors)", &(settings->showCPUTemperature))); |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 121 | Panel_add(super, (Object*) CheckItem_newByRef("- Show temperature in degree Fahrenheit instead of Celsius", &(settings->degreeFahrenheit))); |
| Christian Göttsche | 1b225cd | 2020-09-10 19:56:33 +0200 | [diff] [blame] | 122 | #endif |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 123 | 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 Lange | b3500ac | 2021-01-11 13:50:34 +0100 | [diff] [blame] | 127 | 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 Scott | 728b04b | 2020-08-26 10:15:00 +1000 | [diff] [blame] | 128 | #ifdef HAVE_LIBHWLOC |
| Christian Göttsche | 267014c | 2020-11-21 21:40:08 +0100 | [diff] [blame] | 129 | Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity))); |
| Nathan Scott | 728b04b | 2020-08-26 10:15:00 +1000 | [diff] [blame] | 130 | #endif |
| Hisham Muhammad | da23c8c | 2008-03-09 08:58:38 +0000 | [diff] [blame] | 131 | return this; |
| 132 | } |