X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;ds=sidebyside;f=source%2Fgraphics%2Fx11%2Fwindow.cpp;h=96d098551b561861254e65c2d1a59d6ba8ee0cdf;hb=HEAD;hp=2c03bf745570f7d2680257e30491e4fd56af2403;hpb=eb1a0ac27179962b8719a729c483549a9cca971a;p=libs%2Fgui.git diff --git a/source/graphics/x11/window.cpp b/source/graphics/x11/window.cpp index 2c03bf7..96d0985 100644 --- a/source/graphics/x11/window.cpp +++ b/source/graphics/x11/window.cpp @@ -1,10 +1,10 @@ +#include "window.h" +#include "window_private.h" #include #include #include #include #include "display_private.h" -#include "window.h" -#include "window_private.h" using namespace std; @@ -25,15 +25,24 @@ void Window::platform_init() DisplayHandle dpy = display.get_private().display; priv->wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", true); - priv->invisible_cursor = 0; XSetWindowAttributes attr; attr.override_redirect = options.fullscreen; - attr.event_mask = ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask|EnterWindowMask|ExposureMask; + attr.event_mask = ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask|EnterWindowMask|ExposureMask|FocusChangeMask; + + // User position is set when the window is mapped + int x = 0; + int y = 0; + if(options.fullscreen && !options.fullscreen_exclusive) + { + const Monitor::Settings &ms = options.fullscreen_monitor->current_settings; + x = ms.x; + y = ms.y; + } priv->window = XCreateWindow(dpy, display.get_private().root_window, - 0, 0, + x, y, options.width, options.height, 0, CopyFromParent, @@ -47,8 +56,8 @@ void Window::platform_init() { XSizeHints hints; hints.flags = PMinSize|PMaxSize; - hints.min_width=hints.max_width = options.width; - hints.min_height=hints.max_height = options.height; + hints.min_width = hints.max_width = options.width; + hints.min_height = hints.max_height = options.height; XSetWMNormalHints(dpy, priv->window, &hints); } } @@ -108,7 +117,17 @@ void Window::platform_reconfigure(bool fullscreen_changed) XSetWMNormalHints(dpy, priv->window, &hints); if(options.fullscreen) - XMoveResizeWindow(dpy, priv->window, 0, 0, options.width, options.height); + { + if(options.fullscreen_exclusive) + XMoveResizeWindow(dpy, priv->window, 0, 0, options.width, options.height); + else + { + const Monitor::Settings &ms = options.fullscreen_monitor->current_settings; + XMoveResizeWindow(dpy, priv->window, ms.x, ms.y, options.width, options.height); + } + } + else if(options.user_position) + XMoveResizeWindow(dpy, priv->window, options.x, options.y, options.width, options.height); else XResizeWindow(dpy, priv->window, options.width, options.height); @@ -129,7 +148,7 @@ void Window::show_cursor(bool s) int screen = DefaultScreen(dpy); Pixmap pm = XCreatePixmap(dpy, priv->window, 1, 1, 1); - GC gc = XCreateGC(dpy, pm, 0, 0); + GC gc = XCreateGC(dpy, pm, 0, nullptr); XSetFunction(dpy, gc, GXclear); XDrawPoint(dpy, pm, gc, 0, 0); XFreeGC(dpy, gc); @@ -157,7 +176,10 @@ void Window::platform_set_touch_input() void Window::platform_show() { - XMapRaised(display.get_private().display, priv->window); + DisplayHandle dpy = display.get_private().display; + XMapRaised(dpy, priv->window); + if(options.user_position && !options.fullscreen) + XMoveWindow(dpy, priv->window, options.x, options.y); } void Window::platform_hide() @@ -185,6 +207,47 @@ bool Window::event(const Event &evnt) resizing = false; signal_resize.emit(options.width, options.height); } + + { + int x = ev.xconfigure.x; + int y = ev.xconfigure.y; + + if(priv->reparented) + { + if(!ev.xconfigure.send_event) + { + /* If the window manager reparented us, the coordinates of a + real event are in the parent window's space. */ + priv->rel_x = ev.xconfigure.x; + priv->rel_y = ev.xconfigure.y; + + const Display::Private &dpy_priv = display.get_private(); + WindowHandle dummy; + XTranslateCoordinates(dpy_priv.display, priv->window, dpy_priv.root_window, 0, 0, &x, &y, &dummy); + } + + // Use the coordinates of the window manager frame + x -= priv->rel_x; + y -= priv->rel_y; + } + + if((x==options.x && y==options.y) == moving) + { + options.x = x; + options.y = y; + moving = false; + signal_move.emit(options.x, options.y); + } + } + + break; + case ReparentNotify: + priv->reparented = (ev.xreparent.parent!=display.get_private().root_window); + if(!priv->reparented) + { + priv->rel_x = 0; + priv->rel_y = 0; + } break; case ClientMessage: if(ev.xclient.data.l[0]==static_cast(priv->wm_delete_window)) @@ -195,12 +258,18 @@ bool Window::event(const Event &evnt) XSetInputFocus(display.get_private().display, priv->window, RevertToParent, CurrentTime); break; case MapNotify: - if(options.fullscreen) + if(options.fullscreen && options.fullscreen_exclusive) XGrabPointer(display.get_private().display, priv->window, true, None, GrabModeAsync, GrabModeAsync, priv->window, None, CurrentTime); break; case Expose: signal_expose.emit(ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, evnt); break; + case FocusIn: + signal_got_focus.emit(); + break; + case FocusOut: + signal_lost_focus.emit(); + break; default: return false; }