Bug 691598 - [PATCH] Handle WM_DELETE_WINDOW ClientMessage.
Summary: [PATCH] Handle WM_DELETE_WINDOW ClientMessage.
Status: RESOLVED WONTFIX
Alias: None
Product: MuPDF
Classification: Unclassified
Component: apps (show other bugs)
Version: unspecified
Hardware: PC Linux
: P4 normal
Assignee: Tor Andersson
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-07 03:42 UTC by Graham Gower
Modified: 2010-09-08 11:37 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Graham Gower 2010-09-07 03:42:15 UTC
Various ICCCM compliant window managers require an application to take action upon WM_DELETE_WINDOW in order to exit when the 'X' in the upper right corner is clicked. At least openbox and fvwm perform no action without this patch and the 'q' key must be used to close mupdf.

http://tronche.com/gui/x/icccm/sec-4.html#s-4.2.8.1

diff --git a/apps/x11_main.c b/apps/x11_main.c
index 395f9fd..bd8add7 100644
--- a/apps/x11_main.c
+++ b/apps/x11_main.c
@@ -51,6 +51,8 @@ static Display *xdpy;
 static Atom XA_TARGETS;
 static Atom XA_TIMESTAMP;
 static Atom XA_UTF8_STRING;
+static Atom XA_WM_DELETE_WINDOW;
+static Atom XA_WM_PROTOCOLS;
 static int x11fd;
 static int xscr;
 static Window xwin;
@@ -113,6 +115,8 @@ static void winopen(void)
 	XA_TARGETS = XInternAtom(xdpy, "TARGETS", False);
 	XA_TIMESTAMP = XInternAtom(xdpy, "TIMESTAMP", False);
 	XA_UTF8_STRING = XInternAtom(xdpy, "UTF8_STRING", False);
+	XA_WM_DELETE_WINDOW = XInternAtom(xdpy, "WM_DELETE_WINDOW", False);
+	XA_WM_PROTOCOLS = XInternAtom(xdpy, "WM_PROTOCOLS", False);
 
 	xscr = DefaultScreen(xdpy);
 
@@ -147,6 +151,8 @@ static void winopen(void)
 	XSelectInput(xdpy, xwin,
 		StructureNotifyMask | ExposureMask | KeyPressMask |
 		PointerMotionMask | ButtonPressMask | ButtonReleaseMask);
+	
+	XSetWMProtocols(xdpy, xwin, &XA_WM_DELETE_WINDOW, 1);
 
 	mapped = 0;
 
@@ -544,6 +550,7 @@ int main(int argc, char **argv)
 	int len;
 	char buf[128];
 	KeySym keysym;
+	XClientMessageEvent *cmev;
 	int oldx = 0;
 	int oldy = 0;
 	int resolution = 72;
@@ -619,6 +626,13 @@ int main(int argc, char **argv)
 				dirty = 1;
 				break;
 
+			case ClientMessage:
+				cmev = (XClientMessageEvent *)&xevt;
+				if (cmev->message_type == XA_WM_PROTOCOLS &&
+					cmev->data.l[0] == XA_WM_DELETE_WINDOW)
+					closing = 1;
+				break;
+
 			case ConfigureNotify:
 				if (gapp.image)
 				{
Comment 1 Graham Gower 2010-09-08 04:48:07 UTC
My description of the bug is incorrect and the lack of being able to close mupdf stemmed from a misconfiguration in fvwm-themes default theme, whereby the Delete signal was being sent instead of the Close signal. Feel free to handle the WM_DELTE_WINDOW message or not, at your discretion.

I have further tested with openbox again and problems persist. This is likely an unrelated (non mupdf) problem.
Comment 2 Tor Andersson 2010-09-08 11:37:45 UTC
The usual use for WM_DELETE_WINDOW is for applications to do a clean shutdown, or ignore the command (by popping up a confirmation dialog, for instance). If the client does not respond to WM_DELETE_WINDOW, window managers are supposed to simply kill the process (which is good enough for us).