Hack and / - Lightning Hacks
One of the more interesting parts of any conference is the lightning talks. If you haven't experienced one, a lightning talk typically features a number of different speakers, each giving a short (5–20 minutes) presentation. Lightning talks take advantage of the fact that often a speaker has an interesting topic to present, but the topic won't fill an entire hour time slot. So, lightning talks round up each of these speakers one after the other in the same time slot. Because of the variety of information and the fast nature of lightning talks, they can be really informative, interesting and definitely fun.
As I was considering what topic to cover for this month's column, I realized I had a number of different hacks I'd like to mention, but none that could really fill a full column. In the spirit of lightning talks, I decided to put all of these hacks together in true rapid-fire fashion.
In the March 2008 issue of Linux Journal, I introduced the wmctrl tool and discussed how to use it to move, resize, shade and do all sorts of window management tasks from the command line. I also introduced a few scripts I had written and bound to keys to resize and shade a few different windows on my desktop. Near the end of that article, I mentioned:
My next project is to create a “reset” script that moves all the windows on all of my desktops to precise locations and sizes, in case they all get moved around and resized. Sure, I could do all this by hand, but then I'd miss this great opportunity for automation.
Well, shortly after I wrote that, I completed my reset script. This script goes from desktop to desktop (or because I use Compiz, viewport to viewport) and moves and resizes windows per my specifications. I've added comments to explain particular sections:
#!/bin/sh
# First save my current viewport so I can return
# to it after I'm done
SAVED_VP=`wmctrl -d | perl -ne '/VP: (\d+,\d+)/; print $1;'`
# Then, move to the first viewport (at 0,0). Because it
# can take a second or two for this to take effect,
# I've opted to create a while loop that will
# continue to attempt to switch to that viewport
# until it detects it is actually there.
VP=0,0
while [ `wmctrl -d | perl -ne '/VP: (\d+,\d+)/;
↪print $1;'` != $VP ];
do
wmctrl -o $VP
done
# Now resize, move, and change state of particular
# windows (see the wmctrl man page, or my wmctrl
# column for more information on the options).
wmctrl -r 'Eterm Main 1' -e '0,0,0,645,420'
wmctrl -r 'Irssi Term' -e '0,469,0,810,500'
wmctrl -r 'Irssi Term' -b add,shaded
wmctrl -r 'Irssi Term' -b add,below
wmctrl -r 'gkrellm' -b add,sticky
wmctrl -r "Irssi Notify Term" -e '0,1180,550,100,230'
# I now switch to the second viewport. As my screen
# is 1280x768, the second viewport is at 1280,0.
# If I wasn't sure, I could switch to that viewport
# and check the output of wmctrl -d for the proper coordinates.
VP=1280,0
while [ `wmctrl -d | perl -ne '/VP: (\d+,\d+)/;
↪print $1;'` != $VP ];
do
wmctrl -o $VP
done
wmctrl -r "Mozilla Firefox" -e '0,5,0,1040,708'
# Finally I switch back to my original viewport
# so I'm back where I started.
wmctrl -o $SAVED_VP
Although there are certainly a lot of commands in that script, it actually didn't take long to write. Most of the script is simply one wmctrl command after another, and I spent a majority of the time actually fine-tuning the locations of each window and figuring out the best way to switch viewports. If your desktop environment uses multiple desktops instead of one desktop with multiple viewports, you would use the -s option to change desktops instead of the -o option, which is used for viewports. You also would need to change the logic in the while loop to something more like:
DESKTOP=1
while [ `wmctrl -d | perl -ne '/^(\d+).*?\*/;
↪print $1;'` != $DESKTOP ];
do
wmctrl -s $DESKTOP
done
Although I normally use my laptop with its own built-in screen, I frequently give presentations, so I need to display on both the LCD and the external VGA connector. Unfortunately, my laptop's function keys to toggle between those states don't currently work in Linux, so I've had to put it into a script paired with a keybinding.
The xrandr program works great with my laptop to toggle between displays, so my script first examines the output of xrandr to see whether the VGA port is connected, and if so, it adds it as a display. Otherwise, it disables VGA. I also added a line to echo some text to osd_cat. I installed this program so that I would get some output on the screen to let me know which mode my script had chosen. When I'm ready to output to a projector, I just connect it to my laptop and run the script. When I'm finished with the presentation, I disconnect it and run the script again:
#!/bin/sh
if xrandr | grep -q 'VGA connected'; then
echo "LVDS + VGA" | osd_cat --shadow=2 --align=center
↪--pos=bottom --color=green --delay=2
↪--font=lucidasanstypewriter-bold-24 --offset 40 &
# choose my laptop screen's resolution by default,
# if that fails try the auto-detected mode
xrandr --output VGA --mode 1280x768@60 || xrandr
↪--output VGA --auto
else
echo "LVDS only" | osd_cat --shadow=2 --align=center
↪--pos=bottom --color=green --delay=2
↪--font=lucidasanstypewriter-bold-24 --offset 40 &
xrandr --output VGA --off &
fi
I also created a separate version of the script that spans across both screens instead of mirroring. I chose to span below my current screen (with the --below LVDS option), but most people probably will prefer to use --right-of or --left-of:
#!/bin/sh
if xrandr | grep -q 'VGA connected'; then
echo "LVDS + VGA span" | osd_cat --shadow=2 --align=center
↪--pos=bottom --color=green --delay=2
↪--font=lucidasanstypewriter-bold-24 --offset 40 &
xrandr --output VGA --mode 1280x768@60 --below LVDS || xrandr
↪--output
VGA --below LVDS --auto
else
echo "LVDS only" | osd_cat --shadow=2 --align=center
↪--pos=bottom --color=green --delay=2
↪--font=lucidasanstypewriter-bold-24 --offset 40 &
xrandr --output VGA --off &
fi
Kyle Rankin is a systems architect; and the author of DevOps Troubleshooting, The Official Ubuntu Server Book, Knoppix Hacks, Knoppix Pocket Reference, Linux Multimedia Hacks, and Ubuntu Hacks.
Today’s modular x86 servers are compute-centric, designed as a least common denominator to support a wide range of IT workloads. Those generic, virtualized IT workloads have much different resource optimization requirements than hyperscale and cloud applications. They have resulted in a “one size fits all” enterprise IT architecture that is not optimized for a specific set of IT workloads, and especially not emerging hyperscale workloads, such as web applications, big data, and object storage. In this report, you will learn how shifting the focus from traditional compute-centric IT architectures to an innovative disaggregated fabric-based architecture can optimize and scale your data center.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
| Trying to Tame the Tablet | May 08, 2013 |
| Dart: a New Web Programming Experience | May 07, 2013 |
- New Products
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Home, My Backup Data Center
- RSS Feeds
- New Products
- Trying to Tame the Tablet
- What's the tweeting protocol?
- Dart: a New Web Programming Experience
- Hey God - You may not be
1 hour 26 min ago - Reply to comment | Linux Journal
3 hours 58 min ago - Drupal is an Awesome CMS and a Crappy development framework
8 hours 37 min ago - IT industry leaders
11 hours 23 sec ago - Reply to comment | Linux Journal
1 day 3 hours ago - Reply to comment | Linux Journal
1 day 6 hours ago - Reply to comment | Linux Journal
1 day 7 hours ago - great post
1 day 8 hours ago - Google Docs
1 day 8 hours ago - Reply to comment | Linux Journal
1 day 13 hours ago
Enter to Win an Adafruit Prototyping Pi Plate Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Prototyping Pi Plate Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- Next winner announced on 5-21-13!
Free Webinar: Linux Backup and Recovery
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.




Comments
thanks
thanks for the tip, i was looking for a tool like rdiff