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;
|
||||
}
|
||||
|
||||
static inline Htop_Reaction setSortKey(Settings* settings, ProcessField sortKey) {
|
||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey) {
|
||||
settings->sortKey = sortKey;
|
||||
settings->direction = 1;
|
||||
settings->treeView = false;
|
||||
|
@ -175,7 +175,7 @@ static Htop_Reaction sortBy(State* st) {
|
|||
}
|
||||
ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15);
|
||||
if (field) {
|
||||
reaction |= setSortKey(st->settings, field->key);
|
||||
reaction |= Action_setSortKey(st->settings, field->key);
|
||||
}
|
||||
Object_delete(sortPanel);
|
||||
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) {
|
||||
return setSortKey(st->settings, PERCENT_MEM);
|
||||
return Action_setSortKey(st->settings, PERCENT_MEM);
|
||||
}
|
||||
|
||||
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) {
|
||||
return setSortKey(st->settings, TIME);
|
||||
return Action_setSortKey(st->settings, TIME);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Htop_Reaction Action_setSortKey(Settings* settings, ProcessField sortKey);
|
||||
|
||||
// ----------------------------------------
|
||||
|
||||
void Action_setBindings(Htop_Action* keys);
|
||||
|
|
|
@ -78,7 +78,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
|
|||
|
||||
int selected = Panel_getSelectedIndex(super);
|
||||
switch (ch) {
|
||||
case EVENT_SETSELECTED:
|
||||
case EVENT_SET_SELECTED:
|
||||
result = HANDLED;
|
||||
break;
|
||||
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;
|
||||
|
||||
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);
|
||||
if (filterChanged) {
|
||||
this->state->pl->incFilter = IncSet_filter(this->inc);
|
||||
|
|
10
Panel.c
10
Panel.c
|
@ -37,7 +37,11 @@ typedef enum HandlerResult_ {
|
|||
SYNTH_KEY = 0x20,
|
||||
} 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);
|
||||
|
||||
|
@ -88,7 +92,7 @@ PanelClass Panel_class = {
|
|||
.extends = Class(Object),
|
||||
.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) {
|
||||
|
@ -250,7 +254,7 @@ void Panel_setSelected(Panel* this, int selected) {
|
|||
selected = 0;
|
||||
this->selected = selected;
|
||||
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,
|
||||
} 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);
|
||||
|
||||
|
|
|
@ -190,7 +190,9 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
int prevCh = ch;
|
||||
ch = getch();
|
||||
|
||||
HandlerResult result = IGNORED;
|
||||
if (ch == KEY_MOUSE) {
|
||||
ch = ERR;
|
||||
MEVENT mevent;
|
||||
int ok = getmouse(&mevent);
|
||||
if (ok == OK) {
|
||||
|
@ -199,38 +201,23 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
} else {
|
||||
for (int i = 0; i < this->panelCount; i++) {
|
||||
Panel* panel = (Panel*) Vector_get(this->panels, i);
|
||||
if (mevent.x > panel->x && mevent.x <= panel->x+panel->w &&
|
||||
mevent.y > panel->y && mevent.y <= panel->y+panel->h &&
|
||||
(this->allowFocusChange || panelFocus == panel) ) {
|
||||
if (mevent.x >= panel->x && mevent.x <= panel->x+panel->w) {
|
||||
if (mevent.y == panel->y) {
|
||||
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;
|
||||
panelFocus = setCurrentPanel(panel);
|
||||
Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
|
||||
}
|
||||
ch = KEY_MOUSE;
|
||||
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) {
|
||||
sortTimeout--;
|
||||
|
@ -245,6 +232,25 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
|
|||
continue;
|
||||
}
|
||||
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) {
|
||||
case KEY_RESIZE:
|
||||
|
|
Loading…
Reference in New Issue