Skip to content

added getCenterOfActiveScreen in Screen class #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
];
}
}