Archive for the ‘Tutorials’ Category

h1

Multiple Monitors in Linux? No Problem.

September 15, 2007

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!

h1

The Logitech G15 keyboard under Debian

August 19, 2007

So my MAIN MAN Ry-Guy got me a Logitech G15 keyboard for my birthday. I haven’t really checked up on keyboards lately, but this one seems pretty damn sweet. It’s got 21 or so programmable keys, audio control keys, a volume wheel, a fairly large LCD screen with a nice medium resolution that shows quite a bit, three macro configuration states, two USB ports, and all the keys are backlit blue.

Totally sweet, but of course the drivers that come with it are Windows only. Luckily I found some software on the net to drive this thing under Linux.

As of today I haven’t gotten it totally working, but I’ll update this page as I do. So far I have the following:

  1. Works as a keyboard (pretty necessary)
  2. I can map the extended keys over to built in functions, like opening a web browser, volume/play/stop, etc
  3. I can drive the LCD and have the built in time application working so it displays the time on the LCD
  4. I have g15composer working, so I can successfully send commands to display text/graphics via scripts or anything else I want.
  5. I have lcdproc working via the g15 driver, which shows cpu/memory/network/other info on the screen. LCD buttons work great to flip between each screen or lock onto one screen.

Things left to do:

  1. Add quickkeys to Gnome so I can map any key combination I want to a programmable button, not just built in functions. E.g. G11 -> alt+x or something.
  2. Get the XMMS plugin working so it displays mp3 info on the LCD screen. It’s almost there, it starts to show volume and track information and then freezes xmms up.

This is what I did to get it working. Please note, some of the steps might be unnecessary and I’ll mark them as such, I was rushing to get this up ASAP and didn’t do proper testing at each step.

1. Visit the G15 tools webpage and download both the daemon and all the libs and any plugins you want. http://g15tools.sourceforge.net/ One thing though – for some reason I couldn’t get g15composer to run from compiled source. It would compile great, but seg fault when I actually went to run it. I didn’t investigate too much, I ended up finding a package for it from the Ubuntu forums and that worked great. Here is the thread: http://ubuntuforums.org/showpost.php?p=2461304&postcount=285

2. Compile and install libg15 first. Its the low level library that communicates with the keyboard via the uinput module. PS – make sure you have the uinput module for your kernel. You may have to modprobe it, it wasn’t already loaded for me. After libg15, compile and install the g15daemon, which is the daemon that communicates with the library. Then you come compile and install libg15render, then the composer (from the package if necessary). Don’t compile and install g15lcd, its deprecated by render/composer.

3. At this point, you’ve got all your lowlevel stuff ready to go. Add g15daemon to a init.d startup script, I put mine in my gdm script but it would probably be better to make its own, since the daemon has commands to kill it, or kill it and turn off the backlight, different stuff. Its up to you how much you want to do.

4. If you look inside the contrib folder of the g15daemon install, you’ll see a keymap file in there that you’ll want to copy over to your gnome keymap to use. Copy it into .Xmodmap in your home folder – you probably won’t have that file already unless you’ve done previous mapping, so just create it. Reload GDM and you should get a little dialog asking you if you want to use the .Xmodmap file. Load it and say yes.

5. There is also a patch inside the contrib directory to be run against your X keyboard list. Now, this errored out for me on a couple of the files, so I’m not sure this is necessary, I should have checked before and after to see if it made a difference. However, regardless, you should see “Logitech G15 keyboard support via G15Daemon” as an option under “Keyboard” preferences in Gnome. I manually changed it in my xorg.conf file, but you can do it from Gnome as well.

6. Now you can go to the “Keyboard Shortcuts” preference dialog and set up system function shortcuts, like web browser, email, volume, etc. To get Play/Stop/Next/Previous working for audio controls, I had to UNMAP those shortcuts, or else they were in use when XMMS tried to map to them. This may be different for your setup, especially if you use a different audio program.

7. Install the xmms-xf86audio package, it will read in those audio key bindings once enabled. Now you can play/stop/forward/back xmms. Volume and mute worked for me out of the box regardless of any plugins.

8. Download and install the xmms plugin to use the LCD panel off the g15 website. Make sure you have the xmms-dev package installed, or it will error out while compiling (they should have checked for it during the config step, but oh well). You can enable the plugin, but for me this locks up xmms.

9. Try testing out the composer – it works from reading a pipe for commands. You can run multiple instances all working off different pipes and switch between them using the MR key, which is great for connecting your different applications to a pipe. Anyway, create your pipe with “mknod lcdpipe p” or whatever you want to call it. Then run “g15composer lcdpipe ” and you should notice your LCD display the g15composer logo. You can then echo commands to that pipe. You can find complete reference in the g15composer man page, but a quick test is echo ‘TL “Hello” “World”‘ > lcdpipe. TL is large text, and each set of quotes will go on its own line.

10. After getting that working, download and install the lcdproc program. I had to compile and install it as the Debian package didn’t have the g15 built in by default. I suppose you could get the driver and still use the package, its up to you. Anyway, if you compile, remember to include the configure command to include the g15 driver. Then edit your LCDd.conf file and set the driver to “g15″, and point it to the right driver path (in the config file as well). Then put it into an init.d startup script and run it, and you should see a message on your LCD about LCD clients. At this point you can run lcdproc and see all your cpu/memory stats.

11. Thats about it for now, the XMMS plugin still locks up unfortunately, no idea why yet. There is a package for g15 macros as well, but it requires the new version of g15daemon which wasn’t running properly on my machine. A project for another weekend perhaps.

More on all this soon hopefully!