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) {
ProcessList_printHeader
(
this
->
state
->
pl
,
Panel_getHeader
(
super
));
}
if
(
reaction
&
HTOP_REFRESH
)
{
result
|=
RE
FRESH
;
result
|=
RE
DRAW
;
}
if
(
reaction
&
HTOP_RECALCULATE
)
{
result
|=
RECA
LCULATE
;
result
|=
RE
S
CA
N
;
}
if
(
reaction
&
HTOP_SAVE_SETTINGS
)
{
this
->
state
->
settings
->
changed
=
true
;
...
...
Panel.c
View file @
09c71529
...
...
@@ -31,8 +31,8 @@ typedef enum HandlerResult_ {
HANDLED = 0x01,
IGNORED = 0x02,
BREAK_LOOP = 0x04,
RE
FRESH
= 0x08,
RECA
LCULATE
= 0x10,
RE
DRAW
= 0x08,
RE
S
CA
N
= 0x10,
SYNTH_KEY = 0x20,
} HandlerResult;
...
...
Panel.h
View file @
09c71529
...
...
@@ -20,8 +20,8 @@ typedef enum HandlerResult_ {
HANDLED
=
0x01
,
IGNORED
=
0x02
,
BREAK_LOOP
=
0x04
,
RE
FRESH
=
0x08
,
RECA
LCULATE
=
0x10
,
RE
DRAW
=
0x08
,
RE
S
CA
N
=
0x10
,
SYNTH_KEY
=
0x20
,
}
HandlerResult
;
...
...
ScreenManager.c
View file @
09c71529
...
...
@@ -130,6 +130,45 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) {
// 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
)
{
bool
quit
=
false
;
int
focus
=
0
;
...
...
@@ -138,56 +177,24 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if
(
this
->
fuBar
)
FunctionBar_draw
(
this
->
fuBar
,
NULL
);
struct
timeval
tv
;
double
oldTime
=
0
.
0
;
int
ch
=
ERR
;
int
closeTimeout
=
0
;
bool
drawPanel
=
true
;
bool
timeToRecalculate
=
true
;
bool
doRefresh
=
true
;
bool
forceRecalculate
=
false
;
bool
timedOut
=
true
;
bool
redraw
=
true
;
bool
rescan
=
false
;
int
sortTimeout
=
0
;
int
resetSortTimeout
=
5
;
while
(
!
quit
)
{
int
panels
=
this
->
panelCount
;
if
(
this
->
header
)
{
gettimeofday
(
&
tv
,
NULL
);
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
;
checkRecalculation
(
this
,
&
oldTime
,
&
sortTimeout
,
&
redraw
,
&
rescan
,
&
timedOut
);
}
if
(
drawPanel
)
{
for
(
int
i
=
0
;
i
<
panels
;
i
++
)
{
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
);
}
}
}
if
(
redraw
)
{
ScreenManager_drawPanels
(
this
,
focus
);
}
FunctionBar
*
bar
=
(
FunctionBar
*
)
Vector_get
(
this
->
fuBars
,
focus
);
...
...
@@ -225,16 +232,16 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if
(
result
&
SYNTH_KEY
)
{
ch
=
result
>>
16
;
}
if
(
result
&
RE
FRESH
)
{
doRefresh
=
true
;
if
(
result
&
RE
DRAW
)
{
//redraw
= true;
sortTimeout
=
0
;
}
if
(
result
&
RECA
LCULATE
)
{
forceRecalculate
=
true
;
if
(
result
&
RE
S
CA
N
)
{
rescan
=
true
;
sortTimeout
=
0
;
}
if
(
result
&
HANDLED
)
{
draw
Panel
=
true
;
re
draw
=
true
;
continue
;
}
else
if
(
result
&
BREAK_LOOP
)
{
quit
=
true
;
...
...
@@ -243,17 +250,17 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
}
if
(
ch
==
ERR
)
{
sortTimeout
--
;
if
(
prevCh
==
ch
&&
!
time
ToRecalculate
)
{
if
(
prevCh
==
ch
&&
!
time
dOut
)
{
closeTimeout
++
;
if
(
closeTimeout
==
100
)
{
break
;
}
}
else
closeTimeout
=
0
;
draw
Panel
=
false
;
re
draw
=
false
;
continue
;
}
draw
Panel
=
true
;
re
draw
=
true
;
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