ThinkPad AMD With Mint - Fix Auto Brightness Reduction After Sleep
Published on 2024-09-28
How to Fix Auto-Dimming Brightness After Sleep Issue on ThinkPad T14 Gen 5 AMD Running Linux Mint 22
Introduction
If you've encountered an issue where the brightness of your screen automatically decreases after putting your laptop to sleep, you're not alone. This problem, with a ThinkPad T14 Gen 5 AMD running Linux Mint 22, usually occurs after closing the laptop lid to enter sleep mode and then restarting. However, there are scenarios where this issue doesn't occur. This guide will walk you through creating a script and a system service to resolve the problem.
References
- Laptop model: ThinkPad T14 Gen 5 (AMD)
- Laptop reference: 21MCCTO1WW
- Graphics card: AMD Radeon
- Tested on: Linux Mint 22 (Linux Kernel: 6.8)
Tutorial
1. Identifying the Issue
Here's when the brightness issue occurs and when it doesn't:
- Issue occurs: When you put the laptop to sleep by closing the laptop lid and then reboot.
- No issue:
- If you just reboot (without putting the laptop to sleep).
- If you adjust the brightness after sleep, then reboot.
- If you put the laptop to sleep without closing the lid (using the Mint start menu button), then reboot.
- If you put the laptop to sleep using the Mint start menu button, close the lid, open it to wake the laptop, and then reboot.
2. Creating a Script to Reset Brightness
To automatically reset the brightness after the system boots or wakes up from sleep, create a shell script:
Create and edit the script:
sudo nano /usr/local/bin/reset-brightness.sh
Add the following content to the file:
You can also download this script from my GitHub repository: Reset Brightness Script
#!/bin/bash
# Function to reset screen brightness
resetBrightness() {
logger "Reset-Brightness-Script : ---------- [START] ----------"
sleep 3
# Path to control screen brightness
BACKLIGHT_PATH="/sys/class/backlight/amdgpu_bl1"
if [ ! -f "$BACKLIGHT_PATH/max_brightness" ]; then
logger "Reset-Brightness-Script : [ERROR] Maximum brightness file not found."
exit 1
fi
# Set brightness to 60%
PERCENTAGE=60
# Get the maximum brightness value
MAX_BRIGHTNESS=$(cat $BACKLIGHT_PATH/max_brightness)
# Calculer la luminosité cible en fonction du pourcentage
TARGET_BRIGHTNESS=$((MAX_BRIGHTNESS * PERCENTAGE / 100))
# Calculate the target brightness based on the percentage
echo $TARGET_BRIGHTNESS | sudo tee $BACKLIGHT_PATH/brightness > /dev/null
logger "Reset-Brightness-Script : [INFO] Brightness set to $PERCENTAGE% ($TARGET_BRIGHTNESS)."
# Verify if brightness was set correctly
CURRENT_BRIGHTNESS=$(cat $BACKLIGHT_PATH/brightness)
if [ "$CURRENT_BRIGHTNESS" -eq "$TARGET_BRIGHTNESS" ]; then
logger "Reset-Brightness-Script : [SUCCESS] Brightness set successfully."
else
logger "Reset-Brightness-Script : [WARNING] The actual brightness ($ACTUAL_BRIGHTNESS) differs from the target ($TARGET_BRIGHTNESS)."
fi
logger "Reset-Brightness-Script : ---------- [END] ----------"
}
# Run the resetBrightness function
resetBrightness
Save and exit.
Make the script executable:
sudo chmod +x /usr/local/bin/reset-brightness.sh
3. Creating a System Service
Now, we’ll create a systemd service to run this script at startup and after suspend:
Create and edit the service file:
sudo nano /etc/systemd/system/reset-brightness.service
Add the following content to the file:
[Unit]
Description=Reset screen brightness at startup and after suspend
After=multi-user.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/reset-brightness.sh
[Install]
WantedBy=multi-user.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
Save and exit.
Enable the service to start automatically at boot and start it:
sudo systemctl enable reset-brightness.service
sudo systemctl start reset-brightness.service
sudo systemctl status reset-brightness.service
4. Log Monitoring
To ensure the script runs correctly, you can view the logs with this command:
journalctl -xe | grep "Reset-Brightness-Script"
Conclusion
By implementing this script and system service, you can resolve the issue of automatic screen dimming after sleep on your Linux system. This will ensure consistent brightness levels across reboots and sleep cycles.
GitHub Repository
✨ If you found this tutorial useful, please give me a star on my GitHub repository:
@s-damian - ThinkPad T14 AMD with Linux
Other Tutorials on Linux Support on ThinkPad T14 AMD
📝 See other articles on the same subject: