FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nativeapi-swift/Sources/NativeAPI/DisplayManager.swift at main · libnativeapi/nativeapi-swift · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
libnativeapi
/
nativeapi-swift
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
3
Code
Issues
0
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
nativeapi-swift
/
Sources
/
NativeAPI
/
DisplayManager.swift
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (46 loc) · 2.02 KB
Breadcrumbs
nativeapi-swift
/
Sources
/
NativeAPI
/
DisplayManager.swift
Copy path
File metadata and controls
56 lines (46 loc) · 2.02 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.
import
CNativeAPI
import
Foundation
public
final
class
DisplayManager
:
Sendable
{
/// The shared instance backed by the native singleton.
public
static
let
shared
=
DisplayManager
(
)
private
init
(
)
{
}
public
func
getAll
(
)
->
[
Display
]
{
var
list
=
native_display_manager_get_all
(
)
var
items
:
[
Display
]
=
[
]
if
let
buffer
=
list
.
displays
{
for
index
in
0
..<
Int
(
list
.
count
)
{
items
.
append
(
Display
(
nativeHandle
:
buffer
[
index
]
)
)
}
}
// The handles now belong to `items`; free just the array.
native_display_list_release
(
&
list
)
return
items
}
public
func
getPrimary
(
)
->
Display
?
{
let
handle
=
native_display_manager_get_primary
(
)
guard
handle
!=
NATIVE_INVALID_DISPLAY
else
{
return
nil
}
return
Display
(
nativeHandle
:
handle
)
}
public
func
getCursorPosition
(
)
->
Point
{
return
Point
(
raw
:
native_display_manager_get_cursor_position
(
)
)
}
/// Registers `callback` for every `DisplayEvent` this `DisplayManager` emits.
///
/// The closure is retained for good: the C ABI keeps the context
/// pointer but offers no hook to release it, so removing the listener
/// stops the calls without freeing the closure.
public
func
addListener
(
_ callback
:
@escaping
(
DisplayEvent
)
->
Void
)
->
ListenerId
{
let
context
=
Unmanaged
.
passRetained
(
CallbackBox1
<
DisplayEvent
>
(
callback
)
)
.
toOpaque
(
)
let
trampoline
:
@
convention
(
c
)
(
UnsafePointer
<
native_display_event_t
>
?
,
UnsafeMutableRawPointer
?
)
->
Void
=
{
event
,
userData
in
guard
let
event
,
let
userData
,
let
value
=
DisplayEvent
(
raw
:
event
.
pointee
)
else
{
return
}
Unmanaged
<
CallbackBox1
<
DisplayEvent
>
>
.
fromOpaque
(
userData
)
.
takeUnretainedValue
(
)
.
body
(
value
)
}
return
native_display_manager_add_listener
(
trampoline
,
context
)
}
/// Unregisters a listener. Returns false if unknown.
public
func
removeListener
(
_ listenerId
:
ListenerId
)
->
Bool
{
native_display_manager_remove_listener
(
listenerId
)
}
}
Back
|
FazBrowse Home
|
New Git URL