Ubuntu – How to have the display settings automatically restored after I play a full-screen game

gamesmultiple-monitorssystem-settingsvideo

When I play a full screen game on Ubuntu (Gnome, Kde, XFCE doesn't matter) the game decides what the monitor settings should be and then when the game is over I'm stuck with those settings. Is there an OS function that will restore my monitor settings for me automatically (like in windows) or if not, can I write a script that will save my settings to be restored easily? (like pushing a button or using a hot-key)

First monitor DVI-0 runs at 1440×900 and to it's right VGA-0 runs at 1600×900.

Okay, I've discovered that xrandr --output DVI-0 --auto --rotate normal --pos 0x0 --output VGA-0 --auto --left-of DVI-0 will set my monitors properly, however I still do not know how to make this happen easily whenever I have that "monitor bug" that happens after a full-screen app.

Best Answer

Go to a terminal by pressing Ctrl+Alt+T and type the following commands:

mkdir bin

to create a binary directory in the home directory for your user that automatically will get added to the path.

cd bin
cat > SC

to change to that directory and start creating that file.

Now copy-paste the following code:

#!/bin/bash
# This script starts StarCraft as an example for automatically restoring the video
# resolution as per question https://askubuntu.com/questions/594283/

# Copyright (c) Fabby 2015

# This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. See the GNU General Public License for more details.
# You DID NOT receive a copy of the GNU General Public License along with this program as the license is bigger then this program.
# Therefore, see http://www.gnu.org/licenses/ for more details.
# The following line needs to be changed per game.  Example is for StarCraft
/usr/share/playonlinux/playonlinux --run "StarCraft" $1
# The following line needs to be changed per machine's individual resolution settings:
xrandr --output DVI-0 --auto --rotate normal --pos 0x0 --output VGA-0 --auto --left-of DVI-0 

and hit: Ctrl+D and then type:

chmod +x SC

Now the "program" SC is ready to be executed with 1 parameter. Close the terminal and open it again and type:

cd /path/to/SaveGames
SC szFirstCoupleOflattersOfSaveGame[Tab]

Where /path/to/SaveGames and szFirstCoupleOflattersOfSaveGame are the directory where you keep your savegames and the first couple of letters of the name of your savegame respectively followed by the Tab key to auto-complete the entire name of your savegame. (if you just type SC it will just launch StarCraft without loading any savegame...)

Then finish with Enter and smile!

The above example should be enough for any other game that you have. If you use all capitals all the time for your own games and keep he names for your "programs" short, you'll turn into a real terminal addict. ;-)

If you don't like terminal commands, there are already answers on this site to turn them into icons on your desktop or in your dash (like this one )

Related Question