DisplayOptionsPanel.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. htop - DisplayOptionsPanel.c
  3. (C) 2004-2011 Hisham H. Muhammad
  4. Released under the GNU GPLv2+, see the COPYING file
  5. in the source distribution for its full text.
  6. */
  7. #include "config.h" // IWYU pragma: keep
  8. #include "DisplayOptionsPanel.h"
  9. #include <stdbool.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "CRT.h"
  13. #include "FunctionBar.h"
  14. #include "Header.h"
  15. #include "Object.h"
  16. #include "OptionItem.h"
  17. #include "ProvideCurses.h"
  18. #include "ScreensPanel.h"
  19. static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
  20. static const char* const DisplayOptionsDecIncFunctions[] = {" ", " ", " ", " ", " ", " ", "Dec ", "Inc ", " ", "Done ", NULL};
  21. static const char* const DisplayOptionsDecIncKeys[] = {" " , " " , " " , " " , " " , " " , "F7" , "F8" , " " , "F10" , NULL};
  22. static const int DisplayOptionsDecIncEvents[] = {'-', KEY_F(7), '+', KEY_F(8), ERR, KEY_F(10)};
  23. static void DisplayOptionsPanel_delete(Object* object) {
  24. DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
  25. FunctionBar_delete(this->decIncBar);
  26. Panel_done(&this->super);
  27. free(this);
  28. }
  29. static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
  30. DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
  31. HandlerResult result = IGNORED;
  32. OptionItem* selected = (OptionItem*) Panel_getSelected(super);
  33. if (!selected) {
  34. return result;
  35. }
  36. switch (ch) {
  37. case '\n':
  38. case '\r':
  39. case KEY_ENTER:
  40. case KEY_MOUSE:
  41. case KEY_RECLICK:
  42. case ' ':
  43. switch (OptionItem_kind(selected)) {
  44. case OPTION_ITEM_TEXT:
  45. break;
  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. case KEY_F(7):
  58. if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
  59. NumberItem_decrease((NumberItem*)selected);
  60. result = HANDLED;
  61. }
  62. break;
  63. case '+':
  64. case KEY_F(8):
  65. if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
  66. NumberItem_increase((NumberItem*)selected);
  67. result = HANDLED;
  68. }
  69. break;
  70. case KEY_UP:
  71. case KEY_DOWN:
  72. case KEY_NPAGE:
  73. case KEY_PPAGE:
  74. case KEY_HOME:
  75. case KEY_END:
  76. {
  77. OptionItem* previous = selected;
  78. Panel_onKey(super, ch);
  79. selected = (OptionItem*) Panel_getSelected(super);
  80. if (previous != selected) {
  81. result = HANDLED;
  82. }
  83. }
  84. /* fallthrough */
  85. case EVENT_SET_SELECTED:
  86. if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
  87. super->currentBar = this->decIncBar;
  88. } else {
  89. Panel_setDefaultBar(super);
  90. }
  91. break;
  92. }
  93. if (result == HANDLED) {
  94. this->settings->changed = true;
  95. this->settings->lastUpdate++;
  96. CRT_updateDelay();
  97. Header* header = this->scr->header;
  98. Header_calculateHeight(header);
  99. Header_reinit(header);
  100. Header_updateData(header);
  101. Header_draw(header);
  102. ScreenManager_resize(this->scr);
  103. }
  104. return result;
  105. }
  106. const PanelClass DisplayOptionsPanel_class = {
  107. .super = {
  108. .extends = Class(Panel),
  109. .delete = DisplayOptionsPanel_delete
  110. },
  111. .eventHandler = DisplayOptionsPanel_eventHandler
  112. };
  113. DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
  114. DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
  115. Panel* super = &this->super;
  116. FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
  117. Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
  118. this->decIncBar = FunctionBar_new(DisplayOptionsDecIncFunctions, DisplayOptionsDecIncKeys, DisplayOptionsDecIncEvents);
  119. this->settings = settings;
  120. this->scr = scr;
  121. Panel_setHeader(super, "Display options");
  122. #define TABMSG "For current screen tab: \0"
  123. char tabheader[sizeof(TABMSG) + SCREEN_NAME_LEN + 1] = TABMSG;
  124. strncat(tabheader, settings->ss->heading, SCREEN_NAME_LEN);
  125. Panel_add(super, (Object*) TextItem_new(tabheader));
  126. #undef TABMSG
  127. Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->ss->treeView)));
  128. Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->ss->treeViewAlwaysByPID)));
  129. Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is collapsed by default", &(settings->ss->allBranchesCollapsed)));
  130. Panel_add(super, (Object*) TextItem_new("Global options:"));
  131. Panel_add(super, (Object*) CheckItem_newByRef("Show tabs for screens", &(settings->screenTabs)));
  132. Panel_add(super, (Object*) CheckItem_newByRef("Shadow other users' processes", &(settings->shadowOtherUsers)));
  133. Panel_add(super, (Object*) CheckItem_newByRef("Hide kernel threads", &(settings->hideKernelThreads)));
  134. Panel_add(super, (Object*) CheckItem_newByRef("Hide userland process threads", &(settings->hideUserlandThreads)));
  135. Panel_add(super, (Object*) CheckItem_newByRef("Hide processes running in containers", &(settings->hideRunningInContainer)));
  136. Panel_add(super, (Object*) CheckItem_newByRef("Display threads in a different color", &(settings->highlightThreads)));
  137. Panel_add(super, (Object*) CheckItem_newByRef("Show custom thread names", &(settings->showThreadNames)));
  138. Panel_add(super, (Object*) CheckItem_newByRef("Show program path", &(settings->showProgramPath)));
  139. Panel_add(super, (Object*) CheckItem_newByRef("Highlight program \"basename\"", &(settings->highlightBaseName)));
  140. Panel_add(super, (Object*) CheckItem_newByRef("Highlight out-dated/removed programs (red) / libraries (yellow)", &(settings->highlightDeletedExe)));
  141. Panel_add(super, (Object*) CheckItem_newByRef("Shadow distribution path prefixes", &(settings->shadowDistPathPrefix)));
  142. Panel_add(super, (Object*) CheckItem_newByRef("Merge exe, comm and cmdline in Command", &(settings->showMergedCommand)));
  143. Panel_add(super, (Object*) CheckItem_newByRef("- Try to find comm in cmdline (when Command is merged)", &(settings->findCommInCmdline)));
  144. Panel_add(super, (Object*) CheckItem_newByRef("- Try to strip exe from cmdline (when Command is merged)", &(settings->stripExeFromCmdline)));
  145. Panel_add(super, (Object*) CheckItem_newByRef("Highlight large numbers in memory counters", &(settings->highlightMegabytes)));
  146. Panel_add(super, (Object*) CheckItem_newByRef("Leave a margin around header", &(settings->headerMargin)));
  147. Panel_add(super, (Object*) CheckItem_newByRef("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)", &(settings->detailedCPUTime)));
  148. Panel_add(super, (Object*) CheckItem_newByRef("Count CPUs from 1 instead of 0", &(settings->countCPUsFromOne)));
  149. Panel_add(super, (Object*) CheckItem_newByRef("Update process names on every refresh", &(settings->updateProcessNames)));
  150. Panel_add(super, (Object*) CheckItem_newByRef("Add guest time in CPU meter percentage", &(settings->accountGuestInCPUMeter)));
  151. Panel_add(super, (Object*) CheckItem_newByRef("Also show CPU percentage numerically", &(settings->showCPUUsage)));
  152. Panel_add(super, (Object*) CheckItem_newByRef("Also show CPU frequency", &(settings->showCPUFrequency)));
  153. #ifdef BUILD_WITH_CPU_TEMP
  154. Panel_add(super, (Object*) CheckItem_newByRef(
  155. #if defined(HTOP_LINUX)
  156. "Also show CPU temperature (requires libsensors)",
  157. #elif defined(HTOP_FREEBSD)
  158. "Also show CPU temperature",
  159. #else
  160. #error Unknown temperature implementation!
  161. #endif
  162. &(settings->showCPUTemperature)));
  163. Panel_add(super, (Object*) CheckItem_newByRef("- Show temperature in degree Fahrenheit instead of Celsius", &(settings->degreeFahrenheit)));
  164. #endif
  165. Panel_add(super, (Object*) CheckItem_newByRef("Show cached memory in graph and bar modes", &(settings->showCachedMemory)));
  166. #ifdef HAVE_GETMOUSE
  167. Panel_add(super, (Object*) CheckItem_newByRef("Enable the mouse", &(settings->enableMouse)));
  168. #endif
  169. Panel_add(super, (Object*) NumberItem_newByRef("Update interval (in seconds)", &(settings->delay), -1, 1, 255));
  170. Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges)));
  171. Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24 * 60 * 60));
  172. 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));
  173. #ifdef HAVE_LIBHWLOC
  174. Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
  175. #endif
  176. return this;
  177. }