Skip to content

Instantly share code, notes, and snippets.

@peteruithoven
Last active March 2, 2023 06:31
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save peteruithoven/db0cba0b0849c8cb5e267f6e75126304 to your computer and use it in GitHub Desktop.
Save peteruithoven/db0cba0b0849c8cb5e267f6e75126304 to your computer and use it in GitHub Desktop.
Crude quarter tiling tool for elementary OS
#!/bin/bash
# Crude quarter tiling tool
# Installation:
# Move file to: /usr/local/bin/quarter-tiler
# Make executable: sudo chmod +x /usr/local/bin/quarter-tiler
# Assign keyboard shortcuts to commands like "quarter-tiler topleft"
# Margins around windows (elementary OS native apps) (HiDPI)
MARGIN_TOP=130
MARGIN_RIGHT=158
MARGIN_BOTTOM=185
MARGIN_LEFT=158
# Desktops info
INFO=$(wmctrl -d | head -1)
# Desktop size
[[ $INFO =~ 'DG: '([0-9]+)'x'([0-9]+) ]]
WIDTH=${BASH_REMATCH[1]}
HEIGHT=${BASH_REMATCH[2]}
# Available width height, and offsets see: $ wmctrl -d
[[ $INFO =~ 'WA: '([0-9]+)','([0-9]+)' '([0-9]+)'x'([0-9]+) ]]
OFFSET_X=${BASH_REMATCH[1]}
OFFSET_Y=${BASH_REMATCH[2]}
AV_WIDTH=${BASH_REMATCH[3]}
AV_HEIGHT=${BASH_REMATCH[4]}
X_LEFT=$((0-($MARGIN_RIGHT+$OFFSET_X)))
X_CENTER=$(($AV_WIDTH/2+$MARGIN_RIGHT+$MARGIN_LEFT))
HALF_WIDTH=$X_CENTER
Y_TOP=$((0-($MARGIN_TOP-$OFFSET_Y)))
Y_CENTER=$(($Y_TOP+$HEIGHT/2))
HALF_HEIGHT=$(($AV_HEIGHT/2+$MARGIN_TOP+$MARGIN_BOTTOM))
SIZE=$HALF_WIDTH,$HALF_HEIGHT
case "$1" in
topleft)
CMD="wmctrl -r :ACTIVE: -e 0,$X_LEFT,$Y_TOP,$SIZE"
;;
topright)
CMD="wmctrl -r :ACTIVE: -e 0,$X_CENTER,$Y_TOP,$SIZE"
;;
bottomleft)
CMD="wmctrl -r :ACTIVE: -e 0,$X_LEFT,$Y_CENTER,$SIZE"
;;
bottomright)
CMD="wmctrl -r :ACTIVE: -e 0,$X_CENTER,$Y_CENTER,$SIZE"
;;
esac
# In case window is tiled, disable tile
wmctrl -r :ACTIVE: -b remove,maximized_vert
# Wait for transition
sleep 0.1s
eval $($CMD)
@rijesha
Copy link

rijesha commented Nov 15, 2019

I did something like this to change the margins depending on the process.

APPNAME=$(wmctrl -lx | grep $(xprop -root | grep _NET_ACTIVE_WINDOW | head -1 | \
    awk '{print $5}' | sed 's/,//' | sed 's/^0x/0x0/') | cut -d " " -f 4)

echo $APPNAME

MARGIN_TOP=0
MARGIN_RIGHT=0
MARGIN_BOTTOM=0
MARGIN_LEFT=0

if [[ $APPNAME == io.elementary* ]] || [[ $APPNAME == gedit* ]] ;
then
    echo $APPNAME
    # Margins around windows (elementary OS native apps) (HiDPI)
    MARGIN_TOP=130
    MARGIN_RIGHT=158
    MARGIN_BOTTOM=185
    MARGIN_LEFT=158
fi

@fix777
Copy link

fix777 commented Mar 2, 2023

# In case window is tiled, disable tile
wmctrl -r :ACTIVE: -b remove,maximized_vert,maximized_horz

Add remove maximized_horz would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment