forked from Yadciel/c_tray
1)deleted old struct; 2) formated code
This commit is contained in:
46
example.c
46
example.c
@@ -45,44 +45,38 @@ static void submenu_cb(struct tray_menu *item) {
|
|||||||
tray_update(&tray);
|
tray_update(&tray);
|
||||||
}
|
}
|
||||||
|
|
||||||
//struct tray_submenu *t_sm = (struct tray_submenu[]){{"First",submenu_cb}, {"Second",submenu_cb}, {NULL, NULL},};
|
|
||||||
|
|
||||||
// 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},
|
|
||||||
// {"SubMenu", 0, 0, (struct tray_submenu[]){{"First", NULL,submenu_cb, NULL},
|
|
||||||
// {"Second",
|
|
||||||
// (struct tray_submenu[]){{"Third", NULL,submenu_cb, NULL},
|
|
||||||
// {NULL, NULL, NULL, NULL},},
|
|
||||||
// submenu_cb, NULL},
|
|
||||||
// {NULL, NULL, NULL},}, NULL, NULL},
|
|
||||||
// {"Quit", 0, 0, NULL, quit_cb, NULL},
|
|
||||||
// {NULL, 0, 0, NULL, NULL, NULL}},
|
|
||||||
// };
|
|
||||||
|
|
||||||
// Test tray init
|
// Test tray init
|
||||||
static struct tray tray = {
|
static struct tray tray = {
|
||||||
.icon = TRAY_ICON1,
|
.icon = TRAY_ICON1,
|
||||||
.menu = (struct tray_menu[]){{"Hello", 0, 0, NULL, hello_cb, NULL},
|
.menu = (struct tray_menu[]){
|
||||||
|
{"Hello", 0, 0, NULL, hello_cb, NULL},
|
||||||
{"Checked", 0, 1, NULL, toggle_cb, NULL},
|
{"Checked", 0, 1, NULL, toggle_cb, NULL},
|
||||||
{"Disabled", 1, 0, NULL, NULL, NULL},
|
{"Disabled", 1, 0, NULL, NULL, NULL},
|
||||||
{"-", 0, 0, NULL, NULL, NULL},
|
{"-", 0, 0, NULL, NULL, NULL},
|
||||||
{"Quit", 0, 0, NULL, quit_cb, NULL},
|
{"Quit", 0, 0, NULL, quit_cb, NULL},
|
||||||
{"SubMenu", 0, 0, (struct tray_menu[]){{"FIRST", 0, 1, NULL, submenu_cb, NULL},
|
{"SubMenu", 0, 0,
|
||||||
{"SECOND", 0, 0, (struct tray_menu[]){{"THIRD", 0, 0, (struct tray_menu[]){{"7", 0, 0, NULL, submenu_cb, NULL},
|
(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},
|
{"-", 0, 0, NULL, NULL, NULL},
|
||||||
{"8", 0, 0, NULL, submenu_cb, NULL},
|
{"8", 0, 0, NULL, submenu_cb, NULL},
|
||||||
{NULL, 0, 0, NULL, NULL, NULL}}, NULL, NULL},
|
{NULL, 0, 0, NULL, NULL, NULL}},
|
||||||
{"FOUR", 0, 0, (struct tray_menu[]){{"5", 0, 0, NULL, submenu_cb, NULL},
|
NULL, NULL},
|
||||||
|
{"FOUR", 0, 0,
|
||||||
|
(struct tray_menu[]){{"5", 0, 0, NULL, submenu_cb, NULL},
|
||||||
{"6", 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, 0, 0, NULL, NULL, 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}},
|
||||||
|
NULL, NULL},
|
||||||
{NULL, 0, 0, NULL, NULL, NULL}},
|
{NULL, 0, 0, NULL, NULL, NULL}},
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
if (tray_init(&tray) < 0) {
|
if (tray_init(&tray) < 0) {
|
||||||
printf("failed to create tray\n");
|
printf("failed to create tray\n");
|
||||||
|
|||||||
16
tray.h
16
tray.h
@@ -53,10 +53,11 @@ static int tray_loop(int blocking) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// recursive proc
|
// recursive proc
|
||||||
static void submenu_update(struct tray_menu *m,
|
static void submenu_update(struct tray_menu *m, GtkWidget *_item,
|
||||||
GtkWidget *_item, GtkMenuShell *_submenu) {
|
GtkMenuShell *_submenu) {
|
||||||
GtkMenuShell *submenu;
|
GtkMenuShell *submenu;
|
||||||
for (struct tray_menu *s_m = m->submenu; s_m!=NULL && s_m->text!=NULL; s_m++) {
|
for (struct tray_menu *s_m = m->submenu; s_m != NULL && s_m->text != NULL;
|
||||||
|
s_m++) {
|
||||||
GtkWidget *item;
|
GtkWidget *item;
|
||||||
if (s_m->submenu != NULL) {
|
if (s_m->submenu != NULL) {
|
||||||
item = gtk_menu_item_new_with_label(s_m->text);
|
item = gtk_menu_item_new_with_label(s_m->text);
|
||||||
@@ -65,14 +66,12 @@ static void submenu_update(struct tray_menu *m,
|
|||||||
submenu_update(s_m, item, submenu);
|
submenu_update(s_m, item, submenu);
|
||||||
gtk_widget_show(item);
|
gtk_widget_show(item);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(_submenu), item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(_submenu), item);
|
||||||
|
|
||||||
} else if (strcmp(s_m->text, "-") == 0) {
|
} else if (strcmp(s_m->text, "-") == 0) {
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(_item), (GtkWidget *)_submenu);
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(_item), (GtkWidget *)_submenu);
|
||||||
item = gtk_separator_menu_item_new();
|
item = gtk_separator_menu_item_new();
|
||||||
gtk_widget_show(item);
|
gtk_widget_show(item);
|
||||||
gtk_menu_shell_append(GTK_MENU_SHELL(_submenu), item);
|
gtk_menu_shell_append(GTK_MENU_SHELL(_submenu), item);
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
gtk_menu_item_set_submenu(GTK_MENU_ITEM(_item), (GtkWidget *)_submenu);
|
gtk_menu_item_set_submenu(GTK_MENU_ITEM(_item), (GtkWidget *)_submenu);
|
||||||
item = gtk_check_menu_item_new_with_label(s_m->text);
|
item = gtk_check_menu_item_new_with_label(s_m->text);
|
||||||
gtk_widget_set_sensitive(item, !s_m->disabled);
|
gtk_widget_set_sensitive(item, !s_m->disabled);
|
||||||
@@ -115,7 +114,6 @@ static void tray_update(struct tray *tray) {
|
|||||||
app_indicator_set_menu(indicator, GTK_MENU(menu));
|
app_indicator_set_menu(indicator, GTK_MENU(menu));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void tray_exit() { loop_result = -1; }
|
static void tray_exit() { loop_result = -1; }
|
||||||
|
|
||||||
#elif defined(TRAY_APPKIT)
|
#elif defined(TRAY_APPKIT)
|
||||||
@@ -212,8 +210,8 @@ static NOTIFYICONDATA nid;
|
|||||||
static HWND hwnd;
|
static HWND hwnd;
|
||||||
static HMENU hmenu = NULL;
|
static HMENU hmenu = NULL;
|
||||||
|
|
||||||
static LRESULT CALLBACK _tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam,
|
static LRESULT CALLBACK
|
||||||
LPARAM lparam) {
|
_tray_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) {
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
DestroyWindow(hwnd);
|
DestroyWindow(hwnd);
|
||||||
|
|||||||
Reference in New Issue
Block a user