@kmamal/sdl 0.10.13 → 0.11.0
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 +9 -4
- package/package.json +5 -5
- 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/scripts/clean.mjs +0 -17
package/README.md
CHANGED
|
@@ -195,7 +195,8 @@ Check the [`examples/`](https://github.com/kmamal/node-sdl/tree/master/examples#
|
|
|
195
195
|
* [window.webgpu](#windowwebgpu)
|
|
196
196
|
* [window.native](#windownative)
|
|
197
197
|
* [window.maximized](#windowmaximized)
|
|
198
|
-
* [window.
|
|
198
|
+
* [window.object()](#windowmaximize)
|
|
199
|
+
* `handle : <Buffer>`
|
|
199
200
|
* [window.minimized](#windowminimized)
|
|
200
201
|
* [window.minimize()](#windowminimize)
|
|
201
202
|
* [window.restore()](#windowrestore)
|
|
@@ -960,10 +961,14 @@ Calls to [`render()`](#windowrenderwidth-height-stride-format-buffer-options) wi
|
|
|
960
961
|
|
|
961
962
|
### window.native
|
|
962
963
|
|
|
963
|
-
* `<
|
|
964
|
+
* `<object>`
|
|
965
|
+
* `handle : <Buffer>` The platform-specific handle of the window.
|
|
966
|
+
|
|
967
|
+
The native type of `handle` is HWND on Windows, NSView* on macOS, and Window (unsigned long) on Linux.
|
|
968
|
+
It should work exactly like the [`win.getNativeWindowHandle()`](https://www.electronjs.org/docs/latest/api/browser-window#wingetnativewindowhandle) electron method.
|
|
964
969
|
|
|
965
|
-
|
|
966
|
-
|
|
970
|
+
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).
|
|
971
|
+
Please ignore these.
|
|
967
972
|
|
|
968
973
|
### window.maximized
|
|
969
974
|
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.11.0",
|
|
3
3
|
"name": "@kmamal/sdl",
|
|
4
4
|
"description": "SDL bindings for Node.js",
|
|
5
5
|
"keywords": [
|
|
@@ -60,6 +60,8 @@
|
|
|
60
60
|
"clean": "cd scripts && node clean.mjs"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
+
"node-addon-api": "^8.3.1",
|
|
64
|
+
"node-gyp": "^11.1.0",
|
|
63
65
|
"tar": "^7.4.3"
|
|
64
66
|
},
|
|
65
67
|
"sdl": {
|
|
@@ -68,10 +70,8 @@
|
|
|
68
70
|
"version": "2.26.4"
|
|
69
71
|
},
|
|
70
72
|
"devDependencies": {
|
|
71
|
-
"@kmamal/evdev": "^0.0.
|
|
73
|
+
"@kmamal/evdev": "^0.0.2",
|
|
72
74
|
"@kmamal/testing": "^0.0.31",
|
|
73
|
-
"@types/node": "^22.
|
|
74
|
-
"node-addon-api": "^8.3.0",
|
|
75
|
-
"node-gyp": "^11.0.0"
|
|
75
|
+
"@types/node": "^22.13.5"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -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); }
|
package/src/types/index.d.ts
CHANGED
package/scripts/clean.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import Fs from 'node:fs'
|
|
2
|
-
import Path from 'node:path'
|
|
3
|
-
import C from './util/common.js'
|
|
4
|
-
|
|
5
|
-
const dirs = [
|
|
6
|
-
Path.join(C.dir.root, 'node_modules'),
|
|
7
|
-
C.dir.sdl,
|
|
8
|
-
C.dir.build,
|
|
9
|
-
C.dir.dist,
|
|
10
|
-
C.dir.publish,
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
console.log("delete")
|
|
14
|
-
await Promise.all(dirs.map(async (dir) => {
|
|
15
|
-
console.log(" ", dir)
|
|
16
|
-
await Fs.promises.rm(dir, { recursive: true }).catch(() => {})
|
|
17
|
-
}))
|