| Home · All Namespaces · All Classes |
00001 /*************************************************************************** 00002 ** 00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). 00004 ** All rights reserved. 00005 ** Contact: Nokia Corporation (directui@nokia.com) 00006 ** 00007 ** This file is part of mhome. 00008 ** 00009 ** If you have questions regarding the use of this file, please contact 00010 ** Nokia at directui@nokia.com. 00011 ** 00012 ** This library is free software; you can redistribute it and/or 00013 ** modify it under the terms of the GNU Lesser General Public 00014 ** License version 2.1 as published by the Free Software Foundation 00015 ** and appearing in the file LICENSE.LGPL included in the packaging 00016 ** of this file. 00017 ** 00018 ****************************************************************************/ 00019 00020 #include <QHash> 00021 #include "windowinfo.h" 00022 #include "x11wrapper.h" 00023 #include <QX11Info> 00024 00025 00029 class WindowData : public QSharedData 00030 { 00031 00032 public: 00034 WindowData(Window id) : 00035 window(id), 00036 transientFor(0), 00037 title(), 00038 types(), 00039 states() 00040 { 00041 } 00042 00044 WindowData(const WindowData& source) : QSharedData(source), 00045 window(source.window), 00046 transientFor(source.transientFor), 00047 types(source.types), 00048 states(source.states) 00049 { 00050 } 00051 00053 ~WindowData() 00054 { 00055 } 00056 00058 Window window; 00059 00061 Window transientFor; 00062 00064 QString title; 00065 00067 QList<Atom> types; 00068 00070 QList<Atom> states; 00071 }; 00072 00073 00074 static bool atomsInitialized; 00075 00076 Atom WindowInfo::TypeAtom; 00077 Atom WindowInfo::StateAtom; 00078 Atom WindowInfo::NormalAtom; 00079 Atom WindowInfo::DesktopAtom; 00080 Atom WindowInfo::NotificationAtom; 00081 Atom WindowInfo::DialogAtom; 00082 Atom WindowInfo::CallAtom; 00083 Atom WindowInfo::DockAtom; 00084 Atom WindowInfo::MenuAtom; 00085 Atom WindowInfo::SkipTaskbarAtom; 00086 Atom WindowInfo::NameAtom; 00087 Atom WindowInfo::InputWindowAtom; 00088 00089 void WindowInfo::initializeAtoms() 00090 { 00091 if (!atomsInitialized) { 00092 Display *dpy = QX11Info::display(); 00093 TypeAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); 00094 StateAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_STATE", False); 00095 NormalAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False); 00096 DesktopAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", False); 00097 NotificationAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False); 00098 DialogAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); 00099 CallAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_CALL", False); 00100 DockAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DOCK", False); 00101 MenuAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_MENU", False); 00102 SkipTaskbarAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_STATE_SKIP_TASKBAR", False); 00103 NameAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_NAME", False); 00104 InputWindowAtom = X11Wrapper::XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_INPUT", False); 00105 atomsInitialized = true; 00106 } 00107 } 00108 00109 QHash<Window, QExplicitlySharedDataPointer<WindowData> > WindowInfo::windowDatas; 00110 00111 WindowInfo::WindowInfo(Window window) 00112 { 00113 if (QExplicitlySharedDataPointer<WindowData> data = windowDatas.value(window)) { 00114 d = data; 00115 } else { 00116 d = new WindowData(window); 00117 updateWindowTitle(); 00118 updateWindowProperties(); 00119 windowDatas[window] = d; 00120 } 00121 } 00122 00123 WindowInfo::WindowInfo(const WindowInfo &other) : 00124 d(other.d) 00125 { 00126 } 00127 00128 WindowInfo::~WindowInfo() 00129 { 00130 // If the data object's reference count is two, it means that the only alive 00131 // references are in this object and the global container. That means that this 00132 // object is the last WindowInfo object containing a reference to the data object. 00133 // We don't want to leave a dangling data object to the global container so we'll 00134 // remove the data object here. 00135 if (d->ref == 2) { 00136 windowDatas.remove(d->window); 00137 } 00138 } 00139 00140 WindowInfo& WindowInfo::operator=(const WindowInfo &rhs) 00141 { 00142 d = rhs.d; 00143 return *this; 00144 } 00145 00146 const QString& WindowInfo::title() const 00147 { 00148 return d->title; 00149 } 00150 00151 Window WindowInfo::window() const 00152 { 00153 return d->window; 00154 } 00155 00156 Window WindowInfo::transientFor() const 00157 { 00158 return d->transientFor; 00159 } 00160 00161 QList<Atom> WindowInfo::types() const 00162 { 00163 return d->types; 00164 } 00165 00166 QList<Atom> WindowInfo::states() const 00167 { 00168 return d->states; 00169 } 00170 00171 bool operator==(const WindowInfo &wi1, const WindowInfo &wi2) 00172 { 00173 return wi1.window() == wi2.window(); 00174 } 00175 00176 bool WindowInfo::updateWindowTitle() 00177 { 00178 Display *dpy = QX11Info::display(); 00179 XTextProperty textProperty; 00180 bool updated = false; 00181 int result = X11Wrapper::XGetTextProperty(dpy, d->window, &textProperty, WindowInfo::NameAtom); 00182 if (result == 0) { 00183 result = X11Wrapper::XGetWMName(dpy, d->window, &textProperty); 00184 } 00185 00186 if (result != 0) { 00187 d->title = QString::fromUtf8((const char *)textProperty.value); 00188 X11Wrapper::XFree(textProperty.value); 00189 updated = true; 00190 } 00191 return updated; 00192 } 00193 00194 void WindowInfo::updateWindowProperties() 00195 { 00196 d->types = getWindowProperties(d->window, WindowInfo::TypeAtom); 00197 d->states = getWindowProperties(d->window, WindowInfo::StateAtom); 00198 00199 if (!X11Wrapper::XGetTransientForHint(QX11Info::display(), d->window, &d->transientFor) || d->transientFor == d->window) { 00200 d->transientFor = 0; 00201 } 00202 } 00203 00204 QList<Atom> WindowInfo::getWindowProperties(Window winId, Atom propertyAtom, long maxCount) 00205 { 00206 QList<Atom> properties; 00207 Atom actualType; 00208 int actualFormat; 00209 unsigned long numTypeItems, bytesLeft; 00210 unsigned char *typeData = NULL; 00211 00212 Status result = X11Wrapper::XGetWindowProperty(QX11Info::display(), winId, propertyAtom, 0L, maxCount, False, XA_ATOM, &actualType, &actualFormat, &numTypeItems, &bytesLeft, &typeData); 00213 if (result == Success) { 00214 Atom *type = (Atom *) typeData; 00215 for (unsigned int n = 0; n < numTypeItems; n++) { 00216 properties.append(type[n]); 00217 } 00218 X11Wrapper::XFree(typeData); 00219 } 00220 return properties; 00221 } 00222 00223 uint qHash(WindowInfo wi) { 00224 return static_cast<uint>(wi.window()); 00225 }
| Copyright © 2010 Nokia Corporation | Generated on Thu Nov 4 2010 18:20:42 Doxygen 1.7.1 |
MeeGo Touch |