Useful Things You Can Do with FVWM

Learn how to take screenshots quickly, change window titles and reconfigure a running FVWM instance.
Adding Our Own Action to the Menu

Suppose we want a simple way of saving a screenshot of the current window, so that when we select the correct option from a menu, a screenshot is saved to the file /tmp/screenshot. We can achieve this by adding the following line to the end of the AddToMenu command listed above:


  + "Take screenshot" Exec xwd -id $w -out /tmp/screenshot

Let's examine how this works. As already explained, the first two elements of the line are a plus sign and a label. Then comes the FVWM command, which in this case is:


  Exec xwd -id $w -out /tmp/screenshot

The command name is Exec, which allows one to execute an external command. Its arguments are the external command, followed by the external command's arguments. In this case, the external command is xwd, and the arguments passed to it by FVWM are -id $w -out /tmp/screenshot.

The notation $w in these arguments needs some explanation. It's a special FVWM variable that stands for the window ID of the current window. When FVWM runs the above xwd command, it replaces the argument $w with the relevant window ID.

What is a window ID? The X Window System needs a way of identifying and referring to windows. It does so by assigning each window a unique number, known as the window ID.

For our purposes, you don't need to understand xwd's other arguments just yet. For now, all you need to know is that the command given above causes xwd to put a screenshot of the current window in the file /tmp/screenshot.

At this point, you may be asking, FVWM has many menus; how do I identify the one I need to modify? The answer is the correct one probably is the one called Window-Ops2, but it all depends on whoever packaged and configured FVWM for you. The best way to find the correct menu is to search your FVWM config file for a menu that uses all or most of the following functions: Move, Resize, Raise, Lower, Iconify, Close. If you find such a menu, it's almost certainly the right one.

Running Our Window-Dumping Program

We've completed the preliminaries and now are ready to start looking at the promised solution. It involves a program I call savescreenshot. To have FVWM run it to take a screenshot, we add the following line to the appropriate AddToMenu command:


  + "Take screens&hot" Exec savescreenshot $w
  + "Take &named screenshot" Exec savescreenshot -n $w

You need to make sure savescreenshot can be found by searching the PATH that was defined when FVWM was invoked. If it can't, you can use an absolute pathname for savescreenshot. Also, notice that the above labels make H and N into hotkeys.

xwd, xwud and Conversion Programs

To actually take the screenshot, savescreenshot relies on xwd. Although several screenshot utilities exist, I chose xwd because it comes packaged with X. xwd's basic usage is as follows:


xwd [-id window_ID] [-out output_file]

where window_ID and output_file should be replaced by the actual names of the window ID and output file, respectively.

The -out option, as the summary above suggests, directs xwd's output to the specified output file; if you don't supply it, xwd writes to its standard output. The -id option tells xwd to use the window with the specified window ID. If you don't supply it, xwd changes the mouse pointer's shape to indicate that it wants you to click in a window to select it. When you've done so, it takes a screenshot of that window.

xwd uses its own special image format. This format doesn't use compression, so output files often are quite large. You usually want to convert the output file to a format such as PNG; I'll cover this in a minute.

To view xwd's output files, you can use xwud, which also comes packaged with X. You can specify an input file with the -in option. The command xwud -in browser-window would display the screenshot stored in the file browser-window.

To convert files in xwd format, you can use convert from the ImageMagick suite. The following commands convert an image to various common formats and should be self-explanatory:


  convert browser-window browser-window.png
  convert browser-window browser-window.jpg

If you want to use the netpbm tools, the following two commands correspond to the two commands above:


  xwdtopnm < browser-window | pnmtopng > browser-window.png
  xwdtopnm < browser-window | pnmtojpeg > browser-window.jpg

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Useful Things You Can Do with FVWM

Thomas Adam's picture

Not a bad article on the whole. :) My only gripe with it is that you seem to ignore Fvwm's internal functionality in favour of using superfluous external shell-scripts. Why? For instance, you could use Fvwm{Script,Form} to do all of the preconfigurations easily enough. Not to mention this is the whole reason "PipeRead" exists.

Your title change of window is slightly OTT as well. It would be better to outline the power of Fvwm by actually using its features rather than showing us how good it is to call external scripts. One trick that you can do to title windows:


AddToFunc TitleMeDifferently
+ I ThisWindow ($0) PipeRead 'echo exec xprop -id $[w.id] -set WM_NAME \"$1\"'

Then you can use:


TitleMeDifferently xterm somenewtitle

FVWM for Artists

Anonymous's picture

FVWM can be set up with multiple desktops and zero edge resistance so that an aquired graphic can be stretched across as many desktops as required so that one aquired dot or one print out dot equals one screen pixel.
The results of modifying edges and shading can be seen on a real looking picture as it would appear in the output.

Nice, but what's with all the shell scripts?

Paul Smith's picture

FVWM has a number of modules, including things like FvwmForm which give you a very simple-to-use graphical form generator, that is much nicer for asking users for input than popping an xterm/rxvt and asking from the shell. Someone else commented on starting a new xterm on a remote system; as an example of using FvwmForm I show one I use to do this:


$ cat ~/.fvwm/XTermForm
# -*-fvwm-*-
#
# This is an FvwmForm definition file for creating specific xterms

DestroyModuleConfig XTermForm*

*XTermForm: WarpPointer

*XTermForm: Line center
*XTermForm: Text "Create New XTerm"
*XTermForm: Line left
*XTermForm: Text "Username:"
*XTermForm: Input UserName 12 "psmith"
*XTermForm: Line left
*XTermForm: Text "Login to host:"
*XTermForm: Input HostName 32 "localhost"
*XTermForm: Line left
*XTermForm: Text "Start on host:"
*XTermForm: Selection LocalSel single
*XTermForm: Choice Local Local on "Local"
*XTermForm: Choice Remote Remote off "Remote"
*XTermForm: Line expand
*XTermForm: Button quit "Create" ^M
*XTermForm: Command Exec rterm -l $(UserName) $(Remote?-r) $(HostName)
*XTermForm: Button restart "Clear"
*XTermForm: Button quit "Cancel" ^[
*XTermForm: Command Nop

Then in one of my menus I have:


+ "%menu/terminal.xpm%XTerm" Module FvwmForm XTermForm

(the stuff between the %...% in the menu title is the name of an icon to put in the menu.)

The rterm mentioned above is a script I wrote that handles creating terminals remotely (with DISPLAY set to my local host) or locally (then logging in within the xterm), with different users, etc. It's sort of customized to my environment so I won't include it but it should be straightforward to write your own, or you can simplify things by leaving out the local/remote option altogether.

I actually have a bunch of these forms for different kinds of things; it really helps create a more integrated desktop.

Or, if you're using Gnome with FVWM you can invoke zenity (see the man page) from your shell script to get a GTK dialog which looks nice. I'm sure KDE has something similar.

And there is another, even more powerful FVWM module for this kind of thing called FvwmScript; I've not used that one though.

rxvt is used so user has favourite editor available

The author's picture

Hi Paul. The reason for popping up a terminal
emulator, rather than using FvwmForm or any other
graphical dialog program, is that I want to give
the user the opportunity to use their favourite
text editor. I know that I'm much faster with
vi than I would be with FvwmForm.

Besides, hardened command-line junkies like me
regard GUIs as a necessary evil, and choose
atavistic command-line solutions whenever
possible.

xwd vs import

tjw's picture

I've found that ImageMagick's import utility is in most cases better at capturing screenshots than xwd. xwd often has troubles with windows such as media players, rdesktop, and emulators.

The equivalent of:

xwd -id $w -out /tmp/screenshot && convert /tmp/screenshot /tmp/screenshot.jpg

is:

import -window $w /tmp/screenshot.jpg

Two additional tricks

Anonymous's picture

Two additional tricks I've found useful:

1) create a root window menu item that opens a new xterm connected to a remote host. This requires setting up SSH to support X11 forwarding and using RSA keys so you don't have to use a password.

main-menu-pre.hook:

+ "chaos" Exec /usr/bin/ssh -X -f chaos.example.com "/usr/bin/X11/xterm -T chaos"

You should only use this with trusted systems, but it can be a real timesaver since you can then easily launch any remote X application.

2) set up a dynamic background image that indicates system load. Many people find this annoying, but I've found it useful (in those rare occasions when the desktop isn't wallpapered by windows) since it provides some visual feedback when the system is overloaded.

init.hook:

+ "I" Exec /usr/X11R6/bin/xlock -inroot -mode qix &

If this is too busy you could use xearth, xfishtank, or any other screensaver that can be run on the root window.

This has one other cute "feature" - it tends to blow away Windows users. :-)

xscreensaver hacks

Anonymous's picture

All of the xscreensaver display modes, or "hacks", are separate programs that you can use to animate your desktop background by running with the -root command-line option. Each xscreensaver hack has its own man page, so if you want a slow-motion desktop pattern, check the man page for a speed or "-cycle-delay" option.

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix