aboutsummaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2011-07-20 03:32:35 +0200
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2011-07-20 03:32:35 +0200
commitbeb4f164b808f2dbb3fffa6ed85c931c2710a924 (patch)
tree7976e4c102fb62498ebbf86160b57557d880993f /example
parenta3812f9b8bfe467873bfe261a161b868c2b42118 (diff)
downloadlibayatana-appindicator-beb4f164b808f2dbb3fffa6ed85c931c2710a924.tar.gz
libayatana-appindicator-beb4f164b808f2dbb3fffa6ed85c931c2710a924.tar.bz2
libayatana-appindicator-beb4f164b808f2dbb3fffa6ed85c931c2710a924.zip
examples: use the set_secondary_activate_target API
Diffstat (limited to 'example')
-rw-r--r--example/simple-client-vala.vala20
-rw-r--r--example/simple-client.c113
2 files changed, 63 insertions, 70 deletions
diff --git a/example/simple-client-vala.vala b/example/simple-client-vala.vala
index c0adf5b..8d661ce 100644
--- a/example/simple-client-vala.vala
+++ b/example/simple-client-vala.vala
@@ -72,6 +72,17 @@ class SimpleClient {
menu.append(mi);
mi.activate.connect(() => { print("Sub3\n"); });
+ mi = new MenuItem.with_label("Toggle Attention");
+ menu.append(mi);
+ mi.activate.connect(() => {
+ if (ci.get_status() == IndicatorStatus.ATTENTION)
+ ci.set_status(IndicatorStatus.ACTIVE);
+ else
+ ci.set_status(IndicatorStatus.ATTENTION);
+ });
+
+ ci.set_secondary_activate_target(mi);
+
menu.show_all();
item.set_submenu(menu);
}
@@ -92,13 +103,6 @@ class SimpleClient {
print(@"Got scroll event! delta: $delta, direction: $direction\n");
});
- ci.secondary_activate.connect((x, y) => {
- print(@"Got secondary activate event at $(x)x$(y)\n");
-
- if (ci.get_status() == IndicatorStatus.ATTENTION)
- ci.set_status(IndicatorStatus.ACTIVE);
- });
-
Timeout.add_seconds(1, () => {
percentage = (percentage + 1) % 100;
if (can_haz_label) {
@@ -116,7 +120,7 @@ class SimpleClient {
chk.show();
var radio = new RadioMenuItem.with_label(new SList<RadioMenuItem>(), "2");
- radio.activate.connect(() => { print("2\n"); });
+ radio.activate.connect(() => { print("2\n"); });
menu.append(radio);
radio.show();
diff --git a/example/simple-client.c b/example/simple-client.c
index 32e7240..dcee81b 100644
--- a/example/simple-client.c
+++ b/example/simple-client.c
@@ -31,46 +31,46 @@ static gboolean can_haz_label = TRUE;
static void
label_toggle_cb (GtkWidget * widget, gpointer data)
{
- can_haz_label = !can_haz_label;
+ can_haz_label = !can_haz_label;
- if (can_haz_label) {
- gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "Hide label");
- } else {
- gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "Show label");
- }
+ if (can_haz_label) {
+ gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "Hide label");
+ } else {
+ gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "Show label");
+ }
- return;
+ return;
}
static void
activate_clicked_cb (GtkWidget *widget, gpointer data)
{
- AppIndicator * ci = APP_INDICATOR(data);
-
- if (active) {
- app_indicator_set_status (ci, APP_INDICATOR_STATUS_ATTENTION);
- gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "I'm okay now");
- active = FALSE;
- } else {
- app_indicator_set_status (ci, APP_INDICATOR_STATUS_ACTIVE);
- gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "Get Attention");
- active = TRUE;
- }
+ AppIndicator * ci = APP_INDICATOR(data);
+
+ if (active) {
+ app_indicator_set_status (ci, APP_INDICATOR_STATUS_ATTENTION);
+ gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "I'm okay now");
+ active = FALSE;
+ } else {
+ app_indicator_set_status (ci, APP_INDICATOR_STATUS_ACTIVE);
+ gtk_menu_item_set_label(GTK_MENU_ITEM(widget), "Get Attention");
+ active = TRUE;
+ }
}
static void
local_icon_toggle_cb (GtkWidget *widget, gpointer data)
{
- AppIndicator * ci = APP_INDICATOR(data);
+ AppIndicator * ci = APP_INDICATOR(data);
- if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
- app_indicator_set_icon_full(ci, LOCAL_ICON, "Local Icon");
- } else {
- app_indicator_set_icon_full(ci, "indicator-messages", "System Icon");
- }
+ if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
+ app_indicator_set_icon_full(ci, LOCAL_ICON, "Local Icon");
+ } else {
+ app_indicator_set_icon_full(ci, "indicator-messages", "System Icon");
+ }
- return;
+ return;
}
static void
@@ -100,16 +100,7 @@ image_clicked_cb (GtkWidget *widget, gpointer data)
static void
scroll_event_cb (AppIndicator * ci, gint delta, guint direction, gpointer data)
{
- g_print("Got scroll event! delta: %d, direction: %d\n", delta, direction);
-}
-
-static void
-secondary_activate_cb (AppIndicator * ci, gint x, gint y, gpointer data)
-{
- g_print("Got secondary activate event at %dx%d\n", x, y);
-
- if (app_indicator_get_status (ci) == APP_INDICATOR_STATUS_ATTENTION)
- app_indicator_set_status(ci, APP_INDICATOR_STATUS_ACTIVE);
+ g_print("Got scroll event! delta: %d, direction: %d\n", delta, direction);
}
static void
@@ -147,15 +138,15 @@ guint percentage = 0;
static gboolean
percent_change (gpointer user_data)
{
- percentage = (percentage + 1) % 100;
- if (can_haz_label) {
- gchar * percentstr = g_strdup_printf("%d%%", percentage + 1);
- app_indicator_set_label (APP_INDICATOR(user_data), percentstr, "100%");
- g_free(percentstr);
- } else {
- app_indicator_set_label (APP_INDICATOR(user_data), NULL, NULL);
- }
- return TRUE;
+ percentage = (percentage + 1) % 100;
+ if (can_haz_label) {
+ gchar * percentstr = g_strdup_printf("%d%%", percentage + 1);
+ app_indicator_set_label (APP_INDICATOR(user_data), percentstr, "100%");
+ g_free(percentstr);
+ } else {
+ app_indicator_set_label (APP_INDICATOR(user_data), NULL, NULL);
+ }
+ return TRUE;
}
int
@@ -170,20 +161,17 @@ main (int argc, char ** argv)
"indicator-messages",
APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
- g_assert (IS_APP_INDICATOR (ci));
+ g_assert (IS_APP_INDICATOR (ci));
g_assert (G_IS_OBJECT (ci));
- app_indicator_set_status (ci, APP_INDICATOR_STATUS_ACTIVE);
- app_indicator_set_attention_icon_full(ci, "indicator-messages-new", "System Messages Icon Highlighted");
- app_indicator_set_label (ci, "1%", "100%");
+ app_indicator_set_status (ci, APP_INDICATOR_STATUS_ACTIVE);
+ app_indicator_set_attention_icon_full(ci, "indicator-messages-new", "System Messages Icon Highlighted");
+ app_indicator_set_label (ci, "1%", "100%");
- g_signal_connect (ci, "scroll-event",
+ g_signal_connect (ci, "scroll-event",
G_CALLBACK (scroll_event_cb), NULL);
- g_signal_connect (ci, "secondary-activate",
- G_CALLBACK (secondary_activate_cb), NULL);
-
- g_timeout_add_seconds(1, percent_change, ci);
+ g_timeout_add_seconds(1, percent_change, ci);
menu = gtk_menu_new ();
GtkWidget *item = gtk_check_menu_item_new_with_label ("1");
@@ -207,37 +195,38 @@ main (int argc, char ** argv)
g_signal_connect (toggle_item, "activate",
G_CALLBACK (toggle_sensitivity_cb), item);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), toggle_item);
- gtk_widget_show(toggle_item);
+ gtk_widget_show(toggle_item);
item = gtk_image_menu_item_new_from_stock (GTK_STOCK_NEW, NULL);
g_signal_connect (item, "activate",
G_CALLBACK (image_clicked_cb), NULL);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show(item);
+ gtk_widget_show(item);
item = gtk_menu_item_new_with_label ("Get Attention");
g_signal_connect (item, "activate",
G_CALLBACK (activate_clicked_cb), ci);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show(item);
+ gtk_widget_show(item);
+ app_indicator_set_secondary_activate_target(ci, item);
item = gtk_menu_item_new_with_label ("Show label");
- label_toggle_cb(item, ci);
+ label_toggle_cb(item, ci);
g_signal_connect (item, "activate",
G_CALLBACK (label_toggle_cb), ci);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show(item);
+ gtk_widget_show(item);
item = gtk_check_menu_item_new_with_label ("Set Local Icon");
g_signal_connect (item, "activate",
G_CALLBACK (local_icon_toggle_cb), ci);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_show(item);
+ gtk_widget_show(item);
app_indicator_set_menu (ci, GTK_MENU (menu));
- mainloop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(mainloop);
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
- return 0;
+ return 0;
}