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

KDEUI

  • sources
  • kde-4.14
  • 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  if (m_axWin) {
55  CFRelease(m_axWin);
56  }
57 }
58 
59 void KWindowInfo::Private::updateData()
60 {
61  ProcessInfoRec pinfo;
62  char processName[512];
63 #ifdef Q_OS_MAC32
64  FSSpec appSpec;
65 #else
66  FSRef ref;
67 #endif
68  pinfo.processInfoLength = sizeof pinfo;
69  pinfo.processName = (unsigned char*) processName;
70 #ifdef Q_OS_MAC32
71  pinfo.processAppSpec = &appSpec;
72 #else
73  pinfo.processAppRef = &ref;
74 #endif
75  GetProcessInformation(&m_psn, &pinfo);
76  name = QString::fromLatin1(processName+1, processName[0]);
77 
78  if (m_axWin) {
79  CFStringRef title;
80  if (AXUIElementCopyAttributeValue(m_axWin, kAXTitleAttribute, (CFTypeRef*)&title) == noErr) {
81  CFStringGetCString(title, processName, sizeof processName, kCFStringEncodingUTF8);
82  name = QString::fromUtf8(processName);
83  }
84  }
85 
86 #ifdef Q_OS_MAC32
87  iconSpec = appSpec;
88 
89  FSRef ref;
90  FSpMakeFSRef(&appSpec, &ref);
91 #else
92  iconSpec = ref;
93 #endif
94  // check if it is in an application bundle (foo.app/Contents/MacOS/plasma)
95  HFSUniStr255 name;
96  FSRef parentRef;
97  FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, &name, 0, &parentRef);
98  ref = parentRef;
99  FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, &name, 0, &parentRef);
100  if (QString::fromUtf16(name.unicode, name.length) == "MacOS") {
101  ref = parentRef;
102  FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, &name, 0, &parentRef);
103  if (QString::fromUtf16(name.unicode, name.length) == "Contents") {
104 #ifdef Q_OS_MAC32
105  FSSpec spec;
106  ref = parentRef;
107  FSGetCatalogInfo(&ref, kFSCatInfoNone, 0, &name, &spec, &parentRef);
108  iconSpec = spec;
109 #else
110  iconSpec = parentRef;
111 #endif
112  }
113  }
114 
115  loadedData = true;
116 }
117 
118 KWindowInfo::KWindowInfo( WId win, unsigned long, unsigned long ) : d(new Private)
119 {
120  d->ref = 1;
121  d->win = win;
122  d->isLocal = true;
123  if (!win) {
124  d->win = (WId) d;
125  d->isLocal = false;
126  }
127 }
128 
129 
130 // this one is only to make QList<> or similar happy
131 KWindowInfo::KWindowInfo()
132  : d( NULL )
133 {
134 }
135 
136 KWindowInfo::~KWindowInfo()
137 {
138  if( d != NULL ) {
139  if( --d->ref == 0 ) {
140  delete d;
141  }
142  }
143 }
144 
145 KWindowInfo::KWindowInfo( const KWindowInfo& wininfo )
146  : d( wininfo.d )
147 {
148  if( d != NULL )
149  ++d->ref;
150 }
151 
152 KWindowInfo& KWindowInfo::operator=( const KWindowInfo& wininfo )
153 {
154  if( d != wininfo.d ) {
155  if( d != NULL )
156  if( --d->ref == 0 )
157  delete d;
158  d = wininfo.d;
159  if( d != NULL )
160  ++d->ref;
161  }
162  return *this;
163 }
164 
165 bool KWindowInfo::valid( bool withdrawn_is_valid ) const
166 {
167  return d->pid() >= 0;
168 }
169 
170 WId KWindowInfo::win() const
171 {
172  return d->win;
173 }
174 
175 unsigned long KWindowInfo::state() const
176 {
177  return 0;
178 }
179 
180 bool KWindowInfo::hasState( unsigned long s ) const
181 {
182  return false;
183 }
184 
185 bool KWindowInfo::isMinimized() const
186 {
187  if (d->axElement()) {
188  CFBooleanRef val;
189  if (AXUIElementCopyAttributeValue(d->axElement(), kAXMinimizedAttribute, (CFTypeRef*)&val) == noErr) {
190  return CFBooleanGetValue(val);
191  } else {
192  return false;
193  }
194  } else {
195  return false;
196  }
197 }
198 
199 NET::MappingState KWindowInfo::mappingState() const
200 {
201  return (NET::MappingState) 0;
202 }
203 
204 NETExtendedStrut KWindowInfo::extendedStrut() const
205 {
206  NETExtendedStrut ext;
207  return ext;
208 }
209 
210 NET::WindowType KWindowInfo::windowType( int supported_types ) const
211 {
212  return (NET::WindowType) 0;
213 }
214 
215 QString KWindowInfo::visibleNameWithState() const
216 {
217  QString s = visibleName();
218  if ( isMinimized() ) {
219  s.prepend(QLatin1Char('('));
220  s.append(QLatin1Char(')'));
221  }
222  return s;
223 }
224 
225 QString KWindowInfo::visibleName() const
226 {
227  return name();
228 }
229 
230 QString KWindowInfo::name() const
231 {
232  if (!d->loadedData) {
233  d->updateData();
234  }
235  return d->name;
236 }
237 
238 QString KWindowInfo::visibleIconNameWithState() const
239 {
240  QString s = visibleIconName();
241  if ( isMinimized() ) {
242  s.prepend(QLatin1Char('('));
243  s.append(QLatin1Char(')'));
244  }
245  return s;
246 }
247 
248 QString KWindowInfo::visibleIconName() const
249 {
250  return visibleName();
251 }
252 
253 QString KWindowInfo::iconName() const
254 {
255  return name();
256 }
257 
258 bool KWindowInfo::isOnCurrentDesktop() const
259 {
260  return isOnDesktop( KWindowSystem::currentDesktop());
261 }
262 
263 bool KWindowInfo::isOnDesktop( int _desktop ) const
264 {
265  return true;
266 }
267 
268 bool KWindowInfo::onAllDesktops() const
269 {
270  return false;
271 }
272 
273 int KWindowInfo::desktop() const
274 {
275  return 0;
276 }
277 
278 QRect KWindowInfo::geometry() const
279 {
280  return QRect();
281 }
282 
283 QRect KWindowInfo::frameGeometry() const
284 {
285  return QRect();
286 }
287 
288 bool KWindowInfo::actionSupported( NET::Action action ) const
289 {
290  return true; // no idea if it's supported or not -> pretend it is
291 }
292 
293 #if 0
294 WId KWindowInfo::transientFor() const
295 {
296  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2TransientFor ) == 0, 176 )
297  << "Pass NET::WM2TransientFor to KWindowInfo";
298  return d->info->transientFor();
299 }
300 
301 WId KWindowInfo::groupLeader() const
302 {
303  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2GroupLeader ) == 0, 176 )
304  << "Pass NET::WM2GroupLeader to KWindowInfo";
305  return d->info->groupLeader();
306 }
307 
308 QByteArray KWindowInfo::windowClassClass() const
309 {
310  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 )
311  << "Pass NET::WM2WindowClass to KWindowInfo";
312  return d->info->windowClassClass();
313 }
314 
315 QByteArray KWindowInfo::windowClassName() const
316 {
317  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 )
318  << "Pass NET::WM2WindowClass to KWindowInfo";
319  return d->info->windowClassName();
320 }
321 
322 QByteArray KWindowInfo::windowRole() const
323 {
324  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowRole ) == 0, 176 )
325  << "Pass NET::WM2WindowRole to KWindowInfo";
326  return d->info->windowRole();
327 }
328 
329 QByteArray KWindowInfo::clientMachine() const
330 {
331  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2ClientMachine ) == 0, 176 )
332  << "Pass NET::WM2ClientMachine to KWindowInfo";
333  return d->info->clientMachine();
334 }
335 
336 bool KWindowInfo::actionSupported( NET::Action action ) const
337 {
338  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2AllowedActions ) == 0, 176 )
339  << "Pass NET::WM2AllowedActions to KWindowInfo";
340  if( KWindowSystem::allowedActionsSupported())
341  return d->info->allowedActions() & action;
342  else
343  return true; // no idea if it's supported or not -> pretend it is
344 }
345 
346 // see NETWM spec section 7.6
347 bool KWindowInfo::isMinimized() const
348 {
349  if( mappingState() != NET::Iconic )
350  return false;
351  // NETWM 1.2 compliant WM - uses NET::Hidden for minimized windows
352  if(( state() & NET::Hidden ) != 0
353  && ( state() & NET::Shaded ) == 0 ) // shaded may have NET::Hidden too
354  return true;
355  // older WMs use WithdrawnState for other virtual desktops
356  // and IconicState only for minimized
357  return KWindowSystem::icccmCompliantMappingState() ? false : true;
358 }
359 #endif
QString::append
QString & append(QChar ch)
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:253
KWindowInfo::windowType
NET::WindowType windowType(int supported_types) const
Returns the window type of this window (see NET::WindowType).
Definition: kwindowinfo_mac.cpp:210
QByteArray
KWindowInfo::visibleName
QString visibleName() const
Returns the visible name of the window (i.e.
Definition: kwindowinfo_mac.cpp:225
KWindowInfo::operator=
KWindowInfo & operator=(const KWindowInfo &)
Definition: kwindowinfo_mac.cpp:152
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:248
KWindowInfo::frameGeometry
QRect frameGeometry() const
Returns the frame geometry of the window, i.e.
Definition: kwindowinfo_mac.cpp:283
QString::prepend
QString & prepend(QChar ch)
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:180
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
KWindowInfo::state
unsigned long state() const
Returns the window's state flags (see the NET::State enum for details).
Definition: kwindowinfo_mac.cpp:175
klocale.h
ref
void ref()
KWindowInfo::visibleNameWithState
QString visibleNameWithState() const
Returns a visible name with state.
Definition: kwindowinfo_mac.cpp:215
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:185
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:268
NET::MappingState
MappingState
Client window mapping state.
Definition: netwm_def.h:533
QRect
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:288
KWindowInfo::mappingState
NET::MappingState mappingState() const
Returns the mapping state of the window (see NET::MappingState).
Definition: kwindowinfo_mac.cpp:199
KWindowSystem::currentDesktop
static int currentDesktop()
Returns the current virtual desktop.
Definition: kwindowsystem_mac.cpp:384
QString::fromUtf8
QString fromUtf8(const char *str, int size)
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:204
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:165
QString::fromUtf16
QString fromUtf16(const ushort *unicode, int size)
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:136
KWindowInfo::windowRole
QByteArray windowRole() const
Returns the window role for the window (i.e.
Definition: kwindowinfo_x11.cpp:390
QString
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:263
kxerrorhandler.h
QLatin1Char
KWindowInfo::geometry
QRect geometry() const
Returns the position and size of the window contents.
Definition: kwindowinfo_mac.cpp:278
KWindowInfo::win
WId win() const
Returns the window identifier.
Definition: kwindowinfo_mac.cpp:170
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)
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KWindowInfo::name
QString name() const
Returns the name of the window, as specified by the application, without any modifications.
Definition: kwindowinfo_mac.cpp:230
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:273
KWindowInfo::isOnCurrentDesktop
bool isOnCurrentDesktop() const
Returns true if the window is on the currently active virtual desktop.
Definition: kwindowinfo_mac.cpp:258
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:238
NET::WM2ClientMachine
Definition: netwm_def.h:688
KWindowInfo::KWindowInfo
KWindowInfo()
Definition: kwindowinfo_mac.cpp:131
kwindowinfo.h
NET::WM2AllowedActions
Definition: netwm_def.h:680
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:24:00 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
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • 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