Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie Syndacate's Avatar
    Join Date
    May 2012
    Location
    Hell..no literally, this state is hell..
    Posts
    196

    Swapping Monitors and X has stale invalid resolutions


    I'm writing an app which queries the resolution using the XLib C API, though I don't think this is important, just giving some context into what I'm looking for.

    So the problem I'm having is that X is remembering invalid resolutions and/or not trying to auto select new preferred resolutions, let me step-by-step it.

    I cold boot the system with a monitor plugged in, after booting I run "xrandr -d :0", and get this output:
    Code:
    Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767
    HDMI-0 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 520mm x 290mm
       1920x1080     60.00*+  59.95    50.00
       1680x1050     59.96
       1440x900      59.89
    ...
    OK, looks good, native & preferred resolution is selected, reports correctly, good to go. Now I unplug the monitor and re-run the command:
    Code:
    Screen 0: minimum 8 x 8, current 1920 x 1080, maximum 32767 x 32767
    HDMI-0 disconnected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
      1920x1080 (0x18c) 148.500MHz
            h: width  1920 start 2008 end 2052 total 2200 skew    0 clock  67.50KHz
            v: height 1080 start 1084 end 1089 total 1125           clock  60.00Hz
    So this is where the problems start, but it's not quite a problem yet. The problem is that a resolution is selected while there's no monitor plugged in to support that. I can workaround this easily by getting the HDMI plug connection status, so we're still fine, but now I plug in a new monitor, whose max resolution is 1680x1050, and re-run that command.....and now I have a problem: 1920x1080 is still the current preferred & selected resolution, and both my app and xrandr report that. The monitor doesn't support it, though, so it's throwing an "out of range" error. Now I'm stuck. If I reboot it the preferred/selected will be 1680x1050 as it should be.

    Restating makes it act as it should.

    I have 1 workaround which ALMOST works (and is ugly)
    1a. After unplugging the monitor I run "xrandr -d :0 --auto" to "reset" the resolution, so now "xrandr -d :0" reports:
    Code:
    Screen 0: minimum 8 x 8, current 8 x 8, maximum 32767 x 32767
    HDMI-0 disconnected primary (normal left inverted right x axis y axis)
    1b. The problem here is when I plug the monitor back in and run "xrandr -d :0" I get this:
    Code:
    Screen 0: minimum 8 x 8, current 8 x 8, maximum 32767 x 32767
    HDMI-0 connected primary (normal left inverted right x axis y axis)
       1920x1080     60.00 +  59.95    50.00
       1680x1050     59.96
    The UNSUPPORTED native resolution still shows up as preferred, but it's not selected.
    1c. I run "xrandr -d :0" AGAIN, and this selects the preferred display. The problem is this preferred display is still not valid/supported, so we wind up at square 1.

    I had a 2nd workaround which included restarting X, but I don't recall the exact steps I did - it's having same problem as above, which is very frustrating because restarting X is hacky enough, but it's not even working...

    So anybody have any ideas?

    X is able to somehow remember the old resolution even after it's been restarted, so somewhere else (where?) it's KEEPING the old preferred resolution across PID's. There needs to be some sort of resolution cache that I can flush or something.

    I need a way to do either:
    1. Clear all resolutions from X, so it has no preferred resolutions at all, then when I plug a new monitor in I can do the "auto select preferred" and that should work.
    2. Auto-select NEW preferred on plug-in (which is what I would expect it to do out of the box)

    Any ideas is appreciated!

  2. #2
    Linux Newbie Syndacate's Avatar
    Join Date
    May 2012
    Location
    Hell..no literally, this state is hell..
    Posts
    196
    -->
    Nobody? .

    I have the code set up so the only thing I need is a way to check if a particular mode_info is valid for the monitor.
    XRandR seems to not be able to tell if the selected mode_info is valid, so using XRR interface doesn't seem to be feasible. It's a real big problem, unfortunately...No idea how you're supposed to tell this...
    I either need a way to detect if a particular mode_info is supported via XRR or XLib, OR a way to enable auto-select (a system wide setting is fine) to select native resolution upon HDMI plug/unplug.

    EDIT:
    The only solidly reliable workaround I can think of is to parse the EDID info and check if the selected VIC exists in the monitor caps. That's a stupid round-about way to fix this problem, though.

    EDIT2:
    If I could get frame buffer info access via xrandr / XRR interface I think that would work. Regular DisplayWidth() macros aren't accurate (they use selected resolution information), but as I mentioned in 1st post, the frame buffer details inside /sys/class/graphics/fb0/mode are correct when HDMI is plugged in.
    Last edited by Syndacate; 08-07-2019 at 01:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •