From b36b242f1236c907ae3b14b0dc35ed27e5882d6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 25 Apr 2014 12:09:11 +0200 Subject: [PATCH] Port Unmanaged::track to XCB Uses Xcb::WindowAttributes and Xcb::WindowGeometry instead of XLib variant. In addition it uses the XServerGrabber to ensure that the xserver grab is removed in all code paths. A new macro is added to utils.h to make the grabbing of XServer in current context more obvious. --- unmanaged.cpp | 24 +++++++++++++----------- utils.h | 4 ++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/unmanaged.cpp b/unmanaged.cpp index 21eb8da44e..642713af3b 100644 --- a/unmanaged.cpp +++ b/unmanaged.cpp @@ -23,6 +23,7 @@ along with this program. If not, see . #include "workspace.h" #include "effects.h" #include "deleted.h" +#include "utils.h" #include "xcbutils.h" #include @@ -48,22 +49,24 @@ Unmanaged::~Unmanaged() bool Unmanaged::track(Window w) { - XWindowAttributes attr; - grabXServer(); - if (!XGetWindowAttributes(display(), w, &attr) || attr.map_state != IsViewable) { - ungrabXServer(); + GRAB_SERVER_DURING_CONTEXT + Xcb::WindowAttributes attr(w); + Xcb::WindowGeometry geo(w); + if (attr.isNull() || attr->map_state != XCB_MAP_STATE_VIEWABLE) { return false; } - if (attr.c_class == InputOnly) { - ungrabXServer(); + if (attr->_class == XCB_WINDOW_CLASS_INPUT_ONLY) { + return false; + } + if (geo.isNull()) { return false; } setWindowHandles(w); // the window is also the frame - Xcb::selectInput(w, attr.your_event_mask | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE); - geom = QRect(attr.x, attr.y, attr.width, attr.height); + Xcb::selectInput(w, attr->your_event_mask | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_PROPERTY_CHANGE); + geom = geo.rect(); checkScreen(); - m_visual = attr.visual->visualid; - bit_depth = attr.depth; + m_visual = attr->visual; + bit_depth = geo->depth; info = new NETWinInfo(connection(), w, rootWindow(), NET::WMWindowType | NET::WMPid, NET::WM2Opacity | @@ -78,7 +81,6 @@ bool Unmanaged::track(Window w) getWmOpaqueRegion(); getSkipCloseAnimation(); setupCompositing(); - ungrabXServer(); if (effects) static_cast(effects)->checkInputWindowStacking(); return true; diff --git a/utils.h b/utils.h index e96adbfeb4..466d3b96ba 100644 --- a/utils.h +++ b/utils.h @@ -133,6 +133,8 @@ void ungrabXKeyboard(); * Small helper class which performs @link grabXServer in the ctor and * @link ungrabXServer in the dtor. Use this class to ensure that grab and * ungrab are matched. + * + * To simplify usage consider using the macro GRAB_SERVER_DURING_CONTEXT **/ class XServerGrabber { @@ -145,6 +147,8 @@ public: } }; +#define GRAB_SERVER_DURING_CONTEXT XServerGrabber xserverGrabber; + // the docs say it's UrgencyHint, but it's often #defined as XUrgencyHint #ifndef UrgencyHint #define UrgencyHint XUrgencyHint