Dec 29, 2015

Disable Volume and Brightness OSD in KDE


A few days ago Arch linux team decided to dropout support for KDE 4, and force their users to upgrade to KDE Plasma 5. I've tested Plasma 5 around 10 months ago and, to be honest, my experience was not good, Plasma 5 suffered a lot of stability problems, but the problem that most annoyed me was the backlight OSD thing, i've even reported and suggested a patch for it but their developers ignored me and refused to fix this problem. So i had not option but to return to KDE 4.

Yesterday, i had not option but to try Plasma 5 again, and for my surprise (or not), the backlight OSD thing was not fixed, but also KMix is showing OSD again without option for disabling it, and it was supposed to have been fixed 3 years ago. A this point i don't know what KDE developers are thinking, it seems that their are trying to transform KDE into a Nagware. At least i know that i'm not alone because 3 months after my report, other user reported it again, and developers provided just a partial solution making the OSD smaller than before, but for me it was not ok and decided to get rid of the OSD annoyance once for all.

Looking for code, here and there, i discovered that the backlicht was controlled through D-Bus and it had an option for not showing the OSD when setting the backlight. the code for setting the backlight with D-Bus is as follow:
qdbus org.kde.Solid.PowerManagement /org/kde/Solid/PowerManagement/Actions/BrightnessControl setBrightnessSilent 500
setBrightnessSilent changes the backlight without showing the OSD, while setBrightness does it's normal stuff.

With volume OSD there was not a D-Bus service, so i decided to use the tools provided by PulseAudio. For increasing the volume a 5% in PulseAudio you can do:
pactl set-sink-volume 0 +5%
So i just created an script for calling this commands every time i press a key.
#!/usr/bin/sh

# <command> -> <arch package>
# qdbus -> qt5-tools
# pactl -> libpulse

# % of increment or decrement
diffp=10

function incBrightness() {
    service='org.kde.Solid.PowerManagement'
    path='/org/kde/Solid/PowerManagement/Actions/BrightnessControl'

    method='brightnessMax'
    brightnessMax=$(qdbus ${service} ${path} ${method})

    method='brightness'
    brightness=$(qdbus ${service} ${path} ${method})

    ((brightness += diffp * brightnessMax / 100))

    method='setBrightnessSilent'
    qdbus ${service} ${path} ${method} ${brightness}
}

function decBrightness() {
    service='org.kde.Solid.PowerManagement'
    path='/org/kde/Solid/PowerManagement/Actions/BrightnessControl'

    method='brightnessMax'
    brightnessMax=$(qdbus ${service} ${path} ${method})

    method='brightness'
    brightness=$(qdbus ${service} ${path} ${method})

    ((brightness -= diffp * brightnessMax / 100))

    method='setBrightnessSilent'
    qdbus ${service} ${path} ${method} ${brightness}
}

function incVolume() {
    pactl set-sink-volume 0 +${diffp}%
}

function decVolume() {
    pactl set-sink-volume 0 -${diffp}%
}

# options:
#
# -b    Decrease brightness
# -B    Increase brightness
# -v    Decrease volume
# -V    Increase volume

while getopts "bBvV" option
do
  case $option in
    b)
      decBrightness
      exit 0
      ;;
    B)
      incBrightness
      exit 0
      ;;
    v)
      decVolume
      ;;
    V)
      incVolume
      ;;
  esac
done
And give execution permissions to the script:
chmod +x ./kosdblock.sh
Of course you can test the script in the command line:
./kosdblock.sh -b
./kosdblock.sh -B
./kosdblock.sh -v
./kosdblock.sh -V
Now we reassign volume and brightness global keys to our script. Open System Settings -> Shortcuts -> Custom shortcuts -> Edit -> New Group, and create one group for Brightness and other for volume -> right click in the group -> New -> Global Shortcut -> Command/URL. In the Trigger tab reassign the volume and brightness keys, and in the Action tab, write the path to the script followed by the desired option, Apply and that's all.

2 comments:

  1. > but their developers ignored me and refused to fix this problem

    As the very link that you're pointing to shows, you were _not_ ignored and it was explained to you why your patch cannot be accepted. You actually ended the conversation yourself with "These are my final words" while the last paragraph of Kai's comment even hints on how should this be done properly --> https://bugs.kde.org/show_bug.cgi?id=343962#c11

    Please don't twist the facts.

    ReplyDelete
    Replies
    1. The command:

      pacman -Qo /usr/share/plasma/look-and-feel/org.kde.breeze.desktop/contents/osd/OsdItem.qml

      With output:

      /usr/share/plasma/look-and-feel/org.kde.breeze.desktop/contents/osd/OsdItem.qml is owned by plasma-workspace 5.8.5-1

      Shows that those files are not even part of powerdevil. Non of those files are part of powerdevil:

      pacman -Ql powerdevil

      That "workaround" is not fixing the root problem, because the patch you suggest affects system wide, including those applications that are not even related to powerdevil.

      And please don't come with the argument of "because I'm using Arch", because the code is a proof that those files doesn't even exists there.

      Just take your time and read all the comments in the report, we are not suggesting to remove the OSD, what we want is an option for disabling it, system wide or per application (preferred), we don't want it to be smaller, we don't want it to be transparent, we just don't want it.

      Seriously, KDE devs are too stubborn.

      Delete