Search Unity

Linux standalone player detects 2 screens as one

Discussion in 'Linux' started by Teku-Studios, Oct 13, 2016.

  1. Teku-Studios

    Teku-Studios

    Joined:
    Sep 29, 2012
    Posts:
    257
    · When having a 5:4 and a 21:9 screen connected, I'm getting a "32:9" aspect ratio when checking the main screen
    · When having a 16:9 and a 21:9 screen connected, I'm getting "112:27" aspect ratio when checking the main screen

    Doing some quick maths, (16+21,33)*3 is 112, and transforming 5:4 into a :9 resolution as well makes about 32 when added to 21. Therefore, I think Linux simply adds the two screens together when giving you back the aspect ratio, making nonsense results.

    Is there anything that can be done about this? As usual, I've filed a bug report, just in case:
    https://fogbugz.unity3d.com/default.asp?841094_42q89r7us77cgqi9
     
  2. Teku-Studios

    Teku-Studios

    Joined:
    Sep 29, 2012
    Posts:
    257
  3. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    How are you querying the aspect ratio?
    If you're just doing math based on Screen.currentResolution, it should be noted that this reports the combined desktop resolution on Linux (since that's what the OS reports to us).
    (I also said that on the other thread.)
     
  4. Teku-Studios

    Teku-Studios

    Joined:
    Sep 29, 2012
    Posts:
    257
    Yeah, I use that. Let me show you what I do:

    Code (CSharp):
    1. Vector2 currentAR = GetAspectRatio (Screen.currentResolution.width, Screen.currentResolution.height);
    2.  
    3. Vector2 GetAspectRatio(int x, int y){
    4.     float xf = x;
    5.     float yf = y;
    6.     float f = xf / yf;
    7.     int i = 0;
    8.  
    9.     while(true){
    10.         i++;
    11.         if(System.Math.Round(f * i, 2) == Mathf.RoundToInt(f * i))
    12.             break;
    13.     }
    14.  
    15.     return new Vector2((int)System.Math.Round(f * i, 2), i);
    16. }
    17.  
    18. //Then I do
    19. if(currentAR == new Vector2(16, 9)){ //16:9 monitors
    20.    //blah blah
    21. } else {
    22.    //blah blah
    23. }
    I have to check the current screen's resolution in order to apply certain changes to UIs and other things, but since I keep getting both screens combined (it's worst when each screen has a different AR e.g. one being 16:9 and the other 16:10) I cannot perform the proper actions.

    What would be the best approach for this (although I know this is more of a general code question)?
     
  5. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    Just use Screen.width and Screen.height.
     
    Teku-Studios likes this.
  6. Teku-Studios

    Teku-Studios

    Joined:
    Sep 29, 2012
    Posts:
    257
    Oh wow, that was indeed an easy change. Thanks a lot.

    Does the "Capture Single Screen" property also fix things for this? I have it unchecked.
     
  7. Tak

    Tak

    Joined:
    Mar 8, 2010
    Posts:
    1,001
    I believe this only affects Windows exclusive mode fullscreen.
     
    Teku-Studios likes this.