Add an Auto Rotation Lock
My previous post was about enabling auto screen rotation in Ubuntu and today we'll extend that to add a rotation lock function. Step 1 is including checks to a locking file. I chose to create a hidden file in my home folder. All you have to do is replace the case section in the previous script with what I listed below.
case "$ORIENTATION" in
normal)
if [ ! -e .auto_rotation_lock ] ; then
xrandr --output eDP1 --rotate normal && gsettings set com.canonical.Unity.Launcher launcher-position Left
fi
;;
bottom-up)
if [ ! -e .auto_rotation_lock ] ; then
xrandr --output eDP1 --rotate inverted && gsettings set com.canonical.Unity.Launcher launcher-position Left
fi
;;
right-up)
if [ ! -e .auto_rotation_lock ] ; then
xrandr --output eDP1 --rotate right && gsettings set com.canonical.Unity.Launcher launcher-position Bottom
fi
;;
left-up)
if [ ! -e .auto_rotation_lock ] ; then
xrandr --output eDP1 --rotate left && gsettings set com.canonical.Unity.Launcher launcher-position Bottom
fi
;;
esac
Step 2 is creating a new script that creates the locking file. This one is a simple case of creating the file if it doesn't exist and removing the file if it already exists.
#!/bin/sh
# Create a locking file (.auto_rotation_lock) when the user presses Ctrl+Super+0
cd ~
if [ -e .auto_rotation_lock ] ; then
# Remove the locking file
rm .auto_rotation_lock
else
# Add the locking file
> .auto_rotation_lock
fi
And finally, step three is tying locking script to a keyboard shortcut so it will toggle the lock on and off.
Recent comments
7 years 32 weeks ago
8 years 21 weeks ago
8 years 33 weeks ago
8 years 34 weeks ago
8 years 35 weeks ago
8 years 46 weeks ago
9 years 19 weeks ago
9 years 41 weeks ago
9 years 41 weeks ago
9 years 41 weeks ago