Skip to content

Instantly share code, notes, and snippets.

@meyt
Created September 2, 2025 00:11
Show Gist options
  • Select an option

  • Save meyt/b40139b9f1b34a0ade62cc5b7d47dfeb to your computer and use it in GitHub Desktop.

Select an option

Save meyt/b40139b9f1b34a0ade62cc5b7d47dfeb to your computer and use it in GitHub Desktop.
Fix xfce/xfwm lost maximized window state after second display attached/detached
#!/bin/bash
# Get list of maximized windows (both horizontal and vertical)
wmctrl -l | while read -r id desktop hostname title; do
# Check if window is maximized (both directions)
net_wm_state=$(xprop -id "$id" _NET_WM_STATE 2>/dev/null)
if [[ "$net_wm_state" == *"_NET_WM_STATE_MAXIMIZED_HORZ"* ]] && \
[[ "$net_wm_state" == *"_NET_WM_STATE_MAXIMIZED_VERT"* ]]; then
echo "Processing window: $title ($id)"
# Unmaximize the window
wmctrl -ir "$id" -b remove,maximized_vert,maximized_horz
echo " → Unmaximized"
# Wait 500ms
sleep 0.5
# Maximize again
wmctrl -ir "$id" -b add,maximized_vert,maximized_horz
echo " → Remaximized"
fi
done
echo "Operation completed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment