~rabbits/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH] handle WM_DELETE_WINDOW

Details
Message ID
<20220327053803.3t235zw2qgkifagy@t480>
DKIM signature
pass
Download raw message
Patch: +13 -4
---
I'm not familiar with Xlib programming at all! This patch is an attempt
to get uxn11 to handle WM_DELETE_WINDOW, which is the ClientMessage sent
by a window manager when the user presses the 'X' button or similar.
There are probably better ways to do this.
More info: https://unix.stackexchange.com/a/491265
https://cboard.cprogramming.com/linux-programming/60466-xwindows-close-window-event.html#post429065

 src/uxn11.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/uxn11.c b/src/uxn11.c
index c2b1ebb..c7561c0 100644
--- a/src/uxn11.c
+++ b/src/uxn11.c
@@ -17,6 +17,7 @@
#include "devices/datetime.h"

static Device *devscreen, *devctrl, *devmouse;
static XImage *ximage;

static int
error(char *msg, const char *err)
@@ -72,11 +73,8 @@ load(Uxn *u, char *filepath)
void
redraw(Display *display, Visual *visual, Window window)
{
	XImage *ximage;
	screen_redraw(&uxn_screen, uxn_screen.pixels);
	ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width, uxn_screen.height, 32, 0);
	XPutImage(display, window, DefaultGC(display, 0), ximage, 0, 0, 0, 0, uxn_screen.width, uxn_screen.height);
	/* XDestroyImage(ximage); */
}

/* /usr/include/X11/keysymdef.h */
@@ -138,6 +136,13 @@ processEvent(Display *display, Visual *visual, Window window)
		XMotionEvent *e = (XMotionEvent *)&ev;
		mouse_pos(devmouse, e->x, e->y);
	} break;
	case ClientMessage: {
		XClientMessageEvent *e = (XClientMessageEvent *)&ev;
		XDestroyImage(ximage);
		XDestroyWindow(display, window);
		XCloseDisplay(display);
		exit(0);
	} break;
	}
	if(uxn_screen.fg.changed || uxn_screen.bg.changed) {
		redraw(display, visual, window);
@@ -194,11 +199,15 @@ main(int argc, char **argv)
	}

	XSelectInput(display, window, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask | KeyPressMask | KeyReleaseMask);
	Atom wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);
	XSetWMProtocols(display, window, &wmDelete, 1);
	XMapWindow(display, window);
	ximage = XCreateImage(display, visual, DefaultDepth(display, DefaultScreen(display)), ZPixmap, 0, (char *)uxn_screen.pixels, uxn_screen.width, uxn_screen.height, 32, 0);
	while(1) {
		processEvent(display, visual, window);
		uxn_eval(&u, GETVECTOR(devscreen));
		/* sleep(0.01); */
	}
	XDestroyImage(ximage);
	return 0;
}
\ No newline at end of file
}
-- 
2.35.1
Details
Message ID
<20220327053950.75ial3bzkfmh4y5i@t480>
In-Reply-To
<20220327053803.3t235zw2qgkifagy@t480> (view parent)
DKIM signature
pass
Download raw message
Apologies, I should have mentioned that this patch is for uxn11.
Reply to thread Export thread (mbox)