Hack and / - Lightning Hacks Strike Twice
My laptop doubles as a tablet, and even though I don't use the tablet mode very often, when I do use it, I like to be able to rotate the screen around to portrait mode and back. Now, dock applications exist that can do this with a few clicks, and I always could just try to remember the right xrandr commands, but instead, I wrote a little script that I then bound to one of the hardware buttons on my laptop display. Each time I press the button, it runs the script and rotates the screen another 90 degrees.
The key to the script is to keep track of your current orientation. When xrandr rotates, it rotates only left, right, inverted or normal, so if you already are rotated to the left and rotate left again, it won't change. To accomplish this, I just write the current orientation to a temporary file. Listing 1 shows the full script.
Listing 1. Screen Rotation Script
#!/bin/sh export ORIENTATION=`cat /tmp/.orientation` if [ $ORIENTATION -eq "90" ]; then xrandr --auto xrandr --output LVDS --rotate inverted echo 180 > /tmp/.orientation echo "180" | osd_cat --shadow=2 --align=center \ --pos=bottom --color=green --delay=2 \ --font=lucidasanstypewriter-bold-24 \ --offset 40 & elif [ $ORIENTATION -eq "180" ]; then xrandr --auto xrandr --output LVDS --rotate left echo 270 > /tmp/.orientation echo "270" | osd_cat --shadow=2 --align=center \ --pos=bottom --color=green --delay=2 \ --font=lucidasanstypewriter-bold-24 \ --offset 40 & elif [ $ORIENTATION -eq "270" ]; then xrandr --output LVDS --rotate normal echo "Normal" | osd_cat --shadow=2 --align=center \ --pos=bottom --color=green --delay=2 \ --font=lucidasanstypewriter-bold-24 \ --offset 40 & echo 0 > /tmp/.orientation else xrandr --auto xrandr --output LVDS --rotate right echo 90 > /tmp/.orientation echo "90" | osd_cat --shadow=2 --align=center \ --pos=bottom --color=green --delay=2 \ --font=lucidasanstypewriter-bold-24 \ --offset 40 & fi
Notice in Listing 1 that I also added an echo piped to osd_cat. This is optional and just displays the current orientation on my screen. If you want to use this, be sure you have the osd_cat utility (it's included with the xosd-bin package in Debian and Ubuntu). The way the script is set up, it will run through each of the orientations in order before it goes back to normal. Because the temporary file will be deleted any time the machine reboots, I made sure to set the default mode to rotate 90 degrees.
Kyle Rankin is a Senior Systems Administrator in the San Francisco Bay Area and the author of a number of books, including Knoppix Hacks and Ubuntu Hacks for O'Reilly Media. He is currently the president of the North Bay Linux Users' Group.
Kyle Rankin is a VP of engineering operations at Final, Inc., the author of a number of books including DevOps Troubleshooting and The Official Ubuntu Server Book, and is a columnist for Linux Journal. Follow him @kylerankin.
|Nativ Disc||Sep 23, 2016|
|Android Browser Security--What You Haven't Been Told||Sep 22, 2016|
|The Many Paths to a Solution||Sep 21, 2016|
|Synopsys' Coverity||Sep 20, 2016|
|Naztech's Roadstar 5 Car Charger||Sep 16, 2016|
|RPi-Powered pi-topCEED Makes the Case as a Low-Cost Modular Learning Desktop||Sep 15, 2016|
- Android Browser Security--What You Haven't Been Told
- Nativ Disc
- The Many Paths to a Solution
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Recovery of RAID and LVM2 Volumes
- Naztech's Roadstar 5 Car Charger
- Securing the Programmer
- Synopsys' Coverity
- RPi-Powered pi-topCEED Makes the Case as a Low-Cost Modular Learning Desktop
- Glass Padding
With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.
This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.Get the Guide