! Please note that this is a snapshot of our old Bugzilla server, which is read only since May 29, 2020. Please go to gitlab.xfce.org for our new server !
All monitors turn off when adding or removing one due to uninitialized values...
Status:
RESOLVED: MOVED
Product:
Xfce4-settings
Component:
Display Settings

Comments

Description Alistair Buxton 2019-09-18 02:19:59 CEST
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:

https://git.xfce.org/xfce/xfce4-settings/tree/xfsettingsd/displays.c?id=a5ed05fe5e65a501a56eb632c5301e806633902e#n1265

    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:

https://git.xfce.org/xfce/xfce4-settings/tree/xfsettingsd/displays.c?id=a5ed05fe5e65a501a56eb632c5301e806633902e#n1113

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.
Comment 1 Alistair Buxton 2019-09-18 02:35:54 CEST
Created attachment 9034 
Trivial but possibly wrong patch

This patch initializes the fields to 1 when the struct is first created. This fixes the problem at least if you don't use monitor scaling. I have not tested what happens if you do.
Comment 2 Git Bot editbugs 2019-09-18 14:30:30 CEST
Alistair Buxton referenced this bugreport in commit 8f46eb503d60c1b2ded00d7888c47a6ff3702546

display: Initialize crtc->scalex/y (Bug #15971)

https://git.xfce.org/xfce/xfce4-settings/commit?id=8f46eb503d60c1b2ded00d7888c47a6ff3702546
Comment 3 Git Bot editbugs 2019-09-18 14:31:19 CEST
Alistair Buxton referenced this bugreport in commit db3ca3c489ca33bdca8b616fe321af196462f1ae

display: Initialize crtc->scalex/y (Bug #15971)

https://git.xfce.org/xfce/xfce4-settings/commit?id=db3ca3c489ca33bdca8b616fe321af196462f1ae
Comment 4 Simon Steinbeiss editbugs 2019-09-18 14:32:34 CEST
I pushed the patch because it's always safe to initialize the value (it doesn't override anything else further down the road).

We probably still need a proper patch which gets the scale in those cases.
Comment 5 Git Bot editbugs 2020-05-28 23:15:00 CEST
-- GitLab Migration Automatic Message --

This bug has been migrated to xfce.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.xfce.org/xfce/xfce4-settings/-/issues/146.

Please create an account or use an existing account on one of our supported OAuth providers. 

If you want to fork to submit patches and merge requests please continue reading here: https://docs.xfce.org/contribute/dev/git/start#gitlab_forks_and_merge_requests

Also feel free to reach out to us on the mailing list https://mail.xfce.org/mailman/listinfo/xfce4-dev

Bug #15971

Reported by:
Alistair Buxton
Reported on: 2019-09-18
Last modified on: 2020-05-28

People

Assignee:
Xfce Bug Triage
CC List:
1 user

Version

Version:
unspecified

Attachments

Trivial but possibly wrong patch (1.01 KB, patch)
2019-09-18 02:35 CEST , Alistair Buxton
no flags

Additional information