From 3b7aa0749bd57a38b77752f1b039fbd66c296e6b Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 19 Feb 2025 11:55:48 -0300 Subject: [PATCH 1/2] DisplayOptions: "Dec"/"Inc" operations in the function bar For numeric entries in Display Options, this gives users a hint of which keys operate on the value, and allows the value to be decreasable/increasable using the mouse as well. --- DisplayOptionsPanel.c | 28 ++++++++++++++++++++++++++++ DisplayOptionsPanel.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index d3ef8f5e8..fcba9d828 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -24,9 +24,14 @@ in the source distribution for its full text. static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; +static const char* const DisplayOptionsDecIncFunctions[] = {"Dec ", "Inc ", " ", "Done ", NULL}; +static const char* const DisplayOptionsDecIncKeys[] = {"- ", "+ ", " ", "F10", NULL}; +static const int DisplayOptionsDecIncEvents[] = {'-', '+', ERR, KEY_F(10)}; + static void DisplayOptionsPanel_delete(Object* object) { Panel* super = (Panel*) object; DisplayOptionsPanel* this = (DisplayOptionsPanel*) object; + FunctionBar_delete(this->decIncBar); Panel_done(super); free(this); } @@ -73,6 +78,28 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) { result = HANDLED; } break; + case KEY_UP: + case KEY_DOWN: + case KEY_NPAGE: + case KEY_PPAGE: + case KEY_HOME: + case KEY_END: + { + OptionItem* previous = selected; + Panel_onKey(super, ch); + selected = (OptionItem*) Panel_getSelected(super); + if (previous != selected) { + result = HANDLED; + } + } + /* fallthrough */ + case EVENT_SET_SELECTED: + if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) { + super->currentBar = this->decIncBar; + } else { + Panel_setDefaultBar(super); + } + break; } if (result == HANDLED) { @@ -104,6 +131,7 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar); + this->decIncBar = FunctionBar_new(DisplayOptionsDecIncFunctions, DisplayOptionsDecIncKeys, DisplayOptionsDecIncEvents); this->settings = settings; this->scr = scr; diff --git a/DisplayOptionsPanel.h b/DisplayOptionsPanel.h index 5e87a63b9..4b8343bd5 100644 --- a/DisplayOptionsPanel.h +++ b/DisplayOptionsPanel.h @@ -7,6 +7,7 @@ Released under the GNU GPLv2+, see the COPYING file in the source distribution for its full text. */ +#include "FunctionBar.h" #include "Panel.h" #include "ScreenManager.h" #include "Settings.h" @@ -17,6 +18,7 @@ typedef struct DisplayOptionsPanel_ { Settings* settings; ScreenManager* scr; + FunctionBar* decIncBar; } DisplayOptionsPanel; extern const PanelClass DisplayOptionsPanel_class; From 24b881cf64b6212d821b85b75d8b44934e515919 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Thu, 20 Feb 2025 09:18:47 +0100 Subject: [PATCH 2/2] Avoid casts for &this->super access in Panel classes --- AffinityPanel.c | 10 +++++----- AvailableColumnsPanel.c | 9 ++++----- AvailableMetersPanel.c | 6 +++--- CategoriesPanel.c | 6 +++--- ColorsPanel.c | 6 +++--- ColumnsPanel.c | 8 ++++---- DisplayOptionsPanel.c | 7 ++++--- HeaderOptionsPanel.c | 6 +++--- MainPanel.c | 7 +++---- MetersPanel.c | 10 +++++----- ScreenTabsPanel.c | 14 +++++++------- ScreensPanel.c | 6 ++++-- 12 files changed, 48 insertions(+), 47 deletions(-) diff --git a/AffinityPanel.c b/AffinityPanel.c index a982b30e4..2967f69b1 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -136,20 +136,19 @@ typedef struct AffinityPanel_ { static void AffinityPanel_delete(Object* cast) { AffinityPanel* this = (AffinityPanel*) cast; - Panel* super = (Panel*) this; - Panel_done(super); Vector_delete(this->cpuids); #ifdef HAVE_LIBHWLOC hwloc_bitmap_free(this->workCpuset); MaskItem_delete((Object*) this->topoRoot); #endif + Panel_done(&this->super); free(this); } #ifdef HAVE_LIBHWLOC static void AffinityPanel_updateItem(AffinityPanel* this, MaskItem* item) { - Panel* super = (Panel*) this; + Panel* super = &this->super; item->value = hwloc_bitmap_isincluded(item->cpuset, this->workCpuset) ? 2 : hwloc_bitmap_intersects(item->cpuset, this->workCpuset) ? 1 : 0; @@ -170,7 +169,7 @@ static void AffinityPanel_updateTopo(AffinityPanel* this, MaskItem* item) { #endif static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) { - Panel* super = (Panel*) this; + Panel* super = &this->super; FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : ""); @@ -370,7 +369,8 @@ static const int AffinityPanelEvents[] = {13, 27, KEY_F(1), KEY_F(2), KEY_F(3)}; Panel* AffinityPanel_new(Machine* host, const Affinity* affinity, int* width) { AffinityPanel* this = AllocThis(AffinityPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + Panel_init(super, 1, 1, 1, 1, Class(MaskItem), false, FunctionBar_new(AffinityPanelFunctions, AffinityPanelKeys, AffinityPanelEvents)); this->host = host; diff --git a/AvailableColumnsPanel.c b/AvailableColumnsPanel.c index eef0542f9..da546169e 100644 --- a/AvailableColumnsPanel.c +++ b/AvailableColumnsPanel.c @@ -30,9 +30,8 @@ in the source distribution for its full text. static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL}; static void AvailableColumnsPanel_delete(Object* object) { - Panel* super = (Panel*) object; AvailableColumnsPanel* this = (AvailableColumnsPanel*) object; - Panel_done(super); + Panel_done(&this->super); free(this); } @@ -118,8 +117,7 @@ static void AvailableColumnsPanel_addDynamicScreens(AvailableColumnsPanel* this, } void AvailableColumnsPanel_fill(AvailableColumnsPanel* this, const char* dynamicScreen, Hashtable* dynamicColumns) { - Panel* super = (Panel*) this; - Panel_prune(super); + Panel_prune(&this->super); if (dynamicScreen) { AvailableColumnsPanel_addDynamicScreens(this, dynamicScreen); } else { @@ -130,7 +128,8 @@ void AvailableColumnsPanel_fill(AvailableColumnsPanel* this, const char* dynamic AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns, Hashtable* dynamicColumns) { AvailableColumnsPanel* this = AllocThis(AvailableColumnsPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(AvailableColumnsFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); Panel_setHeader(super, "Available Columns"); diff --git a/AvailableMetersPanel.c b/AvailableMetersPanel.c index f32b91c03..f7a7ffb90 100644 --- a/AvailableMetersPanel.c +++ b/AvailableMetersPanel.c @@ -30,10 +30,9 @@ in the source distribution for its full text. static void AvailableMetersPanel_delete(Object* object) { - Panel* super = (Panel*) object; AvailableMetersPanel* this = (AvailableMetersPanel*) object; - Panel_done(super); free(this->meterPanels); + Panel_done(&this->super); free(this); } @@ -145,7 +144,8 @@ static void AvailableMetersPanel_addPlatformMeter(Panel* super, const MeterClass AvailableMetersPanel* AvailableMetersPanel_new(Machine* host, Header* header, size_t columns, MetersPanel** meterPanels, ScreenManager* scr) { AvailableMetersPanel* this = AllocThis(AvailableMetersPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done "); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); diff --git a/CategoriesPanel.c b/CategoriesPanel.c index 64a3f0624..530093c74 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -35,9 +35,8 @@ in the source distribution for its full text. static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; static void CategoriesPanel_delete(Object* object) { - Panel* super = (Panel*) object; CategoriesPanel* this = (CategoriesPanel*) object; - Panel_done(super); + Panel_done(&this->super); free(this); } @@ -172,7 +171,8 @@ const PanelClass CategoriesPanel_class = { CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Header* header, Machine* host) { CategoriesPanel* this = AllocThis(CategoriesPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); diff --git a/ColorsPanel.c b/ColorsPanel.c index 581c3a00e..e7a715778 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -41,9 +41,8 @@ static const char* const ColorSchemeNames[] = { }; static void ColorsPanel_delete(Object* object) { - Panel* super = (Panel*) object; ColorsPanel* this = (ColorsPanel*) object; - Panel_done(super); + Panel_done(&this->super); free(this); } @@ -91,7 +90,8 @@ const PanelClass ColorsPanel_class = { ColorsPanel* ColorsPanel_new(Settings* settings) { ColorsPanel* this = AllocThis(ColorsPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar); diff --git a/ColumnsPanel.c b/ColumnsPanel.c index d0922563b..2b34b231a 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -28,9 +28,8 @@ in the source distribution for its full text. static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL}; static void ColumnsPanel_delete(Object* object) { - Panel* super = (Panel*) object; ColumnsPanel* this = (ColumnsPanel*) object; - Panel_done(super); + Panel_done(&this->super); free(this); } @@ -126,7 +125,7 @@ static void ColumnsPanel_add(Panel* super, unsigned int key, Hashtable* columns) } void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss, Hashtable* columns) { - Panel* super = (Panel*) this; + Panel* super = &this->super; Panel_prune(super); for (const RowField* fields = ss->fields; *fields; fields++) ColumnsPanel_add(super, *fields, columns); @@ -135,7 +134,8 @@ void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss, Hashtable* column ColumnsPanel* ColumnsPanel_new(ScreenSettings* ss, Hashtable* columns, bool* changed) { ColumnsPanel* this = AllocThis(ColumnsPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); diff --git a/DisplayOptionsPanel.c b/DisplayOptionsPanel.c index fcba9d828..aa8e65f9e 100644 --- a/DisplayOptionsPanel.c +++ b/DisplayOptionsPanel.c @@ -29,10 +29,9 @@ static const char* const DisplayOptionsDecIncKeys[] = {"- ", "+ ", " ", "F10", static const int DisplayOptionsDecIncEvents[] = {'-', '+', ERR, KEY_F(10)}; static void DisplayOptionsPanel_delete(Object* object) { - Panel* super = (Panel*) object; DisplayOptionsPanel* this = (DisplayOptionsPanel*) object; FunctionBar_delete(this->decIncBar); - Panel_done(super); + Panel_done(&this->super); free(this); } @@ -127,7 +126,8 @@ const PanelClass DisplayOptionsPanel_class = { DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) { DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar); @@ -192,5 +192,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* #ifdef HAVE_LIBHWLOC Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity))); #endif + return this; } diff --git a/HeaderOptionsPanel.c b/HeaderOptionsPanel.c index 7b5c81be1..0d024f8c8 100644 --- a/HeaderOptionsPanel.c +++ b/HeaderOptionsPanel.c @@ -25,9 +25,8 @@ in the source distribution for its full text. static const char* const HeaderOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL}; static void HeaderOptionsPanel_delete(Object* object) { - Panel* super = (Panel*) object; HeaderOptionsPanel* this = (HeaderOptionsPanel*) object; - Panel_done(super); + Panel_done(&this->super); free(this); } @@ -74,7 +73,8 @@ const PanelClass HeaderOptionsPanel_class = { HeaderOptionsPanel* HeaderOptionsPanel_new(Settings* settings, ScreenManager* scr) { HeaderOptionsPanel* this = AllocThis(HeaderOptionsPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(HeaderOptionsFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar); diff --git a/MainPanel.c b/MainPanel.c index 47b2f92fe..7852c08f3 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -36,7 +36,7 @@ void MainPanel_updateLabels(MainPanel* this, bool list, bool filter) { } static void MainPanel_idSearch(MainPanel* this, int ch) { - Panel* super = (Panel*) this; + Panel* super = &this->super; pid_t id = ch - 48 + this->idSearch; for (int i = 0; i < Panel_size(super); i++) { const Row* row = (const Row*) Panel_get(super, i); @@ -159,7 +159,7 @@ int MainPanel_selectedRow(MainPanel* this) { } bool MainPanel_foreachRow(MainPanel* this, MainPanel_foreachRowFn fn, Arg arg, bool* wasAnyTagged) { - Panel* super = (Panel*) this; + Panel* super = &this->super; bool ok = true; bool anyTagged = false; for (int i = 0; i < Panel_size(super); i++) { @@ -236,12 +236,11 @@ void MainPanel_setFunctionBar(MainPanel* this, bool readonly) { } void MainPanel_delete(Object* object) { - Panel* super = (Panel*) object; MainPanel* this = (MainPanel*) object; MainPanel_setFunctionBar(this, false); FunctionBar_delete(this->readonlyBar); - Panel_done(super); IncSet_delete(this->inc); free(this->keys); + Panel_done(&this->super); free(this); } diff --git a/MetersPanel.c b/MetersPanel.c index 94c8e58d1..65752f7c2 100644 --- a/MetersPanel.c +++ b/MetersPanel.c @@ -43,14 +43,13 @@ void MetersPanel_cleanup(void) { } static void MetersPanel_delete(Object* object) { - Panel* super = (Panel*) object; MetersPanel* this = (MetersPanel*) object; - Panel_done(super); + Panel_done(&this->super); free(this); } void MetersPanel_setMoving(MetersPanel* this, bool moving) { - Panel* super = (Panel*) this; + Panel* super = &this->super; this->moving = moving; ListItem* selected = (ListItem*)Panel_getSelected(super); if (selected) { @@ -66,7 +65,7 @@ void MetersPanel_setMoving(MetersPanel* this, bool moving) { } static inline bool moveToNeighbor(MetersPanel* this, MetersPanel* neighbor, int selected) { - Panel* super = (Panel*) this; + Panel* super = &this->super; if (this->moving) { if (neighbor) { if (selected < Vector_size(this->meters)) { @@ -185,7 +184,8 @@ const PanelClass MetersPanel_class = { MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* meters, ScreenManager* scr) { MetersPanel* this = AllocThis(MetersPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(MetersFunctions, MetersKeys, MetersEvents); if (!Meters_movingBar) { Meters_movingBar = FunctionBar_new(MetersMovingFunctions, MetersMovingKeys, MetersMovingEvents); diff --git a/ScreenTabsPanel.c b/ScreenTabsPanel.c index e48e5fb8b..007b279d7 100644 --- a/ScreenTabsPanel.c +++ b/ScreenTabsPanel.c @@ -35,7 +35,7 @@ ObjectClass ScreenTabListItem_class = { static void ScreenNamesPanel_fill(ScreenNamesPanel* this, DynamicScreen* ds) { const Settings* settings = this->settings; - Panel* super = (Panel*) this; + Panel* super = &this->super; Panel_prune(super); for (unsigned int i = 0; i < settings->nScreens; i++) { @@ -59,10 +59,8 @@ static void ScreenNamesPanel_fill(ScreenNamesPanel* this, DynamicScreen* ds) { } static void ScreenTabsPanel_delete(Object* object) { - Panel* super = (Panel*) object; ScreenTabsPanel* this = (ScreenTabsPanel*) object; - - Panel_done(super); + Panel_done(&this->super); free(this); } @@ -138,7 +136,8 @@ static const char* const ScreenTabsFunctions[] = {" ", " ", " ", ScreenTabsPanel* ScreenTabsPanel_new(Settings* settings) { ScreenTabsPanel* this = AllocThis(ScreenTabsPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(ScreenTabsFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); @@ -174,8 +173,8 @@ ScreenNameListItem* ScreenNameListItem_new(const char* value, ScreenSettings* ss static const char* const ScreenNamesFunctions[] = {" ", " ", " ", " ", "New ", " ", " ", " ", " ", "Done ", NULL}; static void ScreenNamesPanel_delete(Object* object) { - Panel* super = (Panel*) object; ScreenNamesPanel* this = (ScreenNamesPanel*) object; + Panel* super = &this->super; /* do not delete screen settings still in use */ int n = Panel_size(super); @@ -350,7 +349,8 @@ PanelClass ScreenNamesPanel_class = { ScreenNamesPanel* ScreenNamesPanel_new(Settings* settings) { ScreenNamesPanel* this = AllocThis(ScreenNamesPanel); - Panel* super = (Panel*) this; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(ScreenNamesFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); diff --git a/ScreensPanel.c b/ScreensPanel.c index 4138066b5..2ba7b940d 100644 --- a/ScreensPanel.c +++ b/ScreensPanel.c @@ -290,11 +290,13 @@ PanelClass ScreensPanel_class = { ScreensPanel* ScreensPanel_new(Settings* settings) { ScreensPanel* this = AllocThis(ScreensPanel); - Panel* super = (Panel*) this; - Hashtable* columns = settings->dynamicColumns; + Panel* super = &this->super; + FunctionBar* fuBar = FunctionBar_new(settings->dynamicScreens ? DynamicFunctions : ScreensFunctions, NULL, NULL); Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar); + Hashtable* columns = settings->dynamicColumns; + this->settings = settings; this->columns = ColumnsPanel_new(settings->screens[0], columns, &(settings->changed)); this->availableColumns = AvailableColumnsPanel_new((Panel*) this->columns, columns);