So sometimes a bad situation can turn into a good thing if you find a way to use it to your advantage. As seen below, I recently got a new computer, and after installing Wine on it and testing it out with some of my current favorites (HL2, Civ 4, WoW) I was pleasantly surprised to see I could run them with few issues. I’ve run Linux for a LONG time now, since ’96 or so, so I’ve always had to either dual boot or keep another machine around for games, big pain in the ass. Anyway, now that I could play games, I finally wanted to get a good video card. So I purchased a BFG GeForce 8800 GTS 0C2, and counted the days until it arrived.
Well, I got it, put it in, and everything worked great. I pumped my resolution up to 1680×1050 in all my games and nothing even flinched. BUT – as I was working around on my desktop, I noticed that everything seemed really laggy. I would move a window and it would stutter as it moved, when I was in Firefox I could literally watch chunks being written to the screen when I created a new tab, something was wrong. I read online and saw that a lot of people had the same problem, it seems that the Nvidia drivers 2D support was simply broken for the 8800, (it had until recently been broken for the 8600 but they finally fixed it with the newest driver release, so I’m hoping they do the same for the 8800 eventually).
Anyway, I was bummed, because while I play games sometimes and its why I bought the card, ultimately I need my computer for work. And if everything stutters anytime I do anything, thats unacceptable. I was like CRAP what am I going to do. BUT then I was like “Okay, wait a minute. I still have my built in Nvidia 6XXX (I forget the model), which has no problems with 2D graphics, and I have a monitor with two inputs on it. Why not hooked both my onboard and 8800 up to the monitor main monitor. Then I still have one port left on the 8800 for my second monitor.”
I did that, and life was getting better, but not quite there yet. I realized quickly that while xinerama is cool, I kind of wanted a separate environment for each screen. If I switched to my gaming screen, I no longer had a gnome toolbar because it was on my primary screen, and it was a pain. So I switched off xinerama and just used multiple X sessions on each screen. Now it was getting good, I had 3 screens (amongst 2 monitors, 1 monitor having two inputs), and each screen had its own desktop and toolbar. I could move between them just by moving my mouse off the screen. Which at first I thought was a good idea. But then I started playing games, and the issue came in – I’d move my mouse to the left to scroll the screen in my game or whatever, and suddenly it would go off the screen onto my other monitor, leaving the game. I could fix it for DirectX games because wine had a switch for it, but not for the majority of other OpenGL and non DirectX games.
So I found that if in your xorg.conf file, under the ServerLayout section, if you put the starting coordinates of your 2nd and 3rd screen past the ending coordinates of your first screen (and second screen for the third), the mouse won’t move to the next monitor when you push it past the edge of the screen. E.g. if your main screen has 1680×1050 resolution, it spans 1680 pixels width wise. If you setup your second screen to start at 2000 pixels in ServerLayout, then there will be “dead space” between them and X will not move your mouse off your home screen.
This was great – but now I needed a way to manually tell my mouse to go to another screen. I found a couple utilities that kind of did this. One was called mouse jail or something to that effect. It worked by scanning the location of your cursor and if it went past the edge of your screen, it would reset the coordinates back to the first screen (you would use this by enabling your mouse to go off the edge of the screen, and then turn it on when you wanted to lock the mouse to one screen, and off when you didnt). The problem was, it made the cursor look choppy and took up CPU time and wasn’t the perfect solution of what I was looking for. I wanted X to keep my mouse on one screen and then me manually press a key on the keyboard to move it when I wanted to. So there was another utility called SwitchScreen or something to that effect that was supposed to do this, but it only supported 2 screens, and I had 3. It seemed like it shouldn’t be that big of a deal to support 3, so I took a look at the source of the Screen Switcher, which itself was based off of the mousejail. And while both authors added some bells and whistles, the basic gist of it was a single line of code that switches what screen your mouse is on. And thats all I needed, so I recoded things into this:
#include <stdio.h>
#include <stdlib.h>
#include <X11/X.h>
#include <X11/Xutil.h>
#include <X11/extensions/XTest.h>
int main(int argc, char ** argv)
{
Display * display;
int majorOpcode, firstEvent, firstError;
char * displayName;
int thisScreen;
int otherScreen = -1;
displayName = getenv(“DISPLAY”);
if (displayName == NULL)
{
fprintf(stderr, “DISPLAY is not set\n”);
exit(1);
}
fprintf(stderr, “Opening display %s\n”, displayName);
display = XOpenDisplay(displayName);
if (!XQueryExtension(display,
XTestExtensionName,
&majorOpcode,
&firstEvent,
&firstError))
{
fprintf(stderr, “XTEST extension not available\n”);
return (1);
}
XTestFakeMotionEvent(display, atoi(argv[1]), 0, 0, CurrentTime);
XCloseDisplay(display);
return (0);
}
This simply takes one command line argument, a number of the screen you want your mouse to be on. I called it “ChangeDesktop”, so I can say “./ChangeDesktop 2″ to have it go to my third screen, or “./ChangeDesktop 0″ to go to my first screen. Then I mapped “ChangeDesktop 0″, “”ChangeDesktop 1″, and “”ChangeDesktop 2″ to G4, G5, and G6 on my keyboard, and boom, I had an instant method of putting my mouse on a different screen without having to worry about it dragging off the edge and causing issues. Now I can play a game on my big monitor, press G4 and put the mouse on my second monitor, look on the web for something or whatever, then press G6 and get back to my game. It might sound complicated from this post, but its dead easy and really nice – I thought this setup would be hokey, but as I use it, its really nice to have a separate desktop for my gaming portion, I have all my shortcuts there related to games, keeping it isolated from my work desktop, and I can simply switch between the two using a key on the keyboard (and my monitor). Even if they fix the Nvidia driver, I think I’ll stay with this setup!

