[cheese/three-point-oh] Auto hiding of buttons area in fullscreen mode



commit d138dbf9e4d0081f2e16a83e4d66ba27c358788c
Author: Yuvaraj Pandian T <yuvipanda gmail com>
Date:   Thu Jun 3 03:08:01 2010 +0530

    Auto hiding of buttons area in fullscreen mode

 data/cheese-main-window.ui |    3 ++-
 valasrc/cheese-window.vala |   38 +++++++++++++++++++++++++++++++++++---
 2 files changed, 37 insertions(+), 4 deletions(-)
---
diff --git a/data/cheese-main-window.ui b/data/cheese-main-window.ui
index 3743edf..5c5a9b2 100644
--- a/data/cheese-main-window.ui
+++ b/data/cheese-main-window.ui
@@ -18,6 +18,7 @@
 	  <object class="GtkVBox" id="view_area">
 	    <child>
 	      <object class="GtkClutterEmbed" id="viewport">
+		<property name="events">GDK_POINTER_MOTION_MASK</property>
 		<property name="height_request">450</property>
 		<property name="width_request">600</property>
 	      </object>
@@ -27,7 +28,7 @@
 	      </packing>
 	    </child>
 	    <child>
-	      <object class="GtkHBox" id="action_buttons_area">
+	      <object class="GtkHBox" id="buttons_area">
 		<child>		  
 		  <object class="GtkHBox" id="mode_toggle_buttons">
 		    <property name="homogeneous">True</property>
diff --git a/valasrc/cheese-window.vala b/valasrc/cheese-window.vala
index 340ae6a..b4fddb8 100644
--- a/valasrc/cheese-window.vala
+++ b/valasrc/cheese-window.vala
@@ -5,8 +5,7 @@ using Clutter;
 using Config;
 using Eog;
 
-const int DEFAULT_WINDOW_WIDTH = 600;
-const int DEFAULT_WINDOW_HEIGHT = 450;
+const int FULLSCREEN_TIMEOUT_INTERVAL = 5 * 1000;
 
 public class Cheese.MainWindow : Gtk.Window {
 
@@ -27,6 +26,7 @@ public class Cheese.MainWindow : Gtk.Window {
 	private Gtk.Button take_action_button;
 	private Gtk.ToggleButton effects_toggle_button;
 	private Gtk.Button leave_fullscreen_button;
+	private Gtk.HBox buttons_area;
 	
 	private bool is_fullscreen;
 	private bool is_wide_mode;
@@ -65,6 +65,32 @@ public class Cheese.MainWindow : Gtk.Window {
 		set_fullscreen_mode(action.active);
 	}
 
+	private TimeoutSource timeout;
+	private void clear_fullscreen_timeout() {
+		if (timeout != null) {
+			timeout.destroy();
+			timeout = null;
+		}
+	}
+			
+	private void set_fullscreen_timeout () {
+		timeout = new TimeoutSource(FULLSCREEN_TIMEOUT_INTERVAL);
+		timeout.attach (null);
+		timeout.set_callback(() => { buttons_area.hide();
+									 clear_fullscreen_timeout();
+									 return true;});
+	}
+
+	private bool fullscreen_motion_notify_callback(Gtk.Widget viewport, EventMotion e) {
+		// Start a new timeout at the end of every mouse pointer movement.
+		// So all timeouts will be cancelled, except one at the last pointer movement.
+		// We call show even if the button isn't hidden.
+		clear_fullscreen_timeout();
+		buttons_area.show();
+		set_fullscreen_timeout();
+		return true;
+	}
+	
 	private void set_fullscreen_mode(bool fullscreen_mode) {
 		// After the first time the window has been shown using this.show_all(),
 		// the value of leave_fullscreen_button_container.no_show_all should be set to false
@@ -87,7 +113,9 @@ public class Cheese.MainWindow : Gtk.Window {
 			foreach (Gtk.Button b in buttons) {
 				b.relief = Gtk.ReliefStyle.NONE;
 			}
-			this.fullscreen();			
+			this.fullscreen();
+			viewport_widget.motion_notify_event.connect(fullscreen_motion_notify_callback);
+			set_fullscreen_timeout();
 		}
 		else {
 			if (is_wide_mode) {
@@ -103,6 +131,9 @@ public class Cheese.MainWindow : Gtk.Window {
 			foreach (Gtk.Button b in buttons) {
 				b.relief = Gtk.ReliefStyle.NORMAL;
 			}
+			// Show the buttons area anyway - it might've been hidden in fullscreen mode
+			buttons_area.show();
+			viewport_widget.motion_notify_event.disconnect(fullscreen_motion_notify_callback);
 			this.unfullscreen();
 		}
 	}
@@ -174,6 +205,7 @@ public class Cheese.MainWindow : Gtk.Window {
 		take_action_button = (Gtk.Button) builder.get_object("take_action_button");
 		effects_toggle_button = (Gtk.ToggleButton) builder.get_object("effects_toggle_button");
 		leave_fullscreen_button = (Gtk.Button) builder.get_object("leave_fullscreen_button");
+		buttons_area = (Gtk.HBox) builder.get_object("buttons_area");
 
 		// Array contains all 'buttons', for easier manipulation
 		// IMPORTANT: IF ANOTHER BUTTON IS ADDED UNDER THE VIEWPORT, ADD IT TO THIS ARRAY



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]