by Naac · 6y ago · 0 comments
It's a curation of several tools combined with i3 that gives a pretty fantastic gnome/i3 experience. Similar to spacemacs and emacs.
I managed to golf some tiny generic inline bash scripts that fit directly inside my i3 config for screen brightness and keyboard brightness using /sys/class with generic name matching and no hardcoded values. They do require an external sudoers entry for each /sys/class unfortunately but that's because they require root perms by default.
These have served me well across multiple desktops and laptops without needing to customization for each piece of hardware.
I can post if any interest...
In your i3config for screen and keyboard...
bindsym XF86MonBrightnessDown exec "sys='/sys/class/backlight/*backlight';\
bri=$(cat ${sys}/bri*); max=$(cat ${sys}/max*);\
val=$(($bri - $max / 32)); val=$(($val < 0 ? 0 : $val));\
echo $val | sudo tee ${sys}/bri*;"
bindsym XF86MonBrightnessUp exec "sys='/sys/class/backlight/*backlight';\
bri=$(cat ${sys}/bri*); max=$(cat ${sys}/max*);\
val=$(($bri + $max / 32)); val=$(($val > $max ? $max : $val));\
echo $val | sudo tee ${sys}/bri*;"
bindsym XF86KbdBrightnessDown exec "sys='/sys/class/leds/*backlight';\
bri=$(cat ${sys}/bri*); max=$(cat ${sys}/max*);\
val=$(($bri - $max / 32)); val=$(($val < 0 ? 0 : $val));\
echo $val | sudo tee ${sys}/bri*;"
bindsym XF86KbdBrightnessUp exec "sys='/sys/class/leds/*backlight';\
bri=$(cat ${sys}/bri*); max=$(cat ${sys}/max*);\
val=$(($bri + $max / 32)); val=$(($val > $max ? $max : $val));\
echo $val | sudo tee ${sys}/bri*;"
The only annoying things is that you will need to add NOPASSWD sudoers entries separately for: /usr/bin/tee /sys/class/backlight/*/brightness
and /usr/bin/tee /sys/class/leds/*/brightness
These are the only complex part of my i3config, it might seem a bit lengthy compared to installing xbacklight but for me that tool could only ever fake it by changing the pixels rather than the backlight (on every piece of hardware I have tried).The nice thing about scripting /sys/class directly is that other than the permissions it is self contained and you can easily adapt above to any other stuff it presents on your particular piece of hardware.
The value 32 is the number of divisions over the range, so it should be consistent across different hardware, but you may want to adjust it to taste still.
... awaiting more golfing like a sed oneliner :P i wrote this quite a long time ago.
I'm curious - I've done it both ways, scripting /sys/class and using xbacklight. On my X230 I used xbacklight, and it seemed to work fine. How would I tell if it wasn't changing the backlight itself? I'd rather use /sys/class to get it right.
Also, here's my /sys/class code - not sure where I got it, but I probably adapted something I found. I assume it works, but it's been commented out above the xbacklight version for some time. :)
bindsym XF86MonBrightnessDown exec bctl="/sys/class/backlight/intel_backlight/brightness" && echo $((`cat $bctl`-68)) | tee $bctl
bindsym XF86MonBrightnessUp exec bctl="/sys/class/backlight/intel_backlight/brightness" && echo $((`cat $bctl`+68)) | tee $bctl bindsym XF86MonBrightnessDown exec "xbacklight -dec 10"
bindsym XF86MonBrightnessUp exec "xbacklight -inc 10"Also, is this really only for Ubuntu?
Yes.
>> Or do I have to install it as a completely separate DM?
I'm not sure what you mean. The Ubuntu package provided lets you select this desktop from the login screen ( as opposed to i3, Plasma, or Gnome ). This is essentially a new Desktop Environment, made up of gnome and i3.
>> Also, is this really only for Ubuntu?
Unfortunately yes. I've tried looking at packaging this for Arch Linux, but it looks like quite a bit of dependencies are forked ( i3blocks is now i3xrocks ). Not everything is pushed upstream. Getting this to work on non-ubuntu based distributions looks tricky if you're not familiar with packaging already.