Tool for laying out displays on Linux
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

71 lines
1.5 KiB

<?php
namespace App;
class Display
{
protected $_names;
protected $_output;
protected $_width;
protected $_height;
protected $_x;
protected $_y;
public function __construct(array $names)
{
$this->_names = $names;
}
public function read()
{
foreach ($this->_names as $name)
{
$xrandr = trim(shell_exec('xrandr | grep "^'.$name.'"'));
if (!empty($xrandr))
break;
}
if (empty($xrandr))
throw new \Exception("Cannot load display: ".end($this->_names));
# DVI-I-2-1 connected 1920x1080+1920+1440 (normal left inverted right x axis y axis) 521mm x 293mm
if (!preg_match('/^(?<output>[^ ]+) connected (?<screen_w>[0-9]+)x(?<screen_h>[0-9]+)\\+(?<screen_x>[0-9]+)\\+(?<screen_y>[0-9]+) /', $xrandr, $matches))
throw new \Exception("Cannot parse xrandr response for: ".$name);
$this->_output = $matches['output'];
$this->_x = $matches['screen_x'];
$this->_y = $matches['screen_y'];
$this->_width = $matches['screen_w'];
$this->_height = $matches['screen_h'];
}
public function getX(): int
{
return (int)$this->_x;
}
public function getY(): int
{
return (int)$this->_y;
}
public function getWidth(): int
{
return (int)$this->_width;
}
public function getHeight(): int
{
return (int)$this->_height;
}
public function setOffset(int $x, int $y): void
{
shell_exec('xrandr --output '.$this->_output.' --pos '.$x.'x'.$y);
}
public function setDimensions(int $width, int $height): void
{
shell_exec('xrandr --output '.$this->_output.' --mode '.$width.'x'.$height);
}
}