Customizing Motif



next up previous contents index
Next: Button Bindings Up: Personalizing X Windows Previous: X Startup: .xinitrc

Customizing Motif

In §4.6, Your Workspace: xterm, we will provide examples of using menu items. Before we do that we suggest you make your X life more pleasant by becoming more familiar with how the Motif Window Manager mwm works. Specifically, by modifying the .mwmrc file in your home directory, you customize menu items and mouse buttons to include routine tasks.  

When your login account was first created and Unix initialized you, it probably gave you a general purpose .mwmrc file. If you do not now have such a file in your home directory, look for the standard .mwmrc file contained in /usr/lib/X11/system.mwmrc and copy it into your home directory. (We have provided a sample .mwmrc in Appendix 6.) Look at this .mwmrc file with your favorite editor-but first make a copy, say to .mwmrc.bk, just in case your customizations leave the system in shreds. The file may look rather confusing at first (and at last), but follow a basic rule of Unix survival is to ignore most of the file and worry only about the parts that interest you and which you can understand.

In .mwmrc there should be a section that looks something like this:


# Root Menu Description .mwmrc file. Menu RootMenu { "Root Menu" f.title no-label f.separator "New Window" f.exec "xterm \&" "Shuffle Up" f.circle_up "Shuffle Down" f.circle_down "Refresh" f.refresh no-label f.separator "Restart..." f.restart "Quit" f.quit_mwm }

The left column is the menu which appears when you click on the background with mwm. You may also note some other menus, like Default Window Menu Mwm Window Menu. These additional menus appear when you click on an individual window's menu button (the one to the left of the window), in contrast to the menus which appear when you click on the background. Looking at this Root Menu you see how several functions are accomplished in mwm. The menu has a name, in this case Root Menu, and each line in the menu has two fields. The first field is a string or label which appears in the menu, and the second is a command to be executed when the user selects that menu line.

The first two lines in this .mwmrc file really don't do much. The f.title just gives the title for the menu, while the f.separator draws a line in the menu to separate the title from the menu items. Notice that f.separator is also used to separate the Restart and Quit operations. The third item, "New Window" f.exec "xterm &," is of more interest. Selecting it executes the program xterm, which in turn opens a new window on your screen. What's interesting is the technique. You can insert lines in your .mwmrc file to create menu lines to run any command, even a shell script.gif To run your own command, add a line to the menu with a label, then the mwm command f.exec, and then the command you want to run. Here is an example of a menu item to bring up a calculator:


"Calculator" f.exec "/usr/bin/X11/xcalc >/dev/null 2>/dev/null \&" Calculator window.

Notice first that the menu item label "Calculator" is surrounded by quotes. Next notice that the mwm command f.exec executes the following Unix command in the Borne shell. The command string which actually runs the calculator program is also surrounded by quotes and appears exactly as it would if you were typing a command line in the Born shell (or its cousin, the Korn shell). It is important to also observe that the command string ends with an ampersand & so it will be executed in the background; otherwise, the window manager would be stalled waiting for the menu command to complete.

The redirector >in our Unix command string redirects the standard output and its standard error to /dev/null. The device /dev/null is a black hole where you send data you never care to see again. It is generally a good practice to redirect output from menu commands to this black hole because there is no hope of seeing this output anyway and this will keep the window manager from being disturbed by your blunders.

Finally, notice that in the code line we're examining we used the full path name for the calculator program. This may not be necessary since the window manager uses the same path as the login shell, but it does not hurt to be sure. Using full path names also makes the command more robust since systems and procedures change, and it eliminates any ambiguity you or others may have as to what program is executed. For example, on our current system there are two different xterm programs, /usr/bin/X11/xterm, which came with the system, and /usr/local/bin/X11/xterm, which is a newer version we got from a friend. By using the full path name, we ensure which one will run.

Let us now return to modifying the .mwmrc file. After you add the new menu line, the window manager must reread the file before the changes are affected. The easiest way to do this is to use the menu item marked Restart which makes mwm run f.restart, which in turn makes the window manager reread the setup files and start over. There is the danger that an error in the new .mwmrc file (like unmatched quotes) will cause mwm to die or work improperly. If you are lucky enough in this case to still have an X window available, you can work within that window to fix the mistake, kill mwm, and then restart by issuing the command (from the command line): 

$ mwm &   	Restart mwm.    

If the window manager is really confused, you should kill the X Windows System, use your terminal in its text mode to fix the file, and then restart X.

Now, if you are really going to be playing around with your X environment a lot, a safer way to personalize it is to use a shell command for the window manager which switches back and forth between the default and your personal .mwmrc:

$ alt ctrl shift !   	Toggle between .mwmrc files.     

Yes, this really does mean striking the alt, ctrl, shift, and ! keys all at the same time (easy for you concert pianists out there). A dialog box should appear asking if you want Toggle Behavior. If you click on Yes, mwm restarts using the system defaults. Toggling again makes mwm restart using your .mwmrc file.

The remaining menu lines in the preceding example are built-in window manager commands. To avoid interruption of your personal games you may want to move these to a separate, cascade menu controlled by a different mouse button. These cascade menus are convenient for grouping similar commands. To make one, first create a new menu and then add a menu line to the root menu. Here is an example in which we add a Tools line to the RootMenu:


# Root Menu Description Menu RootMenu { "Root Menu" f.title no-label f.separator "New Window" f.exec "xterm \&" "Tools" f.menu Tools "Shuffle Up" f.circle_up "Shuffle Down" f.circle_down "Refresh" f.refresh no-label f.separator "Restart..." f.restart "Quit" f.quit_mwm }

Now we add a new Tools Menu to our .mwmrc file:


Menu Tools Create cascade menu. { "Tools" f.title "Xrn" !"(xrn)\&" "xcalc" !"(xcalc)\&" "xlock" !"(xlock)\&" }



next up previous contents index
Next: Button Bindings Up: Personalizing X Windows Previous: X Startup: .xinitrc