Browse Source

Ensure values returned from Xrandr layout driver are proper type

master
Adam Pippin 4 years ago
parent
commit
17c4bc7e2a
  1. 18
      app/LayoutDriver/Xrandr.php

18
app/LayoutDriver/Xrandr.php

@ -5,26 +5,26 @@ declare(strict_types=1);
namespace App\LayoutDriver; namespace App\LayoutDriver;
/** /**
* Interface to xrandr for configuring outputs * Interface to xrandr for configuring outputs.
* *
* @author Adam Pippin <hello@adampippin.ca> * @author Adam Pippin <hello@adampippin.ca>
*/ */
class Xrandr implements \App\ILayoutDriver class Xrandr implements \App\ILayoutDriver
{ {
/** /**
* The xrandr command * The xrandr command.
* @var \App\System\Command\Xrandr * @var \App\System\Command\Xrandr
*/ */
protected $_xrandr; protected $_xrandr;
/** /**
* Cache of current display parameters * Cache of current display parameters.
* @var array<string, array> * @var array<string, array>
*/ */
protected $_displays; protected $_displays;
/** /**
* Create a new xrandr driver * Create a new xrandr driver.
* *
* @param \App\System\Command\Xrandr $xrandr_cmd * @param \App\System\Command\Xrandr $xrandr_cmd
*/ */
@ -34,7 +34,7 @@ class Xrandr implements \App\ILayoutDriver
} }
/** /**
* Read display parameters from xrandr * Read display parameters from xrandr.
* *
* @return void * @return void
*/ */
@ -48,10 +48,10 @@ class Xrandr implements \App\ILayoutDriver
if (preg_match('/^(?<output>[^ ]+) connected (?<primary>primary )?(?<screen_w>[0-9]+)x(?<screen_h>[0-9]+)\\+(?<screen_x>[0-9]+)\\+(?<screen_y>[0-9]+) /', $line, $match)) if (preg_match('/^(?<output>[^ ]+) connected (?<primary>primary )?(?<screen_w>[0-9]+)x(?<screen_h>[0-9]+)\\+(?<screen_x>[0-9]+)\\+(?<screen_y>[0-9]+) /', $line, $match))
{ {
$this->_displays[$match['output']] = [ $this->_displays[$match['output']] = [
'x' => $match['screen_x'], 'x' => (int)$match['screen_x'],
'y' => $match['screen_y'], 'y' => (int)$match['screen_y'],
'w' => $match['screen_w'], 'w' => (int)$match['screen_w'],
'h' => $match['screen_h'], 'h' => (int)$match['screen_h'],
'primary' => !empty($match['primary']) 'primary' => !empty($match['primary'])
]; ];
} }

Loading…
Cancel
Save