8000 Screen documentation · SRWieZ/fork-nativephp.com@28ee9e8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 28ee9e8

Browse files
committed
Screen documentation
1 parent 718143a commit 28ee9e8

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

resources/views/docs/1/the-basics/screens.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,43 @@ use Native\Laravel\Facades\Screen;
1212

1313
## Displays
1414

15-
The `displays` method gives you an array of information about all the displays actually used.
15+
The `displays` method gives you an array of information about all the displays actually used.
1616

17-
If you use an external display with your laptop screen closed, the internal screen of your laptop will not be part of the array.
17+
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.
1818

1919
See [Display object](https://www.electronjs.org/docs/latest/api/structures/display) documentation.
2020

2121
```php
2222
$screens = Screen::displays();
2323
```
2424

25+
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.
26+
27+
Example to found out in what screen the window is located:
28+
29+
```php
30+
function getCurrentScreen()
31+
{
32+
$screens = Screen::displays();
33+
$window = Window::current();
34+
35+
foreach ($screens as $screen) {
36+
$bounds = $screen['bounds'];
37+
if ($window->x >= $bounds['x'] && $window->x <= $bounds['x'] + $bounds['width'] && $window->y >= $bounds['y'] && $window->y <= $bounds['y'] + $bounds['height']) {
38+
return $screen;
39+
}
40+
}
41+
42+
return null;
43+
}
44+
```
45+
46+
2547
## Cursor position
2648

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

51+
The position of the cursor is relative to the top-left corner of the primary display. So if your external display is on the right of your laptop screen, the `x` value will be negative.
2952
```php
3053
$position = Screen::cursorPosition();
3154

0 commit comments

Comments
 (0)
0