summaryrefslogtreecommitdiffstats
path: root/ScreensPanel.c
diff options
context:
space:
mode:
authorSohaib Mohamed <sohaib.amhmd@gmail.com>2023-08-22 16:46:59 +1000
committerNathan Scott <nathans@redhat.com>2023-08-30 13:11:57 +1000
commit53bdcab942298e0e452d62237bc18e3a4cd551cf (patch)
treee7a62910b9f4a1a58560a4ded2e6f7e83d0b631e /ScreensPanel.c
parent0f751e991d399769fb8d7800f7c4bccec2ca7f60 (diff)
Support dynamic screens with 'top-most' entities beyond processes
This implements our concept of 'dynamic screens' in htop, with a first use-case of pcp-htop displaying things like top-filesystem and top-cgroups under new screen tabs. However the idea is more general than use in pcp-htop and we've paved the way here for us to collectively build mroe general tabular screens in core htop, as well. From the pcp-htop side of things, dynamic screens are configured using text-based configuration files that define the mapping for PCP metrics to columns (and metric instances to rows). Metrics are defined either directly (via metric names) or indirectly via PCP derived metric specifications. Value scaling and the units displayed is automatic based on PCP metric units and data types. This commit represents a collaborative effort of several months, primarily between myself, Nathan and BenBE. Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com> Signed-off-by: Nathan Scott <nathans@redhat.com>
Diffstat (limited to 'ScreensPanel.c')
-rw-r--r--ScreensPanel.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/ScreensPanel.c b/ScreensPanel.c
index cb664ac4..d0038809 100644
--- a/ScreensPanel.c
+++ b/ScreensPanel.c
@@ -1,7 +1,7 @@
/*
htop - ScreensPanel.c
(C) 2004-2011 Hisham H. Muhammad
-(C) 2020-2022 htop dev team
+(C) 2020-2023 htop dev team
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/
@@ -12,6 +12,7 @@ in the source distribution for its full text.
#include <ctype.h>
#include <string.h>
+#include "AvailableColumnsPanel.h"
#include "CRT.h"
#include "FunctionBar.h"
#include "Hashtable.h"
@@ -43,6 +44,7 @@ ScreenListItem* ScreenListItem_new(const char* value, ScreenSettings* ss) {
}
static const char* const ScreensFunctions[] = {" ", "Rename", " ", " ", "New ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
+static const char* const DynamicFunctions[] = {" ", "Rename", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
static void ScreensPanel_delete(Object* object) {
Panel* super = (Panel*) object;
@@ -55,11 +57,6 @@ static void ScreensPanel_delete(Object* object) {
item->ss = NULL;
}
- /* during renaming the ListItem's value points to our static buffer */
- if (this->renamingItem)
- this->renamingItem->value = this->saved;
-
- Panel_done(super);
free(this);
}
@@ -212,6 +209,8 @@ static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
case KEY_F(5):
case KEY_CTRL('N'):
{
+ if (this->settings->dynamicScreens)
+ break;
addNewScreen(super);
startRenaming(super);
shouldRebuildArray = true;
@@ -272,7 +271,9 @@ static HandlerResult ScreensPanel_eventHandlerNormal(Panel* super, int ch) {
}
ScreenListItem* newFocus = (ScreenListItem*) Panel_getSelected(super);
if (newFocus && oldFocus != newFocus) {
- ColumnsPanel_fill(this->columns, newFocus->ss, this->settings->dynamicColumns);
+ Hashtable* dynamicColumns = this->settings->dynamicColumns;
+ ColumnsPanel_fill(this->columns, newFocus->ss, dynamicColumns);
+ AvailableColumnsPanel_fill(this->availableColumns, newFocus->ss->dynamic, dynamicColumns);
result = HANDLED;
}
if (shouldRebuildArray)
@@ -304,11 +305,12 @@ ScreensPanel* ScreensPanel_new(Settings* settings) {
ScreensPanel* this = AllocThis(ScreensPanel);
Panel* super = (Panel*) this;
Hashtable* columns = settings->dynamicColumns;
- FunctionBar* fuBar = FunctionBar_new(ScreensFunctions, NULL, NULL);
+ FunctionBar* fuBar = FunctionBar_new(settings->dynamicScreens ? DynamicFunctions : ScreensFunctions, NULL, NULL);
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
this->settings = settings;
this->columns = ColumnsPanel_new(settings->screens[0], columns, &(settings->changed));
+ this->availableColumns = AvailableColumnsPanel_new((Panel*) this->columns, columns);
this->moving = false;
this->renamingItem = NULL;
super->cursorOn = false;
@@ -317,7 +319,7 @@ ScreensPanel* ScreensPanel_new(Settings* settings) {
for (unsigned int i = 0; i < settings->nScreens; i++) {
ScreenSettings* ss = settings->screens[i];
- char* name = ss->name;
+ char* name = ss->heading;
Panel_add(super, (Object*) ScreenListItem_new(name, ss));
}
return this;
@@ -332,9 +334,8 @@ void ScreensPanel_update(Panel* super) {
for (int i = 0; i < size; i++) {
ScreenListItem* item = (ScreenListItem*) Panel_get(super, i);
ScreenSettings* ss = item->ss;
- free(ss->name);
+ free_and_xStrdup(&ss->heading, ((ListItem*) item)->value);
this->settings->screens[i] = ss;
- ss->name = xStrdup(((ListItem*) item)->value);
}
this->settings->screens[size] = NULL;
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy