• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

Plasma

windowpreview.cpp

Go to the documentation of this file.
00001 /*
00002  *   Copyright 2007 by Dan Meltzer <hydrogen@notyetimplemented.com>
00003  *   Copyright (C) 2008 by Alexis Ménard <darktears31@gmail.com>
00004  *
00005  *   This program is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU Library General Public License as
00007  *   published by the Free Software Foundation; either version 2, or
00008  *   (at your option) any later version.
00009  *
00010  *   This program is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details
00014  *
00015  *   You should have received a copy of the GNU Library General Public
00016  *   License along with this program; if not, write to the
00017  *   Free Software Foundation, Inc.,
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  */
00020 
00021 #include "windowpreview_p.h"
00022 
00023 #include <kwindowsystem.h>
00024 
00025 #ifdef Q_WS_X11
00026 #include <QX11Info>
00027 
00028 #include <X11/Xlib.h>
00029 #include <fixx11h.h>
00030 #endif
00031 
00032 namespace Plasma {
00033 
00034 bool WindowPreview::previewsAvailable() // static
00035 {
00036     if (!KWindowSystem::compositingActive()) {
00037         return false;
00038     }
00039 #ifdef Q_WS_X11
00040     // hackish way to find out if KWin has the effect enabled,
00041     // TODO provide proper support
00042     Display *dpy = QX11Info::display();
00043     Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
00044     int cnt;
00045     Atom *list = XListProperties(dpy, DefaultRootWindow(dpy), &cnt);
00046     if (list != NULL) {
00047         bool ret = (qFind(list, list + cnt, atom) != list + cnt);
00048         XFree(list);
00049         return ret;
00050     }
00051 #endif
00052     return false;
00053 }
00054 
00055 WindowPreview::WindowPreview(QWidget *parent)
00056     : QWidget(parent)
00057 {
00058 }
00059 
00060 void WindowPreview::setWindowId(WId w)
00061 {
00062     if (!previewsAvailable()) {
00063         id = 0;
00064         return;
00065     }
00066     id = w;
00067     readWindowSize();
00068 }
00069 
00070 WId WindowPreview::windowId() const
00071 {
00072     return id;
00073 }
00074 
00075 QSize WindowPreview::sizeHint() const
00076 {
00077     if (id == 0) {
00078         return QSize();
00079     }
00080     if (!windowSize.isValid()) {
00081         readWindowSize();
00082     }
00083     QSize s = windowSize;
00084     s.scale(200, 150, Qt::KeepAspectRatio);
00085     return s;
00086 }
00087 
00088 void WindowPreview::readWindowSize() const
00089 {
00090 #ifdef Q_WS_X11
00091     Window r;
00092     int x, y;
00093     unsigned int w, h, b, d;
00094     if (id > 0 && XGetGeometry(QX11Info::display(), id, &r, &x, &y, &w, &h, &b, &d)) {
00095         windowSize = QSize(w, h);
00096     } else {
00097         windowSize = QSize();
00098     }
00099 #else
00100     windowSize = QSize();
00101 #endif
00102 }
00103 
00104 void WindowPreview::setInfo()
00105 {
00106 #ifdef Q_WS_X11
00107     Display *dpy = QX11Info::display();
00108     Atom atom = XInternAtom(dpy, "_KDE_WINDOW_PREVIEW", False);
00109     if (id == 0) {
00110         XDeleteProperty(dpy, parentWidget()->winId(), atom);
00111         return;
00112     }
00113     if (!windowSize.isValid()) {
00114         readWindowSize();
00115     }
00116     if (!windowSize.isValid()) {
00117         XDeleteProperty(dpy, parentWidget()->winId(), atom);
00118         return;
00119     }
00120     Q_ASSERT(parentWidget()->isWindow()); // parent must be toplevel
00121     long data[] = { 1, 5, id, x(), y(), width(), height() };
00122     XChangeProperty(dpy, parentWidget()->winId(), atom, atom, 32, PropModeReplace,
00123         reinterpret_cast<unsigned char *>(data), sizeof(data) / sizeof(data[ 0 ]));
00124 #endif
00125 }
00126 
00127 } // namespace Plasma
00128 
00129 #include "windowpreview_p.moc"

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal