Simple Brightness Slider

Window managers, icon programs, widgets, etc.
Post Reply
Message
Author
User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

Simple Brightness Slider

#1 Post by johnywhy »

Update: new streamlined style. Closes on click-away:

Image

Image

Original big version
Stays open until you close it.

Image

both scripts below.

i got tired of using heavy 'Power Manager' background services, when all i wanted was to adjust my screen brightness.

I started by using a simple command to adjust my brightness:

Code: Select all

echo 10000000  > /sys/class/backlight/intel_backlight/brightness
Then i made this lovely brightness slider. Works like a dream. It will auto-scale to the max brightness of your backlight. Small footprint while running, leaves nothing running in the background when you close it.

Will only work if you have the lightweight yad, and if the above command (or something similar) will adjust the brightness on your OS.

To understand the basic function, and to ensure you have yad, try this at a command-line:

Code: Select all

yad --scale --print-partial
Streamline script:

Code: Select all

#!/bin/sh
BrPath='/sys/class/backlight/intel_backlight/'
BrCur=`cat ${BrPath}brightness`
BrMax=`cat ${BrPath}max_brightness`
BrMin=$(( (BrMax + (100 - 1)) / 100))	# 100th max-brightness, rounded up to nearest integer
yad --scale --min-value $BrMin --max-value $BrMax --value $BrCur --print-partial --undecorated - --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --hide-value --close-on-unfocus | while read BrNew 
	do echo "$BrNew" | sudo /usr/bin/tee ${BrPath}brightness
	done
Big-Version script:

Code: Select all

#!/bin/sh
BrPath='/sys/class/backlight/intel_backlight/'
BrCur=`cat ${BrPath}brightness`
BrMax=`cat ${BrPath}max_brightness`
BrMin=$(( (BrMax + (100 - 1)) / 100))	# 100th max-brightness, rounded up to nearest integer
yad --scale --min-value $BrMin --max-value $BrMax --value $BrCur --print-partial --title 'Set brightnessradky's Dpup Stretch 7.5 (RC3)' --width 300 --fixed --sticky --mouse --on-top --escape-ok --button OK --hide-value | while read BrNew 
	do echo "$BrNew" > ${BrPath}brightness 
	done
Explanation of all options:
https://www.mankier.com/1/yad

Now i can remove heavy 'power manager' background services!

Tested on:
StretchDog
Xtahr
radky's Dpup Stretch 7.5 (RC3)
Porteus desktop 32-bit
Linux Mint 19 xfce`

To install:
- Confirm the simple echo command works on your machine. Try various values and see if your brightness changes. But not 0, your screen will go black! Start high-- my machines go up to 12000000+!

Code: Select all

echo 10000000  > /sys/class/backlight/intel_backlight/brightness
- Confirm yad works:

Code: Select all

yad --scale --print-partial
- save the script in a file called set-brightness
- if needed, edit the `BrPath=` line to match your backlight path.
- put the script into /usr/local/bin
- create a launcher on your panel or desktop, which runs the command set-brightness. Since it's in /usr/local/bin, your OS should find it-- no need to enter entire path.

Causes of failure:
- Your backlight path might not be intel. Figure out which backlight path is correct for your machine

Code: Select all

ll /sys/class/backlight/
https://askubuntu.com/a/715310
https://askubuntu.com/questions/437983/ ... which-card

- You don't have backlight. But, as long as there's some command-line way to adjust the brightness of your screen, you can mod this script to use that command.

- You might have an old yad installed, or not installed at all. http://archive.ubuntu.com/ubuntu/pool/universe/y/yad/
- If you're not running as root, you may need to give your user (or all users) write-permissions on the brightness file

Code: Select all

chmod 666 /sys/class/backlight/intel_backlight/brightness

Funny story: i ran this on Mint 19 xfce. First time, Mint crashed :lol: Second time, Mint didn't crash, but you could see the slow-as-molasses performance, and jittery lags in the slider, compared with instantaneous responsiveness on xtahr, DebDog, or Porteus. Go Mint.


Volume slider
check out my alsa volume slider
http://murga-linux.com/puppy/viewtopic.php?t=114237
Attachments
2018-09-05-000720_302x94_scrot.png
Shown running on the awesome StretchDog http://murga-linux.com/puppy/viewtopic.php?p=994600#994600
(7.09 KiB) Downloaded 743 times
Last edited by johnywhy on Sat 08 Sep 2018, 04:00, edited 33 times in total.

Puppyt
Posts: 907
Joined: Fri 09 May 2008, 23:37
Location: Moorooka, Queensland
Contact:

#2 Post by Puppyt »

I really like this, johnywhy! Confirming that your script works very nicely indeed in radky's Dpup Stretch 7.5 (RC3), OOTB.

Any chance of a red tint, perhaps to neatly sideline a similar function served by Redshift GUI and the like? Just thinking... but not seriously, Cheers :)
Search engines for Puppy
[url]http://puppylinux.us/psearch.html[/url]; [url=https://cse.google.com/cse?cx=015995643981050743583%3Aabvzbibgzxo&q=#gsc.tab=0]Google Custom Search[/url]; [url]http://wellminded.net63.net/[/url] others TBA...

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#3 Post by johnywhy »

Puppyt wrote:I really like this, johnywhy! Confirming that your script works very nicely indeed in radky's Dpup Stretch 7.5 (RC3), OOTB.

Any chance of a red tint, perhaps to neatly sideline a similar function served by Redshift GUI and the like? Just thinking... but not seriously, Cheers :)
Sweet!

i won't be doing a redshift tho, i don't like it myself :/
but yeah, i removed redshift cuz it's a ram hog.

THX
Last edited by johnywhy on Thu 06 Sep 2018, 03:43, edited 1 time in total.
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#4 Post by Flash »

Tested in Dell Inspiron 15, model 5570, running Quirky Xerus64 8.6, with this error:

Code: Select all

#Set-brightness
/usr/local/bin/Set-brightness: line 6: syntax error near unexpected token `('
/usr/local/bin/Set-brightness: line 6: `yad --scale --min-value $BrMin --max-value $BrMax --value $BrCur --print-partial --title 'Set brightnessradky's Dpup Stretch 7.5 (RC3)' --width 300 --fixed --sticky --mouse --on-top --escape-ok --button OK --hide-value | while read BrNew'
#

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#5 Post by johnywhy »

Flash wrote:Tested in Dell Inspiron 15, model 5570, running Quirky Xerus64 8.6, with this error:

Code: Select all

/usr/local/bin/Set-brightness: line 6: syntax error near unexpected token `('
sounds like your yad doesn't like parens in the title. Works with parens on my machine. Maybe your yad needs to be updated? I get:

Code: Select all

# apt list yad
yad/testing,now 1:0.38.1 i386 [installed]
If you have a chance, plz try without (RC3) your title. If that works, put the (RC3) back in, and surround the title with double-quotes instead of single-quotes.

THX!
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#6 Post by johnywhy »

new version posted. no buttons or titlebar.

cheers
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#7 Post by MochiMoppel »

@johnywhy: I understand why Flash receives an error and I don't understand why it works for you. Doesn't work for me either.
The single quotes don't match.
-title 'Set brightnessradky's Dpup Stretch 7.5 (RC3)'
The string breaks prematurely after brightnessradky. Either escape the apostrophe or make the title simpler

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#8 Post by johnywhy »

MochiMoppel wrote:@johnywhy: I understand why Flash receives an error and I don't understand why it works for you. Doesn't work for me either.
The single quotes don't match.
-title 'Set brightnessradky's Dpup Stretch 7.5 (RC3)'
The string breaks prematurely after brightnessradky. Either escape the apostrophe or make the title simpler
embarrassed i didn't catch that :oops:

worked for me, cuz i didn't embed an apostrophe, i only tested parens :roll:
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#9 Post by johnywhy »

check out my new alsa volume slider
http://murga-linux.com/puppy/viewtopic.php?t=114237
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#10 Post by johnywhy »

The versions above won't work on arch or other standard linux with root/non-root users, cuz file permissions on the brightness file.

The version below doesn't have permissions problem-- can run as non-root. It uses xbacklight instead of writing directly to the brightness file.

Code: Select all

#!/bin/sh
BrCur=`xbacklight -get`
BrMin=5
yad --close-on-unfocus --scale --min-value $BrMin --max-value 100 --value $BrCur --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --hide-value | while read BrNew 
	do xbacklight -time 0 -set "$BrNew"
	done
Works best if you use page or arrow keys, or click on points along the slider.

You will get very laggy performance if you try to drag the slider. This can prolly be modified for few steps so you don't get the laggyness.
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

enrique
Posts: 595
Joined: Sun 10 Nov 2019, 00:10
Location: Planet Earth

#11 Post by enrique »

Uhm..

There been a few post asking for help due to not functioning default F2 F3 etc. If I knew I could suggest this method as solution. Nice.

User avatar
johnywhy
Posts: 879
Joined: Sat 20 Aug 2011, 14:52

#12 Post by johnywhy »

xbacklight is a real bottleneck, and you can't do continuous slide (at least not on my arch).

The direct filewrite version allows smooth sliding, but permissions on the brightness file block non-root users.

But, you can enable non-roots to use the direct file-write version by creating udev rules.

I created a new file
`/usr/lib/udev/rules.d/98-brightness.rules`

I don't understand how the numbering system works, so i just randomly picked 98.

I put the following rules into the file and rebooted:

Code: Select all

ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", RUN+="/bin/chgrp users /sys/class/backlight/%k/brightness"
ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="intel_backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
Arch recommends putting users into the video group for this, but that's too much admin. I want this for all users, so i just used the users group.

Now i can use the script at the top of this thread, which writes directly to the brightness file. This avoids the xbacklight lagginess. Direct writes give instant response on the slider, and don't have to do any workarounds with step size.

I only wish i could restrict the writes to my brightness script, and disallow writes any other kind of way. Maybe that can be done with udev rules, but i don't know how.

udev rules can be used to permit non-roots to do many root things :)

https://wiki.archlinux.org/index.php/ba ... #Udev_rule

https://superuser.com/a/1393488/112542

https://wiki.archlinux.org/index.php/Udev
[b]Now[/b]: X-Tahr 2.0! StretchDog! DevuanDog!
[b]Tops[/b]: TarhNOP Vlina-R2 Racy
[b]Used[/b]: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
[i]i ♥ Puppy[/i]

Post Reply