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) {
...
@@ -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) {
...
@@ -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) {
...
@@ -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
)
{
...
...
Action.h
View file @
a93db523
...
@@ -45,6 +45,8 @@ Object* Action_pickFromVector(State* st, Panel* list, int x);
...
@@ -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
);
...
...
CategoriesPanel.c
View file @
a93db523
...
@@ -78,7 +78,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) {
...
@@ -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
:
...
...
MainPanel.c
View file @
a93db523
...
@@ -67,7 +67,21 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
...
@@ -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
);
...
...
Panel.c
View file @
a93db523
...
@@ -37,7 +37,11 @@ typedef enum HandlerResult_ {
...
@@ -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 = {
...
@@ -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) {
...
@@ -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
);
}
}
}
}
...
...
Panel.h
View file @
a93db523
...
@@ -26,7 +26,11 @@ typedef enum HandlerResult_ {
...
@@ -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
);
...
...
ScreenManager.c
View file @
a93db523
...
@@ -190,7 +190,9 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -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,39 +201,24 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -199,39 +201,24 @@ 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
);
focus
=
i
;
break
;
panelFocus
=
setCurrentPanel
(
panel
);
}
else
if
(
mevent
.
y
>
panel
->
y
&&
mevent
.
y
<=
panel
->
y
+
panel
->
h
)
{
Panel_setSelected
(
panel
,
mevent
.
y
-
panel
->
y
+
panel
->
scrollV
-
1
);
if
(
panel
==
panelFocus
||
this
->
allowFocusChange
)
{
break
;
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
)
{
if
(
ch
==
ERR
)
{
sortTimeout
--
;
sortTimeout
--
;
if
(
prevCh
==
ch
&&
!
timedOut
)
{
if
(
prevCh
==
ch
&&
!
timedOut
)
{
...
@@ -245,6 +232,25 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -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
:
...
...
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