I spent way too long trying to figure out why wmctrl wouldn’t move my Firefox window (in my case, used for Disney+ streaming). The command looked right — I even verified the window ID with wmctrl -l and double-checked the geometry syntax. Yet nothing happened.
Turns out, if a window is maximized (which Firefox tends to do when launching certain content), wmctrl and even xdotool refuse to move it. I confirmed this with xprop, where I saw:
Code: Select all
_NET_WM_STATE(ATOM) = _NET_WM_STATE_MAXIMIZED_HORZ, _NET_WM_STATE_MAXIMIZED_VERT
That was the culprit.
You need to unmaximize the window first before moving it. Then you can re-maximize it if needed.
Here’s the final working script I built for my startup routine. It waits for an internet connection, launches apps, and smartly moves whichever of my streaming/news tabs is active to my large screen:
Code: Select all
#!/usr/bin/env bash
Wait until there is a connection so that no windows have to be refreshed.
while ! /bin/ping -c1 1.1.1.1 >/dev/null 2>&1; do sleep 2 done
Launch Firefox
/usr/bin/firefox &
Position Thunderbird
wmctrl -r "thunderbird" -e 0,-25,515,-1,-1
Give Firefox time to start
sleep 5
Define accepted streaming/news window titles
STREAMING_WINDOWS=("Disney+" "Netflix" "Tagesschau" "ZDF")
Find the first matching window
for NAME in "${STREAMING_WINDOWS[@]}"; do STREAM_WIN=$(wmctrl -l | grep "$NAME" | awk '{print $1}') if [ -n "$STREAM_WIN" ]; then break fi done
Move window to external screen if found
if [ -n "$STREAM_WIN" ]; then wmctrl -ir "$STREAM_WIN" -b remove,maximized_vert,maximized_horz wmctrl -ir "$STREAM_WIN" -e 0,1920,0,-1,-1 wmctrl -ir "$STREAM_WIN" -b add,maximized_vert,maximized_horz else echo "No streaming/news window found." fi
Hope this helps anyone else who’s been pulling their hair out over this. Cheers!
P.S. AH, and don't forget to always switch on the monitor at least at the same time the computer starts up, or earlier - else no windows can be moved to that monitor !