@kmamal/sdl 1.0.0-8 → 1.0.0-9

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +2 -2
  3. package/binding.gyp +18 -4
  4. package/package.json +1 -1
  5. package/scripts/build.mjs +3 -1
  6. package/scripts/install.mjs +2 -0
  7. package/scripts/util/common.js +1 -0
  8. package/src/javascript/audio/audio-stream.js +4 -3
  9. package/src/javascript/audio/prevent-exit.js +1 -1
  10. package/src/javascript/events/events-via-poll.js +2 -4
  11. package/src/javascript/events/index.js +14 -1
  12. package/src/javascript/events/try.js +3 -0
  13. package/src/javascript/joystick/joystick-device-instance.js +1 -0
  14. package/src/javascript/validate.js +5 -0
  15. package/src/javascript/video/events.js +3 -3
  16. package/src/javascript/video/window.js +53 -7
  17. package/src/native/audio.cpp +24 -26
  18. package/src/native/audio.h +24 -24
  19. package/src/native/clipboard.h +2 -2
  20. package/src/native/enums.cpp +14 -1
  21. package/src/native/enums.h +1 -1
  22. package/src/native/events.cpp +1 -69
  23. package/src/native/events.h +69 -69
  24. package/src/native/gamepad.cpp +65 -4
  25. package/src/native/gamepad.h +8 -8
  26. package/src/native/global.cpp +11 -273
  27. package/src/native/global.h +9 -9
  28. package/src/native/joystick.cpp +26 -3
  29. package/src/native/joystick.h +13 -13
  30. package/src/native/keyboard.cpp +6 -6
  31. package/src/native/keyboard.h +3 -3
  32. package/src/native/module.cpp +3 -0
  33. package/src/native/mouse.cpp +1 -1
  34. package/src/native/mouse.h +9 -9
  35. package/src/native/packed.cpp +5 -12
  36. package/src/native/packed.h +8 -13
  37. package/src/native/power.cpp +7 -1
  38. package/src/native/power.h +2 -2
  39. package/src/native/sensor.cpp +19 -2
  40. package/src/native/sensor.h +6 -6
  41. package/src/native/testing.cpp +17 -0
  42. package/src/native/testing.h +6 -5
  43. package/src/native/threads.cpp +1 -0
  44. package/src/native/threads.h +13 -13
  45. package/src/native/touch.cpp +7 -2
  46. package/src/native/touch.h +2 -2
  47. package/src/native/video.cpp +68 -5
  48. package/src/native/video.h +5 -5
  49. package/src/native/window.cpp +46 -1
  50. package/src/native/window.h +24 -21
  51. package/src/types/index.d.ts +16 -1
package/CHANGELOG.md CHANGED
@@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
19
19
  - Attaching a listener to a destroyed window or a closed instance or stream now throws, instead of silently never firing.
20
20
  - Audio and video formats are reported using the platform-independent enums. The platform-dependent ones are only used as input.
21
21
  - Character keys are reported as the unshifted character (`'ü'` instead of `'Ü'`), so `getKey(getScancode('ü'))` round-trips.
22
- - Display device events now only include the device object itself. Read the changed props from the object.
22
+ - Display events now report the display as `event.display` instead of `event.device`, and only include the display object itself. Read the changed props from the object.
23
23
  - `sdl.keyboard.getState()` returns a `Uint8Array` of `0`/`1` values instead of an array of booleans.
24
24
  - steamHandle is now reported as a BigInt.
25
25
 
package/README.md CHANGED
@@ -16,11 +16,11 @@ SDL bindings for Node.js. Gives desktop applications access to features that Nod
16
16
  - 🖱 Mouse
17
17
  - 🕹 Joysticks
18
18
  - 🎮 Gamepads
19
+ - 🧭 Sensors
19
20
  - 🔈 Audio playback
20
21
  - 🎤 Audio recording
21
22
  - 📋 Clipboard manipulation
22
23
  - 🔋 Battery status
23
- - 🧭 Sensors
24
24
 
25
25
  In addition, all these things can now be used without a browser:
26
26
 
@@ -28,7 +28,7 @@ In addition, all these things can now be used without a browser:
28
28
  - __WebGL:__ [@kmamal/gl](https://github.com/kmamal/headless-gl#readme). A fork of [headless-gl](https://github.com/stackgl/headless-gl#readme) modified to render directly to SDL windows.
29
29
  - __WebGPU:__ [@kmamal/gpu](https://github.com/kmamal/gpu#readme). A fork of [Google Dawn](https://dawn.googlesource.com/dawn/+/refs/heads/main/src/dawn/node/) modified to render directly to SDL windows.
30
30
  - __Web Audio:__ [@kmamal/audio](https://github.com/kmamal/audio#readme). An implementation of the Web Audio API that uses `@kmamal/sdl` for audio playback and recording.
31
- - __Three.js:__ [@kmamal/three](https://github.com/kmamal/three#readme). A fork of [Three.js](https://threejs.org/) ported to the desktop via tha above libraries.
31
+ - __Three.js:__ [@kmamal/three](https://github.com/kmamal/three.js#readme). A fork of [Three.js](https://threejs.org/) ported to the desktop via the above libraries.
32
32
 
33
33
  This package officially supports Linux (X11 and Wayland), Mac, and Windows.
34
34
  It should work on any system that both SDL and Node.js support, but I haven't tried others.
package/binding.gyp CHANGED
@@ -1,4 +1,7 @@
1
1
  {
2
+ 'variables': {
3
+ 'werror%': 0,
4
+ },
2
5
  'targets': [
3
6
  {
4
7
  'target_name':
@@ -27,13 +30,26 @@
27
30
  "<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
28
31
  ],
29
32
  'defines': [
30
- # Node-API version of the oldest supported Node.js (v22.0.0)
33
+ # Node-API 9, which every supported Node.js (v22.16.0 and later) has
31
34
  'NAPI_VERSION=9',
32
35
  'NODE_ADDON_API_DISABLE_DEPRECATED',
33
36
  'NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS',
34
37
  ],
35
- 'cflags': ['-Werror', '-Wall', '-Wextra'],
38
+ 'cflags': ['-Wall', '-Wextra'],
36
39
  'conditions': [
40
+ [
41
+ 'werror == 1', {
42
+ 'cflags': ['-Werror'],
43
+ 'xcode_settings': {
44
+ 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES',
45
+ },
46
+ 'msvs_settings': {
47
+ 'VCCLCompilerTool': {
48
+ 'WarnAsError': 'true',
49
+ },
50
+ },
51
+ }
52
+ ],
37
53
  [
38
54
  'OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "netbsd"', {
39
55
  'cflags': ['-D_REENTRANT'],
@@ -55,7 +71,6 @@
55
71
  'xcode_settings': {
56
72
  'OTHER_CFLAGS': ['-std=c++17'],
57
73
  'WARNING_CFLAGS': ['-Wall', '-Wextra'],
58
- 'GCC_TREAT_WARNINGS_AS_ERRORS': 'YES',
59
74
  },
60
75
  'include_dirs': [
61
76
  '$(SDL_INC)',
@@ -74,7 +89,6 @@
74
89
  'VCCLCompilerTool': {
75
90
  'AdditionalOptions': ['-std:c++17'],
76
91
  'WarningLevel': '4',
77
- 'WarnAsError': 'true',
78
92
  'DisableSpecificWarnings': ['4127'],
79
93
  },
80
94
  },
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.0-8",
2
+ "version": "1.0.0-9",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
package/scripts/build.mjs CHANGED
@@ -23,13 +23,15 @@ if (C.systemSdl) {
23
23
 
24
24
  console.log("build in", C.dir.build)
25
25
 
26
+ const werror = C.isSet(process.env.NODE_SDL_WERROR ?? '1') ? 1 : 0
27
+
26
28
  let archFlag = ''
27
29
  if (process.env.CROSS_COMPILE_ARCH) {
28
30
  archFlag = `--arch ${process.env.CROSS_COMPILE_ARCH}`
29
31
  }
30
32
 
31
33
  process.chdir(C.dir.root)
32
- execSync(`npx -y node-gyp rebuild ${archFlag} -j max --verbose`, {
34
+ execSync(`npx -y node-gyp rebuild ${archFlag} -j max --verbose -- -Dwerror=${werror}`, {
33
35
  stdio: 'inherit',
34
36
  env: {
35
37
  ...process.env,
@@ -1,6 +1,8 @@
1
1
 
2
2
  import C from './util/common.js'
3
3
 
4
+ process.env.NODE_SDL_WERROR ??= '0'
5
+
4
6
  if (C.systemSdl) {
5
7
  console.log("build against the system sdl")
6
8
  await import('./build.mjs')
@@ -27,6 +27,7 @@ sdl.assetName = `SDL-v${sdl.version}-${platform}-${targetArch}.tar.gz`
27
27
 
28
28
  module.exports = {
29
29
  dir,
30
+ isSet,
30
31
  fromSource,
31
32
  systemSdl,
32
33
  version,
@@ -49,13 +49,14 @@ class AudioStream extends EventsViaPoll {
49
49
  Globals.events.withoutPolling(() => { tryEmit(this, notifyEvent, event) })
50
50
  }
51
51
 
52
- const id = Bindings.audio_open(device.id, recording, frequency, _format, channels, buffered, notify, device)
52
+ const { id, format: deviceFormat } = Bindings.audio_open(device.id, recording, frequency, _format, channels, buffered, notify)
53
+ Object.assign(device, deviceFormat)
53
54
  try {
54
55
  if (gain !== 1) { Bindings.audio_setGain(id, gain) }
55
56
  if (frequencyRatio !== 1) { Bindings.audio_setFrequencyRatio(id, frequencyRatio) }
56
57
  }
57
58
  catch (error) {
58
- try { Bindings.audio_close(id, device) }
59
+ try { Object.assign(device, Bindings.audio_close(id)) }
59
60
  catch { }
60
61
  throw error
61
62
  }
@@ -169,7 +170,7 @@ class AudioStream extends EventsViaPoll {
169
170
  Globals.audioStreams.delete(this._id)
170
171
 
171
172
  // This call could throw if the device is gone
172
- try { Bindings.audio_close(this._id, this._device) }
173
+ try { Object.assign(this._device, Bindings.audio_close(this._id)) }
173
174
  catch { }
174
175
 
175
176
  // We might be inside an event listener
@@ -38,7 +38,7 @@ process.on('beforeExit', (code) => {
38
38
  }
39
39
 
40
40
  if (duration) {
41
- // Keeps Node.js alive while audio is playing
41
+ // Keeps Node.js alive while audio is playing; don't unref it
42
42
  resetTimeout()
43
43
  timeout = setTimeout(() => { timeout = null }, Math.min(duration * 1e3, INT32_MAX))
44
44
  }
@@ -1,8 +1,6 @@
1
1
  const Globals = require('../globals')
2
2
  const { EventEmitter } = require('node:events')
3
3
 
4
- let numListeners = 0
5
-
6
4
  const commonEvents = [ 'newListener', 'removeListener', 'error', '*' ]
7
5
  const metaEvents = [ 'newListener', 'removeListener' ]
8
6
  const undemandingEvents = [ ...metaEvents, 'error' ]
@@ -18,7 +16,7 @@ class EventsViaPoll extends EventEmitter {
18
16
  this._addInternalListener('removeListener', (type) => {
19
17
  if (undemandingEvents.includes(type)) { return }
20
18
 
21
- if (--numListeners === 0) { Globals.events.setDemand(false) }
19
+ Globals.events.unref()
22
20
  })
23
21
 
24
22
  this._addInternalListener('newListener', (type) => {
@@ -32,7 +30,7 @@ class EventsViaPoll extends EventEmitter {
32
30
 
33
31
  if (assertReady) { assertReady() }
34
32
 
35
- if (++numListeners === 1) { Globals.events.setDemand(true) }
33
+ Globals.events.ref()
36
34
  })
37
35
  }
38
36
 
@@ -70,6 +70,8 @@ let polling = false
70
70
  let pollInterval = null
71
71
  let pollingFast = null
72
72
 
73
+ // I would like to move this to native code eventually.
74
+ // Sadly a native uv_timer poll loop would needs direct libuv calls, making the binary non-portable across Node.js versions.
73
75
  const setPollingFast = (fast) => {
74
76
  if (!isMainThread || fast === pollingFast) { return }
75
77
  pollingFast = fast
@@ -96,6 +98,16 @@ const withoutPolling = (fn) => {
96
98
 
97
99
  const setDemand = (demand) => { setPollingFast(Bindings.events_setDemand(demand)) }
98
100
 
101
+ let refCount = 0
102
+
103
+ const ref = () => {
104
+ if (++refCount === 1) { setDemand(true) }
105
+ }
106
+
107
+ const unref = () => {
108
+ if (--refCount === 0) { setDemand(false) }
109
+ }
110
+
99
111
  const stopPolling = () => {
100
112
  Timers.clearInterval(pollInterval)
101
113
  pollInterval = null
@@ -106,7 +118,8 @@ const broadcastChange = (name) => { Bindings.events_broadcastChange(name) }
106
118
  Globals.events = {
107
119
  poll,
108
120
  withoutPolling,
109
- setDemand,
121
+ ref,
122
+ unref,
110
123
  stopPolling,
111
124
  broadcastChange,
112
125
  }
@@ -1,3 +1,6 @@
1
+ // Only for code that runs inside a NAPI callback.
2
+ // This is to prevent the exception from bubbling up through C++ code.
3
+ // Everywhere else, emit synchronously with `try { this.emit(...) } catch (error) { this.emit('error', error) }`
1
4
  const rethrow = (error) => {
2
5
  process.nextTick(() => { throw error })
3
6
  }
@@ -47,6 +47,7 @@ const startEffect = (effect, id, _a, _b, duration) => {
47
47
  effect.call(id, a, b, duration === null ? MAX_DURATION : Math.min(duration, MAX_DURATION))
48
48
 
49
49
  // Keeps Node.js alive while rumbling
50
+ // Not unref'd on purpose, so that the process stays alive until the effect finishes
50
51
  const timers = []
51
52
  if (duration === null || duration > MAX_DURATION) {
52
53
  timers.push(setInterval(() => {
@@ -18,6 +18,10 @@ const validateObject = (name, value) => {
18
18
  if (typeof value !== 'object' || value === null) { fail(`${name} must be an object`, name, value) }
19
19
  }
20
20
 
21
+ const validateFunction = (name, value) => {
22
+ if (typeof value !== 'function') { fail(`${name} must be a function`, name, value) }
23
+ }
24
+
21
25
  const validateBuffer = (name, value) => {
22
26
  if (!(value instanceof Buffer)) { fail(`${name} must be a Buffer`, name, value) }
23
27
  }
@@ -95,6 +99,7 @@ module.exports = {
95
99
  validateBoolean,
96
100
  validateString,
97
101
  validateObject,
102
+ validateFunction,
98
103
  validateBuffer,
99
104
  validateNumber,
100
105
  validateNonNegativeNumber,
@@ -15,7 +15,7 @@ const handleDisplayEvent = (event) => {
15
15
 
16
16
  if (Globals.displays.some((a) => a.id === display.id)) { return }
17
17
  Globals.displays.push(display)
18
- event.device = display
18
+ event.display = display
19
19
  } break
20
20
 
21
21
  case 'displayRemove': {
@@ -24,7 +24,7 @@ const handleDisplayEvent = (event) => {
24
24
 
25
25
  const index = Globals.displays.findIndex((a) => a.id === displayId)
26
26
  if (index === -1) { return }
27
- event.device = Globals.displays[index]
27
+ event.display = Globals.displays[index]
28
28
  Globals.displays.splice(index, 1)
29
29
  } break
30
30
 
@@ -41,7 +41,7 @@ const handleDisplayEvent = (event) => {
41
41
  if (!display) { return }
42
42
 
43
43
  Object.assign(display, fresh)
44
- event.device = display
44
+ event.display = display
45
45
  } break
46
46
 
47
47
  // No default
@@ -2,10 +2,12 @@ const Globals = require('../globals')
2
2
  const Bindings = require('../bindings')
3
3
  const Enums = require('../enums')
4
4
  const { EventsViaPoll } = require('../events/events-via-poll')
5
+ const { tryEmit } = require('../events/try')
5
6
  const {
6
7
  validateBoolean,
7
8
  validateString,
8
9
  validateObject,
10
+ validateFunction,
9
11
  validateInt32,
10
12
  validateFloat,
11
13
  validatePositiveFloat,
@@ -54,6 +56,29 @@ const validEvents = [
54
56
  'dropComplete',
55
57
  ]
56
58
 
59
+ const handleHitTest = (windowId, x, y) => {
60
+ const window = Globals.windows.all.get(windowId)
61
+ if (!window?._hitTest) { return Enums.hitTestResult.normal }
62
+
63
+ let value
64
+ hitTestDepth++
65
+ try {
66
+ Globals.events.withoutPolling(() => {
67
+ try {
68
+ const result = window._hitTest(x, y)
69
+ value = result === undefined ? Enums.hitTestResult.normal : Enums.hitTestResult[result]
70
+ if (value === undefined) { throw Object.assign(new Error("invalid hit test result"), { result }) }
71
+ }
72
+ catch (error) { tryEmit(window, 'error', error) }
73
+ })
74
+ }
75
+ finally { hitTestDepth-- }
76
+ return value ?? Enums.hitTestResult.normal
77
+ }
78
+
79
+ let hitTestDepth = 0
80
+ let hitTestHandlerRegistered = false
81
+
57
82
  class Window extends EventsViaPoll {
58
83
  constructor (options = {}) {
59
84
  super(validEvents)
@@ -150,16 +175,13 @@ class Window extends EventsViaPoll {
150
175
  this._minimized = result.minimized
151
176
  this._maximized = result.maximized
152
177
  this._relativeMouseMode = false
178
+ this._hitTest = null
153
179
  this._destroyed = false
154
180
 
155
181
  Globals.windows.all.set(this._id, this)
156
182
 
157
- // Keeps Node.js alive while windows are open
158
- const keepAlive = () => {}
159
- this.on('close', keepAlive)
160
- this._addInternalListener('removeListener', (type, listener) => {
161
- if (listener === keepAlive && !this._destroyed) { this.on('close', keepAlive) }
162
- })
183
+ // Keep Node.js alive while windows are open
184
+ Globals.events.ref()
163
185
 
164
186
  // Manually emit some initial events for convenience.
165
187
  // Note that these can duplicate real events.
@@ -491,6 +513,29 @@ class Window extends EventsViaPoll {
491
513
 
492
514
  unsetRelativeMouseMode () { this.setRelativeMouseMode(false) }
493
515
 
516
+ setHitTest (hitTest) {
517
+ validateNotDestroyed(this)
518
+
519
+ if (hitTest !== null) { validateFunction('hitTest', hitTest) }
520
+
521
+ if (!hitTestHandlerRegistered) {
522
+ Bindings.window_registerHitTestHandler(handleHitTest)
523
+ hitTestHandlerRegistered = true
524
+ }
525
+
526
+ const previous = this._hitTest
527
+ this._hitTest = hitTest
528
+ if ((hitTest !== null) !== (previous !== null)) {
529
+ try { Bindings.window_setHitTest(this._id, hitTest !== null) }
530
+ catch (error) {
531
+ this._hitTest = previous
532
+ throw error
533
+ }
534
+ }
535
+ }
536
+
537
+ unsetHitTest () { this.setHitTest(null) }
538
+
494
539
  render (width, height, stride, format, buffer, options = {}) {
495
540
  validateNotDestroyed(this)
496
541
 
@@ -552,6 +597,7 @@ class Window extends EventsViaPoll {
552
597
  validateNotDestroyed(this)
553
598
 
554
599
  this._destroyed = true
600
+ Globals.events.unref()
555
601
  Globals.windows.all.delete(this._id)
556
602
  if (Globals.windows.hovered === this) { Globals.windows.hovered = null }
557
603
  if (Globals.windows.focused === this) { Globals.windows.focused = null }
@@ -562,7 +608,7 @@ class Window extends EventsViaPoll {
562
608
  }
563
609
 
564
610
  // Defer the native destruction until the pump has unwound.
565
- if (Bindings.events_isDispatchingFromWatch()) {
611
+ if (hitTestDepth > 0 || Bindings.events_isDispatchingFromWatch()) {
566
612
  process.nextTick(destroyNative)
567
613
  }
568
614
  else {
@@ -6,8 +6,21 @@
6
6
  #include <atomic>
7
7
  #include <cstdint>
8
8
 
9
- std::map<bool, packed::Str> audio::device_types;
10
- std::map<SDL_AudioFormat, packed::Str> audio::formats;
9
+ const std::map<bool, packed::Str> audio::device_types {
10
+ { true, "recording" },
11
+ { false, "playback" },
12
+ };
13
+
14
+ const std::map<SDL_AudioFormat, packed::Str> audio::formats {
15
+ { SDL_AUDIO_S8, "s8" },
16
+ { SDL_AUDIO_U8, "u8" },
17
+ { SDL_AUDIO_S16LE, "s16le" },
18
+ { SDL_AUDIO_S16BE, "s16be" },
19
+ { SDL_AUDIO_S32LE, "s32le" },
20
+ { SDL_AUDIO_S32BE, "s32be" },
21
+ { SDL_AUDIO_F32LE, "f32le" },
22
+ { SDL_AUDIO_F32BE, "f32be" },
23
+ };
11
24
 
12
25
  struct StreamState;
13
26
 
@@ -179,18 +192,6 @@ _setFormat (packed::Value &target, SDL_AudioDeviceID id)
179
192
  target.set("buffered", sample_frames);
180
193
  }
181
194
 
182
- static void
183
- _setFormat (Napi::Object &target, SDL_AudioDeviceID id)
184
- {
185
- packed::Value format = packed::Value::object();
186
- _setFormat(format, id);
187
-
188
- Napi::Env env = target.Env();
189
- for (const packed::Member &member : format.members()) {
190
- target.Set(member.key, member.value.toNapi(env));
191
- }
192
- }
193
-
194
195
  static SDL_AudioDeviceID
195
196
  _defaultId (bool is_recording)
196
197
  {
@@ -215,7 +216,7 @@ audio::_getDevice (SDL_AudioDeviceID id)
215
216
  }
216
217
 
217
218
  packed::Value
218
- audio::_getFormat(SDL_AudioDeviceID id)
219
+ audio::_getFormat (SDL_AudioDeviceID id)
219
220
  {
220
221
  packed::Value result = packed::Value::object();
221
222
  _setFormat(result, id);
@@ -223,7 +224,7 @@ audio::_getFormat(SDL_AudioDeviceID id)
223
224
  }
224
225
 
225
226
  packed::Value
226
- audio::_getDefaultDevice(bool is_recording)
227
+ audio::_getDefaultDevice (bool is_recording)
227
228
  {
228
229
  packed::Value device = packed::Value::object();
229
230
  device.set("id", packed::Value());
@@ -257,7 +258,7 @@ _getDevices (Napi::Env &env, bool is_recording)
257
258
  }
258
259
 
259
260
  Napi::Value
260
- audio::getDrivers(const Napi::CallbackInfo &info)
261
+ audio::getDrivers (const Napi::CallbackInfo &info)
261
262
  {
262
263
  Napi::Env env = info.Env();
263
264
 
@@ -280,7 +281,7 @@ audio::getDrivers(const Napi::CallbackInfo &info)
280
281
  }
281
282
 
282
283
  Napi::Value
283
- audio::getDevices(const Napi::CallbackInfo &info)
284
+ audio::getDevices (const Napi::CallbackInfo &info)
284
285
  {
285
286
  Napi::Env env = info.Env();
286
287
 
@@ -307,7 +308,6 @@ audio::open (const Napi::CallbackInfo &info)
307
308
  int channels = info[4].As<Napi::Number>().Int32Value();
308
309
  int samples = info[5].As<Napi::Number>().Int32Value();
309
310
  Napi::Function callback = info[6].As<Napi::Function>();
310
- Napi::Object device = info[7].As<Napi::Object>();
311
311
 
312
312
  SDL_AudioDeviceID device_id = has_id
313
313
  ? info[0].As<Napi::Number>().Uint32Value()
@@ -368,15 +368,16 @@ audio::open (const Napi::CallbackInfo &info)
368
368
  }
369
369
 
370
370
  try {
371
- _setFormat(device, audio_id);
371
+ packed::Value result = packed::Value::object();
372
+ result.set("id", audio_id);
373
+ result.set("format", audio::_getFormat(audio_id));
374
+ return result.toNapi(env);
372
375
  }
373
376
  catch (...) {
374
377
  _destroy(audio_id, entry, true);
375
378
  open_streams.erase(audio_id);
376
379
  throw;
377
380
  }
378
-
379
- return Napi::Number::New(env, audio_id);
380
381
  }
381
382
 
382
383
  Napi::Value
@@ -520,16 +521,13 @@ audio::close (const Napi::CallbackInfo &info)
520
521
  global::assertReady(env);
521
522
 
522
523
  SDL_AudioDeviceID audio_id = info[0].As<Napi::Number>().Uint32Value();
523
- Napi::Object device = info[1].As<Napi::Object>();
524
524
 
525
525
  OpenStream &entry = _getEntry(env, audio_id);
526
526
  SDL_AudioDeviceID device_id = entry.device_id;
527
527
  _destroy(audio_id, entry, entry.env == (napi_env) env);
528
528
  open_streams.erase(audio_id);
529
529
 
530
- _setFormat(device, device_id);
531
-
532
- return env.Undefined();
530
+ return audio::_getFormat(device_id).toNapi(env);
533
531
  }
534
532
 
535
533
  Napi::Value
@@ -9,30 +9,30 @@
9
9
 
10
10
  namespace audio {
11
11
 
12
- extern std::map<bool, packed::Str> device_types;
13
- extern std::map<SDL_AudioFormat, packed::Str> formats;
14
-
15
- void closeAllStreams();
16
-
17
- packed::Value _getDevice(SDL_AudioDeviceID id);
18
- packed::Value _getFormat(SDL_AudioDeviceID id);
19
- packed::Value _getDefaultDevice(bool is_recording);
20
-
21
- Napi::Value getDrivers(const Napi::CallbackInfo &info);
22
- Napi::Value getDevices(const Napi::CallbackInfo &info);
23
- Napi::Value open(const Napi::CallbackInfo &info);
24
- Napi::Value play(const Napi::CallbackInfo &info);
25
- Napi::Value getQueued(const Napi::CallbackInfo &info);
26
- Napi::Value flush(const Napi::CallbackInfo &info);
27
- Napi::Value getAvailable(const Napi::CallbackInfo &info);
28
- Napi::Value putData(const Napi::CallbackInfo &info);
29
- Napi::Value getData(const Napi::CallbackInfo &info);
30
- Napi::Value clear(const Napi::CallbackInfo &info);
31
- Napi::Value close(const Napi::CallbackInfo &info);
32
- Napi::Value setNotify(const Napi::CallbackInfo &info);
33
- Napi::Value setGain(const Napi::CallbackInfo &info);
34
- Napi::Value setFrequencyRatio(const Napi::CallbackInfo &info);
35
- Napi::Value convert(const Napi::CallbackInfo &info);
12
+ extern const std::map<bool, packed::Str> device_types;
13
+ extern const std::map<SDL_AudioFormat, packed::Str> formats;
14
+
15
+ void closeAllStreams ();
16
+
17
+ packed::Value _getDevice (SDL_AudioDeviceID id);
18
+ packed::Value _getFormat (SDL_AudioDeviceID id);
19
+ packed::Value _getDefaultDevice (bool is_recording);
20
+
21
+ Napi::Value getDrivers (const Napi::CallbackInfo &info);
22
+ Napi::Value getDevices (const Napi::CallbackInfo &info);
23
+ Napi::Value open (const Napi::CallbackInfo &info);
24
+ Napi::Value play (const Napi::CallbackInfo &info);
25
+ Napi::Value getQueued (const Napi::CallbackInfo &info);
26
+ Napi::Value flush (const Napi::CallbackInfo &info);
27
+ Napi::Value getAvailable (const Napi::CallbackInfo &info);
28
+ Napi::Value putData (const Napi::CallbackInfo &info);
29
+ Napi::Value getData (const Napi::CallbackInfo &info);
30
+ Napi::Value clear (const Napi::CallbackInfo &info);
31
+ Napi::Value close (const Napi::CallbackInfo &info);
32
+ Napi::Value setNotify (const Napi::CallbackInfo &info);
33
+ Napi::Value setGain (const Napi::CallbackInfo &info);
34
+ Napi::Value setFrequencyRatio (const Napi::CallbackInfo &info);
35
+ Napi::Value convert (const Napi::CallbackInfo &info);
36
36
 
37
37
  }; // namespace audio
38
38
 
@@ -5,8 +5,8 @@
5
5
 
6
6
  namespace clipboard {
7
7
 
8
- Napi::Value getText(const Napi::CallbackInfo &info);
9
- Napi::Value setText(const Napi::CallbackInfo &info);
8
+ Napi::Value getText (const Napi::CallbackInfo &info);
9
+ Napi::Value setText (const Napi::CallbackInfo &info);
10
10
 
11
11
  }; // namespace clipboard
12
12
 
@@ -2,7 +2,7 @@
2
2
  #include <SDL3/SDL.h>
3
3
 
4
4
  Napi::Value
5
- enums::get(const Napi::CallbackInfo &info)
5
+ enums::get (const Napi::CallbackInfo &info)
6
6
  {
7
7
  Napi::Env env = info.Env();
8
8
 
@@ -368,6 +368,18 @@ enums::get(const Napi::CallbackInfo &info)
368
368
  cursors.Set("swResize", (int) SDL_SYSTEM_CURSOR_SW_RESIZE);
369
369
  cursors.Set("wResize", (int) SDL_SYSTEM_CURSOR_W_RESIZE);
370
370
 
371
+ Napi::Object hit_test_results = Napi::Object::New(env);
372
+ hit_test_results.Set("normal", (int) SDL_HITTEST_NORMAL);
373
+ hit_test_results.Set("draggable", (int) SDL_HITTEST_DRAGGABLE);
374
+ hit_test_results.Set("resizeTopLeft", (int) SDL_HITTEST_RESIZE_TOPLEFT);
375
+ hit_test_results.Set("resizeTop", (int) SDL_HITTEST_RESIZE_TOP);
376
+ hit_test_results.Set("resizeTopRight", (int) SDL_HITTEST_RESIZE_TOPRIGHT);
377
+ hit_test_results.Set("resizeRight", (int) SDL_HITTEST_RESIZE_RIGHT);
378
+ hit_test_results.Set("resizeBottomRight", (int) SDL_HITTEST_RESIZE_BOTTOMRIGHT);
379
+ hit_test_results.Set("resizeBottom", (int) SDL_HITTEST_RESIZE_BOTTOM);
380
+ hit_test_results.Set("resizeBottomLeft", (int) SDL_HITTEST_RESIZE_BOTTOMLEFT);
381
+ hit_test_results.Set("resizeLeft", (int) SDL_HITTEST_RESIZE_LEFT);
382
+
371
383
  Napi::Object all = Napi::Object::New(env);
372
384
  all.Set("pixelFormat", pixel_formats);
373
385
  all.Set("scaleMode", scale_mode);
@@ -375,6 +387,7 @@ enums::get(const Napi::CallbackInfo &info)
375
387
  all.Set("scancodes", scancodes);
376
388
  all.Set("mouseButtons", mouse_buttons);
377
389
  all.Set("cursors", cursors);
390
+ all.Set("hitTestResult", hit_test_results);
378
391
 
379
392
  return all;
380
393
  }
@@ -5,7 +5,7 @@
5
5
 
6
6
  namespace enums {
7
7
 
8
- Napi::Value get(const Napi::CallbackInfo &info);
8
+ Napi::Value get (const Napi::CallbackInfo &info);
9
9
 
10
10
  }; // namespace enums
11
11