/
syswm.go
144 lines (117 loc) · 4.09 KB
/
syswm.go
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package sdl
/*
#include "sdl_wrapper.h"
#if defined(__WIN32)
#include <SDL2/SDL_syswm.h>
#else
#include <SDL_syswm.h>
#endif
#if !(SDL_VERSION_ATLEAST(2,0,2))
#define SDL_SYSWM_WAYLAND SDL_SYSWM_UNKNOWN
#define SDL_SYSWM_MIR SDL_SYSWM_UNKNOWN
#endif
#if !(SDL_VERSION_ATLEAST(2,0,3))
#if defined(WARN_OUTDATED)
#pragma message("SDL_SYSWM_WINRT is not supported before SDL 2.0.3")
#endif
#define SDL_SYSWM_WINRT (0)
#endif
#if !(SDL_VERSION_ATLEAST(2,0,4))
#if defined(WARN_OUTDATED)
#pragma message("SDL_SYSWM_ANDROID is not supported before SDL 2.0.4")
#endif
#define SDL_SYSWM_ANDROID (0)
#endif
#if !(SDL_VERSION_ATLEAST(2,0,5))
#if defined(WARN_OUTDATED)
#pragma message("SDL_SYSWM_VIVANTE is not supported before SDL 2.0.5")
#endif
#define SDL_SYSWM_VIVANTE (0)
#endif
*/
import "C"
import "unsafe"
// Various supported windowing subsystems.
const (
SYSWM_UNKNOWN = C.SDL_SYSWM_UNKNOWN
SYSWM_WINDOWS = C.SDL_SYSWM_WINDOWS // Microsoft Windows
SYSWM_X11 = C.SDL_SYSWM_X11 // X Window System
SYSWM_DIRECTFB = C.SDL_SYSWM_DIRECTFB // DirectFB
SYSWM_COCOA = C.SDL_SYSWM_COCOA // Apple Mac OS X
SYSWM_UIKIT = C.SDL_SYSWM_UIKIT // Apple iOS
SYSWM_WAYLAND = C.SDL_SYSWM_WAYLAND // Wayland (>= SDL 2.0.2)
SYSWM_MIR = C.SDL_SYSWM_MIR // Mir (>= SDL 2.0.2)
SYSWM_WINRT = C.SDL_SYSWM_WINRT // WinRT (>= SDL 2.0.3)
SYSWM_ANDROID = C.SDL_SYSWM_ANDROID // Android (>= SDL 2.0.4)
SYSWM_VIVANTE = C.SDL_SYSWM_VIVANTE // Vivante (>= SDL 2.0.5)
)
// SysWMInfo contains system-dependent information about a window.
// (https://wiki.libsdl.org/SDL_SysWMinfo)
type SysWMInfo struct {
Version Version // a Version structure that contains the current SDL version
Subsystem uint32 // the windowing system type
dummy [24]byte // unused (to help compilers when no specific system is available)
}
// WindowsInfo contains Microsoft Windows window information.
type WindowsInfo struct {
Window unsafe.Pointer // the window handle
}
// X11Info contains X Window System window information.
type X11Info struct {
Display unsafe.Pointer // the X11 display
Window uint // the X11 window
}
// DFBInfo contains DirectFB window information.
type DFBInfo struct {
Dfb unsafe.Pointer // the DirectFB main interface
Window unsafe.Pointer // the DirectFB window handle
Surface unsafe.Pointer // the DirectFB client surface
}
// CocoaInfo contains Apple Mac OS X window information.
type CocoaInfo struct {
Window unsafe.Pointer // the Cocoa window
}
// UIKitInfo contains Apple iOS window information.
type UIKitInfo struct {
Window unsafe.Pointer // the UIKit window
}
// SysWMmsg contains system-dependent window manager messages.
// (https://wiki.libsdl.org/SDL_SysWMmsg)
type SysWMmsg struct {
Version Version // a Version structure that contains the current SDL version
Subsystem uint32 // the windowing system type
data [24]byte // internal data
}
func (info *SysWMInfo) cptr() *C.SDL_SysWMinfo {
return (*C.SDL_SysWMinfo)(unsafe.Pointer(info))
}
// GetWMInfo returns driver specific information about a window.
// (https://wiki.libsdl.org/SDL_GetWindowWMInfo)
func (window *Window) GetWMInfo() (*SysWMInfo, error) {
var info SysWMInfo
VERSION(&info.Version)
if C.SDL_GetWindowWMInfo(window.cptr(), info.cptr()) == 0 {
return nil, GetError()
}
return &info, nil
}
// GetWindowsInfo returns Microsoft Windows window information.
func (info *SysWMInfo) GetWindowsInfo() *WindowsInfo {
return (*WindowsInfo)(unsafe.Pointer(&info.dummy[0]))
}
// GetX11Info returns X Window System window information.
func (info *SysWMInfo) GetX11Info() *X11Info {
return (*X11Info)(unsafe.Pointer(&info.dummy[0]))
}
// GetDFBInfo returns DirectFB window information.
func (info *SysWMInfo) GetDFBInfo() *DFBInfo {
return (*DFBInfo)(unsafe.Pointer(&info.dummy[0]))
}
// GetCocoaInfo returns Apple Mac OS X window information.
func (info *SysWMInfo) GetCocoaInfo() *CocoaInfo {
return (*CocoaInfo)(unsafe.Pointer(&info.dummy[0]))
}
// GetUIKitInfo returns Apple iOS window information.
func (info *SysWMInfo) GetUIKitInfo() *UIKitInfo {
return (*UIKitInfo)(unsafe.Pointer(&info.dummy[0]))
}