45
45
# include <Metal/Metal.h>
46
46
#elif defined(SDL_PLATFORM_WIN32 )
47
47
# include <windows.h>
48
+ #elif defined(SDL_VIDEO_DRIVER_X11 )
49
+ # include <X11/Xlib.h>
50
+ #elif defined(SDL_VIDEO_DRIVER_WAYLAND )
51
+ # include <wayland-client-core.h>
48
52
#endif
49
53
50
54
#include <SDL3/SDL.h>
@@ -55,8 +59,8 @@ WGPUSurface SDL_GetWGPUSurface(WGPUInstance instance, SDL_Window* window) {
55
59
#if defined(SDL_PLATFORM_MACOS )
56
60
{
57
61
id metal_layer = NULL ;
58
- NSWindow * nswindow = (__bridge NSWindow * )SDL_GetPointerProperty (props , SDL_PROP_WINDOW_COCOA_WINDOW_POINTER , NULL );
59
- if (!nswindow ) return NULL ;
62
+ NSWindow * ns_window = (__bridge NSWindow * )SDL_GetPointerProperty (props , SDL_PROP_WINDOW_COCOA_WINDOW_POINTER , NULL );
63
+ if (!ns_window ) return NULL ;
60
64
[ns_window .contentView setWantsLayer : YES ];
61
65
metal_layer = [CAMetalLayer layer ];
62
66
[ns_window .contentView setLayer : metal_layer ];
@@ -107,18 +111,19 @@ WGPUSurface SDL_GetWGPUSurface(WGPUInstance instance, SDL_Window* window) {
107
111
return wgpuInstanceCreateSurface (instance , & surfaceDescriptor );
108
112
}
109
113
#elif defined(SDL_PLATFORM_LINUX )
114
+ # if defined(SDL_VIDEO_DRIVER_X11 )
110
115
if (SDL_strcmp (SDL_GetCurrentVideoDriver (), "x11" ) == 0 ) {
111
116
Display * x11_display = (Display * )SDL_GetPointerProperty (props , SDL_PROP_WINDOW_X11_DISPLAY_POINTER , NULL );
112
117
Window x11_window = (Window )SDL_GetNumberProperty (props , SDL_PROP_WINDOW_X11_WINDOW_NUMBER , 0 );
113
118
if (!x11_display || !x11_window ) return NULL ;
114
119
115
- # ifdef WEBGPU_BACKEND_DAWN
120
+ # ifdef WEBGPU_BACKEND_DAWN
116
121
WGPUSurfaceSourceXlibWindow fromXlibWindow ;
117
122
fromXlibWindow .chain .sType = WGPUSType_SurfaceSourceXlibWindow ;
118
- # else
123
+ # else
119
124
WGPUSurfaceDescriptorFromXlibWindow fromXlibWindow ;
120
125
fromXlibWindow .chain .sType = WGPUSType_SurfaceDescriptorFromXlibWindow ;
121
- # endif
126
+ # endif
122
127
fromXlibWindow .chain .next = NULL ;
123
128
fromXlibWindow .display = x11_display ;
124
129
fromXlibWindow .window = x11_window ;
@@ -129,18 +134,20 @@ WGPUSurface SDL_GetWGPUSurface(WGPUInstance instance, SDL_Window* window) {
129
134
130
135
return wgpuInstanceCreateSurface (instance , & surfaceDescriptor );
131
136
}
137
+ # endif // defined(SDL_VIDEO_DRIVER_X11)
138
+ # if defined(SDL_VIDEO_DRIVER_WAYLAND )
132
139
else if (SDL_strcmp (SDL_GetCurrentVideoDriver (), "wayland ") == 0 ) {
133
140
struct wl_display * wayland_display = (struct wl_display * )SDL_GetPointerProperty (props , SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER , NULL );
134
141
struct wl_surface * wayland_surface = (struct wl_surface * )SDL_GetPointerProperty (props , SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER , NULL );
135
142
if (!wayland_display || !wayland_surface ) return NULL ;
136
143
137
- # ifdef WEBGPU_BACKEND_DAWN
144
+ # ifdef WEBGPU_BACKEND_DAWN
138
145
WGPUSurfaceSourceWaylandSurface fromWaylandSurface ;
139
146
fromWaylandSurface .chain .sType = WGPUSType_SurfaceSourceWaylandSurface ;
140
- # else
147
+ # else
141
148
WGPUSurfaceDescriptorFromWaylandSurface fromWaylandSurface ;
142
149
fromWaylandSurface .chain .sType = WGPUSType_SurfaceDescriptorFromWaylandSurface ;
143
- # endif
150
+ # endif
144
151
fromWaylandSurface .chain .next = NULL;
145
152
fromWaylandSurface .display = wayland_display ;
146
153
fromWaylandSurface .surface = wayland_surface ;
@@ -151,6 +158,7 @@ WGPUSurface SDL_GetWGPUSurface(WGPUInstance instance, SDL_Window* window) {
151
158
152
159
return wgpuInstanceCreateSurface (instance , & surfaceDescriptor );
153
160
}
161
+ # endif // defined(SDL_VIDEO_DRIVER_WAYLAND)
154
162
#elif defined(SDL_PLATFORM_WIN32 )
155
163
{
156
164
HWND hwnd = (HWND )SDL_GetPointerProperty (props , SDL_PROP_WINDOW_WIN32_HWND_POINTER , NULL );
0 commit comments