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
09c71529
Commit
09c71529
authored
Mar 22, 2015
by
Hisham Muhammad
Browse files
Refactor state control variables.
parent
4e064e0d
Changes
4
Hide whitespace changes
Inline
Side-by-side
MainPanel.c
View file @
09c71529
...
@@ -98,10 +98,10 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
...
@@ -98,10 +98,10 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
ProcessList_printHeader
(
this
->
state
->
pl
,
Panel_getHeader
(
super
));
ProcessList_printHeader
(
this
->
state
->
pl
,
Panel_getHeader
(
super
));
}
}
if
(
reaction
&
HTOP_REFRESH
)
{
if
(
reaction
&
HTOP_REFRESH
)
{
result
|=
RE
FRESH
;
result
|=
RE
DRAW
;
}
}
if
(
reaction
&
HTOP_RECALCULATE
)
{
if
(
reaction
&
HTOP_RECALCULATE
)
{
result
|=
RECA
LCULATE
;
result
|=
RE
S
CA
N
;
}
}
if
(
reaction
&
HTOP_SAVE_SETTINGS
)
{
if
(
reaction
&
HTOP_SAVE_SETTINGS
)
{
this
->
state
->
settings
->
changed
=
true
;
this
->
state
->
settings
->
changed
=
true
;
...
...
Panel.c
View file @
09c71529
...
@@ -31,8 +31,8 @@ typedef enum HandlerResult_ {
...
@@ -31,8 +31,8 @@ typedef enum HandlerResult_ {
HANDLED = 0x01,
HANDLED = 0x01,
IGNORED = 0x02,
IGNORED = 0x02,
BREAK_LOOP = 0x04,
BREAK_LOOP = 0x04,
RE
FRESH
= 0x08,
RE
DRAW
= 0x08,
RECA
LCULATE
= 0x10,
RE
S
CA
N
= 0x10,
SYNTH_KEY = 0x20,
SYNTH_KEY = 0x20,
} HandlerResult;
} HandlerResult;
...
...
Panel.h
View file @
09c71529
...
@@ -20,8 +20,8 @@ typedef enum HandlerResult_ {
...
@@ -20,8 +20,8 @@ typedef enum HandlerResult_ {
HANDLED
=
0x01
,
HANDLED
=
0x01
,
IGNORED
=
0x02
,
IGNORED
=
0x02
,
BREAK_LOOP
=
0x04
,
BREAK_LOOP
=
0x04
,
RE
FRESH
=
0x08
,
RE
DRAW
=
0x08
,
RECA
LCULATE
=
0x10
,
RE
S
CA
N
=
0x10
,
SYNTH_KEY
=
0x20
,
SYNTH_KEY
=
0x20
,
}
HandlerResult
;
}
HandlerResult
;
...
...
ScreenManager.c
View file @
09c71529
...
@@ -130,6 +130,45 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
...
@@ -130,6 +130,45 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
// TODO: VERTICAL
// TODO: VERTICAL
}
}
static
void
checkRecalculation
(
ScreenManager
*
this
,
double
*
oldTime
,
int
*
sortTimeout
,
bool
*
redraw
,
bool
*
rescan
,
bool
*
timedOut
)
{
ProcessList
*
pl
=
this
->
header
->
pl
;
struct
timeval
tv
;
gettimeofday
(
&
tv
,
NULL
);
double
newTime
=
((
double
)
tv
.
tv_sec
*
10
)
+
((
double
)
tv
.
tv_usec
/
100000
);
*
timedOut
=
(
newTime
-
*
oldTime
>
this
->
settings
->
delay
);
*
rescan
=
*
rescan
||
*
timedOut
;
if
(
newTime
<
*
oldTime
)
*
rescan
=
true
;
// clock was adjusted?
if
(
*
rescan
)
{
*
oldTime
=
newTime
;
ProcessList_scan
(
pl
);
if
(
*
sortTimeout
==
0
||
this
->
settings
->
treeView
)
{
ProcessList_sort
(
pl
);
*
sortTimeout
=
1
;
}
*
redraw
=
true
;
}
if
(
*
redraw
)
{
//pl->incFilter = IncSet_filter(inc);
ProcessList_rebuildPanel
(
pl
);
Header_draw
(
this
->
header
);
}
*
rescan
=
false
;
}
static
void
ScreenManager_drawPanels
(
ScreenManager
*
this
,
int
focus
)
{
int
nPanels
=
this
->
panelCount
;
for
(
int
i
=
0
;
i
<
nPanels
;
i
++
)
{
Panel
*
panel
=
(
Panel
*
)
Vector_get
(
this
->
panels
,
i
);
Panel_draw
(
panel
,
i
==
focus
);
if
(
i
<
nPanels
)
{
if
(
this
->
orientation
==
HORIZONTAL
)
{
mvvline
(
panel
->
y
,
panel
->
x
+
panel
->
w
,
' '
,
panel
->
h
+
1
);
}
}
}
}
void
ScreenManager_run
(
ScreenManager
*
this
,
Panel
**
lastFocus
,
int
*
lastKey
)
{
void
ScreenManager_run
(
ScreenManager
*
this
,
Panel
**
lastFocus
,
int
*
lastKey
)
{
bool
quit
=
false
;
bool
quit
=
false
;
int
focus
=
0
;
int
focus
=
0
;
...
@@ -138,56 +177,24 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -138,56 +177,24 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if
(
this
->
fuBar
)
if
(
this
->
fuBar
)
FunctionBar_draw
(
this
->
fuBar
,
NULL
);
FunctionBar_draw
(
this
->
fuBar
,
NULL
);
struct
timeval
tv
;
double
oldTime
=
0
.
0
;
double
oldTime
=
0
.
0
;
int
ch
=
ERR
;
int
ch
=
ERR
;
int
closeTimeout
=
0
;
int
closeTimeout
=
0
;
bool
drawPanel
=
true
;
bool
timedOut
=
true
;
bool
timeToRecalculate
=
true
;
bool
redraw
=
true
;
bool
doRefresh
=
true
;
bool
rescan
=
false
;
bool
forceRecalculate
=
false
;
int
sortTimeout
=
0
;
int
sortTimeout
=
0
;
int
resetSortTimeout
=
5
;
int
resetSortTimeout
=
5
;
while
(
!
quit
)
{
while
(
!
quit
)
{
int
panels
=
this
->
panelCount
;
if
(
this
->
header
)
{
if
(
this
->
header
)
{
gettimeofday
(
&
tv
,
NULL
);
checkRecalculation
(
this
,
&
oldTime
,
&
sortTimeout
,
&
redraw
,
&
rescan
,
&
timedOut
);
double
newTime
=
((
double
)
tv
.
tv_sec
*
10
)
+
((
double
)
tv
.
tv_usec
/
100000
);
timeToRecalculate
=
(
newTime
-
oldTime
>
this
->
settings
->
delay
);
if
(
newTime
<
oldTime
)
timeToRecalculate
=
true
;
// clock was adjusted?
if
(
doRefresh
)
{
if
(
timeToRecalculate
||
forceRecalculate
)
{
ProcessList_scan
(
this
->
header
->
pl
);
}
if
(
sortTimeout
==
0
||
this
->
settings
->
treeView
)
{
ProcessList_sort
(
this
->
header
->
pl
);
sortTimeout
=
1
;
}
//this->header->pl->incFilter = IncSet_filter(inc);
ProcessList_rebuildPanel
(
this
->
header
->
pl
);
drawPanel
=
true
;
}
if
(
timeToRecalculate
||
forceRecalculate
)
{
Header_draw
(
this
->
header
);
oldTime
=
newTime
;
forceRecalculate
=
false
;
}
doRefresh
=
true
;
}
}
if
(
drawPanel
)
{
if
(
redraw
)
{
for
(
int
i
=
0
;
i
<
panels
;
i
++
)
{
ScreenManager_drawPanels
(
this
,
focus
);
Panel
*
panel
=
(
Panel
*
)
Vector_get
(
this
->
panels
,
i
);
Panel_draw
(
panel
,
i
==
focus
);
if
(
i
<
panels
)
{
if
(
this
->
orientation
==
HORIZONTAL
)
{
mvvline
(
panel
->
y
,
panel
->
x
+
panel
->
w
,
' '
,
panel
->
h
+
1
);
}
}
}
}
}
FunctionBar
*
bar
=
(
FunctionBar
*
)
Vector_get
(
this
->
fuBars
,
focus
);
FunctionBar
*
bar
=
(
FunctionBar
*
)
Vector_get
(
this
->
fuBars
,
focus
);
...
@@ -225,16 +232,16 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -225,16 +232,16 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if
(
result
&
SYNTH_KEY
)
{
if
(
result
&
SYNTH_KEY
)
{
ch
=
result
>>
16
;
ch
=
result
>>
16
;
}
}
if
(
result
&
RE
FRESH
)
{
if
(
result
&
RE
DRAW
)
{
doRefresh
=
true
;
//redraw
= true;
sortTimeout
=
0
;
sortTimeout
=
0
;
}
}
if
(
result
&
RECA
LCULATE
)
{
if
(
result
&
RE
S
CA
N
)
{
forceRecalculate
=
true
;
rescan
=
true
;
sortTimeout
=
0
;
sortTimeout
=
0
;
}
}
if
(
result
&
HANDLED
)
{
if
(
result
&
HANDLED
)
{
draw
Panel
=
true
;
re
draw
=
true
;
continue
;
continue
;
}
else
if
(
result
&
BREAK_LOOP
)
{
}
else
if
(
result
&
BREAK_LOOP
)
{
quit
=
true
;
quit
=
true
;
...
@@ -243,17 +250,17 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
...
@@ -243,17 +250,17 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
}
}
if
(
ch
==
ERR
)
{
if
(
ch
==
ERR
)
{
sortTimeout
--
;
sortTimeout
--
;
if
(
prevCh
==
ch
&&
!
time
ToRecalculate
)
{
if
(
prevCh
==
ch
&&
!
time
dOut
)
{
closeTimeout
++
;
closeTimeout
++
;
if
(
closeTimeout
==
100
)
{
if
(
closeTimeout
==
100
)
{
break
;
break
;
}
}
}
else
}
else
closeTimeout
=
0
;
closeTimeout
=
0
;
draw
Panel
=
false
;
re
draw
=
false
;
continue
;
continue
;
}
}
draw
Panel
=
true
;
re
draw
=
true
;
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