summaryrefslogtreecommitdiffstats
path: root/Action.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 /Action.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 'Action.c')
-rw-r--r--Action.c61
1 files changed, 48 insertions, 13 deletions
diff --git a/Action.c b/Action.c
index f7fc4a43..e00383c7 100644
--- a/Action.c
+++ b/Action.c
@@ -165,6 +165,17 @@ Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
// ----------------------------------------
+static bool Action_writeableProcess(State* st) {
+ const Settings* settings = st->host->settings;
+ bool readonly = Settings_isReadonly() || settings->ss->dynamic;
+ return !readonly;
+}
+
+static bool Action_readableProcess(State* st) {
+ const Settings* settings = st->host->settings;
+ return !settings->ss->dynamic;
+}
+
static Htop_Reaction actionSetSortColumn(State* st) {
Htop_Reaction reaction = HTOP_OK;
Panel* sortPanel = Panel_new(0, 0, 0, 0, Class(ListItem), true, FunctionBar_newEnterEsc("Sort ", "Cancel "));
@@ -303,7 +314,7 @@ static Htop_Reaction actionIncSearch(State* st) {
}
static Htop_Reaction actionHigherPriority(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
bool changed = changePriority(st->mainPanel, -1);
@@ -311,7 +322,7 @@ static Htop_Reaction actionHigherPriority(State* st) {
}
static Htop_Reaction actionLowerPriority(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
bool changed = changePriority(st->mainPanel, 1);
@@ -345,13 +356,27 @@ static Htop_Reaction actionExpandCollapseOrSortColumn(State* st) {
return st->host->settings->ss->treeView ? actionExpandOrCollapse(st) : actionSetSortColumn(st);
}
+static inline void setActiveScreen(Settings* settings, State* st, unsigned int ssIdx) {
+ assert(settings->ssIndex == ssIdx);
+ Machine* host = st->host;
+
+ settings->ss = settings->screens[ssIdx];
+ if (!settings->ss->table)
+ settings->ss->table = host->processTable;
+ host->activeTable = settings->ss->table;
+
+ // set correct functionBar - readonly if requested, and/or with non-process screens
+ bool readonly = Settings_isReadonly() || (host->activeTable != host->processTable);
+ MainPanel_setFunctionBar(st->mainPanel, readonly);
+}
+
static Htop_Reaction actionNextScreen(State* st) {
Settings* settings = st->host->settings;
settings->ssIndex++;
if (settings->ssIndex == settings->nScreens) {
settings->ssIndex = 0;
}
- settings->ss = settings->screens[settings->ssIndex];
+ setActiveScreen(settings, st, settings->ssIndex);
return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
@@ -362,21 +387,22 @@ static Htop_Reaction actionPrevScreen(State* st) {
} else {
settings->ssIndex--;
}
- settings->ss = settings->screens[settings->ssIndex];
+ setActiveScreen(settings, st, settings->ssIndex);
return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
-Htop_Reaction Action_setScreenTab(Settings* settings, int x) {
+Htop_Reaction Action_setScreenTab(State* st, int x) {
+ Settings* settings = st->host->settings;
int s = 2;
for (unsigned int i = 0; i < settings->nScreens; i++) {
if (x < s) {
return 0;
}
- const char* name = settings->screens[i]->name;
- int len = strlen(name);
+ const char* tab = settings->screens[i]->heading;
+ int len = strlen(tab);
if (x <= s + len + 1) {
settings->ssIndex = i;
- settings->ss = settings->screens[i];
+ setActiveScreen(settings, st, i);
return HTOP_UPDATE_PANELHDR | HTOP_REFRESH | HTOP_REDRAW_BAR;
}
s += len + 3;
@@ -389,7 +415,7 @@ static Htop_Reaction actionQuit(ATTR_UNUSED State* st) {
}
static Htop_Reaction actionSetAffinity(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
Machine* host = st->host;
@@ -426,7 +452,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
#ifdef SCHEDULER_SUPPORT
static Htop_Reaction actionSetSchedPolicy(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_KEEP_FOLLOWING;
static int preSelectedPolicy = SCHEDULINGPANEL_INITSELECTEDPOLICY;
@@ -470,7 +496,7 @@ static Htop_Reaction actionSetSchedPolicy(State* st) {
#endif /* SCHEDULER_SUPPORT */
static Htop_Reaction actionKill(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
static int preSelectedSignal = SIGNALSPANEL_INITSELECTEDSIGNAL;
@@ -521,7 +547,7 @@ static Htop_Reaction actionSetup(State* st) {
}
static Htop_Reaction actionLsof(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
@@ -539,6 +565,9 @@ static Htop_Reaction actionLsof(State* st) {
}
static Htop_Reaction actionShowLocks(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
@@ -554,7 +583,7 @@ static Htop_Reaction actionShowLocks(State* st) {
}
static Htop_Reaction actionStrace(State* st) {
- if (Settings_isReadonly())
+ if (!Action_writeableProcess(st))
return HTOP_OK;
const Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
@@ -805,6 +834,9 @@ static Htop_Reaction actionTagAllChildren(State* st) {
}
static Htop_Reaction actionShowEnvScreen(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;
@@ -820,6 +852,9 @@ static Htop_Reaction actionShowEnvScreen(State* st) {
}
static Htop_Reaction actionShowCommandScreen(State* st) {
+ if (!Action_readableProcess(st))
+ return HTOP_OK;
+
Process* p = (Process*) Panel_getSelected((Panel*)st->mainPanel);
if (!p)
return HTOP_OK;

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