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"
25 #include <QStringList>
28 \class QxtDesktopWidget QxtDesktopWidget
30 \brief QxtDesktopWidget provides means for accessing native windows.
32 \note QxtDesktopWidget is portable in principle, but be careful while
33 using it since you are probably about to do something non-portable.
35 <P>Advanced example usage:
37 class NativeWindow : public QWidget {
39 NativeWindow(WId wid) {
40 QWidget::create(wid, false, false); // window, initializeWindow, destroyOldWindow
43 QWidget::destroy(false, false); // destroyWindow, destroySubWindows
49 WindowList windows = QxtDesktopWidget::windows();
50 QStringList titles = QxtDesktopWidget::windowTitles();
52 QString title = QInputDialog::getItem(0, "Choose Window", "Choose a window to be hid:", titles, 0, false, &ok);
55 int index = titles.indexOf(title);
58 NativeWindow window(windows.at(index));
64 \note Currently supported platforms are \b X11 and \b Windows.
68 \fn QxtDesktopWidget::windows()
70 Returns the list of native window system identifiers.
72 \note The windows are not necessarily QWidgets.
74 \sa QApplication::topLevelWidgets(), windowTitles()
79 \fn QxtDesktopWidget::activeWindow()
81 Returns the native window system identifier of the active window if any.
85 WId wid = QxtDesktopWidget::activeWindow();
86 QString title = QxtDesktopWidget::windowTitle(wid);
87 qDebug() << "Currently active window is:" << title;
90 \note The window is not necessarily a QWidget.
92 \sa QApplication::activeWindow()
96 \fn QxtDesktopWidget::findWindow(const QString& title)
98 Returns the native window system identifier of the window if any with given \a title.
102 WId wid = QxtDesktopWidget::findWindow("Mail - Kontact");
103 QPixmap screenshot = QPixmap::grabWindow(wid);
106 \note The window is not necessarily a QWidget.
112 \fn QxtDesktopWidget::windowAt(const QPoint& pos)
114 Returns the native window system identifier of the window if any at \a pos.
118 QPoint point = // a mouse press or something
119 WId wid = QxtDesktopWidget::windowAt(point);
120 QPixmap screenshot = QPixmap::grabWindow(wid);
123 \note The window is not necessarily a QWidget.
125 \sa QApplication::widgetAt()
129 \fn QxtDesktopWidget::windowTitle(WId window)
131 Returns the title of the native \a window.
135 WId wid = QxtDesktopWidget::activeWindow();
136 QString title = QxtDesktopWidget::windowTitle(wid);
137 qDebug() << "Currently active window is:" << title;
140 \sa QWidget::windowTitle(), windowTitles()
144 \fn QxtDesktopWidget::windowTitles()
146 Returns a list of native window titles.
150 qDebug() << "Windows:";
151 foreach (QString title, QxtDesktopWidget::windowTitles())
155 \sa QWidget::windowTitle(), windowTitle(), windows()
159 \fn QxtDesktopWidget::windowGeometry(WId window)
161 Returns the geometry of the native \a window.
165 WId wid = QxtDesktopWidget::activeWindow();
166 QRect geometry = QxtDesktopWidget::windowGeometry(wid);
167 qDebug() << "Geometry of the active window is:" << geometry;
170 \sa QWidget::frameGeometry()
173 QStringList QxtDesktopWidget::windowTitles()
175 WindowList windows = QxtDesktopWidget::windows();
177 foreach (WId window, windows)
178 titles += QxtDesktopWidget::windowTitle(window);