I have an HDMI monitor which I unplug and plug back into my laptop from time to time. When I unplug the monitor, all the windows are moved onto the laptop display. However, when I plug it back in, all the windows are moved onto the 2nd display (which is on the left of the laptop display), even though I haven't moved them myself.

How can I make KDE preserve which display each window is on across unplug-and-replug?

  • Probably not possible. After you unplug, then the previous positioning information is lost. Short of writing a custom script, I can't imagine why Plasma would save this historical information. Also, I'm not sure if this is part of your question, but I think Plasma references the location of windows relative to the top left pixel as the origin. Hence, after you plug the monitor back in, they'll stay on the left-most screen. If you prefer the windows to stay on the laptop screen, I think you can just make that screen "left". (I'm not sure if "Primary screen" has any effect here.) – Sparhawk Oct 2 '16 at 23:50

You can save the current position of windows with:

wmctrl -lG > ~/.windowlistrc

You can restore them with:


while read row; do
  IFS=" " read id g x y w h _ <<< ${row}
  if [[ ${g} == "-1" ]]; then continue; fi
  wmctrl -ir ${id} -b toggle,maximized_vert,maximized_horz
  wmctrl -ir ${id} -b remove,maximized_vert,maximized_horz
  y=$(( ${y} - 30 ))
  wmctrl -ir ${id} -e 0,${x},${y},${w},${h}
done < ${rcfile}

The restore could be much simpler, but I found I needed to toggle things on and off for windows that were arranged by the window manager after dragging near a side or top, and then expanded (by the wm) to fill half the monitor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.