added recursive procedure for submenu. Used one struct for submenu: tray_menu

This commit is contained in:
Max
2017-01-11 20:57:36 +03:00
parent 26009610c1
commit ed255d1a03
2 changed files with 82 additions and 114 deletions

View File

@@ -16,34 +16,34 @@
static struct tray tray;
// static void toggle_cb(struct tray_menu *item) {
// printf("toggle cb\n");
// item->checked = !item->checked;
// tray_update(&tray);
// }
static void toggle_cb(struct tray_menu *item) {
printf("toggle cb\n");
item->checked = !item->checked;
tray_update(&tray);
}
// static void hello_cb(struct tray_menu *item) {
// (void)item;
// printf("hello cb\n");
// if (strcmp(tray.icon, TRAY_ICON1) == 0) {
// tray.icon = TRAY_ICON2;
// } else {
// tray.icon = TRAY_ICON1;
// }
// tray_update(&tray);
// }
static void hello_cb(struct tray_menu *item) {
(void)item;
printf("hello cb\n");
if (strcmp(tray.icon, TRAY_ICON1) == 0) {
tray.icon = TRAY_ICON2;
} else {
tray.icon = TRAY_ICON1;
}
tray_update(&tray);
}
// static void quit_cb(struct tray_menu *item) {
// (void)item;
// printf("quit cb\n");
// tray_exit();
// }
static void quit_cb(struct tray_menu *item) {
(void)item;
printf("quit cb\n");
tray_exit();
}
// static void submenu_cb(struct tray_submenu *item) {
// (void)item;
// printf("submenu cb\n");
// tray_update(&tray);
// }
static void submenu_cb(struct tray_menu *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},};
@@ -62,32 +62,27 @@ static struct tray tray;
// {"Quit", 0, 0, NULL, quit_cb, NULL},
// {NULL, 0, 0, NULL, NULL, NULL}},
// };
//Test tray init
static struct tray tray = {
.icon = TRAY_ICON1,
.menu = (struct tray_menu[]){{"Hello", NULL},
{"Checked", NULL},
{"SubMenu", (struct tray_menu[]){{"FIRST", NULL},
{"SECOND", (struct tray_menu[]){{"THIRD", (struct tray_menu[]){{"7", NULL},
{"8", NULL},
{NULL, NULL}}},
{"FOUR", (struct tray_menu[]){{"5", NULL},
{"6", NULL},
{NULL, NULL}}},
{NULL, NULL}}},
{NULL, NULL}}
},
{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}},
};
// static struct tray tray = {
// .icon = TRAY_ICON1,
// .menu = (struct tray_menu[]){{"Hello", NULL},
// {"Checked", NULL},
// {"SubMenu", (struct tray_menu[]){{"FIRST", NULL},
// {"SECOND", NULL},
// {NULL, NULL}}
// },
// {NULL, NULL}},
// };
int main() {
if (tray_init(&tray) < 0) {
printf("failed to create tray\n");