Hello there, I’m Joseph Henrich and I am the newest addition to the Constant Contact Labs team! I’m here to show you an x.org trick I developed while optimizing how I play World of Warcraft on my Dual-Screen Linux setup.
For a while now I’ve been running my games in a separate X session. There are a couple of reasons why this is a good idea. First, it means that your window manager and eye candy won’t be running on the game slowing things down. Secondly, it also means that if the game crashes you aren’t left with the game’s resolution. This issue was very annoying to me because I use two monitors and when the game changes my X session to a single monitor and then crashes all my programs are on a single monitor and need to be put back into their proper place. Third I used to have lots of issues when I alt-tabbed to another window.
I initially started out by just having a new X session for my games, but over the years I’ve added on to it. I feel that it is a waste to have two monitors and only use one when playing a game, however, most games are actually worse to play when split over two monitors. It is really hard to aim when there is a big crack in the middle of your gun! Real Time Strategy games are the main exception I’ve seen. But I digress, what a waste that screen is, just sitting there. I might as well put it to use. Being a bit ADD I decided that I might like to watch movies while I play games. I’m a fan of mplayer and it works great for this, just tell it to play in the window with whatever settings you fancy and you are good to go. Great! Now I can watch movies, but either I have my mouse leave the game when I’m playing or I have to change back to my main X session to control them… not so great.
The next challenge was to get be able to move my mouse from one screen to the other, but only when I want it to. Looking around I found a cool program, DualscreenMouseUtils, that would let me do just that. Sadly the links to the actual program that I could find were all dead (they are back up now). Then I discovered that you can move a mouse cursor with python and the Xlib library. Python never ceases to amaze. A little scripting later and I had a script that would move the cursor from one screen to the other with the press of a key combo. The main difference I see between my script and DualscreenMouseUtils is that my script can either listen for a key combo and swap then or as a single swap. I designed it to listen because I don’t run a window manager in my gaming x session and so I can’t have the wm listen for keys.
The setup I have isn’t just useful for watching movies and playing games at the same time. Anyone who has their computer hooked up to a TV and watches movies while doing other things might enjoy it, that way their mouse won’t stray into movie unless they want it to. Additionally, using some form of voice chat, ventrillo, skype and such are popular while playing games if the game doesn’t have something built in. This way you can see who is talking, add people or change your settings a lot easier.
How I Did It
While writing this I discovered that recently x.org had moved to a new conf file system. Thankfully it is backwards compatible with the old system. Basically, they added support for classes of input devices and the server now also looks for conf files in the xorg.conf.d directory as well, more details here. If you aren’t familiar with x.org I recommend reading your distribution’s documentation on it before proceeding as file location and setup can vary from distro to distro. You can keep your existing xorg.conf file and not change anything. The files in xorg.conf.d/ are read and applied in numerical order and start with two numbers and a dash and end in .conf, 10-myfile.conf for example. For the moment, until I’ve gotten a chance to figure out how I want everything set up using this new system, the following steps are assuming editing the xorg.conf file.
I set up my ServerLayout to specify that I have two monitors and that the second is placed 2000 pixels away from the other. Any number should work here just as long as it is larger than your resolution. The mouse is now stuck in whatever screen it is in. You will want a ServerLayout section for each different setup of X. The first one in your conf file is the default that is run. You can also set the default in your ServerFlags section (Option “DefaultServerLayout” “layout-id”). To specify a layout on the commandline use the -layout name option.
Section "ServerLayout" Identifier "Layout0" Screen 0 "Screen0" 0 0 Screen 1 "Screen1" 0 2000 InputDevice "Keyboard0" "CoreKeyboard" InputDevice "Mouse0" "CorePointer" EndSection
Then I created a second device section changing the identifier and screen fields:
Section "Device" Identifier "Videocard0 out 0" Driver "nvidia" Option "RenderAccel" "true" Option "UseDisplayDevice" "DFP-0" VendorName "NVIDIA Corporation" BoardName "GeForce 9500 GT" Screen 0 EndSection Section "Device" Identifier "Videocard0 out 1" Driver "nvidia" Option "RenderAccel" "true" Option "UseDisplayDevice" "DFP-1" VendorName "NVIDIA Corporation" BoardName "GeForce 9500 GT" Screen 1 EndSection
I also had to create a second screen section tied to the second device
Section "Screen" Identifier "Screen0" Device "Videocard0 out 0" Monitor "Monitor0" DefaultDepth 24 Option "NoLogo" "true" SubSection "Display" Depth 24 Viewport 0 0 EndSubSection EndSection Section "Screen" Identifier "Screen1" Device "Videocard0 out 1" Monitor "Monitor1" DefaultDepth 24 Option "NoLogo" "true" SubSection "Display" Depth 24 Viewport 0 0 EndSubSection EndSection
At this point you have the setup for an X session with two screen that are seperated. There are only two steps left for my full setup. The screen changing script and the script that launches World of Warcraft. Download both of them and place them where you want. Then edit launch-wow.sh and change the WOW_PATH variable to where your wow is installed also, change the path to screenswap.py to where you put it. Voila! You are all ready to launch World of Warcraft and do something else on a different screen. Just run the launch-wow script and it will start up WoW and the screenswap script. If you want to launch other programs in the other X session just add DISPLAY=:3.1 (if you want it in your second screen, 0 for the first and 2 for the third and so on) in front of whatever command.
Continue the conversation by sharing your comments here on the blog and by following us on Twitter @CTCT_API