Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/display-options-inc-dec' from hi…
Browse files Browse the repository at this point in the history
…shamhm

Closes #737, #745, #722
  • Loading branch information
Daniel Lange authored and Daniel Lange committed Feb 20, 2025
2 parents 5f90660 + 24b881c commit d28659d
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 47 deletions.
10 changes: 5 additions & 5 deletions AffinityPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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" : "");

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions AvailableColumnsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions AvailableMetersPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions CategoriesPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions ColorsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions ColumnsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
35 changes: 32 additions & 3 deletions DisplayOptionsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +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;
Panel_done(super);
FunctionBar_delete(this->decIncBar);
Panel_done(&this->super);
free(this);
}

Expand Down Expand Up @@ -73,6 +77,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) {
Expand Down Expand Up @@ -100,10 +126,12 @@ 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);

this->decIncBar = FunctionBar_new(DisplayOptionsDecIncFunctions, DisplayOptionsDecIncKeys, DisplayOptionsDecIncEvents);
this->settings = settings;
this->scr = scr;

Expand Down Expand Up @@ -164,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;
}
2 changes: 2 additions & 0 deletions DisplayOptionsPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,6 +18,7 @@ typedef struct DisplayOptionsPanel_ {

Settings* settings;
ScreenManager* scr;
FunctionBar* decIncBar;
} DisplayOptionsPanel;

extern const PanelClass DisplayOptionsPanel_class;
Expand Down
6 changes: 3 additions & 3 deletions HeaderOptionsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down
7 changes: 3 additions & 4 deletions MainPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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);
}
10 changes: 5 additions & 5 deletions MetersPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions ScreenTabsPanel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
Loading

0 comments on commit d28659d

Please sign in to comment.