Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Cek argumen
- if [ "$#" -lt 4 ]; then
- echo "Usage: $0 <width%> <height%> <x_offset%> <y_offset%>"
- exit 1
- fi
- w_pct=$1
- h_pct=$2
- x_pct=$3
- y_pct=$4
- # Validasi argumen
- for val in "$w_pct" "$h_pct" "$x_pct" "$y_pct"; do
- if ! [[ "$val" =~ ^[0-9]+$ ]] || [ "$val" -lt 0 ] || [ "$val" -gt 100 ]; then
- echo "Error: arguments must be integers between 0 and 100"
- exit 1
- fi
- done
- # Buffer default
- DEFAULT_BUFFER_W=0
- DEFAULT_BUFFER_H=23
- # Dapatkan window aktif
- win_id=$(xdotool getactivewindow)
- if [ -z "$win_id" ]; then
- echo "Error: cannot get active window"
- exit 1
- fi
- # Dapatkan WM_CLASS dari window aktif
- wm_class=$(xprop -id "$win_id" WM_CLASS | sed -n 's/.*", "\(.*\)".*/\1/p' | xargs)
- wm_instance=$(xprop -id "$win_id" WM_CLASS | sed -n 's/.*"\(.*\)",.*/\1/p' | xargs)
- # Tentukan buffer berdasarkan aplikasi
- if [[ "$wm_class" == "Brave-browser" ]] || [[ "$wm_instance" == "brave" ]]; then
- BUFFER_W=0
- BUFFER_H=0
- else
- BUFFER_W=$DEFAULT_BUFFER_W
- BUFFER_H=$DEFAULT_BUFFER_H
- fi
- # Unmaximize window
- wmctrl -ir "$win_id" -b remove,maximized_vert,maximized_horz
- # Ambil workarea layar (x, y, width, height)
- read wx wy ww wh < <(xprop -root _NET_WORKAREA | sed -n 's/.*= *\([0-9]*\), *\([0-9]*\), *\([0-9]*\), *\([0-9]*\).*/\1 \2 \3 \4/p')
- # Hitung ukuran dan posisi window
- width=$(( ww * w_pct / 100 - BUFFER_W ))
- height=$(( wh * h_pct / 100 - BUFFER_H ))
- if [ "$height" -lt 1 ]; then
- height=1
- fi
- x=$(( wx + ww * x_pct / 100 ))
- y=$(( wy + wh * y_pct / 100 ))
- # Jika window ditile di kanan layar, sesuaikan posisi X agar tidak keluar layar
- if (( x_pct + w_pct >= 100 )); then
- x=$(( x - BUFFER_W ))
- fi
- # Pindahkan dan ubah ukuran window
- xdotool windowmove "$win_id" "$x" "$y"
- xdotool windowsize "$win_id" "$width" "$height"
- echo "Window moved and resized to: $x,$y,$width,$height (Class: $wm_class)"
Advertisement
Add Comment
Please, Sign In to add comment