2010-07-22 20:39:44 -04:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
|
2010-10-20 15:53:23 -04:00
|
|
|
const Clutter = imports.gi.Clutter;
|
2010-07-22 20:39:44 -04:00
|
|
|
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;
|
|
|
|
|
2011-06-21 18:26:57 -04:00
|
|
|
const Main = imports.ui.main;
|
2010-07-22 20:39:44 -04:00
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
2010-11-17 11:43:08 -05:00
|
|
|
const Util = imports.misc.util;
|
2010-07-22 20:39:44 -04:00
|
|
|
|
2010-10-20 15:53:23 -04:00
|
|
|
const VOLUME_ADJUSTMENT_STEP = 0.05; /* Volume adjustment step in % */
|
2010-07-22 20:39:44 -04:00
|
|
|
|
2011-02-15 13:23:36 -05:00
|
|
|
const VOLUME_NOTIFY_ID = 1;
|
|
|
|
|
2010-07-22 20:39:44 -04:00
|
|
|
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' });
|
2011-03-28 10:10:11 -04:00
|
|
|
this._control.connect('state-changed', Lang.bind(this, this._onControlStateChanged));
|
2010-07-22 20:39:44 -04:00
|
|
|
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));
|
2011-03-11 10:45:11 -05:00
|
|
|
this._volumeMax = this._control.get_vol_max_norm();
|
|
|
|
this._volumeMaxAmplified = this._control.get_vol_max_amplified();
|
2010-07-22 20:39:44 -04:00
|
|
|
|
|
|
|
this._output = null;
|
|
|
|
this._outputVolumeId = 0;
|
|
|
|
this._outputMutedId = 0;
|
2010-11-16 09:22:38 -05:00
|
|
|
this._outputTitle = new PopupMenu.PopupMenuItem(_("Volume"), { reactive: false });
|
2011-07-19 19:45:29 -04:00
|
|
|
this._outputSlider = new PopupMenu.PopupSliderMenuItem(0);
|
2010-07-22 20:39:44 -04:00
|
|
|
this._outputSlider.connect('value-changed', Lang.bind(this, this._sliderChanged, '_output'));
|
|
|
|
this._outputSlider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
|
2010-11-16 09:22:38 -05:00
|
|
|
this.menu.addMenuItem(this._outputTitle);
|
2010-07-22 20:39:44 -04:00
|
|
|
this.menu.addMenuItem(this._outputSlider);
|
|
|
|
|
|
|
|
this._separator = new PopupMenu.PopupSeparatorMenuItem();
|
|
|
|
this.menu.addMenuItem(this._separator);
|
|
|
|
|
|
|
|
this._input = null;
|
|
|
|
this._inputVolumeId = 0;
|
|
|
|
this._inputMutedId = 0;
|
2010-11-16 09:22:38 -05:00
|
|
|
this._inputTitle = new PopupMenu.PopupMenuItem(_("Microphone"), { reactive: false });
|
2011-07-19 19:45:29 -04:00
|
|
|
this._inputSlider = new PopupMenu.PopupSliderMenuItem(0);
|
2010-07-22 20:39:44 -04:00
|
|
|
this._inputSlider.connect('value-changed', Lang.bind(this, this._sliderChanged, '_input'));
|
|
|
|
this._inputSlider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
|
2010-11-16 09:22:38 -05:00
|
|
|
this.menu.addMenuItem(this._inputTitle);
|
2010-07-22 20:39:44 -04:00
|
|
|
this.menu.addMenuItem(this._inputSlider);
|
|
|
|
|
|
|
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
2010-11-09 14:38:30 -05:00
|
|
|
this.menu.addAction(_("Sound Settings"), function() {
|
2011-06-21 18:26:57 -04:00
|
|
|
Main.overview.hide();
|
Kill off ShellAppInfo, move into ShellApp
This dramatically thins down and sanitizes the application code.
The ShellAppSystem changes in a number of ways:
* Preferences are special cased more explicitly; they aren't apps,
they're shortcuts for an app), and we don't have many of them, so
don't need e.g. the optimizations in ShellAppSystem for searching.
* get_app() changes to lookup_app() and returns null if an app isn't
found. The semantics where it tried to find the .desktop file
if we didn't know about it were just broken; I am pretty sure no
caller needs this, and if they do we'll fix them.
* ShellAppSystem maintains two indexes on apps (by desktop file id
and by GMenuTreeEntry), but is no longer in the business of
dealing with GMenuTree as far as hierarchy and categories go. That
is moved up into js/ui/appDisplay.js. Actually, it flattens both
apps and settings.
Also, ShellWindowTracker is now the sole reference-owner for
window-backed apps. We still do the weird "window:0x1234beef" id
for these apps, but a reference is not stored in ShellAppSystem.
The js/ui/appDisplay.js code is rewritten, and sucks a lot less.
Variable names are clearer:
_apps -> _appIcons
_filterApp -> _visibleApps
_filters -> _categoryBox
Similarly for function names. We no longer call (for every app) a
recursive lookup in GMenuTree to see if it's in a particular section
on every category switch; it's all cached.
NOTE - this intentionally reverts the incremental loading code from
commit 7813c5b93f6bcde8c4beae286e82bfc472b2b656. It's fast enough
here without that.
https://bugzilla.gnome.org/show_bug.cgi?id=648149
2011-04-21 13:35:01 -04:00
|
|
|
let app = Shell.AppSystem.get_default().lookup_setting('gnome-sound-panel.desktop');
|
2011-08-11 05:35:23 -04:00
|
|
|
app.activate();
|
2010-07-22 20:39:44 -04:00
|
|
|
});
|
|
|
|
|
2010-10-20 15:53:23 -04:00
|
|
|
this.actor.connect('scroll-event', Lang.bind(this, this._onScrollEvent));
|
2010-07-22 20:39:44 -04:00
|
|
|
this._control.open();
|
|
|
|
},
|
|
|
|
|
2011-02-09 15:18:20 -05:00
|
|
|
_getMaxVolume: function(property) {
|
|
|
|
if (this[property].get_can_decibel())
|
2011-03-11 10:45:11 -05:00
|
|
|
return this._volumeMaxAmplified;
|
2011-02-09 15:18:20 -05:00
|
|
|
else
|
2011-03-11 10:45:11 -05:00
|
|
|
return this._volumeMax;
|
2011-02-09 15:18:20 -05:00
|
|
|
},
|
|
|
|
|
2010-10-20 15:53:23 -04:00
|
|
|
_onScrollEvent: function(actor, event) {
|
|
|
|
let direction = event.get_scroll_direction();
|
|
|
|
let currentVolume = this._output.volume;
|
2011-02-09 15:18:20 -05:00
|
|
|
let maxVolume = this._getMaxVolume('_output');
|
2010-10-20 15:53:23 -04:00
|
|
|
|
|
|
|
if (direction == Clutter.ScrollDirection.DOWN) {
|
2010-11-16 09:22:38 -05:00
|
|
|
let prev_muted = this._output.is_muted;
|
2011-02-09 15:18:20 -05:00
|
|
|
this._output.volume = Math.max(0, currentVolume - maxVolume * VOLUME_ADJUSTMENT_STEP);
|
2010-11-16 09:22:38 -05:00
|
|
|
if (this._output.volume < 1) {
|
|
|
|
this._output.volume = 0;
|
|
|
|
if (!prev_muted)
|
|
|
|
this._output.change_is_muted(true);
|
|
|
|
}
|
2010-10-20 15:53:23 -04:00
|
|
|
this._output.push_volume();
|
|
|
|
}
|
|
|
|
else if (direction == Clutter.ScrollDirection.UP) {
|
2011-02-09 15:18:20 -05:00
|
|
|
this._output.volume = Math.min(maxVolume, currentVolume + maxVolume * VOLUME_ADJUSTMENT_STEP);
|
2010-11-16 09:22:38 -05:00
|
|
|
this._output.change_is_muted(false);
|
2010-10-20 15:53:23 -04:00
|
|
|
this._output.push_volume();
|
|
|
|
}
|
2011-02-15 13:23:36 -05:00
|
|
|
|
|
|
|
this._notifyVolumeChange();
|
2010-10-20 15:53:23 -04:00
|
|
|
},
|
|
|
|
|
2011-03-28 10:10:11 -04:00
|
|
|
_onControlStateChanged: function() {
|
|
|
|
if (this._control.get_state() == Gvc.MixerControlState.READY) {
|
|
|
|
this._readOutput();
|
|
|
|
this._readInput();
|
|
|
|
this.actor.show();
|
|
|
|
} else {
|
|
|
|
this.actor.hide();
|
|
|
|
}
|
2010-07-22 20:39:44 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_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');
|
|
|
|
} else {
|
2010-11-16 09:22:38 -05:00
|
|
|
this._outputSlider.setValue(0);
|
2010-07-22 20:39:44 -04:00
|
|
|
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();
|
2010-11-16 09:22:38 -05:00
|
|
|
this._inputTitle.actor.hide();
|
2010-07-22 20:39:44 -04:00
|
|
|
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();
|
2010-10-20 15:15:24 -04:00
|
|
|
if (this._input && recordingApps) {
|
|
|
|
for (let i = 0; i < recordingApps.length; i++) {
|
|
|
|
let outputStream = recordingApps[i];
|
2010-07-22 20:39:44 -04:00
|
|
|
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();
|
2010-11-16 09:22:38 -05:00
|
|
|
this._inputTitle.actor.show();
|
2010-07-22 20:39:44 -04:00
|
|
|
this._inputSlider.actor.show();
|
|
|
|
} else {
|
|
|
|
this._separator.actor.hide();
|
2010-11-16 09:22:38 -05:00
|
|
|
this._inputTitle.actor.hide();
|
2010-07-22 20:39:44 -04:00
|
|
|
this._inputSlider.actor.hide();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_volumeToIcon: function(volume) {
|
2011-02-09 15:18:20 -05:00
|
|
|
let maxVolume = this._getMaxVolume('_output');
|
2010-07-22 20:39:44 -04:00
|
|
|
if (volume <= 0) {
|
|
|
|
return 'audio-volume-muted';
|
|
|
|
} else {
|
2011-02-09 15:18:20 -05:00
|
|
|
let n = Math.floor(3 * volume / maxVolume) + 1;
|
2011-02-05 13:42:50 -05:00
|
|
|
if (n < 2)
|
2010-07-22 20:39:44 -04:00
|
|
|
return 'audio-volume-low';
|
2011-02-05 13:42:50 -05:00
|
|
|
if (n >= 3)
|
2010-07-22 20:39:44 -04:00
|
|
|
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;
|
|
|
|
}
|
2011-02-09 15:18:20 -05:00
|
|
|
let volume = value * this._getMaxVolume(property);
|
2010-11-16 09:22:38 -05:00
|
|
|
let prev_muted = this[property].is_muted;
|
|
|
|
if (volume < 1) {
|
|
|
|
this[property].volume = 0;
|
|
|
|
if (!prev_muted)
|
|
|
|
this[property].change_is_muted(true);
|
|
|
|
} else {
|
|
|
|
this[property].volume = volume;
|
|
|
|
if (prev_muted)
|
|
|
|
this[property].change_is_muted(false);
|
|
|
|
}
|
2010-07-22 20:39:44 -04:00
|
|
|
this[property].push_volume();
|
|
|
|
},
|
|
|
|
|
|
|
|
_notifyVolumeChange: function() {
|
2011-02-15 13:23:36 -05:00
|
|
|
global.cancel_theme_sound(VOLUME_NOTIFY_ID);
|
|
|
|
global.play_theme_sound(VOLUME_NOTIFY_ID, 'audio-volume-change');
|
2010-07-22 20:39:44 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
_mutedChanged: function(object, param_spec, property) {
|
|
|
|
let muted = this[property].is_muted;
|
2010-11-16 09:22:38 -05:00
|
|
|
let slider = this[property+'Slider'];
|
2011-02-09 15:18:20 -05:00
|
|
|
let maxVolume = this._getMaxVolume(property);
|
|
|
|
slider.setValue(muted ? 0 : (this[property].volume / maxVolume));
|
2010-07-22 20:39:44 -04:00
|
|
|
if (property == '_output') {
|
|
|
|
if (muted)
|
|
|
|
this.setIcon('audio-volume-muted');
|
|
|
|
else
|
|
|
|
this.setIcon(this._volumeToIcon(this._output.volume));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_volumeChanged: function(object, param_spec, property) {
|
2011-02-09 15:18:20 -05:00
|
|
|
let maxVolume = this._getMaxVolume(property);
|
|
|
|
this[property+'Slider'].setValue(this[property].volume / maxVolume);
|
2010-10-22 09:31:58 -04:00
|
|
|
if (property == '_output' && !this._output.is_muted)
|
2010-07-22 20:39:44 -04:00
|
|
|
this.setIcon(this._volumeToIcon(this._output.volume));
|
|
|
|
}
|
|
|
|
};
|