1
0
forked from Yadciel/c_tray

moved submenu to the end of the struct to make menu desclaration look better, formatted

This commit is contained in:
Serge A. Zaitsev
2017-01-12 12:48:32 +02:00
parent b677473cd4
commit a1e7598f44
2 changed files with 31 additions and 32 deletions

View File

@@ -48,33 +48,30 @@ static void submenu_cb(struct tray_menu *item) {
// Test tray init // Test tray init
static struct tray tray = { static struct tray tray = {
.icon = TRAY_ICON1, .icon = TRAY_ICON1,
.menu = (struct tray_menu[]){ .menu =
{"Hello", 0, 0, NULL, hello_cb, NULL}, (struct tray_menu[]){
{"Checked", 0, 1, NULL, toggle_cb, NULL}, {"Hello", 0, 0, hello_cb, NULL, NULL},
{"Disabled", 1, 0, NULL, NULL, NULL}, {"Checked", 0, 1, toggle_cb, NULL, NULL},
{"-", 0, 0, NULL, NULL, NULL}, {"Disabled", 1, 0, NULL, NULL, NULL},
{"Quit", 0, 0, NULL, quit_cb, NULL}, {"-", 0, 0, NULL, NULL, NULL},
{"SubMenu", 0, 0, {"Quit", 0, 0, quit_cb, NULL, NULL},
(struct tray_menu[]){ {"SubMenu", 0, 0, NULL, NULL,
{"FIRST", 0, 1, NULL, submenu_cb, NULL}, (struct tray_menu[]){
{"SECOND", 0, 0, {"FIRST", 0, 1, submenu_cb, NULL, NULL},
(struct tray_menu[]){ {"SECOND", 0, 0, NULL, NULL,
{"THIRD", 0, 0, (struct tray_menu[]){
(struct tray_menu[]){{"7", 0, 0, NULL, submenu_cb, NULL}, {"THIRD", 0, 0, NULL, NULL,
{"-", 0, 0, NULL, NULL, NULL}, (struct tray_menu[]){{"7", 0, 0, submenu_cb, NULL, NULL},
{"8", 0, 0, NULL, submenu_cb, NULL}, {"-", 0, 0, NULL, NULL, NULL},
{NULL, 0, 0, NULL, NULL, NULL}}, {"8", 0, 0, submenu_cb, NULL, NULL},
NULL, NULL}, {NULL, 0, 0, NULL, NULL, NULL}}},
{"FOUR", 0, 0, {"FOUR", 0, 0, NULL, NULL,
(struct tray_menu[]){{"5", 0, 0, NULL, submenu_cb, NULL}, (struct tray_menu[]){{"5", 0, 0, submenu_cb, NULL, NULL},
{"6", 0, 0, NULL, submenu_cb, NULL}, {"6", 0, 0, submenu_cb, NULL, NULL},
{NULL, 0, 0, NULL, NULL, NULL}}, {NULL, 0, 0, NULL, NULL, NULL}}},
NULL, NULL}, {NULL, 0, 0, NULL, NULL, NULL}}},
{NULL, 0, 0, NULL, NULL, NULL}}, {NULL, 0, 0, NULL, NULL, NULL}}},
NULL, NULL}, {NULL, 0, 0, NULL, NULL, NULL}},
{NULL, 0, 0, NULL, NULL, NULL}},
NULL, NULL},
{NULL, 0, 0, NULL, NULL, NULL}},
}; };
int main() { int main() {

10
tray.h
View File

@@ -12,10 +12,11 @@ struct tray_menu {
char *text; char *text;
int disabled; int disabled;
int checked; int checked;
struct tray_menu *submenu;
void (*cb)(struct tray_menu *); void (*cb)(struct tray_menu *);
void *context; void *context;
struct tray_menu *submenu;
}; };
static void tray_update(struct tray *tray); static void tray_update(struct tray *tray);
@@ -45,7 +46,8 @@ static GtkMenuShell *_tray_menu(struct tray_menu *m) {
} else { } else {
if (m->submenu != NULL) { if (m->submenu != NULL) {
item = gtk_menu_item_new_with_label(m->text); item = gtk_menu_item_new_with_label(m->text);
gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), GTK_WIDGET(_tray_menu(m->submenu))); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item),
GTK_WIDGET(_tray_menu(m->submenu)));
} else { } else {
item = gtk_check_menu_item_new_with_label(m->text); item = gtk_check_menu_item_new_with_label(m->text);
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);
@@ -180,8 +182,8 @@ static NOTIFYICONDATA nid;
static HWND hwnd; static HWND hwnd;
static HMENU hmenu = NULL; static HMENU hmenu = NULL;
static LRESULT CALLBACK static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam,
_tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { LPARAM lparam) {
switch (msg) { switch (msg) {
case WM_CLOSE: case WM_CLOSE:
DestroyWindow(hwnd); DestroyWindow(hwnd);