Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
36 changes: 33 additions & 3 deletions src/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,45 @@

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

public function cursorPosition(): object
{
return (object) $this->client->get('screen/cursor-position')->json();
return (object) $this->client->get("screen/cursor-position")->json();
}

public function displays(): array
{
return $this->client->get('screen/displays')->json('displays');
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,
];
}
}