FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nativeapi-swift/Sources/NativeAPI/WindowManager.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
/
WindowManager.swift
Copy path
More file actions
More file actions
Latest commit
History
History
History
100 lines (82 loc) · 3.8 KB
Breadcrumbs
nativeapi-swift
/
Sources
/
NativeAPI
/
WindowManager.swift
Copy path
File metadata and controls
100 lines (82 loc) · 3.8 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// AUTO-GENERATED. DO NOT EDIT.
// Any manual changes WILL BE LOST when this file is regenerated.
import
CNativeAPI
import
Foundation
public
final
class
WindowManager
:
Sendable
{
/// The shared instance backed by the native singleton.
public
static
let
shared
=
WindowManager
(
)
private
init
(
)
{
}
public
func
get
(
id
:
WindowId
)
->
Window
?
{
let
handle
=
native_window_manager_get
(
id
)
guard
handle
!=
NATIVE_INVALID_WINDOW
else
{
return
nil
}
return
Window
(
nativeHandle
:
handle
)
}
public
func
getAll
(
)
->
[
Window
]
{
var
list
=
native_window_manager_get_all
(
)
var
items
:
[
Window
]
=
[
]
if
let
buffer
=
list
.
windows
{
for
index
in
0
..<
Int
(
list
.
count
)
{
items
.
append
(
Window
(
nativeHandle
:
buffer
[
index
]
)
)
}
}
// The handles now belong to `items`; free just the array.
native_window_list_release
(
&
list
)
return
items
}
public
func
getCurrent
(
)
->
Window
?
{
let
handle
=
native_window_manager_get_current
(
)
guard
handle
!=
NATIVE_INVALID_WINDOW
else
{
return
nil
}
return
Window
(
nativeHandle
:
handle
)
}
public
func
setWillShowHook
(
hook
:
(
(
UInt32
)
->
Void
)
?
)
->
Void
{
let
hookContext
=
hook
.
map
{
Unmanaged
.
passRetained
(
CallbackBox1
<
UInt32
>
(
$0
)
)
.
toOpaque
(
)
}
let
hookTrampoline
=
{
(
arg0
:
UInt32
,
userData
:
UnsafeMutableRawPointer
?
)
->
Void
in
guard
let
userData
else
{
return
}
Unmanaged
<
CallbackBox1
<
UInt32
>
>
.
fromOpaque
(
userData
)
.
takeUnretainedValue
(
)
.
body
(
arg0
)
}
as
@
convention
(
c
)
(
UInt32
,
UnsafeMutableRawPointer
?
)
->
Void
native_window_manager_set_will_show_hook
(
hookContext
!=
nil
?
hookTrampoline
:
nil
,
hookContext
)
}
public
func
setWillHideHook
(
hook
:
(
(
UInt32
)
->
Void
)
?
)
->
Void
{
let
hookContext
=
hook
.
map
{
Unmanaged
.
passRetained
(
CallbackBox1
<
UInt32
>
(
$0
)
)
.
toOpaque
(
)
}
let
hookTrampoline
=
{
(
arg0
:
UInt32
,
userData
:
UnsafeMutableRawPointer
?
)
->
Void
in
guard
let
userData
else
{
return
}
Unmanaged
<
CallbackBox1
<
UInt32
>
>
.
fromOpaque
(
userData
)
.
takeUnretainedValue
(
)
.
body
(
arg0
)
}
as
@
convention
(
c
)
(
UInt32
,
UnsafeMutableRawPointer
?
)
->
Void
native_window_manager_set_will_hide_hook
(
hookContext
!=
nil
?
hookTrampoline
:
nil
,
hookContext
)
}
public
func
hasWillShowHook
(
)
->
Bool
{
return
native_window_manager_has_will_show_hook
(
)
}
public
func
hasWillHideHook
(
)
->
Bool
{
return
native_window_manager_has_will_hide_hook
(
)
}
public
func
handleWillShow
(
id
:
WindowId
)
->
Void
{
native_window_manager_handle_will_show
(
id
)
}
public
func
handleWillHide
(
id
:
WindowId
)
->
Void
{
native_window_manager_handle_will_hide
(
id
)
}
public
func
callOriginalShow
(
id
:
WindowId
)
->
Bool
{
return
native_window_manager_call_original_show
(
id
)
}
public
func
callOriginalHide
(
id
:
WindowId
)
->
Bool
{
return
native_window_manager_call_original_hide
(
id
)
}
/// Registers `callback` for every `WindowEvent` this `WindowManager` 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
(
WindowEvent
)
->
Void
)
->
ListenerId
{
let
context
=
Unmanaged
.
passRetained
(
CallbackBox1
<
WindowEvent
>
(
callback
)
)
.
toOpaque
(
)
let
trampoline
:
@
convention
(
c
)
(
UnsafePointer
<
native_window_event_t
>
?
,
UnsafeMutableRawPointer
?
)
->
Void
=
{
event
,
userData
in
guard
let
event
,
let
userData
,
let
value
=
WindowEvent
(
raw
:
event
.
pointee
)
else
{
return
}
Unmanaged
<
CallbackBox1
<
WindowEvent
>
>
.
fromOpaque
(
userData
)
.
takeUnretainedValue
(
)
.
body
(
value
)
}
return
native_window_manager_add_listener
(
trampoline
,
context
)
}
/// Unregisters a listener. Returns false if unknown.
public
func
removeListener
(
_ listenerId
:
ListenerId
)
->
Bool
{
native_window_manager_remove_listener
(
listenerId
)
}
}
Back
|
FazBrowse Home
|
New Git URL