|
| 1 | ++++ |
| 2 | +categories = ['Linux'] |
| 3 | +tags = ['Commands', 'Migrated Post'] |
| 4 | +date = '2022-11-29T12:00:00-04:00' |
| 5 | +draft = false |
| 6 | +title = 'Linux Laptop Brightness' |
| 7 | +author = 'Bobby' |
| 8 | +summary = 'So you went ahead and installed a trendy window manager and now you need to change your laptop screen brightness...' |
| 9 | +description = 'brightnessctl to the rescue!' |
| 10 | +slug = 'linux-laptop-brightness' |
| 11 | ++++ |
| 12 | + |
| 13 | +## Change Your Linux Laptop Backlight Brightness |
| 14 | + |
| 15 | +### Table of Contents |
| 16 | + |
| 17 | +<!-- vim-markdown-toc GFM --> |
| 18 | + |
| 19 | +* [The Challenge](#the-challenge) |
| 20 | +* [Change the Backlight from the File](#change-the-backlight-from-the-file) |
| 21 | +* [brightnessctl](#brightnessctl) |
| 22 | + * [Basic Usage](#basic-usage) |
| 23 | + * [Changing Brightness](#changing-brightness) |
| 24 | +* [Reference Links](#reference-links) |
| 25 | + |
| 26 | +<!-- vim-markdown-toc --> |
| 27 | + |
| 28 | +### The Challenge |
| 29 | + |
| 30 | +So you spent too much time looking at fancy configs on Reddit... |
| 31 | + |
| 32 | +After looking at all the cool setups and decided to use a trendy window manager like **i3**, **dwm**, or even **Sway** if you're one of those fancy Wayland kids with an AMD card. |
| 33 | +You finally decided to use one of them and realized, some batteries aren't included and some assembly is required. |
| 34 | + |
| 35 | +Trust me, I lived it. Granted I love it. Tweaking every knob and tuning every dial. |
| 36 | +You do need to figure some things out that you probably took for granted, simple things like changing your laptop screen brightness. |
| 37 | + |
| 38 | +The laptop backlight on my Lenovo Thinkpad T480 was a bit of a learning journey for me. |
| 39 | +I finally got what I needed in the end, gather 'round and hear my tale, maybe it will save you some time. |
| 40 | + |
| 41 | +**⚠️ DISCLAIMER**:[^1] <br /> |
| 42 | +These are my specs: |
| 43 | + |
| 44 | +* Laptop: Lenovo Thinkpad T480, i5-8250U, Intel UHD Graphics 620 |
| 45 | +* OS: Arch Linux |
| 46 | +* WM: i3 (gaps) |
| 47 | + |
| 48 | +_Obligatory Neofetch_... <br /> |
| 49 | + |
| 50 | + |
| 51 | +I started by manually editing my _brightness_ file found within _/sys/class/backlight/intel_backlight/_. Very un-fun. |
| 52 | +I attempted some other utilities like `xbacklight` before settling on `brightnessctl`. |
| 53 | +I don't have a compelling case to why I prefer `brightnessctl`, I just find it easy and simple. |
| 54 | + |
| 55 | +### Change the Backlight from the File |
| 56 | + |
| 57 | +If you [RTFM _(Backlight Hardware Interfaces)_](https://wiki.archlinux.org/title/backlight) you can get some detail on how this all works. I think the Arch wiki quotes it best: |
| 58 | + |
| 59 | +> The brightness of the screen backlight is adjusted by setting the power level of the backlight LEDs or cathodes. The power level can often be controlled using the ACPI kernel module for video. An interface to this module is provided via a sysfs(5) directory at /sys/class/backlight/. |
| 60 | +
|
| 61 | +If you actually look at the contents of the backlight file you'll see it's just a number. |
| 62 | +_(Also in my case it is not just 0-100)_ |
| 63 | +This is the number I was modifying when I was just manually changing the file. |
| 64 | + |
| 65 | +Here we have my backlight _**intel_backlight**_. <br /> |
| 66 | +We can see the _**brightness**_ of my intel_backlight and it is a not very intuitive _**"758"**_ currently on my system. <br /> |
| 67 | +We can also view the _**max_brightness**_ which is _**"1515"**_. <br /> |
| 68 | + |
| 69 | + |
| 70 | + |
| 71 | +Given this we can deduce at the time of writing this my screen is at about 50% brightness. |
| 72 | +While we could edit the _**brightness**_ file it's probably easier to use a utility unless you want to feel like J.P. from Grandma's Boy. |
| 73 | + |
| 74 | +### brightnessctl |
| 75 | + |
| 76 | +Using `brightnessctl` is easy. |
| 77 | +I won't include any gifs here because you won't see the screen change. |
| 78 | +You will just have to trust me, a complete internet stranger! |
| 79 | + |
| 80 | +**❗NOTE**: I am not using sudo because I added my user to the _video_ group. |
| 81 | + |
| 82 | +Simple installation via `pacman` on Arch. |
| 83 | + |
| 84 | +```bash |
| 85 | +sudo pacman -S brightnessctl |
| 86 | +``` |
| 87 | + |
| 88 | +#### Basic Usage |
| 89 | + |
| 90 | +```bash |
| 91 | +# Check current device backlight, note this will match the file |
| 92 | +brightnessctl |
| 93 | + |
| 94 | +# You can also list other devices with brightness controls with -l, --list |
| 95 | +brightnessctl -l |
| 96 | + |
| 97 | +# If you plan to use the output elsewhere you can also use -m, --machine-readable |
| 98 | +# This will output in a comma separated form which can be parsed easily by other tools |
| 99 | +brightnessctl -l -m |
| 100 | +# Lets deserialize it (pwsh only for this example) |
| 101 | +brightnessctl -l -m | ConvertFrom-Csv |
| 102 | + |
| 103 | +# Just get the brightness number from a device |
| 104 | +brightnessctl -d intel_backlight get |
| 105 | + |
| 106 | +# Check the maximum brightness of a device |
| 107 | +brightnessctl -d intel_backlight max |
| 108 | +``` |
| 109 | + |
| 110 | +#### Changing Brightness |
| 111 | + |
| 112 | +```bash |
| 113 | +# Set the backlight! |
| 114 | +# This sets the device (-d, --device=DEVICE) to 75% |
| 115 | +brightnessctl -d intel_backlight set 75% |
| 116 | + |
| 117 | +# Increase from current value + or - 10% |
| 118 | +brightnessctl -d intel_backlight set +10% |
| 119 | +brightnessctl -d intel_backlight set -10% |
| 120 | + |
| 121 | +# If you want to supress the output use -q, --quiet |
| 122 | +# This can be useful if you just don't care about the return or want to wire this into a script |
| 123 | +brightnessctl -d intel_backlight set 100% -q |
| 124 | + |
| 125 | +# You can still set by number too, set to 1515 (max) |
| 126 | +brightnessctl -d intel_backlight set 1515 |
| 127 | + |
| 128 | +# You can test with the -p, --pretend switch which does a whatif/noop |
| 129 | +brightnessctl -d intel_backlight set 1% -p |
| 130 | +``` |
| 131 | + |
| 132 | +**✅TIP**: If you are going to wire `brightnessctl` into another process make sure to leverage the `-m` switch. |
| 133 | +Parsing the comma separated values is **MUCH** easier than trying to regex the default output. |
| 134 | +I learned this the hard way by not reading the help good. Always read the help good. |
| 135 | + |
| 136 | +There you have it, hopefully it helps! |
| 137 | + |
| 138 | + |
| 139 | +### Reference Links |
| 140 | + |
| 141 | + |
| 142 | +* [Arch Wiki - Backlight](https://wiki.archlinux.org/title/backlight) |
| 143 | +* [Reddit Post on brightnessctl permissions](https://www.reddit.com/r/archlinux/comments/fpklbs/brightnessctl_only_works_as_root/) |
| 144 | +* [Github - brightnessctl](https://github.com/Hummer12007/brightnessctl) |
| 145 | + |
| 146 | +[^1]: |
| 147 | + I am by no means an expert at all things Linux and laptop backlights. <br /> |
| 148 | + There are more backlight utilities than I can count and more models of laptops that exist than I can even begin to imagine. <br /> |
| 149 | + This is just what worked for me on my Thinkpad T480 running Arch Linux with i3. <br /> |
| 150 | + Your mileage may vary! <br /> |
| 151 | + |
0 commit comments