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
d0c72c3f
Commit
d0c72c3f
authored
Mar 23, 2015
by
Hisham Muhammad
Browse files
Move FunctionBar inside Panel
parent
1084a3ff
Changes
27
Hide whitespace changes
Inline
Side-by-side
Action.c
View file @
d0c72c3f
...
...
@@ -61,18 +61,16 @@ typedef struct State_ {
}*/
Object
*
Action_pickFromVector
(
State
*
st
,
Panel
*
list
,
int
x
,
const
char
**
keyLabels
)
{
Object
*
Action_pickFromVector
(
State
*
st
,
Panel
*
list
,
int
x
)
{
Panel
*
panel
=
st
->
panel
;
Header
*
header
=
st
->
header
;
Settings
*
settings
=
st
->
settings
;
int
y
=
panel
->
y
;
const
char
*
fuKeys
[]
=
{
"Enter"
,
"Esc"
,
NULL
};
int
fuEvents
[]
=
{
13
,
27
};
ScreenManager
*
scr
=
ScreenManager_new
(
0
,
header
->
height
,
0
,
-
1
,
HORIZONTAL
,
header
,
settings
,
false
);
scr
->
allowFocusChange
=
false
;
ScreenManager_add
(
scr
,
list
,
FunctionBar_new
(
keyLabels
,
fuKeys
,
fuEvents
),
x
-
1
);
ScreenManager_add
(
scr
,
panel
,
NULL
,
-
1
);
ScreenManager_add
(
scr
,
list
,
x
-
1
);
ScreenManager_add
(
scr
,
panel
,
-
1
);
Panel
*
panelFocus
;
int
ch
;
bool
unfollow
=
false
;
...
...
@@ -100,12 +98,10 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, const char** keyLab
// ----------------------------------------
static
const
char
*
CategoriesFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
void
Action_runSetup
(
Settings
*
settings
,
const
Header
*
header
,
ProcessList
*
pl
)
{
ScreenManager
*
scr
=
ScreenManager_new
(
0
,
header
->
height
,
0
,
-
1
,
HORIZONTAL
,
header
,
settings
,
true
);
CategoriesPanel
*
panelCategories
=
CategoriesPanel_new
(
scr
,
settings
,
(
Header
*
)
header
,
pl
);
ScreenManager_add
(
scr
,
(
Panel
*
)
panelCategories
,
FunctionBar_new
(
CategoriesFunctions
,
NULL
,
NULL
),
16
);
ScreenManager_add
(
scr
,
(
Panel
*
)
panelCategories
,
16
);
CategoriesPanel_makeMetersPage
(
panelCategories
);
Panel
*
panelFocus
;
int
ch
;
...
...
@@ -165,11 +161,14 @@ static inline Htop_Reaction setSortKey(Settings* settings, ProcessField sortKey)
return
HTOP_REFRESH
|
HTOP_SAVE_SETTINGS
|
HTOP_UPDATE_PANELHDR
;
}
static
const
char
*
SortFunctions
[]
=
{
"Sort "
,
"Cancel "
,
NULL
};
static
const
char
*
SortKeys
[]
=
{
"Enter"
,
"Esc"
,
NULL
};
static
int
SortEvents
[]
=
{
13
,
27
};
static
Htop_Reaction
sortBy
(
State
*
st
)
{
Htop_Reaction
reaction
=
HTOP_OK
;
Panel
*
sortPanel
=
Panel_new
(
0
,
0
,
0
,
0
,
true
,
Class
(
ListItem
));
Panel
*
sortPanel
=
Panel_new
(
0
,
0
,
0
,
0
,
true
,
Class
(
ListItem
)
,
FunctionBar_new
(
SortFunctions
,
SortKeys
,
SortEvents
)
);
Panel_setHeader
(
sortPanel
,
"Sort by"
);
const
char
*
fuFunctions
[]
=
{
"Sort "
,
"Cancel "
,
NULL
};
ProcessField
*
fields
=
st
->
settings
->
fields
;
for
(
int
i
=
0
;
fields
[
i
];
i
++
)
{
char
*
name
=
String_trim
(
Process_fields
[
fields
[
i
]].
name
);
...
...
@@ -178,7 +177,7 @@ static Htop_Reaction sortBy(State* st) {
Panel_setSelected
(
sortPanel
,
i
);
free
(
name
);
}
ListItem
*
field
=
(
ListItem
*
)
Action_pickFromVector
(
st
,
sortPanel
,
15
,
fuFunctions
);
ListItem
*
field
=
(
ListItem
*
)
Action_pickFromVector
(
st
,
sortPanel
,
15
);
if
(
field
)
{
reaction
|=
setSortKey
(
st
->
settings
,
field
->
key
);
}
...
...
@@ -280,8 +279,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
Panel
*
affinityPanel
=
AffinityPanel_new
(
st
->
pl
,
affinity
);
Affinity_delete
(
affinity
);
const
char
*
fuFunctions
[]
=
{
"Set "
,
"Cancel "
,
NULL
};
void
*
set
=
Action_pickFromVector
(
st
,
affinityPanel
,
15
,
fuFunctions
);
void
*
set
=
Action_pickFromVector
(
st
,
affinityPanel
,
15
);
if
(
set
)
{
Affinity
*
affinity
=
AffinityPanel_getAffinity
(
affinityPanel
,
st
->
pl
);
bool
ok
=
MainPanel_foreachProcess
((
MainPanel
*
)
panel
,
(
MainPanel_ForeachProcessFn
)
Affinity_set
,
(
size_t
)
affinity
,
NULL
);
...
...
@@ -295,8 +293,7 @@ static Htop_Reaction actionSetAffinity(State* st) {
static
Htop_Reaction
actionKill
(
State
*
st
)
{
Panel
*
signalsPanel
=
(
Panel
*
)
SignalsPanel_new
();
const
char
*
fuFunctions
[]
=
{
"Send "
,
"Cancel "
,
NULL
};
ListItem
*
sgn
=
(
ListItem
*
)
Action_pickFromVector
(
st
,
signalsPanel
,
15
,
fuFunctions
);
ListItem
*
sgn
=
(
ListItem
*
)
Action_pickFromVector
(
st
,
signalsPanel
,
15
);
if
(
sgn
)
{
if
(
sgn
->
key
!=
0
)
{
Panel_setHeader
(
st
->
panel
,
"Sending..."
);
...
...
@@ -310,15 +307,18 @@ static Htop_Reaction actionKill(State* st) {
return
HTOP_REFRESH
|
HTOP_REDRAW_BAR
|
HTOP_UPDATE_PANELHDR
;
}
static
const
char
*
UsersFunctions
[]
=
{
"Show "
,
"Cancel "
,
NULL
};
static
const
char
*
UsersKeys
[]
=
{
"Enter"
,
"Esc"
,
NULL
};
static
int
UsersEvents
[]
=
{
13
,
27
};
static
Htop_Reaction
actionFilterByUser
(
State
*
st
)
{
Panel
*
usersPanel
=
Panel_new
(
0
,
0
,
0
,
0
,
true
,
Class
(
ListItem
));
Panel
*
usersPanel
=
Panel_new
(
0
,
0
,
0
,
0
,
true
,
Class
(
ListItem
)
,
FunctionBar_new
(
UsersFunctions
,
UsersKeys
,
UsersEvents
)
);
Panel_setHeader
(
usersPanel
,
"Show processes of:"
);
UsersTable_foreach
(
st
->
ut
,
addUserToVector
,
usersPanel
);
Vector_insertionSort
(
usersPanel
->
items
);
ListItem
*
allUsers
=
ListItem_new
(
"All users"
,
-
1
);
Panel_insert
(
usersPanel
,
0
,
(
Object
*
)
allUsers
);
const
char
*
fuFunctions
[]
=
{
"Show "
,
"Cancel "
,
NULL
};
ListItem
*
picked
=
(
ListItem
*
)
Action_pickFromVector
(
st
,
usersPanel
,
20
,
fuFunctions
);
ListItem
*
picked
=
(
ListItem
*
)
Action_pickFromVector
(
st
,
usersPanel
,
20
);
if
(
picked
)
{
if
(
picked
==
allUsers
)
{
st
->
pl
->
userId
=
-
1
;
...
...
Action.h
View file @
d0c72c3f
...
...
@@ -39,7 +39,7 @@ typedef struct State_ {
}
State
;
Object
*
Action_pickFromVector
(
State
*
st
,
Panel
*
list
,
int
x
,
const
char
**
keyLabels
);
Object
*
Action_pickFromVector
(
State
*
st
,
Panel
*
list
,
int
x
);
// ----------------------------------------
...
...
AffinityPanel.c
View file @
d0c72c3f
...
...
@@ -42,8 +42,12 @@ PanelClass AffinityPanel_class = {
.
eventHandler
=
AffinityPanel_eventHandler
};
static
const
char
*
AffinityFunctions
[]
=
{
"Set "
,
"Cancel "
,
NULL
};
static
const
char
*
AffinityKeys
[]
=
{
"Enter"
,
"Esc"
,
NULL
};
static
int
AffinityEvents
[]
=
{
13
,
27
};
Panel
*
AffinityPanel_new
(
ProcessList
*
pl
,
Affinity
*
affinity
)
{
Panel
*
this
=
Panel_new
(
1
,
1
,
1
,
1
,
true
,
Class
(
CheckItem
));
Panel
*
this
=
Panel_new
(
1
,
1
,
1
,
1
,
true
,
Class
(
CheckItem
)
,
FunctionBar_new
(
AffinityFunctions
,
AffinityKeys
,
AffinityEvents
)
);
Object_setClass
(
this
,
Class
(
AffinityPanel
));
Panel_setHeader
(
this
,
"Use CPUs:"
);
...
...
AvailableColumnsPanel.c
View file @
d0c72c3f
...
...
@@ -26,6 +26,8 @@ typedef struct AvailableColumnsPanel_ {
}*/
static
const
char
*
AvailableColumnsFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
"Add "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
void
AvailableColumnsPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
AvailableColumnsPanel
*
this
=
(
AvailableColumnsPanel
*
)
object
;
...
...
@@ -71,7 +73,8 @@ PanelClass AvailableColumnsPanel_class = {
AvailableColumnsPanel
*
AvailableColumnsPanel_new
(
Panel
*
columns
)
{
AvailableColumnsPanel
*
this
=
AllocThis
(
AvailableColumnsPanel
);
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
);
FunctionBar
*
fuBar
=
FunctionBar_new
(
AvailableColumnsFunctions
,
NULL
,
NULL
);
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
,
fuBar
);
Panel_setHeader
(
super
,
"Available Columns"
);
...
...
AvailableMetersPanel.c
View file @
d0c72c3f
...
...
@@ -34,6 +34,10 @@ typedef struct AvailableMetersPanel_ {
}*/
static
const
char
*
AvailableMetersFunctions
[]
=
{
"Add "
,
"Done "
,
NULL
};
static
const
char
*
AvailableMetersKeys
[]
=
{
"Enter"
,
"Esc"
};
static
int
AvailableMetersEvents
[]
=
{
13
,
27
};
static
void
AvailableMetersPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
AvailableMetersPanel
*
this
=
(
AvailableMetersPanel
*
)
object
;
...
...
@@ -102,7 +106,8 @@ PanelClass AvailableMetersPanel_class = {
AvailableMetersPanel
*
AvailableMetersPanel_new
(
Settings
*
settings
,
Header
*
header
,
Panel
*
leftMeters
,
Panel
*
rightMeters
,
ScreenManager
*
scr
,
ProcessList
*
pl
)
{
AvailableMetersPanel
*
this
=
AllocThis
(
AvailableMetersPanel
);
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
);
FunctionBar
*
fuBar
=
FunctionBar_new
(
AvailableMetersFunctions
,
AvailableMetersKeys
,
AvailableMetersEvents
);
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
,
fuBar
);
this
->
settings
=
settings
;
this
->
header
=
header
;
...
...
CategoriesPanel.c
View file @
d0c72c3f
...
...
@@ -34,21 +34,7 @@ typedef struct CategoriesPanel_ {
}*/
static
const
char
*
MetersFunctions
[]
=
{
"Type "
,
"Move "
,
"Delete"
,
"Done "
,
NULL
};
static
const
char
*
MetersKeys
[]
=
{
"Space"
,
"Enter"
,
"Del"
,
"Esc"
};
static
int
MetersEvents
[]
=
{
' '
,
13
,
27
,
KEY_DC
};
static
const
char
*
AvailableMetersFunctions
[]
=
{
"Add "
,
"Done "
,
NULL
};
static
const
char
*
AvailableMetersKeys
[]
=
{
"Enter"
,
"Esc"
};
static
int
AvailableMetersEvents
[]
=
{
13
,
27
};
static
const
char
*
DisplayOptionsFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
const
char
*
ColumnsFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"MoveUp"
,
"MoveDn"
,
"Remove"
,
"Done "
,
NULL
};
static
const
char
*
ColorsFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
const
char
*
AvailableColumnsFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
"Add "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
const
char
*
CategoriesFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
void
CategoriesPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
...
...
@@ -63,26 +49,26 @@ void CategoriesPanel_makeMetersPage(CategoriesPanel* this) {
leftMeters
->
rightNeighbor
=
rightMeters
;
rightMeters
->
leftNeighbor
=
leftMeters
;
Panel
*
availableMeters
=
(
Panel
*
)
AvailableMetersPanel_new
(
this
->
settings
,
this
->
header
,
(
Panel
*
)
leftMeters
,
(
Panel
*
)
rightMeters
,
this
->
scr
,
this
->
pl
);
ScreenManager_add
(
this
->
scr
,
(
Panel
*
)
leftMeters
,
FunctionBar_new
(
MetersFunctions
,
MetersKeys
,
MetersEvents
),
20
);
ScreenManager_add
(
this
->
scr
,
(
Panel
*
)
rightMeters
,
FunctionBar_new
(
MetersFunctions
,
MetersKeys
,
MetersEvents
),
20
);
ScreenManager_add
(
this
->
scr
,
availableMeters
,
FunctionBar_new
(
AvailableMetersFunctions
,
AvailableMetersKeys
,
AvailableMetersEvents
),
-
1
);
ScreenManager_add
(
this
->
scr
,
(
Panel
*
)
leftMeters
,
20
);
ScreenManager_add
(
this
->
scr
,
(
Panel
*
)
rightMeters
,
20
);
ScreenManager_add
(
this
->
scr
,
availableMeters
,
-
1
);
}
static
void
CategoriesPanel_makeDisplayOptionsPage
(
CategoriesPanel
*
this
)
{
Panel
*
displayOptions
=
(
Panel
*
)
DisplayOptionsPanel_new
(
this
->
settings
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
displayOptions
,
FunctionBar_new
(
DisplayOptionsFunctions
,
NULL
,
NULL
),
-
1
);
ScreenManager_add
(
this
->
scr
,
displayOptions
,
-
1
);
}
static
void
CategoriesPanel_makeColorsPage
(
CategoriesPanel
*
this
)
{
Panel
*
colors
=
(
Panel
*
)
ColorsPanel_new
(
this
->
settings
,
this
->
scr
);
ScreenManager_add
(
this
->
scr
,
colors
,
FunctionBar_new
(
ColorsFunctions
,
NULL
,
NULL
),
-
1
);
ScreenManager_add
(
this
->
scr
,
colors
,
-
1
);
}
static
void
CategoriesPanel_makeColumnsPage
(
CategoriesPanel
*
this
)
{
Panel
*
columns
=
(
Panel
*
)
ColumnsPanel_new
(
this
->
settings
);
Panel
*
availableColumns
=
(
Panel
*
)
AvailableColumnsPanel_new
(
columns
);
ScreenManager_add
(
this
->
scr
,
columns
,
FunctionBar_new
(
ColumnsFunctions
,
NULL
,
NULL
),
20
);
ScreenManager_add
(
this
->
scr
,
availableColumns
,
FunctionBar_new
(
AvailableColumnsFunctions
,
NULL
,
NULL
),
-
1
);
ScreenManager_add
(
this
->
scr
,
columns
,
20
);
ScreenManager_add
(
this
->
scr
,
availableColumns
,
-
1
);
}
static
HandlerResult
CategoriesPanel_eventHandler
(
Panel
*
super
,
int
ch
)
{
...
...
@@ -150,7 +136,8 @@ PanelClass CategoriesPanel_class = {
CategoriesPanel
*
CategoriesPanel_new
(
ScreenManager
*
scr
,
Settings
*
settings
,
Header
*
header
,
ProcessList
*
pl
)
{
CategoriesPanel
*
this
=
AllocThis
(
CategoriesPanel
);
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
);
FunctionBar
*
fuBar
=
FunctionBar_new
(
CategoriesFunctions
,
NULL
,
NULL
);
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
,
fuBar
);
this
->
scr
=
scr
;
this
->
settings
=
settings
;
...
...
ColorsPanel.c
View file @
d0c72c3f
...
...
@@ -34,6 +34,8 @@ typedef struct ColorsPanel_ {
}*/
static
const
char
*
ColorsFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
const
char
*
ColorSchemeNames
[]
=
{
"Default"
,
"Monochromatic"
,
...
...
@@ -94,7 +96,8 @@ PanelClass ColorsPanel_class = {
ColorsPanel
*
ColorsPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
)
{
ColorsPanel
*
this
=
AllocThis
(
ColorsPanel
);
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
CheckItem
),
true
);
FunctionBar
*
fuBar
=
FunctionBar_new
(
ColorsFunctions
,
NULL
,
NULL
);
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
CheckItem
),
true
,
fuBar
);
this
->
settings
=
settings
;
this
->
scr
=
scr
;
...
...
ColumnsPanel.c
View file @
d0c72c3f
...
...
@@ -28,6 +28,8 @@ typedef struct ColumnsPanel_ {
}*/
static
const
char
*
ColumnsFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"MoveUp"
,
"MoveDn"
,
"Remove"
,
"Done "
,
NULL
};
static
void
ColumnsPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
ColumnsPanel
*
this
=
(
ColumnsPanel
*
)
object
;
...
...
@@ -121,7 +123,8 @@ PanelClass ColumnsPanel_class = {
ColumnsPanel
*
ColumnsPanel_new
(
Settings
*
settings
)
{
ColumnsPanel
*
this
=
AllocThis
(
ColumnsPanel
);
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
);
FunctionBar
*
fuBar
=
FunctionBar_new
(
ColumnsFunctions
,
NULL
,
NULL
);
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
,
fuBar
);
this
->
settings
=
settings
;
this
->
moving
=
false
;
...
...
DisplayOptionsPanel.c
View file @
d0c72c3f
...
...
@@ -27,6 +27,8 @@ typedef struct DisplayOptionsPanel_ {
}*/
static
const
char
*
DisplayOptionsFunctions
[]
=
{
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
" "
,
"Done "
,
NULL
};
static
void
DisplayOptionsPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
DisplayOptionsPanel
*
this
=
(
DisplayOptionsPanel
*
)
object
;
...
...
@@ -72,7 +74,8 @@ PanelClass DisplayOptionsPanel_class = {
DisplayOptionsPanel
*
DisplayOptionsPanel_new
(
Settings
*
settings
,
ScreenManager
*
scr
)
{
DisplayOptionsPanel
*
this
=
AllocThis
(
DisplayOptionsPanel
);
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
CheckItem
),
true
);
FunctionBar
*
fuBar
=
FunctionBar_new
(
DisplayOptionsFunctions
,
NULL
,
NULL
);
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
CheckItem
),
true
,
fuBar
);
this
->
settings
=
settings
;
this
->
scr
=
scr
;
...
...
FunctionBar.c
View file @
d0c72c3f
...
...
@@ -6,19 +6,18 @@ in the source distribution for its full text.
*/
#include "FunctionBar.h"
#include "CRT.h"
#include "RichString.h"
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
/*{
#include "Object.h"
#include <stdbool.h>
typedef struct FunctionBar_ {
Object super;
int size;
char** functions;
char** keys;
...
...
@@ -34,12 +33,8 @@ static const char* FunctionBar_FLabels[] = {" ", " ", " ", "
static
int
FunctionBar_FEvents
[]
=
{
KEY_F
(
1
),
KEY_F
(
2
),
KEY_F
(
3
),
KEY_F
(
4
),
KEY_F
(
5
),
KEY_F
(
6
),
KEY_F
(
7
),
KEY_F
(
8
),
KEY_F
(
9
),
KEY_F
(
10
)};
ObjectClass
FunctionBar_class
=
{
.
delete
=
FunctionBar_delete
};
FunctionBar
*
FunctionBar_new
(
const
char
**
functions
,
const
char
**
keys
,
int
*
events
)
{
FunctionBar
*
this
=
A
lloc
This
(
FunctionBar
);
FunctionBar
*
this
=
ca
lloc
(
1
,
sizeof
(
FunctionBar
)
)
;
this
->
functions
=
calloc
(
16
,
sizeof
(
char
*
));
if
(
!
functions
)
{
functions
=
FunctionBar_FLabels
;
...
...
@@ -67,8 +62,7 @@ FunctionBar* FunctionBar_new(const char** functions, const char** keys, int* eve
return
this
;
}
void
FunctionBar_delete
(
Object
*
cast
)
{
FunctionBar
*
this
=
(
FunctionBar
*
)
cast
;
void
FunctionBar_delete
(
FunctionBar
*
this
)
{
for
(
int
i
=
0
;
i
<
15
&&
this
->
functions
[
i
];
i
++
)
{
free
(
this
->
functions
[
i
]);
}
...
...
FunctionBar.h
View file @
d0c72c3f
...
...
@@ -9,10 +9,10 @@ Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
#include "Object.h"
#include <stdbool.h>
typedef
struct
FunctionBar_
{
Object
super
;
int
size
;
char
**
functions
;
char
**
keys
;
...
...
@@ -21,11 +21,9 @@ typedef struct FunctionBar_ {
}
FunctionBar
;
extern
ObjectClass
FunctionBar_class
;
FunctionBar
*
FunctionBar_new
(
const
char
**
functions
,
const
char
**
keys
,
int
*
events
);
void
FunctionBar_delete
(
Object
*
cast
);
void
FunctionBar_delete
(
FunctionBar
*
this
);
void
FunctionBar_setLabel
(
FunctionBar
*
this
,
int
event
,
const
char
*
text
);
...
...
IncSet.c
View file @
d0c72c3f
...
...
@@ -73,7 +73,7 @@ static inline void IncMode_initFilter(IncMode* filter) {
}
static
inline
void
IncMode_done
(
IncMode
*
mode
)
{
FunctionBar_delete
(
(
Object
*
)
mode
->
bar
);
FunctionBar_delete
(
mode
->
bar
);
}
IncSet
*
IncSet_new
(
FunctionBar
*
bar
)
{
...
...
@@ -202,10 +202,11 @@ const char* IncSet_getListItemValue(Panel* panel, int i) {
return
""
;
}
void
IncSet_activate
(
IncSet
*
this
,
IncType
type
)
{
void
IncSet_activate
(
IncSet
*
this
,
IncType
type
,
FunctionBar
**
setBar
)
{
this
->
active
=
&
(
this
->
modes
[
type
]);
this
->
bar
=
this
->
active
->
bar
;
FunctionBar_draw
(
this
->
active
->
bar
,
this
->
active
->
buffer
);
setBar
=
}
void
IncSet_drawBar
(
IncSet
*
this
)
{
...
...
MainPanel.c
View file @
d0c72c3f
...
...
@@ -30,13 +30,15 @@ typedef bool(*MainPanel_ForeachProcessFn)(Process*, size_t);
}*/
void
MainPanel_updateTreeFunctions
(
FunctionBar
*
fuBar
,
bool
mode
)
{
static
const
char
*
MainFunctions
[]
=
{
"Help "
,
"Setup "
,
"Search"
,
"Filter"
,
"Tree "
,
"SortBy"
,
"Nice -"
,
"Nice +"
,
"Kill "
,
"Quit "
,
NULL
};
void
MainPanel_updateTreeFunctions
(
MainPanel
*
this
,
bool
mode
)
{
if
(
mode
)
{
FunctionBar_setLabel
(
fuBar
,
KEY_F
(
5
),
"Sorted"
);
FunctionBar_setLabel
(
fuBar
,
KEY_F
(
6
),
"Collap"
);
FunctionBar_setLabel
(
this
->
fuBar
,
KEY_F
(
5
),
"Sorted"
);
FunctionBar_setLabel
(
this
->
fuBar
,
KEY_F
(
6
),
"Collap"
);
}
else
{
FunctionBar_setLabel
(
fuBar
,
KEY_F
(
5
),
"Tree "
);
FunctionBar_setLabel
(
fuBar
,
KEY_F
(
6
),
"SortBy"
);
FunctionBar_setLabel
(
this
->
fuBar
,
KEY_F
(
5
),
"Tree "
);
FunctionBar_setLabel
(
this
->
fuBar
,
KEY_F
(
6
),
"SortBy"
);
}
}
...
...
@@ -98,7 +100,7 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) {
}
if
(
reaction
&
HTOP_REDRAW_BAR
)
{
MainPanel_updateTreeFunctions
(
this
->
fuBar
,
this
->
state
->
settings
->
treeView
);
MainPanel_updateTreeFunctions
(
this
,
this
->
state
->
settings
->
treeView
);
IncSet_drawBar
(
this
->
inc
);
}
if
(
reaction
&
HTOP_UPDATE_PANELHDR
)
{
...
...
@@ -165,12 +167,12 @@ PanelClass MainPanel_class = {
.
eventHandler
=
MainPanel_eventHandler
};
MainPanel
*
MainPanel_new
(
FunctionBar
*
fuBar
)
{
MainPanel
*
MainPanel_new
()
{
MainPanel
*
this
=
AllocThis
(
MainPanel
);
Panel_init
((
Panel
*
)
this
,
1
,
1
,
1
,
1
,
Class
(
Process
),
false
);
this
->
fuBar
=
FunctionBar_new
(
MainFunctions
,
NULL
,
NULL
);
Panel_init
((
Panel
*
)
this
,
1
,
1
,
1
,
1
,
Class
(
Process
),
false
,
this
->
fuBar
);
this
->
keys
=
calloc
(
KEY_MAX
,
sizeof
(
Htop_Action
));
this
->
fuBar
=
fuBar
;
this
->
inc
=
IncSet_new
(
fuBar
);
this
->
inc
=
IncSet_new
(
this
->
fuBar
);
Action_setBindings
(
this
->
keys
);
Platform_setBindings
(
this
->
keys
);
...
...
MainPanel.h
View file @
d0c72c3f
...
...
@@ -25,7 +25,7 @@ typedef struct MainPanel_ {
typedef
bool
(
*
MainPanel_ForeachProcessFn
)(
Process
*
,
size_t
);
void
MainPanel_updateTreeFunctions
(
FunctionBar
*
fuBar
,
bool
mode
);
void
MainPanel_updateTreeFunctions
(
MainPanel
*
this
,
bool
mode
);
void
MainPanel_pidSearch
(
MainPanel
*
this
,
int
ch
);
...
...
@@ -37,7 +37,7 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, in
extern
PanelClass
MainPanel_class
;
MainPanel
*
MainPanel_new
(
FunctionBar
*
fuBar
);
MainPanel
*
MainPanel_new
();
void
MainPanel_setState
(
MainPanel
*
this
,
State
*
state
);
...
...
MetersPanel.c
View file @
d0c72c3f
...
...
@@ -30,6 +30,10 @@ struct MetersPanel_ {
}*/
static
const
char
*
MetersFunctions
[]
=
{
"Type "
,
"Move "
,
"Delete"
,
"Done "
,
NULL
};
static
const
char
*
MetersKeys
[]
=
{
"Space"
,
"Enter"
,
"Del"
,
"Esc"
};
static
int
MetersEvents
[]
=
{
' '
,
13
,
27
,
KEY_DC
};
static
void
MetersPanel_delete
(
Object
*
object
)
{
Panel
*
super
=
(
Panel
*
)
object
;
MetersPanel
*
this
=
(
MetersPanel
*
)
object
;
...
...
@@ -172,7 +176,8 @@ PanelClass MetersPanel_class = {
MetersPanel
*
MetersPanel_new
(
Settings
*
settings
,
const
char
*
header
,
Vector
*
meters
,
ScreenManager
*
scr
)
{
MetersPanel
*
this
=
AllocThis
(
MetersPanel
);
Panel
*
super
=
(
Panel
*
)
this
;
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
);
FunctionBar
*
fuBar
=
FunctionBar_new
(
MetersFunctions
,
MetersKeys
,
MetersEvents
);
Panel_init
(
super
,
1
,
1
,
1
,
1
,
Class
(
ListItem
),
true
,
fuBar
);
this
->
settings
=
settings
;
this
->
meters
=
meters
;
...
...
OpenFilesScreen.c
View file @
d0c72c3f
...
...
@@ -12,6 +12,7 @@ in the source distribution for its full text.
#include "ListItem.h"
#include "IncSet.h"
#include "String.h"
#include "FunctionBar.h"
#include <string.h>
#include <stdio.h>
...
...
@@ -26,7 +27,6 @@ in the source distribution for its full text.
/*{
#include "Process.h"
#include "Panel.h"
#include "FunctionBar.h"
typedef struct OpenFiles_Data_ {
char* data[256];
...
...
@@ -47,21 +47,21 @@ typedef struct OpenFilesScreen_ {
Process* process;
pid_t pid;
Panel* display;
FunctionBar* bar;
} OpenFilesScreen;
}*/
static
const
char
*
ofs
Functions
[]
=
{
"Search "
,
"Filter "
,
"Refresh"
,
"Done "
,
NULL
};
static
const
char
*
OpenFilesScreen
Functions
[]
=
{
"Search "
,
"Filter "
,
"Refresh"
,
"Done "
,
NULL
};
static
const
char
*
ofs
Keys
[]
=
{
"F3"
,
"F4"
,
"F5"
,
"Esc"
};
static
const
char
*
OpenFilesScreen
Keys
[]
=
{
"F3"
,
"F4"
,
"F5"
,
"Esc"
};
static
int
ofs
Events
[]
=
{
KEY_F
(
3
),
KEY_F
(
4
),
KEY_F
(
5
),
27
};
static
int
OpenFilesScreen
Events
[]
=
{
KEY_F
(
3
),
KEY_F
(
4
),
KEY_F
(
5
),
27
};
OpenFilesScreen
*
OpenFilesScreen_new
(
Process
*
process
)
{
OpenFilesScreen
*
this
=
(
OpenFilesScreen
*
)
malloc
(
sizeof
(
OpenFilesScreen
));
this
->
process
=
process
;
this
->
display
=
Panel_new
(
0
,
1
,
COLS
,
LINES
-
3
,
false
,
Class
(
ListItem
));
FunctionBar
*
bar
=
FunctionBar_new
(
OpenFilesScreenFunctions
,
OpenFilesScreenKeys
,
OpenFilesScreenEvents
);
this
->
display
=
Panel_new
(
0
,
1
,
COLS
,
LINES
-
3
,
false
,
Class
(
ListItem
),
bar
);
if
(
Process_isThread
(
process
))
this
->
pid
=
process
->
tgid
;
else
...
...
@@ -173,7 +173,7 @@ void OpenFilesScreen_run(OpenFilesScreen* this) {
Panel
*
panel
=
this
->
display
;
Panel_setHeader
(
panel
,
" FD TYPE DEVICE SIZE NODE NAME"
);
FunctionBar
*
bar
=
FunctionBar_new
(
ofsFunctions
,
ofsKeys
,
ofsEvents
)
;
FunctionBar
*
bar
=
panel
->
defaultBar
;
IncSet
*
inc
=
IncSet_new
(
bar
);
Vector
*
lines
=
Vector_new
(
panel
->
items
->
type
,
true
,
DEFAULT_SIZE
);
...
...
@@ -241,6 +241,5 @@ void OpenFilesScreen_run(OpenFilesScreen* this) {
}
Vector_delete
(
lines
);
FunctionBar_delete
((
Object
*
)
bar
);
IncSet_delete
(
inc
);
}
OpenFilesScreen.h
View file @
d0c72c3f
...
...
@@ -11,7 +11,6 @@ in the source distribution for its full text.
#include "Process.h"
#include "Panel.h"
#include "FunctionBar.h"
typedef
struct
OpenFiles_Data_
{
char
*
data
[
256
];
...
...
@@ -32,7 +31,6 @@ typedef struct OpenFilesScreen_ {
Process
*
process
;
pid_t
pid
;
Panel
*
display
;
FunctionBar
*
bar
;
}
OpenFilesScreen
;
...
...
Panel.c
View file @
d0c72c3f
...
...
@@ -24,6 +24,7 @@ in the source distribution for its full text.
/*{
#include "Object.h"
#include "Vector.h"
#include "FunctionBar.h"
typedef struct Panel_ Panel;
...
...
@@ -61,6 +62,8 @@ struct Panel_ {
int scrollV;
short scrollH;
bool needsRedraw;
FunctionBar* currentBar;
FunctionBar* defaultBar;
RichString header;
};
...
...
@@ -86,11 +89,11 @@ PanelClass Panel_class = {
.
eventHandler
=
Panel_selectByTyping
};
Panel
*
Panel_new
(
int
x
,
int
y
,
int
w
,
int
h
,
bool
owner
,
ObjectClass
*
type
)
{
Panel
*
Panel_new
(
int
x
,
int
y
,
int
w
,
int
h
,
bool
owner
,
ObjectClass
*
type
,
FunctionBar
*
fuBar
)
{
Panel
*
this
;
this
=
malloc
(
sizeof
(
Panel
));
Object_setClass
(
this
,
Class
(
Panel
));
Panel_init
(
this
,
x
,
y
,
w
,
h
,
type
,
owner
);
Panel_init
(
this
,
x
,
y
,
w
,
h
,
type
,
owner
,
fuBar
);
return
this
;
}
...
...
@@ -100,7 +103,7 @@ void Panel_delete(Object* cast) {
free
(
this
);
}
void
Panel_init
(
Panel
*
this
,
int
x
,
int
y
,
int
w
,
int
h
,
ObjectClass
*
type
,
bool
owner
)
{
void
Panel_init
(
Panel
*
this
,
int
x
,
int
y
,
int
w
,
int
h
,
ObjectClass
*
type
,
bool
owner
,
FunctionBar
*
fuBar
)
{
this
->
x
=
x
;
this
->
y
=
y
;
this
->
w
=
w
;
...
...
@@ -113,12 +116,15 @@ void Panel_init(Panel* this, int x, int y, int w, int h, ObjectClass* type, bool
this
->
oldSelected
=
0
;
this
->
needsRedraw
=
true
;
RichString_beginAllocated
(
this
->
header
);
this
->
defaultBar
=
fuBar
;
this
->
currentBar
=
fuBar
;
}
void
Panel_done
(
Panel
*
this
)
{
assert
(
this
!=
NULL
);
free
(
this
->
eventHandlerState
);
Vector_delete
(
this
->
items
);
FunctionBar_delete
(
this
->
defaultBar
);
RichString_end
(
this
->
header
);
}
...
...
Panel.h
View file @
d0c72c3f
...
...
@@ -13,6 +13,7 @@ in the source distribution for its full text.
#include "Object.h"
#include "Vector.h"
#include "FunctionBar.h"
typedef
struct
Panel_
Panel
;
...
...
@@ -50,6 +51,8 @@ struct Panel_ {
int
scrollV
;
short
scrollH
;
bool
needsRedraw
;
FunctionBar
*
currentBar
;
FunctionBar
*
defaultBar
;
RichString
header
;
};
...
...
@@ -68,11 +71,11 @@ struct Panel_ {
extern
PanelClass
Panel_class
;
Panel
*
Panel_new
(
int
x
,
int
y
,
int
w
,
int
h
,
bool
owner
,
ObjectClass
*
type
);
Panel
*
Panel_new
(
int
x
,
int
y
,
int
w
,
int
h
,
bool
owner
,
ObjectClass
*
type
,
FunctionBar
*
fuBar
);
void
Panel_delete
(
Object
*
cast
);
void
Panel_init
(
Panel
*
this
,
int
x
,
int
y
,
int
w
,
int
h
,
ObjectClass
*
type
,
bool
owner
);
void
Panel_init
(
Panel
*
this
,
int
x
,
int
y
,
int
w
,
int
h
,
ObjectClass
*
type
,
bool
owner
,
FunctionBar
*
fuBar
);
void
Panel_done
(
Panel
*
this
);
...
...
ScreenManager.c
View file @
d0c72c3f
...
...
@@ -34,9 +34,7 @@ typedef struct ScreenManager_ {
int y2;
Orientation orientation;
Vector* panels;
Vector* fuBars;
int panelCount;
const FunctionBar* fuBar;
const Header* header;
const Settings* settings;
bool owner;
...
...
@@ -52,10 +50,8 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
this
->
y1
=
y1
;
this
->
x2
=
x2
;
this
->
y2
=
y2
;
this
->
fuBar
=
NULL
;
this
->
orientation
=
orientation
;
this
->
panels
=
Vector_new
(
Class
(
Panel
),
owner
,
DEFAULT_SIZE
);
this
->
fuBars
=
Vector_new
(
Class
(
FunctionBar
),
true
,
DEFAULT_SIZE
);
this
->
panelCount
=
0
;
this
->
header
=
header
;
this
->
settings
=
settings
;
...
...
@@ -66,7 +62,6 @@ ScreenManager* ScreenManager_new(int x1, int y1, int x2, int y2, Orientation ori
void
ScreenManager_delete
(
ScreenManager
*
this
)
{
Vector_delete
(
this
->
panels
);
Vector_delete
(
this
->
fuBars
);
free
(
this
);
}
...
...
@@ -74,7 +69,7 @@ inline int ScreenManager_size(ScreenManager* this) {
return
this
->
panelCount
;
}
void
ScreenManager_add
(
ScreenManager
*
this
,
Panel
*
item
,
FunctionBar
*
fuBar
,
int
size
)
{
void
ScreenManager_add
(
ScreenManager
*
this
,
Panel
*
item
,
int
size
)
{
if
(
this
->
orientation
==
HORIZONTAL
)
{
int
lastX
=
0
;
if
(
this
->
panelCount
>
0
)
{
...
...
@@ -91,11 +86,6 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int
}
// TODO: VERTICAL
Vector_add
(
this
->
panels
,
item
);
if
(
fuBar
)
Vector_add
(
this
->
fuBars
,
fuBar
);
else
Vector_add
(
this
->
fuBars
,
FunctionBar_new
(
NULL
,
NULL
,
NULL
));
if
(
!
this
->
fuBar
&&
fuBar
)
this
->
fuBar
=
fuBar
;
item
->
needsRedraw
=
true
;
this
->
panelCount
++
;
}
...
...
@@ -103,8 +93,6 @@ void ScreenManager_add(ScreenManager* this, Panel* item, FunctionBar* fuBar, int
Panel
*
ScreenManager_remove
(
ScreenManager
*
this
,
int
idx
)
{
assert
(
this
->
panelCount
>
idx
);
Panel
*
panel
=
(
Panel
*
)
Vector_remove
(
this
->
panels
,
idx
);
Vector_remove
(
this
->
fuBars
,
idx
);
this
->
fuBar
=
NULL
;
this
->
panelCount
--
;
return
panel
;
}
...
...
@@ -173,8 +161,6 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
int
focus
=
0
;
Panel
*
panelFocus
=
(
Panel
*
)
Vector_get
(
this
->
panels
,
focus
);
if
(
this
->
fuBar
)
FunctionBar_draw
(
this
->
fuBar
,
NULL
);
double
oldTime
=
0
.
0
;
...
...
@@ -194,11 +180,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
if
(
redraw
)
{
ScreenManager_drawPanels
(
this
,
focus
);
FunctionBar
*
bar
=
(
FunctionBar
*
)
Vector_get
(
this
->
fuBars
,
focus
);
if
(
bar
)
this
->
fuBar
=
bar
;
if
(
this
->
fuBar
)
FunctionBar_draw
(
this
->
fuBar
,
NULL
);
FunctionBar_draw
(
panelFocus
->
currentBar
,
NULL
);
}
int
prevCh
=
ch
;
...
...
@@ -209,7 +191,7 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) {
int
ok
=
getmouse
(
&
mevent
);
if
(
ok
==
OK
)
{
if
(
mevent
.
y
==
LINES
-
1
)
{
ch
=
FunctionBar_synthesizeEvent
(
this
->
fu
Bar
,
mevent
.
x
);
ch
=
FunctionBar_synthesizeEvent
(
panelFocus
->
current
Bar
,
mevent
.
x
);
}
else
{
for
(
int
i
=
0
;
i
<
this
->
panelCount
;
i
++
)
{
Panel
*
panel
=
(
Panel
*
)
Vector_get
(
this
->
panels
,
i
);
...
...
Prev
1
2
Next
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