]> git.tdb.fi Git - libs/gui.git/blobdiff - source/window.cpp
Set override_redirect attribute when fullscreen is requested
[libs/gui.git] / source / window.cpp
index b977f6bc97ac89cbd7af1e81d02f125593f3de02..ee5bec90d93f6165c742e13316fca7d621d79d10 100644 (file)
@@ -6,8 +6,9 @@ Distributed under the LGPL
 */
 
 #include <vector>
+#include <X11/Xatom.h>
 #include <X11/Xutil.h>
-#include <msp/core/error.h>
+#include <msp/core/except.h>
 #include "window.h"
 
 using namespace std;
@@ -52,6 +53,17 @@ Window::~Window()
                XCloseDisplay(display);
 }
 
+void Window::set_title(const string &title)
+{
+       vector<unsigned char> buf(title.begin(), title.end());
+       XTextProperty prop;
+       prop.value=&buf[0];
+       prop.encoding=XA_STRING;
+       prop.format=8;
+       prop.nitems=title.size();
+       XSetWMName(display, window, &prop);
+}
+
 void Window::show()
 {
        XMapRaised(display, window);
@@ -90,16 +102,17 @@ void Window::prepare()
 
        wm_delete_window=XInternAtom(display, "WM_DELETE_WINDOW", true);
 
+       /* Throwing from the error handler doesn't work too well and I don't know
+          how to dig up all the information that Xlib gives by default, so disable
+               custom error handling for now. */
        //XSetErrorHandler(x_error_handler);
 }
 
-void Window::create()
+void Window::set_window(Handle wnd)
 {
-       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");
+       window=wnd;
 
-       XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask);
+       XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask|EnterWindowMask);
 
        XSetWMProtocols(display, window, &wm_delete_window, 1);
 }
@@ -107,7 +120,12 @@ void Window::create()
 void Window::init()
 {
        prepare();
-       create();
+
+       XSetWindowAttributes attr;
+       attr.override_redirect=options.fullscreen;
+
+       Handle wnd=XCreateWindow(display, DefaultRootWindow(display), 0, 0, options.width, options.height, 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect, &attr);
+       set_window(wnd);
 }
 
 void Window::process_event(const XEvent &event)
@@ -137,15 +155,19 @@ 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;
+       case EnterNotify:
+               XSetInputFocus(display, window, RevertToParent, CurrentTime);
+               break;
        default:;
        }
+
+       on_event(event);
 }
 
 int Window::x_error_handler(Display *display, XErrorEvent *error)