mirror of https://github.com/xzeldon/htop.git
Drop unneeded parameters to the ScreenManager constructor
All calls to ScreenManager_new always pass the same first five values, the orientation is always HORIZONTAL and the y1 parameter is always the height of the passed-in header struct pointer. I think its safe to assert at this point that no VERTICAL orientation will arrive (if it does, its no harm in re-adding this then) - so we can remove unused conditionals (and TODOs) based on orientation too.
This commit is contained in:
parent
83bf8cfad6
commit
fee217551c
4
Action.c
4
Action.c
|
@ -46,7 +46,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
|
||||||
Settings* settings = st->settings;
|
Settings* settings = st->settings;
|
||||||
|
|
||||||
int y = panel->y;
|
int y = panel->y;
|
||||||
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, st, false);
|
ScreenManager* scr = ScreenManager_new(header, settings, st, false);
|
||||||
scr->allowFocusChange = false;
|
scr->allowFocusChange = false;
|
||||||
ScreenManager_add(scr, list, x - 1);
|
ScreenManager_add(scr, list, x - 1);
|
||||||
ScreenManager_add(scr, panel, -1);
|
ScreenManager_add(scr, panel, -1);
|
||||||
|
@ -83,7 +83,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess)
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
static void Action_runSetup(State* st) {
|
static void Action_runSetup(State* st) {
|
||||||
ScreenManager* scr = ScreenManager_new(0, st->header->height, 0, -1, HORIZONTAL, st->header, st->settings, st, true);
|
ScreenManager* scr = ScreenManager_new(st->header, st->settings, st, true);
|
||||||
CategoriesPanel* panelCategories = CategoriesPanel_new(scr, st->settings, st->header, st->pl);
|
CategoriesPanel* panelCategories = CategoriesPanel_new(scr, st->settings, st->header, st->pl);
|
||||||
ScreenManager_add(scr, (Panel*) panelCategories, 16);
|
ScreenManager_add(scr, (Panel*) panelCategories, 16);
|
||||||
CategoriesPanel_makeMetersPage(panelCategories);
|
CategoriesPanel_makeMetersPage(panelCategories);
|
||||||
|
|
4
Header.h
4
Header.h
|
@ -15,7 +15,7 @@ in the source distribution for its full text.
|
||||||
typedef struct Header_ {
|
typedef struct Header_ {
|
||||||
Vector** columns;
|
Vector** columns;
|
||||||
Settings* settings;
|
Settings* settings;
|
||||||
struct ProcessList_* pl;
|
ProcessList* pl;
|
||||||
int nrColumns;
|
int nrColumns;
|
||||||
int pad;
|
int pad;
|
||||||
int height;
|
int height;
|
||||||
|
@ -23,7 +23,7 @@ typedef struct Header_ {
|
||||||
|
|
||||||
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
#define Header_forEachColumn(this_, i_) for (int (i_)=0; (i_) < (this_)->nrColumns; ++(i_))
|
||||||
|
|
||||||
Header* Header_new(struct ProcessList_* pl, Settings* settings, int nrColumns);
|
Header* Header_new(ProcessList* pl, Settings* settings, int nrColumns);
|
||||||
|
|
||||||
void Header_delete(Header* this);
|
void Header_delete(Header* this);
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,13 @@ in the source distribution for its full text.
|
||||||
#include "XUtils.h"
|
#include "XUtils.h"
|
||||||
|
|
||||||
|
|
||||||
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, const State* state, bool owner) {
|
ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const State* state, bool owner) {
|
||||||
ScreenManager* this;
|
ScreenManager* this;
|
||||||
this = xMalloc(sizeof(ScreenManager));
|
this = xMalloc(sizeof(ScreenManager));
|
||||||
this->x1 = x1;
|
this->x1 = 0;
|
||||||
this->y1 = y1;
|
this->y1 = header->height;
|
||||||
this->x2 = x2;
|
this->x2 = 0;
|
||||||
this->y2 = y2;
|
this->y2 = -1;
|
||||||
this->orientation = orientation;
|
|
||||||
this->panels = Vector_new(Class(Panel), owner, DEFAULT_SIZE);
|
this->panels = Vector_new(Class(Panel), owner, DEFAULT_SIZE);
|
||||||
this->panelCount = 0;
|
this->panelCount = 0;
|
||||||
this->header = header;
|
this->header = header;
|
||||||
|
@ -48,7 +47,6 @@ inline int ScreenManager_size(ScreenManager* this) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenManager_add(ScreenManager* this, Panel* item, int size) {
|
void ScreenManager_add(ScreenManager* this, Panel* item, int size) {
|
||||||
if (this->orientation == HORIZONTAL) {
|
|
||||||
int lastX = 0;
|
int lastX = 0;
|
||||||
if (this->panelCount > 0) {
|
if (this->panelCount > 0) {
|
||||||
Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1);
|
Panel* last = (Panel*) Vector_get(this->panels, this->panelCount - 1);
|
||||||
|
@ -61,8 +59,6 @@ void ScreenManager_add(ScreenManager* this, Panel* item, int size) {
|
||||||
Panel_resize(item, COLS - this->x1 + this->x2 - lastX, height);
|
Panel_resize(item, COLS - this->x1 + this->x2 - lastX, height);
|
||||||
}
|
}
|
||||||
Panel_move(item, lastX, this->y1);
|
Panel_move(item, lastX, this->y1);
|
||||||
}
|
|
||||||
// TODO: VERTICAL
|
|
||||||
Vector_add(this->panels, item);
|
Vector_add(this->panels, item);
|
||||||
item->needsRedraw = true;
|
item->needsRedraw = true;
|
||||||
this->panelCount++;
|
this->panelCount++;
|
||||||
|
@ -81,7 +77,6 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
|
||||||
this->x2 = x2;
|
this->x2 = x2;
|
||||||
this->y2 = y2;
|
this->y2 = y2;
|
||||||
int panels = this->panelCount;
|
int panels = this->panelCount;
|
||||||
if (this->orientation == HORIZONTAL) {
|
|
||||||
int lastX = 0;
|
int lastX = 0;
|
||||||
for (int i = 0; i < panels - 1; i++) {
|
for (int i = 0; i < panels - 1; i++) {
|
||||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||||
|
@ -93,8 +88,6 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
|
||||||
Panel_resize(panel, COLS - x1 + x2 - lastX, LINES - y1 + y2);
|
Panel_resize(panel, COLS - x1 + x2 - lastX, LINES - y1 + y2);
|
||||||
Panel_move(panel, lastX, y1);
|
Panel_move(panel, lastX, y1);
|
||||||
}
|
}
|
||||||
// TODO: VERTICAL
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut) {
|
static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut) {
|
||||||
ProcessList* pl = this->header->pl;
|
ProcessList* pl = this->header->pl;
|
||||||
|
@ -131,11 +124,9 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) {
|
||||||
for (int i = 0; i < nPanels; i++) {
|
for (int i = 0; i < nPanels; i++) {
|
||||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||||
Panel_draw(panel, i == focus);
|
Panel_draw(panel, i == focus);
|
||||||
if (this->orientation == HORIZONTAL) {
|
|
||||||
mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1);
|
mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
static Panel* setCurrentPanel(const ScreenManager* this, Panel* panel) {
|
static Panel* setCurrentPanel(const ScreenManager* this, Panel* panel) {
|
||||||
FunctionBar_draw(panel->currentBar);
|
FunctionBar_draw(panel->currentBar);
|
||||||
|
|
|
@ -16,17 +16,11 @@ in the source distribution for its full text.
|
||||||
#include "Vector.h"
|
#include "Vector.h"
|
||||||
|
|
||||||
|
|
||||||
typedef enum Orientation_ {
|
|
||||||
VERTICAL,
|
|
||||||
HORIZONTAL
|
|
||||||
} Orientation;
|
|
||||||
|
|
||||||
typedef struct ScreenManager_ {
|
typedef struct ScreenManager_ {
|
||||||
int x1;
|
int x1;
|
||||||
int y1;
|
int y1;
|
||||||
int x2;
|
int x2;
|
||||||
int y2;
|
int y2;
|
||||||
Orientation orientation;
|
|
||||||
Vector* panels;
|
Vector* panels;
|
||||||
int panelCount;
|
int panelCount;
|
||||||
Header* header;
|
Header* header;
|
||||||
|
@ -36,7 +30,7 @@ typedef struct ScreenManager_ {
|
||||||
bool allowFocusChange;
|
bool allowFocusChange;
|
||||||
} ScreenManager;
|
} ScreenManager;
|
||||||
|
|
||||||
ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation orientation, Header* header, const Settings* settings, const State* state, bool owner);
|
ScreenManager* ScreenManager_new(Header* header, const Settings* settings, const State* state, bool owner);
|
||||||
|
|
||||||
void ScreenManager_delete(ScreenManager* this);
|
void ScreenManager_delete(ScreenManager* this);
|
||||||
|
|
||||||
|
|
2
htop.c
2
htop.c
|
@ -326,7 +326,7 @@ int main(int argc, char** argv) {
|
||||||
if (flags.commFilter)
|
if (flags.commFilter)
|
||||||
setCommFilter(&state, &(flags.commFilter));
|
setCommFilter(&state, &(flags.commFilter));
|
||||||
|
|
||||||
ScreenManager* scr = ScreenManager_new(0, header->height, 0, -1, HORIZONTAL, header, settings, &state, true);
|
ScreenManager* scr = ScreenManager_new(header, settings, &state, true);
|
||||||
ScreenManager_add(scr, (Panel*) panel, -1);
|
ScreenManager_add(scr, (Panel*) panel, -1);
|
||||||
|
|
||||||
ProcessList_scan(pl, false);
|
ProcessList_scan(pl, false);
|
||||||
|
|
Loading…
Reference in New Issue