Guest User

Untitled

a guest
Jul 2nd, 2025
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Cek argumen
  4. if [ "$#" -lt 4 ]; then
  5. echo "Usage: $0 <width%> <height%> <x_offset%> <y_offset%>"
  6. exit 1
  7. fi
  8.  
  9. w_pct=$1
  10. h_pct=$2
  11. x_pct=$3
  12. y_pct=$4
  13.  
  14. # Validasi argumen
  15. for val in "$w_pct" "$h_pct" "$x_pct" "$y_pct"; do
  16. if ! [[ "$val" =~ ^[0-9]+$ ]] || [ "$val" -lt 0 ] || [ "$val" -gt 100 ]; then
  17. echo "Error: arguments must be integers between 0 and 100"
  18. exit 1
  19. fi
  20. done
  21.  
  22. # Buffer default
  23. DEFAULT_BUFFER_W=0
  24. DEFAULT_BUFFER_H=23
  25.  
  26. # Dapatkan window aktif
  27. win_id=$(xdotool getactivewindow)
  28.  
  29. if [ -z "$win_id" ]; then
  30. echo "Error: cannot get active window"
  31. exit 1
  32. fi
  33.  
  34. # Dapatkan WM_CLASS dari window aktif
  35. wm_class=$(xprop -id "$win_id" WM_CLASS | sed -n 's/.*", "\(.*\)".*/\1/p' | xargs)
  36. wm_instance=$(xprop -id "$win_id" WM_CLASS | sed -n 's/.*"\(.*\)",.*/\1/p' | xargs)
  37.  
  38. # Tentukan buffer berdasarkan aplikasi
  39. if [[ "$wm_class" == "Brave-browser" ]] || [[ "$wm_instance" == "brave" ]]; then
  40. BUFFER_W=0
  41. BUFFER_H=0
  42. else
  43. BUFFER_W=$DEFAULT_BUFFER_W
  44. BUFFER_H=$DEFAULT_BUFFER_H
  45. fi
  46.  
  47. # Unmaximize window
  48. wmctrl -ir "$win_id" -b remove,maximized_vert,maximized_horz
  49.  
  50. # Ambil workarea layar (x, y, width, height)
  51. 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')
  52.  
  53. # Hitung ukuran dan posisi window
  54. width=$(( ww * w_pct / 100 - BUFFER_W ))
  55. height=$(( wh * h_pct / 100 - BUFFER_H ))
  56. if [ "$height" -lt 1 ]; then
  57. height=1
  58. fi
  59.  
  60. x=$(( wx + ww * x_pct / 100 ))
  61. y=$(( wy + wh * y_pct / 100 ))
  62.  
  63. # Jika window ditile di kanan layar, sesuaikan posisi X agar tidak keluar layar
  64. if (( x_pct + w_pct >= 100 )); then
  65. x=$(( x - BUFFER_W ))
  66. fi
  67.  
  68. # Pindahkan dan ubah ukuran window
  69. xdotool windowmove "$win_id" "$x" "$y"
  70. xdotool windowsize "$win_id" "$width" "$height"
  71.  
  72. echo "Window moved and resized to: $x,$y,$width,$height (Class: $wm_class)"
  73.  
Advertisement
Add Comment
Please, Sign In to add comment