read

I use a Logitech Performance MX wireless mouse, on Ubuntu 18.10 (Cosmic Cuttlefish), with Gnome 3.30.2 Ubuntu 20.04, with Gnome 3.36.2.

This mouse uses regular 1.2V AA NiMH rechargeable battery1, which usually lasts 3 months on a single charge

The problem is that Ubuntu's power system tries to detect how much voltage is left, and either the voltage sensors or the calculation algorithm is completely broken, so it starts to show notifications 6-8 weeks before it really runs out.

The worse part is that these notifications won't fade away after a few seconds like you'd expect. And to make it more infuriating, they have an audible alert, and show up after a every period of brief inactivity, which means you'll get dozens of notifications per day -- and you'll will need to click to dismiss them every single time.

I don't really need to be notified two months in advance on a mouse battery (or at all). When it runs out, I can just connect the cable. It's not like a printer, that you need to buy ink in advance.

It seems I'm not alone: tons of users have reported the same problem for years (1, or 2, or 3), but no solution.

It seems that upower developers recognize that the battery % should be ignored, but still emits warnings on low battery, and Gnome Settings Daemon doesn't offer any way to selectively disable or control these notifications:

$ upower --dump
Device: /org/freedesktop/UPower/devices/mouse_hidpp_battery_12  
  native-path:          hidpp_battery_12
  model:                Performance MX
  serial:               104a-8a-10-ee-9b
  power supply:         no
  updated:              Sun Jun  2 18:09:54 2019 (15 seconds ago)
  has history:          yes
  has statistics:       yes
  mouse
    present:             yes
    rechargeable:        yes
    state:               discharging
    warning-level:       none
    battery-level:       critical
    percentage:          5% (should be ignored) ◀◀◀
    icon-name:          'battery-caution-symbolic'

Most of the workarounds I found involve patching gnome-settings-daemon (which I've done before, but for different reasons), or disabling power notifications entirely. I dislike both solutions, and wanted to selectively disable only mouse battery notifications, without touching anything else.

Thanks to a tip by @daFritz84, I decided to patch upowerd directly (although I used a different method than Stefan). The good news is that upower has few dependencies, so it's pretty straightforward to compile and patch your system.

Here's the patch to be applied over up-device.c:

--- up-device.c    2019-06-15 00:18:57.607554731 -0400
+++ up-device-silent.c    2019-06-15 00:19:03.207705276 -0400
@@ -63,6 +63,15 @@
     UpDeviceLevel warning_level, battery_level;
     UpExportedDevice *skeleton = UP_EXPORTED_DEVICE (device);

+    /* Disable warning notifications for wireless mice with rechargeable batteries */
+    int type = up_exported_device_get_type_ (skeleton);
+    int state = up_exported_device_get_state(skeleton);
+    if (type == UP_DEVICE_KIND_MOUSE && state == UP_DEVICE_STATE_DISCHARGING) {
+        warning_level = UP_DEVICE_LEVEL_NONE;
+        up_exported_device_set_warning_level (skeleton, warning_level);
+        return;
+    }
+
     /* Not finished setting up the object? */
     if (device->priv->daemon == NULL)
         return;

Here's the step-by-step, tested on Ubuntu 18.04, 20.04, 20.10, and Manjaro (disclaimer: provided as is; you are responsible for checking the accuracy of the patch and ensure it won't ruin your system. Having said that, let me know in the comments below if it doesn't work for you, and I'll try to incorporate new distributions over time):

UPOWER_ORIG_VER=`upower --version`  
OS=`awk -F= '/^ID=/{print $2}' /etc/os-release`  
OS_VER=`awk -F= '/^VERSION_ID=/{print $2}' /etc/os-release | cut -d "\"" -f 2`

if [[ "$OS" == "manjaro" ]]  
then  
    sudo pacman -S base-devel gtk-doc gobject-introspection git
    PATH_UPOWERD="/usr/lib"
    PATH_UPOWER="/usr/bin"
elif [[ "$OS" == "ubuntu" ]]  
then  
    sudo apt install git gtk-doc-tools gobject-introspection libgudev-1.0-dev libusb-1.0-0-dev autoconf libtool autopoint
    if [[ "$OS_VER" == "20.10" ]]
    then
        PATH_UPOWERD="/usr/libexec"
        PATH_UPOWER="/usr/bin"
    else
        PATH_UPOWERD="/usr/lib/upower"
        PATH_UPOWER="/usr/bin"
    fi
else  
    echo "Unknown system; this script was only tested on ubuntu and manjaro."
    exit 1
fi

# Download and patch upowerd
#
git clone https://gitlab.freedesktop.org/upower/upower  
cd upower/src  
wget https://gist.githubusercontent.com/guiambros/f2bf07f1cc085f8f0b0a9e04c0a767b4/raw/ef90dfcfa2489bab577bd984a6082abacdf8b0b1/up-device.patch  
patch < up-device.patch  
cd ..  
./autogen.sh
./configure
make

# Install upowerd
#
CUR_DATETIME=`date +%Y-%m-%d-%H%M%S`

pushd .  
cd src/.libs  
strip upowerd  
sudo chown root.root upowerd  
sudo mv upowerd ${PATH_UPOWERD}/upowerd-silent  
cd ${PATH_UPOWERD}  
sudo mv upowerd upowerd-original-${CUR_DATETIME}  
sudo ln -s upowerd-silent upowerd  
popd

# Install upower
#
pushd .  
cd tools/.libs  
strip upower  
sudo chown root.root upower  
sudo mv upower ${PATH_UPOWER}/upower-silent  
cd ${PATH_UPOWER}  
sudo mv upower upower-original-${CUR_DATETIME}  
sudo ln -s upower-silent upower  
popd

# Restart upowerd
#
sudo systemctl restart upower

# Compare versions before/after (they will likely be different, but it depends on what your distro packages by default)
echo  
echo "---------------------------------------------------------------------------"  
echo "upower version BEFORE the update:"  
echo "${UPOWER_ORIG_VER}"  
echo "-------------------------------------"  
echo "upower version AFTER the update:"  
upower --version

To make it easier, here's the full script. You can run with:

wget -O - https://gist.githubusercontent.com/guiambros/166039459a8579638b57f7d135505ab1/raw/89de0e881f543097155a7ca8ce53248955a7ff54/silent-mouse.sh | bash  

Now enjoy your low battery spam-free system :) Let me know in the comments below if it works for you.

1My old Performance MX uses a replaceable battery; the Performance MX 3 uses an internal non-replaceable battery that lasts even longer


Blog Logo

Gui Ambros

Maker, engineer, ad:tech veteran. Incurable optimist. I was there when the web was born. Opinions here are my own. @GuiAmbros


Published

Image

wrgms.com

/dev/random rants about technology, electronics, startups.

Back to Overview