(OLD) (ARCHIVED) Puppy Linux Discussion Forum Forum Index (OLD) (ARCHIVED) Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info

This forum can also be accessed as http://oldforum.puppylinux.com
It is now read-only and serves only as archives.

Please register over the NEW forum
https://forum.puppylinux.com
and continue your work there. Thank you.

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups    
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 26 Sep 2020, 23:11
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
Simple Brightness Slider
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. View previous topic :: View next topic
Page 1 of 1 [12 Posts]  
Author Message
johnywhy


Joined: 20 Aug 2011
Posts: 890

PostPosted: Wed 05 Sep 2018, 03:18    Post subject:  Simple Brightness Slider
Subject description: For sys/class/backlight
 

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





Original big version
Stays open until you close it.



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:
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:
yad --scale --print-partial


Streamline script:
Code:
#!/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:

#!/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:
echo 10000000  > /sys/class/backlight/intel_backlight/brightness

- Confirm yad works:
Code:
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:
ll /sys/class/backlight/

https://askubuntu.com/a/715310
https://askubuntu.com/questions/437983/how-to-find-backlight-is-managed-by-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:
chmod 666 /sys/class/backlight/intel_backlight/brightness



Funny story: i ran this on Mint 19 xfce. First time, Mint crashed Laughing 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
2018-09-05-000720_302x94_scrot.png
 Description   Shown running on the awesome StretchDog http://murga-linux.com/puppy/viewtopic.php?p=994600#994600
 Filesize   7.09 KB
 Viewed   788 Time(s)

2018-09-05-000720_302x94_scrot.png


Last edited by johnywhy on Sat 08 Sep 2018, 00:00; edited 33 times in total
Back to top
View user's profile Send private message 
Puppyt

Joined: 09 May 2008
Posts: 908
Location: Moorooka, Queensland

PostPosted: Wed 05 Sep 2018, 08:18    Post subject:  

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 Smile

_________________
Search engines for Puppy
http://puppylinux.us/psearch.html; Google Custom Search; http://wellminded.net63.net/ others TBA...
Back to top
View user's profile Send private message Visit poster's website 
johnywhy


Joined: 20 Aug 2011
Posts: 890

PostPosted: Wed 05 Sep 2018, 08:27    Post subject:  

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 Smile


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

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

Last edited by johnywhy on Wed 05 Sep 2018, 23:43; edited 1 time in total
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 13653
Location: Arizona USA

PostPosted: Wed 05 Sep 2018, 16:09    Post subject:  

Tested in Dell Inspiron 15, model 5570, running Quirky Xerus64 8.6, with this error:
Code:
#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'
#
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 890

PostPosted: Wed 05 Sep 2018, 16:27    Post subject:  

Flash wrote:
Tested in Dell Inspiron 15, model 5570, running Quirky Xerus64 8.6, with this error:
Code:
/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:
# 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!

_________________
Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 890

PostPosted: Fri 07 Sep 2018, 22:07    Post subject:  

new version posted. no buttons or titlebar.

cheers

_________________
Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 2084
Location: Japan

PostPosted: Fri 07 Sep 2018, 23:03    Post subject:  

@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
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 890

PostPosted: Fri 07 Sep 2018, 23:37    Post subject:  

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 Embarassed

worked for me, cuz i didn't embed an apostrophe, i only tested parens Rolling Eyes

_________________
Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 890

PostPosted: Fri 07 Sep 2018, 23:47    Post subject:  

check out my new alsa volume slider
http://murga-linux.com/puppy/viewtopic.php?t=114237

_________________
Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 890

PostPosted: Sun 24 May 2020, 01:43    Post subject:  

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:
#!/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.

_________________
Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Back to top
View user's profile Send private message 
enrique

Joined: 09 Nov 2019
Posts: 601
Location: Planet Earth

PostPosted: Sun 24 May 2020, 04:28    Post subject:  

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.
Back to top
View user's profile Send private message 
johnywhy


Joined: 20 Aug 2011
Posts: 890

PostPosted: Thu 28 May 2020, 18:26    Post subject:  

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:
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 Smile

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

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

https://wiki.archlinux.org/index.php/Udev

_________________
Now: X-Tahr 2.0! StretchDog! DevuanDog!
Tops: TarhNOP Vlina-R2 Racy
Used: Puppeee Precise Lucid Wary Tahrpup Quirky Slacko MacPup Saluki Puppy Studio LxPupTarh Lina-Lite Lina
i ♥ Puppy
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [12 Posts]  
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Desktop
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0964s ][ Queries: 13 (0.0448s) ][ GZIP on ]