*/ class Xrandr implements \App\ILayoutDriver { /** * The xrandr command * @var \App\System\Command\Xrandr */ protected $_xrandr; /** * Cache of current display parameters * @var array */ protected $_displays; /** * Create a new xrandr driver * * @param \App\System\Command\Xrandr $xrandr_cmd */ public function __construct(\App\System\Command\Xrandr $xrandr_cmd) { $this->_xrandr = $xrandr_cmd; } /** * Read display parameters from xrandr * * @return void */ public function read() { $xrandr = $this->_xrandr->__invoke([]); $this->_displays = []; foreach ($xrandr as $line) { if (preg_match('/^(?[^ ]+) connected (?primary )?(?[0-9]+)x(?[0-9]+)\\+(?[0-9]+)\\+(?[0-9]+) /', $line, $match)) { $this->_displays[$match['output']] = [ 'x' => $match['screen_x'], 'y' => $match['screen_y'], 'w' => $match['screen_w'], 'h' => $match['screen_h'], 'primary' => !empty($match['primary']) ]; } } } public function setOffset(string $output, int $x, int $y): void { $this->_displays[$output]['x'] = $x; $this->_displays[$output]['y'] = $y; $this->_xrandr->__invoke(['--output', $output, '--pos', $x.'x'.$y]); echo "Put $output at ${x}x${y}".PHP_EOL; } public function getOffset(string $output): array { return [ $this->_displays[$output]['x'], $this->_displays[$output]['y'] ]; } public function setDimensions(string $output, int $w, int $h): void { $this->_displays[$output]['w'] = $w; $this->_displays[$output]['h'] = $h; $this->_xrandr->__invoke(['--output', $output, '--mode', $w.'x'.$h]); } public function getDimensions(string $output): array { return [ $this->_displays[$output]['w'], $this->_displays[$output]['h'] ]; } public function isPrimary(string $output): bool { return $this->_displays[$output]['primary']; } public function isConnected(string $output): bool { return isset($this->_displays[$output]); } }