This dual function script, mounts and unmounts partitions, and also rotates screen/touchpad/touchScreen...
Creates mount directory in /Here is a significant update to Mounter_Rotator_2.0.
UPDATE!!: In this update I have added functions for window placement (top,bottom,left,right,topleft,topright,bottomleft.bottomright) using wmctrl (dependency).
The menu now has an entry to add my custom keycodes to sven, and restart sven.
To rotate screen press WinKey + arrows. To place windows in screen halves press Ctrl + arrows. To place selected window in quarter screen positions press Alt + arrows. The script does not add keycodes if such codes are already used. In that case you will need to change keycodes manually first.
Mounter_Rotator_3.0
Code: Select all
#!/bin/sh
# Copyright (C) 2014 stemsee
# gpl v3 license applies for personal use
#[[ "`whoami`" != "root" ]] && exec sudo -E -S ${0} "$\""
res=`xwininfo -root | grep -e 'Height' -e 'Width' | awk '{print $2}'`
XX=`echo $res | awk '{print $1}'`
YY=`echo $res | awk '{print $2}'`
export lng="$2"
function BH
{
YY=$(((YY / 2) - 33))
wmctrl -r :ACTIVE: -e 0,0,$YY,$XX,$YY
}
function TH
{
YY=$((YY / 2))
wmctrl -r :ACTIVE: -b remove,maximized_horz,maximized_vert
wmctrl -r :ACTIVE: -e 0,0,0,$XX,$YY
}
function LH
{
XX=$((XX / 2))
YY=$((YY - 56))
wmctrl -r :ACTIVE: -b remove,maximized_horz,maximized_vert
wmctrl -r :ACTIVE: -e 0,0,0,$XX,$YY
}
function RH
{
XX=$((XX / 2))
YY=$((YY - 56))
wmctrl -r :ACTIVE: -b remove,maximized_horz,maximized_vert
wmctrl -r :ACTIVE: -e 0,$XX,0,$XX,$YY
}
function LHU
{
XX=$((XX / 2))
YY=$((YY / 2))
wmctrl -r :ACTIVE: -e 0,0,0,$XX,$YY
}
function LHD
{
XX=$((XX / 2))
YY=$((YY / 2))
wmctrl -r :ACTIVE: -e 0,0,$YY,$XX,$YY
}
function RHU
{
XX=$((XX / 2))
YY=$((YY / 2))
wmctrl -r :ACTIVE: -e 0,$XX,0,$XX,$YY
}
function RHD
{
XX=$((XX / 2))
YY=$((YY / 2 ))
wmctrl -r :ACTIVE: -e 0,$XX,$YY,$XX,$YY
}
function add2sven
{
LEFT="[113:64]
type=cmd
enable=1
description=$(gettext 'Rotate Screen Left')
command=/root/Startup/rotate left
comment=Rotate Left\n"
[[ -z $(grep '113:64' /root/.sven/key_config) ]] && echo -e "$LEFT" >> /root/.sven/key_config
RIGHT="[114:64]
type=cmd
enable=1
description=$(gettext 'Rotate Screen Right')
command=/root/Startup/rotate right
comment=Rotate Right\n"
[[ -z $(grep '114:64' /root/.sven/key_config) ]] && echo -e "$RIGHT" >> /root/.sven/key_config
INVERTED="[111:64]
type=cmd
enable=1
description=$(gettext 'Rotate Inverted')
command=/root/Startup/rotate inverted
comment=Rotate Inverted\n"
[[ -z $(grep '1116:4' /root/.sven/key_config) ]] && echo -e "$INVERTED" >> /root/.sven/key_config
NORMAL="[116:64]
type=cmd
enable=1
description=$(gettext 'Rotate Screen normal')
command=/root/Startup/rotate normal
comment=Rotate Screen Normal\n"
[[ -z $(grep '116:64' /root/.sven/key_config) ]] && echo -e "$NORMAL" >> /root/.sven/key_config
LH="[113:4]
type=cmd
enable=1
description=$(gettext 'Left Half of Screen')
command=/root/Startup/rotate LH
comment=Move Window to Left\n"
[[ -z $(grep '113:4' /root/.sven/key_config) ]] && echo -e "$LH" >> /root/.sven/key_config
RH="[114:4]
type=cmd
enable=1
description=$(gettext 'Right Half of Screem')
command=/root/Startup/rotate RH
comment=Move Window To Right\n"
[[ -z $(grep '114:4' /root/.sven/key_config) ]] && echo -e "$RH" >> /root/.sven/key_config
TH="[111:4]
type=cmd
enable=1
description=$(gettext 'Top Half of Screen')
command=/root/Startup/rotate TH
comment=Move to Top Half\n"
[[ -z $(grep '111:4' /root/.sven/key_config) ]] && echo -e "$TH" >> /root/.sven/key_config
BH="[116:4]
type=cmd
enable=1
description=$(gettext 'Bottom Half of Screen')
command=/root/Startup/rotate BH
comment=Move Window To Bottom\n"
[[ -z $(grep '116:4' /root/.sven/key_config) ]] && echo -e "$BH" >> /root/.sven/key_config
RHU="[111:8]
type=cmd
enable=1
description=$(gettext 'Move Window to Right Top')
command=/root/Startup/rotate RHU
comment=\n"
[[ -z $(grep '111:8' /root/.sven/key_config) ]] && echo -e "$RHU" >> /root/.sven/key_config
RHD="[114:8]
type=cmd
enable=1
description=$(gettext 'Move Window to Right Down')
command=/root/Startup/rotate RHD
comment=\n"
[[ -z $(grep '114:8' /root/.sven/key_config) ]] && echo -e "$RHD" >> /root/.sven/key_config
LHU="[113:8]
type=cmd
enable=1
description=$(gettext 'Move Window to Left Top')
command=/root/Startup/rotate LHU
comment=\n"
[[ -z $(grep '113:8' /root/.sven/key_config) ]] && echo -e "$LHU" >> /root/.sven/key_config
LHD="[116:8]
type=cmd
enable=1
description=$(gettext 'Move Window to Left Down')
command=/root/Startup/rotate LHD
comment=\n"
[[ -z $(grep '116:8' /root/.sven/key_config) ]] && echo -e "$LHD" >> /root/.sven/key_config
sven -k
sven &
};export -f add2sven
export TRANSFORM='Coordinate Transformation Matrix'
export OUTPUT_CHARSET=UTF-8
export connected=`xrandr | grep connected | cut -f1 -d' ' | head -1`
function left (){
events=$(cat /etc/rotate_events)
export touch=`echo "$events" | cut -f2 -d' '`
export pad=`echo "$events" | cut -f1 -d' '`
xrandr --output "$connected" --rotate left
xinput set-prop "$touch" "Evdev Axis Inversion" 0, 1
xinput set-prop "$touch" "Evdev Axes Swap" 1
xinput set-prop "$pad" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1
xinput set-prop "$touch" "$TRANSFORM" 0 -1 1 1 0 0 0 0 1
echo "left" >/etc/rotate
echo "icon:left.png" >>/tmp/RPIPE
}; export -f left
function right (){
events=$(cat /etc/rotate_events)
export touch=`echo "$events" | cut -f2 -d' '`
export pad=`echo "$events" | cut -f1 -d' '`
xrandr --output "$connected" --rotate right
xinput set-prop "$touch" "Evdev Axis Inversion" 0, 1
xinput set-prop "$touch" "Evdev Axes Swap" 1
xinput set-prop "$pad" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1
xinput set-prop "$touch" "$TRANSFORM" 0 1 0 -1 0 1 0 0 1
echo "right" >/etc/rotate
echo "icon:right.png" >>/tmp/RPIPE
}; export -f right
function inverted (){
events=$(cat /etc/rotate_events)
touch=$(echo "$events" | cut -f2 -d' ')
pad=$(echo "$events" | cut -f1 -d' ')
xrandr --output "$connected" --rotate inverted
xinput set-prop "$touch" "Evdev Axis Inversion" 1, 1
xinput set-prop "$touch" "Evdev Axes Swap" 0
xinput set-prop "$pad" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1
xinput set-prop "$touch" "$TRANSFORM" -1 0 1 0 -1 1 0 0 1
echo "inverted" >/etc/rotate
echo "icon:inverted.png" >>/tmp/RPIPE
}; export -f inverted
function normal (){
events=$(cat /etc/rotate_events)
touch=`echo "$events" | cut -f2 -d' '`
pad=`echo "$events" | cut -f1 -d' '`
xrandr --output "$connected" --rotate normal
xinput set-prop "$touch" "Evdev Axis Inversion" 0, 0
xinput set-prop "$touch" "Evdev Axes Swap" 0
xinput set-prop "$pad" "$TRANSFORM" 1 0 0 0 1 0 0 0 1
xinput set-prop "$touch" "$TRANSFORM" 1 0 0 0 1 0 0 0 1
echo "normal" >/etc/rotate
echo "icon:normal.png" >>/tmp/RPIPE
}; export -f normal
function rotate_flipx {
xrandr -x
};export -f rotate_flipx
function rotate_flipy {
xrandr -y
};export -f rotate_flipy
function rotate_flip_normal {
xrandr -o normal
};export rotate_flip_normal
function driveumnt {
umount /dev/"$1" /mnt/"$1"
DrivIcons
echo "icon:/usr/share/pixmaps/driveOFF.png" >>/tmp/DRIVES
};export -f driveumnt
function drivemnt {
mount /dev/"$1" /mnt/"$1"
DrivIcons
echo "icon:/usr/share/pixmaps/driveON.png" >> /tmp/DRIVES
};export -f drivemnt
function DrivIcons {
mkfifo -m755 /tmp/DRIVES
exec 8<> /tmp/DRIVES
cnt=1
for i in $(fdisk -l | grep dev | grep -v Disk | awk '{print $1}' | tr '\n' ' ')
do
INFO=$(lsblk "$i" | tail -n1)
SWAP=$(cat /proc/swaps | tail -n+1 | cut -f1 -d' ' | grep $i)
[ "$SWAP" ] && i="SWAP"
case "$i" in
'/dev/sd'*|'/dev/mmcblk'*) DRIVENAME=$(basename $i)
export MENU$cnt="$(gettext 'mount') $INFO!bash -c \"drivemnt $DRIVENAME;rox /mnt/$DRIVENAME \"!/usr/share/pixmaps/driveON.png|$(gettext 'UnMount') $DRIVENAME!bash -c \"driveumnt $DRIVENAME \"!/usr/share/pixmaps/driveOFF.png||";;
SWAP) DRIVENAME=$(echo $INFO | cut -f1 -d' ')
export MENU$cnt="$(gettext 'Swap On') $INFO!bash -c \"swapon /dev/$DRIVENAME;DivvIcons \"!/usr/share/pixmaps/driveON.png|$(gettext 'Swap Off') $DRIVENAME!bash -c \"swapoff /dev/$DRIVENAME;DrivIcons \"!/usr/share/pixmaps/driveOFF.png||"
;;
esac
export cnt=$((cnt + 1))
unset SWAP
done
yad --notification --listen --text="$(gettext "Storage Devices")" --tray-icon="/usr/share/pixmaps/driveON.png" --command="bash -c \"rox /mnt/ \"" --menu="$(gettext 'Drive Mounting')|||$MENU12$MENU11$MENU10$MENU9$MENU8$MENU7$MENU6$MENU5$MENU4$MENU3$MENU2$MENU1|Close!quit!gtk-cancel" <& 8 &
echo "icon:/usr/share/pixmaps/driveON.png" >> /tmp/DRIVES
}; export -f DrivIcons
function on_exit (){
rm -f /tmp/RPIPE
for i in $(fdisk -l | grep dev | grep -v Disk | awk '{print $1}' | tr '\n' ' ')
do
rm -f /tmp/$(basename $i)
done
}
export -f on_exit
trap 'on_exit' EXIT
running=`ps -e | grep rotate | wc -l`
[[ "$running" -gt 2 ]] && exit #check if running, one instance only
export HANDEL="$RANDOM"
mkfifo -m755 /tmp/$HANDEL
exec 1<> /tmp/$HANDEL
function maingui (){
export WINDOWTITLE="$(gettext 'Mounter_Rotator')"
sayonara 8 &
yad --center \
--form --item-separator='#' \
--field="$(gettext 'Mount'):FBTN" "bash -c \"mkdir -p "%3"; mount "%2" "%3" \"" \
--field="$(gettext 'Partition'):CBE" "`fdisk -l | grep dev | grep -v Disk | awk '{print $1}' | tr '\n' '#'``blkid -o device | tr '\n' '#'`" \
--field="$(gettext 'Mount Dir'):CBE" `ls /mnt | sed 's|^|/mnt/|g' | tr '\n' '#'``ls /media | sed 's|^|/media/|g' | tr '\n' '#'``ls /aufs | sed 's|^|/aufs/|g' | tr '\n' '#'` \
--field="$(gettext 'un-Mount'):FBTN" "bash -c \"umount -f -A "%2"; umount -f -A "%3" \"" \
--field="$(gettext 'Xinput Events'):TXT" "`xinput`" \
--field="$(gettext 'touchpad event id='):NUM" "`cat /etc/rotate_events | cut -f1 -d' '`" \
--field="$(gettext 'Touchscreen event id='):NUM" "`cat /etc/rotate_events | cut -f2 -d' '`" \
--field="$(gettext 'Store Events'):FBTN" "bash -c \"echo "%6" "%7" >/etc/rotate_events \"" \
--field="$(gettext 'Rotate left'):FBTN" "bash -c \"left \"" \
--field="$(gettext 'Rotate right'):FBTN" "bash -c \"right \"" \
--field="$(gettext 'Rotate normal'):FBTN" "bash -c \"normal \"" \
--field="$(gettext 'Rotate inverted'):FBTN" "bash -c \"inverted \"" \
--field="$(gettext 'Mirror X axis'):FBTN" "bash -c 'rotate_flipx'" \
--field="$(gettext 'Mirror Y axis'):FBTN" "bash -c 'rotate_flipy'" \
--field="$(gettext 'Create Drive Icons'):FBTN" "bash -c 'DrivIcons'" \
--no-buttons \
--title="$(gettext "$WINDOWTITLE")" --window-icon="gtk-refresh" \
--geometry="$(cat /root/.config/geometry/$WINDOWTITLE)" &
}; export -f maingui
if [ ! -f /tmp/ROTATE ]; then
yad --notification --listen --text="$(gettext 'Click then position cursor to get right click menu')" --tray-icon="/usr/share/pixmaps/normal.png" --command="bash -c 'sleep 4; xdotool click 3'" --menu="$(gettext 'Storage Devices')!bash -c DrivIcons!/usr/share/pixmaps/driveON.png|$(gettext 'Screen Rotation Win-Key + arrows')|$(gettext 'Window Placement Alt/Ctrl + arrows')|$(gettext 'Rotate Left')!bash -c left!/usr/share/pixmaps/left.png|$(gettext 'Rotate right')!bash -c right!/usr/share/pixmaps/right.png|$(gettext 'Rotate Inverted')!bash -c inverted!/usr/share/pixmaps/inverted.png|$(gettext 'Rotate Normal')!bash -c normal!/usr/share/pixmaps/normal.png|$(gettext 'Mirror X axis')!bash -c 'rotate_flipx'!/usr/share/pixmaps/flipx.png|$(gettext 'Mirror Y axis')!bash -c 'rotate_flipy'!/usr/share/pixmaps/flipy.png|$(gettext 'Open Graphical User Interface')!bash -c maingui!gtk-open|$(gettext 'Write key-combos to') sven!bash -c '/root/Startup/rotate sven'!gtk-save|$(gettext 'Close')!quit!gtk-cancel" <& 1 &
echo "icon:/usr/share/pixmaps/normal.png" >> /tmp/$HANDEL
[ ! -f /tmp/ROTATE ] && touch /tmp/ROTATE
fi
case $1 in
left) $1
;;
right) $1
;;
inverted) $1
;;
normal) $1
;;
BH) $1
;;
TH) $1
;;
RH) $1
;;
LH) $1
;;
LHD) $1
;;
LHU) $1
;;
RHD) $1
;;
RHU) $1
;;
sven) add2sven
;;
esac