You are not logged in.
Pages: 1
Performance is weird-- on arch xfce, a slider app i made responds fast if i click on points on the slider, but extremely laggy if i try to drag the slider. Maybe there's a way to tell yad "don't update until i stop dragging", but fast response is preferable. Maybe the problem is my script or the OS.
Here's the script:
#!/bin/sh
BrPath='/sys/class/backlight/intel_backlight/' # may need to change this for your backlight
BrCur=`cat ${BrPath}brightness`
BrMax=`cat ${BrPath}max_brightness`
BrMin=$(( (BrMax + (100 - 1)) / 100)) # 100th max-brightness, rounded up to nearest integer
yad --close-on-unfocus --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 | while read BrNew
do echo "$BrNew" > ${BrPath}brightness
done
Last edited by johnywhy (2020-05-28 20:21:01)
arch xfce x86_64
Offline
By default, I believe yad uses step sizes of 1. If your max_brightness value is large, that would be numerous brightness value file writes that your script would trigger in even a small slide, which might cause the lag. Perhaps using the "--step=" parameter (and some calculations to have at max 10 or 20 steps from min to max) might help cut down on the number of these writes.
Out of curiosity, how have you set up user access to the restricted brightness file?
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
so, to fix my problem, i'd need to make the slider somehow skip all the in-between values while i'm sliding, and only update when i stop sliding. Not sure how. If i want to get fancy, skip more in-betweens the faster i drag.
well, i could reduce the number of steps on the slider, and then multiply up to get the values needed for the brightness command. Seems that would work, but would be nice to get full resolution
i put the file into /usr/local/bin/
here are the permissions
[Edit 1]
Oh, you asked about permissions on the brightness file. Indeed, a non-root user cannot write to it. Here's the command in the xfce launcher:
/usr/local/bin/set-xbrightness.sh
i can't recall how i did it Maybe, since the slider-script is owned by root, it executes as root? Note, i am not running sudo on this OS. I think just by the script living in /usr/local/bin, it can do root things. Here's are the directory permissions:
[Edit 2]
My apologies, i'm running a different script. Looks like this:
#!/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
Maybe that -time thing is the problem Why did i do that (as if you would know). And how am i getting it to scale correctly? (as if you would know
$ cat /sys/class/backlight/intel_backlight/max_brightness
12750000
$ xbacklight -get
63.000000
Ok, i get it. I changed my script to use xbacklight, instead of writing to the brightness file. Either xbacklight, or the `time` thing are the source of the lag.
i used xbacklight to enable non-root user to execute. That answers both our questions, laggy and permissions.
Last edited by johnywhy (2020-05-24 05:23:31)
arch xfce x86_64
Offline
Good that xbacklight is working - that's probably the best way.
With respect to my suggestion of using the "--scale" parameter... With a max_brightness of 12750000 (12 million steps !!! - wow), if you added:
--scale=637500
...to the yad command, it would still give you 20 steps of brightness between the min and the max values and would cut down on the number of file writes.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
if you added:
--scale=637500
...to the yad command, it would still give you 20 steps of brightness between the min and the max values and would cut down on the number of file writes.
Thx, tried it, still very laggy. Seems xbacklight is the bottleneck.
Other option is to use my original script direct writes to the brightness file, and give non-root users write permissions on the file.
Do you know another workaround to give non-root users write-access only through that script? Maybe setuid?
https://www.baeldung.com/linux/advanced … ermissions
i tried this
# chmod u+s set-brightness.sh
# ls -l
-rwsr-xr-x 1 root root 540 May 23 22:20 set-brightness.sh
but still getting permissions error when non-root runs the script.
/usr/local/bin/set-brightness.sh: line 8: /sys/class/backlight/intel_backlight/brightness: Permission denied
thx
Last edited by johnywhy (2020-05-24 19:22:03)
arch xfce x86_64
Offline
Other option is to use my original script direct writes to the brightness file, and give non-root users write permissions on the file.
Do you know another workaround to give non-root users write-access only through that script? Maybe setuid?
I think you can add the command to the sudoers file using visudo:
Enable explicitly defined commands only for user USER_NAME on host HOST_NAME:
USER_NAME HOST_NAME=/usr/bin/halt,/usr/bin/poweroff,/usr/bin/reboot,/usr/bin/pacman -Syu
from: https://wiki.archlinux.org/index.php/Sudo#Using_visudo
Offline
you can add the command to the sudoers file
Thx but i don't run sudo on this machine.
Would be great if setuid can work.
thx
arch xfce x86_64
Offline
Thx but i don't run sudo on this machine.
Would be great if setuid can work.
Ah! Did it work with setuid? The other alternative I see in my searches is "File Capabilities" (also here).
Good luck!
Offline
Good that xbacklight is working - that's probably the best way.
With respect to my suggestion of using the "--scale" parameter... With a max_brightness of 12750000 (12 million steps !!! - wow), if you added:
--scale=637500
...to the yad command, it would still give you 20 steps of brightness between the min and the max values and would cut down on the number of file writes.
Sorry, I was wrong. It should have said "--step" but it doesn't work.
Give this script a try. It breaks down the reads into increments (steps - initially set at 20) and only writes to the file when the group of values enters the previous or next group. It should cut down the number of file writes and hopefully the laginess:
#!/bin/bash
STEPS=20
BRPATH='/sys/class/backlight/intel_backlight/'
BRMAX="$(cat ${BRPATH}max_brightness)"
BRMIN=0
BRCUR="$(cat ${BRPATH}brightness)"
BRSTEP=$(( $BRMAX / $STEPS))
BRSTEPCUR=$(( $BRCUR / $BRSTEP ))
yad --close-on-unfocus --scale --min-value $BRMIN --max-value $STEPS --value $BRSTEPCUR --print-partial --undecorated --width 300 --fixed --sticky --mouse --on-top --escape-ok --no-buttons --hide-value | while read BrNew
do
if [ "$BrOld" != "$BrNew" ]; then
echo "$(( $BrNew * $BRSTEP ))" > ${BRPATH}brightness
BrOld=$BrNew
fi
done
exit 0
For testing purposes, you can set the permissions on the /sys/class/backlight/intel_backlight/brightness with root privileges to 666:
chmod 666 /sys/class/backlight/intel_backlight/brightness
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
Give this script a try.
Wow, thx for doing that! Is the `if` statement really needed? Won't that only be true if the scroller doesn't move? I think yad won't run the code if the scroller doesn't move.
For testing purposes, you can set the permissions on the /sys/class/backlight/intel_backlight/brightness with root privileges to 666:
chmod 666 /sys/class/backlight/intel_backlight/brightness
Thx! But i think the idea is to apply your coarse steps to the xbacklight version, so that we don't have to touch permissions on the brightness file, right?
If performance of the xbacklight version is still laggy with your awesome code, then i'd like to figure out how to use setuid. I'd like to learn to use setuid iac.
I've looked at File Capabilities in the past, and could never figure what's the right cap for this purpose. Not even clear setcap can help, because i think setcap simply allows a nonroot to execute protected executables. We want to impersonate root on my .sh, right?
thx!
Last edited by johnywhy (2020-05-25 02:21:24)
arch xfce x86_64
Offline
ToZ wrote:Give this script a try.
Wow, thx for doing that! Is the `if` statement really needed? Won't that only be true if the scroller doesn't move?
yad reports movements in increments of 1. With such a large variation of brightness steps, you will have numerous file writes:
echo 1 > brightness
echo 2 > brightness
echo 3 > brightness
...
...with minimal on-screen difference. I believe this is what is causing the lag. So this code basically breaks up your brightness range into 20 steps and only writes to the file if the value is in a new band. For example (something like):
echo 1 > brightness
echo 16050 > brightness
echo 40300 > brightnes
...
...it saves on the actual number of writes by only writing once in a while (meaning there are 20 steps of brightness changes between min_brightness and max_brightness).
For testing purposes, you can set the permissions on the /sys/class/backlight/intel_backlight/brightness with root privileges to 666:
chmod 666 /sys/class/backlight/intel_backlight/brightness
Thx! But i think the idea is to apply your coarse steps to the xbacklight version, so that we don't have to touch permissions on the brightness file, right?
Absolutely, if xbacklight works better then by all means use it. I was really focused on trying to improve your original script to see if I could remove the lag.
Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline
I was really focused on trying to improve your original script to see if I could remove the lag.
Thx for that, but the lag is in the xbacklight version. Sorry for messing up my explanation of that. My fault for posting the wrong script up top.
The direct writes version doesn't have the lag problem.
arch xfce x86_64
Offline
Resolved. It possible to allow non-root users to write to the brightness file, without changing permissions on the file.
It's done with a udev rule. 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:
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, without allowing 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
Last edited by johnywhy (2020-05-29 03:14:37)
arch xfce x86_64
Offline
Pages: 1
[ Generated in 0.012 seconds, 8 queries executed - Memory usage: 610.42 KiB (Peak: 627.27 KiB) ]