Arman's stuff
Guest
xinit

(Mon Oct 25 12:05:26 2010)

I'm pretty pleased with myself, right about now.

In my recent work with games and Wine (where by 'Wine' I mean 'Wine Is Not An Emulator', not 'fermented grape juice'), I've run across a fairly annoying problem - resolution. Old Windows games want to change the screen resolution down to 640x480 or 800x600 - a far cry from 1680x1050 + 1280x1024. That results in the screen being squished funny, pixels not being square, and general ugliness. Newer Windows games and many Linux games will try to go full screen - by which I mean 2960x1050, the full width of my dual monitors. Dual monitors is great for cross referencing a webpage and programming at the same time, but terrible for playing Warzone 2100. This is where my recent research comes in.

Wine usually works pretty well, but it doesn't like to chance resolutions much, especially if something goes wrong. It's a painful process to go from 640x480 back to my original resolution, let me tell you. So, I wanted to find a way to open a new X window, run the game in it, and then close that window when the game finished. That way, I don't need to worry about manually running a program to turn off one monitor while I'm playing and restart it afterward, and I don't need to deal with programs that don't end well and leave my resolution completely messed up. It's a win-win situation - and one that's a lot easier than I thought it was, too!

My first search turned up a very complicated shell script; I'm sure it works well, but it was very, very involved, and the instructions that came with it were... suspect at best. It involved making a few changes I wasn't completely comfortable making. After looking through the script a bit, I realized I had no idea what it did. At all. So, I decided to dig a bit deeper, and broaden my search a bit. That script was meant for Wine, and I wanted something for any program. Last night, I found a man page on xinit, and it seemed to be what I was looking for. A quick test showed that, indeed, it was exactly what I was looking for! A little bit of scripting later, and I was able to start any program I wanted in a second screen. I ran into a couple snags - the first was that it wasn't initializing the window correctly, and the second was that the game I was testing refused to start. Those were both easily fixed. I had the configuration in the wrong order for the first problem, and the settings file was corrupt for the second; swapping the commands around and deleting the settings fixed it perfectly. Now when I want to run a game, I just type "newscreen [name of game] [options]" and away I go! It's easy, it's fast, and it's useful - I can, for instance, switch between windows with ctrl+alt+F7 (desktop) and ctrl+alt+F8 (new window). Obviously, I can only have one game running at a time, but who needs more than that, eh?

For those of you who might have the same problem (and to document this for my own records), here are the steps I followed:

1) Set up the permissions, so you can start a new X display:
sudo cp /etc/X11/Xwrapper.config /etc/X11/Xwrapper.config.custom
sudo su
md5sum /etc/X11/Xwrapper.config > /var/lib/x11/Xwrapper.config.md5sum
exit
sudo dpkg-reconfigure xserver-common

This will allow anyone to start a new X window, without needing root access. Note: your directory for the md5sum might be /var/lib/xfree86/Xwrapper.config.md5sum instead of /var/lib/x11/Xwrapper.config.md5sum - at least that's how I've seen others do it. YMMV, and all that.

2) Next, add the actual authority; run this to get a list of all the codey bits (run xauth, then type 'list'):
xauth list
You'll get something like this:
phoenix.i-arman.com:0 MIT-MAGIC-COOKIE-1 98bnw94589ghp9aer958gh943898gyae
phoenix.local:0 MIT-MAGIC-COOKIE-1 98bnw94589ghp9aer958gh943898gyae
[fe80::221:85ff:fe03:5f0]:0 98bnw94589ghp9aer958gh943898gyae
phoenix/unix:0 MIT-MAGIC-COOKIE-1 98bnw94589ghp9aer958gh943898gyae


If it just sits there and doesn't give you the command line back (it did for me, anyway), go ahead and hit ctrl+C to break it.
The part you want is probably on the first line, after localhost.local or somesuch. You want the bit after "MIT-MAGIC-COOKIE-1", that long alphanumeric code. It won't be the same as mine. Copy it, then do:
xauth add :1.0 MIT-MAGIC-COOKIE-1 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
where the x's are the code you copied. That adds the key for the new display you'll use.

4) Just before we make the actual script, you might want to edit your X window setup; if you don't want to bother, just take the "-config xorg-newscreen.conf" out of the script. Otherwise, do this:
sudo cp /etc/X11/xorg.conf /etc/X11/xorg-newscreen.conf
Edit the xorg-newscreen.conf (explaining how to edit a root-access-only file is left up to other guides) and change any settings you wish; I removed all references to my second monitor, among other things. Save it, and you're ready for the last step!

5) Finally, set up the script that actually DOES stuff; edit a new file and put the following in it:
#!/bin/bash
FILE=`which $1`
shift
xinit $FILE $* -- :1 -config xorg-newscreen.conf

Save it as "newscreen", then:
chmod a+x newscreen
mv newscreen /usr/bin/

That will make the script executeable, and moving it to /usr/bin makes it executeable from anywhere.
If you start your game (or other program) with
mygame --option 1 --option 2 --option 3
just start this with
myscript mygame --option 1 --option 2 --option 3
The options are passed right on through. If you don't want to bother with all that, you could skip the script and just use xinit:
xinit /path/to/your/game --option 1 --option 2 -- :1


<< Busy Ain't The Half Of ItNew tag selector! >>

This blag is tagged: Games, Linux, Wine, All