Server Administration and Linux Tipps & Tricks

Xinerama moving windows problemAre you a Xinerama user, who runs regularly into a Xinerama moving windows problem like this one on the left?

It’s your lucky day. You have finally found the solution for that damned bug in Xinerama!

I couldn’t find the answer anywhere before. As I have finally fixed it, I am going to share the solution for the other fellow Xinerama users.

I used Xinerama moving windows problem phrase so many times for SEO purposes. It will make people looking for fixing that problem find this website.

I have found this Xinerama moving windows problem happens when you have incorrectly set screen order in your /etc/X11/xorg.conf file. The windows are starting to jump on other monitors when you, for example, try to move a window from screen 1 to screen 3. Not all windows behave like this, but there is software that does it all the time (NetBeans is an example).

To fix and set the screen order properly (which fixes the Xinerama moving windows problem), you need to set screen IDs using a proper order. To achieve that, you need to order the monitors in your xorg.conf file starting from monitor most to the left, ending on monitor most to the right. If you have a multi-level monitors setup as I have, start by numbering left-to-right monitors on top, then continue left-to-right for monitors on bottom.

How to set the screens and identify monitors in xorg.conf file?

Open terminal as a root and go to /etc/X11 directory.
# cd /etc/X11

Create a backup of the xorg.conf file. We do not want to mess up our X server if something goes wrong.
# cp xorg.conf xorg.conf.bak

Open the xorg.conf file for editing.
# vim xorg.conf

In the opened file, you need to find Section “ServerLayout”

ServerLayout section in xorg.confWhat interest you there, are “Screen” values. They have syntax as following:

screen <id> <identifier> <horizontal position (axis X)> <vertical position (axis Y)>

This layout represents the following setup:

My monitors setup

As you look at the order of screens in xorg.conf and physical order of monitors, you see something is not right.

The screen 0 is the monitor in the middle (bottom), screen 1 is the top monitor, screen 2 is the right one and screen 3 is left one. A complete disorder!

To fix that, change the order by numbering monitors from zero starting from left to right. If you use a similar setup like me, start counting from top monitors left-to right, then bottom monitors left to right. To change the order, you need to update the screen IDs.

In my case, the update looked as following: screen 1 -> screen 0,  3 -> 1,  0->2,  2-> 3.

Here is again the screen value syntax:

screen <screen id> <identifier> <horizontal position (axis X)> <vertical position (axis Y)>

Once you have your screen IDs updated, restart the X server. You may do it just by logging off and then logging in again. If your system does not restart X during logging off, you can try ctrl+alt+backspace key combination. If you are Ubuntu user, you may try Right-Alt + PrintScreen + K combination. If none works, simply reboot. Remember that restarting X makes you log out immediately, so be sure you have all files saved – you will lost them otherwise!

Once X server is restarted, you will notice something is not right. Your monitors will display screens not in your physical monitors order. Monitor at the left may be displaying the screen that should be at the right side, etc.

You have to update the layout of the monitors in xorg.conf. You need to let your X server know, that a monitor on your left side is on the left side, and monitor on the right side in on the right side, etc. To do that, you need to update the horizontal and vertical positions of the screens.

screen <screen id> <identifier> <horizontal position (axis X)> <vertical position (axis Y)>

The best and fastest way to fix the positions is to use the tools that came with your graphic card drivers. For example, nvidia users have nvidia-settings tool, executed by following command (be sure to be root, otherwise you will be not able to update xorg.conf content!):
# nvidia-settings

nvidia-settings

Using nvidia-settings tool you can reposition the screens using your mouse. Click “Save to X Configuration File” once you are done and choose the option to “merge with existing xorg.conf file” in the window that will appear.

Another way, if you have no access to such cool tools, is just to swap the current values you already have, by using copy-paste.

My top screen, previously with ID 1 and currently with 0, had this position set: 2160 0. I had copied this value to my screen ID 0. My left screen was identified with ID 3 and now has ID 1. It had value 0 900. I had copied it to screen ID 1. You need to perform the same operation using your values. Copy your screen values to a notepad before you start editing, otherwise you will override other values and forget what they were.

Once your layout is done, you can restart your X server again. If your screens are still not positioned properly, you have made a mistake with your positions in xorg.conf. You need to correct them.

If the screens are displayed correctly, then congratulations – everything is done!

Now you can enjoy Xinerama without that terrible bug which throws windows away to other monitors during resizing or moving.

Your Xinerama moving windows problem is fixed!