@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 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.maximize()](#windowmaximize)
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
- * `<any>`
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
- Holds a copy of the native (platform-specific) representation of the window.
966
- Only used for passing to [@kmamal/gl](https://github.com/kmamal/headless-gl#readme) or [@kmamal/gpu](https://github.com/kmamal/gpu#readme).
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.10.13",
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.1",
73
+ "@kmamal/evdev": "^0.0.2",
72
74
  "@kmamal/testing": "^0.0.31",
73
- "@types/node": "^22.10.7",
74
- "node-addon-api": "^8.3.0",
75
- "node-gyp": "^11.0.0"
75
+ "@types/node": "^22.13.5"
76
76
  }
77
77
  }
@@ -3,10 +3,13 @@
3
3
 
4
4
 
5
5
  #ifndef __OBJC__
6
+ class NSView;
6
7
  class CALayer;
7
8
  #endif
8
9
 
9
10
 
11
+ extern "C" NSView *getCocoaWindowHandle(NSWindow *);
12
+
10
13
  extern "C" CALayer *getCocoaGlView(NSWindow *);
11
14
 
12
15
  extern "C" CALayer *getCocoaGpuView(NSWindow *);
@@ -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];
@@ -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::Value native;
156
+ Napi::Object native = Napi::Object::New(env);
154
157
 
155
- if (is_opengl || is_webgpu) {
156
- SDL_SysWMinfo info;
157
- SDL_VERSION(&(info.version));
158
- bool got_info = SDL_GetWindowWMInfo(window, &info);
159
- if (got_info == SDL_FALSE) {
160
- std::ostringstream message;
161
- message << "SDL_GetWindowWMInfo(" << window_id << ") error: " << SDL_GetError();
162
- SDL_ClearError();
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
- if (is_opengl) {
167
- int native_size = sizeof(GL_NativeWindow);
168
- Napi::Buffer<char> native_buffer = Napi::Buffer<char>::New(env, native_size);
169
- GL_NativeWindow *native_window = (GL_NativeWindow *) native_buffer.Data();
170
- native = native_buffer;
171
-
172
- #if defined(__LINUX__)
173
- *native_window = info.info.x11.window;
174
- #elif defined(__WIN32__)
175
- *native_window = info.info.win.window;
176
- #elif defined(__MACOSX__)
177
- *native_window = getCocoaGlView(info.info.cocoa.window);
178
- #endif
179
- } else if (is_webgpu) {
180
- int native_size = sizeof(GPU_NativeData);
181
- Napi::Buffer<char> native_buffer = Napi::Buffer<char>::New(env, native_size);
182
- GPU_NativeData *native_data = (GPU_NativeData *) native_buffer.Data();
183
- native = native_buffer;
184
-
185
- #if defined(__LINUX__)
186
- native_data->display = info.info.x11.display;
187
- native_data->window = info.info.x11.window;
188
- #elif defined(__WIN32__)
189
- native_data->hwnd = info.info.win.window;
190
- native_data->hinstance = info.info.win.hinstance;
191
- #elif defined(__MACOSX__)
192
- native_data->layer = getCocoaGpuView(info.info.cocoa.window);
193
- #endif
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); }
@@ -447,7 +447,7 @@ export namespace Sdl {
447
447
 
448
448
  readonly opengl: boolean
449
449
  readonly webgpu: boolean
450
- readonly native: unknown
450
+ readonly native: { handle: Buffer }
451
451
 
452
452
  readonly maximized: boolean
453
453
  maximize (): void
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
- }))