Skip to content

Commit f5f5add

Browse files
ziga-lunargcharles-lunarg
authored andcommitted
cube: Fix xlib window close
XSetVMProtocols is needed to register WM_DELETE_WINDOW. Without this the window close event was never received. The window was still destroyed and vkAcquireNextImageKHR returned VK_ERROR_SURFACE_LOST_KHR
1 parent 95cfb8b commit f5f5add

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

cube/cube.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,6 +2854,7 @@ static void demo_create_xlib_window(struct demo *demo) {
28542854
XMapWindow(demo->xlib_display, demo->xlib_window);
28552855
XFlush(demo->xlib_display);
28562856
demo->xlib_wm_delete_window = XInternAtom(demo->xlib_display, "WM_DELETE_WINDOW", False);
2857+
XSetWMProtocols(demo->xlib_display, demo->xlib_window, &demo->xlib_wm_delete_window, 1);
28572858
}
28582859
static void demo_handle_xlib_event(struct demo *demo, const XEvent *event) {
28592860
switch (event->type) {

cube/cube.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,6 +3224,7 @@ void Demo::create_window<WsiPlatform::xlib>() {
32243224
XMapWindow(xlib_display, xlib_window);
32253225
XFlush(xlib_display);
32263226
xlib_wm_delete_window = XInternAtom(xlib_display, "WM_DELETE_WINDOW", False);
3227+
XSetWMProtocols(xlib_display, xlib_window, &xlib_wm_delete_window, 1);
32273228
}
32283229

32293230
void Demo::handle_xlib_event(const XEvent *event) {

cube/xlib_loader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef int (*PFN_XCloseDisplay)(Display* /* display */
4141
typedef Status (*PFN_XInitThreads)(void);
4242
typedef int (*PFN_XFlush)(Display* /* display */
4343
);
44+
typedef Status (*PFN_XSetWMProtocols)(Display*, Window, Atom*, int);
4445

4546
static PFN_XDestroyWindow cube_XDestroyWindow = NULL;
4647
static PFN_XOpenDisplay cube_XOpenDisplay = NULL;
@@ -55,6 +56,7 @@ static PFN_XGetVisualInfo cube_XGetVisualInfo = NULL;
5556
static PFN_XCloseDisplay cube_XCloseDisplay = NULL;
5657
static PFN_XInitThreads cube_XInitThreads = NULL;
5758
static PFN_XFlush cube_XFlush = NULL;
59+
static PFN_XSetWMProtocols cube_XSetWMProtocols = NULL;
5860

5961
#define XDestroyWindow cube_XDestroyWindow
6062
#define XOpenDisplay cube_XOpenDisplay
@@ -69,6 +71,7 @@ static PFN_XFlush cube_XFlush = NULL;
6971
#define XCloseDisplay cube_XCloseDisplay
7072
#define XInitThreads cube_XInitThreads
7173
#define XFlush cube_XFlush
74+
#define XSetWMProtocols cube_XSetWMProtocols
7275

7376
void* initialize_xlib() {
7477
void* xlib_library = NULL;
@@ -101,6 +104,7 @@ void* initialize_xlib() {
101104
cube_XCloseDisplay = TYPE_CONVERSION(PFN_XCloseDisplay)(dlsym(xlib_library, "XCloseDisplay"));
102105
cube_XInitThreads = TYPE_CONVERSION(PFN_XInitThreads)(dlsym(xlib_library, "XInitThreads"));
103106
cube_XFlush = TYPE_CONVERSION(PFN_XFlush)(dlsym(xlib_library, "XFlush"));
107+
cube_XSetWMProtocols = TYPE_CONVERSION(PFN_XSetWMProtocols)(dlsym(xlib_library, "XSetWMProtocols"));
104108

105109
return xlib_library;
106110
}

0 commit comments

Comments
 (0)