*/ class Screen { /** * A list of possible hardware outputs that could implement this screen * @var string[] */ protected $_outputs; /** * The driver for manipulating the layout * @var ILayoutDriver */ protected $_driver; /** * Set up a new screen * * @param string[] $outputs * @param ILayoutDriver $driver */ public function __construct(array $outputs, ILayoutDriver $driver) { $this->_outputs = $outputs; $this->_driver = $driver; } /** * Enumerate all possible outputs and return the first that is found to be connected * * @return string */ protected function getOutputName(): string { foreach ($this->_outputs as $output) { if ($this->_driver->isConnected($output)) { return $output; } } throw new \Exception("No connected output found!"); } /** * Determine whether this screen is connected * * @return bool */ public function isConnected(): bool { try { $this->getOutputName(); return true; } catch (\Exception $ex) { return false; } } /** * Determine whether this screen is considered the "primary" screen * * @return bool */ public function isPrimary(): bool { return $this->_driver->isPrimary($this->getOutputName()); } /** * Get the pixel dimensions of the screen * * @return int[] x, y */ public function getDimensions(): array { return $this->_driver->getDimensions($this->getOutputName()); } /** * Get the pixel offset of the screen * * @return int[] x, y */ public function getOffset(): array { return $this->_driver->getOffset($this->getOutputName()); } /** * Set the pixel offset of the screen * * @param int $x * @param int $y * @return void */ public function setOffset(int $x, int $y): void { $this->_driver->setOffset($this->getOutputName(), $x, $y); } /** * Set the resolution of the screen * * @param int $w * @param int $h * @return void */ public function setDimensions(int $w, int $h): void { $this->_driver->setDimensions($this->getOutputName(), $w, $h); } }