Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
a93db523
Commit
a93db523
authored
Mar 24, 2015
by
Hisham Muhammad
Browse files
handle clicks on panel header line
parent
38fd1bfa
Changes
7
Hide whitespace changes
Inline
Side-by-side
Action.c
View file @
a93db523
...
...
@@ -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
)
{
...
...
Action.h
View file @
a93db523
...
...
@@ -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
);
...
...
CategoriesPanel.c
View file @
a93db523
...
...
@@ -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
:
...
...
MainPanel.c
View file @
a93db523
...
...
@@ -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
);
...
...
Panel.c
View file @
a93db523
...
...
@@ -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
);
}
}
...
...
Panel.h
View file @
a93db523
...
...
@@ -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
);
...
...
ScreenManager.c
View file @
a93db523
...
...
@@ -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
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment