Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] xbacklight no function
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware
View previous topic :: View next topic  
Author Message
DerPreis
n00b
n00b


Joined: 30 Jul 2018
Posts: 16

PostPosted: Thu Aug 30, 2018 6:31 pm    Post subject: [solved] xbacklight no function Reply with quote

Hello,

I can't get xbacklight to work. If I use something like
Code:
xbacklight -dec -20


there is no function and no error.

I have an Optimus Laptop. It is possible to change the backlight brightness with

Code:
 echo xxx > /sys/class/backlight/intel_backlight/brightness


Have someone a solution for this?


Last edited by DerPreis on Fri Aug 31, 2018 11:19 pm; edited 1 time in total
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6098
Location: Dallas area

PostPosted: Thu Aug 30, 2018 6:34 pm    Post subject: Reply with quote

Does the optimus have a function key for adjusting brightness?
_________________
PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland
Back to top
View user's profile Send private message
DerPreis
n00b
n00b


Joined: 30 Jul 2018
Posts: 16

PostPosted: Thu Aug 30, 2018 6:42 pm    Post subject: Reply with quote

Yes its FN+F11/F12. But they shouldn't be mapped yet, because I use i3 as windows manager without a desktop enviroment and have to map the keys myself
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6098
Location: Dallas area

PostPosted: Thu Aug 30, 2018 7:04 pm    Post subject: Reply with quote

I saw something while googling brightness and it reference using acpi so I modified the acpi script /etc/acpi/default.sh

under cd) I added
Code:


        video)
                case $action in
                        displayoff) :;;
                        brightnessdown)
                                    max=$(cat /sys/class/backlight/intel_backlight/max_brightness)
                                    curr=$(cat /sys/class/backlight/intel_backlight/actual_brightness)
                                    div=$((max / 10))
                                    next=$((curr-div))
                                    if [ $next -gt 0 ];
                                    then
                                        curr=$next
                                    else
                                        curr=0
                                    fi
                                    echo $curr  > /sys/class/backlight/intel_backlight/brightness
                                    ;;
                        brightnessup)
                                    max=$(cat /sys/class/backlight/intel_backlight/max_brightness)
                                    curr=$(cat /sys/class/backlight/intel_backlight/actual_brightness)
                                    div=$((max / 10))
                                    next=$((curr+div))
                                    if [ $next -lt $max ];
                                    then
                                        curr=$next
                                    else
                                        curr=$max
                                    fi
                                    echo $curr  > /sys/class/backlight/intel_backlight/brightness
                                    ;;
                        *) uhd $*;;
                esac
                ;;

It allowed my function keys to work perfectly.

Edit to add: I guess you could make a script to just write values to the /sys/*/brightness file but I like using the function keys, values are between 0 and 100.
Using acpi it even works from the console.
_________________
PRIME x570-pro, 3700x, 6.1 zen kernel
gcc 13, profile 17.0 (custom bare multilib), openrc, wayland
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Aug 30, 2018 8:49 pm    Post subject: Reply with quote

DerPreis ...

like the example posted by Anon-E-moose ... though without cluttering up 'default.sh', and the UUoC ;)

/etc/acpi/actions/backlight.sh:
#!/bin/sh
set -e

backlight_sys_dir="/sys/class/backlight/intel_backlight"

read -r max_brightness < "${backlight_sys_dir}/max_brightness"
read -r curr_brightness < "${backlight_sys_dir}/brightness"

case "$1" in
      up) increment="+ 10" ;;
    down) increment="- 10" ;;
       *) exit 1 ;;
esac

new_brightness=$(($curr_brightness $increment))

if $((new_brightness < 1)) || $((new_brightness > $max_brightness)); then
    exit 1
else
    echo "$new_brightness" > ${backlight_sys_dir}/brightness
fi

You would then call 'backlight.sh' via 'default.sh' for 'brightnessup' and 'brightnessdown' (which 'acpi_listen' should show correspond to your brightness keys).

/etc/acpi/default.sh:
case "$group" in
[...]
  video)
    case "$action" in
      brightnessup) /etc/acpi/actions/backlight.sh up ;;
      brightnessdown) /etc/acpi/actions/backlight.sh down ;;
      *) log_unhandled $* ;;
    esac ;;

HTH & best ... khay
Back to top
View user's profile Send private message
DerPreis
n00b
n00b


Joined: 30 Jul 2018
Posts: 16

PostPosted: Fri Aug 31, 2018 4:43 pm    Post subject: Reply with quote

First of all thanks for the help. I particually understand the magic of acpi now...

At the moment state my FN+Brightnessdown is working. The FN+Brightnessup won't. I don't understand why.

I have mapped the backlight.sh up/down script in i3 to Alt+F11/F12 and its working there.

I tried to change the default.sh to only brightess up but it still only changes the brightness down... strange...

these are my files...

/etc/acpi/default.sh
Code:
#!/bin/sh
# /etc/acpi/default.sh
# Default acpi script that takes an entry for all actions

set $*

group=${1%%/*}
action=${1#*/}
device=$2
id=$3
value=$4

log_unhandled() {
   logger "ACPI event unhandled: $*"
}

case "$group" in
   button)
      case "$action" in
         power)
            /etc/acpi/actions/powerbtn.sh
            ;;

         # if your laptop doesnt turn on/off the display via hardware
         # switch and instead just generates an acpi event, you can force
         # X to turn off the display via dpms.  note you will have to run
         # 'xhost +local:0' so root can access the X DISPLAY.
         #lid)
         #   xset dpms force off
         #   ;;

         *)   log_unhandled $* ;;
   video)
      case "$action" in
         brightnessup) /etc/acpi/actions/backlight.sh up ;;
         brightnessdown) /etc/acpi/actions/backlight.sh down ;;
         *)   log_unhandled $* ;;
      esac
      ;;

   ac_adapter)
      case "$value" in
         # Add code here to handle when the system is unplugged
         # (maybe change cpu scaling to powersave mode).  For
         # multicore systems, make sure you set powersave mode
         # for each core!
         #*0)
         #   cpufreq-set -g powersave
         #   ;;

         # Add code here to handle when the system is plugged in
         # (maybe change cpu scaling to performance mode).  For
         # multicore systems, make sure you set performance mode
         # for each core!
         #*1)
         #   cpufreq-set -g performance
         #   ;;

         *)   log_unhandled $* ;;
      esac
      ;;

   *)   log_unhandled $* ;;
esac


/etc/acpi/actions/backlight.sh
Code:
#!/bin/sh

set -e

backlight_sys_dir="/sys/class/backlight/intel_backlight"

read -r max_brightness < "${backlight_sys_dir}/max_brightness"
read -r curr_brightness < "${backlight_sys_dir}/brightness"

echo $max_brightness, $curr_brightness

case "$1" in
   up) increment="+ 375" ;;
   down) increment="- 375" ;;
   *) exit 1 ;;
esac

new_brightness=$(($curr_brightness $increment))

if (($new_brightness < 1)) || (($new_brightness > $max_brightness)); then
   exit 1
else
   echo "$new_brightness" > ${backlight_sys_dir}/brightness
fi


acpi_listen
Code:
video/brightnessup BRTUP 00000086 00000000
video/brightnessdown BRTDN 00000087 00000000


I changed the value in brightness to 375 cause of the max of 7500...
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Fri Aug 31, 2018 9:30 pm    Post subject: Reply with quote

DerPreis ... you're missing a closing 'esac' for the 'case $action in power)', it should be:

Code:
case "$group" in
  button)
    case "$action" in
      power) /etc/acpi/actions/powerbtn.sh ;;
      *) log_unhandled $* ;;
    esac ;;
  video)
    case "$action" in
      brightnessup) /etc/acpi/actions/backlight.sh up ;;
      brightnessdown) /etc/acpi/actions/backlight.sh down ;;
      *) log_unhandled $* ;;
    esac ;;

If correcting that doesn't resolve the issue then post the output of the following:

Code:
# find /sys/class/backlight/intel_backlight -maxdepth 1 -type f -print -exec cat {} \;
# ls -l /etc/acpi/actions/

Also note that "echo $max_brightness, $curr_brightness" is wasted, there is no TTY for that output, if you want that to go somewhere then you will need to use 'logger', eg:

Code:
logger "ACPI backlight: max_brightness: $max_brightness, curr_brightness: $curr_brightness"

best ... khay
Back to top
View user's profile Send private message
DerPreis
n00b
n00b


Joined: 30 Jul 2018
Posts: 16

PostPosted: Fri Aug 31, 2018 11:19 pm    Post subject: Reply with quote

Awesome! It works now!

The missing "esac" was the mistake... the echo [..] was only for testing and is deleted now!

Thank you very much for this lesson, I definitely learned something!
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Sat Sep 01, 2018 12:06 pm    Post subject: Reply with quote

DerPreis wrote:
Awesome! It works now!

DerPreis ... ok, good. You might also want to add the following under 'button)'

/etc/acpi/default.sh:
mute) /usr/bin/amixer -q set Master toggle ;;
volumeup) /usr/bin/amixer -q set Master 2dB+ unmute ;;
volumedown) /usr/bin/amixer -q set Master 2dB- unmute ;;

DerPreis wrote:
Thank you very much for this lesson, I definitely learned something!

You're welcome & best ... khay
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Kernel & Hardware All times are GMT
Page 1 of 1

 
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