summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHisham Muhammad <hisham@gobolinux.org>2015-03-24 23:12:43 -0300
committerHisham Muhammad <hisham@gobolinux.org>2015-03-24 23:12:43 -0300
commita93db5234c8e24c56c4b5b615de837afeeac5e74 (patch)
treef68394fa63113bc62798e1e9fff66caaae1a7f8a
parent38fd1bfaba8b742d476a146ee111bf24cce9193e (diff)
handle clicks on panel header line
-rw-r--r--Action.c10
-rw-r--r--Action.h2
-rw-r--r--CategoriesPanel.c2
-rw-r--r--MainPanel.c16
-rw-r--r--Panel.c10
-rw-r--r--Panel.h6
-rw-r--r--ScreenManager.c62
7 files changed, 69 insertions, 39 deletions
diff --git a/Action.c b/Action.c
index 6e01a295..67231f1f 100644
--- a/Action.c
+++ b/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) {
diff --git a/Action.h b/Action.h
index 2c7d2063..8927ce2f 100644
--- a/Action.h
+++ b/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);
diff --git a/CategoriesPanel.c b/CategoriesPanel.c
index 8cb442e4..d67be86a 100644
--- a/CategoriesPanel.c
+++ b/CategoriesPanel.c
@@ -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:
diff --git a/MainPanel.c b/MainPanel.c
index 9927dee3..6276edbf 100644
--- a/MainPanel.c
+++ b/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);
diff --git a/Panel.c b/Panel.c
index 42c5ef2f..ccf6ba68 100644
--- a/Panel.c
+++ b/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);
}
}
diff --git a/Panel.h b/Panel.h
index 21428418..71740bf6 100644
--- a/Panel.h
+++ b/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);
diff --git a/ScreenManager.c b/ScreenManager.c
index e0993612..c9253c3f 100644
--- a/ScreenManager.c
+++ b/ScreenManager.c
@@ -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,39 +201,24 @@ 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) ) {
- focus = i;
- panelFocus = setCurrentPanel(panel);
- Panel_setSelected(panel, mevent.y - panel->y + panel->scrollV - 1);
- break;
+ 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--;
if (prevCh == ch && !timedOut) {
@@ -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:

© 2014-2024 Faster IT GmbH | imprint | privacy policy