X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fwindow.cpp;h=224195605225f16a33427cec2762e3f77f690cb1;hb=7c7c2cdce368b09b8b07bab860874440c7bc3c14;hp=b977f6bc97ac89cbd7af1e81d02f125593f3de02;hpb=935c50bdcc95fe95d39931182461a2b25ac30b9d;p=libs%2Fgui.git diff --git a/source/window.cpp b/source/window.cpp index b977f6b..2241956 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -6,40 +6,38 @@ Distributed under the LGPL */ #include +#include #include -#include +#include +#include "display.h" #include "window.h" using namespace std; namespace Msp { +namespace Graphics { -DisplayOptions::DisplayOptions(): +WindowOptions::WindowOptions(): width(640), height(480), - fullscreen(false) + fullscreen(false), + resizable(false) { } -/** -Initializes the class but does not open the window. Intended for use by -derived classes. -*/ -Window::Window(): - display(0), - window(0) -{ } - -Window::Window(unsigned w, unsigned h) +Window::Window(Display &dpy, unsigned w, unsigned h, bool fs): + display(dpy) { options.width=w; options.height=h; + options.fullscreen=fs; init(); } -Window::Window(const DisplayOptions &dopt): - options(dopt) +Window::Window(Display &dpy, const WindowOptions &opts): + display(dpy), + options(opts) { init(); } @@ -47,115 +45,105 @@ Window::Window(const DisplayOptions &dopt): Window::~Window() { if(window) - XDestroyWindow(display, window); - if(display) - XCloseDisplay(display); + XDestroyWindow(display.get_display(), window); + + display.remove_window(this); + + if(options.fullscreen) + display.restore_mode(); } -void Window::show() +void Window::set_title(const string &title) { - XMapRaised(display, window); + vector buf(title.begin(), title.end()); + XTextProperty prop; + prop.value=&buf[0]; + prop.encoding=XA_STRING; + prop.format=8; + prop.nitems=title.size(); + XSetWMName(display.get_display(), window, &prop); + display.check_error(); } -void Window::hide() +void Window::show() { - XUnmapWindow(display, window); + XMapRaised(display.get_display(), window); + display.check_error(); } -void Window::tick() +void Window::hide() { - while(1) - { - int pending=XPending(display); - if(pending==0) - break; - - for(int i=0; i(&event.xkey), buf, sizeof(buf), 0, 0); + XLookupString(const_cast(&ev.xkey), buf, sizeof(buf), 0, 0); // XXX Handle the result according to locale - signal_key_press.emit(event.xkey.keycode, event.xkey.state, buf[0]); + signal_key_press.emit(ev.xkey.keycode, ev.xkey.state, buf[0]); } break; case KeyRelease: - signal_key_release.emit(event.xkey.keycode, event.xkey.state); + signal_key_release.emit(ev.xkey.keycode, ev.xkey.state); break; case ConfigureNotify: - options.width=event.xconfigure.width; - options.height=event.xconfigure.height; - on_resize(); + options.width=ev.xconfigure.width; + options.height=ev.xconfigure.height; signal_resize.emit(options.width, options.height); break; case ClientMessage: - if(event.xclient.data.l[0]==static_cast(wm_delete_window)) + if(ev.xclient.data.l[0]==static_cast(wm_delete_window)) signal_close.emit(); break; + case EnterNotify: + XSetInputFocus(display.get_display(), window, RevertToParent, CurrentTime); + break; + case MapNotify: + if(options.fullscreen) + XGrabPointer(display.get_display(), window, true, None, GrabModeAsync, GrabModeAsync, window, None, CurrentTime); + break; default:; } } -int Window::x_error_handler(Display *display, XErrorEvent *error) -{ - char buf[128]; - XGetErrorText(display, error->error_code, buf, sizeof(buf)); - /*string request_code=lexical_cast(error->request_code); - char buf2[1024]; - XGetErrorDatabaseText(display, "XRequest", request_code.c_str(), buf, buf2, sizeof(buf2));*/ - throw Exception(buf); -} - +} // namespace Graphics } // namespace Msp