Solved How to set the initial brightness in X11, or what are XF86MonBrightness doing exactly

Hello, I am running FreeBSD 13.2 on Thinkpad T430s with i3wm. The function keys for regulating brightness, Fn+F8 and Fn+F9 (XF86MonBrightnessDown and Up), are working out-of-the-box (lucky me). However, I would like to find out what command exactly they are sending to the system when pressed, because I would like to exploit this command to set the initial brightness to my liking through .xinitrc. Now the brightness always starts at 100% which is a bit too bright.

I tried to run
Code:
rgrep -i -I "xf86monbrightness /usr/
rgrep -i -I "xf86monbrightness /etc/
hoping to find some default setting, but to no avail. I can just see that these keys are called key <I232> and key <I233> in /usr/local/share/X11/xkb/symbols/inet.

I checked xbacklight, but it is apparently offline ("No outputs have backlight property").

I played a bit with xrandr, but I can see clearly that the brightness setting there is changing gamma level on the software level, while XF86MonBrightness-keys are actually doing it hardware-wise.

I ran also
Code:
freebsd# sysctl -a | grep backlight
hw.i915kms.enable_dpcd_backlight: -1
compat.linuxkpi.i915_enable_dpcd_backlight: -1
freebsd# sysctl -a | grep brightness
hw.i915kms.invert_brightness: 0
compat.linuxkpi.i915_invert_brightness: 0
but the settings I am getting seem to be about enabling / disabling backlight and brightness. I cannot regulate them in real time; the system asks me to do it at boot.

Googling the issue is confusing, because most people have problems with XF86MonBrightness that do not work at all, while I am having a kind of opposite issue. :)
 
Actually, I do not have these settings in my sysctl, because acpi_video_load is unset in load.conf. I could have set it, but then again, brightness was changing without it, so I kept looking among things I already have.

And then I found backlight (not xbacklight) which does exactly what I want. By issuing backlight 50 I can decrease the brightness to half.

However, I would like to make the system start with backlight 50. How exactly can I do that?
  • If I put backlight 50 into .xinitrc it won't adjust the console at startup.
  • If I put backlight 50 into .zshrc it won't adjust X immediately.
  • If I put it into both these places it seems inelegant :)
  • I cannot find any brightness related flag/setting in /etc/defaults/rc.d
Is there another startup config file that I could put a setting like that?
 
I read about practical rc.d scripting, and I have created a script /etc/reduce_backlight like this:

Code:
#!/bin/sh

. /etc/rc.subr

name="reduce_backlight"
rcvar="reduce_backlight_enable"
start_cmd="${name}_start"
stop_cmd=":"

load_rc_config $name
: ${reduce_backlight_enable:=yes}

start_cmd="backlight 50"

run_rc_command "$1"

I have also added the line
Code:
reduce_backlight_enable="YES"
to rc.conf, although I would think it is unnecessary since
Code:
: ${reduce_backlight_enable:=yes}
is supposed to give the default setting from within script, right?

Anyway, it does not work automatically. When the system starts, backlight is still at 100. The script works, however, because issuing
/etc/rc.d/reduce_backlight start
manually does reduce backlight to 50.

I did set chmod a+x reduce_backlight, by the way.

1) What am I doing wrong? Why is the script not activated at startup?
2) Is it the right way to approach the problem of reducing the backlight at startup, or is it actually an overkill?
 
OK, I have finally succeeded. :)

First, I have ascertained with rcorder /etc/rc.d/* that the script is really running at startup. It was, but very early.

So, I have added full path for start_cmd in case environment was not set so early in the startup process. It didn't help, but then I realized that backlight probably depends on some drivers that must be loaded first. I grepped rc.d-scripts for some relevant key words like brightness, screen etc. but didn't find anything.

Thus, I have added
Code:
# REQUIRE: LOGIN
to my script to ensure that it is being run as late in the process as possible. It worked. :)

I still wonder, however
1) which exactly preceeding script in rc.d is a precondition for backlight,
2) where the keys Fn+F8 and Fn+F9 are defined as XF86MonBrightness and connected to backlight control
If someone knows, please tell. :)
 
  • Like
Reactions: mro
Back
Top