Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tray
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vladislav
tray
Commits
b677473c
Commit
b677473c
authored
Jan 12, 2017
by
Serge A. Zaitsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplified recusrive menus (gtk)
parent
721107bf
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
58 deletions
+27
-58
tray.h
tray.h
+27
-58
No files found.
tray.h
View file @
b677473c
...
...
@@ -36,6 +36,31 @@ static void _tray_menu_cb(GtkMenuItem *item, gpointer data) {
m
->
cb
(
m
);
}
static
GtkMenuShell
*
_tray_menu
(
struct
tray_menu
*
m
)
{
GtkMenuShell
*
menu
=
(
GtkMenuShell
*
)
gtk_menu_new
();
for
(;
m
!=
NULL
&&
m
->
text
!=
NULL
;
m
++
)
{
GtkWidget
*
item
;
if
(
strcmp
(
m
->
text
,
"-"
)
==
0
)
{
item
=
gtk_separator_menu_item_new
();
}
else
{
if
(
m
->
submenu
!=
NULL
)
{
item
=
gtk_menu_item_new_with_label
(
m
->
text
);
gtk_menu_item_set_submenu
(
GTK_MENU_ITEM
(
item
),
GTK_WIDGET
(
_tray_menu
(
m
->
submenu
)));
}
else
{
item
=
gtk_check_menu_item_new_with_label
(
m
->
text
);
gtk_check_menu_item_set_active
(
GTK_CHECK_MENU_ITEM
(
item
),
!!
m
->
checked
);
}
gtk_widget_set_sensitive
(
item
,
!
m
->
disabled
);
if
(
m
->
cb
!=
NULL
)
{
g_signal_connect
(
item
,
"activate"
,
G_CALLBACK
(
_tray_menu_cb
),
m
);
}
}
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
menu
,
item
);
}
return
menu
;
}
static
int
tray_init
(
struct
tray
*
tray
)
{
if
(
gtk_init_check
(
0
,
NULL
)
==
FALSE
)
{
return
-
1
;
...
...
@@ -52,66 +77,11 @@ static int tray_loop(int blocking) {
return
loop_result
;
}
// recursive proc
static
void
submenu_update
(
struct
tray_menu
*
m
,
GtkWidget
*
_item
,
GtkMenuShell
*
_submenu
)
{
GtkMenuShell
*
submenu
;
for
(
struct
tray_menu
*
s_m
=
m
->
submenu
;
s_m
!=
NULL
&&
s_m
->
text
!=
NULL
;
s_m
++
)
{
GtkWidget
*
item
;
if
(
s_m
->
submenu
!=
NULL
)
{
item
=
gtk_menu_item_new_with_label
(
s_m
->
text
);
submenu
=
(
GtkMenuShell
*
)
gtk_menu_new
();
gtk_menu_item_set_submenu
(
GTK_MENU_ITEM
(
item
),
(
GtkWidget
*
)
submenu
);
submenu_update
(
s_m
,
item
,
submenu
);
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
_submenu
),
item
);
}
else
if
(
strcmp
(
s_m
->
text
,
"-"
)
==
0
)
{
gtk_menu_item_set_submenu
(
GTK_MENU_ITEM
(
_item
),
(
GtkWidget
*
)
_submenu
);
item
=
gtk_separator_menu_item_new
();
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
_submenu
),
item
);
}
else
{
gtk_menu_item_set_submenu
(
GTK_MENU_ITEM
(
_item
),
(
GtkWidget
*
)
_submenu
);
item
=
gtk_check_menu_item_new_with_label
(
s_m
->
text
);
gtk_widget_set_sensitive
(
item
,
!
s_m
->
disabled
);
gtk_check_menu_item_set_active
(
GTK_CHECK_MENU_ITEM
(
item
),
!!
s_m
->
checked
);
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
_submenu
),
item
);
if
(
s_m
->
cb
!=
NULL
)
{
g_signal_connect
(
item
,
"activate"
,
G_CALLBACK
(
_tray_menu_cb
),
s_m
);
}
}
}
}
static
void
tray_update
(
struct
tray
*
tray
)
{
GtkMenuShell
*
menu
=
(
GtkMenuShell
*
)
gtk_menu_new
();
for
(
struct
tray_menu
*
m
=
tray
->
menu
;
m
!=
NULL
&&
m
->
text
!=
NULL
;
m
++
)
{
GtkWidget
*
item
;
if
(
m
->
submenu
!=
NULL
)
{
GtkMenuShell
*
submenu
=
(
GtkMenuShell
*
)
gtk_menu_new
();
item
=
gtk_menu_item_new_with_label
(
m
->
text
);
gtk_menu_item_set_submenu
(
GTK_MENU_ITEM
(
item
),
(
GtkWidget
*
)
submenu
);
submenu_update
(
m
,
item
,
submenu
);
}
else
if
(
strcmp
(
m
->
text
,
"-"
)
==
0
)
{
item
=
gtk_separator_menu_item_new
();
}
else
{
item
=
gtk_check_menu_item_new_with_label
(
m
->
text
);
gtk_widget_set_sensitive
(
item
,
!
m
->
disabled
);
gtk_check_menu_item_set_active
(
GTK_CHECK_MENU_ITEM
(
item
),
!!
m
->
checked
);
}
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
menu
),
item
);
if
(
m
->
cb
!=
NULL
)
{
g_signal_connect
(
item
,
"activate"
,
G_CALLBACK
(
_tray_menu_cb
),
m
);
}
}
app_indicator_set_icon
(
indicator
,
tray
->
icon
);
// GTK is all about reference counting, so previous menu should be destroyed
// here
app_indicator_set_menu
(
indicator
,
GTK_MENU
(
menu
));
app_indicator_set_menu
(
indicator
,
GTK_MENU
(
_tray_menu
(
tray
->
menu
)
));
}
static
void
tray_exit
()
{
loop_result
=
-
1
;
}
...
...
@@ -349,4 +319,4 @@ static void tray_update(struct tray *tray) {}
static
void
tray_exit
();
#endif
#endif
/* TRAY_H */
\ No newline at end of file
#endif
/* TRAY_H */
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