diff options
author | 2010-07-30 21:52:09 +0200 | |
---|---|---|
committer | 2010-07-30 21:52:09 +0200 | |
commit | 4900747be558fa7bcdade34a21aa12d10010de40 (patch) | |
tree | b4c9d1d00b1a710fd697c42e576545f86bcb9e6f /plugins/gtkui | |
parent | 6cb93555535f85e5e0744cc6f9bcf6f189115287 (diff) |
added option to hide system tray icon
Diffstat (limited to 'plugins/gtkui')
-rw-r--r-- | plugins/gtkui/callbacks.c | 1 | ||||
-rw-r--r-- | plugins/gtkui/callbacks.h | 4 | ||||
-rw-r--r-- | plugins/gtkui/deadbeef.glade | 20 | ||||
-rw-r--r-- | plugins/gtkui/gtkui.c | 88 | ||||
-rw-r--r-- | plugins/gtkui/interface.c | 9 | ||||
-rw-r--r-- | plugins/gtkui/prefwin.c | 12 |
6 files changed, 107 insertions, 27 deletions
diff --git a/plugins/gtkui/callbacks.c b/plugins/gtkui/callbacks.c index fabeae76..800b7489 100644 --- a/plugins/gtkui/callbacks.c +++ b/plugins/gtkui/callbacks.c @@ -1035,3 +1035,4 @@ create_seekbar (gchar *widget_name, gchar *string1, gchar *string2, { return GTK_WIDGET (ddb_seekbar_new ()); } + diff --git a/plugins/gtkui/callbacks.h b/plugins/gtkui/callbacks.h index 67251101..e7961bac 100644 --- a/plugins/gtkui/callbacks.h +++ b/plugins/gtkui/callbacks.h @@ -938,3 +938,7 @@ on_proxyuser_changed (GtkEditable *editable, void on_proxypassword_changed (GtkEditable *editable, gpointer user_data); + +void +on_hide_tray_icon_toggled (GtkToggleButton *togglebutton, + gpointer user_data); diff --git a/plugins/gtkui/deadbeef.glade b/plugins/gtkui/deadbeef.glade index d73983ef..625eccbd 100644 --- a/plugins/gtkui/deadbeef.glade +++ b/plugins/gtkui/deadbeef.glade @@ -2761,6 +2761,26 @@ Album</property> </child> <child> + <widget class="GtkCheckButton" id="hide_tray_icon"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">Hide system tray icon</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <property name="active">False</property> + <property name="inconsistent">False</property> + <property name="draw_indicator">True</property> + <signal name="toggled" handler="on_hide_tray_icon_toggled" last_modification_time="Fri, 30 Jul 2010 18:27:34 GMT"/> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> <widget class="GtkNotebook" id="notebook4"> <property name="visible">True</property> <property name="can_focus">True</property> diff --git a/plugins/gtkui/gtkui.c b/plugins/gtkui/gtkui.c index ac993b57..94db2ce7 100644 --- a/plugins/gtkui/gtkui.c +++ b/plugins/gtkui/gtkui.c @@ -220,11 +220,13 @@ update_songinfo (gpointer ctx) { void set_tray_tooltip (const char *text) { + if (trayicon) { #if (GTK_MINOR_VERSION < 16) gtk_status_icon_set_tooltip (trayicon, text); #else gtk_status_icon_set_tooltip_text (trayicon, text); #endif + } } gboolean @@ -510,6 +512,61 @@ gtkui_on_volumechanged (DB_event_t *ev, uintptr_t data) { return 0; } +static gboolean +gtkui_update_status_icon (gpointer unused) { + int hide_tray_icon = deadbeef->conf_get_int ("gtkui.hide_tray_icon", 0); + if (hide_tray_icon && !trayicon) { + return FALSE; + } + if (trayicon) { + if (hide_tray_icon) { + g_object_set (trayicon, "visible", FALSE, NULL); + } + else { + g_object_set (trayicon, "visible", TRUE, NULL); + } + return FALSE; + } + // system tray icon + traymenu = create_traymenu (); + + const char *icon_name = deadbeef->conf_get_str ("gtkui.custom_tray_icon", TRAY_ICON); + GtkIconTheme *theme = gtk_icon_theme_get_default(); + + if (!gtk_icon_theme_has_icon(theme, icon_name)) + icon_name = "deadbeef"; + else { + GtkIconInfo *icon_info = gtk_icon_theme_lookup_icon(theme, icon_name, 48, GTK_ICON_LOOKUP_USE_BUILTIN); + const gboolean icon_is_builtin = gtk_icon_info_get_filename(icon_info) == NULL; + gtk_icon_info_free(icon_info); + icon_name = icon_is_builtin ? "deadbeef" : icon_name; + } + + trayicon = gtk_status_icon_new_from_icon_name(icon_name); + if (hide_tray_icon) { + g_object_set (trayicon, "visible", FALSE, NULL); + } + + set_tray_tooltip ("DeaDBeeF"); + +#if GTK_MINOR_VERSION <= 14 + g_signal_connect ((gpointer)trayicon, "activate", G_CALLBACK (on_trayicon_activate), NULL); +#else + g_signal_connect ((gpointer)trayicon, "scroll_event", G_CALLBACK (on_trayicon_scroll_event), NULL); + g_signal_connect ((gpointer)trayicon, "button_press_event", G_CALLBACK (on_trayicon_button_press_event), NULL); +#endif + g_signal_connect ((gpointer)trayicon, "popup_menu", G_CALLBACK (on_trayicon_popup_menu), NULL); + + return FALSE; +} + +static void +gtkui_hide_status_icon () { + if (trayicon) { + g_object_set (trayicon, "visible", FALSE, NULL); + } +} + static int gtkui_on_configchanged (DB_event_t *ev, uintptr_t data) { // order and looping @@ -535,6 +592,9 @@ gtkui_on_configchanged (DB_event_t *ev, uintptr_t data) { int stop_after_current = deadbeef->conf_get_int ("playlist.stop_after_current", 0); gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (lookup_widget (mainwin, "stop_after_current")), stop_after_current ? TRUE : FALSE); + // tray icon + g_idle_add (gtkui_update_status_icon, NULL); + return 0; } @@ -808,33 +868,6 @@ gtkui_thread (void *ctx) { gtk_disable_setlocale (); gtk_init (&argc, (char ***)&argv); - // system tray icon - traymenu = create_traymenu (); - - const char *icon_name = deadbeef->conf_get_str ("gtkui.custom_tray_icon", TRAY_ICON); - GtkIconTheme *theme = gtk_icon_theme_get_default(); - - if (!gtk_icon_theme_has_icon(theme, icon_name)) - icon_name = "deadbeef"; - else { - GtkIconInfo *icon_info = gtk_icon_theme_lookup_icon(theme, icon_name, 48, GTK_ICON_LOOKUP_USE_BUILTIN); - const gboolean icon_is_builtin = gtk_icon_info_get_filename(icon_info) == NULL; - gtk_icon_info_free(icon_info); - icon_name = icon_is_builtin ? "deadbeef" : icon_name; - } - - trayicon = gtk_status_icon_new_from_icon_name(icon_name); - - set_tray_tooltip ("DeaDBeeF"); - //gtk_status_icon_set_title (GTK_STATUS_ICON (trayicon), "DeaDBeeF"); -#if GTK_MINOR_VERSION <= 14 - g_signal_connect ((gpointer)trayicon, "activate", G_CALLBACK (on_trayicon_activate), NULL); -#else - g_signal_connect ((gpointer)trayicon, "scroll_event", G_CALLBACK (on_trayicon_scroll_event), NULL); - g_signal_connect ((gpointer)trayicon, "button_press_event", G_CALLBACK (on_trayicon_button_press_event), NULL); -#endif - g_signal_connect ((gpointer)trayicon, "popup_menu", G_CALLBACK (on_trayicon_popup_menu), NULL); - mainwin = create_mainwin (); gtkpl_init (); @@ -941,6 +974,7 @@ gtkui_thread (void *ctx) { eq_window_destroy (); trkproperties_destroy (); progress_destroy (); + gtkui_hide_status_icon (); gtk_widget_destroy (mainwin); gtk_widget_destroy (searchwin); gdk_threads_leave (); diff --git a/plugins/gtkui/interface.c b/plugins/gtkui/interface.c index 93f581b5..ff747791 100644 --- a/plugins/gtkui/interface.c +++ b/plugins/gtkui/interface.c @@ -1558,6 +1558,7 @@ create_prefwin (void) GtkWidget *vbox9; GtkWidget *pref_close_send_to_tray; GtkWidget *mmb_delete_playlist; + GtkWidget *hide_tray_icon; GtkWidget *notebook4; GtkWidget *vbox21; GtkWidget *override_bar_colors; @@ -1800,6 +1801,10 @@ create_prefwin (void) gtk_widget_show (mmb_delete_playlist); gtk_box_pack_start (GTK_BOX (vbox9), mmb_delete_playlist, FALSE, FALSE, 0); + hide_tray_icon = gtk_check_button_new_with_mnemonic (_("Hide system tray icon")); + gtk_widget_show (hide_tray_icon); + gtk_box_pack_start (GTK_BOX (vbox9), hide_tray_icon, FALSE, FALSE, 0); + notebook4 = gtk_notebook_new (); gtk_widget_show (notebook4); gtk_box_pack_start (GTK_BOX (vbox9), notebook4, TRUE, TRUE, 0); @@ -2440,6 +2445,9 @@ create_prefwin (void) g_signal_connect ((gpointer) mmb_delete_playlist, "toggled", G_CALLBACK (on_mmb_delete_playlist_toggled), NULL); + g_signal_connect ((gpointer) hide_tray_icon, "toggled", + G_CALLBACK (on_hide_tray_icon_toggled), + NULL); g_signal_connect ((gpointer) override_bar_colors, "toggled", G_CALLBACK (on_override_bar_colors_toggled), NULL); @@ -2583,6 +2591,7 @@ create_prefwin (void) GLADE_HOOKUP_OBJECT (prefwin, vbox9, "vbox9"); GLADE_HOOKUP_OBJECT (prefwin, pref_close_send_to_tray, "pref_close_send_to_tray"); GLADE_HOOKUP_OBJECT (prefwin, mmb_delete_playlist, "mmb_delete_playlist"); + GLADE_HOOKUP_OBJECT (prefwin, hide_tray_icon, "hide_tray_icon"); GLADE_HOOKUP_OBJECT (prefwin, notebook4, "notebook4"); GLADE_HOOKUP_OBJECT (prefwin, vbox21, "vbox21"); GLADE_HOOKUP_OBJECT (prefwin, override_bar_colors, "override_bar_colors"); diff --git a/plugins/gtkui/prefwin.c b/plugins/gtkui/prefwin.c index cb2e73b2..2f0618cf 100644 --- a/plugins/gtkui/prefwin.c +++ b/plugins/gtkui/prefwin.c @@ -504,6 +504,9 @@ on_preferences_activate (GtkMenuItem *menuitem, // close_send_to_tray gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "pref_close_send_to_tray")), deadbeef->conf_get_int ("close_send_to_tray", 0)); + // hide tray icon + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "hide_tray_icon")), deadbeef->conf_get_int ("gtkui.hide_tray_icon", 0)); + // mmb_delete_playlist gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (lookup_widget (w, "mmb_delete_playlist")), deadbeef->conf_get_int ("gtkui.mmb_delete_playlist", 0)); @@ -731,6 +734,15 @@ on_pref_close_send_to_tray_clicked (GtkButton *button, } void +on_hide_tray_icon_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + int active = gtk_toggle_button_get_active (togglebutton); + deadbeef->conf_set_int ("gtkui.hide_tray_icon", active); + deadbeef->sendmessage (M_CONFIGCHANGED, 0, 0, 0); +} + +void on_mmb_delete_playlist_toggled (GtkToggleButton *togglebutton, gpointer user_data) { |