Skip to content

Commit

Permalink
Use muffin's sound player instead of csd-sound.
Browse files Browse the repository at this point in the history
This eliminates the need for csd-sound.

Changed the volume slider and sound applet's mouse-scrolling to
filter out 'smooth' scroll events, as we were playing sounds for
two events at a time (we received both smooth and directional
scroll events for the same action).

Removed any volume control for sounds - it was only used in the
sound applet, and was never actually used, as stream.decibal would
usually be a negative value. It's unnecessary anyhow, as the
volume sound will play at the current volume.. that is being
adjusted.
  • Loading branch information
mtwebster committed Oct 27, 2021
1 parent 77b0abe commit 7ab95f0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 76 deletions.
6 changes: 4 additions & 2 deletions files/usr/share/cinnamon/applets/sound@cinnamon.org/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,9 @@ class CinnamonSoundApplet extends Applet.TextIconApplet {

this._applet_tooltip.show();

this._notifyVolumeChange(this._output);
if (event.get_scroll_direction() != Clutter.ScrollDirection.SMOOTH) {
this._notifyVolumeChange(this._output);
}
}

_onButtonPressEvent (actor, event) {
Expand Down Expand Up @@ -1462,7 +1464,7 @@ class CinnamonSoundApplet extends Applet.TextIconApplet {
}

_notifyVolumeChange(stream) {
Main.soundManager.playVolume('volume', stream.decibel);
Main.soundManager.play('volume');
}

_mutedChanged(object, param_spec, property) {
Expand Down
4 changes: 2 additions & 2 deletions js/ui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ function start() {
// when the system is bogged down
if (do_animation) {
let id = GLib.idle_add(GLib.PRIORITY_LOW, () => {
if (do_login_sound)
if (do_login_sound && !global.session_running)
soundManager.play_once_per_session('login');
layoutManager._doStartupAnimation();
return GLib.SOURCE_REMOVE;
Expand All @@ -503,7 +503,7 @@ function start() {
global.background_actor.show();
setRunState(RunState.RUNNING);

if (do_login_sound)
if (do_login_sound && !global.session_running)
soundManager.play_once_per_session('login');
}

Expand Down
3 changes: 3 additions & 0 deletions js/ui/popupMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,9 @@ var PopupSliderMenuItem = class PopupSliderMenuItem extends PopupBaseMenuItem {

_onScrollEvent (actor, event) {
let direction = event.get_scroll_direction();
if (direction == Clutter.ScrollDirection.SMOOTH) {
return;
}

if (direction == Clutter.ScrollDirection.DOWN) {
this._value = Math.max(0, this._value - SLIDER_SCROLL_STEP);
Expand Down
90 changes: 18 additions & 72 deletions js/ui/soundManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,11 @@ const Gio = imports.gi.Gio;
const Main = imports.ui.main;
const Mainloop = imports.mainloop;

const iface =
"<node> \
<interface name='org.cinnamon.SettingsDaemon.Sound'> \
<annotation name='org.freedesktop.DBus.GLib.CSymbol' value='csd_sound_manager'/> \
<method name='PlaySoundFile'> \
<arg name='id' direction='in' type='u'/> \
<arg name='filename' direction='in' type='s'/> \
</method> \
<method name='PlaySoundFileVolume'> \
<arg name='id' direction='in' type='u'/> \
<arg name='filename' direction='in' type='s'/> \
<arg name='volume' direction='in' type='s'/> \
</method> \
<method name='PlaySound'> \
<arg name='id' direction='in' type='u'/> \
<arg name='name' direction='in' type='s'/> \
</method> \
<method name='CancelSound'> \
<arg name='id' direction='in' type='u'/> \
</method> \
</interface> \
</node>";

const proxy = Gio.DBusProxy.makeProxyWrapper(iface);

const PLAY_ONCE_FLAG = 8675309;

function SoundManager() {
this._init();
}

SoundManager.prototype = {

_init : function() {
this.keys = ["switch", "close", "map", "minimize", "maximize", "unmaximize", "tile", "login", "plug", "unplug", "notification"];
this.desktop_keys = ["volume"];
Expand All @@ -53,32 +25,22 @@ SoundManager.prototype = {
Mainloop.timeout_add_seconds(10, Lang.bind(this, function() {
this.startup_delay = false;
}));

this.proxy = new proxy(Gio.DBus.session,
'org.cinnamon.SettingsDaemon.Sound',
'/org/cinnamon/SettingsDaemon/Sound');

/* patch public methods into global to keep backward compatibility */

global.play_theme_sound = Lang.bind(this, this.playSound);
global.play_sound_file = Lang.bind(this, this.playSoundFile);
global.cancel_sound = Lang.bind(this, this.cancelSound);
},

_cacheSettings: function() {
for (var i in this.keys) {
let key = this.keys[i];
this.enabled[key] = this.settings.get_boolean(key + "-enabled");
this.file[key] = this.settings.get_string(key + "-file");
}
}
},

_cacheDesktopSettings: function() {
for (var i in this.desktop_keys) {
let key = this.desktop_keys[i];
this.enabled[key] = this.desktop_settings.get_boolean(key + "-sound-enabled");
this.file[key] = this.desktop_settings.get_string(key + "-sound-file");
}
}
},

play: function(sound) {
Expand All @@ -89,46 +51,30 @@ SoundManager.prototype = {
}
},

// Deprecated - this was only used by sound applets for volume notification,
// but had no effect, as decibal levels were < 0 and always rejected
// as a result.
playVolume: function(sound, volume) {
if (this.startup_delay)
return;
if (this.enabled[sound] && this.file[sound] != "") {
this.playSoundFileVolume(0, this.file[sound], volume);
}
},

/* We want the login sound synced to the fade-in animation
* but we don't want it playing every time someone restarts
* Cinnamon - passing PLAY_ONCE_FLAG will let the sound handler
* know not to play this more than once for its lifetime (usually
* for the session.)
*/

play_once_per_session: function(sound) {
if (this.enabled[sound] && this.file[sound] != "") {
this.playSoundFile(PLAY_ONCE_FLAG, this.file[sound]);
}
this.play(sound);
},

/* Public methods. */

playSoundFile: function(id, filename) {
this.proxy.PlaySoundFileRemote(id, filename);
},

playSoundFileVolume: function(id, filename, volume) {
//ignore volume parameter if it is not valid (no mute)
if (!Number.isFinite(volume) || Number.isNaN(volume) || volume < 0)
this.playSoundFile(id, filename);
else
this.proxy.PlaySoundFileVolumeRemote(id, filename, volume + "");
global.display.get_sound_player().play_from_file
(
Gio.File.new_for_path(filename),
id.toString(),
null
);
},

playSound: function(id, name) {
this.proxy.PlaySoundRemote(id, name);
global.display.get_sound_player().play_from_theme
(
Gio.File.new_for_path(filename),
id.toString(),
null
);
},

cancelSound: function(id) {
this.proxy.CancelSoundRemote(id);
}
};

0 comments on commit 7ab95f0

Please sign in to comment.