Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
1 change: 1 addition & 0 deletions src/Facades/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/**
* @method static object cursorPosition()
* @method static array displays()
* @method static array getCenterOfActiveScreen()
*/
class Screen extends Facade
{
Expand Down
54 changes: 45 additions & 9 deletions src/Screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,54 @@
namespace Native\Laravel;

use Native\Laravel\Client\Client;
use Illuminate\Support\Facades\Log;

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();
}
public function getClient()
{
return $this->client;
}

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

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,
];
}
}