Skip to content

Commit 7a943af

Browse files
committed
Update constants and add Wayland platform
1 parent 52a8222 commit 7a943af

File tree

6 files changed

+137
-26
lines changed

6 files changed

+137
-26
lines changed

index.d.ts

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -376,24 +376,24 @@ declare module "glfw-raub" {
376376
*
377377
* @see https://www.glfw.org/docs/latest/group__keys.html
378378
*/
379-
getKey(): number;
379+
getKey(key: number): number;
380380

381381
/**
382382
* Get mouse button state (GLFW_PRESS/GLFW_RELEASE).
383383
*
384384
* @see https://www.glfw.org/docs/latest/group__buttons.html
385385
*/
386-
getMouseButton(): number;
386+
getMouseButton(button: number): number;
387387

388388
/**
389389
* Get window attribute.
390390
*
391391
* @see https://www.glfw.org/docs/latest/window_guide.html#window_attribs
392392
*/
393-
getWindowAttrib(): number;
393+
getWindowAttrib(attrib: number): number;
394394

395395
/** Set input mode option. */
396-
setInputMode(mode: number): void;
396+
setInputMode(mode: number, value: number): void;
397397

398398
/** Swaps the front and back buffers of the window. */
399399
swapBuffers(): void;
@@ -594,7 +594,7 @@ declare module "glfw-raub" {
594594
const showConsole: TCbVoid;
595595

596596
/** Draws a test scene, used in examples here. */
597-
const testScene: TCbVoid;
597+
const testScene: (w: number, h: number, z: number) => void;
598598

599599
/** Draws a test scene, that reacts to a joystick. */
600600
const testJoystick: TCbVoid;
@@ -675,8 +675,8 @@ declare module "glfw-raub" {
675675
const showWindow: TFnWindow;
676676
const windowShouldClose: (window: TWindowPtr) => number;
677677
const setWindowShouldClose: (window: TWindowPtr, shouldClose: number) => void;
678-
const getWindowAttrib: (window: TWindowPtr) => number;
679-
const setWindowAttrib: (window: TWindowPtr, value: number) => void;
678+
const getWindowAttrib: (window: TWindowPtr, attrib: number) => number;
679+
const setWindowAttrib: (window: TWindowPtr, attrib: number, value: number) => void;
680680
const setInputMode: (window: TWindowPtr, mode: number, value: number) => void;
681681
const getInputMode: (window: TWindowPtr, mode: number) => number;
682682
const pollEvents: TCbVoid;
@@ -946,6 +946,10 @@ declare module "glfw-raub" {
946946
const PLATFORM_ERROR: number;
947947
const FORMAT_UNAVAILABLE: number;
948948
const NO_WINDOW_CONTEXT: number;
949+
const CURSOR_UNAVAILABLE: number;
950+
const FEATURE_UNAVAILABLE: number;
951+
const FEATURE_UNIMPLEMENTED: number;
952+
const PLATFORM_UNAVAILABLE: number;
949953
const FOCUSED: number;
950954
const ICONIFIED: number;
951955
const RESIZABLE: number;
@@ -958,6 +962,9 @@ declare module "glfw-raub" {
958962
const TRANSPARENT_FRAMEBUFFER: number;
959963
const HOVERED: number;
960964
const FOCUS_ON_SHOW: number;
965+
const MOUSE_PASSTHROUGH: number;
966+
const POSITION_X: number;
967+
const POSITION_Y: number;
961968
const RED_BITS: number;
962969
const GREEN_BITS: number;
963970
const BLUE_BITS: number;
@@ -980,12 +987,14 @@ declare module "glfw-raub" {
980987
const CONTEXT_REVISION: number;
981988
const CONTEXT_ROBUSTNESS: number;
982989
const OPENGL_FORWARD_COMPAT: number;
990+
const CONTEXT_DEBUG: number;
983991
const OPENGL_DEBUG_CONTEXT: number;
984992
const OPENGL_PROFILE: number;
985993
const CONTEXT_RELEASE_BEHAVIOR: number;
986994
const CONTEXT_NO_ERROR: number;
987995
const CONTEXT_CREATION_API: number;
988996
const SCALE_TO_MONITOR: number;
997+
const SCALE_FRAMEBUFFER: number;
989998
const COCOA_RETINA_FRAMEBUFFER: number;
990999
const COCOA_FRAME_NAME: number;
9911000
const COCOA_GRAPHICS_SWITCHING: number;
@@ -1008,24 +1017,55 @@ declare module "glfw-raub" {
10081017
const CURSOR_NORMAL: number;
10091018
const CURSOR_HIDDEN: number;
10101019
const CURSOR_DISABLED: number;
1011-
const ANY_RELEASE_BEHAVIOR: number;
1012-
const RELEASE_BEHAVIOR_FLUSH: number;
1013-
const RELEASE_BEHAVIOR_NONE: number;
1014-
const NATIVE_CONTEXT_API: number;
1015-
const EGL_CONTEXT_API: number;
1016-
const OSMESA_CONTEXT_API: number;
1020+
const CURSOR_CAPTURED: number;
10171021
const ARROW_CURSOR: number;
10181022
const IBEAM_CURSOR: number;
10191023
const CROSSHAIR_CURSOR: number;
10201024
const HAND_CURSOR: number;
10211025
const HRESIZE_CURSOR: number;
10221026
const VRESIZE_CURSOR: number;
1027+
const POINTING_HAND_CURSOR: number;
1028+
const RESIZE_EW_CURSOR: number;
1029+
const RESIZE_NS_CURSOR: number;
1030+
const RESIZE_NWSE_CURSOR: number;
1031+
const RESIZE_NESW_CURSOR: number;
1032+
const RESIZE_ALL_CURSOR: number;
1033+
const NOT_ALLOWED_CURSOR: number;
1034+
const ANY_RELEASE_BEHAVIOR: number;
1035+
const RELEASE_BEHAVIOR_FLUSH: number;
1036+
const RELEASE_BEHAVIOR_NONE: number;
1037+
const NATIVE_CONTEXT_API: number;
1038+
const EGL_CONTEXT_API: number;
1039+
const OSMESA_CONTEXT_API: number;
1040+
const WIN32_KEYBOARD_MENU: number;
1041+
const WIN32_SHOWDEFAULT: number;
1042+
const WAYLAND_APP_ID: number;
1043+
const ANGLE_PLATFORM_TYPE_NONE: number;
1044+
const ANGLE_PLATFORM_TYPE_OPENGL: number;
1045+
const ANGLE_PLATFORM_TYPE_OPENGLES: number;
1046+
const ANGLE_PLATFORM_TYPE_D3D9: number;
1047+
const ANGLE_PLATFORM_TYPE_D3D11: number;
1048+
const ANGLE_PLATFORM_TYPE_VULKAN: number;
1049+
const ANGLE_PLATFORM_TYPE_METAL: number;
1050+
const WAYLAND_PREFER_LIBDECOR: number;
1051+
const WAYLAND_DISABLE_LIBDECOR: number;
1052+
const ANGLE_PLATFORM_TYPE: number;
1053+
const PLATFORM: number;
1054+
const X11_XCB_VULKAN_SURFACE: number;
1055+
const WAYLAND_LIBDECOR: number;
1056+
const ANY_PLATFORM: number;
1057+
const PLATFORM_WIN32: number;
1058+
const PLATFORM_COCOA: number;
1059+
const PLATFORM_WAYLAND: number;
1060+
const PLATFORM_X11: number;
1061+
const PLATFORM_NULL: number;
10231062
const CONNECTED: number;
10241063
const DISCONNECTED: number;
10251064
const JOYSTICK_HAT_BUTTONS: number;
10261065
const COCOA_CHDIR_RESOURCES: number;
10271066
const COCOA_MENUBAR: number;
10281067
const DONT_CARE: number;
1068+
const ANY_POSITION: number;
10291069

10301070
/**
10311071
* Human-readable names for keyboard keys.

js/window.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,9 @@ class Window extends EventEmitter {
219219
glfw.setWindowPos(this._window, this._x, this._y);
220220
}
221221
} else if (this._mode === 'borderless') {
222-
223222
const monitor = this._monitors[this._display];
224223
glfw.setWindowPos(this._window, monitor.pos_x, monitor.pos_y);
225224
glfw.setWindowSize(this._window, monitor.width, monitor.height);
226-
227225
}
228226

229227
this.makeCurrent();

src/cpp/bindings.cpp

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,10 @@ Napi::Object initModule(Napi::Env env, Napi::Object exports) {
352352
JS_GLFW_CONSTANT(PLATFORM_ERROR);
353353
JS_GLFW_CONSTANT(FORMAT_UNAVAILABLE);
354354
JS_GLFW_CONSTANT(NO_WINDOW_CONTEXT);
355+
JS_GLFW_CONSTANT(CURSOR_UNAVAILABLE);
356+
JS_GLFW_CONSTANT(FEATURE_UNAVAILABLE);
357+
JS_GLFW_CONSTANT(FEATURE_UNIMPLEMENTED);
358+
JS_GLFW_CONSTANT(PLATFORM_UNAVAILABLE);
355359

356360
JS_GLFW_CONSTANT(FOCUSED);
357361
JS_GLFW_CONSTANT(ICONIFIED);
@@ -366,6 +370,9 @@ Napi::Object initModule(Napi::Env env, Napi::Object exports) {
366370

367371
JS_GLFW_CONSTANT(HOVERED);
368372
JS_GLFW_CONSTANT(FOCUS_ON_SHOW);
373+
JS_GLFW_CONSTANT(MOUSE_PASSTHROUGH);
374+
JS_GLFW_CONSTANT(POSITION_X);
375+
JS_GLFW_CONSTANT(POSITION_Y);
369376
JS_GLFW_CONSTANT(RED_BITS);
370377
JS_GLFW_CONSTANT(GREEN_BITS);
371378
JS_GLFW_CONSTANT(BLUE_BITS);
@@ -389,12 +396,14 @@ Napi::Object initModule(Napi::Env env, Napi::Object exports) {
389396
JS_GLFW_CONSTANT(CONTEXT_REVISION);
390397
JS_GLFW_CONSTANT(CONTEXT_ROBUSTNESS);
391398
JS_GLFW_CONSTANT(OPENGL_FORWARD_COMPAT);
399+
JS_GLFW_CONSTANT(CONTEXT_DEBUG);
392400
JS_GLFW_CONSTANT(OPENGL_DEBUG_CONTEXT);
393401
JS_GLFW_CONSTANT(OPENGL_PROFILE);
394402
JS_GLFW_CONSTANT(CONTEXT_RELEASE_BEHAVIOR);
395403
JS_GLFW_CONSTANT(CONTEXT_NO_ERROR);
396404
JS_GLFW_CONSTANT(CONTEXT_CREATION_API);
397405
JS_GLFW_CONSTANT(SCALE_TO_MONITOR);
406+
JS_GLFW_CONSTANT(SCALE_FRAMEBUFFER);
398407
JS_GLFW_CONSTANT(COCOA_RETINA_FRAMEBUFFER);
399408
JS_GLFW_CONSTANT(COCOA_FRAME_NAME);
400409
JS_GLFW_CONSTANT(COCOA_GRAPHICS_SWITCHING);
@@ -423,18 +432,50 @@ Napi::Object initModule(Napi::Env env, Napi::Object exports) {
423432
JS_GLFW_CONSTANT(CURSOR_NORMAL);
424433
JS_GLFW_CONSTANT(CURSOR_HIDDEN);
425434
JS_GLFW_CONSTANT(CURSOR_DISABLED);
426-
JS_GLFW_CONSTANT(ANY_RELEASE_BEHAVIOR);
427-
JS_GLFW_CONSTANT(RELEASE_BEHAVIOR_FLUSH);
428-
JS_GLFW_CONSTANT(RELEASE_BEHAVIOR_NONE);
429-
JS_GLFW_CONSTANT(NATIVE_CONTEXT_API);
430-
JS_GLFW_CONSTANT(EGL_CONTEXT_API);
431-
JS_GLFW_CONSTANT(OSMESA_CONTEXT_API);
435+
JS_GLFW_CONSTANT(CURSOR_CAPTURED);
432436
JS_GLFW_CONSTANT(ARROW_CURSOR);
433437
JS_GLFW_CONSTANT(IBEAM_CURSOR);
434438
JS_GLFW_CONSTANT(CROSSHAIR_CURSOR);
435439
JS_GLFW_CONSTANT(HAND_CURSOR);
436440
JS_GLFW_CONSTANT(HRESIZE_CURSOR);
437441
JS_GLFW_CONSTANT(VRESIZE_CURSOR);
442+
JS_GLFW_CONSTANT(POINTING_HAND_CURSOR);
443+
JS_GLFW_CONSTANT(RESIZE_EW_CURSOR);
444+
JS_GLFW_CONSTANT(RESIZE_NS_CURSOR);
445+
JS_GLFW_CONSTANT(RESIZE_NWSE_CURSOR);
446+
JS_GLFW_CONSTANT(RESIZE_NESW_CURSOR);
447+
JS_GLFW_CONSTANT(RESIZE_ALL_CURSOR);
448+
JS_GLFW_CONSTANT(NOT_ALLOWED_CURSOR);
449+
450+
JS_GLFW_CONSTANT(ANY_RELEASE_BEHAVIOR);
451+
JS_GLFW_CONSTANT(RELEASE_BEHAVIOR_FLUSH);
452+
JS_GLFW_CONSTANT(RELEASE_BEHAVIOR_NONE);
453+
454+
JS_GLFW_CONSTANT(NATIVE_CONTEXT_API);
455+
JS_GLFW_CONSTANT(EGL_CONTEXT_API);
456+
JS_GLFW_CONSTANT(OSMESA_CONTEXT_API);
457+
JS_GLFW_CONSTANT(WIN32_KEYBOARD_MENU);
458+
JS_GLFW_CONSTANT(WIN32_SHOWDEFAULT);
459+
JS_GLFW_CONSTANT(WAYLAND_APP_ID);
460+
JS_GLFW_CONSTANT(ANGLE_PLATFORM_TYPE_NONE);
461+
JS_GLFW_CONSTANT(ANGLE_PLATFORM_TYPE_OPENGL);
462+
JS_GLFW_CONSTANT(ANGLE_PLATFORM_TYPE_OPENGLES);
463+
JS_GLFW_CONSTANT(ANGLE_PLATFORM_TYPE_D3D9);
464+
JS_GLFW_CONSTANT(ANGLE_PLATFORM_TYPE_D3D11);
465+
JS_GLFW_CONSTANT(ANGLE_PLATFORM_TYPE_VULKAN);
466+
JS_GLFW_CONSTANT(ANGLE_PLATFORM_TYPE_METAL);
467+
JS_GLFW_CONSTANT(WAYLAND_PREFER_LIBDECOR);
468+
JS_GLFW_CONSTANT(WAYLAND_DISABLE_LIBDECOR);
469+
JS_GLFW_CONSTANT(ANGLE_PLATFORM_TYPE);
470+
JS_GLFW_CONSTANT(PLATFORM);
471+
JS_GLFW_CONSTANT(X11_XCB_VULKAN_SURFACE);
472+
JS_GLFW_CONSTANT(WAYLAND_LIBDECOR);
473+
JS_GLFW_CONSTANT(ANY_PLATFORM);
474+
JS_GLFW_CONSTANT(PLATFORM_WIN32);
475+
JS_GLFW_CONSTANT(PLATFORM_COCOA);
476+
JS_GLFW_CONSTANT(PLATFORM_WAYLAND);
477+
JS_GLFW_CONSTANT(PLATFORM_X11);
478+
JS_GLFW_CONSTANT(PLATFORM_NULL);
438479

439480
JS_GLFW_CONSTANT(CONNECTED);
440481
JS_GLFW_CONSTANT(DISCONNECTED);
@@ -445,8 +486,7 @@ Napi::Object initModule(Napi::Env env, Napi::Object exports) {
445486
JS_GLFW_CONSTANT(COCOA_MENUBAR);
446487

447488
JS_GLFW_CONSTANT(DONT_CARE);
448-
449-
JS_GLFW_CONSTANT(NO_API);
489+
JS_GLFW_CONSTANT(ANY_POSITION);
450490

451491
return exports;
452492
}

src/cpp/glfw-platform.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ DBG_EXPORT JS_METHOD(platformDevice) { NAPI_ENV;
1313
#ifdef _WIN32
1414
RET_NUM(reinterpret_cast<uint64_t>(wglGetCurrentDC()));
1515
#elif __linux__
16-
RET_NUM(reinterpret_cast<uint64_t>(glfwGetX11Display()));
16+
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
17+
RET_NUM(reinterpret_cast<uint64_t>(glfwGetWaylandDisplay()));
18+
} else {
19+
RET_NUM(reinterpret_cast<uint64_t>(glfwGetX11Display()));
20+
}
1721
#elif __APPLE__
1822
CGLContextObj kCGLContext = CGLGetCurrentContext();
1923
RET_NUM(reinterpret_cast<uint64_t>(CGLGetShareGroup(kCGLContext)));
@@ -25,7 +29,11 @@ DBG_EXPORT JS_METHOD(platformWindow) { NAPI_ENV; THIS_WINDOW;
2529
#ifdef _WIN32
2630
RET_NUM(reinterpret_cast<uint64_t>(glfwGetWin32Window(window)));
2731
#elif __linux__
28-
RET_NUM(reinterpret_cast<uint64_t>(glfwGetX11Window(window)));
32+
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
33+
RET_NUM(reinterpret_cast<uint64_t>(glfwGetWaylandWindow(window)));
34+
} else {
35+
RET_NUM(reinterpret_cast<uint64_t>(glfwGetX11Window(window)));
36+
}
2937
#elif __APPLE__
3038
RET_NUM(reinterpret_cast<uint64_t>(glfwGetCocoaWindow(window)));
3139
#endif
@@ -36,10 +44,24 @@ DBG_EXPORT JS_METHOD(platformContext) { NAPI_ENV; THIS_WINDOW;
3644
#ifdef _WIN32
3745
RET_NUM(reinterpret_cast<uint64_t>(glfwGetWGLContext(window)));
3846
#elif __linux__
39-
RET_NUM(reinterpret_cast<uint64_t>(glfwGetGLXContext(window)));
47+
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
48+
RET_NUM(reinterpret_cast<uint64_t>(glfwGetEGLContext(window)));
49+
} else {
50+
RET_NUM(reinterpret_cast<uint64_t>(glfwGetGLXContext(window)));
51+
}
4052
#elif __APPLE__
4153
RET_NUM(reinterpret_cast<uint64_t>(glfwGetNSGLContext(window)));
4254
#endif
4355
}
4456

57+
58+
DBG_EXPORT JS_METHOD(getPlatform) { NAPI_ENV;
59+
RET_NUM(glfwGetPlatform());
60+
}
61+
62+
DBG_EXPORT JS_METHOD(platformSupported) { NAPI_ENV;
63+
REQ_INT_ARG(0, platform);
64+
RET_NUM(glfwPlatformSupported(platform));
65+
}
66+
4567
} // namespace glfw

src/cpp/glfw-platform.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#define GLFW_EXPOSE_NATIVE_NSGL
1313
#elif __linux__
1414
#define GLFW_EXPOSE_NATIVE_X11
15+
#define GLFW_EXPOSE_NATIVE_WAYLAND
1516
#define GLFW_EXPOSE_NATIVE_GLX
17+
#define GLFW_EXPOSE_NATIVE_EGL
1618
#endif
1719
#include <GLFW/glfw3native.h>
1820

@@ -21,6 +23,8 @@ namespace glfw {
2123
DBG_EXPORT JS_METHOD(platformDevice);
2224
DBG_EXPORT JS_METHOD(platformWindow);
2325
DBG_EXPORT JS_METHOD(platformContext);
26+
DBG_EXPORT JS_METHOD(getPlatform);
27+
DBG_EXPORT JS_METHOD(platformSupported);
2428
} // namespace glfw
2529

2630

src/cpp/glfw-window.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ DBG_EXPORT JS_METHOD(createWindow) { NAPI_ENV;
121121
std::cerr << "Error. Ignoring invalid monitor index: " << monitor_idx << "." << std::endl;
122122
}
123123
}
124+
125+
// WAYLAND fix - will not be needed after 3.5? See: https://github.com/glfw/glfw/issues/2518
126+
#ifdef __linux__
127+
if (glfwGetPlatform() == GLFW_PLATFORM_WAYLAND) {
128+
glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
129+
}
130+
#endif
124131

125132
if (!isNoApi && !_share) {
126133
glfwWindowHint(GLFW_VISIBLE, false);

0 commit comments

Comments
 (0)