NativePHP
Windows support is here! 🔥 Read the full announcement →
Screens

NativePHP is currently in alpha development

Let's get to beta!

#
Screens

The Screen facade lets you get information about the screens currently connected to the computer.

Copied!
1use Native\Laravel\Facades\Screen;

#
Displays

The displays method gives you an array of information about all the displays actually used.

The Display object represents a physical display connected to the system. A fake display may exist on a headless system, or a display may correspond to a remote, virtual display. If you use an external display with your laptop screen closed, the internal screen of your laptop will not be part of the array.

See Display object documentation.

Copied!
1$screens = Screen::displays();
2 
3[
4 0 => [
5 'bounds' => [
6 'x' => 0,
7 'y' => 0,
8 'width' => 2560,
9 'height' => 1440,
10 ],
11 'detected' => true,
12 'id' => 2026675401,
13 'internal' => false,
14 'label' => 'U3277WB',
15 'size' => [
16 'width' => 2560,
17 'height' => 1440,
18 ],
19 'workArea' => [
20 'x' => 0,
21 'y' => 25,
22 'width' => 2560,
23 'height' => 1345,
24 ],
25 // ...
26 ],
27 // ...
28]

The screen bounds are the desktop area that the screen covers. The x and y values are the top-left corner of the screen relative to the primary display, and the width and height values are the width and height of the screen.

#
Cursor position

The cursorPosition method gives you the coordinates of the current absolute position of the mouse cursor.

Copied!
1$position = Screen::cursorPosition();
2 
3(object) [
4 'x' => 627,
5 'y' => 168,
6]

The position of the cursor is relative to the top-left corner of the primary display. These values can be negative as well as positive.

For example, a secondary display may be oriented by your system to the right of your primary display. If your mouse cursor is on the secondary display when calling Screen::cursorPosition(), the x value will be a negative integer.