@kmamal/sdl 0.10.14 → 0.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/package.json +1 -1
- package/src/native/cocoa-window.h +3 -0
- package/src/native/cocoa-window.mm +6 -0
- package/src/native/window.cpp +53 -41
- package/src/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -960,10 +960,14 @@ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) wi
|
|
|
960
960
|
|
|
961
961
|
### window.native
|
|
962
962
|
|
|
963
|
-
* `<
|
|
963
|
+
* `<object>`
|
|
964
|
+
* `handle : <Buffer>` The platform-specific handle of the window.
|
|
965
|
+
|
|
966
|
+
The native type of `handle` is HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux.
|
|
967
|
+
It should work exactly like the [`win.getNativeWindowHandle()`](https://www.electronjs.org/docs/latest/api/browser-window#wingetnativewindowhandle) electron method.
|
|
964
968
|
|
|
965
|
-
|
|
966
|
-
|
|
969
|
+
This object might also include extra fields that are used for passing to [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) or [@kmamal/gpu](https://github.com/kmamal/gpu#readme).
|
|
970
|
+
Please ignore these.
|
|
967
971
|
|
|
968
972
|
### window.maximized
|
|
969
973
|
|
package/package.json
CHANGED
|
@@ -4,6 +4,12 @@
|
|
|
4
4
|
#include "cocoa-window.h"
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
extern "C" NSView *getCocoaWindowHandle(NSWindow *window) {
|
|
8
|
+
@autoreleasepool {
|
|
9
|
+
return [window contentView];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
7
13
|
extern "C" CALayer *getCocoaGlView(NSWindow *window) {
|
|
8
14
|
@autoreleasepool {
|
|
9
15
|
NSView *view = [window contentView];
|
package/src/native/window.cpp
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
#if defined(__LINUX__)
|
|
9
|
+
#define NativeWindowHandle Window
|
|
9
10
|
#define GL_NativeWindow Window
|
|
10
11
|
struct GPU_NativeData {
|
|
11
12
|
Display *display;
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
};
|
|
14
15
|
#define GPU_WINDOW_FLAG SDL_WINDOW_VULKAN
|
|
15
16
|
#elif defined(__WIN32__)
|
|
17
|
+
#define NativeWindowHandle HWND
|
|
16
18
|
#define GL_NativeWindow HWND
|
|
17
19
|
struct GPU_NativeData {
|
|
18
20
|
HWND hwnd;
|
|
@@ -21,6 +23,7 @@
|
|
|
21
23
|
#define GPU_WINDOW_FLAG 0
|
|
22
24
|
#elif defined(__MACOSX__)
|
|
23
25
|
#include "cocoa-window.h"
|
|
26
|
+
#define NativeWindowHandle NSView *
|
|
24
27
|
#define GL_NativeWindow CALayer *
|
|
25
28
|
struct GPU_NativeData {
|
|
26
29
|
CALayer *layer;
|
|
@@ -150,52 +153,61 @@ window::create (const Napi::CallbackInfo &info)
|
|
|
150
153
|
int pixel_width, pixel_height;
|
|
151
154
|
SDL_GetWindowSizeInPixels(window, &pixel_width, &pixel_height);
|
|
152
155
|
|
|
153
|
-
Napi::
|
|
156
|
+
Napi::Object native = Napi::Object::New(env);
|
|
154
157
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
throw Napi::Error::New(env, message.str());
|
|
164
|
-
}
|
|
158
|
+
SDL_SysWMinfo sys_wm_info;
|
|
159
|
+
SDL_VERSION(&(sys_wm_info.version));
|
|
160
|
+
if (SDL_GetWindowWMInfo(window, &sys_wm_info) == SDL_FALSE) {
|
|
161
|
+
std::ostringstream message;
|
|
162
|
+
message << "SDL_GetWindowWMInfo(" << window_id << ") error: " << SDL_GetError();
|
|
163
|
+
SDL_ClearError();
|
|
164
|
+
throw Napi::Error::New(env, message.str());
|
|
165
|
+
}
|
|
165
166
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
167
|
+
int native_handle_size = sizeof(NativeWindowHandle);
|
|
168
|
+
Napi::Buffer<char> native_handle_buffer = Napi::Buffer<char>::New(env, native_handle_size);
|
|
169
|
+
NativeWindowHandle *native_handle = (NativeWindowHandle *) native_handle_buffer.Data();
|
|
170
|
+
native.Set("handle", native_handle_buffer);
|
|
171
|
+
|
|
172
|
+
#if defined(__LINUX__)
|
|
173
|
+
*native_handle = sys_wm_info.info.x11.window;
|
|
174
|
+
#elif defined(__WIN32__)
|
|
175
|
+
*native_handle = sys_wm_info.info.win.window;
|
|
176
|
+
#elif defined(__MACOSX__)
|
|
177
|
+
*native_handle = getCocoaWindowHandle(sys_wm_info.info.cocoa.window);
|
|
178
|
+
#endif
|
|
179
|
+
|
|
180
|
+
if (is_opengl) {
|
|
181
|
+
int native_gl_size = sizeof(GL_NativeWindow);
|
|
182
|
+
Napi::Buffer<char> native_gl_buffer = Napi::Buffer<char>::New(env, native_gl_size);
|
|
183
|
+
GL_NativeWindow *native_gl = (GL_NativeWindow *) native_gl_buffer.Data();
|
|
184
|
+
native.Set("gl", native_gl_buffer);
|
|
185
|
+
|
|
186
|
+
#if defined(__LINUX__)
|
|
187
|
+
*native_gl = sys_wm_info.info.x11.window;
|
|
188
|
+
#elif defined(__WIN32__)
|
|
189
|
+
*native_gl = sys_wm_info.info.win.window;
|
|
190
|
+
#elif defined(__MACOSX__)
|
|
191
|
+
*native_gl = getCocoaGlView(sys_wm_info.info.cocoa.window);
|
|
192
|
+
#endif
|
|
193
|
+
} else if (is_webgpu) {
|
|
194
|
+
int native_gpu_size = sizeof(GPU_NativeData);
|
|
195
|
+
Napi::Buffer<char> native_gpu_buffer = Napi::Buffer<char>::New(env, native_gpu_size);
|
|
196
|
+
GPU_NativeData *native_gpu = (GPU_NativeData *) native_gpu_buffer.Data();
|
|
197
|
+
native.Set("gpu", native_gpu_buffer);
|
|
198
|
+
|
|
199
|
+
#if defined(__LINUX__)
|
|
200
|
+
native_gpu->display = sys_wm_info.info.x11.display;
|
|
201
|
+
native_gpu->window = sys_wm_info.info.x11.window;
|
|
202
|
+
#elif defined(__WIN32__)
|
|
203
|
+
native_gpu->hwnd = sys_wm_info.info.win.window;
|
|
204
|
+
native_gpu->hinstance = sys_wm_info.info.win.hinstance;
|
|
205
|
+
#elif defined(__MACOSX__)
|
|
206
|
+
native_gpu->layer = getCocoaGpuView(sys_wm_info.info.cocoa.window);
|
|
207
|
+
#endif
|
|
195
208
|
}
|
|
196
209
|
else {
|
|
197
210
|
updateRenderer(env, window, &is_accelerated, &is_vsync);
|
|
198
|
-
native = env.Null();
|
|
199
211
|
}
|
|
200
212
|
|
|
201
213
|
if (is_visible) { SDL_ShowWindow(window); }
|