2011-12-26 21:35:57 +00:00
|
|
|
/*
|
|
|
|
htop - CategoriesPanel.c
|
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2021-09-22 09:33:00 +00:00
|
|
|
Released under the GNU GPLv2+, see the COPYING file
|
2011-12-26 21:35:57 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2006-05-30 13:47:28 +00:00
|
|
|
#include "CategoriesPanel.h"
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2020-09-19 11:55:23 +00:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "AvailableColumnsPanel.h"
|
2006-05-30 13:47:28 +00:00
|
|
|
#include "AvailableMetersPanel.h"
|
|
|
|
#include "ColorsPanel.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "DisplayOptionsPanel.h"
|
|
|
|
#include "FunctionBar.h"
|
2020-12-25 15:42:35 +00:00
|
|
|
#include "Header.h"
|
2021-08-24 15:27:43 +00:00
|
|
|
#include "HeaderLayout.h"
|
2020-12-25 15:42:35 +00:00
|
|
|
#include "HeaderOptionsPanel.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "ListItem.h"
|
2021-08-24 15:27:43 +00:00
|
|
|
#include "Macros.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "MetersPanel.h"
|
|
|
|
#include "Object.h"
|
|
|
|
#include "ProvideCurses.h"
|
2021-08-31 05:38:52 +00:00
|
|
|
#include "ScreensPanel.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "Vector.h"
|
2021-08-24 15:27:43 +00:00
|
|
|
#include "XUtils.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
|
2017-07-23 02:41:19 +00:00
|
|
|
static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static void CategoriesPanel_delete(Object* object) {
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel* super = (Panel*) object;
|
|
|
|
CategoriesPanel* this = (CategoriesPanel*) object;
|
|
|
|
Panel_done(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2021-08-21 15:42:48 +00:00
|
|
|
static void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
|
2020-12-25 15:42:35 +00:00
|
|
|
size_t columns = HeaderLayout_getColumns(this->scr->header->headerLayout);
|
2021-08-31 05:43:59 +00:00
|
|
|
MetersPanel** meterPanels = xMallocArray(columns, sizeof(MetersPanel*));
|
2020-12-25 15:42:35 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < columns; i++) {
|
|
|
|
char titleBuffer[32];
|
|
|
|
xSnprintf(titleBuffer, sizeof(titleBuffer), "Column %zu", i + 1);
|
|
|
|
meterPanels[i] = MetersPanel_new(this->settings, titleBuffer, this->header->columns[i], this->scr);
|
|
|
|
|
|
|
|
if (i != 0) {
|
|
|
|
meterPanels[i]->leftNeighbor = meterPanels[i - 1];
|
|
|
|
meterPanels[i - 1]->rightNeighbor = meterPanels[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
ScreenManager_add(this->scr, (Panel*) meterPanels[i], 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
Panel* availableMeters = (Panel*) AvailableMetersPanel_new(this->settings, this->header, columns, meterPanels, this->scr, this->pl);
|
2015-03-23 18:26:56 +00:00
|
|
|
ScreenManager_add(this->scr, availableMeters, -1);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CategoriesPanel_makeDisplayOptionsPage(CategoriesPanel* this) {
|
|
|
|
Panel* displayOptions = (Panel*) DisplayOptionsPanel_new(this->settings, this->scr);
|
2015-03-23 18:26:56 +00:00
|
|
|
ScreenManager_add(this->scr, displayOptions, -1);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void CategoriesPanel_makeColorsPage(CategoriesPanel* this) {
|
2021-08-21 15:58:23 +00:00
|
|
|
Panel* colors = (Panel*) ColorsPanel_new(this->settings);
|
2015-03-23 18:26:56 +00:00
|
|
|
ScreenManager_add(this->scr, colors, -1);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
2021-08-31 05:38:52 +00:00
|
|
|
static void CategoriesPanel_makeScreensPage(CategoriesPanel* this) {
|
|
|
|
Panel* screens = (Panel*) ScreensPanel_new(this->settings);
|
|
|
|
Panel* columns = (Panel*) ((ScreensPanel*)screens)->columns;
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
Panel* availableColumns = (Panel*) AvailableColumnsPanel_new(columns, this->settings->dynamicColumns);
|
2021-08-31 05:38:52 +00:00
|
|
|
ScreenManager_add(this->scr, screens, 20);
|
2015-03-23 18:26:56 +00:00
|
|
|
ScreenManager_add(this->scr, columns, 20);
|
|
|
|
ScreenManager_add(this->scr, availableColumns, -1);
|
2008-03-09 08:58:38 +00:00
|
|
|
}
|
|
|
|
|
2020-12-25 15:42:35 +00:00
|
|
|
static void CategoriesPanel_makeHeaderOptionsPage(CategoriesPanel* this) {
|
|
|
|
Panel* colors = (Panel*) HeaderOptionsPanel_new(this->settings, this->scr);
|
|
|
|
ScreenManager_add(this->scr, colors, -1);
|
|
|
|
}
|
|
|
|
|
2021-08-21 15:42:48 +00:00
|
|
|
typedef void (* CategoriesPanel_makePageFunc)(CategoriesPanel* ref);
|
|
|
|
typedef struct CategoriesPanelPage_ {
|
|
|
|
const char* name;
|
|
|
|
CategoriesPanel_makePageFunc ctor;
|
|
|
|
} CategoriesPanelPage;
|
|
|
|
|
|
|
|
static const CategoriesPanelPage categoriesPanelPages[] = {
|
|
|
|
{ .name = "Display options", .ctor = CategoriesPanel_makeDisplayOptionsPage },
|
|
|
|
{ .name = "Header layout", .ctor = CategoriesPanel_makeHeaderOptionsPage },
|
|
|
|
{ .name = "Meters", .ctor = CategoriesPanel_makeMetersPage },
|
2021-08-31 05:38:52 +00:00
|
|
|
{ .name = "Screens", .ctor = CategoriesPanel_makeScreensPage },
|
2021-08-21 15:42:48 +00:00
|
|
|
{ .name = "Colors", .ctor = CategoriesPanel_makeColorsPage },
|
|
|
|
};
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
2006-05-30 13:47:28 +00:00
|
|
|
CategoriesPanel* this = (CategoriesPanel*) super;
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
HandlerResult result = IGNORED;
|
|
|
|
|
2008-03-05 06:54:30 +00:00
|
|
|
int selected = Panel_getSelectedIndex(super);
|
2006-03-04 18:16:49 +00:00
|
|
|
switch (ch) {
|
2015-03-25 02:12:43 +00:00
|
|
|
case EVENT_SET_SELECTED:
|
2008-03-05 06:54:30 +00:00
|
|
|
result = HANDLED;
|
|
|
|
break;
|
2006-03-04 18:16:49 +00:00
|
|
|
case KEY_UP:
|
2016-06-15 15:45:23 +00:00
|
|
|
case KEY_CTRL('P'):
|
2006-03-04 18:16:49 +00:00
|
|
|
case KEY_DOWN:
|
2016-06-15 15:45:23 +00:00
|
|
|
case KEY_CTRL('N'):
|
2006-03-04 18:16:49 +00:00
|
|
|
case KEY_NPAGE:
|
|
|
|
case KEY_PPAGE:
|
|
|
|
case KEY_HOME:
|
|
|
|
case KEY_END: {
|
2008-03-05 06:54:30 +00:00
|
|
|
int previous = selected;
|
2006-05-30 13:47:28 +00:00
|
|
|
Panel_onKey(super, ch);
|
2008-03-05 06:54:30 +00:00
|
|
|
selected = Panel_getSelectedIndex(super);
|
|
|
|
if (previous != selected)
|
|
|
|
result = HANDLED;
|
|
|
|
break;
|
|
|
|
}
|
2012-11-10 00:31:37 +00:00
|
|
|
default:
|
2020-11-21 17:02:39 +00:00
|
|
|
if (0 < ch && ch < 255 && isgraph((unsigned char)ch))
|
2012-11-10 00:31:37 +00:00
|
|
|
result = Panel_selectByTyping(super, ch);
|
|
|
|
if (result == BREAK_LOOP)
|
|
|
|
result = IGNORED;
|
|
|
|
break;
|
2008-03-05 06:54:30 +00:00
|
|
|
}
|
|
|
|
if (result == HANDLED) {
|
|
|
|
int size = ScreenManager_size(this->scr);
|
|
|
|
for (int i = 1; i < size; i++)
|
|
|
|
ScreenManager_remove(this->scr, 1);
|
2020-11-01 00:09:51 +00:00
|
|
|
|
2021-08-21 15:42:48 +00:00
|
|
|
if (selected >= 0 && (size_t)selected < ARRAYSIZE(categoriesPanelPages)) {
|
|
|
|
categoriesPanelPages[selected].ctor(this);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-10-05 11:19:50 +00:00
|
|
|
const PanelClass CategoriesPanel_class = {
|
2012-12-05 15:12:20 +00:00
|
|
|
.super = {
|
|
|
|
.extends = Class(Panel),
|
|
|
|
.delete = CategoriesPanel_delete
|
|
|
|
},
|
|
|
|
.eventHandler = CategoriesPanel_eventHandler
|
|
|
|
};
|
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Settings* settings, Header* header, ProcessList* pl) {
|
2012-12-05 15:12:20 +00:00
|
|
|
CategoriesPanel* this = AllocThis(CategoriesPanel);
|
2008-03-09 08:58:38 +00:00
|
|
|
Panel* super = (Panel*) this;
|
2015-03-23 18:26:56 +00:00
|
|
|
FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL);
|
|
|
|
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
this->scr = scr;
|
2015-01-22 01:27:31 +00:00
|
|
|
this->settings = settings;
|
|
|
|
this->header = header;
|
|
|
|
this->pl = pl;
|
2021-08-31 05:38:52 +00:00
|
|
|
Panel_setHeader(super, "Categories");
|
2021-08-21 15:42:48 +00:00
|
|
|
for (size_t i = 0; i < ARRAYSIZE(categoriesPanelPages); i++)
|
|
|
|
Panel_add(super, (Object*) ListItem_new(categoriesPanelPages[i].name, 0));
|
|
|
|
|
|
|
|
ScreenManager_add(scr, super, 16);
|
|
|
|
categoriesPanelPages[0].ctor(this);
|
2008-03-09 08:58:38 +00:00
|
|
|
return this;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|