Results 1 to 5 of 5

Thread: Call For Help: Run This Simple Script

  1. #1

    Default 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!

  2. #2
    Join Date
    Mar 2008
    Location
    40N 105W
    Posts
    45

    Default 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...

  3. #3
    Join Date
    Nov 2007
    Posts
    20

    Default

    W1152x864H
    W1280x960H
    W800x600H
    W1024x768H
    W1280x1024H

  4. #4
    Join Date
    Apr 2008
    Posts
    22

    Default

    W800x600H
    W1024x768H
    W1280x1024H
    W1680x1050H
    W1600x1200H
    W1920x1080H

  5. #5

    Default

    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.

Posting Permissions

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