Skip to content

Commit 2b9f115

Browse files
authored
Merge pull request #1343 from catilac/1305-wayland
Wayland Support
2 parents b40adac + 01f8923 commit 2b9f115

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

core/src/processing/webgpu/PGraphicsWebGPU.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public PSurface createSurface() {
1111
return surface = new PSurfaceGLFW(this);
1212
}
1313

14-
protected void initWebGPUSurface(long windowHandle, int width, int height, float scaleFactor) {
15-
surfaceId = PWebGPU.createSurface(windowHandle, width, height, scaleFactor);
14+
protected void initWebGPUSurface(long windowHandle, long displayHandle, int width, int height, float scaleFactor) {
15+
surfaceId = PWebGPU.createSurface(windowHandle, displayHandle, width, height, scaleFactor);
1616
if (surfaceId == 0) {
1717
System.err.println("Failed to create WebGPU surface");
1818
}

core/src/processing/webgpu/PSurfaceGLFW.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
package processing.webgpu;
22

3-
import org.lwjgl.glfw.GLFW;
4-
import org.lwjgl.glfw.GLFWErrorCallback;
5-
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
6-
import org.lwjgl.glfw.GLFWNativeCocoa;
7-
import org.lwjgl.glfw.GLFWNativeWin32;
8-
import org.lwjgl.glfw.GLFWWindowPosCallback;
3+
import org.lwjgl.glfw.*;
94
import org.lwjgl.system.MemoryUtil;
105
import org.lwjgl.system.Platform;
116

@@ -30,6 +25,7 @@ public class PSurfaceGLFW implements PSurface {
3025
protected PGraphics graphics;
3126

3227
protected long window;
28+
protected long display;
3329
protected boolean running = false;
3430

3531
protected boolean paused;
@@ -78,6 +74,8 @@ public void initFrame(PApplet sketch) {
7874
throw new RuntimeException("Failed to create GLFW window");
7975
}
8076

77+
display = GLFW.glfwGetPrimaryMonitor();
78+
8179
windowCount.incrementAndGet();
8280

8381
// event callbacks
@@ -87,11 +85,12 @@ public void initFrame(PApplet sketch) {
8785
PWebGPU.init();
8886

8987
long windowHandle = getWindowHandle();
88+
long displayHandle = getDisplayHandle();
9089
int width = sketch.sketchWidth();
9190
int height = sketch.sketchHeight();
9291
float scaleFactor = sketch.sketchPixelDensity();
9392

94-
webgpu.initWebGPUSurface(windowHandle, width, height, scaleFactor);
93+
webgpu.initWebGPUSurface(windowHandle, displayHandle, width, height, scaleFactor);
9594
}
9695
}
9796

@@ -123,6 +122,24 @@ public long getWindowHandle() {
123122
return GLFWNativeCocoa.glfwGetCocoaWindow(window);
124123
} else if (Platform.get() == Platform.WINDOWS) {
125124
return GLFWNativeWin32.glfwGetWin32Window(window);
125+
} else if (Platform.get() == Platform.LINUX) {
126+
// TODO: need to check if x11 or wayland
127+
return GLFWNativeWayland.glfwGetWaylandWindow(window);
128+
} else {
129+
throw new UnsupportedOperationException("Window handle retrieval not implemented for this platform");
130+
}
131+
}
132+
133+
public long getDisplayHandle() {
134+
if (Platform.get() == Platform.MACOSX) {
135+
// TODO: Currently unsupported
136+
return 0;
137+
} else if (Platform.get() == Platform.WINDOWS) {
138+
// TODO: Currently unsupported
139+
return 0;
140+
} else if (Platform.get() == Platform.LINUX) {
141+
// TODO: need to check if x11 or wayland
142+
return GLFWNativeWayland.glfwGetWaylandDisplay();
126143
} else {
127144
throw new UnsupportedOperationException("Window handle retrieval not implemented for this platform");
128145
}

core/src/processing/webgpu/PWebGPU.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ public static void init() {
3838
* Creates a WebGPU surface from a native window handle.
3939
*
4040
* @param windowHandle The native window handle
41+
* @param displayHandle The native display handle
4142
* @param width Window width in physical pixels
4243
* @param height Window height in phsyical pixels
4344
* @param scaleFactor os provided scale factor
4445
* @return Window ID to use for subsequent operations
4546
*/
46-
public static long createSurface(long windowHandle, int width, int height, float scaleFactor) {
47-
long surfaceId = processing_create_surface(windowHandle, width, height, scaleFactor);
47+
public static long createSurface(long windowHandle, long displayHandle, int width, int height, float scaleFactor) {
48+
long surfaceId = processing_create_surface(windowHandle, displayHandle, width, height, scaleFactor);
4849
checkError();
4950
return surfaceId;
5051
}

0 commit comments

Comments
 (0)