X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcontrib%2Flibqxt-2007-10-24%2Fsrc%2Fgui%2Fqxtdesktopwidget_x11.cpp;fp=src%2Fcontrib%2Flibqxt-2007-10-24%2Fsrc%2Fgui%2Fqxtdesktopwidget_x11.cpp;h=aa979009c85922dad85b0a6e4c1f03ec1cb60165;hp=0000000000000000000000000000000000000000;hb=a634acadbcf6017474f68a3eaf7cb632660e9e49;hpb=cd122ca8e0d2c0ffc5397e0a813c75d791a7e6e3 diff --git a/src/contrib/libqxt-2007-10-24/src/gui/qxtdesktopwidget_x11.cpp b/src/contrib/libqxt-2007-10-24/src/gui/qxtdesktopwidget_x11.cpp new file mode 100644 index 00000000..aa979009 --- /dev/null +++ b/src/contrib/libqxt-2007-10-24/src/gui/qxtdesktopwidget_x11.cpp @@ -0,0 +1,140 @@ +/**************************************************************************** +** +** Copyright (C) Qxt Foundation. Some rights reserved. +** +** This file is part of the QxtGui module of the Qt eXTension library +** +** This library is free software; you can redistribute it and/or modify it +** under the terms of th Common Public License, version 1.0, as published by +** IBM. +** +** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY +** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY +** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR +** FITNESS FOR A PARTICULAR PURPOSE. +** +** You should have received a copy of the CPL along with this file. +** See the LICENSE file and the cpl1.0.txt file included with the source +** distribution for more information. If you did not receive a copy of the +** license, contact the Qxt Foundation. +** +** +** +****************************************************************************/ +#include "qxtdesktopwidget.h" +#include +#include + +static void qxt_getWindowProperty(Window wid, Atom prop, int maxlen, Window** data, int* count) +{ + Atom type = 0; + int format = 0; + unsigned long after = 0; + XGetWindowProperty(QX11Info::display(), wid, prop, 0, maxlen / 4, False, AnyPropertyType, + &type, &format, (unsigned long*) count, &after, (unsigned char**) data); +} + +static QRect qxt_getWindowRect(Window wid) +{ + QRect rect; + XWindowAttributes attr; + if (XGetWindowAttributes(QX11Info::display(), wid, &attr)) + { + rect = QRect(attr.x, attr.y, attr.width, attr.height); + } + return rect; +} + +WindowList QxtDesktopWidget::windows() +{ + static Atom net_clients = 0; + if (!net_clients) + net_clients = XInternAtom(QX11Info::display(), "_NET_CLIENT_LIST_STACKING", True); + + int count = 0; + Window* list = 0; + qxt_getWindowProperty(QX11Info::appRootWindow(), net_clients, 1024 * sizeof(Window), &list, &count); + + WindowList res; + for (int i = 0; i < count; ++i) + res += list[i]; + XFree(list); + return res; +} + +WId QxtDesktopWidget::activeWindow() +{ + Window focus; + int revert = 0; + Display* display = QX11Info::display(); + XGetInputFocus(display, &focus, &revert); + return focus; +} + +WId QxtDesktopWidget::findWindow(const QString& title) +{ + Window result = 0; + WindowList list = windows(); + foreach (Window wid, list) + { + if (windowTitle(wid) == title) + { + result = wid; + break; + } + } + return result; +} + +WId QxtDesktopWidget::windowAt(const QPoint& pos) +{ + Window result = 0; + WindowList list = windows(); + for (int i = list.size() - 1; i >= 0; --i) + { + WId wid = list.at(i); + if (windowGeometry(wid).contains(pos)) + { + result = wid; + break; + } + } + return result; +} + +QString QxtDesktopWidget::windowTitle(WId window) +{ + QString name; + char* str = 0; + if (XFetchName(QX11Info::display(), window, &str)) + { + name = QString::fromLatin1(str); + } + XFree(str); + return name; +} + +QRect QxtDesktopWidget::windowGeometry(WId window) +{ + QRect rect = qxt_getWindowRect(window); + + Window root = 0; + Window parent = 0; + Window* children = 0; + unsigned int count = 0; + Display* display = QX11Info::display(); + if (XQueryTree(display, window, &root, &parent, &children, &count)) + { + window = parent; // exclude decoration + XFree(children); + while (window != 0 && XQueryTree(display, window, &root, &parent, &children, &count)) + { + XWindowAttributes attr; + if (parent != 0 && XGetWindowAttributes(display, parent, &attr)) + rect.translate(QRect(attr.x, attr.y, attr.width, attr.height).topLeft()); + window = parent; + XFree(children); + } + } + return rect; +}