add a close button
authorDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 19:01:51 +0000 (19:01 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 19:01:51 +0000 (19:01 +0000)
render2/test.c

index 4db87ff8033b3538d924e4135ed5c0cd92faa4ce..080b5d8d8e67b56668073f8279ae9794c1b49e42 100644 (file)
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <X11/Xlib.h>
+#include <X11/Xatom.h>
 #include <X11/extensions/shape.h>
 #include <string.h>
 #include <stdlib.h>
@@ -21,6 +22,8 @@ int main()
     struct RrInstance *inst;
     XEvent report;
     XClassHint chint;
+    Atom delete_win, protocols;
+    int quit;
 
     if (!(display = XOpenDisplay(NULL))) {
         fprintf(stderr, "couldn't connect to X server in DISPLAY\n");
@@ -41,6 +44,10 @@ int main()
     chint.res_class = "Rendertest";
     XSetClassHint(display, win, &chint);
 
+    delete_win = XInternAtom(display, "WM_DELETE_WINDOW", False);
+    protocols = XInternAtom(display, "WM_PROTOCOLS", False);
+    XSetWMProtocols(display, win, &delete_win, 1);
+
     /* init Render */
     if (!(inst = RrInit(display, DefaultScreen(display)))) {
         fprintf(stderr, "couldn't initialize the Render library "
@@ -49,9 +56,14 @@ int main()
     }
 
     /*paint(win, look);*/
-    while (1) {
+    quit = 0;
+    while (!quit) {
         XNextEvent(display, &report);
         switch (report.type) {
+        case ClientMessage:
+            if ((Atom)report.xclient.message_type == protocols)
+                if ((Atom)report.xclient.data.l[0] == delete_win)
+                    quit = 1;
         case Expose:
             break;
         case ConfigureNotify:
@@ -63,5 +75,7 @@ int main()
 
     }
 
+    RrDestroy(inst);
+
     return 1;
 }