"Linux Gazette...making Linux just a little more fun!"


Fvwm Configuration in Different Environments using cpp

By Gerd Bavendiek,


Do you use Linux at home ? In the office ? On a laptop ? Do you use fvwm 2.xx or fvwm95 as your windowmanager ?

If yes, you should read on.

Perhaps you have read my article about Using a Laptop in Different Environments. There I described an easy way to setup a Linux laptop to boot into different network configurations. I mentioned that setting up a shell variable called PROFILE is useful not only for configuring the network but also the windowmanager.

Why should you do that ?

Your windowmanager needs to be configured quite different when you are using it on a laptop with 600x420 pixel or on a 17"-monitor with 1024x768 pixel. This is a rather basic difference - there may be others. Think of using your system in a network environment. There it will be handy to have a taskbar labeled appropiate to rlogin-sessions. After fiddling some time with patching different fvwm configuration files on different machines I found this to be a pain. A typical .fvwm95rc is about 900 lines. Keeping several of them in sync is not the thing I like.

Generating ~/.fvwm95rc using cpp

My solution is simple: Use cpp, the C-preprocessor ! fvwm 2.xx as well as fvwm95 are configured by a central file. fvwm95 is derived from fvwm, so the basic idea applies to both. Let me show you the details using fvwm95. I keep my fvwm95 configuration in the file ~/.fvwm95rc-cpp.

You can use the system default setup in /etc/X11/fvwm95/system.fvwm2rc95 as starting point. Look at this code fragment from my .xinitrc (For me, .xsession is linked to .xinitrc):

...
# I need the value of PROFILE for generating .fvwm95rc
# netenv contains an assignment like e.g. PROFILE=32
if [ -r /tmp/netenv ]; then
. /tmp/netenv
fi

# Now the actual .fvwm95rc is generated depending on the value of PROFILE
cpp -lang-c++ -D PROFILE=$PROFILE ~/.fvwm95rc-cpp ~/.fvwm95rc

exec fvwm95 # exec saves the extra memory for a no longer useful shell ...
...
The shell variable PROFILE contains the information about the current environment. The file /tmp/netenv is set up by init when going to run level 2. I described this in the article mentioned above. Obviously you need cpp, which comes either as an extra package or as part of gcc. Yes, I know that there is a module FvwmCpp (which calls cpp) - but I never managed to get it work.

One advantage of the old-fashioned style of configuration files is that you can put comments in. You really should do this ! All that hidden dot files in your home directory make up your personal environment (these files will never be touched by a system update). Having comments will make it easier to maintain this environment.

system.fvwm95rc comes in shell style comment syntax (so does fvwm). You can't feed this into cpp. I didn't like traditional c-style comments in a configuration file, so I switched all these comment lines

# this is a useful comment
      
into c++-style comments
// this is a useful comment
      
(hail emacs !). Calling cpp with
-lang-c++
      
tells cpp to preprocess c++-code. A hint for those, who are not familiar with cpp: cpp strips off the comment lines of the input file. You probably will get output with a lot of blank lines.

Examples how to use cpp-syntax

Now let us have a look inside my .fvwm95rc-cpp. Of course, everything herein is strongly a matter of personal taste.

I don't like to stress my eyes. So I hate small letters, I barely can read them in the evening of a long day ... So my desktop has 4x2 pages. Each page is assigned to one application (or a few). I use <Alt><F1> to <F8> to switch quickly between pages. Using the fabulous fvwm95 mini icons my screen holds the FvwmTaskBar and on the right hand side a column holding some icons. This way I can maximize the application window.

The screenshot should make it clear.

Defining geometry

One important application is xemacs for me. So I define a mini button in the FvwmButtons section like this:
*MiniButtons -   mini-edit.xpm        Exec  "Xemacs" /usr/bin/xemacs \
                                      -geometry EMACS_GEO &
      
EMACS_GEO is to be substituted by cpp. I put all the #define in the beginning of my .fvwm95rc-cpp. Basically it reads like this
#if PROFILE == 30 || PROFILE == 31 || PROFILE == 32 
#define EMACS_GEO 80x25+0+480
#else
#define EMACS_GEO 96x31+0+767
#endif
      
Whenever I'm on my laptop, PROFILE equals 30, 31 oder 32 (at home, in the office, on customers site). The LCD-Display has 600x420 pixel. My other systems have 17" monitors and there I use 1024x768. The +0+480 or +0+767 pops up the xemacs window on the leftmost page on the bottom row of my 4x2 desktop. But this is true only when being on the very first page while clicking the icon. I'm shure, this could be improved.

With defining

Key F5          A       M       GotoPage 0 1
      
I can conveniently switch to my xemacs window using without leaving the keyboard.

Launching applications

Being at home or in the office, I have usually some rlogin sessions to some well known machines. Being on a customers site I frequently have to work with high availability configurations mostly consisting of two machines. I call them always abba and bebe. See how this can be set up (shortened for clarity):
DestroyFunc "InitFunction" 
#if PROFILE == 30
AddToFunc "InitFunction" \
  "I" Exec xsetroot -solid turquoise4 -cursor_name top_left_arrow &
+ "I" Exec xconsole -font 6x10 -geometry XCONSOLE_GEO -sb -file /dev/xconsole &
+ "I" Exec rxvt -geometry 94x28+0+0 -fn DEF_FONT -ls -sb -vb \ 
                          -title TERMWIN_ID1 -n TERMWIN_ID1 -cr Yellow3 &
+ "I" Exec rxvt -geometry TERMWIN_GEO2 -fn DEF_FONT -ls -sb  -vb \
                          -title TERMWIN_ID2 -n TERMWIN_ID2 -cr Red3 &
+ "I" Exec rxvt -geometry TERMWIN_GEO3 -fn DEF_FONT -ls -sb  -vb \
                          -title TERMWIN_ID3 -n TERMWIN_ID3 -cr Magenta3 &
+ "I" Module FvwmButtons MiniButtons
+ "I" Module FvwmTaskBar
+ "I" Module FvwmAuto 700
+ "I" Module FvwmPager 0 0
#elif PROFILE == 10
...
#else
AddToFunc "InitFunction" \
...
...
+ "I" Exec rxvt -geometry 94x28+0+0 -fn DEF_FONT -ls -sb -vb \
                          -title TERMWIN_ID1 -n home -cr Yellow3 &
+ "I" Exec rxvt -geometry TERMWIN_GEO2 -fn DEF_FONT -ls -sb  -vb \
                          -title TERMWIN_ID2 -n TERMWIN_ID2 -cr Red3 &
+ "I" Exec rxvt -geometry TERMWIN_GEO3 -fn DEF_FONT -ls -sb  -vb \
                          -title TERMWIN_ID3 -n TERMWIN_ID3 -cr Magenta3 &
+ "I" Exec rxvt -geometry TERMWIN_GEO4 -fn DEF_FONT -ls -sb  -vb \
                          -title TERMWIN_ID4 -n TERMWIN_ID4 -cr Green3 &
+ "I" Exec rxvt -geometry TERMWIN_GEO5 -fn DEF_FONT -ls -sb  -vb \
                          -title TERMWIN_ID5 -n TERMWIN_ID5 -cr Blue3 &
...
...
#endif

The terminal geometry und identifiers are defined as follows:

#if PROFILE == 10
#define TERMWIN_ID1 bav@nana
#define TERMWIN_ID2 nana
#define TERMWIN_ID3 lulu
#elif PROFILE == 20
...
#elif PROFILE == 30
...#define TERMWIN_ID1 bav@lulu
#elif PROFILE == 31
...
#elif PROFILE == 32
#define TERMWIN_ID1 bav@lulu
#define TERMWIN_ID2 lulu
#define TERMWIN_ID3 abba
#define TERMWIN_ID4 bebe
#define TERMWIN_ID5 abba
#endif

Conclusion

Screen geometry and network environment differ from one machine to another. Everyone, who wants to have one configuration file for his fvwm 2.xx or fvwm95 to reflect these differences, should consider to use cpp as shown.

Perhaps you know, that xrdb(1) also can make use of cpp. So you can preprocess your ~/.Xdefaults achieving the discussed advantages.

I hope you will find these ideas somehow useful !

Kind regards

Gerd



Copyright © 1997, Gerd Bavendiek
Published in Issue 21 of the Linux Gazette, September 1997


[ TABLE OF CONTENTS ] [ FRONT PAGE ]  Back  Next