LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Brightness control not working. (https://www.linuxquestions.org/questions/slackware-14/brightness-control-not-working-4175433486/)

Ipe 10-22-2012 08:15 AM

Brightness control not working.
 
I'm a Slackware newbie. I install Slackware 14 x64 on a Toshiba L750 laptop. Screen is too bright, can't change it using brightness control (on panel). I'm using KDE.

dr.s 10-22-2012 09:06 AM

You should be able to change it in KDE using main menu --> System Settings --> Power Management, or if laptop is running on battery you'll see a battery icon in the lower right hand corner, click on it and use the Screen Brightness slider
or you can try this from the console (as root), first 2 commands display the max brightness and brightness levels on my machine, last command sets it to a new value.
Quote:

cat /sys/class/backlight/intel_backlight/max_brightness
4882

cat /sys/class/backlight/intel_backlight/brightness
1416

echo 2000 > /sys/class/backlight/intel_backlight/brightness

DrCube 10-22-2012 01:02 PM

Can I piggyback on this question?

Basically, I want to do the same thing in i3wm. I can make keyboard shortcuts in .i3/config, but I don't know what program to call from there. Also, I'd like some indicator of what the current brightness level is in i3bar.

Thanks.

Ipe 10-22-2012 05:52 PM

the console command works. thank you dr.s!
But how could i make my setting permanent or default?
i wonder why the Screen Brightness slider in power management
or in the battery monitor not working.

DrCube 10-26-2012 07:44 AM

Quote:

Originally Posted by DrCube (Post 4812355)
Can I piggyback on this question?

Basically, I want to do the same thing in i3wm. I can make keyboard shortcuts in .i3/config, but I don't know what program to call from there. Also, I'd like some indicator of what the current brightness level is in i3bar.

Thanks.

Here's what I did: First, I read the thread. I originally skimmed over Dr.S's post because I saw "KDE menu" and thought it didn't apply to me. But he basically told me what to do. Only my computer uses "acpi_video0/brightness" between 1-8 rather than "intel_backlight/brightness" between 0 and 4882.

So, I wrote two scripts, bright_up and bright_down:

bright_up
Code:

#! /bin/bash

max_brightness=$(cat /sys/class/backlight/acpi_video0/max_brightness)
brightness=$(cat /sys/class/backlight/acpi_video0/brightness)

if (($brightness<$max_brightness))
then
    let brightness=$brightness+1

fi

echo $brightness > /sys/class/backlight/acpi_video0/brightness

bright_down
Code:

#! /bin/bash

max_brightness=$(cat /sys/class/backlight/acpi_video0/max_brightness)
brightness=$(cat /sys/class/backlight/acpi_video0/brightness)

if (($brightness>0))
then
    let brightness=$brightness-1

fi

echo $brightness > /sys/class/backlight/acpi_video0/brightness

Then, chmod +x both of those files, and put the following in my .i3/config:

Code:

# Brightness control
bindsym $mod+F9 exec /home/drcube/.i3/bright_up
bindsym $mod+F8 exec /home/drcube/.i3/bright_down

The thing is, my brightness function keys don't work. I need the System 76 driver, and I haven't figured out how to port that over from Ubuntu yet. So, I just used mod+the function keys that should control brightness.

Finally, root owns that brightness file (/sys/class/backlight/acpi_video0/brightness), and you can't chown permanently because the file gets rebuilt every time you boot. So, I put this in my /etc/rc.d/rc.local:

Code:

chown <user>:users /sys/class/backlight/acpi_video0/brightness
where <user> is me.

I still haven't figured out how to indicate the brightness level in i3bar. And I know this is probably way too much info for what I actually did, but hopefully the next person can google this and get up and running pretty fast. I tried to lay it all out there.

Mark Pettit 10-26-2012 08:40 AM

@DrCube: I think chowning that device to your user is probably not a good idea. Please read up on the "sudo" command, and add the appropriate entries in the /etc/sudoers.conf file.

DrCube 10-26-2012 10:10 AM

Quote:

Originally Posted by Mark Pettit (Post 4815458)
@DrCube: I think chowning that device to your user is probably not a good idea. Please read up on the "sudo" command, and add the appropriate entries in the /etc/sudoers.conf file.

Please fight my ignorance here, because I don't see how this would work. Can I really use sudo to allow a single program (i3) the ability to edit a single root-owned file (/sys/class/backlight/acpi_video0/brightness)? Without needing a password?

I'm not saying you're wrong, I'm just saying:

1) I don't know how to do it with sudo, and
b) even if I could, it seems more dangerous to elevate i3's privileges than for a user to take ownership of a single, fairly harmless, file.

I don't want my window manager to have any extra privileges that I as a user don't have, except the ability to write to /sys/class/backlight/acpi_video0/brightness.

markush 10-26-2012 01:28 PM

Hi,

this thread inspired me to find out how I can control the backlight on my Samsung laptop. The function-keys for the backlight don't work. Thanks to the posting above I found out that
Code:

echo > "value" /sys/class/backlight/acpi_video0/brightness
really sets the backlight.

I've written the following script
Code:

#!/bin/bash

yet=`cat /sys/class/backlight/acpi_video0/actual_brightness`
max=`cat /sys/class/backlight/acpi_video0/max_brightness`

bl_up() {
    if [ $yet -lt $max ]; then
        let new=$yet+1
        echo $new > /sys/class/backlight/acpi_video0/brightness
    else
        echo "Helligkeit ist schon maximal"
    fi
}

bl_down() {
    if [ $yet -gt 0 ]; then
        let new=$yet-1
        echo $new > /sys/class/backlight/acpi_video0/brightness
    else
        echo "Noch dunkler geht nicht"
    fi
}

case "$1" in
    'h')
        bl_up
        ;;
    'd')
        bl_down
        ;;
    'z')
        echo "aktuelle Helligkeit $yet von $max"
        ;;
    *)
        echo "screen.sh h (heller) | d (dunkler) | z (aktueller Wert)"
esac

which works. But I wanted to configure some keybindings for this. I'm using xmonad as windowmanager. In my ~/.xmonad/xmonad.hs I have added the following two lines:
Code:

,((mod4Mask, xK_Up), spawn "/usr/local/bin/screen.sh h")
 ,((mod4Mask, xK_Down), spawn "/usr/local/bin/screen.sh d")

Now I can set the backlight with <Windows>+<Cursor Up> and <Windows>+<Cursor Down>

Markus

Mark Pettit 10-27-2012 07:13 AM

Quote:

Originally Posted by DrCube (Post 4815531)
Please fight my ignorance here, because I don't see how this would work. Can I really use sudo to allow a single program (i3) the ability to edit a single root-owned file (/sys/class/backlight/acpi_video0/brightness)? Without needing a password?

That is EXACTLY what sudo can be setup to achieve. I'm speaking from memory here, but you can setup the sudoers.conf file to say something like :
Allow userx to run "abc def ghi 123" without a password. You can configure it to ask a password, but in this case it would be unhelpful. The sudoers method is far safer than anything else. I work in a large(ish) Unix environment (Solaris servers), and we use sudo to allow lower level users access to commands that would otherwise require root permissions.

dr.s 10-28-2012 08:36 AM

@DrCube and @markush, thanks for the script samples!

Quote:

Originally Posted by DrCube (Post 4815531)
Please fight my ignorance here, because I don't see how this would work. Can I really use sudo to allow a single program (i3) the ability to edit a single root-owned file (/sys/class/backlight/acpi_video0/brightness)? Without needing a password?

I'm not saying you're wrong, I'm just saying:
1) I don't know how to do it with sudo, and
b) even if I could, it seems more dangerous to elevate i3's privileges than for a user to take ownership of a single, fairly harmless, file.

I don't want my window manager to have any extra privileges that I as a user don't have, except the ability to write to /sys/class/backlight/acpi_video0/brightness.

@DrCube, as suggested in Mark's post, you don't need to chown, use something like the following, it will prompt you for a password:
Code:

su -c "echo $brightness > /sys/class/backlight/acpi_video0/brightness"

dr.s 10-28-2012 08:43 AM

Quote:

Originally Posted by Ipe (Post 4812568)
the console command works. thank you dr.s!
But how could i make my setting permanent or default?
i wonder why the Screen Brightness slider in power management
or in the battery monitor not working.

Not sure about the power management issue on your machine. You can add the command that worked for you to /etc/rc.d/rc.local so it will kick in at startup.

Ipe 10-31-2012 11:01 AM

Thanks dr.s. I think I'm gonna like it here (the forum). You guys are very helpful. It's a nice learning experience.


All times are GMT -5. The time now is 04:08 PM.