# lenovo X230 - ACPI  -Fn+key- brightness control [SOLVED]

## OneNoteMan

EDIT: This is now solved. I wanted to also make note for other x230 owners out there as I know it is popular laptop..

I am running a lenovo thinkpad x230, with the older legendary x220 keyboard, I modded the bios to fix the keymapping, and with gentoo, all the keys and Fn+keys are functioning.

Hi 

I am still fairly new to gentoo and linux in general. 

I have everything up and running the only thing that doesnt work are my fn+keys, and special keys

my keys cannot control volume, brightness,

my laptop:

Lenovo ThinkPad X230, and i am running xmonad on it

when i run acpi_listen, i do get inputs for each keys, so it seems they are registering but not actually doing anything. They are all mismatched from the actual keyboard but its there nonetheless. 

The only special function keys that work are the fn+f5 which toggles on and off the wifi, unfortunately this is the most uesless one out of all of them.

I followed this wiki to a T:

https://wiki.gentoo.org/wiki/ACPI/ThinkPad-special-buttons

Dmesg output:

https://paste.pound-python.org/show/djwn8Q3jvSkZlxdNuxTk/

thinkpad related config options:

https://paste.pound-python.org/show/kuqjUT4jcy4Mgy84PCgQ/Last edited by OneNoteMan on Sat Sep 29, 2018 4:36 pm; edited 1 time in total

----------

## Anon-E-moose

This might help https://forums.gentoo.org/viewtopic-t-1085854-highlight-.html

----------

## OneNoteMan

do I need xbacklight though?

I already have the lenovo ACPI driver, its just not functioning properly

----------

## Anon-E-moose

That thread was more about how to set acpi to recognize things like the fn keys.

----------

## khayyam

 *OneNoteMan wrote:*   

> do I need xbacklight though?

 

OneNoteMan ... no, all you need is a backlight script and inform acpid (via /etc/acpid/default.sh) that it should run this on recieving 'brightnessup' and 'brightnessdown'. The linked post should cover everything, but if you have any questions, ask.

best ... khay

----------

## OneNoteMan

I tried to modify the script but it still isnt working

my default.sh is here:

https://paste.pound-python.org/show/DfjVcXOI3pKBY7KW6fzl/

I have also done chmod +x on the scripts

I am not very experienced in bash, so im not sure if its correct. I installed linux to learn bash more.

not sure why it still isnt working.

I tried to run the script directly by typing

./backlight.sh down

but its saying command not found line 17

I copied and pasted the backlight script exact though

----------

## Anon-E-moose

what does "ls /sys/class/backlight/" return?

if it shows intel_backlight then what does "ls /sys/class/backlight/intel_backlight" return?

----------

## OneNoteMan

 *Anon-E-moose wrote:*   

> what does "ls /sys/class/backlight/" return?
> 
> if it shows intel_backlight then what does "ls /sys/class/backlight/intel_backlight" return?

 

ls /sys/class/backlight/

gives: 

intel_backlight

ls /sys/class/backlight/intel_backlight

gives:

actual_brightness

bl_power

brightness

device

max_brightness

power

subsystem

type

uevent

----------

## Anon-E-moose

I don't see curr_brightness which is probably why it doesn't work. change it to actual_brightness in the brightness.sh script and see if it works

----------

## OneNoteMan

I tried to make the changes to the file but im getting an error

cp: cannot create regular file

it appears that i only have read permisson to anything in the folder

/sys/class/backlight/intel_backlight

this doesnt make sense because im trying yo make these modifications as root

of course i couldnt chmod it because even as root permission is denied

ls -a /sys/class/backlight/intel_backlight ..results here:

https://paste.pound-python.org/show/L5e8vjOWdwIdL8aNbUyb/

I suspect that this also may be the reason i am not able to change brightness, since I only have read permission?

im not sure why this is I certain my partitions are set up correctly, as it is exactly like the handbook specifies

----------

## khayyam

 *Anon-E-moose wrote:*   

> I don't see curr_brightness which is probably why it doesn't work. change it to actual_brightness in the brightness.sh script and see if it works

 

Anon-E-moose ... no, 'current_brightness' is a variable that reads in the contents of 'brightness' ... and that exists under /sys/class/backlight/intel_backlight.

 *OneNoteMan wrote:*   

> I tried to make the changes to the file but im getting an error
> 
> ```
> cp: cannot create regular file
> ```
> ...

 

You shouldn't need to make any changes to the script, but ok, from what command is that error produced? ... because the script doesn't include a 'cp', so that must come from elsewhere.

 *OneNoteMan wrote:*   

> it appears that i only have read permisson to anything in the folder /sys/class/backlight/intel_backlight

 

No, the files which are non-modifiable (ie, which contain a state ... such as 'actual_brightness' and 'max_brightness') are read only, but the file 'brightness', which is the only file modified by the script, is +rw.

So, just place an un-modified backlight.sh in /etc/acpi/actions with u+x, then fn+brightness down, and fn+brightnessup, that should work.

BTW, it's not "bash", the script is written in posix sh.

EDIT: actually, there is a problem there with the test condition ... try the following:

```
#!/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 -lt 1 ] || [ $new_brightness -gt $max_brightness ]; then

    exit 1

else

    echo "$new_brightness" > ${backlight_sys_dir}/brightness 

fi
```

best ... khay

----------

## Anon-E-moose

 *khayyam wrote:*   

> Anon-E-moose ... no, 'current_brightness' is a variable that reads in the contents of 'brightness' ... and that exists under /sys/class/backlight/intel_backlight.

 

 :Embarassed:  Sorry I was already nodding off when I made that reply.

----------

## josephg

 *OneNoteMan wrote:*   

> I tried to run the script directly by typing
> 
> ./backlight.sh down
> 
> but its saying command not found line 17

 

what is the output of

```
$ ls -lh ./backlight.sh
```

```
$ cat ./backlight
```

----------

## OneNoteMan

so there is nothing wrong with the permissions as per khayyam

i was trying to rename the actual_brightness by using cp and then rm, but that is not needed.

I have tried doing the adjustments as stated but still no luck  :Sad: 

Oh I should also mention the power button led is off, it is generally on when my system is on, it still functions though. Maybe this is a clue, i am not sure. I dont care much for the leds, I just want the buttons to work.

I tried to redo the instructions: 

https://wiki.gentoo.org/wiki/ACPI/ThinkPad-special-buttons

I tried logging in as both root and user, starting x and trying to control brightness to no avail

My file permissions for backlight.sh 

-rwxr-xr-x

and other action scripts copied from the wiki are for brightness control:

-rwxr--r--

----------

## OneNoteMan

also tried a different wm incase there was something going on with xmonad

still no brightness control

----------

## Anon-E-moose

what does "cat /sys/class/backlight/intel_backlight/brightness" return?

and what does "cat /sys/class/backlight/intel_backlight/max_brightness" return?

And are you trying to run the shell script as root?

----------

## OneNoteMan

both return just the number 4437

I can only run the scripts as root, the user cannot run it

but even still I cant get the brightness to change as root or user.

I noticed that my power button led is now lighting up for some reason even though i did not change anything

I tried running the scripts in my /etc/acpi/actions

i ran as root

FnHome-brightnessup.sh

this script actually returns a decreasing number, and outputs that number twice

FnHome-brightnessup.sh

this script actually returns a increasing number, and outputs that number twice

Also the changes are reflected in the file /sys/class/backlight/intel_backlight/brightness

so the actions scripts are changing the value of the brightness, but only when I manually run the command, and not when the key is pressed

interestingly when i run the script

powerbtn.sh

it actually shuts of my computer

I restarted again and the led for my power button is off again

----------

## Anon-E-moose

Ok run this command as root

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

does that change the brightness?

----------

## OneNoteMan

I also realized something 

I actually didnt do the portion from the wiki:

"...

By default some buttons are mapped to key codes that X can not handle or has no keysym for. So the following might be useful. It modifies the udev defaults slightly to fix the key combinations that otherwise would not work in X:

..."

the folder

/etc/udev/hwdb.d

did not exist is it necessary to make the folder and file?

----------

## Anon-E-moose

I don't think you need the folder

do this run acpi_listen and hit the fn+brightness up and down keys, and tell me what it returns.

----------

## josephg

 *OneNoteMan wrote:*   

> I tried to redo the instructions: 
> 
> https://wiki.gentoo.org/wiki/ACPI/ThinkPad-special-buttons
> 
> I tried logging in as both root and user, starting x and trying to control brightness to no avail
> ...

 

I see no backlight.sh in that wiki page. Did you copy it from somewhere else?

----------

## Anon-E-moose

 *josephg wrote:*   

> 
> 
> I see no backlight.sh in that wiki page. Did you copy it from somewhere else?

 

I had modified the default.sh script for acpi, and khayyam (very nicely) created the backlight.sh script from that. It gets talked about in the earlier link I provided.

----------

## OneNoteMan

so I did the following and now it works.

firstly it seems no modification is required to  /etc/acpi/default.sh  so I did not need the info from:

https://forums.gentoo.org/viewtopic-t-1085854-highlight-.html

I also still did not make the change specified in the wiki https://wiki.gentoo.org/wiki/ACPI/ThinkPad-special-buttons starting at the point where it says:

"...

By default some buttons are mapped to key codes that X can not handle or has no keysym for. So the following might be useful. It modifies the udev defaults slightly to fix the key combinations that otherwise would not work in X:..."

so these modifcations are unnecessary 

I restarted acpid

I though it still wasnt working but surely something was happening because a decrements and increment were occurring when the script ran.

I rebooted by laptop. Still nothing.

I remegered acpid set it to default and did

dispatch-conf

and took the new (untouched) files from the reinstall and overwrite the old ones that I modified.

rebooted again.

now my keys combinations were registering fn+home and fn+end were changing the brightness level numerically but no changes appeared.

I manually changed the value of the brightness, in the brightness file using Anon-E-moose's suggested command:

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

and boom brightness dropped  :Smile: 

I tried my fn key combos again and this time held if for an extended period, the brightness does go down but just slowly ..very slowly.

Everything works now, so hopefully the rest of the function keys should go smoothly

----------

## Anon-E-moose

So change the script increment value from 10 to something like 200 (both up and down)

I originally set it at 10 because in my case it goes from 0 - 100, in your case it goes from 0 - 4437, so 10 will take a long time to show anything.

----------

## josephg

So it's working now but very slowly? Good. You need to experiment with the increment value to change brightness when you hit the Fn keys. It seems yours is in the 1000s. Once you find a value you're comfortable with, you need to update your acpi scripts with that value.

----------

## OneNoteMan

 *Anon-E-moose wrote:*   

> So change the script increment value from 10 to something like 200 (both up and down)
> 
> I originally set it at 10 because in my case it goes from 0 - 100, in your case it goes from 0 - 4437, so 10 will take a long time to show anything.

 

yeah thats what im going to do I want 5% increments so I suppose 4437/20 =~ 222 will work for me

Thanks everyone for your help!

----------

