Wireless mouse battery status
calendar June 9, 2016   category  scripting , gnome-shell   comments  comments


I have a trackball by Logitech and it's super awesome. Well, almost. The previous incarnation was a Logitech Trackman Wheel which used a cord and was my preferred pointing device. It never suffered from the "oops my battery is dead and now I have to replace it" problem, it felt great and Just Works.

Until, one day, it didn't anymore :(

I tried everything, even opened up the device and tried to find the issue. Couldn't find it so I set to find a replacement. I quickly discovered that my beloved trackball was no longer sold and was actually rapidly becoming a collecter's item. On Amazon I could purchase a new one for $300!!  What the ....

Having no desire to come up with that kind of money for a trackball, I bought the next best thing: the wireless variant of the Trackman. I did replace the blue ball for the oriinal red one, for nostalgic reasons, but still the battery problem existed.

So to keep track of how the battery is doing, I installed a nifty utility called Solaar. It's available in the Fedora repository, and I imagine Ubuntu's too, so installing it is a breeze. Launching it quickly reveals that yes, it found my trackball, but didn't have rights to it. And it was correct:

 

porcaria ~ # ls -l /dev/hidraw0 
crw-------. 1 root root 248, 0 Jun  9 09:04 /dev/hidraw0

 

Since it's in /dev you can't simply do a chmod and expect it to persist. And running it as root seems rather silly. So what to do then?

Enter udev. Reading the excellent guide here I came up with the following snippet, which I've placed in /etc/udev/rules.d/10-wireless-mouse.conf :

 

KERNEL=="hidraw0", NAME="hidraw0", OWNER="leon"

 

This ensures that I am also the owner of the file. Now, reload the udev daemon:

 

porcaria ~ # udevadm control --reload 

 

Take out the wireless receiver thingie and plug it back in. Let's look at the file now:

 

porcaria ~ # ls -l /dev/hidraw0
crw-rw----+ 1 root root 248, 0 Jun  9 11:52 /dev/hidraw0

 

Still root? But look, there's a plus sign now next to the usual rights, and the group permissions seem to have changed from nothing to read+write. The plus sign indicates extra permissions and in this case an ACL. Reading the ACL is easy:

 

porcaria ~ # getfacl /dev/hidraw0
getfacl: Removing leading '/' from absolute path names
# file: dev/hidraw0
# owner: root
# group: root
user::rw-
user:leon:rw-
group::---
mask::rw-
other::---

There we go! And indeed, now after executing Solaar again, it no longer complains. So now you can add it to your start-up programs, using gnome-tweak-tool.

 



Share: