#!/bin/sh

WINDOW_ID="$1"
SCREEN_WIDTH="$2"
SCREEN_HEIGHT="$3"
SCREEN_OFFSET_X="$4"
SCREEN_OFFSET_Y="$5"

GRAVITY="0"
WIDTH="$(($SCREEN_WIDTH/2))"
HEIGHT="-1"
X="$(($SCREEN_OFFSET_X+$SCREEN_WIDTH-$WIDTH))"
Y="0"

# we need to remove the maximized_horz attribute in case the window was maximized with hit_top before
wmctrl -i -r "$WINDOW_ID" -b remove,maximized_horz

# maximize it vertically via EWMH so padding (taskbar for example) is respected
wmctrl -i -r "$WINDOW_ID" -b add,maximized_vert

# change position and size of the window
wmctrl -i -r "$WINDOW_ID" -e $GRAVITY,$X,$Y,$WIDTH,$HEIGHT
