[PATCH 2/2] autohide sidebar in compact mode.



---
 data/gnome-shell.schemas |   14 +++++++
 js/ui/sidebar.js         |   87 ++++++++++++++++++++++++++++++++++++++++++++++
 js/ui/widgetBox.js       |   18 +++++++++
 3 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/data/gnome-shell.schemas b/data/gnome-shell.schemas
index 9ace3bc..fb8cfe0 100644
--- a/data/gnome-shell.schemas
+++ b/data/gnome-shell.schemas
@@ -74,6 +74,20 @@
       </schema>
 
       <schema>
+        <key>/schemas/desktop/gnome/shell/sidebar/autohide</key>
+	<applyto>/desktop/gnome/shell/sidebar/autohide</applyto>
+	<owner>gnome-shell</owner>
+	<type>bool</type>
+	<default>true</default>
+	<locale name="C">
+	  <short>Whether the sidebar should autmatically hide itself in compact mode</short>
+	  <long>
+	    Controls the autohide state of the sidebar.
+	  </long>
+	</locale>
+      </schema>
+
+      <schema>
         <key>/schemas/desktop/gnome/shell/sidebar/widgets</key>
 	<applyto>/desktop/gnome/shell/sidebar/widgets</applyto>
 	<owner>gnome-shell</owner>
diff --git a/js/ui/sidebar.js b/js/ui/sidebar.js
index 5389f25..d19be89 100644
--- a/js/ui/sidebar.js
+++ b/js/ui/sidebar.js
@@ -4,6 +4,7 @@ const Big = imports.gi.Big;
 const Clutter = imports.gi.Clutter;
 const Shell = imports.gi.Shell;
 const Lang = imports.lang;
+const Mainloop = imports.mainloop;
 
 const Main = imports.ui.main;
 const Panel = imports.ui.panel;
@@ -58,6 +59,12 @@ Sidebar.prototype = {
         if (this._visible)
             Main.chrome.addActor(this.actor);
 
+        this._autohide = this._gconf.get_boolean ("sidebar/autohide");
+        if (this._autohide)
+            this.actor.set_reactive(true);
+
+        this._hidden = false;
+        this._wantsToHide = false;
         this._widgets = [];
         this.addWidget(new ToggleWidget());
 
@@ -69,8 +76,16 @@ Sidebar.prototype = {
                             Lang.bind(this, this._expandedChanged));
         this._gconf.connect('changed::sidebar/visible',
                             Lang.bind(this, this._visibleChanged));
+        this._gconf.connect('changed::sidebar/autohide',
+                            Lang.bind(this, this._autohideChanged));
+
+        this.actor.connect('enter-event',Lang.bind(this,this._restoreHidden));
+        this.actor.connect('leave-event',Lang.bind(this,this._startHideTimeout));
 
         this._adjustPosition();
+
+        if (this._autohide)
+            this._hide();
     },
 
     addWidget: function(widget) {
@@ -118,6 +133,22 @@ Sidebar.prototype = {
             this._collapse();
     },
 
+    _autohideChanged: function() {
+        let autohide = this._gconf.get_boolean("sidebar/autohide");
+        if (autohide == this._autohide)
+            return;
+
+        this._autohide = autohide;
+        if (autohide) {
+            this.actor.set_reactive(true);
+            this._hide();
+        }
+        else {
+            this.actor.set_reactive(false);
+            this._restore();
+        }
+    },
+
     _expand: function() {
         this._expanded = true;
         for (let i = 0; i < this._widgets.length; i++)
@@ -142,6 +173,62 @@ Sidebar.prototype = {
                                  } });
     },
 
+    _hide: function() {
+        if(!this._expanded)
+        {
+            this._hidden = true;
+            for (let i = 0; i < this._widgets.length; i++)
+                this._widgets[i].hide();
+
+            // Updated the strut/stage area after the animation completes
+            Tweener.addTween(this, { time: WidgetBox.ANIMATION_TIME/2,
+                                     onComplete: function () {
+                                         this.actor.width = WidgetBox.WIDGETBOX_PADDING*2+SIDEBAR_PADDING;
+                                     } });
+        }
+    },
+
+    _restore: function() {
+        if(!this._expanded)
+        {
+            this._hidden = false;
+            for (let i = 0; i < this._widgets.length; i++)
+                this._widgets[i].restore();
+
+            // Updated the strut/stage area after the animation completes
+            Tweener.addTween(this, { time: WidgetBox.ANIMATION_TIME/2,
+                                     onComplete: function () {
+                                         this.actor.width = SIDEBAR_COLLAPSED_WIDTH;
+                                     } });
+        }
+    },
+
+    _restoreHidden: function(actor,event) {
+        if(this._hidden)
+        {
+            this._restore();
+        }
+        this._wantsToHide = false;
+        return false;
+    },
+
+    _startHideTimeout: function(actor,event) {
+        if(!this._expanded)
+        {
+            this._wantsToHide = true;
+            Mainloop.timeout_add(2000,Lang.bind(this,this._hideTimeoutFunc));
+        }
+        return false;
+    },
+
+    _hideTimeoutFunc: function() {
+        if(this._wantsToHide)
+        {
+            this._hide();
+        }
+        return false;
+    },
+
     destroy: function() {
         this.hide();
 
diff --git a/js/ui/widgetBox.js b/js/ui/widgetBox.js
index b7dae74..c4343d4 100644
--- a/js/ui/widgetBox.js
+++ b/js/ui/widgetBox.js
@@ -373,6 +373,24 @@ WidgetBox.prototype = {
         Main.chrome.untrackActor(this._hbox);
     },
 
+    hide: function() {
+        if(this.state == Widget.STATE_COLLAPSED)
+        {
+            Tweener.addTween(this._cbox, { x: -Widget.COLLAPSED_WIDTH,
+                                           time: ANIMATION_TIME/2,
+                                           transition: "easeOutQuad" });
+        }
+    },
+
+    restore: function() {
+        if(this.state == Widget.STATE_COLLAPSED)
+        {
+            Tweener.addTween(this._cbox, { x: 0,
+                                           time: ANIMATION_TIME/2,
+                                           transition: "easeOutQuad" });
+        }
+    },
+
     destroy: function() {
         if (this._widget.destroy)
             this._widget.destroy();
-- 
1.6.5.3


--=-asl5sckQgXgHW69JxpmX--



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