autohide sidebar in compact mode (v3)
https://bugzilla.gnome.org/show_bug.cgi?id=604118
This commit is contained in:
parent
8c178378ae
commit
38b20ca0a4
@ -73,6 +73,20 @@
|
||||
</locale>
|
||||
</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 automatically 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>
|
||||
|
@ -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,8 @@ Sidebar.prototype = {
|
||||
if (this._visible)
|
||||
Main.chrome.addActor(this.actor);
|
||||
|
||||
this._hidden = false;
|
||||
this._hideTimeoutId = 0;
|
||||
this._widgets = [];
|
||||
this.addWidget(new ToggleWidget());
|
||||
|
||||
@ -69,8 +72,14 @@ 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();
|
||||
this._autohideChanged();
|
||||
},
|
||||
|
||||
addWidget: function(widget) {
|
||||
@ -90,7 +99,7 @@ Sidebar.prototype = {
|
||||
_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.y = Math.floor(Math.max(primary.y + Panel.PANEL_HEIGHT,primary.height/2 - this.actor.height/2));
|
||||
this.actor.x = primary.x;
|
||||
},
|
||||
|
||||
@ -118,6 +127,21 @@ 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++)
|
||||
@ -135,16 +159,70 @@ Sidebar.prototype = {
|
||||
for (let i = 0; i < this._widgets.length; i++)
|
||||
this._widgets[i].collapse();
|
||||
|
||||
// Updated the strut/stage area after the animation completes
|
||||
// Update the strut/stage area after the animation completes
|
||||
Tweener.addTween(this, { time: WidgetBox.ANIMATION_TIME,
|
||||
onComplete: function () {
|
||||
onComplete: Lang.bind(this, function () {
|
||||
this.actor.width = SIDEBAR_COLLAPSED_WIDTH;
|
||||
} });
|
||||
}) });
|
||||
},
|
||||
|
||||
_hide: function() {
|
||||
if (!this._expanded) {
|
||||
this._hidden = true;
|
||||
for (let i = 0; i < this._widgets.length; i++)
|
||||
this._widgets[i].hide();
|
||||
|
||||
// Update the strut/stage area after the animation completes
|
||||
Tweener.addTween(this, { time: WidgetBox.ANIMATION_TIME / 2,
|
||||
onComplete: Lang.bind(this, function () {
|
||||
this.actor.width = Math.floor(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) {
|
||||
this._cancelHideTimeout();
|
||||
if (this._hidden)
|
||||
this._restore();
|
||||
return false;
|
||||
},
|
||||
|
||||
_startHideTimeout: function(actor, event) {
|
||||
if (!this._expanded) {
|
||||
this._cancelHideTimeout();
|
||||
this._hideTimeoutId = Mainloop.timeout_add_seconds(2, Lang.bind(this,this._hideTimeoutFunc));
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
_cancelHideTimeout: function() {
|
||||
if (this._hideTimeoutId != 0) {
|
||||
Mainloop.source_remove(this._hideTimeoutId);
|
||||
this._hideTimeoutId = 0;
|
||||
}
|
||||
},
|
||||
|
||||
_hideTimeoutFunc: function() {
|
||||
this._hide();
|
||||
return false;
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
this.hide();
|
||||
|
||||
for (let i = 0; i < this._widgets.length; i++)
|
||||
this._widgets[i].destroy();
|
||||
this.actor.destroy();
|
||||
|
@ -373,6 +373,20 @@ 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();
|
||||
|
Loading…
Reference in New Issue
Block a user