summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkkard2 <[email protected]>2025-09-24 15:18:56 +0200
committerkkard2 <[email protected]>2025-09-24 15:18:56 +0200
commit83413173c00e0387fbf05cc3d764fcd6a43bf991 (patch)
treeed9b74aaa0dbfc29a02ec6d22247403f844b0b50
parentbcfd31ce9ea9ea067b285a78eb747e3d68561bca (diff)
fix BadDrawable on x11 termination
-rw-r--r--.gitignore1
-rw-r--r--examples/platform/platform_x11.c21
2 files changed, 15 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 8ad6369..17166a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
*.ilk
*.pdb
*.rdi
+example
diff --git a/examples/platform/platform_x11.c b/examples/platform/platform_x11.c
index 3136e51..70a827e 100644
--- a/examples/platform/platform_x11.c
+++ b/examples/platform/platform_x11.c
@@ -91,6 +91,9 @@ int main() {
BlackPixel(dpy, screen)
);
+ Atom atom_wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
+ XSetWMProtocols(dpy, win, &atom_wm_delete_window, 1);
+
XStoreName(dpy, win, "sponge");
XSelectInput(dpy, win, ExposureMask | PointerMotionMask | StructureNotifyMask);
@@ -103,6 +106,12 @@ int main() {
int running = 1;
while (running) {
+ if (sponge_texture_valid(canvas)) {
+ draw_frame_3d(canvas, depths);
+ XPutImage(dpy, win, gc, ximg, 0, 0, 0, 0, canvas.width, canvas.height);
+ usleep(16000);
+ }
+
while (XPending(dpy)) {
XEvent ev;
XNextEvent(dpy, &ev);
@@ -116,15 +125,13 @@ int main() {
case MotionNotify:
mouse_move(ev.xmotion.x, ev.xmotion.y);
break;
+ case ClientMessage:
+ if ((Atom)ev.xclient.data.l[0] == atom_wm_delete_window) {
+ running = 0;
+ }
+ break;
}
}
-
- if (sponge_texture_valid(canvas)) {
- draw_frame_3d(canvas, depths);
- XPutImage(dpy, win, gc, ximg, 0, 0, 0, 0, canvas.width, canvas.height);
- }
-
- usleep(16000);
}
if (ximg) {