Merge branch 'master' into datetime
This commit is contained in:
@ -5,6 +5,10 @@ const Lang = imports.lang;
|
||||
const St = imports.gi.St;
|
||||
const Shell = imports.gi.Shell;
|
||||
|
||||
const Tweener = imports.ui.tweener;
|
||||
|
||||
const POPUP_ANIMATION_TIME = 0.15;
|
||||
|
||||
/**
|
||||
* BoxPointer:
|
||||
* @side: A St.Side type; currently only St.Side.TOP is implemented
|
||||
@ -38,6 +42,80 @@ BoxPointer.prototype = {
|
||||
this.bin.raise(this._border);
|
||||
},
|
||||
|
||||
animateAppear: function(onComplete) {
|
||||
let x = this.actor.x;
|
||||
let y = this.actor.y;
|
||||
let themeNode = this.actor.get_theme_node();
|
||||
let [found, rise] = themeNode.get_length('-arrow-rise', false);
|
||||
if (!found)
|
||||
rise = 0;
|
||||
|
||||
this.actor.opacity = 0;
|
||||
this.actor.show();
|
||||
|
||||
switch (this._arrowSide) {
|
||||
case St.Side.TOP:
|
||||
this.actor.y -= rise;
|
||||
break;
|
||||
case St.Side.BOTTOM:
|
||||
this.actor.y += rise;
|
||||
break;
|
||||
case St.Side.LEFT:
|
||||
this.actor.x -= rise;
|
||||
break;
|
||||
case St.Side.RIGHT:
|
||||
this.actor.x += rise;
|
||||
break;
|
||||
}
|
||||
|
||||
Tweener.addTween(this.actor, { opacity: 255,
|
||||
x: x,
|
||||
y: y,
|
||||
transition: "linear",
|
||||
onComplete: onComplete,
|
||||
time: POPUP_ANIMATION_TIME });
|
||||
},
|
||||
|
||||
animateDisappear: function(onComplete) {
|
||||
let x = this.actor.x;
|
||||
let y = this.actor.y;
|
||||
let originalX = this.actor.x;
|
||||
let originalY = this.actor.y;
|
||||
let themeNode = this.actor.get_theme_node();
|
||||
let [found, rise] = themeNode.get_length('-arrow-rise', false);
|
||||
if (!found)
|
||||
rise = 0;
|
||||
|
||||
switch (this._arrowSide) {
|
||||
case St.Side.TOP:
|
||||
y += rise;
|
||||
break;
|
||||
case St.Side.BOTTOM:
|
||||
y -= rise;
|
||||
break;
|
||||
case St.Side.LEFT:
|
||||
x += rise;
|
||||
break;
|
||||
case St.Side.RIGHT:
|
||||
x -= rise;
|
||||
break;
|
||||
}
|
||||
|
||||
Tweener.addTween(this.actor, { opacity: 0,
|
||||
x: x,
|
||||
y: y,
|
||||
transition: "linear",
|
||||
time: POPUP_ANIMATION_TIME,
|
||||
onComplete: Lang.bind(this, function () {
|
||||
this.actor.hide();
|
||||
this.actor.x = originalX;
|
||||
this.actor.y = originalY;
|
||||
if (onComplete)
|
||||
onComplete();
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
_adjustAllocationForArrow: function(isWidth, alloc) {
|
||||
let themeNode = this.actor.get_theme_node();
|
||||
let found, borderWidth, base, rise;
|
||||
@ -186,6 +264,92 @@ BoxPointer.prototype = {
|
||||
cr.stroke();
|
||||
},
|
||||
|
||||
setPosition: function(sourceActor, gap, alignment) {
|
||||
let primary = global.get_primary_monitor();
|
||||
|
||||
// We need to show it now to force an allocation,
|
||||
// so that we can query the correct size.
|
||||
this.actor.show();
|
||||
|
||||
// Position correctly relative to the sourceActor
|
||||
let [sourceX, sourceY] = sourceActor.get_transformed_position();
|
||||
let [sourceWidth, sourceHeight] = sourceActor.get_transformed_size();
|
||||
|
||||
let [minWidth, minHeight, natWidth, natHeight] = this.actor.get_preferred_size();
|
||||
|
||||
let resX, resY;
|
||||
|
||||
switch (this._arrowSide) {
|
||||
case St.Side.TOP:
|
||||
resY = sourceY + sourceHeight + gap;
|
||||
break;
|
||||
case St.Side.BOTTOM:
|
||||
resY = sourceY - natHeight - gap;
|
||||
break;
|
||||
case St.Side.LEFT:
|
||||
resX = sourceX + sourceWidth + gap;
|
||||
break;
|
||||
case St.Side.RIGHT:
|
||||
resX = sourceX - natWidth - gap;
|
||||
break;
|
||||
}
|
||||
|
||||
// Now align and position the pointing axis, making sure
|
||||
// it fits on screen
|
||||
switch (this._arrowSide) {
|
||||
case St.Side.TOP:
|
||||
case St.Side.BOTTOM:
|
||||
switch (alignment) {
|
||||
case St.Align.START:
|
||||
resX = sourceX;
|
||||
break;
|
||||
case St.Align.MIDDLE:
|
||||
resX = sourceX - Math.floor((natWidth - sourceWidth) / 2);
|
||||
break;
|
||||
case St.Align.END:
|
||||
resX = sourceX - (natWidth - sourceWidth);
|
||||
break;
|
||||
}
|
||||
|
||||
resX = Math.min(resX, primary.x + primary.width - natWidth);
|
||||
resX = Math.max(resX, primary.x);
|
||||
|
||||
this.setArrowOrigin((sourceX - resX) + Math.floor(sourceWidth / 2));
|
||||
break;
|
||||
|
||||
case St.Side.LEFT:
|
||||
case St.Side.RIGHT:
|
||||
switch (alignment) {
|
||||
case St.Align.START:
|
||||
resY = sourceY;
|
||||
break;
|
||||
case St.Align.MIDDLE:
|
||||
resY = sourceY - Math.floor((natHeight - sourceHeight) / 2);
|
||||
break;
|
||||
case St.Align.END:
|
||||
resY = sourceY - (natHeight - sourceHeight);
|
||||
break;
|
||||
}
|
||||
|
||||
resY = Math.min(resY, primary.y + primary.height - natHeight);
|
||||
resY = Math.max(resY, primary.y);
|
||||
|
||||
this.setArrowOrigin((sourceY - resY) + Math.floor(sourceHeight / 2));
|
||||
break;
|
||||
}
|
||||
|
||||
let parent = this.actor.get_parent();
|
||||
let success, x, y;
|
||||
while (!success) {
|
||||
[success, x, y] = parent.transform_stage_point(resX, resY);
|
||||
parent = parent.get_parent();
|
||||
}
|
||||
|
||||
// Actually set the position
|
||||
this.actor.x = Math.floor(x);
|
||||
this.actor.y = Math.floor(y);
|
||||
},
|
||||
|
||||
// @origin: Coordinate specifying middle of the arrow, along
|
||||
// the Y axis for St.Side.LEFT, St.Side.RIGHT from the top and X axis from
|
||||
// the left for St.Side.TOP and St.Side.BOTTOM.
|
||||
|
@ -51,6 +51,12 @@ function loadExtension(dir, enabled, type) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (extensions[meta.uuid] != undefined) {
|
||||
global.logError(baseErrorString + "extension already loaded");
|
||||
return;
|
||||
}
|
||||
|
||||
// Encourage people to add this
|
||||
if (!meta['url']) {
|
||||
global.log(baseErrorString + 'Warning: Missing "url" property in metadata.json');
|
||||
|
@ -135,9 +135,12 @@ function IconGrid(params) {
|
||||
|
||||
IconGrid.prototype = {
|
||||
_init: function(params) {
|
||||
params = Params.parse(params, { rowLimit: null, columnLimit: null });
|
||||
params = Params.parse(params, { rowLimit: null,
|
||||
columnLimit: null,
|
||||
xAlign: St.Align.MIDDLE });
|
||||
this._rowLimit = params.rowLimit;
|
||||
this._colLimit = params.columnLimit;
|
||||
this._xAlign = params.xAlign;
|
||||
|
||||
this.actor = new St.BoxLayout({ style_class: 'icon-grid',
|
||||
vertical: true });
|
||||
@ -189,9 +192,19 @@ IconGrid.prototype = {
|
||||
|
||||
let [nColumns, usedWidth] = this._computeLayout(availWidth);
|
||||
|
||||
let overallPaddingX = Math.floor((availWidth - usedWidth) / 2);
|
||||
let leftPadding;
|
||||
switch(this._xAlign) {
|
||||
case St.Align.START:
|
||||
leftPadding = 0;
|
||||
break;
|
||||
case St.Align.MIDDLE:
|
||||
leftPadding = Math.floor((availWidth - usedWidth) / 2);
|
||||
break;
|
||||
case St.Align.END:
|
||||
leftPadding = availWidth - usedWidth;
|
||||
}
|
||||
|
||||
let x = box.x1 + overallPaddingX;
|
||||
let x = box.x1 + leftPadding;
|
||||
let y = box.y1;
|
||||
let columnIndex = 0;
|
||||
let rowIndex = 0;
|
||||
@ -231,7 +244,7 @@ IconGrid.prototype = {
|
||||
|
||||
if (columnIndex == 0) {
|
||||
y += this._item_size + this._spacing;
|
||||
x = box.x1 + overallPaddingX;
|
||||
x = box.x1 + leftPadding;
|
||||
} else {
|
||||
x += this._item_size + this._spacing;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ const St = imports.gi.St;
|
||||
const Tweener = imports.ui.tweener;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const BoxPointer = imports.ui.boxpointer;
|
||||
const Params = imports.misc.params;
|
||||
|
||||
const ANIMATION_TIME = 0.2;
|
||||
@ -778,15 +779,19 @@ MessageTray.prototype = {
|
||||
this._summaryBin.child = this._summary;
|
||||
this._summaryBin.opacity = 0;
|
||||
|
||||
this._summaryNotificationBin = new St.Bin({ name: 'summary-notification-bin',
|
||||
anchor_gravity: Clutter.Gravity.NORTH_EAST,
|
||||
reactive: true,
|
||||
track_hover: true });
|
||||
this.actor.add_actor(this._summaryNotificationBin);
|
||||
this._summaryNotificationBin.lower_bottom();
|
||||
this._summaryNotificationBin.hide();
|
||||
this._summaryMotionId = 0;
|
||||
|
||||
this._summaryNotificationBoxPointer = new BoxPointer.BoxPointer(St.Side.BOTTOM,
|
||||
{ reactive: true,
|
||||
track_hover: true });
|
||||
this._summaryNotificationBoxPointer.actor.style_class = 'summary-notification-boxpointer';
|
||||
this.actor.add_actor(this._summaryNotificationBoxPointer.actor);
|
||||
this._summaryNotificationBoxPointer.actor.lower_bottom();
|
||||
this._summaryNotificationBoxPointer.actor.hide();
|
||||
|
||||
this._summaryNotification = null;
|
||||
this._clickedSummaryItem = null;
|
||||
this._clickedSummaryItemAllocationChangedId = 0;
|
||||
this._expandedSummaryItem = null;
|
||||
this._summaryItemTitleWidth = 0;
|
||||
|
||||
@ -817,7 +822,7 @@ MessageTray.prototype = {
|
||||
Main.chrome.addActor(this.actor, { affectsStruts: false,
|
||||
visibleInOverview: true });
|
||||
Main.chrome.trackActor(this._notificationBin);
|
||||
Main.chrome.trackActor(this._summaryNotificationBin);
|
||||
Main.chrome.trackActor(this._summaryNotificationBoxPointer.actor);
|
||||
|
||||
global.gdk_screen.connect('monitors-changed', Lang.bind(this, this._setSizePosition));
|
||||
|
||||
@ -859,7 +864,6 @@ MessageTray.prototype = {
|
||||
|
||||
// These work because of their anchor_gravity
|
||||
this._summaryBin.x = primary.width;
|
||||
this._summaryNotificationBin.x = primary.width;
|
||||
},
|
||||
|
||||
contains: function(source) {
|
||||
@ -964,7 +968,7 @@ MessageTray.prototype = {
|
||||
needUpdate = true;
|
||||
}
|
||||
if (this._clickedSummaryItem && this._clickedSummaryItem.source == source) {
|
||||
this._clickedSummaryItem = null;
|
||||
this._unsetClickedSummaryItem();
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
@ -993,7 +997,7 @@ MessageTray.prototype = {
|
||||
if (!this._locked)
|
||||
return;
|
||||
this._locked = false;
|
||||
this._clickedSummaryItem = null;
|
||||
this._unsetClickedSummaryItem();
|
||||
this._updateState();
|
||||
},
|
||||
|
||||
@ -1116,7 +1120,7 @@ MessageTray.prototype = {
|
||||
if (!this._clickedSummaryItem || this._clickedSummaryItem != summaryItem)
|
||||
this._clickedSummaryItem = summaryItem;
|
||||
else
|
||||
this._clickedSummaryItem = null;
|
||||
this._unsetClickedSummaryItem();
|
||||
|
||||
this._updateState();
|
||||
},
|
||||
@ -1478,25 +1482,51 @@ MessageTray.prototype = {
|
||||
if (index != -1)
|
||||
this._notificationQueue.splice(index, 1);
|
||||
|
||||
this._summaryNotificationBin.child = this._summaryNotification.actor;
|
||||
this._summaryNotificationBoxPointer.bin.child = this._summaryNotification.actor;
|
||||
this._summaryNotification.grabFocus(true);
|
||||
|
||||
this._summaryNotificationBin.opacity = 0;
|
||||
this._summaryNotificationBin.y = this.actor.height;
|
||||
this._summaryNotificationBin.show();
|
||||
|
||||
if (!this._summaryNotificationExpandedId)
|
||||
this._summaryNotificationExpandedId = this._summaryNotification.connect('expanded', Lang.bind(this, this._onSummaryNotificationExpanded));
|
||||
this._summaryNotification.expand(false);
|
||||
|
||||
this._clickedSummaryItemAllocationChangedId =
|
||||
this._clickedSummaryItem.actor.connect('allocation-changed',
|
||||
Lang.bind(this, this._adjustNotificationBoxPointerPosition));
|
||||
// _clickedSummaryItem.actor can change absolute postiion without changing allocation
|
||||
this._summaryMotionId = this._summary.connect('allocation-changed',
|
||||
Lang.bind(this, this._adjustNotificationBoxPointerPosition));
|
||||
|
||||
this._summaryNotificationBoxPointer.actor.opacity = 0;
|
||||
this._summaryNotificationBoxPointer.actor.show();
|
||||
this._adjustNotificationBoxPointerPosition();
|
||||
|
||||
this._summaryNotificationState = State.SHOWNING;
|
||||
this._summaryNotificationBoxPointer.animateAppear(Lang.bind(this, function() {
|
||||
this._summaryNotificationState = State.SHOWN;
|
||||
}));
|
||||
},
|
||||
|
||||
_adjustNotificationBoxPointerPosition: function() {
|
||||
// The position of the arrow origin should be the same as center of this._clickedSummaryItem.actor
|
||||
if (!this._clickedSummaryItem)
|
||||
return;
|
||||
|
||||
this._summaryNotificationBoxPointer.setPosition(this._clickedSummaryItem.actor, 0, St.Align.MIDDLE);
|
||||
},
|
||||
|
||||
_unsetClickedSummaryItem: function() {
|
||||
if (this._clickedSummaryItemAllocationChangedId) {
|
||||
this._clickedSummaryItem.actor.disconnect(this._clickedSummaryItemAllocationChangedId);
|
||||
this._summary.disconnect(this._summaryMotionId);
|
||||
this._clickedSummaryItemAllocationChangedId = 0;
|
||||
this._summaryMotionId = 0;
|
||||
}
|
||||
|
||||
this._clickedSummaryItem = null;
|
||||
},
|
||||
|
||||
_onSummaryNotificationExpanded: function() {
|
||||
this._tween(this._summaryNotificationBin, '_summaryNotificationState', State.SHOWN,
|
||||
{ y: this.actor.height - this._summaryNotificationBin.height,
|
||||
opacity: 255,
|
||||
time: ANIMATION_TIME,
|
||||
transition: 'easeOutQuad'
|
||||
});
|
||||
this._adjustNotificationBoxPointerPosition();
|
||||
},
|
||||
|
||||
_hideSummaryNotification: function() {
|
||||
@ -1504,25 +1534,18 @@ MessageTray.prototype = {
|
||||
this._summaryNotification.disconnect(this._summaryNotificationExpandedId);
|
||||
this._summaryNotificationExpandedId = 0;
|
||||
}
|
||||
|
||||
// Unset this._clickedSummaryItem if we are no longer showing the summary
|
||||
if (this._summaryState != State.SHOWN)
|
||||
this._clickedSummaryItem = null;
|
||||
this._summaryNotification.ungrabFocus();
|
||||
this._unsetClickedSummaryItem();
|
||||
|
||||
this._tween(this._summaryNotificationBin, '_summaryNotificationState', State.HIDDEN,
|
||||
{ y: this.actor.height,
|
||||
opacity: 0,
|
||||
time: ANIMATION_TIME,
|
||||
transition: 'easeOutQuad',
|
||||
onComplete: this._hideSummaryNotificationCompleted,
|
||||
onCompleteScope: this
|
||||
});
|
||||
this._summaryNotification.ungrabFocus();
|
||||
this._summaryNotificationState = State.HIDING;
|
||||
this._summaryNotificationBoxPointer.animateDisappear(Lang.bind(this, this._hideSummaryNotificationCompleted));
|
||||
},
|
||||
|
||||
_hideSummaryNotificationCompleted: function() {
|
||||
this._summaryNotificationBin.hide();
|
||||
this._summaryNotificationBin.child = null;
|
||||
this._summaryNotificationState = State.HIDDEN;
|
||||
this._summaryNotificationBoxPointer.bin.child = null;
|
||||
this._summaryNotification.collapseCompleted();
|
||||
let summaryNotification = this._summaryNotification;
|
||||
this._summaryNotification = null;
|
||||
|
@ -32,7 +32,8 @@ const SPINNER_SPEED = 0.02;
|
||||
|
||||
const STANDARD_TRAY_ICON_ORDER = ['a11y', 'display', 'keyboard', 'volume', 'bluetooth', 'network', 'battery'];
|
||||
const STANDARD_TRAY_ICON_SHELL_IMPLEMENTATION = {
|
||||
'a11y': imports.ui.status.accessibility.ATIndicator
|
||||
'a11y': imports.ui.status.accessibility.ATIndicator,
|
||||
'volume': imports.ui.status.volume.Indicator,
|
||||
};
|
||||
|
||||
function AnimatedIcon(name, size) {
|
||||
|
@ -16,8 +16,6 @@ const Tweener = imports.ui.tweener;
|
||||
const Gettext = imports.gettext.domain('gnome-shell');
|
||||
const _ = Gettext.gettext;
|
||||
|
||||
const POPUP_ANIMATION_TIME = 0.1;
|
||||
|
||||
function Switch() {
|
||||
this._init.apply(this, arguments);
|
||||
}
|
||||
@ -178,7 +176,7 @@ PopupSliderMenuItem.prototype = {
|
||||
if (isNaN(value))
|
||||
// Avoid spreading NaNs around
|
||||
throw TypeError('The slider value must be a number');
|
||||
this._displayValue = this._value = Math.max(Math.min(value, 1), 0);
|
||||
this._value = Math.max(Math.min(value, 1), 0);
|
||||
|
||||
this._slider = new St.DrawingArea({ style_class: 'popup-slider-menu-item', reactive: true });
|
||||
this.actor.set_child(this._slider);
|
||||
@ -193,7 +191,7 @@ PopupSliderMenuItem.prototype = {
|
||||
if (isNaN(value))
|
||||
throw TypeError('The slider value must be a number');
|
||||
|
||||
this._displayValue = this._value = Math.max(Math.min(value, 1), 0);
|
||||
this._value = Math.max(Math.min(value, 1), 0);
|
||||
this._slider.queue_repaint();
|
||||
},
|
||||
|
||||
@ -233,7 +231,7 @@ PopupSliderMenuItem.prototype = {
|
||||
cr.stroke();
|
||||
|
||||
let handleY = height / 2;
|
||||
let handleX = handleRadius + (width - 2 * handleRadius) * this._displayValue;
|
||||
let handleX = handleRadius + (width - 2 * handleRadius) * this._value;
|
||||
|
||||
let color = new Clutter.Color();
|
||||
themeNode.get_foreground_color(color);
|
||||
@ -271,8 +269,7 @@ PopupSliderMenuItem.prototype = {
|
||||
Clutter.ungrab_pointer();
|
||||
this._dragging = false;
|
||||
|
||||
this._value = this._displayValue;
|
||||
this.emit('value-changed', this._value);
|
||||
this.emit('drag-end');
|
||||
}
|
||||
return true;
|
||||
},
|
||||
@ -301,8 +298,9 @@ PopupSliderMenuItem.prototype = {
|
||||
newvalue = 1;
|
||||
else
|
||||
newvalue = (relX - handleRadius) / (width - 2 * handleRadius);
|
||||
this._displayValue = newvalue;
|
||||
this._value = newvalue;
|
||||
this._slider.queue_repaint();
|
||||
this.emit('value-changed', this._value);
|
||||
},
|
||||
|
||||
get value() {
|
||||
@ -313,9 +311,10 @@ PopupSliderMenuItem.prototype = {
|
||||
let key = event.get_key_symbol();
|
||||
if (key == Clutter.Right || key == Clutter.Left) {
|
||||
let delta = key == Clutter.Right ? 0.1 : -0.1;
|
||||
this._value = this._displayValue = Math.max(0, Math.min(this._value + delta, 1));
|
||||
this._value = Math.max(0, Math.min(this._value + delta, 1));
|
||||
this._slider.queue_repaint();
|
||||
this.emit('value-changed', this._value);
|
||||
this.emit('drag-end');
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -552,7 +551,6 @@ PopupMenu.prototype = {
|
||||
|
||||
let [minWidth, minHeight, natWidth, natHeight] = this.actor.get_preferred_size();
|
||||
|
||||
let menuX, menuY;
|
||||
let menuWidth = natWidth, menuHeight = natHeight;
|
||||
|
||||
// Position the non-pointing axis
|
||||
@ -575,75 +573,12 @@ PopupMenu.prototype = {
|
||||
this._boxPointer._arrowSide = this._arrowSide = St.Side.LEFT;
|
||||
}
|
||||
}
|
||||
switch (this._arrowSide) {
|
||||
case St.Side.TOP:
|
||||
menuY = sourceY + sourceHeight + this._gap;
|
||||
break;
|
||||
case St.Side.BOTTOM:
|
||||
menuY = sourceY - menuHeight - this._gap;
|
||||
break;
|
||||
case St.Side.LEFT:
|
||||
menuX = sourceX + sourceWidth + this._gap;
|
||||
break;
|
||||
case St.Side.RIGHT:
|
||||
menuX = sourceX - menuWidth - this._gap;
|
||||
break;
|
||||
}
|
||||
|
||||
// Now align and position the pointing axis, making sure
|
||||
// it fits on screen
|
||||
switch (this._arrowSide) {
|
||||
case St.Side.TOP:
|
||||
case St.Side.BOTTOM:
|
||||
switch (this._alignment) {
|
||||
case St.Align.START:
|
||||
menuX = sourceX;
|
||||
break;
|
||||
case St.Align.MIDDLE:
|
||||
menuX = sourceX - Math.floor((menuWidth - sourceWidth) / 2);
|
||||
break;
|
||||
case St.Align.END:
|
||||
menuX = sourceX - (menuWidth - sourceWidth);
|
||||
break;
|
||||
}
|
||||
|
||||
menuX = Math.min(menuX, primary.x + primary.width - menuWidth);
|
||||
menuX = Math.max(menuX, primary.x);
|
||||
|
||||
this._boxPointer.setArrowOrigin((sourceX - menuX) + Math.floor(sourceWidth / 2));
|
||||
break;
|
||||
|
||||
case St.Side.LEFT:
|
||||
case St.Side.RIGHT:
|
||||
switch (this._alignment) {
|
||||
case St.Align.START:
|
||||
menuY = sourceY;
|
||||
break;
|
||||
case St.Align.MIDDLE:
|
||||
menuY = sourceY - Math.floor((menuHeight - sourceHeight) / 2);
|
||||
break;
|
||||
case St.Align.END:
|
||||
menuY = sourceY - (menuHeight - sourceHeight);
|
||||
break;
|
||||
}
|
||||
|
||||
menuY = Math.min(menuY, primary.y + primary.height - menuHeight);
|
||||
menuY = Math.max(menuY, primary.y);
|
||||
|
||||
this._boxPointer.setArrowOrigin((sourceY - menuY) + Math.floor(sourceHeight / 2));
|
||||
break;
|
||||
}
|
||||
|
||||
// Actually set the position
|
||||
this.actor.x = Math.floor(menuX);
|
||||
this.actor.y = Math.floor(menuY);
|
||||
this._boxPointer.setPosition(this.sourceActor, this._gap, this._alignment);
|
||||
|
||||
// Now show it
|
||||
this.actor.opacity = 0;
|
||||
this.actor.reactive = true;
|
||||
Tweener.addTween(this.actor, { opacity: 255,
|
||||
transition: "easeOutQuad",
|
||||
time: POPUP_ANIMATION_TIME });
|
||||
this._boxPointer.animateAppear();
|
||||
this.isOpen = true;
|
||||
this.emit('open-state-changed', true);
|
||||
},
|
||||
@ -657,11 +592,7 @@ PopupMenu.prototype = {
|
||||
if (this._activeMenuItem)
|
||||
this._activeMenuItem.setActive(false);
|
||||
this.actor.reactive = false;
|
||||
Tweener.addTween(this.actor, { opacity: 0,
|
||||
transition: "easeOutQuad",
|
||||
time: POPUP_ANIMATION_TIME,
|
||||
onComplete: Lang.bind(this, function () { this.actor.hide(); })});
|
||||
|
||||
this._boxPointer.animateDisappear();
|
||||
this.isOpen = false;
|
||||
this.emit('open-state-changed', false);
|
||||
},
|
||||
|
206
js/ui/status/volume.js
Normal file
206
js/ui/status/volume.js
Normal file
@ -0,0 +1,206 @@
|
||||
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
|
||||
const DBus = imports.dbus;
|
||||
const Lang = imports.lang;
|
||||
const Mainloop = imports.mainloop;
|
||||
const Shell = imports.gi.Shell;
|
||||
const Gvc = imports.gi.Gvc;
|
||||
const Signals = imports.signals;
|
||||
const St = imports.gi.St;
|
||||
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
const PopupMenu = imports.ui.popupMenu;
|
||||
|
||||
const Gettext = imports.gettext.domain('gnome-shell');
|
||||
const _ = Gettext.gettext;
|
||||
|
||||
const VOLUME_MAX = 65536.0; /* PA_VOLUME_NORM */
|
||||
|
||||
function Indicator() {
|
||||
this._init.apply(this, arguments);
|
||||
}
|
||||
|
||||
Indicator.prototype = {
|
||||
__proto__: PanelMenu.SystemStatusButton.prototype,
|
||||
|
||||
_init: function() {
|
||||
PanelMenu.SystemStatusButton.prototype._init.call(this, 'audio-volume-muted', null);
|
||||
|
||||
this._control = new Gvc.MixerControl({ name: 'GNOME Shell Volume Control' });
|
||||
this._control.connect('ready', Lang.bind(this, this._onControlReady));
|
||||
this._control.connect('default-sink-changed', Lang.bind(this, this._readOutput));
|
||||
this._control.connect('default-source-changed', Lang.bind(this, this._readInput));
|
||||
this._control.connect('stream-added', Lang.bind(this, this._maybeShowInput));
|
||||
this._control.connect('stream-removed', Lang.bind(this, this._maybeShowInput));
|
||||
|
||||
this._output = null;
|
||||
this._outputVolumeId = 0;
|
||||
this._outputMutedId = 0;
|
||||
this._outputSwitch = new PopupMenu.PopupSwitchMenuItem(_("Output: Muted"), false);
|
||||
this._outputSwitch.connect('toggled', Lang.bind(this, this._switchToggled, '_output'));
|
||||
this._outputSlider = new PopupMenu.PopupSliderMenuItem(0);
|
||||
this._outputSlider.connect('value-changed', Lang.bind(this, this._sliderChanged, '_output'));
|
||||
this._outputSlider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
|
||||
this.menu.addMenuItem(this._outputSwitch);
|
||||
this.menu.addMenuItem(this._outputSlider);
|
||||
|
||||
this._separator = new PopupMenu.PopupSeparatorMenuItem();
|
||||
this.menu.addMenuItem(this._separator);
|
||||
|
||||
this._input = null;
|
||||
this._inputVolumeId = 0;
|
||||
this._inputMutedId = 0;
|
||||
this._inputSwitch = new PopupMenu.PopupSwitchMenuItem(_("Input: Muted"), false);
|
||||
this._inputSwitch.connect('toggled', Lang.bind(this, this._switchToggled, '_input'));
|
||||
this._inputSlider = new PopupMenu.PopupSliderMenuItem(0);
|
||||
this._inputSlider.connect('value-changed', Lang.bind(this, this._sliderChanged, '_input'));
|
||||
this._inputSlider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
|
||||
this.menu.addMenuItem(this._inputSwitch);
|
||||
this.menu.addMenuItem(this._inputSlider);
|
||||
|
||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||
this.menu.addAction(_("Sound Preferences"), function() {
|
||||
let p = new Shell.Process({ args: ['gnome-control-center', 'volume'] });
|
||||
p.run();
|
||||
});
|
||||
|
||||
this._control.open();
|
||||
},
|
||||
|
||||
_onControlReady: function() {
|
||||
this._readOutput();
|
||||
this._readInput();
|
||||
},
|
||||
|
||||
_readOutput: function() {
|
||||
if (this._outputVolumeId) {
|
||||
this._output.disconnect(this._outputVolumeId);
|
||||
this._output.disconnect(this._outputMutedId);
|
||||
this._outputVolumeId = 0;
|
||||
this._outputMutedId = 0;
|
||||
}
|
||||
this._output = this._control.get_default_sink();
|
||||
if (this._output) {
|
||||
this._outputMutedId = this._output.connect('notify::is-muted', Lang.bind(this, this._mutedChanged, '_output'));
|
||||
this._outputVolumeId = this._output.connect('notify::volume', Lang.bind(this, this._volumeChanged, '_output'));
|
||||
this._mutedChanged (null, null, '_output');
|
||||
this._volumeChanged (null, null, '_output');
|
||||
this.setIcon(this._volumeToIcon(this._output.volume));
|
||||
} else {
|
||||
this._outputSwitch.label.text = _("Output: Muted");
|
||||
this._outputSwitch.setToggleState(false);
|
||||
this.setIcon('audio-volume-muted-symbolic');
|
||||
}
|
||||
},
|
||||
|
||||
_readInput: function() {
|
||||
if (this._inputVolumeId) {
|
||||
this._input.disconnect(this._inputVolumeId);
|
||||
this._input.disconnect(this._inputMutedId);
|
||||
this._inputVolumeId = 0;
|
||||
this._inputMutedId = 0;
|
||||
}
|
||||
this._input = this._control.get_default_source();
|
||||
if (this._input) {
|
||||
this._inputMutedId = this._input.connect('notify::is-muted', Lang.bind(this, this._mutedChanged, '_input'));
|
||||
this._inputVolumeId = this._input.connect('notify::volume', Lang.bind(this, this._volumeChanged, '_input'));
|
||||
this._mutedChanged (null, null, '_input');
|
||||
this._volumeChanged (null, null, '_input');
|
||||
} else {
|
||||
this._separator.actor.hide();
|
||||
this._inputSwitch.actor.hide();
|
||||
this._inputSlider.actor.hide();
|
||||
}
|
||||
},
|
||||
|
||||
_maybeShowInput: function() {
|
||||
// only show input widgets if any application is recording audio
|
||||
let showInput = false;
|
||||
let recordingApps = this._control.get_source_outputs();
|
||||
if (this._source && recordingApps) {
|
||||
for (let i = 0; i < recordingApp.length; i++) {
|
||||
let outputStream = recordingApp[i];
|
||||
let id = outputStream.get_application_id();
|
||||
// but skip gnome-volume-control and pavucontrol
|
||||
// (that appear as recording because they show the input level)
|
||||
if (!id || (id != 'org.gnome.VolumeControl' && id != 'org.PulseAudio.pavucontrol')) {
|
||||
showInput = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (showInput) {
|
||||
this._separator.actor.show();
|
||||
this._inputSwitch.actor.show();
|
||||
this._inputSlider.actor.show();
|
||||
} else {
|
||||
this._separator.actor.hide();
|
||||
this._inputSwitch.actor.hide();
|
||||
this._inputSlider.actor.hide();
|
||||
}
|
||||
},
|
||||
|
||||
_volumeToIcon: function(volume) {
|
||||
if (volume <= 0) {
|
||||
return 'audio-volume-muted';
|
||||
} else {
|
||||
let v = volume / VOLUME_MAX;
|
||||
if (v < 0.33)
|
||||
return 'audio-volume-low';
|
||||
if (v > 0.8)
|
||||
return 'audio-volume-high';
|
||||
return 'audio-volume-medium';
|
||||
}
|
||||
},
|
||||
|
||||
_sliderChanged: function(slider, value, property) {
|
||||
if (this[property] == null) {
|
||||
log ('Volume slider changed for %s, but %s does not exist'.format(property, property));
|
||||
return;
|
||||
}
|
||||
this[property].volume = value * VOLUME_MAX;
|
||||
this[property].push_volume();
|
||||
},
|
||||
|
||||
_notifyVolumeChange: function() {
|
||||
global.play_theme_sound('audio-volume-change');
|
||||
},
|
||||
|
||||
_switchToggled: function(switchItem, state, property) {
|
||||
if (this[property] == null) {
|
||||
log ('Volume mute switch toggled for %s, but %s does not exist'.format(property, property));
|
||||
return;
|
||||
}
|
||||
this[property].change_is_muted(!state);
|
||||
this._notifyVolumeChange();
|
||||
},
|
||||
|
||||
_mutedChanged: function(object, param_spec, property) {
|
||||
let muted = this[property].is_muted;
|
||||
let toggleSwitch = this[property+'Switch'];
|
||||
toggleSwitch.setToggleState(!muted);
|
||||
this._updateLabel(property);
|
||||
if (property == '_output') {
|
||||
if (muted)
|
||||
this.setIcon('audio-volume-muted');
|
||||
else
|
||||
this.setIcon(this._volumeToIcon(this._output.volume));
|
||||
}
|
||||
},
|
||||
|
||||
_volumeChanged: function(object, param_spec, property) {
|
||||
this[property+'Slider'].setValue(this[property].volume / VOLUME_MAX);
|
||||
this._updateLabel(property);
|
||||
if (property == '_output')
|
||||
this.setIcon(this._volumeToIcon(this._output.volume));
|
||||
},
|
||||
|
||||
_updateLabel: function(property) {
|
||||
let label;
|
||||
if (this[property].is_muted)
|
||||
label = (property == '_output' ? _("Output: Muted") : _("Input: Muted"));
|
||||
else
|
||||
label = (property == '_output' ? _("Output: %3.0f%%") : _("Input: %3.0f%%")).format(this[property].volume / VOLUME_MAX * 100);
|
||||
this[property+'Switch'].label.text = label;
|
||||
}
|
||||
};
|
@ -31,6 +31,8 @@ StatusMenuButton.prototype = {
|
||||
this.actor.set_child(box);
|
||||
|
||||
this._gdm = Gdm.UserManager.ref_default();
|
||||
this._gdm.queue_load()
|
||||
|
||||
this._user = this._gdm.get_user(GLib.get_user_name());
|
||||
this._presence = new GnomeSession.Presence();
|
||||
|
||||
@ -48,27 +50,31 @@ StatusMenuButton.prototype = {
|
||||
this._presence.connect('StatusChanged', Lang.bind(this, this._updatePresenceIcon));
|
||||
this._presence.getStatus(Lang.bind(this, this._updatePresenceIcon));
|
||||
|
||||
this._name = new St.Label({ text: this._user.get_real_name() });
|
||||
this._name = new St.Label();
|
||||
box.add(this._name, { y_align: St.Align.MIDDLE, y_fill: false });
|
||||
this._userNameChangedId = this._user.connect('notify::display-name', Lang.bind(this, this._updateUserName));
|
||||
this._userLoadedId = this._user.connect('notify::is-loaded', Lang.bind(this, this._updateUserName));
|
||||
this._userChangedId = this._user.connect('changed', Lang.bind(this, this._updateUserName));
|
||||
|
||||
this._createSubMenu();
|
||||
this._gdm.connect('users-loaded', Lang.bind(this, this._updateSwitchUser));
|
||||
this._gdm.connect('notify::is-loaded', Lang.bind(this, this._updateSwitchUser));
|
||||
this._gdm.connect('user-added', Lang.bind(this, this._updateSwitchUser));
|
||||
this._gdm.connect('user-removed', Lang.bind(this, this._updateSwitchUser));
|
||||
},
|
||||
|
||||
_onDestroy: function() {
|
||||
this._user.disconnect(this._userNameChangedId);
|
||||
this._user.disconnect(this._userLoadedId);
|
||||
this._user.disconnect(this._userChangedId);
|
||||
},
|
||||
|
||||
_updateUserName: function() {
|
||||
this._name.set_text(this._user.get_real_name());
|
||||
if (this._user.is_loaded)
|
||||
this._name.set_text(this._user.get_real_name());
|
||||
else
|
||||
this._name.set_text("");
|
||||
},
|
||||
|
||||
_updateSwitchUser: function() {
|
||||
let users = this._gdm.list_users();
|
||||
if (users.length > 1)
|
||||
if (this._gdm.can_switch ())
|
||||
this._loginScreenItem.actor.show();
|
||||
else
|
||||
this._loginScreenItem.actor.hide();
|
||||
|
Reference in New Issue
Block a user