Sound Menu: only show the slider

Reimplement UI without any indication of percentage or mutedness,
and whitout switches. The only interaction point is slider, but
it still supports mute changing for applications that track it,
and will react appropriately to external changes.

https://bugzilla.gnome.org/show_bug.cgi?id=634329
This commit is contained in:
Giovanni Campagna 2010-11-16 15:22:38 +01:00
parent de50cf80a8
commit d5bfc503fe
2 changed files with 32 additions and 38 deletions

View File

@ -296,15 +296,15 @@ PopupBaseMenuItem.prototype = {
}; };
Signals.addSignalMethods(PopupBaseMenuItem.prototype); Signals.addSignalMethods(PopupBaseMenuItem.prototype);
function PopupMenuItem(text) { function PopupMenuItem() {
this._init(text); this._init.apply(this, arguments);
} }
PopupMenuItem.prototype = { PopupMenuItem.prototype = {
__proto__: PopupBaseMenuItem.prototype, __proto__: PopupBaseMenuItem.prototype,
_init: function (text) { _init: function (text, params) {
PopupBaseMenuItem.prototype._init.call(this); PopupBaseMenuItem.prototype._init.call(this, params);
this.label = new St.Label({ text: text }); this.label = new St.Label({ text: text });
this.addActor(this.label); this.addActor(this.label);

View File

@ -38,12 +38,11 @@ Indicator.prototype = {
this._output = null; this._output = null;
this._outputVolumeId = 0; this._outputVolumeId = 0;
this._outputMutedId = 0; this._outputMutedId = 0;
this._outputSwitch = new PopupMenu.PopupSwitchMenuItem(_("Volume: Muted"), false); this._outputTitle = new PopupMenu.PopupMenuItem(_("Volume"), { reactive: false });
this._outputSwitch.connect('toggled', Lang.bind(this, this._switchToggled, '_output'));
this._outputSlider = new PopupMenu.PopupSliderMenuItem(0); this._outputSlider = new PopupMenu.PopupSliderMenuItem(0);
this._outputSlider.connect('value-changed', Lang.bind(this, this._sliderChanged, '_output')); this._outputSlider.connect('value-changed', Lang.bind(this, this._sliderChanged, '_output'));
this._outputSlider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange)); this._outputSlider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
this.menu.addMenuItem(this._outputSwitch); this.menu.addMenuItem(this._outputTitle);
this.menu.addMenuItem(this._outputSlider); this.menu.addMenuItem(this._outputSlider);
this._separator = new PopupMenu.PopupSeparatorMenuItem(); this._separator = new PopupMenu.PopupSeparatorMenuItem();
@ -52,12 +51,11 @@ Indicator.prototype = {
this._input = null; this._input = null;
this._inputVolumeId = 0; this._inputVolumeId = 0;
this._inputMutedId = 0; this._inputMutedId = 0;
this._inputSwitch = new PopupMenu.PopupSwitchMenuItem(_("Microphone: Muted"), false); this._inputTitle = new PopupMenu.PopupMenuItem(_("Microphone"), { reactive: false });
this._inputSwitch.connect('toggled', Lang.bind(this, this._switchToggled, '_input'));
this._inputSlider = new PopupMenu.PopupSliderMenuItem(0); this._inputSlider = new PopupMenu.PopupSliderMenuItem(0);
this._inputSlider.connect('value-changed', Lang.bind(this, this._sliderChanged, '_input')); this._inputSlider.connect('value-changed', Lang.bind(this, this._sliderChanged, '_input'));
this._inputSlider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange)); this._inputSlider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
this.menu.addMenuItem(this._inputSwitch); this.menu.addMenuItem(this._inputTitle);
this.menu.addMenuItem(this._inputSlider); this.menu.addMenuItem(this._inputSlider);
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
@ -75,11 +73,18 @@ Indicator.prototype = {
let currentVolume = this._output.volume; let currentVolume = this._output.volume;
if (direction == Clutter.ScrollDirection.DOWN) { if (direction == Clutter.ScrollDirection.DOWN) {
let prev_muted = this._output.is_muted;
this._output.volume = Math.max(0, currentVolume - VOLUME_MAX * VOLUME_ADJUSTMENT_STEP); this._output.volume = Math.max(0, currentVolume - VOLUME_MAX * VOLUME_ADJUSTMENT_STEP);
if (this._output.volume < 1) {
this._output.volume = 0;
if (!prev_muted)
this._output.change_is_muted(true);
}
this._output.push_volume(); this._output.push_volume();
} }
else if (direction == Clutter.ScrollDirection.UP) { else if (direction == Clutter.ScrollDirection.UP) {
this._output.volume = Math.min(VOLUME_MAX, currentVolume + VOLUME_MAX * VOLUME_ADJUSTMENT_STEP); this._output.volume = Math.min(VOLUME_MAX, currentVolume + VOLUME_MAX * VOLUME_ADJUSTMENT_STEP);
this._output.change_is_muted(false);
this._output.push_volume(); this._output.push_volume();
} }
}, },
@ -103,8 +108,7 @@ Indicator.prototype = {
this._mutedChanged (null, null, '_output'); this._mutedChanged (null, null, '_output');
this._volumeChanged (null, null, '_output'); this._volumeChanged (null, null, '_output');
} else { } else {
this._outputSwitch.label.text = _("Volume: Muted"); this._outputSlider.setValue(0);
this._outputSwitch.setToggleState(false);
this.setIcon('audio-volume-muted-symbolic'); this.setIcon('audio-volume-muted-symbolic');
} }
}, },
@ -124,7 +128,7 @@ Indicator.prototype = {
this._volumeChanged (null, null, '_input'); this._volumeChanged (null, null, '_input');
} else { } else {
this._separator.actor.hide(); this._separator.actor.hide();
this._inputSwitch.actor.hide(); this._inputTitle.actor.hide();
this._inputSlider.actor.hide(); this._inputSlider.actor.hide();
} }
}, },
@ -147,11 +151,11 @@ Indicator.prototype = {
} }
if (showInput) { if (showInput) {
this._separator.actor.show(); this._separator.actor.show();
this._inputSwitch.actor.show(); this._inputTitle.actor.show();
this._inputSlider.actor.show(); this._inputSlider.actor.show();
} else { } else {
this._separator.actor.hide(); this._separator.actor.hide();
this._inputSwitch.actor.hide(); this._inputTitle.actor.hide();
this._inputSlider.actor.hide(); this._inputSlider.actor.hide();
} }
}, },
@ -174,7 +178,17 @@ Indicator.prototype = {
log ('Volume slider changed for %s, but %s does not exist'.format(property, property)); log ('Volume slider changed for %s, but %s does not exist'.format(property, property));
return; return;
} }
this[property].volume = value * VOLUME_MAX; let volume = value * VOLUME_MAX;
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);
}
this[property].push_volume(); this[property].push_volume();
}, },
@ -182,20 +196,10 @@ Indicator.prototype = {
global.play_theme_sound('audio-volume-change'); 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) { _mutedChanged: function(object, param_spec, property) {
let muted = this[property].is_muted; let muted = this[property].is_muted;
let toggleSwitch = this[property+'Switch']; let slider = this[property+'Slider'];
toggleSwitch.setToggleState(!muted); slider.setValue(muted ? 0 : (this[property].volume / VOLUME_MAX));
this._updateLabel(property);
if (property == '_output') { if (property == '_output') {
if (muted) if (muted)
this.setIcon('audio-volume-muted'); this.setIcon('audio-volume-muted');
@ -206,17 +210,7 @@ Indicator.prototype = {
_volumeChanged: function(object, param_spec, property) { _volumeChanged: function(object, param_spec, property) {
this[property+'Slider'].setValue(this[property].volume / VOLUME_MAX); this[property+'Slider'].setValue(this[property].volume / VOLUME_MAX);
this._updateLabel(property);
if (property == '_output' && !this._output.is_muted) if (property == '_output' && !this._output.is_muted)
this.setIcon(this._volumeToIcon(this._output.volume)); this.setIcon(this._volumeToIcon(this._output.volume));
},
_updateLabel: function(property) {
let label;
if (this[property].is_muted)
label = (property == '_output' ? _("Volume: Muted") : _("Microphone: Muted"));
else
label = (property == '_output' ? _("Volume: %3.0f%%") : _("Microphone: %3.0f%%")).format(this[property].volume / VOLUME_MAX * 100);
this[property+'Switch'].label.text = label;
} }
}; };