~scriptstiling
10 itemsDownload ./*


..
xrectsel
drawterm
ext.grid
grid
gridmacro
gridmacro.kde
snap.all
snap.grid
split.grid
swap.grid


tilingext.grid
1 6656 years agoDownloadRawClose


#!/bin/bash
#
#   Author:         Twily                                   2014 - 2015
#   Description:    Extension script to "grid" for custom sized layouts
#   Requires:       wmctrl, xdotool, xwininfo
#                       (This also requires openbox to dishonor size hints.
#                        Comment out Ln 1742-1749 and 1760-1761 in openbox/client.c
#                        [Guide: http://pastebin.com/tE6meLfD])
#   Usage:          $ sh ./ext.grid 1 2
#                       (See below for keybind alternative.
#                        Keybinds can be set in your WM)
#

DES=$(xdotool get_desktop)
ACT=$(xdotool getactivewindow) && WNAME=$(xdotool getactivewindow getwindowname)
if [ "$WNAME" == "Desktop" ]; then exit 3; fi

dW=1920             # Desktop Width
dH=1080             # Desktop Height

pW=77               # Pixels of dW to inc/dec
pH=55               # Pixels of dH to inc/dec

eM=48               # (Used for equal margin on all sides)

L=$eM               # Left Margin
T=$(( $eM + 24 ))   # Top Margin (+24 for panel)
R=$eM               # Right Margin
B=$eM               # Bottom Margin

G=24                # Window Gap
D=0                 # Decoration Height (0 = none)
M=0                 # Border Width (0 = none)

if [ "$D" -gt "0" ]; then D=$(( $D + $M )); fi 

M=$(( $M * 2 ))

getwindowgeometry() {
    unset X Y W H
    eval $(xwininfo -id $1 | 
        sed -n -e "s/^ \+Absolute upper-left X: \+\([0-9]\+\).*/X=\1/p" \
               -e "s/^ \+Absolute upper-left Y: \+\([0-9]\+\).*/Y=\1/p" \
               -e "s/^ \+Width: \+\([0-9]\+\).*/W=\1/p" \
               -e "s/^ \+Height: \+\([0-9]\+\).*/H=\1/p" )

    Y=$(( $Y - $D - $M / 2 ))
    X=$(( $X - $M / 2 ))
}

getwindowgeometry $ACT
cX=$X && cY=$Y && cW=$W && cH=$H

WINS=$(xdotool search --onlyvisible --desktop $DES --name "")
for WIN in $WINS; do
    if [ "$WIN" -ne "$ACT" ]; then
        getwindowgeometry $WIN

        case "$1" in
            1)  case "$2" in # left/top edge control (ext.grid 1 [1-4])
                    1)  if [ "$X" -eq "$cX" ]; then                                    X=$(( $X - $pW )) && Y=$(( $Y ))       && W=$(( $W + $pW )) && H=$(( $H ));        fi  # inc left
                        if [ "$(( $X + $W ))" -eq "$(( $cX - $G - $M ))" ]; then       X=$(( $X ))       && Y=$(( $Y ))       && W=$(( $W - $pW )) && H=$(( $H ));        fi  ;;
                    2)  if [ "$Y" -eq "$cY" ]; then                                    X=$(( $X ))       && Y=$(( $Y - $pH )) && W=$(( $W ))       && H=$(( $H + $pH ));  fi  # inc top
                        if [ "$(( $Y + $H + $D ))" -eq "$(( $cY - $G - $M ))" ]; then  X=$(( $X ))       && Y=$(( $Y ))       && W=$(( $W ))       && H=$(( $H - $pH ));  fi  ;;

                    3)  if [ "$X" -eq "$cX" ]; then                                    X=$(( $X + $pW )) && Y=$(( $Y ))       && W=$(( $W - $pW )) && H=$(( $H ));        fi  # dec left
                        if [ "$(( $X + $W ))" -eq "$(( $cX - $G - $M ))" ]; then       X=$(( $X ))       && Y=$(( $Y ))       && W=$(( $W + $pW )) && H=$(( $H ));        fi  ;;
                    4)  if [ "$Y" -eq "$cY" ]; then                                    X=$(( $X ))       && Y=$(( $Y + $pH )) && W=$(( $W ))       && H=$(( $H - $pH ));  fi  # dec top
                        if [ "$(( $Y + $H + $D ))" -eq "$(( $cY - $G - $M ))" ]; then  X=$(( $X ))       && Y=$(( $Y ))       && W=$(( $W ))       && H=$(( $H + $pH ));  fi  ;;

                    *)  exit 2  ;;
                esac
            ;;

            2)  case "$2" in # righ/bot edge control (ext.grid 2 [1-4])
                    1)  if [ "$(( $X + $W ))" -eq "$(( $cX + $cW ))" ]; then           X=$(( $X ))       && Y=$(( $Y ))       && W=$(( $W + $pW )) && H=$(( $H ));        fi  # inc right
                        if [ "$X" -eq "$(( $cX + $cW + $G + $M ))" ]; then             X=$(( $X + $pW )) && Y=$(( $Y ))       && W=$(( $W - $pW )) && H=$(( $H ));        fi  ;;
                    2)  if [ "$(( $Y + $H ))" -eq "$(( $cY + $cH ))" ]; then           X=$(( $X ))       && Y=$(( $Y ))       && W=$(( $W ))       && H=$(( $H + $pH ));  fi  # inc bot
                        if [ "$Y" -eq "$(( $cY + $cH + $D + $G + $M ))" ]; then        X=$(( $X ))       && Y=$(( $Y + $pH )) && W=$(( $W ))       && H=$(( $H - $pH ));  fi  ;;

                    3)  if [ "$(( $X + $W ))" -eq "$(( $cX + $cW ))" ]; then           X=$(( $X ))       && Y=$(( $Y ))       && W=$(( $W - $pW )) && H=$(( $H ));        fi  # dec right
                        if [ "$X" -eq "$(( $cX + $cW + $G + $M ))" ]; then             X=$(( $X - $pW )) && Y=$(( $Y ))       && W=$(( $W + $pW )) && H=$(( $H ));        fi  ;;
                    4)  if [ "$(( $Y + $H ))" -eq "$(( $cY + $cH ))" ]; then           X=$(( $X ))       && Y=$(( $Y ))       && W=$(( $W ))       && H=$(( $H - $pH ));  fi  # dec bot
                        if [ "$Y" -eq "$(( $cY + $cH + $D + $G + $M ))" ]; then        X=$(( $X ))       && Y=$(( $Y - $pH )) && W=$(( $W ))       && H=$(( $H + $pH ));  fi  ;;

                    *)  exit 2  ;;
                esac
            ;;

            *)  exit 1  ;;
        esac

        if [ "$X" -lt "$L" ]; then S=$(( $L - $X )) && X=$L; if [ "$W" -le "$(( $dW - $L - $R ))" ]; then W=$(( $W - $S )); fi; fi
        if [ "$Y" -lt "$T" ]; then S=$(( $T - $Y )) && Y=$T; if [ "$H" -le "$(( $dH - $T - $B ))" ]; then H=$(( $H - $S )); fi; fi
        if [ "$(( $X + $W ))" -gt "$(( $dW - $R ))" ]; then W=$(( $dW - $X - $R - $M )); fi
        if [ "$(( $Y + $H ))" -gt "$(( $dH - $B ))" ]; then H=$(( $dH - $Y - $B - $D - $M )); fi

        wmctrl -i -r $WIN -e 0,$X,$Y,$W,$H
    fi
done

case "$1" in
    1)  case "$2" in # left/top edge control (ext.grid 1 [1-4])                     [Keybind alternative]
            1)  cX=$(( $cX - $pW )) && cW=$(( $cW + $pW ))  ;;  # inc left          [W-S-KP_8]
            2)  cY=$(( $cY - $pH )) && cH=$(( $cH + $pH ))  ;;  # inc top           [W-S-KP_7]

            3)  cX=$(( $cX + $pW )) && cW=$(( $cW - $pW ))  ;;  # dec left          [W-S-KP_9]
            4)  cY=$(( $cY + $pH )) && cH=$(( $cH - $pH ))  ;;  # dec top           [W-S_KP_4]

            *)  exit 2  ;;
        esac
    ;;

    2)  case "$2" in # righ/bot edge control (ext.grid 2 [1-4])                     [Keybind alternative]
            1)  cW=$(( $cW + $pW )) && cX=$(( $cX ))        ;;  # inc right         [W-S-KP_2]
            2)  cH=$(( $cH + $pH )) && cY=$(( $cY ))        ;;  # inc bot           [W-S-KP_3]

            3)  cW=$(( $cW - $pW )) && cX=$(( $cX ))        ;;  # dec right         [W-S-KP_1]
            4)  cH=$(( $cH - $pH )) && cY=$(( $cY ))        ;;  # dec bot           [W-S-KP_6]

            *)  exit 2  ;;
        esac
    ;;

    *)  exit 1  ;;
esac

if [ "$cX" -lt "$L" ]; then S=$(( $L - $cX )) && cX=$L; if [ "$cW" -le "$(( $dW - $L - $R ))" ]; then cW=$(( $cW - $S )); fi; fi
if [ "$cY" -lt "$T" ]; then S=$(( $T - $cY )) && cY=$T; if [ "$cH" -le "$(( $dH - $T - $B ))" ]; then cH=$(( $cH - $S )); fi; fi
if [ "$(( $cX + $cW ))" -gt "$(( $dW - $R ))" ]; then cW=$(( $dW - $cX - $R - $M )); fi
if [ "$(( $cY + $cH ))" -gt "$(( $dH - $B ))" ]; then cH=$(( $dH - $cY - $B - $D - $M )); fi

wmctrl -i -r $ACT -e 0,$cX,$cY,$cW,$cH
exit 0

Top
twily at twily dot info
©twily.info 2013 - 2021



1 687 333 visits
... ^ v