Useful Things You Can Do with FVWM
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.
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.
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
- Non-Linux FOSS: Don't Drink the Apple Kool-Aid; Brew Your Own!
- Preseeding Full Disk Encryption
- Returning Values from Bash Functions
- William Rothwell and Nick Garner's Certified Ethical Hacker Complete Video Course (Pearson IT Certification)
- Three EU Industries That Need HPC Now
- Hodge Podge
- FinTech and SAP HANA
- How to Calculate Flash Storage TCO
- Two Ways GDPR Will Change Your Data Storage Solution
- HOSTING Monitoring Insights