diff --git a/src/Facades/Screen.php b/src/Facades/Screen.php index fe917f1..82dfcfa 100644 --- a/src/Facades/Screen.php +++ b/src/Facades/Screen.php @@ -7,6 +7,9 @@ /** * @method static object cursorPosition() * @method static array displays() + * @method static array getCenterOfActiveScreen() + * @method static array active() + * @method static array primary() */ class Screen extends Facade { diff --git a/src/Screen.php b/src/Screen.php index dfd98bb..ab8d61b 100644 --- a/src/Screen.php +++ b/src/Screen.php @@ -6,7 +6,9 @@ class Screen { - public function __construct(protected Client $client) {} + public function __construct(protected Client $client) + { + } public function cursorPosition(): object { @@ -17,4 +19,32 @@ public function displays(): array { return $this->client->get('screen/displays')->json('displays'); } + + public function primary(): object + { + return $this->client->get('screen/primary-display')->json('primaryDisplay'); + } + + public function active(): object + { + return $this->client->get('screen/active')->json(); + } + + /** + * Returns the center of the screen where the mouse pointer is placed. + * + * @return array + */ + public function getCenterOfActiveScreen(): array + { + /* Navigate every screen and check for cursor position against the bounds of the screen. */ + $activeScreen = $this->active(); + + $bounds = $activeScreen['bounds']; + + return [ + 'x' => $bounds['x'] + $bounds['width'] / 2, + 'y' => $bounds['y'] + $bounds['height'] / 2, + ]; + } }