Cinnamon volume step and media keys

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Particle_Man
Level 1
Level 1
Posts: 19
Joined: Thu Feb 06, 2020 9:27 am

Cinnamon volume step and media keys

Post by Particle_Man »

LM 19.3 x64 Cinnamon.


1. I would like media keys to adjust volume in smaller than 5% increments (2% or 1%). However, a setting like "volume-step" does not appear to exist in dconf-editor.

Every media key adjusts in increments of 5%: volume-up and volume-down--as well as, curiously, volume-up-quiet and volume-down-quiet.


2. When adjusting volume, I would like to display the tooltip of the Sound applet instead of the OSD; or, alternatively, I would like to edit the OSD to include the volume percentage.


My current workaround of two keyboard shortcuts does not include notification:
pactl set-sink-volume @DEFAULT_SINK@ +2%
pactl set-sink-volume @DEFAULT_SINK@ -2%

(FWIW, '@DEFAULT_SINK@' works better than '0' with my external DAC.)
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Cinnamon volume step and media keys

Post by smurphos »

Hi, welcome to the forums.
Particle_Man wrote: Thu Feb 13, 2020 2:22 pm 1. I would like media keys to adjust volume in smaller than 5% increments (2% or 1%). However, a setting like "volume-step" does not appear to exist in dconf-editor.

Every media key adjusts in increments of 5%: volume-up and volume-down--as well as, curiously, volume-up-quiet and volume-down-quiet.
The media key volume step is hard-coded in cinnamon-settings-daemon. But it's a 5 minute job to download the sources, modify and install the modded version

Open Software Sources application and enable Source Code repositories - follow the prompts to update the cache.

Open a terminal window and

Download the sources

Code: Select all

apt source cinnamon-settings-daemon
Open the relevant file in a text editor

Code: Select all

xed ~/cinnamon-settings-daemon-4.4.0+tricia/plugins/media-keys/csd-media-keys-manager.c
In the text editor navigate to the line below and amend 5 to your preferred value then save and close the text editor.

Code: Select all

#define VOLUME_STEP 5           /* percents for one volume button press */
In the terminal window run (note the version string will differ for different versions of Cinnamon)

Code: Select all

cd cinnamon-settings-daemon-4.4.0+tricia
Then install the build dependencies

Code: Select all

apt build-dep cinnamon-settings-daemon
Then build from the modified sources

Code: Select all

apt build
Install the modified deb file (again note the version string may differ for different Cinnamon versions)

Code: Select all

apt deb ~/cinnamon-settings-daemon_4.4.0+tricia_amd64.deb
Log out and log back in - test.
Last edited by smurphos on Mon Feb 17, 2020 12:58 am, edited 3 times in total.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Cinnamon volume step and media keys

Post by smurphos »

Particle_Man wrote: Thu Feb 13, 2020 2:22 pm 2. When adjusting volume, I would like to display the tooltip of the Sound applet instead of the OSD; or, alternatively, I would like to edit the OSD to include the volume percentage.
Hi this post should get you started on a mod to show the volume percentage in the OSD - viewtopic.php?f=208&t=277976

I've got to go to work now but if you need more help I'll look at a step by step over the weekend for this part of your query.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Cinnamon volume step and media keys

Post by smurphos »

smurphos wrote: Fri Feb 14, 2020 3:07 am I've got to go to work now but if you need more help I'll look at a step by step over the weekend for this part of your query.
Hi,

Here's a step by step add a label with the percentage for the volume and brightness media keys OSD

1) Backup the original osdWindow.js using this command in a terminal

Code: Select all

sudo cp /usr/share/cinnamon/js/ui/osdWindow.js /usr/share/cinnamon/js/ui/osdWindow.js.original
2) Open osdWindow.js with elevated privileges in a text editor using this command in a terminal

Code: Select all

xed admin:///usr/share/cinnamon/js/ui/osdWindow.js
Navigate to to this code block and amend to add the three lines

Code: Select all

        this._label = new St.Label();
        this._label.style = 'font-size: 1.2em; text-align: center;'
        this.actor.add(this._label);
Original

Code: Select all

OsdWindow.prototype = {
    _init: function(monitorIndex) {
        this._popupSize = 0;

        this._osdSettings = new Gio.Settings({ schema_id: "org.cinnamon" });
        this._osdSettings.connect("changed::show-media-keys-osd", Lang.bind(this, this._onOsdSettingsChanged));

        this._monitorIndex = monitorIndex;

        this.actor = new St.BoxLayout({ style_class: 'osd-window',
                                       vertical: true,
                                       important: true });

        this._icon = new St.Icon();
        this.actor.add(this._icon, { expand: true });

        this._level = new LevelBar();
        this.actor.add(this._level.actor);

        this._hideTimeoutId = 0;
        this._reset();

        Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._monitorsChanged));
        this._onOsdSettingsChanged();

        Main.uiGroup.add_child(this.actor);
    },
Amended

Code: Select all

OsdWindow.prototype = {
    _init: function(monitorIndex) {
        this._popupSize = 0;

        this._osdSettings = new Gio.Settings({ schema_id: "org.cinnamon" });
        this._osdSettings.connect("changed::show-media-keys-osd", Lang.bind(this, this._onOsdSettingsChanged));

        this._monitorIndex = monitorIndex;

        this.actor = new St.BoxLayout({ style_class: 'osd-window',
                                       vertical: true,
                                       important: true });

        this._icon = new St.Icon();
        this.actor.add(this._icon, { expand: true });

        this._level = new LevelBar();
        this.actor.add(this._level.actor);
        
        this._label = new St.Label();
        this._label.style = 'font-size: 1.2em; text-align: center;'
        this.actor.add(this._label);

        this._hideTimeoutId = 0;
        this._reset();

        Main.layoutManager.connect('monitors-changed', Lang.bind(this, this._monitorsChanged));
        this._onOsdSettingsChanged();

        Main.uiGroup.add_child(this.actor);
    },
Then navigate to this code block and amend to add a couple of lines to set the label text.

Original

Code: Select all

    setLevel: function(level) {
        this._level.actor.visible = (level != undefined);
        if (level != undefined) {
            if (this.actor.visible)
                Tweener.addTween(this._level,
                                 { level: level,
                                   time: LEVEL_ANIMATION_TIME,
                                   transition: 'easeOutQuad' });
            else
                this._level.level = level;
        }
    },
Amended

Code: Select all

    setLevel: function(level) {
        this._level.actor.visible = (level != undefined);
        this._label.set_text("N/A");
        if (level != undefined) {
            this._label.set_text(String(level) + " %");
            if (this.actor.visible)
                Tweener.addTween(this._level,
                                 { level: level,
                                   time: LEVEL_ANIMATION_TIME,
                                   transition: 'easeOutQuad' });
            else
                this._level.level = level;
        }
    },
Save the file, restart Cinnamon with Ctrl-Alt-Esc and test.
Last edited by smurphos on Sat Feb 15, 2020 3:26 am, edited 1 time in total.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Cinnamon volume step and media keys

Post by smurphos »

Image
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Dennis_J

Re: Cinnamon volume step and media keys

Post by Dennis_J »

smurphos, thank you for this fix. The last part of your post, providing an OSD, works perfectly. It's changing the volume step size where I encounter difficulty. In the last few lines of the build, is this error:
“dpkg-buildpackage: error: failed to sign .dsc file” and no .deb is created.
I notice that near the end, signing points to the directory
“cinnamon-settings-daemon_4.4.0+tricia.dsc “ which does not exist. There is a very long output in the terminal, from which I extracted areas showing warnings and errors. I appreciate any words of wisdom. Thanks, Dennis_J

This was a fresh Mint 19.3 install on my test machine, native, not a VM. 19.3 has been stable since install last month. All updates are current.

After adding source and running:
apt source cinnamon-settings-daemon
No errors.

Edited plugins/media-keys/csd-media-keys-manager.c (changed step size from 5 to 2)

First problem occurs here:
cd cinnamon-settings-daemon_4.4.0+tricia
bash: cd: cinnamon-settings-daemon_4.4.0+tricia: No such file or directory


There is a directory using a hyphen (-) instead of underscore (_). Changing to that directory, things proceed.
cd cinnamon-settings-daemon-4.4.0+tricia

tech@xps:~/cinnamon-settings-daemon-4.4.0+tricia$ apt build

Loads of errors - This warning repeats numerous times

/bin/bash ../../libtool --mode=install /usr/bin/install -c csd-a11y-keyboard '/home/tech/cinnamon-settings-daemon-4.4.0+tricia/debian/tmp/usr/lib/x86_64-linux-gnu/cinnamon-settings-daemon'
libtool: warning: '../../cinnamon-settings-daemon/libcsd.la' has not been installed in '/usr/lib/x86_64-linux-gnu/cinnamon-settings-daemon-3.0'

. . . .

make[1]: Leaving directory '/home/tech/cinnamon-settings-daemon-4.4.0+tricia'
dh_shlibdeps
dpkg-shlibdeps: warning: can't extract name and version from library name 'libcsd.so'
dpkg-shlibdeps: warning: can't extract name and version from library name 'libcsd.so'
dpkg-shlibdeps: warning: can't extract name and version from library name 'libcsd.so'
dpkg-shlibdeps: warning: can't extract name and version from library name 'libcsd.so'
dpkg-shlibdeps: warning: can't extract name and version from library name 'libcsd.so'
dpkg-shlibdeps: warning: can't extract name and version from library name 'libcsd.so'
dh_installdeb
dh_gencontrol
dpkg-gencontrol: warning: Depends field of package cinnamon-settings-daemon-dev: unknown substitution variable ${shlibs:Depends}
dh_md5sums
dh_builddeb
dpkg-deb: building package 'cinnamon-settings-daemon-dev' in '../cinnamon-settings-daemon-dev_4.4.0+tricia_amd64.deb'.
dpkg-deb: building package 'cinnamon-settings-daemon' in '../cinnamon-settings-daemon_4.4.0+tricia_amd64.deb'.
dpkg-deb: building package 'cinnamon-settings-daemon-dbgsym' in 'debian/.debhelper/scratch-space/build-cinnamon-settings-daemon/cinnamon-settings-daemon-dbgsym_4.4.0+tricia_amd64.deb'.
Renaming cinnamon-settings-daemon-dbgsym_4.4.0+tricia_amd64.deb to cinnamon-settings-daemon-dbgsym_4.4.0+tricia_amd64.ddeb


dpkg-genbuildinfo
dpkg-genchanges >../cinnamon-settings-daemon_4.4.0+tricia_amd64.changes
dpkg-genchanges: info: including full source code in upload
dpkg-source --after-build cinnamon-settings-daemon-4.4.0+tricia
dpkg-buildpackage: info: full upload; Debian-native package (full source is included)
signfile cinnamon-settings-daemon_4.4.0+tricia.dsc
gpg: skipped "Clement Lefebvre <root@linuxmint.com>": No secret key
gpg: dpkg-sign.YstRLXfV/cinnamon-settings-daemon_4.4.0+tricia.dsc: clear-sign failed: No secret key

dpkg-buildpackage: error: failed to sign .dsc file
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Cinnamon volume step and media keys

Post by smurphos »

Dennis_J wrote: Sun Feb 16, 2020 9:41 pm There is a directory using a hyphen (-) instead of underscore (_). Changing to that directory, things proceed.
cd cinnamon-settings-daemon-4.4.0+tricia
Thanks for spotting that - I've edited the post to fix the typo.

The output of build / compile commands is always very verbose.

The signing errors as they are simply because your machine doesn't have Clem's personal package signing key that signs the packages being built as genuine Mint packages. As long as you got a deb file at the end of it you should be good to install it.
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
Dennis_J

Re: Cinnamon volume step and media keys

Post by Dennis_J »

smurphos, no .deb is created.

Is this a material error? Says warning though. As a dev, you probably have tools installed us "normal" users don't :-)
libtool: warning: '../../cinnamon-settings-daemon/libcsd.la' has not been installed in '/usr/lib/x86_64-linux-gnu/cinnamon-settings-daemon-3.0'

Will try to find that dependency and also look for how to add Clem's signing key.

Thanks! This is not an urgent thing, sure will be neat to get working though.
Dennis_J
Dennis_J

Re: Cinnamon volume step and media keys

Post by Dennis_J »

smurphos,

Cleaned up from yesterday's attempt and ran it again this morning, same PC, got a deb file! Installed it and it works just like you said it would. Same errors show up, tried to install Clem's public key, that didn't fix the signing error, but bottom line is, IT WORKS! Very handy when using a workstation for audio,

Thanks again, sorry to have bothered you.

Dennis_J
Particle_Man
Level 1
Level 1
Posts: 19
Joined: Thu Feb 06, 2020 9:27 am

Re: Cinnamon volume step and media keys

Post by Particle_Man »

smurphos, First, I want to express how impressed I am at the level of support you have provided; this speaks to the helpfulness that I've observed in the Linux Mint community in general.

-------

I've compiled the .deb without signing, but it seems to contain many more files than should be relevant to this patch.

1. How to back up the current file(s)?
2. After having installed the .deb, how to revert to the backup?

-------

Otherwise, for those who may be interested, I'm currently at different degrees of scripting workarounds to display the volume percentage: one with xdotool, very kludgey, to display the tooltip of the Sound applet; and another with yad and other utils, a fairly and simply customizable OSD, less kludgey than the xdotool approach.
User avatar
smurphos
Level 18
Level 18
Posts: 8501
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Cinnamon volume step and media keys

Post by smurphos »

Particle_Man wrote: Thu Feb 27, 2020 8:35 am 1. How to back up the current file(s)?
2. After having installed the .deb, how to revert to the backup?
No real need to back up because the revert is as simple as

Code: Select all

apt install --reinstall cinnamon-settings-daemon
But if you want a copy of the original deb stored somewhere you can

Code: Select all

apt download cinnamon-settings-daemon
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
dhunter

Re: Cinnamon volume step and media keys

Post by dhunter »

This is a fabulous thread for those of us more used to smaller, (i.e. 2%) sound increments, so thanks Smurphos.

There is one very minor item in the displayed volume, at least in Mint 20, (4.6.4+ulyana). For some reason, if the sound level is anything > 0, the value in the osdWindow from the above code is 1 less than the value shown in the tray icon, but if you mute the sound, (level = 0) the value in the osdWindow and the tray icon are in sync, so I just added a quick if statement to fix this minor issue up. The below code block should be a drop-in replacement for Smurphos' last "Amended" one.

Code: Select all

    setLevel: function(level) {
        this._level.actor.visible = (level != undefined);
        this._label.set_text("N/A");
        if (level != undefined) {
            if (level != 0) {
                this._label.set_text(String(level + 1) + " %");
            } else {
                this._label.set_text(String(level) + " %");
            }
            if (this.actor.visible)
                Tweener.addTween(this._level,
                                 { level: level,
                                   time: LEVEL_ANIMATION_TIME,
                                   transition: 'easeOutQuad' });
            else
                this._level.level = level;
        }
    },
freezoid
Level 1
Level 1
Posts: 16
Joined: Mon Oct 16, 2017 7:22 pm

Re: Cinnamon volume step and media keys

Post by freezoid »

Hi I tried the above steps but with cinnamon-settings-daemon-4.6.4+ulyana
and I'm not getting a deb file at the end.
Pretty much the same situation as here where Dennis_J got stuck viewtopic.php?p=1763666#p1763666

Could please tell me what I did wrong here?

Commands used:

Code: Select all

apt source cinnamon-settings-daemon
xed ~/cinnamon-settings-daemon-4.6.4+ulyana/plugins/media-keys/csd-media-keys-manager.c
cd cinnamon-settings-daemon-4.6.4+ulyana
apt build-dep cinnamon-settings-daemon
apt build
apt deb ~/cinnamon-settings-daemon-4.6.4+ulyana_amd64.deb
Edit: Sorry I just realised this topic is 1 year old...
CruziX
Level 1
Level 1
Posts: 2
Joined: Tue Feb 09, 2021 1:39 pm

Re: Cinnamon volume step and media keys

Post by CruziX »

Running the command 'apt build' as root did the trick for me.

My Steps for Linux Mint 20.1 Ulyssa:
The following commands as non root user:

Code: Select all

apt source cinnamon-settings-daemon
xed ~/cinnamon-settings-daemon-4.8.4+ulyssa/plugins/media-keys/csd-media-keys-manager.c
change '#define VOLUME_STEP 5' -> '#define VOLUME_STEP 2' -> Save

Code: Select all

cd cinnamon-settings-daemon-4.8.4+ulyssa/
apt build-dep cinnamon-settings-daemon
sudo apt build
sudo apt ~/cinnamon-settings-daemon_4.8.4+ulyssa_amd64.deb
CruziX
Level 1
Level 1
Posts: 2
Joined: Tue Feb 09, 2021 1:39 pm

Re: Cinnamon volume step and media keys

Post by CruziX »

I've changed the VOLUME_STEP value to 2, but if I increase the volume with media keys to >= 98 I can't decrease anymore until I decrease the volume in the sound applet.
Does anyone have a solution?
arcai
Level 1
Level 1
Posts: 1
Joined: Tue Mar 23, 2021 10:35 am

Re: Cinnamon volume step and media keys

Post by arcai »

I was looking solution to change this 5 step to 2 and this thread helped me (yes, long time Windows user). On manjaro cinnamon works the same way. Thank you.
CruziX wrote: Mon Feb 22, 2021 1:12 pm I've changed the VOLUME_STEP value to 2, but if I increase the volume with media keys to >= 98 I can't decrease anymore until I decrease the volume in the sound applet.
Does anyone have a solution?
0-100% and 100%-0 works for me this way:
/usr/share/cinnamon/applets/sound@cinnamon.org/applet.js (maybe mint has the same path, i dont know)

change line "VOLUME_ADJUSTMENT_STEP = 0.05; /* Volume adjustment step in % */"

to "VOLUME_ADJUSTMENT_STEP = 0.01; /* Volume adjustment step in % */"

It also changes increase/decrease by 1% while scrolling mouse wheel at speaker icon.
Loufute
Level 1
Level 1
Posts: 12
Joined: Sun Oct 06, 2019 2:20 am

Re: Cinnamon volume step and media keys

Post by Loufute »

Hi,

Does one of you know where we could ask for a change so that it is not hard coded but allowing us to personalize it (at least in a config file)? I am not yet familiar with requesting features in Mint so I do not know where to start :oops:
[EDIT] I think I found where : on Github. I see that there is already a request, that has "recently" (October 2020) been marked as a bug.

In the meantime, and following another post on this Forum, I used another and much less elegant method, but which does not require rebuilding at every update.

I will share it here for those interested, and also if someone wants to improve it :
For volume increase
  1. Create a text file wherever you want, name it whatever you want (e.g. ".volumeUp" in "Home")
  2. Open it with any text software
  3. Add the following code :

    Code: Select all

    #!/bin/sh
    pactl set-sink-volume @DEFAULT_SINK@ +2%;
    amixer sget Master | zenity --timeout 1 --info --text $(grep -o -P "[0-9]{1,3}%";);
    
    First line indicates that is is a script.
    Second line increases the volume by 2%. Change it for any step you'd like.
    Third line first get the Master volume (amixer sget Master <- it requires ALSA driver, I think it is the one used by default in Mint???), pass the information (vertical line), then uses zenity to display an info message (the one with ok - that's the most inelegant part of this workaround) during 1 second (--timeout 1), the message being the volume level (it searches in the results of "sget Master" a text having 1-to-3 digits and a percent).
  4. Save the file
  5. Right click on the file > Properties > Permissions > Tick "Allow executing file as program" > Close
  6. Open "Keyboard" in the menu (goes to System settings > Hardware > Keyboard)
  7. Open the "Shortcuts" Tab
  8. Sound and Media > Volume up > Double click Keyboard bindings and push backspace (to remove it)
  9. Click "Add custom shortcut"
  10. Give it any name (e.g. "Increasing volume by 2%")
  11. Click on the folder (right of "Command") and select the file you created (e.g. ".volumeUp" in "Home") or indicate its path in "Command"
  12. Click Add
  13. Click on it > Double click "Keyboard bindings" > Push on the "increase volume" key
  14. Test it
Normally, it should increase the volume by the percent you asked for, and indicate for 1 second an info message with the percent of volume. If you increase it several times, that is as many infoboxes that will appear, but they will stay only for 1 second (except if you change that).
I wanted to send it as notification (with notify-send instead of zenity), but I could not find how to reduce the amount of time the notification was displayed (so there was a lot of lag).
I also wished to display the OSD volume instead but could not find the right command (if you have it, do not hesitate, that'd be much better already).

To decrease volume, you only have to adapt names and changes "+2%" by "-2%" :
For volume decrease
  1. Create a text file wherever you want, name it whatever you want (e.g. ".volumeDown" in "Home")
  2. Open it with any text software
  3. Add the following code :

    Code: Select all

    #!/bin/sh
    pactl set-sink-volume @DEFAULT_SINK@ -2%;
    amixer sget Master | zenity --timeout 1 --info --text $(grep -o -P "[0-9]{1,3}%";);
    
    First line indicates that is is a script.
    Second line decreases (see the minus) the volume by 2%. Change it for any step you'd like.
    Third line first get the Master volume (amixer sget Master <- it requires ALSA driver), pass the information (vertical line), then uses zenity to display an info message (the one with ok) during 1 second (--timeout 1), the message being the volume level.
  4. Save the file
  5. Right click on the file > Properties > Permissions > Tick "Allow executing file as program" > Close
  6. Open "Keyboard" in the menu (goes to System settings > Hardware > Keyboard)
  7. Open the "Shortcuts" Tab
  8. Sound and Media > Volume down > Double click Keyboard bindings and push backspace (to remove it)
  9. Click "Add custom shortcut"
  10. Give it any name (e.g. "Decreasing volume by 2%")
  11. Click on the folder (right of "Command") and select the file you created (e.g. ".volumeDown" in "Home") or indicate its path in "Command"
  12. Click Add
  13. Click on it > Double click "Keyboard bindings" > Push on the "decrease volume" key
  14. Test it
jawenakat8ep
Level 1
Level 1
Posts: 18
Joined: Tue Feb 04, 2020 8:55 pm

Re: Cinnamon volume step and media keys

Post by jawenakat8ep »

smurphos wrote: Fri Feb 14, 2020 3:03 am The media key volume step is hard-coded in cinnamon-settings-daemon. But it's a 5 minute job to download the sources, modify and install the modded version
...
Thank you for posting these instructions! I can confirm they still work as of 8/17/2021.

cinnamon-settings-daemon_5.0.4+uma_amd64.deb
Locked

Return to “Sound”