master ohmu/wmutils / scripts / half.sh
ohmu  ·  2026-07-25
 1#!/bin/sh
 2
 3. ~/.theme
 4
 5if [ $# -ne 2 ]; then
 6    echo "Usage: $0 {left|right} wid"
 7    echo "  left  - snap window to left side"
 8    echo "  right - snap window to right side"
 9    exit 1
10fi
11
12DIRECTION=$1
13WIN=$2
14
15# Get screen dimensions
16ROOT_W=$(wattr w $(lsw -r))
17ROOT_H=$(wattr h $(lsw -r))
18
19# Get window dimensions
20WIN_W=$(wattr w $WIN)
21WIN_H=$(wattr h $WIN)
22
23# Define gaps (adjust these values as needed)
24GAP_TOP=30
25GAP_BOTTOM=30
26GAP_SIDE=30
27
28# Calculate new window size (full height minus gaps)
29NEW_H=$((ROOT_H - GAP_TOP - GAP_BOTTOM))
30NEW_W=$((WIN_W))  # Keep original width or set to half screen? Let's keep original
31
32# Option: Uncomment below to make window take half of screen width
33# NEW_W=$(((ROOT_W - GAP_SIDE * 3) / 2))
34
35case $DIRECTION in
36    right)
37        NEW_X=$((ROOT_W - NEW_W - GAP_SIDE))
38        NEW_Y=$GAP_TOP
39        ;;
40    left)
41        NEW_X=$GAP_SIDE
42        NEW_Y=$GAP_TOP
43        ;;
44    *)
45        echo "Invalid argument. Use: left or right"
46        exit 1
47        ;;
48esac
49
50# Move and resize window
51wtp $NEW_X $NEW_Y $NEW_W $NEW_H $WIN
52
53# Optionally move cursor to center of window
54# NEW_CURSOR_X=$((NEW_X + NEW_W/2))
55# NEW_CURSOR_Y=$((NEW_Y + NEW_H/2))
56# wmp -a $NEW_CURSOR_X $NEW_CURSOR_Y