Created
March 4, 2020 04:05
-
-
Save y56/710b16844681e4fe51a08428b0dca30a to your computer and use it in GitHub Desktop.
Disable "Mouse battery low" spam notification on Ubuntu
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Disable "Mouse battery low" spam notification on Ubuntu | |
==== | |
https://wrgms.com/disable-mouse-battery-low-spam-notification/ | |
==== | |
Disable "Mouse battery low" spam notification on Ubuntu | |
Blog Logo | |
Gui Ambros on 02 Jun 2019 | |
3 min read | |
I use a Logitech Performance MX wireless mouse, on Ubuntu 18.10 (Cosmic Cuttlefish), with Gnome 3.30.2. This mouse uses regular 1.2V AA NiMH rechargeable battery, which usually last 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 stops working. | |
The worse part is that these notifications won't fade away after a few seconds like you'd expect. And to make it even more infuriating, they show up after a every period of brief inactivity, which means you'll get dozens of notifications per day -- and will need to click on every one of them. | |
I don't really need to be spammed with alerts of low battery for two months before it runs out. Plus, when it runs out, you just need to connect the USB cable. It's not like a printer, that you need to buy ink days in advance. | |
It seems I'm not alone: tons of users have reported the same problem for years (1, 2, 3). | |
It seems that upower developers recognize that the battery % should be ignored, but they still decided to emit warnings on low battery, and Gnome Settings Daemon doesn't offer any granular 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 mice 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 (disclaimer: provided as is; you are responsible for checking the accuracy of the code): | |
# Check which version you're using | |
upower --version | |
# Install dependencies | |
sudo apt install gtk-doc-tools gobject-introspection libgudev-1.0-dev libusb-1.0-0-dev | |
# 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 | |
# | |
pushd . | |
cd src/.libs | |
strip upowerd | |
sudo chown root.root upowerd | |
sudo mv upowerd /usr/lib/upower/upowerd-silent | |
cd /usr/lib/upower | |
sudo mv upowerd upowerd-original | |
sudo ln -s upowerd-silent upowerd | |
popd | |
# Install upower | |
# | |
pushd . | |
cd tools/.libs | |
strip upower | |
sudo chown root.root upower | |
sudo mv upower /usr/bin/upower-silent | |
cd /usr/bin | |
sudo mv upower upower-original | |
sudo ln -s upower-silent upower | |
popd | |
# Restart upowerd | |
# | |
sudo systemctl restart upower | |
# Check the new version you've installed. It's likely different from the one you had originally | |
upower --version | |
Now enjoy your low battery spam-free system :) | |
[ Show comments ] | |
Written by | |
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 02 Jun 2019 | |
Supported by | |
Proudly published with Ghost | |
You should subscribe to my RSS feed. | |
All content copyright wrgms.com © 2020 | |
All rights reserved. | |
Image | |
wrgms.com | |
/dev/random rants about technology, electronics, startups. | |
Back to Overview |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment