Simple customisation of twm on cygwin

twm is just about the simplest mouse-based window manager for X windows. For using cygwin/X on older hardware, it is still a useful choice since it comes ready to use with the installation. In default form it is pretty ugly. Using it on cygwin and making it a little nicer to look at is very easy, however.

First, create a .twmrc file in your home directory, by finding the system-wide one (probably in /etc/X11/twm and called system.twmrc), and copying it. Now, on many Linux distros there is a trick here — system.twmrc populates its menu using (if present) a file called menudefs.hook, which is automagically generated by the system. Your personal .twmrc does not, so when installing or removing applications, your personal .twmrc needs to be (manually) ‘remerged’ with system.twmrc. This is pretty simple, and just means it is a good idea to keep any changes you make localised to the top, well away from the menu definitions.

Anyway, there are a couple of simple steps to make twm a little nicer. First, anything you want to add to the menu can be added easily, just using existing menu entries as models — but note caveat above. Second, it should be possible to change colour schemes. Some suggestions about the relevant sections of .twmrc to copy and paste are shown here. Just copy the text straight into your .twmrc and comment out (#) the old.

Fonts are most easily changed by opening .twmrc in your editor and then running xfontsel which gives you a gui that you can use to explore the font options. Then just select the various qualities to create the font string (examples are shown in .twmrc) then hit the ‘select’ box in xfontsel, go to your editor and middle-button-paste it into .twmrc. For example, here is the xfontsel dialogue for Bigelow & Holmes lucida typewriter,bold, roman at a ‘size’ of 120.  These are the main fields required…

xfontsel

xfontsel

…and here is the relevant bit of .twmrc where there are five font fields, each chosen using a font string. Note the quotation marks.
font strings

This pretty much is all you need to do with .twmrc. Now, if on cygwin, I would recommend then making a file .xinitrc with (at least) two lines. These are:

xinitrc

So line 1 uses xloadimage to set the file color1.jpg as the background, then line 2 launches the X session with twm as the window manager. There is a command to set the background colour rather than what I have done which was create a jpg file filled with a flat colour I liked, but I’ve shown this example because you might like an actual background image. For cygwin, that is enough. Start your cygwin shell then type startx and you’re away.  The net result is hardly earth-shaking, but it is a bit nicer than default and in my opinion if you can change the colours, change the fonts and add things to the menu, you have hit the 80:20 rule sweet spot and any more tweaking enters the realm of diminishing returns. I don’t like to mess with key and mouse bindings, because that means that when I am away from my home system things don’t behave as I expect.

For no reason, here is what it looks like at work, cygwin running on Windows 7, using the config file I’ve attached at the end of this post.

twm as customised.

twm as customised.

Other cygwin stuff.


NoGrabServer
RestartPreviousState
DecorateTransients
ResizeFont “-bitstream-bitstream vera sans-*-r-*-*-*-*-*-*-*-*-*-*”
MenuFont “-bitstream-bitstream vera sans-*-r-*-*-*-*-*-*-*-*-*-*”
IconFont “-b&h-lucidatypewriter-bold-r-normal-*-*-100-*-*-*-*-*-*”
IconManagerFont “-b&h-lucida-bold-r-normal-*-*-80-*-*-*-*-*-*”
TitleFont “-b&h-lucidatypewriter-bold-r-normal-*-*-100-*-*-*-*-*-*”
#ClientBorderWidth

# from http://cpcnw.co.uk/twm/

Color
{
BorderColor “#000000”
DefaultBackground “#E6E6E6”
DefaultForeground “#000000”

TitleBackground “#45152F”
TitleForeground “White”

MenuTitleBackground “#45152F”
MenuTitleForeground “White”

MenuBackground “#E6E6E6”
MenuForeground “#363636”

MenuShadowColor “#363636”
MenuBorderColor “#000000”
}

#
# Define some useful functions for motion-based actions.
#
MoveDelta 3
Function “move-or-lower” { f.move f.deltastop f.lower }
Function “move-or-raise” { f.move f.deltastop f.raise }
Function “move-or-iconify” { f.move f.deltastop f.iconify }

#
# Set some useful bindings. Sort of uwm-ish, sort of simple-button-ish
#
Button1 = : root : f.menu “defops”

Button1 = m : window|icon : f.function “move-or-lower”
Button2 = m : window|icon : f.iconify
Button3 = m : window|icon : f.function “move-or-raise”

Button1 = : title : f.function “move-or-raise”
Button2 = : title : f.raiselower

Button1 = : icon : f.function “move-or-iconify”
Button2 = : icon : f.iconify

Button1 = : iconmgr : f.iconify
Button2 = : iconmgr : f.iconify

#
# And a menus with the usual things
#
menu “defops”
{
“Twm” f.title
“Iconify” f.iconify
“Resize” f.resize
“Move” f.move
“Raise” f.raise
“Lower” f.lower
“” f.nop
“Focus” f.focus
“Unfocus” f.unfocus
“Show Iconmgr” f.showiconmgr
“Hide Iconmgr” f.hideiconmgr
“” f.nop
“Xterm” f.exec “exec xterm &”
“urxvt” f.exec “exec urxvt &”
“xcalc” f.exec “exec xcalc &”
“” f.nop
“Kill” f.destroy
“Delete” f.delete
“” f.nop
“Restart” f.restart
“Exit” f.quit
}

Advertisements

Tags: , , , , ,

About Darren

I'm a scientist by training, based in Australia.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s