File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 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 */
1114class Screen extends Facade
1215{
Original file line number Diff line number Diff line change 66
77class 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}
You can’t perform that action at this time.
0 commit comments