Skip to content

Commit d28659d

Browse files
Daniel LangeDaniel Lange
authored andcommitted
Merge remote-tracking branch 'origin/display-options-inc-dec' from hishamhm
Closes #737, #745, #722
2 parents 5f90660 + 24b881c commit d28659d

13 files changed

Lines changed: 78 additions & 47 deletions

AffinityPanel.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,19 @@ typedef struct AffinityPanel_ {
136136

137137
static void AffinityPanel_delete(Object* cast) {
138138
AffinityPanel* this = (AffinityPanel*) cast;
139-
Panel* super = (Panel*) this;
140-
Panel_done(super);
141139
Vector_delete(this->cpuids);
142140
#ifdef HAVE_LIBHWLOC
143141
hwloc_bitmap_free(this->workCpuset);
144142
MaskItem_delete((Object*) this->topoRoot);
145143
#endif
144+
Panel_done(&this->super);
146145
free(this);
147146
}
148147

149148
#ifdef HAVE_LIBHWLOC
150149

151150
static void AffinityPanel_updateItem(AffinityPanel* this, MaskItem* item) {
152-
Panel* super = (Panel*) this;
151+
Panel* super = &this->super;
153152

154153
item->value = hwloc_bitmap_isincluded(item->cpuset, this->workCpuset) ? 2 :
155154
hwloc_bitmap_intersects(item->cpuset, this->workCpuset) ? 1 : 0;
@@ -170,7 +169,7 @@ static void AffinityPanel_updateTopo(AffinityPanel* this, MaskItem* item) {
170169
#endif
171170

172171
static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) {
173-
Panel* super = (Panel*) this;
172+
Panel* super = &this->super;
174173

175174
FunctionBar_setLabel(super->currentBar, KEY_F(3), this->topoView ? "Collapse/Expand" : "");
176175

@@ -370,7 +369,8 @@ static const int AffinityPanelEvents[] = {13, 27, KEY_F(1), KEY_F(2), KEY_F(3)};
370369

371370
Panel* AffinityPanel_new(Machine* host, const Affinity* affinity, int* width) {
372371
AffinityPanel* this = AllocThis(AffinityPanel);
373-
Panel* super = (Panel*) this;
372+
Panel* super = &this->super;
373+
374374
Panel_init(super, 1, 1, 1, 1, Class(MaskItem), false, FunctionBar_new(AffinityPanelFunctions, AffinityPanelKeys, AffinityPanelEvents));
375375

376376
this->host = host;

AvailableColumnsPanel.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ in the source distribution for its full text.
3030
static const char* const AvailableColumnsFunctions[] = {" ", " ", " ", " ", "Add ", " ", " ", " ", " ", "Done ", NULL};
3131

3232
static void AvailableColumnsPanel_delete(Object* object) {
33-
Panel* super = (Panel*) object;
3433
AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
35-
Panel_done(super);
34+
Panel_done(&this->super);
3635
free(this);
3736
}
3837

@@ -118,8 +117,7 @@ static void AvailableColumnsPanel_addDynamicScreens(AvailableColumnsPanel* this,
118117
}
119118

120119
void AvailableColumnsPanel_fill(AvailableColumnsPanel* this, const char* dynamicScreen, Hashtable* dynamicColumns) {
121-
Panel* super = (Panel*) this;
122-
Panel_prune(super);
120+
Panel_prune(&this->super);
123121
if (dynamicScreen) {
124122
AvailableColumnsPanel_addDynamicScreens(this, dynamicScreen);
125123
} else {
@@ -130,7 +128,8 @@ void AvailableColumnsPanel_fill(AvailableColumnsPanel* this, const char* dynamic
130128

131129
AvailableColumnsPanel* AvailableColumnsPanel_new(Panel* columns, Hashtable* dynamicColumns) {
132130
AvailableColumnsPanel* this = AllocThis(AvailableColumnsPanel);
133-
Panel* super = (Panel*) this;
131+
Panel* super = &this->super;
132+
134133
FunctionBar* fuBar = FunctionBar_new(AvailableColumnsFunctions, NULL, NULL);
135134
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
136135
Panel_setHeader(super, "Available Columns");

AvailableMetersPanel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ in the source distribution for its full text.
3030

3131

3232
static void AvailableMetersPanel_delete(Object* object) {
33-
Panel* super = (Panel*) object;
3433
AvailableMetersPanel* this = (AvailableMetersPanel*) object;
35-
Panel_done(super);
3634
free(this->meterPanels);
35+
Panel_done(&this->super);
3736
free(this);
3837
}
3938

@@ -145,7 +144,8 @@ static void AvailableMetersPanel_addPlatformMeter(Panel* super, const MeterClass
145144

146145
AvailableMetersPanel* AvailableMetersPanel_new(Machine* host, Header* header, size_t columns, MetersPanel** meterPanels, ScreenManager* scr) {
147146
AvailableMetersPanel* this = AllocThis(AvailableMetersPanel);
148-
Panel* super = (Panel*) this;
147+
Panel* super = &this->super;
148+
149149
FunctionBar* fuBar = FunctionBar_newEnterEsc("Add ", "Done ");
150150
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
151151

CategoriesPanel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ in the source distribution for its full text.
3535
static const char* const CategoriesFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
3636

3737
static void CategoriesPanel_delete(Object* object) {
38-
Panel* super = (Panel*) object;
3938
CategoriesPanel* this = (CategoriesPanel*) object;
40-
Panel_done(super);
39+
Panel_done(&this->super);
4140
free(this);
4241
}
4342

@@ -172,7 +171,8 @@ const PanelClass CategoriesPanel_class = {
172171

173172
CategoriesPanel* CategoriesPanel_new(ScreenManager* scr, Header* header, Machine* host) {
174173
CategoriesPanel* this = AllocThis(CategoriesPanel);
175-
Panel* super = (Panel*) this;
174+
Panel* super = &this->super;
175+
176176
FunctionBar* fuBar = FunctionBar_new(CategoriesFunctions, NULL, NULL);
177177
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
178178

ColorsPanel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ static const char* const ColorSchemeNames[] = {
4141
};
4242

4343
static void ColorsPanel_delete(Object* object) {
44-
Panel* super = (Panel*) object;
4544
ColorsPanel* this = (ColorsPanel*) object;
46-
Panel_done(super);
45+
Panel_done(&this->super);
4746
free(this);
4847
}
4948

@@ -91,7 +90,8 @@ const PanelClass ColorsPanel_class = {
9190

9291
ColorsPanel* ColorsPanel_new(Settings* settings) {
9392
ColorsPanel* this = AllocThis(ColorsPanel);
94-
Panel* super = (Panel*) this;
93+
Panel* super = &this->super;
94+
9595
FunctionBar* fuBar = FunctionBar_new(ColorsFunctions, NULL, NULL);
9696
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
9797

ColumnsPanel.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@ in the source distribution for its full text.
2828
static const char* const ColumnsFunctions[] = {" ", " ", " ", " ", " ", " ", "MoveUp", "MoveDn", "Remove", "Done ", NULL};
2929

3030
static void ColumnsPanel_delete(Object* object) {
31-
Panel* super = (Panel*) object;
3231
ColumnsPanel* this = (ColumnsPanel*) object;
33-
Panel_done(super);
32+
Panel_done(&this->super);
3433
free(this);
3534
}
3635

@@ -126,7 +125,7 @@ static void ColumnsPanel_add(Panel* super, unsigned int key, Hashtable* columns)
126125
}
127126

128127
void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss, Hashtable* columns) {
129-
Panel* super = (Panel*) this;
128+
Panel* super = &this->super;
130129
Panel_prune(super);
131130
for (const RowField* fields = ss->fields; *fields; fields++)
132131
ColumnsPanel_add(super, *fields, columns);
@@ -135,7 +134,8 @@ void ColumnsPanel_fill(ColumnsPanel* this, ScreenSettings* ss, Hashtable* column
135134

136135
ColumnsPanel* ColumnsPanel_new(ScreenSettings* ss, Hashtable* columns, bool* changed) {
137136
ColumnsPanel* this = AllocThis(ColumnsPanel);
138-
Panel* super = (Panel*) this;
137+
Panel* super = &this->super;
138+
139139
FunctionBar* fuBar = FunctionBar_new(ColumnsFunctions, NULL, NULL);
140140
Panel_init(super, 1, 1, 1, 1, Class(ListItem), true, fuBar);
141141

DisplayOptionsPanel.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ in the source distribution for its full text.
2424

2525
static const char* const DisplayOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
2626

27+
static const char* const DisplayOptionsDecIncFunctions[] = {"Dec ", "Inc ", " ", "Done ", NULL};
28+
static const char* const DisplayOptionsDecIncKeys[] = {"- ", "+ ", " ", "F10", NULL};
29+
static const int DisplayOptionsDecIncEvents[] = {'-', '+', ERR, KEY_F(10)};
30+
2731
static void DisplayOptionsPanel_delete(Object* object) {
28-
Panel* super = (Panel*) object;
2932
DisplayOptionsPanel* this = (DisplayOptionsPanel*) object;
30-
Panel_done(super);
33+
FunctionBar_delete(this->decIncBar);
34+
Panel_done(&this->super);
3135
free(this);
3236
}
3337

@@ -73,6 +77,28 @@ static HandlerResult DisplayOptionsPanel_eventHandler(Panel* super, int ch) {
7377
result = HANDLED;
7478
}
7579
break;
80+
case KEY_UP:
81+
case KEY_DOWN:
82+
case KEY_NPAGE:
83+
case KEY_PPAGE:
84+
case KEY_HOME:
85+
case KEY_END:
86+
{
87+
OptionItem* previous = selected;
88+
Panel_onKey(super, ch);
89+
selected = (OptionItem*) Panel_getSelected(super);
90+
if (previous != selected) {
91+
result = HANDLED;
92+
}
93+
}
94+
/* fallthrough */
95+
case EVENT_SET_SELECTED:
96+
if (OptionItem_kind(selected) == OPTION_ITEM_NUMBER) {
97+
super->currentBar = this->decIncBar;
98+
} else {
99+
Panel_setDefaultBar(super);
100+
}
101+
break;
76102
}
77103

78104
if (result == HANDLED) {
@@ -100,10 +126,12 @@ const PanelClass DisplayOptionsPanel_class = {
100126

101127
DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager* scr) {
102128
DisplayOptionsPanel* this = AllocThis(DisplayOptionsPanel);
103-
Panel* super = (Panel*) this;
129+
Panel* super = &this->super;
130+
104131
FunctionBar* fuBar = FunctionBar_new(DisplayOptionsFunctions, NULL, NULL);
105132
Panel_init(super, 1, 1, 1, 1, Class(OptionItem), true, fuBar);
106133

134+
this->decIncBar = FunctionBar_new(DisplayOptionsDecIncFunctions, DisplayOptionsDecIncKeys, DisplayOptionsDecIncEvents);
107135
this->settings = settings;
108136
this->scr = scr;
109137

@@ -164,5 +192,6 @@ DisplayOptionsPanel* DisplayOptionsPanel_new(Settings* settings, ScreenManager*
164192
#ifdef HAVE_LIBHWLOC
165193
Panel_add(super, (Object*) CheckItem_newByRef("Show topology when selecting affinity by default", &(settings->topologyAffinity)));
166194
#endif
195+
167196
return this;
168197
}

DisplayOptionsPanel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Released under the GNU GPLv2+, see the COPYING file
77
in the source distribution for its full text.
88
*/
99

10+
#include "FunctionBar.h"
1011
#include "Panel.h"
1112
#include "ScreenManager.h"
1213
#include "Settings.h"
@@ -17,6 +18,7 @@ typedef struct DisplayOptionsPanel_ {
1718

1819
Settings* settings;
1920
ScreenManager* scr;
21+
FunctionBar* decIncBar;
2022
} DisplayOptionsPanel;
2123

2224
extern const PanelClass DisplayOptionsPanel_class;

HeaderOptionsPanel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ in the source distribution for its full text.
2525
static const char* const HeaderOptionsFunctions[] = {" ", " ", " ", " ", " ", " ", " ", " ", " ", "Done ", NULL};
2626

2727
static void HeaderOptionsPanel_delete(Object* object) {
28-
Panel* super = (Panel*) object;
2928
HeaderOptionsPanel* this = (HeaderOptionsPanel*) object;
30-
Panel_done(super);
29+
Panel_done(&this->super);
3130
free(this);
3231
}
3332

@@ -74,7 +73,8 @@ const PanelClass HeaderOptionsPanel_class = {
7473

7574
HeaderOptionsPanel* HeaderOptionsPanel_new(Settings* settings, ScreenManager* scr) {
7675
HeaderOptionsPanel* this = AllocThis(HeaderOptionsPanel);
77-
Panel* super = (Panel*) this;
76+
Panel* super = &this->super;
77+
7878
FunctionBar* fuBar = FunctionBar_new(HeaderOptionsFunctions, NULL, NULL);
7979
Panel_init(super, 1, 1, 1, 1, Class(CheckItem), true, fuBar);
8080

MainPanel.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void MainPanel_updateLabels(MainPanel* this, bool list, bool filter) {
3636
}
3737

3838
static void MainPanel_idSearch(MainPanel* this, int ch) {
39-
Panel* super = (Panel*) this;
39+
Panel* super = &this->super;
4040
pid_t id = ch - 48 + this->idSearch;
4141
for (int i = 0; i < Panel_size(super); i++) {
4242
const Row* row = (const Row*) Panel_get(super, i);
@@ -159,7 +159,7 @@ int MainPanel_selectedRow(MainPanel* this) {
159159
}
160160

161161
bool MainPanel_foreachRow(MainPanel* this, MainPanel_foreachRowFn fn, Arg arg, bool* wasAnyTagged) {
162-
Panel* super = (Panel*) this;
162+
Panel* super = &this->super;
163163
bool ok = true;
164164
bool anyTagged = false;
165165
for (int i = 0; i < Panel_size(super); i++) {
@@ -236,12 +236,11 @@ void MainPanel_setFunctionBar(MainPanel* this, bool readonly) {
236236
}
237237

238238
void MainPanel_delete(Object* object) {
239-
Panel* super = (Panel*) object;
240239
MainPanel* this = (MainPanel*) object;
241240
MainPanel_setFunctionBar(this, false);
242241
FunctionBar_delete(this->readonlyBar);
243-
Panel_done(super);
244242
IncSet_delete(this->inc);
245243
free(this->keys);
244+
Panel_done(&this->super);
246245
free(this);
247246
}

0 commit comments

Comments
 (0)