X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fwindow.cpp;h=3de9ba7f33894ba1c5c07d1f71a73d7faf1a51eb;hb=eb9a95ca4acbbdbc6c17acd6b8a135deab906f39;hp=75a88dce6f3331e82917ea161de7bc604a67b5e7;hpb=1fbd1b60d9fffe40febe499315347762da007269;p=libs%2Fgui.git diff --git a/source/window.cpp b/source/window.cpp index 75a88dc..3de9ba7 100644 --- a/source/window.cpp +++ b/source/window.cpp @@ -6,14 +6,13 @@ Distributed under the LGPL */ #include -#include +#include +#include #include #include "window.h" using namespace std; -#include - namespace Msp { DisplayOptions::DisplayOptions(): @@ -54,6 +53,17 @@ Window::~Window() XCloseDisplay(display); } +void Window::set_title(const string &title) +{ + 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, window, &prop); +} + void Window::show() { XMapRaised(display, window); @@ -90,18 +100,29 @@ void Window::prepare() if(!display) throw Exception("Couldn't open X display"); + 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::set_window(Handle wnd) +{ + window=wnd; + + XSelectInput(display, window, ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask); + + XSetWMProtocols(display, window, &wm_delete_window, 1); +} + void Window::init() { 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); + Handle wnd=XCreateWindow(display, DefaultRootWindow(display), 0, 0, options.width, options.height, 0, CopyFromParent, InputOutput, CopyFromParent, 0, 0); + set_window(wnd); } void Window::process_event(const XEvent &event) @@ -131,9 +152,16 @@ void Window::process_event(const XEvent &event) case ConfigureNotify: options.width=event.xconfigure.width; options.height=event.xconfigure.height; + signal_resize.emit(options.width, options.height); + break; + case ClientMessage: + if(event.xclient.data.l[0]==static_cast(wm_delete_window)) + signal_close.emit(); break; default:; } + + on_event(event); } int Window::x_error_handler(Display *display, XErrorEvent *error)