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
9ff5d2b2
Commit
9ff5d2b2
authored
Mar 16, 2015
by
Hisham Muhammad
Browse files
Fix saving of header states, motion in Setup screen.
parent
14a17780
Changes
8
Hide whitespace changes
Inline
Side-by-side
Action.c
View file @
9ff5d2b2
...
...
@@ -112,6 +112,9 @@ static void Action_runSetup(Settings* settings, const Header* header, ProcessLis
int
ch
;
ScreenManager_run
(
scr
,
&
panelFocus
,
&
ch
);
ScreenManager_delete
(
scr
);
if
(
settings
->
changed
)
{
Header_writeBackToSettings
(
header
);
}
}
static
bool
changePriority
(
MainPanel
*
panel
,
int
delta
)
{
...
...
AvailableMetersPanel.c
View file @
9ff5d2b2
...
...
@@ -43,7 +43,7 @@ static void AvailableMetersPanel_delete(Object* object) {
static
inline
void
AvailableMetersPanel_addMeter
(
Header
*
header
,
Panel
*
panel
,
MeterClass
*
type
,
int
param
,
int
column
)
{
Meter
*
meter
=
(
Meter
*
)
Header_addMeterByClass
(
header
,
type
,
param
,
column
);
Panel_add
(
panel
,
(
Object
*
)
Meter_toListItem
(
meter
));
Panel_add
(
panel
,
(
Object
*
)
Meter_toListItem
(
meter
,
false
));
Panel_setSelected
(
panel
,
Panel_size
(
panel
)
-
1
);
((
MetersPanel
*
)
panel
)
->
moving
=
true
;
((
ListItem
*
)
Panel_getSelected
(
panel
))
->
moving
=
true
;
...
...
Header.c
View file @
9ff5d2b2
...
...
@@ -65,12 +65,41 @@ void Header_populateFromSettings(Header* this) {
MeterColumnSettings
*
colSettings
=
&
this
->
settings
->
columns
[
col
];
for
(
int
i
=
0
;
i
<
colSettings
->
len
;
i
++
)
{
Header_addMeterByName
(
this
,
colSettings
->
names
[
i
],
col
);
Header_setMode
(
this
,
i
,
colSettings
->
modes
[
i
],
col
);
if
(
colSettings
->
modes
[
i
]
!=
0
)
{
Header_setMode
(
this
,
i
,
colSettings
->
modes
[
i
],
col
);
}
}
}
Header_calculateHeight
(
this
);
}
void
Header_writeBackToSettings
(
const
Header
*
this
)
{
Header_forEachColumn
(
this
,
col
)
{
MeterColumnSettings
*
colSettings
=
&
this
->
settings
->
columns
[
col
];
String_freeArray
(
colSettings
->
names
);
free
(
colSettings
->
modes
);
Vector
*
vec
=
this
->
columns
[
col
];
int
len
=
Vector_size
(
vec
);
colSettings
->
names
=
calloc
(
len
+
1
,
sizeof
(
char
*
));
colSettings
->
modes
=
calloc
(
len
,
sizeof
(
int
));
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
vec
,
i
);
char
*
name
=
calloc
(
64
,
sizeof
(
char
*
));
if
(
meter
->
param
)
{
snprintf
(
name
,
63
,
"%s(%d)"
,
As_Meter
(
meter
)
->
name
,
meter
->
param
);
}
else
{
snprintf
(
name
,
63
,
"%s"
,
As_Meter
(
meter
)
->
name
);
}
colSettings
->
names
[
i
]
=
name
;
colSettings
->
modes
[
i
]
=
meter
->
mode
;
}
}
}
MeterModeId
Header_addMeterByName
(
Header
*
this
,
char
*
name
,
int
column
)
{
Vector
*
meters
=
this
->
columns
[
column
];
...
...
Header.h
View file @
9ff5d2b2
...
...
@@ -37,6 +37,8 @@ void Header_delete(Header* this);
void
Header_populateFromSettings
(
Header
*
this
);
void
Header_writeBackToSettings
(
const
Header
*
this
);
MeterModeId
Header_addMeterByName
(
Header
*
this
,
char
*
name
,
int
column
);
void
Header_setMode
(
Header
*
this
,
int
i
,
MeterModeId
mode
,
int
column
);
...
...
Meter.c
View file @
9ff5d2b2
...
...
@@ -191,7 +191,7 @@ void Meter_setMode(Meter* this, int modeIndex) {
this
->
mode
=
modeIndex
;
}
ListItem
*
Meter_toListItem
(
Meter
*
this
)
{
ListItem
*
Meter_toListItem
(
Meter
*
this
,
bool
moving
)
{
char
mode
[
21
];
if
(
this
->
mode
)
snprintf
(
mode
,
20
,
" [%s]"
,
Meter_modes
[
this
->
mode
]
->
uiName
);
...
...
@@ -204,7 +204,9 @@ ListItem* Meter_toListItem(Meter* this) {
number
[
0
]
=
'\0'
;
char
buffer
[
51
];
snprintf
(
buffer
,
50
,
"%s%s%s"
,
Meter_uiName
(
this
),
number
,
mode
);
return
ListItem_new
(
buffer
,
0
);
ListItem
*
li
=
ListItem_new
(
buffer
,
0
);
li
->
moving
=
moving
;
return
li
;
}
/* ---------- TextMeterMode ---------- */
...
...
Meter.h
View file @
9ff5d2b2
...
...
@@ -111,7 +111,7 @@ void Meter_setCaption(Meter* this, const char* caption);
void
Meter_setMode
(
Meter
*
this
,
int
modeIndex
);
ListItem
*
Meter_toListItem
(
Meter
*
this
);
ListItem
*
Meter_toListItem
(
Meter
*
this
,
bool
moving
);
/* ---------- TextMeterMode ---------- */
...
...
MetersPanel.c
View file @
9ff5d2b2
...
...
@@ -40,16 +40,17 @@ static void MetersPanel_delete(Object* object) {
static
inline
bool
moveToNeighbor
(
MetersPanel
*
this
,
MetersPanel
*
neighbor
,
int
selected
)
{
Panel
*
super
=
(
Panel
*
)
this
;
if
(
this
->
moving
)
{
this
->
moving
=
false
;
((
ListItem
*
)
Panel_getSelected
(
super
))
->
moving
=
false
;
if
(
neighbor
)
{
if
(
selected
<
Vector_size
(
this
->
meters
))
{
((
ListItem
*
)
Panel_getSelected
(
super
))
->
moving
=
false
;
Meter
*
meter
=
(
Meter
*
)
Vector_take
(
this
->
meters
,
selected
);
Panel_remove
(
super
,
selected
);
Vector_insert
(
neighbor
->
meters
,
selected
,
meter
);
Panel_insert
(
&
(
neighbor
->
super
),
selected
,
(
Object
*
)
Meter_toListItem
(
meter
));
Panel_insert
(
&
(
neighbor
->
super
),
selected
,
(
Object
*
)
Meter_toListItem
(
meter
,
false
));
Panel_setSelected
(
&
(
neighbor
->
super
),
selected
);
this
->
moving
=
false
;
neighbor
->
moving
=
true
;
((
ListItem
*
)
Panel_getSelected
((
Panel
*
)
neighbor
))
->
moving
=
true
;
return
true
;
...
...
@@ -84,7 +85,7 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
int
mode
=
meter
->
mode
+
1
;
if
(
mode
==
LAST_METERMODE
)
mode
=
1
;
Meter_setMode
(
meter
,
mode
);
Panel_set
(
super
,
selected
,
(
Object
*
)
Meter_toListItem
(
meter
));
Panel_set
(
super
,
selected
,
(
Object
*
)
Meter_toListItem
(
meter
,
this
->
moving
));
result
=
HANDLED
;
break
;
}
...
...
@@ -123,13 +124,20 @@ static HandlerResult MetersPanel_eventHandler(Panel* super, int ch) {
case
KEY_RIGHT
:
{
sideMove
=
moveToNeighbor
(
this
,
this
->
rightNeighbor
,
selected
);
// don't set HANDLED; let ScreenManager handle focus.
if
(
this
->
moving
&&
!
sideMove
)
{
// lock user here until it exits positioning-mode
result
=
HANDLED
;
}
// if user is free, don't set HANDLED;
// let ScreenManager handle focus.
break
;
}
case
KEY_LEFT
:
{
sideMove
=
moveToNeighbor
(
this
,
this
->
leftNeighbor
,
selected
);
// don't set HANDLED; let ScreenManager handle focus.
if
(
this
->
moving
&&
!
sideMove
)
{
result
=
HANDLED
;
}
break
;
}
case
KEY_F
(
9
):
...
...
@@ -175,7 +183,7 @@ MetersPanel* MetersPanel_new(Settings* settings, const char* header, Vector* met
Panel_setHeader
(
super
,
header
);
for
(
int
i
=
0
;
i
<
Vector_size
(
meters
);
i
++
)
{
Meter
*
meter
=
(
Meter
*
)
Vector_get
(
meters
,
i
);
Panel_add
(
super
,
(
Object
*
)
Meter_toListItem
(
meter
));
Panel_add
(
super
,
(
Object
*
)
Meter_toListItem
(
meter
,
false
));
}
return
this
;
}
Settings.c
View file @
9ff5d2b2
...
...
@@ -109,6 +109,7 @@ static void Settings_defaultMeters(Settings* this, int cpuCount) {
for
(
int
i
=
0
;
i
<
2
;
i
++
)
{
this
->
columns
[
i
].
names
=
calloc
(
sizes
[
i
],
sizeof
(
char
*
));
this
->
columns
[
i
].
modes
=
calloc
(
sizes
[
i
],
sizeof
(
int
));
this
->
columns
[
i
].
len
=
sizes
[
i
];
}
int
r
=
0
;
...
...
@@ -371,6 +372,7 @@ Settings* Settings_new(int cpuCount) {
this
->
hideKernelThreads
=
true
;
this
->
highlightMegabytes
=
true
;
this
->
highlightThreads
=
false
;
this
->
headerMargin
=
true
;
}
}
free
(
legacyDotfile
);
...
...
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