]> git.tdb.fi Git - libs/gui.git/blobdiff - source/window.cpp
React to resize and close events
[libs/gui.git] / source / window.cpp
index 75a88dce6f3331e82917ea161de7bc604a67b5e7..b977f6bc97ac89cbd7af1e81d02f125593f3de02 100644 (file)
@@ -6,14 +6,12 @@ Distributed under the LGPL
 */
 
 #include <vector>
-#include <GL/glx.h>
+#include <X11/Xutil.h>
 #include <msp/core/error.h>
 #include "window.h"
 
 using namespace std;
 
-#include <msp/strings/lexicalcast.h>
-
 namespace Msp {
 
 DisplayOptions::DisplayOptions():
@@ -90,18 +88,26 @@ void Window::prepare()
        if(!display)
                throw Exception("Couldn't open X display");
 
+       wm_delete_window=XInternAtom(display, "WM_DELETE_WINDOW", true);
+
        //XSetErrorHandler(x_error_handler);
 }
 
-void Window::init()
+void Window::create()
 {
-       prepare();
-
        window=XCreateWindow(display, DefaultRootWindow(display), 0, 0, options.width, options.height, 0, CopyFromParent, InputOutput, CopyFromParent, 0, 0);
        if(!window)
                throw Exception("Couldn't create a window");
 
        XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask);
+
+       XSetWMProtocols(display, window, &wm_delete_window, 1);
+}
+
+void Window::init()
+{
+       prepare();
+       create();
 }
 
 void Window::process_event(const XEvent &event)
@@ -131,6 +137,12 @@ void Window::process_event(const XEvent &event)
        case ConfigureNotify:
                options.width=event.xconfigure.width;
                options.height=event.xconfigure.height;
+               on_resize();
+               signal_resize.emit(options.width, options.height);
+               break;
+       case ClientMessage:
+               if(event.xclient.data.l[0]==static_cast<long>(wm_delete_window))
+                       signal_close.emit();
                break;
        default:;
        }