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.
It should then print something like:
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!
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"; ?>
$ php test.php
W1280x960H
W1280x1024H
W1440x900H
W1680x1050H
W1280x960H
W1280x1024H
W1440x900H
W1680x1050H
Comment