Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Action.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ static Htop_Reaction actionRedraw(ATTR_UNUSED State* st) {
return HTOP_REFRESH | HTOP_REDRAW_BAR;
}

static Htop_Reaction actionTogglePauseProcessUpdate(State* st) {
st->pauseProcessUpdate = !st->pauseProcessUpdate;
static Htop_Reaction actionTogglePauseUpdate(State* st) {
st->pauseUpdate = !st->pauseUpdate;
return HTOP_REFRESH | HTOP_REDRAW_BAR;
}

Expand Down Expand Up @@ -831,7 +831,7 @@ void Action_setBindings(Htop_Action* keys) {
#ifdef SCHEDULER_SUPPORT
keys['Y'] = actionSetSchedPolicy;
#endif
keys['Z'] = actionTogglePauseProcessUpdate;
keys['Z'] = actionTogglePauseUpdate;
keys['['] = actionLowerPriority;
keys['\014'] = actionRedraw; // Ctrl+L
keys['\177'] = actionCollapseIntoParent;
Expand Down
8 changes: 5 additions & 3 deletions Action.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ in the source distribution for its full text.
#include "Panel.h"
#include "Process.h"
#include "ProcessList.h"
#include "GenericDataList.h"
#include "Settings.h"
#include "UsersTable.h"

Expand All @@ -39,15 +40,16 @@ typedef struct State_ {
Settings* settings;
UsersTable* ut;
ProcessList* pl;
GenericDataList* gl;
struct MainPanel_* mainPanel;
Header* header;
bool pauseProcessUpdate;
bool hideProcessSelection;
bool pauseUpdate;
bool hideSelection;
bool hideMeters;
} State;

static inline bool State_hideFunctionBar(const State* st) {
return st->settings->hideFunctionBar == 2 || (st->settings->hideFunctionBar == 1 && st->hideProcessSelection);
return st->settings->hideFunctionBar == 2 || (st->settings->hideFunctionBar == 1 && st->hideSelection);
}

typedef Htop_Reaction (*Htop_Action)(State* st);
Expand Down
16 changes: 14 additions & 2 deletions AvailableColumnsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@ in the source distribution for its full text.
#include "XUtils.h"


Panel* activeAvailableColumns;

static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};

static void AvailableColumnsPanel_delete(Object* object) {
Panel* super = (Panel*) object;
AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
if (activeAvailableColumns == super)
activeAvailableColumns = NULL;
Panel_done(super);
free(this);
}
Expand Down Expand Up @@ -81,6 +85,9 @@ const PanelClass AvailableColumnsPanel_class = {

static void AvailableColumnsPanel_addDynamicColumn(ht_key_t key, void* value, void* data) {
const DynamicColumn* column = (const DynamicColumn*) value;
if (column->hasDynamicScreen)
return;

Panel* super = (Panel*) data;
const char* title = column->caption ? column->caption : column->heading;
if (!title)
Expand All @@ -91,13 +98,13 @@ static void AvailableColumnsPanel_addDynamicColumn(ht_key_t key, void* value, vo
}

// Handle DynamicColumns entries in the AvailableColumnsPanel
static void AvailableColumnsPanel_addDynamicColumns(Panel* super, Hashtable* dynamicColumns) {
void AvailableColumnsPanel_addDynamicColumns(Panel* super, Hashtable* dynamicColumns) {
assert(dynamicColumns);
Hashtable_foreach(dynamicColumns, AvailableColumnsPanel_addDynamicColumn, super);
}

// Handle remaining Platform Meter entries in the AvailableColumnsPanel
static void AvailableColumnsPanel_addPlatformColumn(Panel* super) {
void AvailableColumnsPanel_addPlatformColumn(Panel* super) {
for (int i = 1; i < LAST_PROCESSFIELD; i++) {
if (i != COMM && Process_fields[i].description) {
char description[256];
Expand All @@ -117,6 +124,11 @@ AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns, Hashtable* dyna
AvailableColumnsPanel_addPlatformColumn(super);
AvailableColumnsPanel_addDynamicColumns(super, dynamicColumns);

activeAvailableColumns = super;
this->columns = columns;
return this;
}

Panel* AvailableColumnsPanel_get(void) {
return activeAvailableColumns;
}
6 changes: 6 additions & 0 deletions AvailableColumnsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ extern const PanelClass AvailableColumnsPanel_class;

AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns, Hashtable* dynamicColumns);

void AvailableColumnsPanel_addPlatformColumn(Panel* super);

void AvailableColumnsPanel_addDynamicColumns(Panel* super, Hashtable* dynamicColumns);

Panel* AvailableColumnsPanel_get(void);

#endif
29 changes: 23 additions & 6 deletions CommandLine.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ in the source distribution for its full text.
#include "CRT.h"
#include "DynamicColumn.h"
#include "DynamicMeter.h"
#include "DynamicScreen.h"
#include "GenericDataList.h"
#include "Hashtable.h"
#include "Header.h"
#include "IncSet.h"
Expand Down Expand Up @@ -328,11 +330,18 @@ int CommandLine_run(const char* name, int argc, char** argv) {
dc = Hashtable_new(0, true);

ProcessList* pl = ProcessList_new(ut, dm, dc, flags.pidMatchList, flags.userId);

Settings* settings = Settings_new(pl->activeCPUs, dc);
fprintf(stderr, "Settings created\n");
Hashtable* dt = DynamicScreens_new(settings);
fprintf(stderr, "DynamicScreens created\n");
GenericDataList* gl = GenericDataList_new();
fprintf(stderr, "GenericDataList created\n");

pl->settings = settings;
if (gl)
gl->settings = settings;

Header* header = Header_new(pl, settings, 2);
Header* header = Header_new(pl, gl, settings, 2);

Header_populateFromSettings(header);

Expand Down Expand Up @@ -362,7 +371,7 @@ int CommandLine_run(const char* name, int argc, char** argv) {
CRT_init(settings, flags.allowUnicode);

MainPanel* panel = MainPanel_new();
ProcessList_setPanel(pl, (Panel*) panel);
MainPanel* genericDataPanel = MainPanel_new();

MainPanel_updateLabels(panel, settings->ss->treeView, flags.commFilter);

Expand All @@ -372,12 +381,18 @@ int CommandLine_run(const char* name, int argc, char** argv) {
.pl = pl,
.mainPanel = panel,
.header = header,
.pauseProcessUpdate = false,
.hideProcessSelection = false,
.pauseUpdate = false,
.hideSelection = false,
.hideMeters = false,
};

MainPanel_setState(panel, &state);
panel->state = &state;
genericDataPanel->state = &state;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be ... ?

   MainPanel_setState(panel, &state);
   MainPanel_setState(genericDataPanel, &state);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natoscott I think we need a new panel working in parallel with/instead MainPanel. This is a big part of what I'm talking about so far...
this panel will be minimal and doesn't have Nice (f7) or Kill (f9) panels [dito]
This will fix a lot of issues, maybe one of them is the issue mentioned above --enable-debug, not sure, this part needs surgery ^^"
but MainPanel has Class(Process):

Panel_init((Panel*) this, 1, 1, 1, 1, Class(Process), false, FunctionBar_new(Settings_isReadonly() ? MainFunctions_ro : MainFunctions, NULL, NULL));

also, @BenBE told me before how to do that: @natoscott I need your help here...

BenBe: I think it might be worth looking into a direction where the current Panel code is just used as a derived class ProcessListPanel (showing a process list), while most of its code is split into a base class GenericPanel (doing mostly nothing). From that GenericPanel class you could then split another derived class "FancyPanel" for doing all the Fancy stuff ;-)

Sohaib: Could you explain this more please?

BenBe: Basically what I was going at was not adopting the current Panel class to also show generic stuff, but to use the existing inheritance stuff so you can just push different kinds of Panels ("Process Lists" vs. "Generic Panels") into the list of tabs handled by the ScreenManager code.
The way to do this mostly boils down to split the current Panel implementation into the basic "draw the panel" code (extracted from current source BasePanel class) and the code drawing the process list (a new ProcessListPanel class).
The ScreenManager then instead of listing plain Panels would list BasePanels, which could be ProcessListPanels (working like they do now) or GenricStuffPanels (doing something generic).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenBE any chance you can help @smalinux here with some sample code changes to get him started on this aspect? thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will have to wait for next week; not in town tomorrow and the day after (giving a talk for a small conference). Changes-wise it boils down to creating inherited classes similar to what can be seen with ProcessList and <Platform>ProcessList with the Panel managing the ProcessList stuff getting most of the current process list draw code. Extra points when rendering the header/list items is split in a way so that for the generic tabs and the process list the actual rendering code is the same, but only creating/filling the content buffers differs. As said, I can elaborate next week …

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BenBE ping - can you post that detailed writeup here when you get a free minute? :) Thanks!


ProcessList_setPanel(pl, (Panel*) panel);
if (gl)
GenericDataList_setPanel(gl, (Panel*) genericDataPanel);

if (flags.commFilter)
setCommFilter(&state, &(flags.commFilter));

Expand Down Expand Up @@ -405,6 +420,7 @@ int CommandLine_run(const char* name, int argc, char** argv) {

Header_delete(header);
ProcessList_delete(pl);
GenericDataList_delete(gl);

ScreenManager_delete(scr);
MetersPanel_cleanup();
Expand All @@ -420,6 +436,7 @@ int CommandLine_run(const char* name, int argc, char** argv) {
Settings_delete(settings);
DynamicColumns_delete(dc);
DynamicMeters_delete(dm);
DynamicScreens_delete(dt);

return 0;
}
14 changes: 8 additions & 6 deletions DynamicColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
#include "RichString.h"


#define DYNAMIC_MAX_COLUMN_WIDTH 28
#define DYNAMIC_MAX_COLUMN_WIDTH 64
#define DYNAMIC_DEFAULT_COLUMN_WIDTH -5

typedef struct DynamicColumn_ {
char name[32]; /* unique, internal-only name */
char* heading; /* displayed in main screen */
char* caption; /* displayed in setup menu (short name) */
char* description; /* displayed in setup menu (detail) */
int width; /* display width +/- for value alignment */
char name[32]; /* unique, internal-only name */
char* heading; /* displayed in main screen */
char* caption; /* displayed in setup menu (short name) */
char* description; /* displayed in setup menu (detail) */
int width; /* display width +/- for value alignment */
bool hasDynamicScreen; /* from a DynamicScreen or ProcessList screen? */
bool enabled; /* false == ignore this column */
} DynamicColumn;

Hashtable* DynamicColumns_new(void);
Expand Down
62 changes: 62 additions & 0 deletions DynamicScreen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
htop - DynamicScreen.c
(C) 2022 Sohaib Mohammed
(C) 2022 htop dev team
(C) 2022 Red Hat, Inc. All Rights Reserved.
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

#include "DynamicScreen.h"

#include <stdbool.h>
#include <stddef.h>

#include "Hashtable.h"
#include "Platform.h"
#include "XUtils.h"


Hashtable* DynamicScreens_new(Settings* settings) {
return Platform_dynamicScreens(settings);
}

void DynamicScreens_delete(Hashtable* dynamics) {
if (dynamics) {
Platform_dynamicScreensDone(dynamics);
Hashtable_delete(dynamics);
}
}

typedef struct {
ht_key_t key;
const char* name;
bool found;
} DynamicIterator;

static void DynamicScreen_compare(ht_key_t key, void* value, void* data) {
const DynamicScreen* screen = (const DynamicScreen*)value;
DynamicIterator* iter = (DynamicIterator*)data;
if (String_eq(iter->name, screen->name)) {
iter->found = true;
iter->key = key;
}
}

bool DynamicScreen_search(Hashtable* dynamics, const char* name, ht_key_t* key) {
DynamicIterator iter = { .key = 0, .name = name, .found = false };
if (dynamics)
Hashtable_foreach(dynamics, DynamicScreen_compare, &iter);
if (key)
*key = iter.key;
return iter.found;
}

const char* DynamicScreen_lookup(Hashtable* dynamics, ht_key_t key) {
const DynamicScreen* screen = Hashtable_get(dynamics, key);
return screen ? screen->name : NULL;
}

void DynamicScreen_availableColumns(char* currentScreen) {
Platform_dynamicScreenAvailableColumns(currentScreen);
}
28 changes: 28 additions & 0 deletions DynamicScreen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef HEADER_DynamicScreen
#define HEADER_DynamicScreen

#include <stdbool.h>

#include "Hashtable.h"
#include "Settings.h"


typedef struct DynamicScreen_ {
char name[32]; /* unique name, cannot contain spaces */
char* caption;
char* fields;
char* sortKey;
int direction;
} DynamicScreen;

Hashtable* DynamicScreens_new(Settings* settings);

void DynamicScreens_delete(Hashtable* dynamics);

const char* DynamicScreen_lookup(Hashtable* dynamics, unsigned int key);

bool DynamicScreen_search(Hashtable* dynamics, const char* name, unsigned int* key);

void DynamicScreen_availableColumns(char* currentScreen);

#endif
69 changes: 69 additions & 0 deletions GenericData.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
htop - GenericData.c
(C) 2022 Sohaib Mohammed
(C) 2022 htop dev team
(C) 2022 Red Hat, Inc.
Released under the GNU GPLv2+, see the COPYING file
in the source distribution for its full text.
*/

#include "GenericData.h"

#include <assert.h>

#include "CRT.h"
#include "Macros.h"
#include "Process.h"
#include "RichString.h"
#include "Settings.h"


void GenericData_init(GenericData* this, const Settings* settings) {
this->settings = settings;
}

void GenericData_done(ATTR_UNUSED GenericData* this) {
assert (this != NULL);
}

void GenericData_writeField(ATTR_UNUSED const GenericData* this, ATTR_UNUSED RichString* str, ATTR_UNUSED int field) {
return;
}

void GenericData_display(const Object* cast, RichString* out) {
const GenericData* this = (const GenericData*) cast;
const ProcessField* fields = this->settings->ss->fields;
for (int i = 0; fields[i]; i++)
As_GenericData(this)->writeField(this, out, i);
}

int GenericData_compare(const void* v1, const void* v2) {
const GenericData* g1 = (const GenericData*)v1;
const GenericData* g2 = (const GenericData*)v2;

const Settings* settings = g1->settings;
const ScreenSettings* ss = settings->ss;

ProcessField key = ScreenSettings_getActiveSortKey(ss);

int result = GenericData_compareByKey(g1, g2, key);

return (ScreenSettings_getActiveDirection(ss) == 1) ? result : -result;
}

int GenericData_compareByKey_Base(const GenericData* g1, const GenericData* g2, ATTR_UNUSED ProcessField key) {
// TODO
(void) g1;
(void) g2;

return 0;
}

const GenericDataClass GenericData_class = {
.super = {
.extends = Class(Object),
.display = GenericData_display,
.compare = GenericData_compare,
},
.writeField = GenericData_writeField,
};
Loading