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