[Xfce4-commits] <xfce4-notes-plugin:master> Make title bar more insensitive when window is unfocused

Mike Massonnet noreply at xfce.org
Sat Nov 6 21:52:03 CET 2010


Updating branch refs/heads/master
         to b058ce6fb84ce78e6853e5e1288dac50a6039e5d (commit)
       from c66f67c893c9cf63a14428dbe7413151ff9e04d4 (commit)

commit b058ce6fb84ce78e6853e5e1288dac50a6039e5d
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Sat Nov 6 16:32:17 2010 +0100

    Make title bar more insensitive when window is unfocused
    
    Set all of the title bar elements (the menu button, title label and
    close button) insensitive when the window is unfocused.
    
    Add the method set_widget_source_color() to Xnp.IconButton to set the
    Cairo context source color normal, active or insensitive.

 lib/icon-button.vala |   13 ++++++++++---
 lib/window.vala      |   13 +++++++++----
 2 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/lib/icon-button.vala b/lib/icon-button.vala
index 1a09d42..9e9088f 100644
--- a/lib/icon-button.vala
+++ b/lib/icon-button.vala
@@ -38,6 +38,15 @@ namespace Xnp {
 
 		protected abstract void draw_icon (Cairo.Context cr, int width, int height);
 
+		protected void set_widget_source_color (Cairo.Context cr) {
+			if (sensitive && active)
+				Gdk.cairo_set_source_color (cr, style.base[Gtk.StateType.NORMAL]);
+			else if (sensitive && !active)
+				Gdk.cairo_set_source_color (cr, style.fg[Gtk.StateType.INSENSITIVE]);
+			else if (!sensitive)
+				Gdk.cairo_set_source_color (cr, style.text[Gtk.StateType.INSENSITIVE]);
+		}
+
 		public override void add (Gtk.Widget widget) {
 			warning ("This object doesn't allow packing child widgets.");
 		}
@@ -134,9 +143,7 @@ namespace Xnp {
 
 			cr.stroke ();
 
-			Gdk.cairo_set_source_color (cr,
-					active ? style.base[Gtk.StateType.NORMAL]
-						  : style.fg[Gtk.StateType.INSENSITIVE]);
+			set_widget_source_color (cr);
 			cr.set_line_width (2.66);
 			cr.move_to (x1, y1);
 			cr.line_to (x2, y2);
diff --git a/lib/window.vala b/lib/window.vala
index e545b2a..12727d4 100644
--- a/lib/window.vala
+++ b/lib/window.vala
@@ -36,6 +36,7 @@ namespace Xnp {
 		private Gdk.Pixbuf menu_pixbuf;
 		private Gdk.Pixbuf menu_hover_pixbuf;
 		private Gtk.Label title_label;
+		private Xnp.IconButton close_button;
 		private Gtk.VBox content_box;
 		private Gtk.Notebook notebook;
 		private Gtk.HBox navigation_box;
@@ -248,9 +249,9 @@ namespace Xnp {
 			this.title_label.xalign = (float)0.0;
 			title_evbox.add (this.title_label);
 			title_box.pack_start (title_evbox, true, true, 6);
-			var close_box = new Xnp.TitleBarButton (Xnp.TitleBarButtonType.CLOSE);
-			close_box.tooltip_text = _("Hide (%s)").printf (Gtk.accelerator_get_label (0xff1b, 0)); // GDK_Escape
-			title_box.pack_start (close_box, false, false, 2);
+			this.close_button = new Xnp.TitleBarButton (Xnp.TitleBarButtonType.CLOSE);
+			this.close_button.tooltip_text = _("Hide (%s)").printf (Gtk.accelerator_get_label (0xff1b, 0)); // GDK_Escape
+			title_box.pack_start (this.close_button, false, false, 2);
 			title_box.show_all ();
 			vbox_frame.pack_start (title_box, false, false, 0);
 
@@ -320,7 +321,7 @@ namespace Xnp {
 
 			/* Connect mouse click signals */
 			menu_evbox.button_press_event.connect (menu_evbox_pressed_cb);
-			close_box.clicked.connect (() => { hide (); });
+			this.close_button.clicked.connect (() => { hide (); });
 			add_box.clicked.connect (action_new_note);
 			del_box.clicked.connect (action_delete_note);
 			this.goleft_box.clicked.connect (action_prev_note);
@@ -333,11 +334,15 @@ namespace Xnp {
 				return true;
 			});
 			focus_in_event.connect (() => {
+				menu_image.sensitive = true;
 				title_label.sensitive = true;
+				close_button.sensitive = true;
 				return false;
 			});
 			focus_out_event.connect (() => {
+				menu_image.sensitive = false;
 				title_label.sensitive = false;
+				close_button.sensitive = false;
 				return false;
 			});
 			leave_notify_event.connect (navigation_leaved_cb);



More information about the Xfce4-commits mailing list