1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtGui module of the Qt eXTension library
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
21 ** <http://libqxt.sourceforge.net> <foundation@libqxt.org>
23 ****************************************************************************/
24 #include "qxtdesktopwidget.h"
26 #include <X11/Xutil.h>
28 static void qxt_getWindowProperty(Window wid, Atom prop, int maxlen, Window** data, int* count)
32 unsigned long after = 0;
33 XGetWindowProperty(QX11Info::display(), wid, prop, 0, maxlen / 4, False, AnyPropertyType,
34 &type, &format, (unsigned long*) count, &after, (unsigned char**) data);
37 static QRect qxt_getWindowRect(Window wid)
40 XWindowAttributes attr;
41 if (XGetWindowAttributes(QX11Info::display(), wid, &attr))
43 rect = QRect(attr.x, attr.y, attr.width, attr.height);
48 WindowList QxtDesktopWidget::windows()
50 static Atom net_clients = 0;
52 net_clients = XInternAtom(QX11Info::display(), "_NET_CLIENT_LIST_STACKING", True);
56 qxt_getWindowProperty(QX11Info::appRootWindow(), net_clients, 1024 * sizeof(Window), &list, &count);
59 for (int i = 0; i < count; ++i)
65 WId QxtDesktopWidget::activeWindow()
69 Display* display = QX11Info::display();
70 XGetInputFocus(display, &focus, &revert);
74 WId QxtDesktopWidget::findWindow(const QString& title)
77 WindowList list = windows();
78 foreach (Window wid, list)
80 if (windowTitle(wid) == title)
89 WId QxtDesktopWidget::windowAt(const QPoint& pos)
92 WindowList list = windows();
93 for (int i = list.size() - 1; i >= 0; --i)
96 if (windowGeometry(wid).contains(pos))
105 QString QxtDesktopWidget::windowTitle(WId window)
109 if (XFetchName(QX11Info::display(), window, &str))
111 name = QString::fromLatin1(str);
117 QRect QxtDesktopWidget::windowGeometry(WId window)
119 QRect rect = qxt_getWindowRect(window);
123 Window* children = 0;
124 unsigned int count = 0;
125 Display* display = QX11Info::display();
126 if (XQueryTree(display, window, &root, &parent, &children, &count))
128 window = parent; // exclude decoration
130 while (window != 0 && XQueryTree(display, window, &root, &parent, &children, &count))
132 XWindowAttributes attr;
133 if (parent != 0 && XGetWindowAttributes(display, parent, &attr))
134 rect.translate(QRect(attr.x, attr.y, attr.width, attr.height).topLeft());