All monitors turn off when adding or removing one due to uninitialized values in crtc struct
@ali1234
Submitted by Alistair Buxton Assigned to Xfce Bug Triage
Description
Wen you connect or disconnect a monitor to the system, display settings tries to re-configure the screen appropriately. It looks for a saved profile matching the set of connected monitors to apply. If there is no such saved profile it attempts to come up with a reasonable default.
The problem happens because during this process it tries to calculate the screen size required to contain all monitors. In doing this it takes in to account the monitor's scalex and scaley. These are crtc->scalex and crtc->scaley in the code. The calculation looks like this:
helper->width = MAX (helper->width, crtc->x + crtc->width * crtc->scalex);
helper->height = MAX (helper->height, crtc->y + crtc->height * crtc->scaley);
This runs for each monitor to accumulate the right-most and bottom-most coordinates of all monitors.
The crtc struct is initialized here:
Notice that scalex and scaley are not initialized in this code. They are only initialized here:
https://github.com/xfce-mirror/xfce4-settings/blob/master/xfsettingsd/displays.c#L849
That piece of code runs when loading a profile from xfconf, and that only happens if your monitor configuration has a matching profile. If you add or remove a monitor such that you are in a state that doesn't match any profile, then scalex and scaley are used uninitialized in the screen calculation, meaning that they have value 0, and it thinks that all your monitors are 0x0. The screen size then ends up as the rectangle containing all the top left coordinates of all monitors. Display settings then thinks your monitors cannot fit on the screen, so it turns them off. Now all your monitors are turned off and you can't turn them back on unless you can put them back into a state that matches a saved profile, or you reboot.
So the question is how to fix this. It would be trivial to initialize the crtc struct with 1 instead of 0 for scale. This prevents the problem from happening for me, however I do not use the scale feature at all, and this may have side-effects for people who do.