You are not logged in.

#1 2010-05-22 08:48:39

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

xbacklight issue

Hello guys,

I try to set my brightness via xbacklight depending on my battery state.

Whenever my laptop is on-line the value 100 should be used. If not it should be set to 0. This should happen dynamically, means also when the laptop is already running and I then change it to off-line, brightness should be set to 0.

I thought about a small extension of my loop in xinitrc, but when I add xbacklight, my laptop becomes quite inresponsable with delays of ~0,5s or so.

Here my .xinitrc

#statusbar
while true
do
    if acpi -a | grep off-line > /dev/null; then
        xbacklight -set 0
        xsetroot -name "Bat. $( acpi -b | awk '{ print $4 " " $5 }' | tr -d ',' ) | $(date +"%a, %b %d %R")"
    else
        xbacklight -set 100
        xsetroot -name "$(date +"%a, %b %d %R")"
    fi
    sleep 1s   
done &

Any ideas?

Offline

#2 2010-05-22 09:07:06

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: xbacklight issue

/etc/acpi/handler.sh

#!/bin/sh
# /etc/acpi/handler.sh
for x in /tmp/.X11-unix/*; do
    DISPLAYNUM=$(echo $x | sed s#/tmp/.X11-unix/X##)
    if [ x"$XAUTHORITY" != x"" ]; then
            export DISPLAY=":$DISPLAYNUM"
    fi
done

set $*

case "$1" in
    ac_adapter)
        case "$2" in
            AC)
                case "$4" in
                    00000000) xbacklight -set 0;;
                    00000001) xbacklight -set 1;;
                esac;;
            *);;
        esac;;
    *);;
esac

I use

BRIGHT=/sys/class/backlight/acpi_video0/brightness
                    *0)    [ $(cat $BRIGHT) != 4 ] && echo 4 > $BRIGHT;;
                    *1)    [ $(cat $BRIGHT) != 8 ] && echo 8 > $BRIGHT;;

Regards,
demian


no place like /home
github

Offline

#3 2010-05-22 09:12:39

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: xbacklight issue

Hello demian,

thanks for your solution. What exactly do I have to do?

Creating handler.sh and then?

Where do I put the code BRIGHT=[...]?

Regards

Offline

#4 2010-05-22 09:45:16

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: xbacklight issue

handler.sh is part of acpid, a very useful application for laptops that that traps acpi events and associates actions to them.

So, install acpid from the official repos. acpid already comes with all the files you need. you only have to adjust /etc/acpi/handler.sh like i posted.

The BRIGHT part goes into the handler.sh too, it's just an alternative to xbacklight if you have the file /sys/class/backlight/acpi_video0/brightness.
I guess it's preferable because it works without X. Maybe xbacklight does too, i don't know.

Regards,
demian

Last edited by demian (2010-05-22 09:45:59)


no place like /home
github

Offline

#5 2010-05-22 10:07:18

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: xbacklight issue

Ah I see. So the acpid daemon is for task like this the preferable way. Allright I'll have a look into this but I still don't understand why my loop seems to be such unefficient. I mean it only checks whether it is on-line or not and then runs xbacklight.

Offline

#6 2010-05-22 10:32:38

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: xbacklight issue

orschiro wrote:

but I still don't understand why my loop seems to be such unefficient.

Nobody said it was.
But didn't you say yourself that your laptop becomes less responsive when having that loop in the background?
acpid gives you the ability to execute actions when you open/close the lid, plug/unplug battery/ac, press buttons and use switches as long as there's an according acpi event. i'd say that makes it very valuable to any laptop user. no need to reinvent it.

//edit: sorry, seem to have misunderstood you there.

Last edited by demian (2010-05-22 10:34:39)


no place like /home
github

Offline

#7 2010-05-22 10:59:05

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: xbacklight issue

I made a small extension to my loop. Obviously it costs too much performance running xbacklight every second. It's working fine now but nevertheless thanks for your suggestion on acpid. smile

#variables for xbacklight changes
i = 0
j = 0

#set statusbar and xbacklight
while true
do
    if acpi -a | grep off-line > /dev/null; then
        if [ i = 0 ]; then
           xbacklight -set 0
           i = 1
           j = 0
        fi
        xsetroot -name "Bat. $( acpi -b | awk '{ print $4 " " $5 }' | tr -d ',' ) | $(date +"%a, %b %d %R")"
    else
        if [ j = 0 ]; then
           xbacklight -set 100
           j = 1
           i = 0
        fi
        xsetroot -name "$(date +"%a, %b %d %R")"
    fi
    sleep 1s   
done &

Last edited by orschiro (2010-05-22 21:52:51)

Offline

Board footer

Powered by FluxBB