Skip to content

Commit b5982c5

Browse files
added getCenterOfActiveScreen in Screen class (#375)
1 parent 4666245 commit b5982c5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/Facades/Screen.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/**
88
* @method static object cursorPosition()
99
* @method static array displays()
10+
* @method static array getCenterOfActiveScreen()
11+
* @method static array active()
12+
* @method static array primary()
1013
*/
1114
class Screen extends Facade
1215
{

src/Screen.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
class Screen
88
{
9-
public function __construct(protected Client $client) {}
9+
public function __construct(protected Client $client)
10+
{
11+
}
1012

1113
public function cursorPosition(): object
1214
{
@@ -17,4 +19,32 @@ public function displays(): array
1719
{
1820
return $this->client->get('screen/displays')->json('displays');
1921
}
22+
23+
public function primary(): object
24+
{
25+
return $this->client->get('screen/primary-display')->json('primaryDisplay');
26+
}
27+
28+
public function active(): object
29+
{
30+
return $this->client->get('screen/active')->json();
31+
}
32+
33+
/**
34+
* Returns the center of the screen where the mouse pointer is placed.
35+
*
36+
* @return array<string,int>
37+
*/
38+
public function getCenterOfActiveScreen(): array
39+
{
40+
/* Navigate every screen and check for cursor position against the bounds of the screen. */
41+
$activeScreen = $this->active();
42+
43+
$bounds = $activeScreen['bounds'];
44+
45+
return [
46+
'x' => $bounds['x'] + $bounds['width'] / 2,
47+
'y' => $bounds['y'] + $bounds['height'] / 2,
48+
];
49+
}
2050
}

0 commit comments

Comments
 (0)