From a1e7598f44acca3c12695d50f51729f9d4d97d5d Mon Sep 17 00:00:00 2001 From: "Serge A. Zaitsev" Date: Thu, 12 Jan 2017 12:48:32 +0200 Subject: [PATCH] moved submenu to the end of the struct to make menu desclaration look better, formatted --- example.c | 53 +++++++++++++++++++++++++---------------------------- tray.h | 10 ++++++---- 2 files changed, 31 insertions(+), 32 deletions(-) diff --git a/example.c b/example.c index 424f9ac..a9aad65 100644 --- a/example.c +++ b/example.c @@ -48,33 +48,30 @@ static void submenu_cb(struct tray_menu *item) { // Test tray init static struct tray tray = { .icon = TRAY_ICON1, - .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}}, + .menu = + (struct tray_menu[]){ + {"Hello", 0, 0, hello_cb, NULL, NULL}, + {"Checked", 0, 1, toggle_cb, NULL, NULL}, + {"Disabled", 1, 0, NULL, NULL, NULL}, + {"-", 0, 0, NULL, NULL, NULL}, + {"Quit", 0, 0, quit_cb, NULL, NULL}, + {"SubMenu", 0, 0, NULL, NULL, + (struct tray_menu[]){ + {"FIRST", 0, 1, submenu_cb, NULL, NULL}, + {"SECOND", 0, 0, NULL, NULL, + (struct tray_menu[]){ + {"THIRD", 0, 0, NULL, NULL, + (struct tray_menu[]){{"7", 0, 0, submenu_cb, NULL, NULL}, + {"-", 0, 0, NULL, NULL, NULL}, + {"8", 0, 0, submenu_cb, NULL, NULL}, + {NULL, 0, 0, NULL, NULL, NULL}}}, + {"FOUR", 0, 0, NULL, NULL, + (struct tray_menu[]){{"5", 0, 0, submenu_cb, NULL, NULL}, + {"6", 0, 0, submenu_cb, NULL, NULL}, + {NULL, 0, 0, NULL, NULL, NULL}}}, + {NULL, 0, 0, NULL, NULL, NULL}}}, + {NULL, 0, 0, NULL, NULL, NULL}}}, + {NULL, 0, 0, NULL, NULL, NULL}}, }; int main() { @@ -86,4 +83,4 @@ int main() { printf("iteration\n"); } return 0; -} \ No newline at end of file +} diff --git a/tray.h b/tray.h index 55dfc95..23d576b 100644 --- a/tray.h +++ b/tray.h @@ -12,10 +12,11 @@ struct tray_menu { char *text; int disabled; int checked; - struct tray_menu *submenu; void (*cb)(struct tray_menu *); void *context; + + struct tray_menu *submenu; }; static void tray_update(struct tray *tray); @@ -45,7 +46,8 @@ static GtkMenuShell *_tray_menu(struct tray_menu *m) { } 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))); + 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); @@ -180,8 +182,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);