Useful Things You Can Do with FVWM
I have a script called convert-xwd that makes the process of converting a slew of XWD files much easier. If you supply arguments, it assumes they're the names of XWD files and converts them to PNG format. If you supply no arguments, it finds all of the XWD files in the current directory and converts them. After successfully converting an XWD file to PNG, it deletes the XWD file. Here's the script:
#!/bin/bash
main() {
if [ $# = 0 ]
then
do_files *
else
do_files "$@"
fi
}
do_files() {
local file
for file in "$@"
do
if file "$file" | fgrep -q ": XWD X-Windows Dump image data,"
then
echo "Doing $file"
convert "$file" "$file.png" && rm "$file"
fi
done
}
main "$@"
I've given two sample invocations of savescreenshot. Now it's time to explain what they do. As the accompanying labels suggest, when run with no arguments, savescreenshot simply saves a screenshot, and when passed the -n option, it saves and names a screenshot.
savescreenshot uses two directories, $HOME/.screenshots/t and $HOME/.screenshots/n. If they don't exist, it creates them. In the first directory, savescreenshot saves a screenshot whose name has the form of NNN-HHMM.SS. NNN is a three-digit number representing the number of the day in the year, HH is a two-digit number representing the hour, MM is a two-digit number for the minute and SS is a two-digit number for the second.
The second directory, $HOME/.screenshots/n, is left untouched unless the -n option was given. If it was, savescreenshot pops up a window to ask the user what name the screenshot should have. After the user has answered, savescreenshot creates a symbolic link, using the name entered in the popup window, in $HOME/.screenshots/n pointing to the screenshot in $HOME/.screenshots/t.
The user needs to know when the screenshot has been taken so that he can continue interacting with the window he's dumped. xwd beeps when it's finished, but in case you have the bell disabled, as I do, savescreenshot also makes the screen flash red when xwd has completed.
Here's the savescreenshot program. I don't believe it needs much comment. One thing to note, however, is it handles prompting the user for a name by invoking itself again with a private option.
Another interesting feature is the savescreenshot program attempts to delay the screenshot a little if it believes the window may be slow to update. This can happen with windows whose contents are fetched over a network. Examples of applications that create such windows are remote administration programs such as VNC and rdesktop.
#!/bin/bash
main() {
dir=~/.screenshots
timedir=$dir/t
namedir=$dir/n
test -e "$timedir" || mkdir -p "$timedir"
test -e "$namedir" || mkdir -p "$namedir"
menu_linger_time=.1
# we wait this amount of time to allow for the menu obscuring the
# window to disappear.
prompt_for_name=false
timestamp=`date +%j-%H%M.%S`
case "$1" in
-n)
prompt_for_name=true
shift
;;
-p)
timestamp=$2
read -p "Please supply name for screenshot: " name
ln -s "../t/$timestamp" "$namedir/$name"
exit
esac
window_id=$1
sleep $menu_linger_time
sleep `get_delay_for_update $window_id`
xwd -id "$window_id" -out "$timedir/$timestamp"
xrefresh -solid red
# this is to inform the user that xwd has finished.
sleep .5
xrefresh -solid red
# just in case the user blinked and missed the first flash.
if $prompt_for_name
then
title="Please supply name..."
x rxvt -T "$title" -n "$title" -e "$0" -p "$timestamp"
fi
}
# this function estimates how long it will take the application to repaint
# the part of the window uncovered when the FVWM menu obscuring it disappears.
# most applications repaint almost instantaneously, but some applications which
# need to fetch data over a network in order to repaint take a little time.
#
# this method isn't failsafe, because the window's title may have been
# manually changed.
get_delay_for_update() {
local window_id=$1
case "`window_title "$window_id"`" in
TightVNC:\ *)
echo 2
;;
rdesktop\ *)
echo 1
;;
*)
echo 0
esac
}
window_title() {
local window_id=$1
xwininfo -id "$window_id" | perl -ne 'if(/"(.*)"\s*$/) { print $1; exit }'
}
main "$@"
Making screenshots is a good thing to know how to do, but sometimes you want to capture continuous video. Here's a link to an interesting article on Newsforge that describes how to do this task.
Your FVWM undoubtedly is configured to put a titlebar at the top of every window. To be entirely accurate here, I should have said nearly every window. Some applications, such as xbiff, create small persistent windows, and putting a titlebar on them would clutter the screen needlessly. These titles also are used by window-listing facilities, such as FVWM's WindowList command or its FvwmWinList module.
Below I present a program that easily changes the title on a window. It is invoked by opening the window operations menu--the same one we modified in the previous section--choosing the Change title option and entering the new title when prompted, whereupon the window's title is changed.
I often find that I have many windows open at one time. They obscure one another, of course, so the only way to manage them and bring up the one I want when I need it is to use some window-listing facility.
In order for me to be able to find the window I want in the list, windows need to have informative titles. Applications don't always choose informative titles for their windows, however. Furthermore, sometimes the functions of windows change over time, making the initial title inappropriate. Other times, I start several instances of one application, and they all use the same title, making it impossible to distinguish between them.
I've covered modifying FVWM menu definitions in an earlier section (see FVWM Menu Definitions), so I won't go over it again. Instead, below is the line you need to add to the relevant menu definition in order to be able to change the title:
+ "Change &title" Exec set-new-title $w
As before, if set-new-title isn't in the PATH, you have to use an absolute pathname.
Here's the program, called set-new-title. It relies on xwit, which is the utility that actually changes the title.
#!/bin/bash
set -u
main() {
window_id=$1
title=`xwininfo -id "$window_id" | perl -ne 'print $1 if /"(.*)"\s*$/'`
if ! tempfile=`mktemp`
then
echo "Cannot create temporary file" 1>&2
exit 1
fi
echo "$title" > "$tempfile"
popup_window_title="Choose new title in editor, then save and exit..."
rxvt -T "$popup_window_title" -n "$popup_window_title" \
-e "${EDITOR:-vi}" "$tempfile"
newtitle=`head -c 1000 "$tempfile"`
xwit -id "$window_id" -name "$newtitle"
}
main "$@"
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
| Introduction to MapReduce with Hadoop on Linux | Jun 05, 2013 |
- Containers—Not Virtual Machines—Are the Future Cloud
- Non-Linux FOSS: libnotify, OS X Style
- Linux Systems Administrator
- Validate an E-Mail Address with PHP, the Right Way
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- RSS Feeds
- Introduction to MapReduce with Hadoop on Linux
- user namespaces
48 min 42 sec ago - yea
1 hour 14 min ago - One advantage with VMs
3 hours 43 min ago - about info
4 hours 16 min ago - info
4 hours 17 min ago - info
4 hours 18 min ago - info
4 hours 20 min ago - info
4 hours 21 min ago - abut info
4 hours 22 min ago - info
4 hours 23 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?



Comments
Useful Things You Can Do with FVWM
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
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?
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
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
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
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
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.