_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('/^(?[^ ]+) connected (?[0-9]+)x(?[0-9]+)\\+(?[0-9]+)\\+(?[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); } }