@kmamal/sdl 0.11.4 → 0.11.7
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 +70 -16
- package/binding.gyp +1 -0
- package/package.json +1 -1
- package/src/javascript/audio/audio-instance.js +2 -3
- package/src/javascript/audio/device.js +1 -10
- package/src/javascript/audio/index.js +5 -7
- package/src/javascript/controller/controller-instance.js +2 -0
- package/src/javascript/controller/device.js +14 -3
- package/src/javascript/controller/index.js +5 -11
- package/src/javascript/events/index.js +61 -123
- package/src/javascript/events/reconcile-audio-devices.js +15 -0
- package/src/javascript/events/reconcile-displays.js +16 -0
- package/src/javascript/events/reconcile-joystick-and-controller-devices.js +37 -0
- package/src/javascript/events/reconcile.js +61 -0
- package/src/javascript/joystick/device.js +9 -3
- package/src/javascript/joystick/index.js +13 -5
- package/src/javascript/joystick/joystick-instance.js +2 -0
- package/src/javascript/sensor/sensor-instance.js +2 -0
- package/src/javascript/video/display.js +4 -0
- package/src/javascript/video/index.js +1 -0
- package/src/javascript/video/window.js +6 -0
- package/src/native/audio.cpp +10 -12
- package/src/native/audio.h +4 -0
- package/src/native/controller.cpp +72 -56
- package/src/native/controller.h +3 -0
- package/src/native/enums.cpp +315 -315
- package/src/native/events.cpp +161 -79
- package/src/native/events.h +2 -0
- package/src/native/global.cpp +47 -20
- package/src/native/joystick.cpp +87 -48
- package/src/native/joystick.h +3 -2
- package/src/native/keyboard.cpp +1 -1
- package/src/native/mouse.cpp +2 -2
- package/src/native/power.cpp +9 -3
- package/src/native/sensor.cpp +24 -13
- package/src/native/video.cpp +21 -13
- package/src/native/video.h +1 -0
- package/src/native/window.cpp +41 -29
- package/src/types/index.d.ts +65 -17
|
@@ -1,71 +1,11 @@
|
|
|
1
1
|
const Globals = require('../globals')
|
|
2
2
|
const Bindings = require('../bindings')
|
|
3
3
|
const { video: videoModule } = require('../video')
|
|
4
|
+
const { reconcileDisplays } = require('./reconcile-displays')
|
|
4
5
|
const { mapping } = require('../keyboard/key-mapping')
|
|
5
|
-
const {
|
|
6
|
-
const {
|
|
7
|
-
const { audio: audioModule } = require('../audio')
|
|
6
|
+
const { reconcileAudioDevices } = require('./reconcile-audio-devices')
|
|
7
|
+
const { reconcileJoystickAndControllerDevices } = require('./reconcile-joystick-and-controller-devices')
|
|
8
8
|
const { clipboard: clipboardModule } = require('../clipboard')
|
|
9
|
-
const {
|
|
10
|
-
make: makeJoystickDevice,
|
|
11
|
-
compare: compareJoystickDevice,
|
|
12
|
-
} = require('../joystick/device')
|
|
13
|
-
const {
|
|
14
|
-
make: makeControllerDevice,
|
|
15
|
-
compare: compareControllerDevice,
|
|
16
|
-
filter: filterControllerDevice,
|
|
17
|
-
} = require('../controller/device')
|
|
18
|
-
const {
|
|
19
|
-
make: makeAudioDevice,
|
|
20
|
-
compare: compareAudioDevice,
|
|
21
|
-
} = require('../audio/device')
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const reconcileDevices = (emitter, mainList, currList, compare) => {
|
|
25
|
-
currList.sort(compare)
|
|
26
|
-
|
|
27
|
-
let mainIndex = 0
|
|
28
|
-
let currIndex = 0
|
|
29
|
-
let mainDevice = mainList[mainIndex]
|
|
30
|
-
let currDevice = currList[currIndex]
|
|
31
|
-
while (mainIndex < mainList.length && currIndex < currList.length) {
|
|
32
|
-
const cmp = compare(mainDevice, currDevice)
|
|
33
|
-
if (cmp === 0) {
|
|
34
|
-
mainDevice = mainList[++mainIndex]
|
|
35
|
-
currDevice = currList[++currIndex]
|
|
36
|
-
} else if (cmp < 0) {
|
|
37
|
-
mainList.splice(mainIndex, 1)
|
|
38
|
-
const type = 'deviceRemove'
|
|
39
|
-
const event = { type, device: mainDevice }
|
|
40
|
-
emitter.emit(type, event)
|
|
41
|
-
mainDevice = mainList[mainIndex]
|
|
42
|
-
} else {
|
|
43
|
-
mainList.splice(mainIndex, 0, currDevice)
|
|
44
|
-
mainDevice = mainList[++mainIndex]
|
|
45
|
-
const type = 'deviceAdd'
|
|
46
|
-
const event = { type, device: currDevice }
|
|
47
|
-
emitter.emit(type, event)
|
|
48
|
-
currDevice = currList[++currIndex]
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (mainIndex < mainList.length) {
|
|
53
|
-
while (mainIndex < mainList.length) {
|
|
54
|
-
[ mainDevice ] = mainList.splice(mainIndex, 1)
|
|
55
|
-
const type = 'deviceRemove'
|
|
56
|
-
const event = { type, device: mainDevice }
|
|
57
|
-
emitter.emit(type, event)
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
while (currIndex < currList.length) {
|
|
61
|
-
mainList.push(currDevice)
|
|
62
|
-
const type = 'deviceAdd'
|
|
63
|
-
const event = { type, device: currDevice }
|
|
64
|
-
emitter.emit(type, event)
|
|
65
|
-
currDevice = currList[++currIndex]
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
9
|
|
|
70
10
|
|
|
71
11
|
const handleEvent = (event) => {
|
|
@@ -75,7 +15,7 @@ const handleEvent = (event) => {
|
|
|
75
15
|
|
|
76
16
|
switch (family) {
|
|
77
17
|
case 'app': {
|
|
78
|
-
if (
|
|
18
|
+
if (type !== 'quit') { return }
|
|
79
19
|
|
|
80
20
|
for (const window of Globals.windows.all.values()) {
|
|
81
21
|
window.destroyGently()
|
|
@@ -87,15 +27,40 @@ const handleEvent = (event) => {
|
|
|
87
27
|
const { displayIndex } = event
|
|
88
28
|
delete event.displayIndex
|
|
89
29
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
30
|
+
switch (type) {
|
|
31
|
+
case 'displayAdd':
|
|
32
|
+
case 'displayRemove':
|
|
33
|
+
{
|
|
34
|
+
const { displays } = event
|
|
35
|
+
delete event.displays
|
|
36
|
+
|
|
37
|
+
reconcileDisplays(displays)
|
|
38
|
+
return
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
case 'displayOrient': {
|
|
42
|
+
const display = Globals.displays[displayIndex]
|
|
43
|
+
display.orientation = event.orientation
|
|
44
|
+
} break
|
|
45
|
+
|
|
46
|
+
case 'displayMove': {
|
|
47
|
+
const { geometryX, geometryY, usableX, usableY } = event
|
|
48
|
+
delete event.geometryX
|
|
49
|
+
delete event.geometryY
|
|
50
|
+
delete event.usableX
|
|
51
|
+
delete event.usableY
|
|
52
|
+
|
|
53
|
+
const display = Globals.displays[displayIndex]
|
|
54
|
+
display.geometry.x = geometryX
|
|
55
|
+
display.geometry.y = geometryY
|
|
56
|
+
display.usable.x = usableX
|
|
57
|
+
display.usable.y = usableY
|
|
58
|
+
} break
|
|
93
59
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
: newDisplays[displayIndex]
|
|
60
|
+
// No default
|
|
61
|
+
}
|
|
97
62
|
|
|
98
|
-
videoModule.emit(
|
|
63
|
+
videoModule.emit(type, event)
|
|
99
64
|
} break
|
|
100
65
|
|
|
101
66
|
case 'window': {
|
|
@@ -116,6 +81,11 @@ const handleEvent = (event) => {
|
|
|
116
81
|
window._pixelWidth = event.pixelWidth
|
|
117
82
|
window._pixelHeight = event.pixelHeight
|
|
118
83
|
} break
|
|
84
|
+
case 'displayChange': {
|
|
85
|
+
window._displayIndex = event.displayIndex
|
|
86
|
+
delete event.displayIndex
|
|
87
|
+
event.display = window.display
|
|
88
|
+
} break
|
|
119
89
|
|
|
120
90
|
case 'show': {
|
|
121
91
|
window._visible = true
|
|
@@ -168,7 +138,7 @@ const handleEvent = (event) => {
|
|
|
168
138
|
default: return
|
|
169
139
|
}
|
|
170
140
|
|
|
171
|
-
window.emit(
|
|
141
|
+
window.emit(type, event)
|
|
172
142
|
} break
|
|
173
143
|
|
|
174
144
|
case 'keyboard': {
|
|
@@ -181,7 +151,7 @@ const handleEvent = (event) => {
|
|
|
181
151
|
const { key } = event
|
|
182
152
|
event.key = mapping[key] ?? (key?.length === 1 ? key : null)
|
|
183
153
|
|
|
184
|
-
window.emit(
|
|
154
|
+
window.emit(type, event)
|
|
185
155
|
} break
|
|
186
156
|
|
|
187
157
|
case 'mouse':
|
|
@@ -193,7 +163,7 @@ const handleEvent = (event) => {
|
|
|
193
163
|
const window = Globals.windows.all.get(windowId)
|
|
194
164
|
if (!window) { return }
|
|
195
165
|
|
|
196
|
-
window.emit(
|
|
166
|
+
window.emit(type, event)
|
|
197
167
|
} break
|
|
198
168
|
|
|
199
169
|
case 'joystickDevice': {
|
|
@@ -218,33 +188,10 @@ const handleEvent = (event) => {
|
|
|
218
188
|
}
|
|
219
189
|
}
|
|
220
190
|
|
|
221
|
-
const { devices
|
|
191
|
+
const { devices } = event
|
|
222
192
|
delete event.devices
|
|
223
193
|
|
|
224
|
-
|
|
225
|
-
.filter(filterControllerDevice)))
|
|
226
|
-
|
|
227
|
-
for (const joystickDevice of joystickDevices) {
|
|
228
|
-
makeJoystickDevice(joystickDevice)
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
for (const controllerDevice of controllerDevices) {
|
|
232
|
-
makeControllerDevice(controllerDevice)
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
reconcileDevices(
|
|
236
|
-
joystickModule,
|
|
237
|
-
Globals.joystickDevices,
|
|
238
|
-
joystickDevices,
|
|
239
|
-
compareJoystickDevice,
|
|
240
|
-
)
|
|
241
|
-
|
|
242
|
-
reconcileDevices(
|
|
243
|
-
controllerModule,
|
|
244
|
-
Globals.controllerDevices,
|
|
245
|
-
controllerDevices,
|
|
246
|
-
compareControllerDevice,
|
|
247
|
-
)
|
|
194
|
+
reconcileJoystickAndControllerDevices(devices)
|
|
248
195
|
} break
|
|
249
196
|
|
|
250
197
|
case 'joystick': {
|
|
@@ -258,7 +205,7 @@ const handleEvent = (event) => {
|
|
|
258
205
|
case 'axisMotion': {
|
|
259
206
|
for (const joystickInstance of collection) {
|
|
260
207
|
joystickInstance._axes[event.axis] = event.value
|
|
261
|
-
joystickInstance.emit(
|
|
208
|
+
joystickInstance.emit(type, event)
|
|
262
209
|
}
|
|
263
210
|
} break
|
|
264
211
|
|
|
@@ -267,27 +214,27 @@ const handleEvent = (event) => {
|
|
|
267
214
|
const ball = joystickInstance._balls[event.ball]
|
|
268
215
|
ball.x = event.x
|
|
269
216
|
ball.y = event.y
|
|
270
|
-
joystickInstance.emit(
|
|
217
|
+
joystickInstance.emit(type, event)
|
|
271
218
|
}
|
|
272
219
|
} break
|
|
273
220
|
|
|
274
221
|
case 'buttonDown': {
|
|
275
222
|
for (const joystickInstance of collection) {
|
|
276
223
|
joystickInstance._buttons[event.button] = true
|
|
277
|
-
joystickInstance.emit(
|
|
224
|
+
joystickInstance.emit(type, event)
|
|
278
225
|
}
|
|
279
226
|
} break
|
|
280
227
|
case 'buttonUp': {
|
|
281
228
|
for (const joystickInstance of collection) {
|
|
282
229
|
joystickInstance._buttons[event.button] = false
|
|
283
|
-
joystickInstance.emit(
|
|
230
|
+
joystickInstance.emit(type, event)
|
|
284
231
|
}
|
|
285
232
|
} break
|
|
286
233
|
|
|
287
234
|
case 'hatMotion': {
|
|
288
235
|
for (const joystickInstance of collection) {
|
|
289
236
|
joystickInstance._hats[event.hat] = event.value
|
|
290
|
-
joystickInstance.emit(
|
|
237
|
+
joystickInstance.emit(type, event)
|
|
291
238
|
}
|
|
292
239
|
} break
|
|
293
240
|
|
|
@@ -306,21 +253,21 @@ const handleEvent = (event) => {
|
|
|
306
253
|
case 'axisMotion': {
|
|
307
254
|
for (const controllerInstance of collection.values()) {
|
|
308
255
|
controllerInstance._axes[event.axis] = event.value
|
|
309
|
-
controllerInstance.emit(
|
|
256
|
+
controllerInstance.emit(type, event)
|
|
310
257
|
}
|
|
311
258
|
} break
|
|
312
259
|
|
|
313
260
|
case 'buttonDown': {
|
|
314
261
|
for (const controllerInstance of collection.values()) {
|
|
315
262
|
controllerInstance._buttons[event.button] = true
|
|
316
|
-
controllerInstance.emit(
|
|
263
|
+
controllerInstance.emit(type, event)
|
|
317
264
|
}
|
|
318
265
|
} break
|
|
319
266
|
|
|
320
267
|
case 'buttonUp': {
|
|
321
268
|
for (const controllerInstance of collection.values()) {
|
|
322
269
|
controllerInstance._buttons[event.button] = false
|
|
323
|
-
controllerInstance.emit(
|
|
270
|
+
controllerInstance.emit(type, event)
|
|
324
271
|
}
|
|
325
272
|
} break
|
|
326
273
|
|
|
@@ -332,7 +279,7 @@ const handleEvent = (event) => {
|
|
|
332
279
|
for (const controllerInstance of collection.values()) {
|
|
333
280
|
Object.assign(controllerInstance._axes, axes)
|
|
334
281
|
Object.assign(controllerInstance._buttons, buttons)
|
|
335
|
-
controllerInstance.emit(
|
|
282
|
+
controllerInstance.emit(type, event)
|
|
336
283
|
}
|
|
337
284
|
} break
|
|
338
285
|
|
|
@@ -350,7 +297,7 @@ const handleEvent = (event) => {
|
|
|
350
297
|
switch (type) {
|
|
351
298
|
case 'update': {
|
|
352
299
|
for (const sensorInstance of collection.values()) {
|
|
353
|
-
sensorInstance.emit(
|
|
300
|
+
sensorInstance.emit(type, event)
|
|
354
301
|
}
|
|
355
302
|
} break
|
|
356
303
|
|
|
@@ -359,8 +306,8 @@ const handleEvent = (event) => {
|
|
|
359
306
|
} break
|
|
360
307
|
|
|
361
308
|
case 'audioDevice': {
|
|
362
|
-
const {
|
|
363
|
-
delete event.
|
|
309
|
+
const { audioDeviceType } = event
|
|
310
|
+
delete event.audioDeviceType
|
|
364
311
|
|
|
365
312
|
if (type === 'deviceRemove') {
|
|
366
313
|
const { audioId } = event
|
|
@@ -370,23 +317,14 @@ const handleEvent = (event) => {
|
|
|
370
317
|
if (audioInstance) { audioInstance.close() }
|
|
371
318
|
}
|
|
372
319
|
|
|
373
|
-
const { devices
|
|
320
|
+
const { devices } = event
|
|
374
321
|
delete event.devices
|
|
375
322
|
|
|
376
|
-
|
|
377
|
-
makeAudioDevice(audioDevice)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
reconcileDevices(
|
|
381
|
-
audioModule,
|
|
382
|
-
Globals.audioDevices[isRecorder ? 'recording' : 'playback'],
|
|
383
|
-
audioDevices,
|
|
384
|
-
compareAudioDevice,
|
|
385
|
-
)
|
|
323
|
+
reconcileAudioDevices(devices, audioDeviceType)
|
|
386
324
|
} break
|
|
387
325
|
|
|
388
326
|
case 'clipboard': {
|
|
389
|
-
clipboardModule.emit(
|
|
327
|
+
clipboardModule.emit(type, event)
|
|
390
328
|
} break
|
|
391
329
|
|
|
392
330
|
// No default
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const Globals = require('../globals')
|
|
2
|
+
const { reconcileDevices } = require('./reconcile')
|
|
3
|
+
|
|
4
|
+
const { compare: compareAudioDevice } = require('../audio/device')
|
|
5
|
+
|
|
6
|
+
const reconcileAudioDevices = (audioDevices, audioDeviceType) => {
|
|
7
|
+
reconcileDevices(
|
|
8
|
+
require('../audio').audio,
|
|
9
|
+
Globals.audioDevices[audioDeviceType],
|
|
10
|
+
audioDevices,
|
|
11
|
+
compareAudioDevice,
|
|
12
|
+
)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = { reconcileAudioDevices }
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const Globals = require('../globals')
|
|
2
|
+
const { reconcileDevices } = require('./reconcile')
|
|
3
|
+
|
|
4
|
+
const { compare: compareDisplays } = require('../video/display')
|
|
5
|
+
|
|
6
|
+
const reconcileDisplays = (displays) => {
|
|
7
|
+
reconcileDevices(
|
|
8
|
+
require('../video').video,
|
|
9
|
+
Globals.displays,
|
|
10
|
+
displays,
|
|
11
|
+
compareDisplays,
|
|
12
|
+
'display',
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
module.exports = { reconcileDisplays }
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const Globals = require('../globals')
|
|
2
|
+
const { reconcileDevices } = require('./reconcile')
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
make: makeJoystickDevice,
|
|
6
|
+
compare: compareJoystickDevice,
|
|
7
|
+
} = require('../joystick/device')
|
|
8
|
+
const {
|
|
9
|
+
make: makeControllerDevice,
|
|
10
|
+
compare: compareControllerDevice,
|
|
11
|
+
filter: filterControllerDevice,
|
|
12
|
+
} = require('../controller/device')
|
|
13
|
+
|
|
14
|
+
const reconcileJoystickAndControllerDevices = (devices) => {
|
|
15
|
+
const joystickDevices = devices
|
|
16
|
+
.map(makeJoystickDevice)
|
|
17
|
+
|
|
18
|
+
const controllerDevices = devices
|
|
19
|
+
.filter(filterControllerDevice)
|
|
20
|
+
.map(makeControllerDevice)
|
|
21
|
+
|
|
22
|
+
reconcileDevices(
|
|
23
|
+
require('../joystick').joystick,
|
|
24
|
+
Globals.joystickDevices,
|
|
25
|
+
joystickDevices,
|
|
26
|
+
compareJoystickDevice,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
reconcileDevices(
|
|
30
|
+
require('../controller').controller,
|
|
31
|
+
Globals.controllerDevices,
|
|
32
|
+
controllerDevices,
|
|
33
|
+
compareControllerDevice,
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
module.exports = { reconcileJoystickAndControllerDevices }
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
|
|
2
|
+
const reconcileDevices = (
|
|
3
|
+
emitter,
|
|
4
|
+
mainList,
|
|
5
|
+
currList,
|
|
6
|
+
compare,
|
|
7
|
+
prefix = 'device',
|
|
8
|
+
) => {
|
|
9
|
+
const addEventType = `${prefix}Add`
|
|
10
|
+
const removeEventType = `${prefix}Remove`
|
|
11
|
+
|
|
12
|
+
currList.sort(compare)
|
|
13
|
+
|
|
14
|
+
let mainIndex = 0
|
|
15
|
+
let currIndex = 0
|
|
16
|
+
let mainDevice = mainList[mainIndex]
|
|
17
|
+
let currDevice = currList[currIndex]
|
|
18
|
+
while (mainIndex < mainList.length && currIndex < currList.length) {
|
|
19
|
+
const cmp = compare(mainDevice, currDevice)
|
|
20
|
+
if (cmp === 0) {
|
|
21
|
+
Object.assign(mainList[mainIndex], currList[currIndex])
|
|
22
|
+
mainDevice = mainList[++mainIndex]
|
|
23
|
+
currDevice = currList[++currIndex]
|
|
24
|
+
}
|
|
25
|
+
else if (cmp < 0) {
|
|
26
|
+
mainList.splice(mainIndex, 1)
|
|
27
|
+
const type = removeEventType
|
|
28
|
+
const event = { type, device: mainDevice }
|
|
29
|
+
emitter.emit(type, event)
|
|
30
|
+
mainDevice = mainList[mainIndex]
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
mainList.splice(mainIndex, 0, currDevice)
|
|
34
|
+
mainDevice = mainList[++mainIndex]
|
|
35
|
+
const type = addEventType
|
|
36
|
+
const event = { type, device: currDevice }
|
|
37
|
+
emitter.emit(type, event)
|
|
38
|
+
currDevice = currList[++currIndex]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (mainIndex < mainList.length) {
|
|
43
|
+
while (mainIndex < mainList.length) {
|
|
44
|
+
[ mainDevice ] = mainList.splice(mainIndex, 1)
|
|
45
|
+
const type = removeEventType
|
|
46
|
+
const event = { type, device: mainDevice }
|
|
47
|
+
emitter.emit(type, event)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
while (currIndex < currList.length) {
|
|
52
|
+
mainList.push(currDevice)
|
|
53
|
+
const type = addEventType
|
|
54
|
+
const event = { type, device: currDevice }
|
|
55
|
+
emitter.emit(type, event)
|
|
56
|
+
currDevice = currList[++currIndex]
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = { reconcileDevices }
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
|
|
2
2
|
const make = (device) => {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const {
|
|
4
|
+
isController,
|
|
5
|
+
controllerMapping,
|
|
6
|
+
controllerName,
|
|
7
|
+
controllerType,
|
|
8
|
+
...rest
|
|
9
|
+
} = device
|
|
10
|
+
return rest
|
|
5
11
|
}
|
|
6
12
|
|
|
7
|
-
const compare = (a, b) => a.
|
|
13
|
+
const compare = (a, b) => a._index - b._index
|
|
8
14
|
|
|
9
15
|
module.exports = {
|
|
10
16
|
make,
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
const Globals = require('../globals')
|
|
2
2
|
const Bindings = require('../bindings')
|
|
3
|
-
const { make: makeJoystickDevice } = require('./device')
|
|
4
3
|
const { EventsViaPoll } = require('../events/events-via-poll')
|
|
5
4
|
const { JoystickInstance } = require('./joystick-instance')
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
|
|
7
|
+
const { make: makeJoystickDevice } = require('./device')
|
|
8
|
+
const {
|
|
9
|
+
make: makeControllerDevice,
|
|
10
|
+
filter: filterControllerDevice,
|
|
11
|
+
} = require('../controller/device')
|
|
12
|
+
|
|
13
|
+
const devices = Bindings.joystick_getDevices()
|
|
14
|
+
Globals.joystickDevices = devices
|
|
15
|
+
.map(makeJoystickDevice)
|
|
16
|
+
Globals.controllerDevices = devices
|
|
17
|
+
.filter(filterControllerDevice)
|
|
18
|
+
.map(makeControllerDevice)
|
|
11
19
|
|
|
12
20
|
|
|
13
21
|
const validEvents = [ 'deviceAdd', 'deviceRemove' ]
|
|
@@ -15,6 +15,8 @@ class JoystickInstance extends EventsViaPoll {
|
|
|
15
15
|
constructor (device) {
|
|
16
16
|
super(validEvents)
|
|
17
17
|
|
|
18
|
+
if (!Globals.joystickDevices.includes(device)) { throw Object.assign(new Error("invalid device"), { device }) }
|
|
19
|
+
|
|
18
20
|
const result = Bindings.joystick_open(device._index)
|
|
19
21
|
|
|
20
22
|
this._firmwareVersion = result.firmwareVersion
|
|
@@ -11,6 +11,8 @@ class SensorInstance extends EventsViaPoll {
|
|
|
11
11
|
constructor (device) {
|
|
12
12
|
super(validEvents)
|
|
13
13
|
|
|
14
|
+
if (!Globals.sensorDevices.includes(device)) { throw Object.assign(new Error("invalid device"), { device }) }
|
|
15
|
+
|
|
14
16
|
Bindings.sensor_open(device._index)
|
|
15
17
|
|
|
16
18
|
this._device = device
|
|
@@ -12,6 +12,7 @@ const validEvents = [
|
|
|
12
12
|
'restore',
|
|
13
13
|
'move',
|
|
14
14
|
'resize',
|
|
15
|
+
'displayChange',
|
|
15
16
|
'focus',
|
|
16
17
|
'blur',
|
|
17
18
|
'hover',
|
|
@@ -121,6 +122,7 @@ class Window extends EventsViaPoll {
|
|
|
121
122
|
this._height = result.height
|
|
122
123
|
this._pixelWidth = result.pixelWidth
|
|
123
124
|
this._pixelHeight = result.pixelHeight
|
|
125
|
+
this._displayIndex = result.displayIndex
|
|
124
126
|
this._fullscreen = result.fullscreen
|
|
125
127
|
this._resizable = result.resizable
|
|
126
128
|
this._borderless = result.borderless
|
|
@@ -237,6 +239,10 @@ class Window extends EventsViaPoll {
|
|
|
237
239
|
get pixelWidth () { return this._pixelWidth }
|
|
238
240
|
get pixelHeight () { return this._pixelHeight }
|
|
239
241
|
|
|
242
|
+
get display () {
|
|
243
|
+
return Globals.displays[this._displayIndex]
|
|
244
|
+
}
|
|
245
|
+
|
|
240
246
|
get visible () { return this._visible }
|
|
241
247
|
show (show = true) {
|
|
242
248
|
if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
|
package/src/native/audio.cpp
CHANGED
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
#include <sstream>
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
std::map<bool, std::string> audio::device_types;
|
|
9
|
+
|
|
10
|
+
|
|
8
11
|
Napi::Array
|
|
9
12
|
audio::_getDevices(Napi::Env &env, bool is_capture)
|
|
10
13
|
{
|
|
11
|
-
const char *error = SDL_GetError();
|
|
12
|
-
if (error != global::no_error) { fprintf(stderr, "SDL silent error: %s\n", error); }
|
|
13
|
-
SDL_ClearError();
|
|
14
|
-
|
|
15
14
|
int num_devices = SDL_GetNumAudioDevices(is_capture ? 1 : 0);
|
|
16
15
|
if (num_devices == -1) {
|
|
17
|
-
|
|
16
|
+
// SDL_GetNumAudioDevices can return -1 even if there is no error
|
|
17
|
+
const char *error = SDL_GetError();
|
|
18
18
|
if (error != global::no_error) {
|
|
19
19
|
std::ostringstream message;
|
|
20
20
|
message << "SDL_GetNumAudioDevices(" << is_capture << ") error: " << error;
|
|
@@ -26,6 +26,8 @@ audio::_getDevices(Napi::Env &env, bool is_capture)
|
|
|
26
26
|
|
|
27
27
|
Napi::Array devices = Napi::Array::New(env, num_devices);
|
|
28
28
|
|
|
29
|
+
std::string device_type = audio::device_types[is_capture];
|
|
30
|
+
|
|
29
31
|
for (int i = 0; i < num_devices; i++) {
|
|
30
32
|
const char *name = SDL_GetAudioDeviceName(i, is_capture);
|
|
31
33
|
if (name == nullptr) {
|
|
@@ -36,8 +38,8 @@ audio::_getDevices(Napi::Env &env, bool is_capture)
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
Napi::Object device = Napi::Object::New(env);
|
|
39
|
-
device.Set("
|
|
40
|
-
device.Set("
|
|
41
|
+
device.Set("name", name);
|
|
42
|
+
device.Set("type", device_type);
|
|
41
43
|
|
|
42
44
|
devices.Set(i, device);
|
|
43
45
|
}
|
|
@@ -155,12 +157,8 @@ audio::dequeue (const Napi::CallbackInfo &info)
|
|
|
155
157
|
void *dst = info[1].As<Napi::Buffer<char>>().Data();
|
|
156
158
|
int size = info[2].As<Napi::Number>().Int32Value();
|
|
157
159
|
|
|
158
|
-
const char *error = SDL_GetError();
|
|
159
|
-
if (error != global::no_error) { fprintf(stderr, "SDL silent error: %s\n", error); }
|
|
160
|
-
SDL_ClearError();
|
|
161
|
-
|
|
162
160
|
int num = SDL_DequeueAudio(audio_id, dst, size);
|
|
163
|
-
error = SDL_GetError();
|
|
161
|
+
const char *error = SDL_GetError();
|
|
164
162
|
if (error != global::no_error) {
|
|
165
163
|
std::ostringstream message;
|
|
166
164
|
message << "SDL_DequeueAudio(" << audio_id << ") error: " << error;
|
package/src/native/audio.h
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
#define _AUDIO_H_
|
|
3
3
|
|
|
4
4
|
#include <napi.h>
|
|
5
|
+
#include <map>
|
|
6
|
+
#include <string>
|
|
5
7
|
|
|
6
8
|
namespace audio {
|
|
7
9
|
|
|
10
|
+
extern std::map<bool, std::string> device_types;
|
|
11
|
+
|
|
8
12
|
Napi::Array _getDevices(Napi::Env &env, bool is_capture);
|
|
9
13
|
|
|
10
14
|
Napi::Value getDevices(const Napi::CallbackInfo &info);
|