Since i have this problem of the back light not working in Linux and NOTHING worked, i decided to share my workaround to this problem. I hope no one needs to do the same but this may help someone.
My issues were the brightness and night mode, two important things to me.
What i did was using python scripts and 2 text files. Here are the steps i did:
Create this files “brightness-up, brightness-down, load-brightness, night-mode, current-brightness.txt, night-mode-switch.txt”, python files don’t need extensions because Linux can read them at the beggining of the file.
NOTE: when creating current-brightness.txt write “1.0” inside it and write “false” in night-mode-switch.txt
Copy and paste to the following:
brightness-up:
#!/bin/python
import os
brightnessPath = "/home/lighttigerxiv/Scripts/current-brightness.txt" #replace this lines with current-brightness.txt location
nightModePath = "/home/lighttigerxiv/Scripts/night-mode-switch.txt" #replace this lines with night-mode-switch.txt location
display = "DP-4" #Change this to your according display, you can find it with xrandr command
#Opens the brightness text file:
fileCurrentBrightness = open( brightnessPath, "r" )
fileNightModeSwitch = open( nightModePath, "r" )
#Reads the brigtness:
currentBrightness = fileCurrentBrightness.readline()
nightModeSwitch = fileNightModeSwitch.readline()
#Changes the brightness value:
brightnessFloat = float(currentBrightness)
fileCurrentBrightness.close()
fileNightModeSwitch.close()
if brightnessFloat >= 1:
pass
else:
brightnessFloat = round(brightnessFloat + 0.1, 2)
fileCurrentBrightness = open(brightnessPath, "w")
new_brightness = str(brightnessFloat)
fileCurrentBrightness.write(new_brightness)
#Night mode
if nightModeSwitch == "true":
bashCommand = "xrandr --output " + display + " --brightness " + new_brightness + " --gamma 1:1:0.8"
#Normal mode
else:
bashCommand = "xrandr --output " + display + " --brightness " + new_brightness + " --gamma 1:1:1"
os.system(bashCommand)
brightness-down:
#!/bin/python
import os
brightnessPath = "/home/lighttigerxiv/Scripts/current-brightness.txt" #replace this lines with current-brightness.txt location
nightModePath = "/home/lighttigerxiv/Scripts/night-mode-switch.txt" #replace this lines with night-mode-switch.txt location
display = "DP-4" #Change this to your according display, you can find it with xrandr command
#Opens the brightness text file:
fileCurrentBrightness = open(brightnessPath, "r")
fileNightModeSwitch = open( nightModePath, "r" )
#Reads the brigtness:
currentBrightness = fileCurrentBrightness.readline()
nightModeSwitch = fileNightModeSwitch.readline()
#Changes the brightness value:
brightnessFloat = float(currentBrightness)
fileCurrentBrightness.close()
fileNightModeSwitch.close()
if brightnessFloat <= 0.4:
pass
else:
brightnessFloat = round(brightnessFloat - 0.1, 2)
fileCurrentBrightness = open(brightnessPath, "w")
new_brightness = str(brightnessFloat)
fileCurrentBrightness.write(new_brightness)
if nightModeSwitch == "true":
bashCommand = "xrandr --output " + display + " --brightness " + new_brightness + " --gamma 1:1:0.8"
else:
bashCommand = "xrandr --output " + display + " --brightness " + new_brightness + " --gamma 1:1:1"
os.system(bashCommand)
load-brightness:
#!/bin/python
import os
import time
brightnessPath = "/home/lighttigerxiv/Scripts/current-brightness.txt" #replace this lines with current-brightness.txt location
nightModePath = "/home/lighttigerxiv/Scripts/night-mode-switch.txt" #replace this lines with night-mode-switch.txt location
display = "DP-4" #Change this to your according display, you can find it with xrandr command
#Opens the brightness text file:
fileCurrentBrightness = open( brightnessPath, "r" )
fileNightModeSwitch = open( nightModePath, "r" )
#Reads the brigtness:
currentBrightness = fileCurrentBrightness.readline()
nightModeSwitch = fileNightModeSwitch.readline()
#Changes the brightness value:
fileCurrentBrightness.close()
fileNightModeSwitch.close()
time.sleep(1) #Change this timer to more, like 2 3 4, if your pc is slow at starting up
if nightModeSwitch == "true":
bashCommand = "xrandr --output " + display + " --brightness " + currentBrightness + " --gamma 1:1:0.8"
else:
bashCommand = "xrandr --output " + display + " --brightness " + currentBrightness + " --gamma 1:1:1"
os.system(bashCommand)
night-mode:
#!/bin/python
import os
brightnessPath = "/home/lighttigerxiv/Scripts/current-brightness.txt"
nightModePath = "/home/lighttigerxiv/Scripts/night-mode-switch.txt"
display = "DP-4"
fileNightModeSwitch = open( nightModePath, "r" )
fileCurrentBrightness = open( brightnessPath, "r" )
nightModeSwitch = fileNightModeSwitch.readline()
currentBrightness = fileCurrentBrightness.readline()
fileNightModeSwitch.close()
fileCurrentBrightness.close()
if nightModeSwitch == "false":
command = "xrandr --output " + display + " --brightness " + currentBrightness + " --gamma 1:1:0.8"
os.system(command)
fileNightModeSwitch = open( nightModePath, "w" )
fileNightModeSwitch.write("true")
fileNightModeSwitch.close()
else:
command = "xrandr --output " + display + " --brightness " + currentBrightness + " --gamma 1:1:1"
os.system(command)
fileNightModeSwitch = open( nightModePath, "w" )
fileNightModeSwitch.write("false")
fileNightModeSwitch.close()
Now that every file is properly created, you need to change the permissions of the files in order to run.
Open the terminal and go to folder where you created all this files. Now do:
chmod +x brightness-down brightness-up load-brightness night-mode
Next step is moving them to /usr/local/bin/
sudo mv brightness-down brightness-up load-brightness night-mode /usr/local/bin/
Now that you have everything the only two things left to do. The next one is to keybind those scripts. Since i am in kde i just need to go to custom shortcuts and add them (i recommend using the normal keybindings with your pc):
With brightness up you just need to run “brightness-up” (since the scripts are /usr/local/bin/ you don’t need to add a path). With brightness down, the same philosophy “brightness-down” and with night mode, “night-mode” (i am using super-n) to activate it.
The last step to do is to add load-brightness to the autostart. In kde just write autostart and it should show an option to add a login script. Select the “load-brightness” in /usr/local/bin/ and you should be good to go