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
721107bf
Commit
721107bf
authored
Jan 12, 2017
by
Serge Zaitsev
Committed by
GitHub
Jan 12, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1 from angelskieglazki/master
Added submenu
parents
83a182dd
a66de7c4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
11 deletions
+81
-11
example.c
example.c
+36
-7
tray.h
tray.h
+45
-4
No files found.
example.c
View file @
721107bf
...
...
@@ -39,14 +39,42 @@ static void quit_cb(struct tray_menu *item) {
tray_exit
();
}
static
void
submenu_cb
(
struct
tray_menu
*
item
)
{
(
void
)
item
;
printf
(
"submenu cb!!!
\n
"
);
tray_update
(
&
tray
);
}
// Test tray init
static
struct
tray
tray
=
{
.
icon
=
TRAY_ICON1
,
.
menu
=
(
struct
tray_menu
[]){{
"Hello"
,
0
,
0
,
hello_cb
,
NULL
},
{
"Checked"
,
0
,
1
,
toggle_cb
,
NULL
},
{
"Disabled"
,
1
,
0
,
NULL
,
NULL
},
{
"-"
,
0
,
0
,
NULL
,
NULL
},
{
"Quit"
,
0
,
0
,
quit_cb
,
NULL
},
{
NULL
,
0
,
0
,
NULL
,
NULL
}},
.
menu
=
(
struct
tray_menu
[]){
{
"Hello"
,
0
,
0
,
NULL
,
hello_cb
,
NULL
},
{
"Checked"
,
0
,
1
,
NULL
,
toggle_cb
,
NULL
},
{
"Disabled"
,
1
,
0
,
NULL
,
NULL
,
NULL
},
{
"-"
,
0
,
0
,
NULL
,
NULL
,
NULL
},
{
"Quit"
,
0
,
0
,
NULL
,
quit_cb
,
NULL
},
{
"SubMenu"
,
0
,
0
,
(
struct
tray_menu
[]){
{
"FIRST"
,
0
,
1
,
NULL
,
submenu_cb
,
NULL
},
{
"SECOND"
,
0
,
0
,
(
struct
tray_menu
[]){
{
"THIRD"
,
0
,
0
,
(
struct
tray_menu
[]){{
"7"
,
0
,
0
,
NULL
,
submenu_cb
,
NULL
},
{
"-"
,
0
,
0
,
NULL
,
NULL
,
NULL
},
{
"8"
,
0
,
0
,
NULL
,
submenu_cb
,
NULL
},
{
NULL
,
0
,
0
,
NULL
,
NULL
,
NULL
}},
NULL
,
NULL
},
{
"FOUR"
,
0
,
0
,
(
struct
tray_menu
[]){{
"5"
,
0
,
0
,
NULL
,
submenu_cb
,
NULL
},
{
"6"
,
0
,
0
,
NULL
,
submenu_cb
,
NULL
},
{
NULL
,
0
,
0
,
NULL
,
NULL
,
NULL
}},
NULL
,
NULL
},
{
NULL
,
0
,
0
,
NULL
,
NULL
,
NULL
}},
NULL
,
NULL
},
{
NULL
,
0
,
0
,
NULL
,
NULL
,
NULL
}},
NULL
,
NULL
},
{
NULL
,
0
,
0
,
NULL
,
NULL
,
NULL
}},
};
int
main
()
{
...
...
@@ -58,4 +86,4 @@ int main() {
printf
(
"iteration
\n
"
);
}
return
0
;
}
}
\ No newline at end of file
tray.h
View file @
721107bf
...
...
@@ -12,6 +12,7 @@ struct tray_menu {
char
*
text
;
int
disabled
;
int
checked
;
struct
tray_menu
*
submenu
;
void
(
*
cb
)(
struct
tray_menu
*
);
void
*
context
;
...
...
@@ -51,17 +52,56 @@ 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
(
strcmp
(
m
->
text
,
"-"
)
==
0
)
{
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
)
{
...
...
@@ -170,8 +210,8 @@ static NOTIFYICONDATA nid;
static
HWND
hwnd
;
static
HMENU
hmenu
=
NULL
;
static
LRESULT
CALLBACK
_tray_wnd_proc
(
HWND
hwnd
,
UINT
msg
,
WPARAM
wparam
,
LPARAM
lparam
)
{
static
LRESULT
CALLBACK
_tray_wnd_proc
(
HWND
hwnd
,
UINT
msg
,
WPARAM
wparam
,
LPARAM
lparam
)
{
switch
(
msg
)
{
case
WM_CLOSE
:
DestroyWindow
(
hwnd
);
...
...
@@ -309,4 +349,4 @@ static void tray_update(struct tray *tray) {}
static
void
tray_exit
();
#endif
#endif
/* TRAY_H */
#endif
/* TRAY_H */
\ No newline at end of file
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