Skip to content

Commit

Permalink
added getCenterOfActiveScreen in Screen class (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpetrica authored Oct 20, 2024
1 parent 4666245 commit b5982c5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/Facades/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
32 changes: 31 additions & 1 deletion src/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

class Screen
{
public function __construct(protected Client $client) {}
public function __construct(protected Client $client)
{
}

public function cursorPosition(): object
{
Expand All @@ -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<string,int>
*/
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,
];
}
}

0 comments on commit b5982c5

Please sign in to comment.