hi, i have written some small improvements (for me anyway) for the sidebar:
1) center the sidebar on the left side on the primary monitor. 2) autohide sidebar in collapsed mode (gconf key sidebar/autohide) as i'm new to gnome-shell,clutter and javascript in general the code is not perfect ... comments are welcome. flo
>From ae218d66b936450fd37d02fed40886158fae4db6 Mon Sep 17 00:00:00 2001 From: Florian Scandella <[email protected]> Date: Wed, 2 Dec 2009 18:21:30 +0100 Subject: [PATCH 1/2] position sidebar centerd on the left side of the primary monitor --- js/ui/sidebar.js | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/js/ui/sidebar.js b/js/ui/sidebar.js index 9e2ebd3..5389f25 100644 --- a/js/ui/sidebar.js +++ b/js/ui/sidebar.js @@ -69,6 +69,8 @@ Sidebar.prototype = { Lang.bind(this, this._expandedChanged)); this._gconf.connect('changed::sidebar/visible', Lang.bind(this, this._visibleChanged)); + + this._adjustPosition(); }, addWidget: function(widget) { @@ -82,6 +84,14 @@ Sidebar.prototype = { this.box.append(widgetBox.actor, Big.BoxPackFlags.NONE); this._widgets.push(widgetBox); + this._adjustPosition(); + }, + + _adjustPosition: function() { + let primary=global.get_primary_monitor(); + + this.actor.y = Math.max(primary.y + Panel.PANEL_HEIGHT,primary.height/2 - this.actor.height/2); + this.actor.x = primary.x; }, _visibleChanged: function() { -- 1.6.5.3
>From fbe37e7a4f91e6289f4a30a5a83069b356034ad5 Mon Sep 17 00:00:00 2001 From: Florian Scandella <[email protected]> Date: Wed, 2 Dec 2009 21:35:11 +0100 Subject: [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
_______________________________________________ gnome-shell-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/gnome-shell-list
