mirror of https://github.com/xzeldon/htop.git
handle clicks on panel header line
This commit is contained in:
parent
38fd1bfaba
commit
a93db5234c
10
Action.c
10
Action.c
|
@ -154,7 +154,7 @@ static bool expandCollapse(Panel* panel) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Htop_Reaction setSortKey(Settings* settings, ProcessField sortKey) {
|
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||||
settings->sortKey = sortKey;
|
settings->sortKey = sortKey;
|
||||||
settings->direction = 1;
|
settings->direction = 1;
|
||||||
settings->treeView = false;
|
settings->treeView = false;
|
||||||
|
@ -175,7 +175,7 @@ static Htop_Reaction sortBy(State* st) {
|
||||||
}
|
}
|
||||||
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15);
|
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15);
|
||||||
if (field) {
|
if (field) {
|
||||||
reaction |= setSortKey(st->settings, field->key);
|
reaction |= Action_setSortKey(st->settings, field->key);
|
||||||
}
|
}
|
||||||
Object_delete(sortPanel);
|
Object_delete(sortPanel);
|
||||||
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR;
|
||||||
|
@ -189,15 +189,15 @@ static Htop_Reaction actionResize(State* st) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionSortByMemory(State* st) {
|
static Htop_Reaction actionSortByMemory(State* st) {
|
||||||
return setSortKey(st->settings, PERCENT_MEM);
|
return Action_setSortKey(st->settings, PERCENT_MEM);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionSortByCPU(State* st) {
|
static Htop_Reaction actionSortByCPU(State* st) {
|
||||||
return setSortKey(st->settings, PERCENT_CPU);
|
return Action_setSortKey(st->settings, PERCENT_CPU);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionSortByTime(State* st) {
|
static Htop_Reaction actionSortByTime(State* st) {
|
||||||
return setSortKey(st->settings, TIME);
|
return Action_setSortKey(st->settings, TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Htop_Reaction actionToggleKernelThreads(State* st) {
|
static Htop_Reaction actionToggleKernelThreads(State* st) {
|
||||||
|
|
2
Action.h
2
Action.h
|
@ -45,6 +45,8 @@ Object* Action_pickFromVector(State* st, Panel* list, int x);
|
||||||
|
|
||||||
bool Action_setUserOnly(const char* userName, uid_t* userId);
|
bool Action_setUserOnly(const char* userName, uid_t* userId);
|
||||||
|
|
||||||
|
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
void Action_setBindings(Htop_Action* keys);
|
void Action_setBindings(Htop_Action* keys);
|
||||||
|
|
|
@ -78,7 +78,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
||||||
|
|
||||||
int selected = Panel_getSelectedIndex(super);
|
int selected = Panel_getSelectedIndex(super);
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case EVENT_SETSELECTED:
|
case EVENT_SET_SELECTED:
|
||||||
result = HANDLED;
|
result = HANDLED;
|
||||||
break;
|
break;
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
|
|
16
MainPanel.c
16
MainPanel.c
|
@ -67,7 +67,21 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
|
||||||
|
|
||||||
Htop_Reaction reaction = HTOP_OK;
|
Htop_Reaction reaction = HTOP_OK;
|
||||||
|
|
||||||
if (ch != ERR && this->inc->active) {
|
if (EVENT_IS_HEADER_CLICK(ch)) {
|
||||||
|
int x = EVENT_HEADER_CLICK_GET_X(ch);
|
||||||
|
ProcessList* pl = this->state->pl;
|
||||||
|
Settings* settings = this->state->settings;
|
||||||
|
int hx = super->scrollH + x + 1;
|
||||||
|
ProcessField field = ProcessList_keyAt(pl, hx);
|
||||||
|
if (field == settings->sortKey) {
|
||||||
|
Settings_invertSortOrder(settings);
|
||||||
|
settings->treeView = false;
|
||||||
|
} else {
|
||||||
|
reaction |= Action_setSortKey(settings, field);
|
||||||
|
}
|
||||||
|
reaction |= HTOP_RECALCULATE;
|
||||||
|
result = HANDLED;
|
||||||
|
} else if (ch != ERR && this->inc->active) {
|
||||||
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
|
bool filterChanged = IncSet_handleKey(this->inc, ch, super, (IncMode_GetPanelValue) MainPanel_getValue, NULL);
|
||||||
if (filterChanged) {
|
if (filterChanged) {
|
||||||
this->state->pl->incFilter = IncSet_filter(this->inc);
|
this->state->pl->incFilter = IncSet_filter(this->inc);
|
||||||
|
|
10
Panel.c
10
Panel.c
|
@ -37,7 +37,11 @@ typedef enum HandlerResult_ {
|
||||||
SYNTH_KEY = 0x20,
|
SYNTH_KEY = 0x20,
|
||||||
} HandlerResult;
|
} HandlerResult;
|
||||||
|
|
||||||
#define EVENT_SETSELECTED -1
|
#define EVENT_SET_SELECTED -1
|
||||||
|
|
||||||
|
#define EVENT_HEADER_CLICK(x_) (-10000 + x_)
|
||||||
|
#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000)
|
||||||
|
#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000)
|
||||||
|
|
||||||
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
||||||
|
|
||||||
|
@ -88,7 +92,7 @@ PanelClass Panel_class = {
|
||||||
.extends = Class(Object),
|
.extends = Class(Object),
|
||||||
.delete = Panel_delete
|
.delete = Panel_delete
|
||||||
},
|
},
|
||||||
.eventHandler = Panel_selectByTyping
|
.eventHandler = Panel_selectByTyping,
|
||||||
};
|
};
|
||||||
|
|
||||||
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar) {
|
Panel* Panel_new(int x, int y, int w, int h, bool owner, ObjectClass* type, FunctionBar* fuBar) {
|
||||||
|
@ -250,7 +254,7 @@ void Panel_setSelected(Panel* this, int selected) {
|
||||||
selected = 0;
|
selected = 0;
|
||||||
this->selected = selected;
|
this->selected = selected;
|
||||||
if (Panel_eventHandlerFn(this)) {
|
if (Panel_eventHandlerFn(this)) {
|
||||||
Panel_eventHandler(this, EVENT_SETSELECTED);
|
Panel_eventHandler(this, EVENT_SET_SELECTED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
Panel.h
6
Panel.h
|
@ -26,7 +26,11 @@ typedef enum HandlerResult_ {
|
||||||
SYNTH_KEY = 0x20,
|
SYNTH_KEY = 0x20,
|
||||||
} HandlerResult;
|
} HandlerResult;
|
||||||
|
|
||||||
#define EVENT_SETSELECTED -1
|
#define EVENT_SET_SELECTED -1
|
||||||
|
|
||||||
|
#define EVENT_HEADER_CLICK(x_) (-10000 + x_)
|
||||||
|
#define EVENT_IS_HEADER_CLICK(ev_) (ev_ >= -10000 && ev_ <= -9000)
|
||||||
|
#define EVENT_HEADER_CLICK_GET_X(ev_) (ev_ + 10000)
|
||||||
|
|
||||||
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
typedef HandlerResult(*Panel_EventHandler)(Panel*, int);
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,9 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
int prevCh = ch;
|
int prevCh = ch;
|
||||||
ch = getch();
|
ch = getch();
|
||||||
|
|
||||||
|
HandlerResult result = IGNORED;
|
||||||
if (ch == KEY_MOUSE) {
|
if (ch == KEY_MOUSE) {
|
||||||
|
ch = ERR;
|
||||||
MEVENT mevent;
|
MEVENT mevent;
|
||||||
int ok = getmouse(&mevent);
|
int ok = getmouse(&mevent);
|
||||||
if (ok == OK) {
|
if (ok == OK) {
|
||||||
|
@ -199,38 +201,23 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < this->panelCount; i++) {
|
for (int i = 0; i < this->panelCount; i++) {
|
||||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||||
if (mevent.x > panel->x && mevent.x <= panel->x+panel->w &&
|
if (mevent.x >= panel->x && mevent.x <= panel->x+panel->w) {
|
||||||
mevent.y > panel->y && mevent.y <= panel->y+panel->h &&
|
if (mevent.y == panel->y) {
|
||||||
(this->allowFocusChange || panelFocus == panel) ) {
|
ch = EVENT_HEADER_CLICK(mevent.x - panel->x);
|
||||||
|
break;
|
||||||
|
} else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) {
|
||||||
|
if (panel == panelFocus || this->allowFocusChange) {
|
||||||
focus = i;
|
focus = i;
|
||||||
panelFocus = setCurrentPanel(panel);
|
panelFocus = setCurrentPanel(panel);
|
||||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||||
|
}
|
||||||
|
ch = KEY_MOUSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Panel_eventHandlerFn(panelFocus)) {
|
|
||||||
HandlerResult result = Panel_eventHandler(panelFocus, ch);
|
|
||||||
if (result & SYNTH_KEY) {
|
|
||||||
ch = result >> 16;
|
|
||||||
}
|
|
||||||
if (result & REDRAW) {
|
|
||||||
//redraw = true;
|
|
||||||
sortTimeout = 0;
|
|
||||||
}
|
|
||||||
if (result & RESCAN) {
|
|
||||||
rescan = true;
|
|
||||||
sortTimeout = 0;
|
|
||||||
}
|
|
||||||
if (result & HANDLED) {
|
|
||||||
redraw = true;
|
|
||||||
continue;
|
|
||||||
} else if (result & BREAK_LOOP) {
|
|
||||||
quit = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (ch == ERR) {
|
if (ch == ERR) {
|
||||||
sortTimeout--;
|
sortTimeout--;
|
||||||
|
@ -245,6 +232,25 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
redraw = true;
|
redraw = true;
|
||||||
|
if (Panel_eventHandlerFn(panelFocus)) {
|
||||||
|
result = Panel_eventHandler(panelFocus, ch);
|
||||||
|
}
|
||||||
|
if (result & SYNTH_KEY) {
|
||||||
|
ch = result >> 16;
|
||||||
|
}
|
||||||
|
if (result & REDRAW) {
|
||||||
|
sortTimeout = 0;
|
||||||
|
}
|
||||||
|
if (result & RESCAN) {
|
||||||
|
rescan = true;
|
||||||
|
sortTimeout = 0;
|
||||||
|
}
|
||||||
|
if (result & HANDLED) {
|
||||||
|
continue;
|
||||||
|
} else if (result & BREAK_LOOP) {
|
||||||
|
quit = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case KEY_RESIZE:
|
case KEY_RESIZE:
|
||||||
|
|
Loading…
Reference in New Issue