For those who have more than one monitors connected to Ubuntu machine, here’s how to turn off either laptop’s built-in screen or external monitor without dis-connecting it (Support both Wayland and Xorg).
Option 1: Turn off screen in GNOME Wayland
For the default GNOME with Wayland session, there’s so far (2023) no universal method to do the job. But, there’s a third-party tool gnome-monitor-config works in my case in Ubuntu 22.04 default session.
The gnome-monitor-config project has not been updated for a few years! It still works in Ubuntu 22.04 (until developer remove the project), but may or may not for higher Ubuntu/Gnome editions.
Step 1: Built & install gnome-monitor-config
The tool does not provide any binary package and compile instruction. Here’s how I built and install it in Ubuntu 22.04.
1. First, press Ctrl+Alt+T on keyboard to open a terminal window. When it opens, run command to install the dependency packages:
sudo apt install git libcairo2-dev cmake meson ninja-build libglib2.0-dev
Type user password (no asterisk feedback) when it asks and hit Enter.
2. Then, run command to download the source code. Of course you can alternatively download via the browser link (see link above):
git clone https://github.com/jadahl/gnome-monitor-config.git
3. Once you got it, navigate to the source folder, and build it:
cd gnome-monitor-config
meson build
4. If no error occurred, you can now go to ‘build’ folder and compile to generate executable file:
cd build
meson compile
Step 2: Disable primary or external screen via the tool
If everything goes well, there should be a “gnome-monitor-config” executable file created under ‘src’ folder.
1. First, run command to navigate to that folder, then list all files. There’s should be the execute file in green text color.
cd ~/gnome-monitor-config/build/src/ && ls
2. Then, you may select run commands below to turn off your desired screen.
- First, run command to list all available monitors:
./gnome-monitor-config list | grep Monitor
In my case (see screenshot below), I have 2 monitors: eDP-1 and DP-1.
- To turn off the build-in display (eDP-1 in my case), just run command to enable DP-1 which will leave all others disabled:
./gnome-monitor-config set -LpM DP-1
- To turn off the external monitor (DP-1 in the case), just enable eDP-1 which also leave all others disabled:
./gnome-monitor-config set -LpM eDP-1
- If you want to re-enable both monitors, use command:
./gnome-monitor-config set -LpM eDP-1 -LM DP-1 -x 1366
NOTE: In last command I set “eDP-1” as primary display. It has 1366×768 screen resolution. For you, change the number 1366 accordingly!
Step 3: Install the tool to system PATH
If previous commands are working good, you can move it to system path by running command:
sudo mv ~/gnome-monitor-config/build/src/gnome-monitor-config /usr/local/bin
So, next time you can open terminal and run the previous commands (in Step 2) anywhere without “./”. For example:
- List all monitors:
gnome-monitor-config list
- Enable one monitor, leave others off:
gnome-monitor-config set -LpM DEVICE_NAME
Step 4: Add Keyboard Shortcut to Turn Off Monitors
To make life easier, you can assign keyboard shortcuts for the previous commands.
First, open “Settings”, navigate to “Keyboard” from left and “Keyboard Shortcuts -> View and Customize Shortcuts” in right.
In pop-up dialog, choose “Custom Shortcut” and then add new:
- Name: whatever as your want.
- Command:
gnome-monitor-config set -LpM DEVICE_NAME
- Shortcut: set your desired key combination.
For choice, you can add more shortcuts to disable other or re-enable monitors.
Option 2: Turn off a screen in Xorg session
For Ubuntu on Xorg, XUbuntu, Ubuntu Mate, Linux Mint, and most other Linux with classic Xorg, there’s a system built-in tool xrandr
can do the job.
To do the job:
- First open a terminal window from start menu (system application launcher).
- Run command to list all connected monitors:
xrandr --listmonitors
- Then, use the command below to disable a screen:
xrandr --output DEVICE_NAME --off
- In case you want to turn the monitor back on, use command:
xrandr --output DEVICE_NAME --auto