Announcement

Collapse
No announcement yet.

Call For Help: Run This Simple Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Call For Help: Run This Simple Script

    Hey guys,

    For those interested in PTS or just happen to have php-cli installed, it would be great if you could please save the below code to a .php file and then run it (php file.php) and post the output here. Just trying to make sure this code is working properly when it comes to reading all of the RandR resolutions we want.

    Code:
    <?php
    function pts_trim_double($double, $accuracy = 2)
    {
        $return = explode('.', $double);
    
        if(count($return) == 1)
            $return[1] = "00";
    
        if(count($return) == 2)
        {
            $strlen = strlen($return[1]);
    
            if($strlen > $accuracy)
                $return[1] = substr($return[1], 0, $accuracy);
            else if($strlen < $accuracy)
                for($i = $strlen; $i < $accuracy; $i++)
                    $return[1] .= '0';
    
            $return = $return[0] . "." . $return[1];
        }
        else
            $return = $return[0];
    
        return $return;
    }
    function xrandr_available_modes()
    {
        $info = shell_exec("xrandr 2>&1");
        $xrandr_lines = array_reverse(explode("\n", $info));
        $available_modes = array();
    
        foreach($xrandr_lines as $xrandr_mode)
        {
            $res = explode("x", $xrandr_mode);
    
            if(count($res) == 2)
            {
                $res[0] = trim($res[0]);
                $res[1] = trim($res[1]);
    
                $res[0] = substr($res[0], strpos($res[0], " "));
                $res[1] = substr($res[1], 0, strpos($res[1], " "));
    
                if(is_numeric($res[0]) && is_numeric($res[1]) && $res[0] >= 800 && $res[1] >= 600)
                {
                    $ratio = pts_trim_double($res[0] / $res[1], 2);
                    $supported_ratios = array(1.60, 1.25, 1.33);
    
                    if(in_array($ratio, $supported_ratios))
                        array_push($available_modes, array($res[0], $res[1]));
                }
            }
        }
    
        if(count($available_modes) < 2)
        {
            $available_modes = array(array(800, 600), array(1024, 768), array(1280, 1024), array(1680, 1050), array(1600, 1200), array(1920, 1080));
        }
    
        return $available_modes;
    }
    
    foreach(xrandr_available_modes() as $mode)
        echo "W" . $mode[0] . "x" . $mode[1] . "H\n";
    
    ?>
    It should then print something like:

    $ php test.php
    W1280x960H
    W1280x1024H
    W1440x900H
    W1680x1050H
    I just want to make sure for some configurations that it's not messing up with parsing the xrandr information or showing odd resolutions. Thanks!
    Michael Larabel
    https://www.michaellarabel.com/

  • #2
    At least I got something to work

    W1280x800H
    W1400x1050H
    W1280x1024H
    W1280x960H
    W1152x864H
    W800x600H
    W832x624H
    W1024x768H

    Now if I could just figure out how to run a benchmark test...

    Comment


    • #3
      W1152x864H
      W1280x960H
      W800x600H
      W1024x768H
      W1280x1024H

      Comment


      • #4
        W800x600H
        W1024x768H
        W1280x1024H
        W1680x1050H
        W1600x1200H
        W1920x1080H

        Comment


        • #5
          Thanks guys, that should be enough to see it works. Try out Phoronix Test Suite 1.2.0 Beta 1 and now when running a graphics game that gives you a resolution option (aside from ut2004-demo), instead of showing a static list of resolutions it will dynamically generate the list for you based upon your monitor and GPU and what's reported to RandR.
          Michael Larabel
          https://www.michaellarabel.com/

          Comment

          Working...
          X