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
a09222db
Commit
a09222db
authored
Jan 10, 2017
by
angelskieglazki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added submenu
parent
19d958a8
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
20 deletions
+47
-20
example.c
example.c
+15
-7
tray.h
tray.h
+32
-13
No files found.
example.c
View file @
a09222db
...
@@ -39,15 +39,23 @@ static void quit_cb(struct tray_menu *item) {
...
@@ -39,15 +39,23 @@ static void quit_cb(struct tray_menu *item) {
tray_exit
();
tray_exit
();
}
}
static
void
submenu_cb
(
struct
tray_submenu
*
item
)
{
(
void
)
item
;
printf
(
"submenu cb
\n
"
);
tray_update
(
&
tray
);
}
//struct tray_submenu *t_sm = (struct tray_submenu[]){{"First",submenu_cb}, {"Second",submenu_cb}, {NULL, NULL},};
static
struct
tray
tray
=
{
static
struct
tray
tray
=
{
.
icon
=
TRAY_ICON1
,
.
icon
=
TRAY_ICON1
,
.
menu
=
(
struct
tray_menu
[]){{
"Hello"
,
0
,
0
,
hello_cb
,
NULL
},
.
menu
=
(
struct
tray_menu
[]){{
"Hello"
,
0
,
0
,
NULL
,
hello_cb
,
NULL
},
{
"Checked"
,
0
,
1
,
toggle_cb
,
NULL
},
{
"Checked"
,
0
,
1
,
NULL
,
toggle_cb
,
NULL
},
{
"Disabled"
,
1
,
0
,
NULL
,
NULL
},
{
"Disabled"
,
1
,
0
,
NULL
,
NULL
,
NULL
},
{
"-"
,
0
,
0
,
NULL
,
NULL
},
{
"-"
,
0
,
0
,
NULL
,
NULL
,
NULL
},
{
"
+"
,
0
,
0
,
NULL
,
NULL
},
{
"
SubMenu"
,
0
,
0
,
(
struct
tray_submenu
[]){{
"First"
,
submenu_cb
,
NULL
},
{
"Second"
,
submenu_cb
,
NULL
},
{
NULL
,
NULL
,
NULL
},},
NULL
,
NULL
},
{
"Quit"
,
0
,
0
,
quit_cb
,
NULL
},
{
"Quit"
,
0
,
0
,
NULL
,
quit_cb
,
NULL
},
{
NULL
,
0
,
0
,
NULL
,
NULL
}},
{
NULL
,
0
,
0
,
NULL
,
NULL
,
NULL
}},
};
};
int
main
()
{
int
main
()
{
...
...
tray.h
View file @
a09222db
...
@@ -8,10 +8,17 @@ struct tray {
...
@@ -8,10 +8,17 @@ struct tray {
struct
tray_menu
*
menu
;
struct
tray_menu
*
menu
;
};
};
struct
tray_submenu
{
char
*
text
;
void
(
*
cb
)(
struct
tray_submenu
*
);
void
*
context
;
};
struct
tray_menu
{
struct
tray_menu
{
char
*
text
;
char
*
text
;
int
disabled
;
int
disabled
;
int
checked
;
int
checked
;
struct
tray_submenu
*
submenu
;
void
(
*
cb
)(
struct
tray_menu
*
);
void
(
*
cb
)(
struct
tray_menu
*
);
void
*
context
;
void
*
context
;
...
@@ -35,6 +42,12 @@ static void _tray_menu_cb(GtkMenuItem *item, gpointer data) {
...
@@ -35,6 +42,12 @@ static void _tray_menu_cb(GtkMenuItem *item, gpointer data) {
m
->
cb
(
m
);
m
->
cb
(
m
);
}
}
static
void
_tray_submenu_cb
(
GtkMenuItem
*
item
,
gpointer
data
)
{
(
void
)
item
;
struct
tray_submenu
*
s_m
=
(
struct
tray_submenu
*
)
data
;
s_m
->
cb
(
s_m
);
}
static
int
tray_init
(
struct
tray
*
tray
)
{
static
int
tray_init
(
struct
tray
*
tray
)
{
if
(
gtk_init_check
(
0
,
NULL
)
==
FALSE
)
{
if
(
gtk_init_check
(
0
,
NULL
)
==
FALSE
)
{
return
-
1
;
return
-
1
;
...
@@ -55,28 +68,34 @@ static void tray_update(struct tray *tray) {
...
@@ -55,28 +68,34 @@ static void tray_update(struct tray *tray) {
GtkMenuShell
*
menu
=
(
GtkMenuShell
*
)
gtk_menu_new
();
GtkMenuShell
*
menu
=
(
GtkMenuShell
*
)
gtk_menu_new
();
for
(
struct
tray_menu
*
m
=
tray
->
menu
;
m
!=
NULL
&&
m
->
text
!=
NULL
;
m
++
)
{
for
(
struct
tray_menu
*
m
=
tray
->
menu
;
m
!=
NULL
&&
m
->
text
!=
NULL
;
m
++
)
{
GtkWidget
*
item
;
GtkWidget
*
item
;
if
(
strcmp
(
m
->
text
,
"+"
)
==
0
)
{
if
(
m
->
submenu
!=
NULL
)
{
GtkWidget
*
submenu1
=
gtk_menu_new
();
item
=
gtk_menu_item_new_with_label
(
"SubMenu1"
);
GtkWidget
*
submenu
=
gtk_menu_new
();
gtk_menu_item_set_submenu
(
GTK_MENU_ITEM
(
item
),
submenu1
);
item
=
gtk_menu_item_new_with_label
(
m
->
text
);
GtkWidget
*
submenu1_option
;
gtk_menu_item_set_submenu
(
GTK_MENU_ITEM
(
item
),
submenu
);
submenu1_option
=
gtk_menu_item_new_with_label
(
"Submenu option!"
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
submenu1
),
submenu1_option
);
for
(
struct
tray_submenu
*
s_m
=
m
->
submenu
;
s_m
!=
NULL
&&
s_m
->
text
!=
NULL
;
s_m
++
)
{
GtkWidget
*
submenu_item
;
submenu_item
=
gtk_menu_item_new_with_label
(
s_m
->
text
);
gtk_widget_show
(
submenu_item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
submenu
),
submenu_item
);
if
(
s_m
->
cb
!=
NULL
)
{
g_signal_connect
(
submenu_item
,
"activate"
,
G_CALLBACK
(
_tray_submenu_cb
),
s_m
);
}
}
else
{
if
(
strcmp
(
m
->
text
,
"-"
)
==
0
)
{
}
}
else
if
(
strcmp
(
m
->
text
,
"-"
)
==
0
)
{
item
=
gtk_separator_menu_item_new
();
item
=
gtk_separator_menu_item_new
();
}
else
{
}
else
{
item
=
gtk_check_menu_item_new_with_label
(
m
->
text
);
item
=
gtk_check_menu_item_new_with_label
(
m
->
text
);
gtk_widget_set_sensitive
(
item
,
!
m
->
disabled
);
gtk_widget_set_sensitive
(
item
,
!
m
->
disabled
);
gtk_check_menu_item_set_active
(
GTK_CHECK_MENU_ITEM
(
item
),
!!
m
->
checked
);
gtk_check_menu_item_set_active
(
GTK_CHECK_MENU_ITEM
(
item
),
!!
m
->
checked
);
}
}
}
gtk_widget_show
(
item
);
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
menu
),
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
menu
),
item
);
if
(
m
->
cb
!=
NULL
)
{
if
(
m
->
cb
!=
NULL
)
{
g_signal_connect
(
item
,
"activate"
,
G_CALLBACK
(
_tray_menu_cb
),
m
);
g_signal_connect
(
item
,
"activate"
,
G_CALLBACK
(
_tray_menu_cb
),
m
);
}
}
...
...
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