LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-05-2006, 08:18 AM   #1
ylikone
Member
 
Registered: Dec 2004
Location: Ontario, Canada
Distribution: ArchLinux, VectorLinux, Ubuntu, Debian, Linspire
Posts: 66

Rep: Reputation: 15
BASH script for changing screen resolution


I've setup a Linux computer for my mother-in-law and everytime she plays a certain game, it resizes her screen to 640x480... this is fine except that the game doesn't bother to revert back to 1024x768 when she quits. She can't ever remember the steps to reset the resolution from the desktop options menu in KDE. What I want to do it make her a simple icon in the top left corner of her screen that she can click on to reset the screen resolution for her automagically. I figure this can be accomplished easily enough with the proper command line script (that I can point the desktop icon to). Thanks for any help!
 
Old 05-05-2006, 08:28 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Not a script, but the "magic" key combinations: "CTRL ALT +" and "CTRL ALT -" should hop through the available X-server resolutions.

Important note: These are the '+' and '-' on the numpad. The "normal" '+' and '-' don't work.

Hope this helps.

Last edited by Hko; 05-05-2006 at 08:32 AM.
 
Old 05-05-2006, 01:48 PM   #3
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 30
You could write a script using xvidtune -next/-prev but it's probably easier to use ctrl alt +/- as Hko explained.

Also, if you ever find that a game/app has locked the display so you can't change resolution, then xvidtune -unlock will, well, unlock it.
 
Old 05-05-2006, 03:35 PM   #4
krizzz
Member
 
Registered: Oct 2004
Location: NY
Distribution: Slackware
Posts: 198

Rep: Reputation: 30
You also have to have appropriate modes defined in your xorg.conf file to switch between them like that.
 
Old 05-05-2006, 06:22 PM   #5
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,202

Rep: Reputation: 291Reputation: 291Reputation: 291
xrandr is the command to change res

xrandr -q to list modes, then
xrandr -s 0,1,2 etc
 
Old 05-06-2006, 02:33 AM   #6
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 30
Quote:
xrandr is the command to change res
Well, it's _a_ command, not _the_ command. TMTOWTDI!
 
Old 05-06-2006, 04:47 AM   #7
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,202

Rep: Reputation: 291Reputation: 291Reputation: 291
Quote:
Originally Posted by ioerror
Well, it's _a_ command, not _the_ command. TMTOWTDI!
True there is more than one way, but I don't know any other commands
 
Old 05-07-2006, 08:56 PM   #8
ylikone
Member
 
Registered: Dec 2004
Location: Ontario, Canada
Distribution: ArchLinux, VectorLinux, Ubuntu, Debian, Linspire
Posts: 66

Original Poster
Rep: Reputation: 15
Thanks, that xrandr command will work nicely. I know about CTRL ALT+/-, but I'm not going to expect grandma to remember that! A nice big screen icon that says "Restore my screen" is what she needs.
 
Old 05-10-2006, 06:01 PM   #9
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 30
*blink* I don't know why it didn't occur to me before but the obvious solution would be to wrap the game(s) in a script that would automatically reset the resolution if necessary.

Looking at xrandr, this should be simple, the current resolution is shown with a *. Since the default resolution is size "0", it's a trivial matter to check it.

Code:
#!/bin/sh

# run game

res="$(xrandr -q|grep '^\*')"
if [[ "${res:1:1}" != 0 ]]; then
        xrandr -s 0
fi
Of course, you'll probably want to keep that icon handy, in case some other program/game frobs with the resolution too...

Last edited by ioerror; 05-10-2006 at 06:04 PM.
 
Old 05-10-2006, 07:49 PM   #10
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,202

Rep: Reputation: 291Reputation: 291Reputation: 291
You could simplify and just put xrandr -s 0 after run game command, after all we know the res is going to be wrong anyhow
 
Old 05-11-2006, 05:11 AM   #11
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 30
True, in this case. I was aiming for a more general solution (and trying to be elegant by avoiding unnecessary command).

BTW, what kind of game is it anyway? If it's open source, it should be easy enough to patch it to reset the resolution itself.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem changing the video adapter setting and changing the screen resolution habiblove Linux - General 3 02-18-2006 05:10 PM
Changing Screen Resolution gunner_uk2000 Fedora 3 11-28-2005 02:24 PM
changing bash resolution mlu Linux - Software 3 05-01-2005 09:18 PM
changing screen resolution.. kurrupt Debian 4 10-24-2004 12:45 PM
Changing the screen resolution? Stillwell Linux - Newbie 2 09-28-2003 04:30 PM


All times are GMT -5. The time now is 07:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration