Adam Pippin
4 years ago
19 changed files with 510 additions and 316 deletions
@ -1,71 +0,0 @@ |
|||
<?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); |
|||
} |
|||
} |
@ -1,14 +1,67 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
namespace App; |
|||
|
|||
/** |
|||
* Provide an interface to manipulating outputs |
|||
* |
|||
* @author Adam Pippin <hello@adampippin.ca> |
|||
*/ |
|||
interface ILayoutDriver |
|||
{ |
|||
|
|||
/** |
|||
* Set the offset of an output |
|||
* |
|||
* @param string $output |
|||
* @param int $x |
|||
* @param int $y |
|||
* @return void |
|||
*/ |
|||
public function setOffset(string $output, int $x, int $y): void; |
|||
|
|||
/** |
|||
* Get the offset of an output |
|||
* |
|||
* @param string $output |
|||
* @return int[] x, y |
|||
*/ |
|||
public function getOffset(string $output): array; |
|||
|
|||
/** |
|||
* Set the dimensions of the output |
|||
* |
|||
* @param string $output |
|||
* @param int $x |
|||
* @param int $y |
|||
* @return void |
|||
*/ |
|||
public function setDimensions(string $output, int $x, int $y): void; |
|||
|
|||
/** |
|||
* Get the dimensions of an output |
|||
* |
|||
* @param string $output |
|||
* @return int[] x, y |
|||
*/ |
|||
public function getDimensions(string $output): array; |
|||
|
|||
/** |
|||
* Check whether an output is connected |
|||
* |
|||
* @param string $output |
|||
* @return bool |
|||
*/ |
|||
public function isConnected(string $output): bool; |
|||
|
|||
/** |
|||
* Check whether the output is considered primary |
|||
* |
|||
* @param string $output |
|||
* @return bool |
|||
*/ |
|||
public function isPrimary(string $output): bool; |
|||
} |
|||
|
|||
} |
|||
|
@ -1,28 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Providers; |
|||
|
|||
use Illuminate\Support\ServiceProvider; |
|||
|
|||
class AppServiceProvider extends ServiceProvider |
|||
{ |
|||
/** |
|||
* Bootstrap any application services. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function boot() |
|||
{ |
|||
// |
|||
} |
|||
|
|||
/** |
|||
* Register any application services. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function register() |
|||
{ |
|||
// |
|||
} |
|||
} |
Loading…
Reference in new issue