static void notify(const char *title, const char *msg, const char *icon) { if (msg == NULL) return; /* Don't spam the same message */ if (notify_last_msg) { if (notify_last_msg && strcmp(msg, notify_last_msg) == 0) return; g_free(notify_last_msg); } notify_last_msg = g_strdup(msg); if (nn != NULL) notify_notification_close(nn, NULL); #if NOTIFY_CHECK_VERSION(0,7,0) nn = notify_notification_new(title, msg, icon); notify_notification_set_hint(nn, "transient", g_variant_new_boolean(TRUE)); #else if (gtk_status_icon_get_visible(status_icon)) nn = notify_notification_new_with_status_icon(title, msg, icon, status_icon); else nn = notify_notification_new(title, msg, icon, NULL); #endif notify_notification_set_timeout(nn, 5000); g_signal_connect(nn, "closed", G_CALLBACK(notify_closed), NULL); notify_notification_show(nn, NULL); }
static gboolean delete_window (void) { if (!gtk_status_icon_get_visible (status_icon)) { gtk_main_quit (); return FALSE; } gtk_widget_hide (window); return TRUE; }
void on_visible_get_clicked(GtkWidget *widget, gpointer data) { GtkEntry *entry = data; gboolean val; val = gtk_status_icon_get_visible(status_icon); if (val) gtk_entry_set_text(entry, "true"); else gtk_entry_set_text(entry, "false"); }
gboolean notification_trayicon_is_available(void) { gboolean is_available; is_available = FALSE; if(trayicon) { if(gtk_status_icon_is_embedded(trayicon) && gtk_status_icon_get_visible(trayicon)) is_available = TRUE; } return is_available; }
static void icon_activated (GtkStatusIcon *icon) { GtkWidget *content_area; GtkWidget *dialog; GtkWidget *toggle; dialog = g_object_get_data (G_OBJECT (icon), "test-status-icon-dialog"); if (dialog == NULL) { dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CLOSE, "You wanna test the status icon ?"); gtk_window_set_screen (GTK_WINDOW (dialog), gtk_status_icon_get_screen (icon)); gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); g_object_set_data_full (G_OBJECT (icon), "test-status-icon-dialog", dialog, (GDestroyNotify) gtk_widget_destroy); g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_hide), NULL); g_signal_connect (dialog, "delete_event", G_CALLBACK (gtk_widget_hide_on_delete), NULL); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); toggle = gtk_toggle_button_new_with_mnemonic ("_Show the icon"); gtk_box_pack_end (GTK_BOX (content_area), toggle, TRUE, TRUE, 6); gtk_widget_show (toggle); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), gtk_status_icon_get_visible (icon)); g_signal_connect (toggle, "toggled", G_CALLBACK (visible_toggle_toggled), NULL); toggle = gtk_toggle_button_new_with_mnemonic ("_Change images"); gtk_box_pack_end (GTK_BOX (content_area), toggle, TRUE, TRUE, 6); gtk_widget_show (toggle); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle), timeout != 0); g_signal_connect (toggle, "toggled", G_CALLBACK (timeout_toggle_toggled), NULL); } gtk_window_present (GTK_WINDOW (dialog)); }
static gboolean init_timeout (void) { guint num_processes; gfloat cpu, memory, swap; guint64 swap_free, swap_total; gchar tooltip[1024]; xtm_task_manager_get_system_info (task_manager, &num_processes, &cpu, &memory, &swap); xtm_process_window_set_system_info (XTM_PROCESS_WINDOW (window), num_processes, cpu, memory, swap); xtm_task_manager_get_swap_usage (task_manager, &swap_free, &swap_total); xtm_process_window_show_swap_usage (XTM_PROCESS_WINDOW (window), (swap_total > 0)); if (gtk_status_icon_get_visible (status_icon)) { #if GTK_CHECK_VERSION (2,16,0) g_snprintf (tooltip, 1024, _("<b>Processes:</b> %u\n" "<b>CPU:</b> %.0f%%\n" "<b>Memory:</b> %.0f%%\n" "<b>Swap:</b> %.0f%%"), num_processes, cpu, memory, swap); gtk_status_icon_set_tooltip_markup (GTK_STATUS_ICON (status_icon), tooltip); #else g_snprintf (tooltip, 1024, _("Processes: %u\n" "CPU: %.0f%%\n" "Memory: %.0f%%\n" "Swap: %.0f%%"), num_processes, cpu, memory, swap); gtk_status_icon_set_tooltip (GTK_STATUS_ICON (status_icon), tooltip); #endif } xtm_task_manager_update_model (task_manager); if (timeout == 0) { guint refresh_rate; g_object_get (settings, "refresh-rate", &refresh_rate, NULL); timeout = g_timeout_add (refresh_rate, (GSourceFunc)init_timeout, NULL); } return TRUE; }
void show_notification(const gchar *summary, const gchar *message, const gchar *action, gint timeout, GCallback handler) { NotifyActionCallback callback; #ifndef HAVE_APP_INDICATOR GdkScreen *screen; GdkRectangle area; #endif /* HAVE_APP_INDICATOR */ if (notify_is_initted() == FALSE) return; if (notify) { g_signal_handlers_destroy(notify); notify_notification_close(notify, NULL); } notify = notify_notification_new(summary, message, ACTIVE_ICON_NAME); notify_notification_set_timeout(notify, timeout); #ifndef HAVE_APP_INDICATOR if (gtk_status_icon_get_visible(statusicon) == TRUE) { gtk_status_icon_get_geometry(statusicon, &screen, &area, NULL); notify_notification_set_hint_int32(notify, "x", area.x + area.width / 2); notify_notification_set_hint_int32(notify, "y", area.y + area.height / 2); } #endif /* HAVE_APP_INDICATOR */ notify_notification_set_urgency(notify, NOTIFY_URGENCY_NORMAL); callback = handler ? NOTIFY_ACTION_CALLBACK(handler) : notify_action; notify_notification_add_action(notify, "default", "action", callback, NULL, NULL); if (action != NULL) notify_notification_add_action(notify, "button", action, callback, NULL, NULL); notify_notification_show(notify, NULL); }
static gboolean handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data) { if ((condition & G_IO_IN) != 0) { GString *string; GError *err = NULL; string = g_string_new (NULL); while (channel->is_readable == FALSE); do { gint status; gchar *command = NULL, *value = NULL, **args; do { status = g_io_channel_read_line_string (channel, string, NULL, &err); while (gdk_events_pending ()) gtk_main_iteration (); } while (status == G_IO_STATUS_AGAIN); if (status != G_IO_STATUS_NORMAL) { if (err) { g_printerr ("yad_notification_handle_stdin(): %s\n", err->message); g_error_free (err); err = NULL; } /* stop handling but not exit */ g_io_channel_shutdown (channel, TRUE, NULL); return FALSE; } strip_new_line (string->str); if (!string->str[0]) continue; args = g_strsplit (string->str, ":", 2); command = g_strdup (args[0]); if (args[1]) value = g_strdup (args[1]); g_strfreev (args); if (value) g_strstrip (value); if (!g_ascii_strcasecmp (command, "icon") && value) { g_free (icon); icon = g_strdup (value); if (gtk_status_icon_get_visible (status_icon) && gtk_status_icon_is_embedded (status_icon)) set_icon (); } else if (!g_ascii_strcasecmp (command, "tooltip")) { if (g_utf8_validate (value, -1, NULL)) { gchar *message = g_strcompress (value); if (!options.data.no_markup) gtk_status_icon_set_tooltip_markup (status_icon, message); else gtk_status_icon_set_tooltip_text (status_icon, message); g_free (message); } else g_printerr (_("Invalid UTF-8 in tooltip!\n")); } else if (!g_ascii_strcasecmp (command, "visible")) { #if !GTK_CHECK_VERSION(2,22,0) if (!g_ascii_strcasecmp (value, "blink")) { gboolean state = gtk_status_icon_get_blinking (status_icon); gtk_status_icon_set_blinking (status_icon, !state); } else #endif if (!g_ascii_strcasecmp (value, "false")) { gtk_status_icon_set_visible (status_icon, FALSE); #if !GTK_CHECK_VERSION(2,22,0) gtk_status_icon_set_blinking (status_icon, FALSE); #endif } else { gtk_status_icon_set_visible (status_icon, TRUE); #if !GTK_CHECK_VERSION(2,22,0) gtk_status_icon_set_blinking (status_icon, FALSE); #endif } } else if (!g_ascii_strcasecmp (command, "action")) { g_free (action); if (value) action = g_strdup (value); } else if (!g_ascii_strcasecmp (command, "quit")) { exit_code = YAD_RESPONSE_OK; gtk_main_quit (); } else if (!g_ascii_strcasecmp (command, "menu")) { if (value) parse_menu_str (value); } else g_printerr (_("Unknown command '%s'\n"), command); g_free (command); g_free (value); } while (g_io_channel_get_buffer_condition (channel) == G_IO_IN); g_string_free (string, TRUE); } if ((condition & G_IO_HUP) != 0) { g_io_channel_shutdown (channel, TRUE, NULL); gtk_main_quit (); return FALSE; } return TRUE; }