Archive for September 15th, 2008

Installing Cygwin/X and WindowMaker

I’ve been using the Cygwin shell for a 8 or 10 years. On a couple of occasions I have attempted to install the Cygwin X server packages, and it always seem to be more difficult than it should be. After a while I’d get tired of messing with it, and go back to using the standard non-graphical Cygwin shell.

Unfortunately, cutting and pasting between the non-graphical shell and Windows applications is a major pain in the rear. Having to click the upper left corner, select ‘Mark’, highlight the text, hit Enter, then paste it somewhere was just too many awkward mouse clicks. I longed for the nice X or KDE windows environment, where left-clicking and highlighting the text copied it, and center-clicking the mouse pasted it. Simple, fast, reliable.

Another thing I missed having was all my SSH sessions in one place. I use SSH a lot, into 3 or 4 different systems each day, sometimes with multiple windows open to each. Generally I used Tectia’s free SSH client, which is getting a little long in the tooth. Terminal emulation seems a little iffy, particularly when it comes to using the ‘Home’ and ‘End’ keys on the command line to jump to one end or the other. Being able to use a modern ssh client under an xterm session would solve that issue. And I got tired of having all those Tectia icons on the task bar.

I don’t remember the exact circumstance, but something prompted me to look into installing X again. I fired up the ‘setup.exe’ from the Cygwin.com site, selected X11 and the WindowMaker window manager and let it install.

After it finished, I attempted to start X the way I’m familiar with on my Linux boxes: open a shell and type ‘startx’. Nothing good happened, so a little poking around was required. I found that ‘startxwin.sh’ in the ‘/usr/X11R6/bin’ directory would bring it up, but not running WindowMaker. Instead, I was getting the default, twm. twm is a little too basic for my tastes, and the visual appeal is non-existent. I imagine there are some that like it, but not me.

A little more poking around revealed that I need to replace the ‘exec twm &’ with ‘exec wmaker &’ in ‘startxwin.sh’, and comment out the ‘xterm’ line. This is definitely an improvement, but I found two things I don’t like.

The first is that Alt-Tab was still moving between Windows windows, and not WindowMaker windows. A lot of searching found that -keyhook needs to be added to the XWin.exe line in ‘startxwin.sh’. Now Alt-Tab switches between Windows windows until the Cygwin window is active, then Alt-Tab moves between WindowMaker windows. To switch to a different Windows application requires clicking on the task bar icon. I find this acceptable.

The second is that I had a Cygwin shell still open and present on the task bar, along with the Cygwin/X icon. Closing the Cygwin shell resulted in shutting down Cygwin/X, even through the process was detached. I expected this is because it follows a typical Unix-like programming model, where the Cygwin shell is the parent process, Cygwin/X is the child process, and killing the parent kills the child.

I happened to notice that in addition to ‘startxwin.sh’ there is also a ‘startxwin.bat’. I made the same changes to it as the ‘startxwin.sh’ file, then created a shortcut to the batch file on the desktop. I also changed the default batch file icon by right clicking the batch file, selecting ‘Change Icon’, and pointing it to ‘%SystemDrive%\Cygwin\usr\X11R6\bin\XWin.exe’. This results in the batch file having the XWin.exe icon, which is a nice black ‘X’ on a transparent background.

So now we’re all good to go: We can start X without having an extra icon on the task bar, WindowMaker is started, Alt-Tab moves between WindowMaker Windows, and I have what I consider to be much more proper copy’n'paste behavior.

Below is a screen shot of the X11 packages I have installed. You’ll want to make sure these packages are selected in the ‘setup.exe’ program. They’re all under the ‘X11′ menu, at the bottom of the list.

Selected X11 Packages

Selected X11 Packages

Below is the ‘/usr/X11R6/bin/startxwin.sh’ with all the comments removed (for brevity).


#!/bin/sh
export DISPLAY=127.0.0.1:0.0
export PATH=/usr/X11R6/bin:"$PATH"
export XAPPLRESDIR=/usr/X11R6/lib/X11/app-defaults
export XCMSDB=/usr/X11R6/lib/X11/Xcms.txt
export XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
export XNLSPATH=/usr/X11R6/lib/X11/locale

rm -rf /tmp/.X11-unix
XWin -keyhook -clipboard -silent-dup-error &
exec wmaker &
exit

And also the '/usr/X11R6/bin/startxwin.bat' file:


@echo off
SET DISPLAY=127.0.0.1:0.0
SET CYGWIN_ROOT=\cygwin
SET RUN=%CYGWIN_ROOT%\bin\run -p /usr/X11R6/bin
SET PATH=.;%CYGWIN_ROOT%\bin;%CYGWIN_ROOT%\usr\X11R6\bin;%PATH%
SET XAPPLRESDIR=/usr/X11R6/lib/X11/app-defaults
SET XCMSDB=/usr/X11R6/lib/X11/Xcms.txt
SET XKEYSYMDB=/usr/X11R6/lib/X11/XKeysymDB
SET XNLSPATH=/usr/X11R6/lib/X11/locale

if not exist %CYGWIN_ROOT%\tmp\.X11-unix\X0 goto CLEANUP-FINISH
attrib -s %CYGWIN_ROOT%\tmp\.X11-unix\X0
del %CYGWIN_ROOT%\tmp\.X11-unix\X0

:CLEANUP-FINISH
if exist %CYGWIN_ROOT%\tmp\.X11-unix rmdir %CYGWIN_ROOT%\tmp\.X11-unix

if "%OS%" == "Windows_NT" goto OS_NT
echo startxwin.bat - Starting on Windows 95/98/Me
goto STARTUP

:OS_NT
echo startxwin.bat - Starting on Windows NT/2000/XP/2003
:STARTUP

%RUN% XWin -keyhook -clipboard -silent-dup-error
%RUN% wmaker

Hopefully the time I wasted trying to get Cygwin/X tuned the way I wanted will save someone else a few minutes. Or if you stumble across this post, encourage you to try Cygwin/X.