appindicator test

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <gtk/gtk.h>
#include <libappindicator/app-indicator.h>
// cc main.c $(pkg-config --libs --cflags appindicator-0.1 gtk+-2.0) -o main && ./main
AppIndicator *indicator;
static void
activate_action (GtkAction *action)
{
static int i=0;
i++;
if (i == 3) {
i=0;
}
switch (i) {
case 0:
app_indicator_set_icon(indicator, "/usr/share/gxkb/flags/ua.png");
break;
case 1:
app_indicator_set_icon(indicator, "/usr/share/gxkb/flags/us.png");
break;
case 2:
app_indicator_set_icon(indicator, "/usr/share/gxkb/flags/de.png");
break;
}
}
int main (int argc, char **argv)
{
GError *error = NULL;
gtk_init (&argc, &argv);
/* Indicator */
indicator = app_indicator_new ("example-simple-client",
"indicator-messages",
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
app_indicator_set_status (indicator, APP_INDICATOR_STATUS_ACTIVE);
//app_indicator_set_icon_full(indicator, "/usr/share/gxkb/flags/ua.png", "UA");
app_indicator_set_icon(indicator, "/usr/share/gxkb/flags/ua.png");
GtkWidget *mi;
GtkWidget *menu = gtk_menu_new();
mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_DIALOG_INFO, NULL);
g_signal_connect(G_OBJECT(mi), "activate", (GCallback)activate_action, NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
gtk_widget_show (mi);
mi = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, NULL);
g_signal_connect(G_OBJECT(mi), "activate", (GCallback)gtk_main_quit, NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
gtk_widget_show (mi);
app_indicator_set_menu (indicator, GTK_MENU (menu));
gtk_main ();
return 0;
}