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

KDEUI

  • sources
  • kde-4.12
  • kdelibs
  • kdeui
  • windowmanagement
kwindowinfo_mac.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (C) 2008 Marijn Kruisselbrink (m.kruisselbrink@student.tue.nl)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "kwindowinfo_mac_p.h"
22 #include "kwindowinfo.h"
23 #include "kwindowsystem.h"
24 
25 #include <kiconloader.h>
26 #include <klocale.h>
27 #include <kdebug.h>
28 #include <kxerrorhandler.h>
29 #include <netwm.h>
30 #include <QtGui/QBitmap>
31 #include <QDesktopWidget>
32 #include <QtGui/QDialog>
33 #include <QtDBus/QtDBus>
34 
35 KWindowInfo::Private::Private()
36  : ref(0), win(0), isLocal(false), loadedData(false), m_axWin(0), parent(), m_pid(-1)
37 {
38 }
39 
40 void KWindowInfo::Private::setAxElement(const AXUIElementRef& axWin)
41 {
42  m_axWin = axWin;
43  CFRetain(m_axWin);
44 }
45 
46 void KWindowInfo::Private::setProcessSerialNumber(const ProcessSerialNumber& psn)
47 {
48  m_psn = psn;
49  GetProcessPID(&psn, &m_pid);
50 }
51 
52 KWindowInfo::Private::~Private()
53 {
54  CFRelease(m_axWin);
55 }
56 
57 void KWindowInfo::Private::updateData()
58 {
59  ProcessInfoRec pinfo;
60  char processName[512];
61 #ifdef Q_OS_MAC32
62  FSSpec appSpec;
63 #else
64  FSRef ref;
65 #endif
66  pinfo.processInfoLength = sizeof pinfo;
67  pinfo.processName = (unsigned char*) processName;
68 #ifdef Q_OS_MAC32
69  pinfo.processAppSpec = &appSpec;
70 #else
71  pinfo.processAppRef = &ref;
72 #endif
73  GetProcessInformation(&m_psn, &pinfo);
74  name = QString::fromLatin1(processName+1, processName[0]);
75 
76  if (m_axWin) {
77  CFStringRef title;
78  if (AXUIElementCopyAttributeValue(m_axWin, kAXTitleAttribute, (CFTypeRef*)&title) == noErr) {
79  CFStringGetCString(title, processName, sizeof processName, kCFStringEncodingUTF8);
80  name = QString::fromUtf8(processName);
81  }
82  }
83 
84 #ifdef Q_OS_MAC32
85  iconSpec = appSpec;
86 
87  FSRef ref;
88  FSpMakeFSRef(&appSpec, &ref);
89 #else
90  iconSpec = ref;
91 #endif
92  // check if it is in an application bundle (foo.app/Contents/MacOS/plasma)
93  HFSUniStr255 name;
94  FSRef parentRef;
95  FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, &name, 0, &parentRef);
96  ref = parentRef;
97  FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, &name, 0, &parentRef);
98  if (QString::fromUtf16(name.unicode, name.length) == "MacOS") {
99  ref = parentRef;
100  FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, &name, 0, &parentRef);
101  if (QString::fromUtf16(name.unicode, name.length) == "Contents") {
102 #ifdef Q_OS_MAC32
103  FSSpec spec;
104  ref = parentRef;
105  FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, &name, &spec, &parentRef);
106  iconSpec = spec;
107 #else
108  iconSpec = parentRef;
109 #endif
110  }
111  }
112 
113  loadedData = true;
114 }
115 
116 KWindowInfo::KWindowInfo( WId win, unsigned long, unsigned long ) : d(new Private)
117 {
118  d->ref = 1;
119  d->win = win;
120  d->isLocal = true;
121  if (!win) {
122  d->win = (WId) d;
123  d->isLocal = false;
124  }
125 }
126 
127 
128 // this one is only to make QList<> or similar happy
129 KWindowInfo::KWindowInfo()
130  : d( NULL )
131 {
132 }
133 
134 KWindowInfo::~KWindowInfo()
135 {
136  if( d != NULL ) {
137  if( --d->ref == 0 ) {
138  delete d;
139  }
140  }
141 }
142 
143 KWindowInfo::KWindowInfo( const KWindowInfo& wininfo )
144  : d( wininfo.d )
145 {
146  if( d != NULL )
147  ++d->ref;
148 }
149 
150 KWindowInfo& KWindowInfo::operator=( const KWindowInfo& wininfo )
151 {
152  if( d != wininfo.d ) {
153  if( d != NULL )
154  if( --d->ref == 0 )
155  delete d;
156  d = wininfo.d;
157  if( d != NULL )
158  ++d->ref;
159  }
160  return *this;
161 }
162 
163 bool KWindowInfo::valid( bool withdrawn_is_valid ) const
164 {
165  return d->pid() >= 0;
166 }
167 
168 WId KWindowInfo::win() const
169 {
170  return d->win;
171 }
172 
173 unsigned long KWindowInfo::state() const
174 {
175  return 0;
176 }
177 
178 bool KWindowInfo::hasState( unsigned long s ) const
179 {
180  return false;
181 }
182 
183 bool KWindowInfo::isMinimized() const
184 {
185  if (d->axElement()) {
186  CFBooleanRef val;
187  if (AXUIElementCopyAttributeValue(d->axElement(), kAXMinimizedAttribute, (CFTypeRef*)&val) == noErr) {
188  return CFBooleanGetValue(val);
189  } else {
190  return false;
191  }
192  } else {
193  return false;
194  }
195 }
196 
197 NET::MappingState KWindowInfo::mappingState() const
198 {
199  return (NET::MappingState) 0;
200 }
201 
202 NETExtendedStrut KWindowInfo::extendedStrut() const
203 {
204  NETExtendedStrut ext;
205  return ext;
206 }
207 
208 NET::WindowType KWindowInfo::windowType( int supported_types ) const
209 {
210  return (NET::WindowType) 0;
211 }
212 
213 QString KWindowInfo::visibleNameWithState() const
214 {
215  QString s = visibleName();
216  if ( isMinimized() ) {
217  s.prepend(QLatin1Char('('));
218  s.append(QLatin1Char(')'));
219  }
220  return s;
221 }
222 
223 QString KWindowInfo::visibleName() const
224 {
225  return name();
226 }
227 
228 QString KWindowInfo::name() const
229 {
230  if (!d->loadedData) {
231  d->updateData();
232  }
233  return d->name;
234 }
235 
236 QString KWindowInfo::visibleIconNameWithState() const
237 {
238  QString s = visibleIconName();
239  if ( isMinimized() ) {
240  s.prepend(QLatin1Char('('));
241  s.append(QLatin1Char(')'));
242  }
243  return s;
244 }
245 
246 QString KWindowInfo::visibleIconName() const
247 {
248  return visibleName();
249 }
250 
251 QString KWindowInfo::iconName() const
252 {
253  return name();
254 }
255 
256 bool KWindowInfo::isOnCurrentDesktop() const
257 {
258  return isOnDesktop( KWindowSystem::currentDesktop());
259 }
260 
261 bool KWindowInfo::isOnDesktop( int _desktop ) const
262 {
263  return true;
264 }
265 
266 bool KWindowInfo::onAllDesktops() const
267 {
268  return false;
269 }
270 
271 int KWindowInfo::desktop() const
272 {
273  return 0;
274 }
275 
276 QRect KWindowInfo::geometry() const
277 {
278  return QRect();
279 }
280 
281 QRect KWindowInfo::frameGeometry() const
282 {
283  return QRect();
284 }
285 
286 bool KWindowInfo::actionSupported( NET::Action action ) const
287 {
288  return true; // no idea if it's supported or not -> pretend it is
289 }
290 
291 #if 0
292 WId KWindowInfo::transientFor() const
293 {
294  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2TransientFor ) == 0, 176 )
295  << "Pass NET::WM2TransientFor to KWindowInfo";
296  return d->info->transientFor();
297 }
298 
299 WId KWindowInfo::groupLeader() const
300 {
301  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2GroupLeader ) == 0, 176 )
302  << "Pass NET::WM2GroupLeader to KWindowInfo";
303  return d->info->groupLeader();
304 }
305 
306 QByteArray KWindowInfo::windowClassClass() const
307 {
308  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 )
309  << "Pass NET::WM2WindowClass to KWindowInfo";
310  return d->info->windowClassClass();
311 }
312 
313 QByteArray KWindowInfo::windowClassName() const
314 {
315  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 )
316  << "Pass NET::WM2WindowClass to KWindowInfo";
317  return d->info->windowClassName();
318 }
319 
320 QByteArray KWindowInfo::windowRole() const
321 {
322  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowRole ) == 0, 176 )
323  << "Pass NET::WM2WindowRole to KWindowInfo";
324  return d->info->windowRole();
325 }
326 
327 QByteArray KWindowInfo::clientMachine() const
328 {
329  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2ClientMachine ) == 0, 176 )
330  << "Pass NET::WM2ClientMachine to KWindowInfo";
331  return d->info->clientMachine();
332 }
333 
334 bool KWindowInfo::actionSupported( NET::Action action ) const
335 {
336  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2AllowedActions ) == 0, 176 )
337  << "Pass NET::WM2AllowedActions to KWindowInfo";
338  if( KWindowSystem::allowedActionsSupported())
339  return d->info->allowedActions() & action;
340  else
341  return true; // no idea if it's supported or not -> pretend it is
342 }
343 
344 // see NETWM spec section 7.6
345 bool KWindowInfo::isMinimized() const
346 {
347  if( mappingState() != NET::Iconic )
348  return false;
349  // NETWM 1.2 compliant WM - uses NET::Hidden for minimized windows
350  if(( state() & NET::Hidden ) != 0
351  && ( state() & NET::Shaded ) == 0 ) // shaded may have NET::Hidden too
352  return true;
353  // older WMs use WithdrawnState for other virtual desktops
354  // and IconicState only for minimized
355  return KWindowSystem::icccmCompliantMappingState() ? false : true;
356 }
357 #endif
kdebug.h
KWindowInfo::iconName
QString iconName() const
Returns the name of the window that should be shown in taskbar and all other "iconic" representations...
Definition: kwindowinfo_mac.cpp:251
KWindowInfo::windowType
NET::WindowType windowType(int supported_types) const
Returns the window type of this window (see NET::WindowType).
Definition: kwindowinfo_mac.cpp:208
KWindowInfo::visibleName
QString visibleName() const
Returns the visible name of the window (i.e.
Definition: kwindowinfo_mac.cpp:223
KWindowInfo::operator=
KWindowInfo & operator=(const KWindowInfo &)
Definition: kwindowinfo_mac.cpp:150
KWindowInfo::visibleIconName
QString visibleIconName() const
Returns the visible name of the window that should be shown in taskbar and all other "iconic" represe...
Definition: kwindowinfo_mac.cpp:246
KWindowInfo::frameGeometry
QRect frameGeometry() const
Returns the frame geometry of the window, i.e.
Definition: kwindowinfo_mac.cpp:281
NET::Iconic
indicates that the client window is not visible, but its icon is.
Definition: netwm_def.h:547
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
KWindowInfo
Information about a window.
Definition: kwindowinfo.h:35
KWindowInfo::hasState
bool hasState(unsigned long s) const
Returns true if the window has the given state flag set (see the NET::State enum for details)...
Definition: kwindowinfo_mac.cpp:178
NET::WM2WindowClass
Definition: netwm_def.h:686
NET::WM2GroupLeader
Definition: netwm_def.h:679
kiconloader.h
NETExtendedStrut
Partial strut class for NET classes.
Definition: netwm_def.h:152
QString
KWindowInfo::state
unsigned long state() const
Returns the window's state flags (see the NET::State enum for details).
Definition: kwindowinfo_mac.cpp:173
klocale.h
ref
void ref()
KWindowInfo::visibleNameWithState
QString visibleNameWithState() const
Returns a visible name with state.
Definition: kwindowinfo_mac.cpp:213
KWindowInfo::clientMachine
QByteArray clientMachine() const
Returns the client machine for the window (i.e.
Definition: kwindowinfo_x11.cpp:399
KWindowInfo::isMinimized
bool isMinimized() const
Returns true if the window is minimized.
Definition: kwindowinfo_mac.cpp:183
NET::Hidden
indicates that a window should not be visible on the screen (e.g.
Definition: netwm_def.h:475
KWindowInfo::onAllDesktops
bool onAllDesktops() const
Returns true if the window is on all desktops (equal to desktop()==NET::OnAllDesktops).
Definition: kwindowinfo_mac.cpp:266
NET::MappingState
MappingState
Client window mapping state.
Definition: netwm_def.h:533
KWindowInfo::actionSupported
bool actionSupported(NET::Action action) const
Returns true if the given action is currently supported for the window by the window manager...
Definition: kwindowinfo_mac.cpp:286
KWindowInfo::mappingState
NET::MappingState mappingState() const
Returns the mapping state of the window (see NET::MappingState).
Definition: kwindowinfo_mac.cpp:197
KWindowSystem::currentDesktop
static int currentDesktop()
Returns the current virtual desktop.
Definition: kwindowsystem_mac.cpp:384
NET::WM2WindowRole
Definition: netwm_def.h:687
NET::WM2TransientFor
Definition: netwm_def.h:678
netwm.h
KWindowInfo::extendedStrut
NETExtendedStrut extendedStrut() const
Returns the window extended (partial) strut.
Definition: kwindowinfo_mac.cpp:202
KWindowInfo::valid
bool valid(bool withdrawn_is_valid=false) const
Returns false if this window info is not valid (most probably the given window doesn't exist)...
Definition: kwindowinfo_mac.cpp:163
NET::WindowType
WindowType
Window type.
Definition: netwm_def.h:305
KWindowSystem::icccmCompliantMappingState
static bool icccmCompliantMappingState()
Definition: kwindowsystem_mac.cpp:542
KWindowInfo::~KWindowInfo
~KWindowInfo()
Definition: kwindowinfo_mac.cpp:134
KWindowInfo::windowRole
QByteArray windowRole() const
Returns the window role for the window (i.e.
Definition: kwindowinfo_x11.cpp:390
KWindowInfo::groupLeader
WId groupLeader() const
Returns the leader window for the group the window is in, if any.
Definition: kwindowinfo_x11.cpp:363
KWindowInfo::isOnDesktop
bool isOnDesktop(int desktop) const
Returns true if the window is on the given virtual desktop.
Definition: kwindowinfo_mac.cpp:261
kxerrorhandler.h
KWindowInfo::geometry
QRect geometry() const
Returns the position and size of the window contents.
Definition: kwindowinfo_mac.cpp:276
KWindowInfo::win
WId win() const
Returns the window identifier.
Definition: kwindowinfo_mac.cpp:168
QRect
NETWinInfo::PROTOCOLS2
Definition: netwm.h:835
NET::Shaded
indicates that the window is shaded (rolled-up).
Definition: netwm_def.h:453
KWindowSystem::allowedActionsSupported
static bool allowedActionsSupported()
Returns true if the WM announces which actions it allows for windows.
Definition: kwindowsystem_mac.cpp:597
KWindowInfo::transientFor
WId transientFor() const
Returns the WM_TRANSIENT_FOR property for the window, i.e.
Definition: kwindowinfo_x11.cpp:354
KWindowInfo::windowClassName
QByteArray windowClassName() const
Returns the name component of the window class for the window (i.e.
Definition: kwindowinfo_win.cpp:293
kwindowsystem.h
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KWindowInfo::name
QString name() const
Returns the name of the window, as specified by the application, without any modifications.
Definition: kwindowinfo_mac.cpp:228
NET::Action
Action
Actions that can be done with a window (_NET_WM_ALLOWED_ACTIONS).
Definition: netwm_def.h:553
KWindowInfo::desktop
int desktop() const
Returns the virtual desktop this window is on (NET::OnAllDesktops if the window is on all desktops)...
Definition: kwindowinfo_mac.cpp:271
KWindowInfo::isOnCurrentDesktop
bool isOnCurrentDesktop() const
Returns true if the window is on the currently active virtual desktop.
Definition: kwindowinfo_mac.cpp:256
KWindowInfo::windowClassClass
QByteArray windowClassClass() const
Returns the class component of the window class for the window (i.e.
Definition: kwindowinfo_win.cpp:277
KWindowInfo::visibleIconNameWithState
QString visibleIconNameWithState() const
Returns a visible name with state.
Definition: kwindowinfo_mac.cpp:236
NET::WM2ClientMachine
Definition: netwm_def.h:688
KWindowInfo::KWindowInfo
KWindowInfo()
Definition: kwindowinfo_mac.cpp:129
kwindowinfo.h
NET::WM2AllowedActions
Definition: netwm_def.h:680
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:49:16 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal