DisplayOptionsPanel.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 void DisplayOptionsPanel_delete(Object* object) {
  21. Panel* super = (Panel*) object;
  22. DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
  23. Panel_done(super);
  24. free(this);
  25. }
  26. static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
  27. DisplayOptionsPanel* this = (DisplayOptionsPanel*) super;
  28. HandlerResult result = IGNORED;
  29. OptionItem* selected = (OptionItem*) Panel_getSelected(super);
  30. switch (ch) {
  31. case '\n':
  32. case '\r':
  33. case KEY_ENTER:
  34. case KEY_MOUSE:
  35. case KEY_RECLICK:
  36. case ' ':
  37. switch (OptionItem_kind(selected)) {
  38. case OPTION_ITEM_TEXT:
  39. break;
  40. case OPTION_ITEM_CHECK:
  41. CheckItem_toggle((CheckItem*)selected);
  42. result = HANDLED;
  43. break;
  44. case OPTION_ITEM_NUMBER:
  45. NumberItem_toggle((NumberItem*)selected);
  46. result = HANDLED;
  47. break;
  48. }
  49. break;
  50. case '-':
  51. if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
  52. NumberItem_decrease((NumberItem*)selected);
  53. result = HANDLED;
  54. }
  55. break;
  56. case '+':
  57. if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
  58. NumberItem_increase((NumberItem*)selected);
  59. result = HANDLED;
  60. }
  61. break;
  62. }
  63. if (result == HANDLED) {
  64. this->settings->changed = true;
  65. this->settings->lastUpdate++;
  66. CRT_updateDelay();
  67. Header* header = this->scr->header;
  68. Header_calculateHeight(header);
  69. Header_reinit(header);
  70. Header_updateData(header);
  71. Header_draw(header);
  72. ScreenManager_resize(this->scr);
  73. }
  74. return result;
  75. }
  76. const PanelClass DisplayOptionsPanel_class = {
  77. .super = {
  78. .extends = Class(Panel),
  79. .delete = DisplayOptionsPanel_delete
  80. },
  81. .eventHandler = DisplayOptionsPanel_eventHandler
  82. };
  83. DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
  84. DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
  85. Panel* super = (Panel*) this;
  86. FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
  87. Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
  88. this->settings = settings;
  89. this->scr = scr;
  90. Panel_setHeader(super, "Display options");
  91. #define TABMSG "For current screen tab: \0"
  92. char tabheader[sizeof(TABMSG) + SCREEN_NAME_LEN + 1] = TABMSG;
  93. strncat(tabheader, settings->ss->heading, SCREEN_NAME_LEN);
  94. Panel_add(super, (Object*) TextItem_new(tabheader));
  95. #undef TABMSG
  96. Panel_add(super, (Object*) CheckItem_newByRef("Tree view", &(settings->ss->treeView)));
  97. Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is always sorted by PID (htop 2 behavior)", &(settings->ss->treeViewAlwaysByPID)));
  98. Panel_add(super, (Object*) CheckItem_newByRef("- Tree view is collapsed by default", &(settings->ss->allBranchesCollapsed)));
  99. Panel_add(super, (Object*) TextItem_new("Global options:"));
  100. Panel_add(super, (Object*) CheckItem_newByRef("Show tabs for screens", &(settings->screenTabs)));
  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("Hide processes running in containers", &(settings->hideRunningInContainer)));
  105. Panel_add(super, (Object*) CheckItem_newByRef("Display threads in a different color", &(settings->highlightThreads)));
  106. Panel_add(super, (Object*) CheckItem_newByRef("Show custom thread names", &(settings->showThreadNames)));
  107. Panel_add(super, (Object*) CheckItem_newByRef("Show program path", &(settings->showProgramPath)));
  108. Panel_add(super, (Object*) CheckItem_newByRef("Highlight program \"basename\"", &(settings->highlightBaseName)));
  109. Panel_add(super, (Object*) CheckItem_newByRef("Highlight out-dated/removed programs (red) / libraries (yellow)", &(settings->highlightDeletedExe)));
  110. Panel_add(super, (Object*) CheckItem_newByRef("Shadow distribution path prefixes", &(settings->shadowDistPathPrefix)));
  111. Panel_add(super, (Object*) CheckItem_newByRef("Merge exe, comm and cmdline in Command", &(settings->showMergedCommand)));
  112. Panel_add(super, (Object*) CheckItem_newByRef("- Try to find comm in cmdline (when Command is merged)", &(settings->findCommInCmdline)));
  113. Panel_add(super, (Object*) CheckItem_newByRef("- Try to strip exe from cmdline (when Command is merged)", &(settings->stripExeFromCmdline)));
  114. Panel_add(super, (Object*) CheckItem_newByRef("Highlight large numbers in memory counters", &(settings->highlightMegabytes)));
  115. Panel_add(super, (Object*) CheckItem_newByRef("Leave a margin around header", &(settings->headerMargin)));
  116. Panel_add(super, (Object*) CheckItem_newByRef("Detailed CPU time (System/IO-Wait/Hard-IRQ/Soft-IRQ/Steal/Guest)", &(settings->detailedCPUTime)));
  117. Panel_add(super, (Object*) CheckItem_newByRef("Count CPUs from 1 instead of 0", &(settings->countCPUsFromOne)));
  118. Panel_add(super, (Object*) CheckItem_newByRef("Update process names on every refresh", &(settings->updateProcessNames)));
  119. Panel_add(super, (Object*) CheckItem_newByRef("Add guest time in CPU meter percentage", &(settings->accountGuestInCPUMeter)));
  120. Panel_add(super, (Object*) CheckItem_newByRef("Also show CPU percentage numerically", &(settings->showCPUUsage)));
  121. Panel_add(super, (Object*) CheckItem_newByRef("Also show CPU frequency", &(settings->showCPUFrequency)));
  122. #ifdef BUILD_WITH_CPU_TEMP
  123. Panel_add(super, (Object*) CheckItem_newByRef(
  124. #if defined(HTOP_LINUX)
  125. "Also show CPU temperature (requires libsensors)",
  126. #elif defined(HTOP_FREEBSD)
  127. "Also show CPU temperature",
  128. #else
  129. #error Unknown temperature implementation!
  130. #endif
  131. &(settings->showCPUTemperature)));
  132. Panel_add(super, (Object*) CheckItem_newByRef("- Show temperature in degree Fahrenheit instead of Celsius", &(settings->degreeFahrenheit)));
  133. #endif
  134. #ifdef HAVE_GETMOUSE
  135. Panel_add(super, (Object*) CheckItem_newByRef("Enable the mouse", &(settings->enableMouse)));
  136. #endif
  137. Panel_add(super, (Object*) NumberItem_newByRef("Update interval (in seconds)", &(settings->delay), -1, 1, 255));
  138. Panel_add(super, (Object*) CheckItem_newByRef("Highlight new and old processes", &(settings->highlightChanges)));
  139. Panel_add(super, (Object*) NumberItem_newByRef("- Highlight time (in seconds)", &(settings->highlightDelaySecs), 0, 1, 24 * 60 * 60));
  140. 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));
  141. #ifdef HAVE_LIBHWLOC
  142. Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
  143. #endif
  144. return this;
  145. }