[Xfce4-commits] <xfmpc:master> main-window: Add status icon in the notification area

Mike Massonnet noreply at xfce.org
Sat Aug 13 10:54:03 CEST 2011


Updating branch refs/heads/master
         to 24132cf3d9ca3e4a83e9337b096fc13bb128d7bb (commit)
       from 241b415a196ec5e95be43b96259e68f28d0cbdeb (commit)

commit 24132cf3d9ca3e4a83e9337b096fc13bb128d7bb
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Sun Jul 31 19:44:36 2011 +0200

    main-window: Add status icon in the notification area
    
    Show a status icon, clicking on it will hide/show the application,
    the application won't show in the taskbar.

 src/main-window.vala |   24 ++++++++++++++++++++++--
 src/preferences.vala |    6 ++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/src/main-window.vala b/src/main-window.vala
index db0c97a..1b3136b 100644
--- a/src/main-window.vala
+++ b/src/main-window.vala
@@ -23,6 +23,8 @@ namespace Xfmpc {
 
 	public class MainWindow : Window {
 
+		private Gtk.StatusIcon status_icon;
+
 		private unowned Xfmpc.Mpdclient mpdclient;
 		private unowned Xfmpc.Preferences preferences;
 
@@ -63,6 +65,12 @@ namespace Xfmpc {
 			mpdclient = Xfmpc.Mpdclient.get_default ();
 			preferences = Xfmpc.Preferences.get_default ();
 
+			/* StatusIcon */
+			this.status_icon = new Gtk.StatusIcon.from_icon_name ("stock_volume");
+			show_hide_status_icon ();
+			this.status_icon.activate.connect (status_icon_activated);
+			this.preferences.notify["show-status-icon"].connect (show_hide_status_icon);
+
   	  	  	/* Window */
 			set_default_icon_name ("xfmpc");
 			set_icon_name ("stock_volume");
@@ -125,6 +133,19 @@ namespace Xfmpc {
 			Timeout.add (1000, refresh);
 		}
 
+		private void show_hide_status_icon () {
+			this.status_icon.set_visible (this.preferences.show_status_icon);
+		}
+
+		private void status_icon_activated () {
+			if (!this.visible) {
+				this.show ();
+				this.deiconify ();
+			} else {
+				this.hide ();
+			}
+		}
+
 		private bool refresh () {
 			if (this.mpdclient.is_connected ()) {
 				this.mpdclient.update_status ();
@@ -150,13 +171,12 @@ namespace Xfmpc {
    	   	   	 * window-state-event signal, so here we take the value only if
    	   	   	 * the window is visible
    	   	   	 **/
-			if ((bool) event.changed_mask & Gdk.WindowState.STICKY && this.visible){
+			if ((bool) event.changed_mask & Gdk.WindowState.STICKY && this.visible) {
 				bool sticky;
 				if (((bool) event.new_window_state & Gdk.WindowState.STICKY) == false)
 					sticky = false;
 				else
 					sticky = true;
-
 				this.preferences.last_window_state_sticky = sticky;
 			}
 
diff --git a/src/preferences.vala b/src/preferences.vala
index fa3d2a0..1656e75 100644
--- a/src/preferences.vala
+++ b/src/preferences.vala
@@ -86,6 +86,11 @@ namespace Xfmpc {
 			get { return _mpd_use_defaults; }
 			set { _mpd_use_defaults = value; store (); }
 		}
+		private bool _show_status_icon;
+		public bool show_status_icon {
+			get { return _show_status_icon; }
+			set { _show_status_icon = value; store (); }
+		}
 		private bool _show_statusbar;
 		public bool show_statusbar {
 			get { return _show_statusbar; }
@@ -113,6 +118,7 @@ namespace Xfmpc {
 			_mpd_port = 6600;
 			_mpd_password = "";
 			_mpd_use_defaults = true;
+			_show_status_icon = false;
 			_show_statusbar = true;
 			_song_format = SongFormat.ARTIST_TITLE;
 			_song_format_custom = "%a - %t";


More information about the Xfce4-commits mailing list