For the brightness shortcut keys to work, I generally do the following:

1. Run acpi_listen

2. Use the problematic key.

3. Watch output of acpi_listen, we want the first new line that pops up,
and first part before the space unless it says "hotkey" (in which case
we would like the full line).

4. Take note of the interesting part of the message.

5. Press Ctrl + C (terminating acpi_listen).

6. As root, make a shell script in "/etc/acpi", I choose
"acpi-to-nouveau-backlight-brightness.sh", any name is enough, but you
have to remember your custom name later on:

$ sudo nano "/etc/acpi/acpi-to-nouveau-backlight-brightness.sh"

7. Here is the content of my shell script, the things that you will
probably want to change are the ones related to Nouveau (and "nv_"
variables):

# Begin of file
#!/bin/bash

# acpi-to-nouveau-backlight-brightness.sh: Translate ACPI brightness
# to work with Nouveau brightness.
# Copyright © 2017 Adonay "adfeno" Felipe Nogueira 
<https://libreplanet.org/wiki/User:Adfeno> <[email protected]>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# # Dependencies
#
# - GNU bash is under GNU GPL 3+.
#
# - acpi is under GNU GPL 2+.

declare -A acpi_video
declare -A nv_backlight

acpi_video[path]="/sys/class/backlight/acpi_video0"
nv_backlight[path]="/sys/class/backlight/nv_backlight"

if [[ ! -d "${acpi_video[path]}" && ! -d "${nv_backlight[path]}" ]]
then
        exit 1
fi

min_brightness=0
acpi_video[max_brightness]="$(cat "${acpi_video[path]}/max_brightness")"
nv_backlight[max_brightness]="$(cat "${nv_backlight[path]}/max_brightness")"
acpi_video[brightness]="$(cat "${acpi_video[path]}/brightness")"
nv_backlight[brightness]="$(cat "${nv_backlight[path]}/brightness")"

# Needed so that we don't have to watch the ACPI backlight brightness
# every time, and so that the Nouveau backlight brightness matches the
# ACPI one.
nv_backlight[brightness]="$(( ( ${acpi_video[brightness]} * 
${nv_backlight[max_brightness]} ) / ${acpi_video[max_brightness]} ))"

# Needed to convert an ACPI backlight brightness step to a Nouveau
# backlight brightness step.
acpi_video_to_nv_backlight_step="$(( ( 1 * ${nv_backlight[max_brightness]} ) / 
${acpi_video[max_brightness]} ))"

if [[ "${1}" == "down" ]]
then
        nv_backlight[brightness]="$(( ( ( ${acpi_video[brightness]} * 
${nv_backlight[max_brightness]} ) / ${acpi_video[max_brightness]} ) - 
acpi_video_to_nv_backlight_step ))"
elif [[ "${1}" == "up" ]]
then
        nv_backlight[brightness]="$(( ( ( ${acpi_video[brightness]} * 
${nv_backlight[max_brightness]} ) / ${acpi_video[max_brightness]} ) + 
acpi_video_to_nv_backlight_step ))"
fi

if [[ "${nv_backlight[brightness]}" -lt "${min_brightness}" ]]
then
        nv_backlight[brightness]="${min_brightness}"
        elif [[ "${nv_backlight[brightness]}" -gt 
"${nv_backlight[max_brightness]}" ]]
        then
                nv_backlight[brightness]="${nv_backlight[max_brightness]}"
        fi

echo "${nv_backlight[brightness]}" > "${nv_backlight[path]}/brightness"
# End of file

8. Now, change the script mode so that everyone can read and execute:

$ sudo chmod +rx "/etc/acpi/acpi-to-nouveau-backlight-brightness.sh"

9. Now let's make ACPI events for the brightness keys, you can choose any
name, it doesn't have to be related to the script name. I choose
"acpi-to-nouveau-backlight-brightness-down" and
"acpi-to-nouveau-backlight-brightness-up" for down and up keys,
respectively.

However, if you changed the name of the first script, you have to change
it accordingly in the "event=" line of these "-down" and "-up" files.

$ sudo nano "acpi-to-nouveau-backlight-brightness-down"

# Begin of file
event=video/brightnessdown
action=/etc/acpi/acpi-to-nouveau-backlight-brightness.sh down
# End of file

$ sudo nano "acpi-to-nouveau-backlight-brightness-up"

# Begin of file
event=video/brightnessup
action=/etc/acpi/acpi-to-nouveau-backlight-brightness.sh up
# End of file

10. Make sure that each of these are readable by everyone:

$ sudo chmod +r "acpi-to-nouveau-backlight-brightness-down" 
"acpi-to-nouveau-backlight-brightness-up"


Happy hacking! :)
-- 
- [[https://libreplanet.org/wiki/User:Adfeno]]
- Palestrante e consultor sobre /software/ livre (não confundir com
  gratis).
- "WhatsApp"? Ele não é livre, por isso não uso. Iguais a ele prefiro
  Ring, ou Tox. Quer outras formas de contato? Adicione o vCard que
  está no endereço acima aos teus contatos.
- Pretende me enviar arquivos .doc, .ppt, .cdr, ou .mp3? OK, eu
  aceito, mas não repasso. Entrego apenas em formatos favoráveis ao
  /software/ livre. Favor entrar em contato em caso de dúvida.
- "People said I should accept the world. Bullshit! I don't accept the
  world."
                                                 --- Richard Stallman

Reply via email to