While you're here, please consider supporting GamingOnLinux on:
Reward Tiers: Patreon. Plain Donations: PayPal.
This ensures all of our main content remains totally free for everyone! Patreon supporters can also remove all adverts and sponsors! Supporting us helps bring good, fresh content. Without your continued support, we simply could not continue!
You can find even more ways to support us on this dedicated page any time. If you already are, thank you!
Reward Tiers: Patreon. Plain Donations: PayPal.
This ensures all of our main content remains totally free for everyone! Patreon supporters can also remove all adverts and sponsors! Supporting us helps bring good, fresh content. Without your continued support, we simply could not continue!
You can find even more ways to support us on this dedicated page any time. If you already are, thank you!
Login / Register
- Unofficial PC port of Zelda: Majora's Mask, 2 Ship 2 Harkinian has a big new release out
- Steam Controller 2 is apparently a thing and being 'tooled for a mass production' plus a new VR controller
- Half-Life: Blue Shift remake mod Black Mesa: Blue Shift - Chapter 5: Focal Point released
- Linux kernel 6.12 is out now with real-time capabilities, more gaming handheld support
- Steam Deck OLED: Limited Edition White and Steam Deck Australia have launched
- > See more over 30 days here
-
Kathy Rain 2: Soothsayer announced and there's a demo a…
- Raaben -
War Thunder adds stealth tech, ray tracing and graphics…
- Pikolo -
Steam Controller 2 is apparently a thing and being 'too…
- FutureSuture -
Dungeon Clawler will grab hold of your free time now it…
- USteppin -
War Thunder adds stealth tech, ray tracing and graphics…
- chr - > See more comments
- Weekend Players' Club 11/22/2024
- Pengling - Our own anti-cheat list
- Liam Dawe - Spare gog keys
- on_en_a_gros - What do you want to see on GamingOnLinux?
- dpanter - Nintendo-style gaming, without Nintendo!
- Talon1024 - See more posts
View PC info
On the telegram chat group somebody asked for a simple solution to turning on/off one of two screens.
This is especially useful for Linux gamers because Steam games mostly start on your main screen. If you want games to run on your TV or a different screen, it's a little bit of a hassle to manually switch which one is your main screen. This solution makes that much easier.
So I decided to write a little explanation on how it could be done using xrandr.
For a small description on xrandr I'll quote the man page
I'm doing this on my own desktop that has 2 monitors a 1080p and an old vga 1280x1024 one. These are the ones I'm using in the example. adapt to your own needs
I'm using a terminal to execute these commands so fire up xterm/lxterm/xfce-terminal/gterm/terminator/etc/etc.
1) Identify screens
xrandr -q
This returns 2 monitors for me
Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 16384 x 16384
VGA-0 connected (normal left inverted right x axis y axis)
1280x1024 60.02 + 75.02
1024x768 75.03 75.03 70.07 60.00
800x600 75.00 72.19 60.32 56.25
640x480 75.00 72.81 59.94
DVI-D-0 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 368mm x 207mm
1920x1080 60.00*+
1680x1050 59.95
1600x900 60.00
1440x900 59.89
1280x1024 75.02 60.02
1280x960 60.00
1280x800 59.81
1280x720 60.00
1152x864 60.00
1024x768 75.03 70.07 60.00
800x600 75.00 72.19 60.32 56.25
640x480 75.00 72.81 59.94
In my examples I shall use DVI-D-0 and VGA-0, replace them with your own names found.
2) Test with xrandr
So now that we know our monitors , let's try turning on the second one and turning off the first one. That way we don't have to work blind.
xrandr --output VGA-0 --auto
and turn off the first monitor
xrandr --output DVI-D-0 --off
And now let's reverse the process
xrandr --output DVI-D-0 --auto
xrandr --output VGA-0 --off
3) Profit!
The previous steps worked perfectly for me. I decided to create a script that would automate this for me.
3.1) example script
#!/bin/bash
#Either use the hardcoded stuff below
#replace these values with your own!!!
#MON1=DVI-D-0
#MON2=VGA-0
#OR try to get the first and last connected monitor
MON1=`xrandr -q|grep \ connected|awk '{print $1}'|head -n1`
MON2=`xrandr -q|grep \ connected|awk '{print $1}'|tail -n1`
MON1_CURRENT=`xrandr --listactivemonitors| awk '{ print $4 }'| grep ${MON1}`
# 0 we want the 2nd monitor to turn on
# 1 we want the 1st monitor to turn on
STATE=0
# ASSUMPTION!
# if MON1_CURRENT is empty were probably using the secondary monitor
if [ "x$MON1_CURRENT" == "x" ]
then
STATE=1
fi
if [ $STATE -eq 0 ]
then
#turn of MON1 and turn on MON2
xrandr --output $MON1 --off
xrandr --output $MON2 --auto
else
#turn of MON2 and turn on MON1
xrandr --output $MON2 --off
xrandr --output $MON1 --auto
fi
To turn this into a script for yourself you can copy/paste the code above into your favourite text-editor and save it with the name of your choice. I chose togglescreen.sh because that's what it does and it's a shell-script.
mark the file as being executable using your filemanager or using the terminal.
chmod +x owgodwheredidIsavethedamnthingthistime
I saved it in my homefolder so for me it's
chmod +x togglescreen.sh
3.2) take a testdrive
Either run it from your filemanager, probably using a doubleclick, or alternatively
/insomepath/where/i/saved/it/owgodwheredidIsavethedamnthingthistime
again for me that translates into
~/togglescreen.sh
Repeat running the scripts to revert to the old state.
As a sidenote you can adapt the commands to do other stuff than just turning monitors on and off. Do take the time to read the manpage for xrandr.
To read the manpage from the terminal
man xrandr
For people using nvidia proprietary drivers this link might help prevent tearing after switching screens.
I hope this helps a few people. Any suggestions or questions, add them below.
Regards,
Ysblokje
PS: thanks goes to Jan for proofreading and some suggestions
View PC info
You're right it doesn't make sense. So I changed to not use a statefile at all now.
Also it's my example script. You're free to modify it to your own needs.