@kmamal/sdl 0.7.0 → 0.7.2

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
@@ -47,11 +47,11 @@ window.on('*', console.log)
47
47
  ### Canvas
48
48
  ```js
49
49
  import sdl from '@kmamal/sdl'
50
- import canvas from 'canvas'
50
+ import { createCanvas } from 'canvas'
51
51
 
52
52
  const window = sdl.video.createWindow({ title: "Canvas" })
53
53
  const { width, height } = window
54
- const canvas = canvas.createCanvas(width, height)
54
+ const canvas = createCanvas(width, height)
55
55
  const ctx = canvas.getContext('2d')
56
56
 
57
57
  // Clear screen to red
@@ -136,6 +136,7 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
136
136
  * [window.resizable](#windowresizable)
137
137
  * [window.setResizable(resizable)](#windowsetresizableresizable)
138
138
  * [window.borderless](#windowborderless)
139
+ * [window.alwaysOnTop](#windowalwaysontop)
139
140
  * [window.setBorderless(borderless)](#windowsetborderlessborderless)
140
141
  * [window.accelerated](#windowaccelerated)
141
142
  * [window.setAccelerated(accelerated)](#windowsetacceleratedaccelerated)
@@ -151,6 +152,10 @@ There are more examples [in the `examples/` folder](https://github.com/kmamal/no
151
152
  * [window.focused](#windowfocused)
152
153
  * [window.focus()](#windowfocus)
153
154
  * [window.hovered](#windowhovered)
155
+ * [window.skipTaskbar](#windowskiptaskbar)
156
+ * [window.popupMenu](#windowpopupmenu)
157
+ * [window.tooltip](#windowtooltip)
158
+ * [window.utility](#windowutility)
154
159
  * [window.render(width, height, stride, format, buffer)](#windowrenderwidth-height-stride-format-buffer)
155
160
  * [window.setIcon(width, height, stride, format, buffer)](#windowseticonwidth-height-stride-format-buffer)
156
161
  * [window.destroyed](#windowdestroyed)
@@ -482,9 +487,14 @@ The window that the mouse is hovered over, or `null` if the mouse is not over a
482
487
  * `fullscreen: <boolean>` Set to `true` to create the window in fullscreen mode. Default: `false`
483
488
  * `resizable: <boolean>` Set to `true` to allow resizing the window by dragging its borders. Default: `false`
484
489
  * `borderless: <boolean>` Set to `true` to completely hide the window's borders and title bar. Default: `false`
490
+ * `alwaysOnTop: <boolean>` Set to `true` to always show this window above others. Default: `false`
485
491
  * `accelerated: <boolean>` Set to `false` to disable hardware accelerated rendering. Default: `true`
486
492
  * `vsync: <boolean>` Set to `false` to disable frame rate synchronization. Default: `true`
487
493
  * `opengl: <boolean>` Set to `true` to create an OpenGL-compatible window (for use with [@kmamal/gl](https://github.com/kmamal/headless-gl#readme)). Default: `false`
494
+ * `skipTaskbar: <boolean>` X11 only. Set to `true` to not add this window to the taskbar. Default: `false`
495
+ * `popupMenu: <boolean>` X11 only. Set to `true` to treat this window like a popup menu. Default: `false`
496
+ * `tooltip: <boolean>` X11 only. Set to `true` to treat this window like a tooltip. Default: `false`
497
+ * `utility: <boolean>` X11 only. Set to `true` to treat this window like a utility window. Default: `false`
488
498
  * Returns: [`<Window>`](#class-window) an object representing the new window.
489
499
 
490
500
  Creates a new window.
@@ -512,7 +522,7 @@ Fired when a window becomes hidden.
512
522
 
513
523
  ### Event: 'expose'
514
524
 
515
- Fired when a window becomes exposed.
525
+ Fired when a window becomes exposed and should be redrawn.
516
526
 
517
527
  ### Event: 'minimize'
518
528
 
@@ -773,6 +783,13 @@ A borderless window has no borders or title bar.
773
783
 
774
784
  Changes the window's borderless property.
775
785
 
786
+ ### window.alwaysOnTop
787
+
788
+ * `<boolean>`
789
+
790
+ Will be `true` if the window was created with `alwaysOnTop: true`.
791
+ Such a window will always be shown above other windows.
792
+
776
793
  ### window.accelerated
777
794
 
778
795
  * `<boolean>`
@@ -854,6 +871,38 @@ Gives the window the keyboard focus.
854
871
 
855
872
  Will be `true` if the mouse is over the window.
856
873
 
874
+ ### window.skipTaskbar
875
+
876
+ * `<boolean>`
877
+
878
+ X11 only.
879
+ Will be `true` if the window was created with `skipTaskbar: true`.
880
+ Such a window will not be added to the taskbar.
881
+
882
+ ### window.popupMenu
883
+
884
+ * `<boolean>`
885
+
886
+ X11 only.
887
+ Will be `true` if the window was created with `popupMenu: true`.
888
+ Such a window will always be treated as a popup menu.
889
+
890
+ ### window.tooltip
891
+
892
+ * `<boolean>`
893
+
894
+ X11 only.
895
+ Will be `true` if the window was created with `tooltip: true`.
896
+ Such a window will always be treated as a tooltip.
897
+
898
+ ### window.utility
899
+
900
+ * `<boolean>`
901
+
902
+ X11 only.
903
+ Will be `true` if the window was created with `utility: true`.
904
+ Such a window will always be treated as a utility window.
905
+
857
906
  ### window.render(width, height, stride, format, buffer)
858
907
 
859
908
  * `width, height, stride, format, buffer: `[`<Image>`](#image-data) The image to display on the window.
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.7.0",
2
+ "version": "0.7.2",
3
3
  "name": "@kmamal/sdl",
4
4
  "description": "SDL bindings for Node.js",
5
5
  "keywords": [
@@ -100,6 +100,9 @@ const handleEvents = () => {
100
100
  case Enums.eventType.hide: {
101
101
  window._visible = false
102
102
  } break
103
+ case Enums.eventType.expose: {
104
+ // Nothing
105
+ } break
103
106
 
104
107
  case Enums.eventType.minimize: {
105
108
  window._visible = false
@@ -44,9 +44,14 @@ class Window extends EventsViaPoll {
44
44
  fullscreen = false,
45
45
  resizable = false,
46
46
  borderless = false,
47
+ alwaysOnTop = false,
47
48
  accelerated = true,
48
49
  vsync = true,
49
50
  opengl = false,
51
+ skipTaskbar = false,
52
+ popupMenu = false,
53
+ tooltip = false,
54
+ utility = false,
50
55
  } = options
51
56
 
52
57
  if (typeof title !== 'string') { throw Object.assign(new Error("title must be a string"), { title }) }
@@ -65,9 +70,14 @@ class Window extends EventsViaPoll {
65
70
  if (typeof fullscreen !== 'boolean') { throw Object.assign(new Error("fullscreen must be a boolean"), { fullscreen }) }
66
71
  if (typeof resizable !== 'boolean') { throw Object.assign(new Error("resizable must be a boolean"), { resizable }) }
67
72
  if (typeof borderless !== 'boolean') { throw Object.assign(new Error("borderless must be a boolean"), { borderless }) }
73
+ if (typeof alwaysOnTop !== 'boolean') { throw Object.assign(new Error("alwaysOnTop must be a boolean"), { alwaysOnTop }) }
68
74
  if (typeof accelerated !== 'boolean') { throw Object.assign(new Error("accelerated must be a boolean"), { accelerated }) }
69
75
  if (typeof vsync !== 'boolean') { throw Object.assign(new Error("vsync must be a boolean"), { vsync }) }
70
76
  if (typeof opengl !== 'boolean') { throw Object.assign(new Error("opengl must be a boolean"), { opengl }) }
77
+ if (typeof skipTaskbar !== 'boolean') { throw Object.assign(new Error("skipTaskbar must be a boolean"), { skipTaskbar }) }
78
+ if (typeof popupMenu !== 'boolean') { throw Object.assign(new Error("popupMenu must be a boolean"), { popupMenu }) }
79
+ if (typeof tooltip !== 'boolean') { throw Object.assign(new Error("tooltip must be a boolean"), { tooltip }) }
80
+ if (typeof utility !== 'boolean') { throw Object.assign(new Error("utility must be a boolean"), { utility }) }
71
81
  if (display && (Number.isFinite(x) || Number.isFinite(y))) { throw Object.assign(new Error("display and x/y are mutually exclusive"), { display, x, y }) }
72
82
  if (resizable && borderless) { throw Object.assign(new Error("resizable and borderless are mutually exclusive"), { resizable, borderless }) }
73
83
 
@@ -90,9 +100,14 @@ class Window extends EventsViaPoll {
90
100
  fullscreen,
91
101
  resizable,
92
102
  borderless,
103
+ alwaysOnTop,
93
104
  accelerated,
94
105
  vsync,
95
106
  opengl,
107
+ skipTaskbar,
108
+ popupMenu,
109
+ tooltip,
110
+ utility,
96
111
  )
97
112
 
98
113
  this._id = result.id
@@ -103,9 +118,14 @@ class Window extends EventsViaPoll {
103
118
  this._fullscreen = result.fullscreen
104
119
  this._resizable = result.resizable
105
120
  this._borderless = result.borderless
121
+ this._alwaysOnTop = result.alwaysOnTop
106
122
  this._accelerated = result.accelerated
107
123
  this._vsync = result.vsync
108
124
  this._native = result.native ?? null
125
+ this._skipTaskbar = result.skipTaskbar
126
+ this._popupMenu = result.popupMenu
127
+ this._tooltip = result.tooltip
128
+ this._utility = result.utility
109
129
 
110
130
  this._title = title
111
131
  this._visible = visible
@@ -221,6 +241,8 @@ class Window extends EventsViaPoll {
221
241
  this._borderless = Bindings.window_setBorderless(this._id, borderless)
222
242
  }
223
243
 
244
+ get alwaysOnTop () { return this._alwaysOnTop }
245
+
224
246
  get accelerated () { return this._accelerated }
225
247
  setAccelerated (accelerated) {
226
248
  if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
@@ -285,6 +307,11 @@ class Window extends EventsViaPoll {
285
307
 
286
308
  get hovered () { return this._hovered }
287
309
 
310
+ get skipTaskbar () { return this._skipTaskbar }
311
+ get popupMenu () { return this._popupMenu }
312
+ get tooltip () { return this._tooltip }
313
+ get utility () { return this._utility }
314
+
288
315
  render (width, height, stride, format, buffer) {
289
316
  if (this._destroyed) { throw Object.assign(new Error("window is destroyed"), { id: this._id }) }
290
317
 
@@ -303,7 +303,7 @@ window_create(napi_env env, napi_callback_info info)
303
303
  int * height = nullptr;
304
304
  void * native_pointer = nullptr;
305
305
 
306
- napi_value argv[13];
306
+ napi_value argv[18];
307
307
  size_t argc = sizeof(argv) / sizeof(napi_value);
308
308
  CALL_NAPI(napi_get_cb_info, info, &argc, argv, nullptr, nullptr);
309
309
 
@@ -341,21 +341,30 @@ window_create(napi_env env, napi_callback_info info)
341
341
  CALL_NAPI(napi_get_value_int32, argv[5], y);
342
342
  }
343
343
 
344
- bool visible, fullscreen, resizable, borderless, accelerated, vsync, opengl;
344
+ bool visible, fullscreen, resizable, borderless, alwaysOnTop,
345
+ accelerated, vsync, opengl,
346
+ skipTaskbar, popupMenu, tooltip, utility;
345
347
  CALL_NAPI(napi_get_value_bool, argv[6], &visible);
346
348
  CALL_NAPI(napi_get_value_bool, argv[7], &fullscreen);
347
349
  CALL_NAPI(napi_get_value_bool, argv[8], &resizable);
348
350
  CALL_NAPI(napi_get_value_bool, argv[9], &borderless);
349
- CALL_NAPI(napi_get_value_bool, argv[10], &accelerated);
350
- CALL_NAPI(napi_get_value_bool, argv[11], &vsync);
351
- CALL_NAPI(napi_get_value_bool, argv[12], &opengl);
351
+ CALL_NAPI(napi_get_value_bool, argv[10], &alwaysOnTop);
352
+ CALL_NAPI(napi_get_value_bool, argv[11], &accelerated);
353
+ CALL_NAPI(napi_get_value_bool, argv[12], &vsync);
354
+ CALL_NAPI(napi_get_value_bool, argv[13], &opengl);
355
+ CALL_NAPI(napi_get_value_bool, argv[14], &skipTaskbar);
356
+ CALL_NAPI(napi_get_value_bool, argv[15], &popupMenu);
357
+ CALL_NAPI(napi_get_value_bool, argv[16], &tooltip);
358
+ CALL_NAPI(napi_get_value_bool, argv[17], &utility);
352
359
 
353
360
  int window_id;
354
361
  int native_pointer_size;
355
362
  CALL_SDL_HELPER(window_create,
356
363
  title, display,
357
364
  &x, &y, &width, &height,
358
- visible, &fullscreen, &resizable, &borderless, &accelerated, &vsync, opengl,
365
+ visible, &fullscreen, &resizable, &borderless, &alwaysOnTop,
366
+ &accelerated, &vsync, opengl,
367
+ &skipTaskbar, &popupMenu, &tooltip, &utility,
359
368
  &window_id, &native_pointer, &native_pointer_size
360
369
  );
361
370
 
@@ -397,6 +406,11 @@ window_create(napi_env env, napi_callback_info info)
397
406
  CALL_NAPI(napi_create_string_latin1, "borderless", 10, &key);
398
407
  CALL_NAPI(napi_set_property, result, key, value);
399
408
 
409
+ CALL_NAPI(napi_create_int32, alwaysOnTop, &value);
410
+ CALL_NAPI(napi_coerce_to_bool, value, &value);
411
+ CALL_NAPI(napi_create_string_latin1, "alwaysOnTop", 11, &key);
412
+ CALL_NAPI(napi_set_property, result, key, value);
413
+
400
414
  CALL_NAPI(napi_create_int32, accelerated, &value);
401
415
  CALL_NAPI(napi_coerce_to_bool, value, &value);
402
416
  CALL_NAPI(napi_create_string_latin1, "accelerated", 11, &key);
@@ -407,6 +421,26 @@ window_create(napi_env env, napi_callback_info info)
407
421
  CALL_NAPI(napi_create_string_latin1, "vsync", 5, &key);
408
422
  CALL_NAPI(napi_set_property, result, key, value);
409
423
 
424
+ CALL_NAPI(napi_create_int32, skipTaskbar, &value);
425
+ CALL_NAPI(napi_coerce_to_bool, value, &value);
426
+ CALL_NAPI(napi_create_string_latin1, "skipTaskbar", 11, &key);
427
+ CALL_NAPI(napi_set_property, result, key, value);
428
+
429
+ CALL_NAPI(napi_create_int32, popupMenu, &value);
430
+ CALL_NAPI(napi_coerce_to_bool, value, &value);
431
+ CALL_NAPI(napi_create_string_latin1, "popupMenu", 9, &key);
432
+ CALL_NAPI(napi_set_property, result, key, value);
433
+
434
+ CALL_NAPI(napi_create_int32, tooltip, &value);
435
+ CALL_NAPI(napi_coerce_to_bool, value, &value);
436
+ CALL_NAPI(napi_create_string_latin1, "tooltip", 7, &key);
437
+ CALL_NAPI(napi_set_property, result, key, value);
438
+
439
+ CALL_NAPI(napi_create_int32, utility, &value);
440
+ CALL_NAPI(napi_coerce_to_bool, value, &value);
441
+ CALL_NAPI(napi_create_string_latin1, "utility", 7, &key);
442
+ CALL_NAPI(napi_set_property, result, key, value);
443
+
410
444
  if (native_pointer) {
411
445
  CALL_NAPI(napi_create_external_buffer,
412
446
  native_pointer_size, native_pointer, freePointer, native_pointer,
@@ -1376,9 +1376,14 @@ window_create (
1376
1376
  bool * fullscreen,
1377
1377
  bool * resizable,
1378
1378
  bool * borderless,
1379
+ bool * alwaysOnTop,
1379
1380
  bool * accelerated,
1380
1381
  bool * vsync,
1381
1382
  bool opengl,
1383
+ bool * skipTaskbar,
1384
+ bool * popupMenu,
1385
+ bool * tooltip,
1386
+ bool * utility,
1382
1387
  int * window_id, void ** native_pointer, int * native_pointer_size
1383
1388
  ) {
1384
1389
  SDL_Window * window;
@@ -1404,7 +1409,12 @@ window_create (
1404
1409
  | (*fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0)
1405
1410
  | (*resizable ? SDL_WINDOW_RESIZABLE : 0)
1406
1411
  | (*borderless ? SDL_WINDOW_BORDERLESS : 0)
1407
- | (opengl ? SDL_WINDOW_OPENGL : 0);
1412
+ | (*alwaysOnTop ? SDL_WINDOW_ALWAYS_ON_TOP : 0)
1413
+ | (opengl ? SDL_WINDOW_OPENGL : 0)
1414
+ | (*skipTaskbar ? SDL_WINDOW_SKIP_TASKBAR : 0)
1415
+ | (*popupMenu ? SDL_WINDOW_POPUP_MENU : 0)
1416
+ | (*tooltip ? SDL_WINDOW_TOOLTIP : 0)
1417
+ | (*utility ? SDL_WINDOW_UTILITY : 0);
1408
1418
 
1409
1419
  window = SDL_CreateWindow(title, **x, **y, **width, **height, desired_flags);
1410
1420
  if (window == nullptr) {
@@ -1417,6 +1427,11 @@ window_create (
1417
1427
  *fullscreen = actual_flags & (SDL_WINDOW_FULLSCREEN | SDL_WINDOW_FULLSCREEN_DESKTOP);
1418
1428
  *resizable = actual_flags & SDL_WINDOW_RESIZABLE;
1419
1429
  *borderless = actual_flags & SDL_WINDOW_BORDERLESS;
1430
+ *alwaysOnTop = actual_flags & SDL_WINDOW_ALWAYS_ON_TOP;
1431
+ *skipTaskbar = actual_flags & SDL_WINDOW_SKIP_TASKBAR;
1432
+ *popupMenu = actual_flags & SDL_WINDOW_POPUP_MENU;
1433
+ *tooltip = actual_flags & SDL_WINDOW_TOOLTIP;
1434
+ *utility = actual_flags & SDL_WINDOW_UTILITY;
1420
1435
 
1421
1436
  *window_id = SDL_GetWindowID(window);
1422
1437
  if (*window_id == 0) {
@@ -60,9 +60,14 @@ ErrorMessage * window_create (
60
60
  bool * fullscreen,
61
61
  bool * resizable,
62
62
  bool * borderless,
63
+ bool * alwaysOnTop,
63
64
  bool * accelerated,
64
65
  bool * vsync,
65
66
  bool opengl,
67
+ bool * skipTaskbar,
68
+ bool * popupMenu,
69
+ bool * tooltip,
70
+ bool * utility,
66
71
  int * window_id, void ** native_pointer, int * native_pointer_size
67
72
  );
68
73
  ErrorMessage * window_setTitle (int window_id, const char * title);
@@ -328,6 +328,8 @@ export namespace Sdl {
328
328
  readonly borderless: boolean
329
329
  setBorderless (borderless: boolean): void
330
330
 
331
+ readonly alwaysOnTop: boolean
332
+
331
333
  readonly accelerated: boolean
332
334
  setAccelerated (accelerated: boolean): void
333
335
 
@@ -349,6 +351,11 @@ export namespace Sdl {
349
351
 
350
352
  readonly hovered: boolean
351
353
 
354
+ readonly skipTaskbar: boolean
355
+ readonly popupMenu: boolean
356
+ readonly tooltip: boolean
357
+ readonly utility: boolean
358
+
352
359
  render (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
353
360
 
354
361
  setIcon (width: number, height: number, stride: number, format: Format, buffer: Buffer): void
@@ -375,9 +382,14 @@ export namespace Sdl {
375
382
  fullscreen?: boolean
376
383
  resizable?: boolean
377
384
  borderless?: boolean
385
+ alwaysOnTop?: boolean
378
386
  accelerated?: boolean
379
387
  vsync?: boolean
380
388
  opengl?: boolean
389
+ skipTaskbar?: boolean
390
+ popupMenu?: boolean
391
+ tooltip?: boolean
392
+ utility?: boolean
381
393
  }): Window
382
394
  }
383
395
  }