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 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 |
- RSS Feeds
- 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
- Home, My Backup Data Center
- A Topic for Discussion - Open Source Feature-Richness?
- Dart: a New Web Programming Experience
- Developer Poll
- May 2013 Issue of Linux Journal: Raspberry Pi
- What's the tweeting protocol?
- great post
28 min ago - Google Docs
50 min 31 sec ago - Reply to comment | Linux Journal
5 hours 38 min ago - Reply to comment | Linux Journal
6 hours 25 min ago - Web Hosting IQ
7 hours 59 min ago - Thanks for taking the time to
9 hours 36 min ago - Linux is good
11 hours 33 min ago - Reply to comment | Linux Journal
11 hours 51 min ago - Web Hosting IQ
12 hours 21 min ago - Web Hosting IQ
12 hours 21 min 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
dual head ?
I know that in ubuntu is now allowed to enable dualhead monitor and that probably it is done with xrandr. What about it on other distro ? on fedora there is something related in desktop configuration but it seem to not work
Help Stomp out Control-C programming
two things about this article; first use ssh-copy-id to setup authorized keys on remote hosts.
second, the copy-pasted code in your orientation script drove me nuts so i rewrote it.
#!/bin/sh ORIENTATION_FILE="/tmp/.orientation" function set_orientation() { local orientation="$1" if [ "$orientation" -ne "270" ]; then xrandr --auto fi xrandr --output LVDS --rotate $orientation record_orienation "$orientation" } function record_orientation() { echo "$1" > $ORIENTATION_FILE } function get_orientation() { echo "$(cat $ORIENTATION_FILE)" } function set_osd() { local message="$1" osd_cat --shadow=2 --align=center \ --pos=bottom --color=green \ --delay=2 --font=lucidasanstypewriter-bold-24 \ --offset 40 < "$(cat $message)" } case "$(get_orientation)"; in '90') set_orientation "180" set_osd "180" ;; '180') set_orientation "270" set_osd "270" ;; '270') set_orientation "0" set_osd "Normal" ;; *) set_orientation "90" set_osd "90" ;; esac exit 0Some problems here
I believe you cannot call a function before defining it. i.e. record_orientation should be defined above set orientation.
I don't think you can pass '0' '90' '180' or '270' as arguments to xrandr
Also I think the xrandr syntax is outdated for ubuntu 9.04 users in both this rewrite and the original lightning hack.
Line 34: case statement: remove the ';' before 'in'
schelcj: Did you test this before posting it?
-Z