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

KDEUI

  • 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
35KWindowInfo::Private::Private()
36 : ref(0), win(0), isLocal(false), loadedData(false), m_axWin(0), parent(), m_pid(-1)
37{
38}
39
40void KWindowInfo::Private::setAxElement(const AXUIElementRef& axWin)
41{
42 m_axWin = axWin;
43 CFRetain(m_axWin);
44}
45
46void KWindowInfo::Private::setProcessSerialNumber(const ProcessSerialNumber& psn)
47{
48 m_psn = psn;
49 GetProcessPID(&psn, &m_pid);
50}
51
52KWindowInfo::Private::~Private()
53{
54 if (m_axWin) {
55 CFRelease(m_axWin);
56 }
57}
58
59void 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
118KWindowInfo::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
131KWindowInfo::KWindowInfo()
132 : d( NULL )
133{
134}
135
136KWindowInfo::~KWindowInfo()
137{
138 if( d != NULL ) {
139 if( --d->ref == 0 ) {
140 delete d;
141 }
142 }
143}
144
145KWindowInfo::KWindowInfo( const KWindowInfo& wininfo )
146 : d( wininfo.d )
147{
148 if( d != NULL )
149 ++d->ref;
150}
151
152KWindowInfo& 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
165bool KWindowInfo::valid( bool withdrawn_is_valid ) const
166{
167 return d->pid() >= 0;
168}
169
170WId KWindowInfo::win() const
171{
172 return d->win;
173}
174
175unsigned long KWindowInfo::state() const
176{
177 return 0;
178}
179
180bool KWindowInfo::hasState( unsigned long s ) const
181{
182 return false;
183}
184
185bool 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
199NET::MappingState KWindowInfo::mappingState() const
200{
201 return (NET::MappingState) 0;
202}
203
204NETExtendedStrut KWindowInfo::extendedStrut() const
205{
206 NETExtendedStrut ext;
207 return ext;
208}
209
210NET::WindowType KWindowInfo::windowType( int supported_types ) const
211{
212 return (NET::WindowType) 0;
213}
214
215QString 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
225QString KWindowInfo::visibleName() const
226{
227 return name();
228}
229
230QString KWindowInfo::name() const
231{
232 if (!d->loadedData) {
233 d->updateData();
234 }
235 return d->name;
236}
237
238QString 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
248QString KWindowInfo::visibleIconName() const
249{
250 return visibleName();
251}
252
253QString KWindowInfo::iconName() const
254{
255 return name();
256}
257
258bool KWindowInfo::isOnCurrentDesktop() const
259{
260 return isOnDesktop( KWindowSystem::currentDesktop());
261}
262
263bool KWindowInfo::isOnDesktop( int _desktop ) const
264{
265 return true;
266}
267
268bool KWindowInfo::onAllDesktops() const
269{
270 return false;
271}
272
273int KWindowInfo::desktop() const
274{
275 return 0;
276}
277
278QRect KWindowInfo::geometry() const
279{
280 return QRect();
281}
282
283QRect KWindowInfo::frameGeometry() const
284{
285 return QRect();
286}
287
288bool 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
294WId 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
301WId 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
308QByteArray 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
315QByteArray 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
322QByteArray 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
329QByteArray 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
336bool 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
347bool 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
KWindowInfo
Information about a window.
Definition: kwindowinfo.h:36
KWindowInfo::KWindowInfo
KWindowInfo()
Definition: kwindowinfo_mac.cpp:131
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::extendedStrut
NETExtendedStrut extendedStrut() const
Returns the window extended (partial) strut.
Definition: kwindowinfo_mac.cpp:204
KWindowInfo::windowType
NET::WindowType windowType(int supported_types) const
Returns the window type of this window (see NET::WindowType).
Definition: kwindowinfo_mac.cpp:210
KWindowInfo::state
unsigned long state() const
Returns the window's state flags (see the NET::State enum for details).
Definition: kwindowinfo_mac.cpp:175
KWindowInfo::isMinimized
bool isMinimized() const
Returns true if the window is minimized.
Definition: kwindowinfo_mac.cpp:185
KWindowInfo::visibleName
QString visibleName() const
Returns the visible name of the window (i.e.
Definition: kwindowinfo_mac.cpp:225
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
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::~KWindowInfo
~KWindowInfo()
Definition: kwindowinfo_mac.cpp:136
KWindowInfo::windowClassName
QByteArray windowClassName() const
Returns the name component of the window class for the window (i.e.
Definition: kwindowinfo_win.cpp:293
KWindowInfo::windowRole
QByteArray windowRole() const
Returns the window role for the window (i.e.
Definition: kwindowinfo_x11.cpp:390
KWindowInfo::visibleIconNameWithState
QString visibleIconNameWithState() const
Returns a visible name with state.
Definition: kwindowinfo_mac.cpp:238
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
KWindowInfo::isOnCurrentDesktop
bool isOnCurrentDesktop() const
Returns true if the window is on the currently active virtual desktop.
Definition: kwindowinfo_mac.cpp:258
KWindowInfo::visibleNameWithState
QString visibleNameWithState() const
Returns a visible name with state.
Definition: kwindowinfo_mac.cpp:215
KWindowInfo::isOnDesktop
bool isOnDesktop(int desktop) const
Returns true if the window is on the given virtual desktop.
Definition: kwindowinfo_mac.cpp:263
KWindowInfo::win
WId win() const
Returns the window identifier.
Definition: kwindowinfo_mac.cpp:170
KWindowInfo::transientFor
WId transientFor() const
Returns the WM_TRANSIENT_FOR property for the window, i.e.
Definition: kwindowinfo_x11.cpp:354
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::groupLeader
WId groupLeader() const
Returns the leader window for the group the window is in, if any.
Definition: kwindowinfo_x11.cpp:363
KWindowInfo::onAllDesktops
bool onAllDesktops() const
Returns true if the window is on all desktops (equal to desktop()==NET::OnAllDesktops).
Definition: kwindowinfo_mac.cpp:268
KWindowInfo::geometry
QRect geometry() const
Returns the position and size of the window contents.
Definition: kwindowinfo_mac.cpp:278
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::windowClassClass
QByteArray windowClassClass() const
Returns the class component of the window class for the window (i.e.
Definition: kwindowinfo_win.cpp:277
KWindowInfo::mappingState
NET::MappingState mappingState() const
Returns the mapping state of the window (see NET::MappingState).
Definition: kwindowinfo_mac.cpp:199
KWindowInfo::frameGeometry
QRect frameGeometry() const
Returns the frame geometry of the window, i.e.
Definition: kwindowinfo_mac.cpp:283
KWindowInfo::clientMachine
QByteArray clientMachine() const
Returns the client machine for the window (i.e.
Definition: kwindowinfo_x11.cpp:399
KWindowInfo::name
QString name() const
Returns the name of the window, as specified by the application, without any modifications.
Definition: kwindowinfo_mac.cpp:230
KWindowSystem::allowedActionsSupported
static bool allowedActionsSupported()
Returns true if the WM announces which actions it allows for windows.
Definition: kwindowsystem_mac.cpp:597
KWindowSystem::currentDesktop
static int currentDesktop()
Returns the current virtual desktop.
Definition: kwindowsystem_mac.cpp:384
KWindowSystem::icccmCompliantMappingState
static bool icccmCompliantMappingState()
Definition: kwindowsystem_mac.cpp:542
NETWinInfo::PROTOCOLS2
@ PROTOCOLS2
Definition: netwm.h:835
NET::Shaded
@ Shaded
indicates that the window is shaded (rolled-up).
Definition: netwm_def.h:453
NET::Hidden
@ Hidden
indicates that a window should not be visible on the screen (e.g.
Definition: netwm_def.h:475
NET::WindowType
WindowType
Window type.
Definition: netwm_def.h:305
NET::WM2WindowClass
@ WM2WindowClass
Definition: netwm_def.h:686
NET::WM2WindowRole
@ WM2WindowRole
Definition: netwm_def.h:687
NET::WM2AllowedActions
@ WM2AllowedActions
Definition: netwm_def.h:680
NET::WM2TransientFor
@ WM2TransientFor
Definition: netwm_def.h:678
NET::WM2GroupLeader
@ WM2GroupLeader
Definition: netwm_def.h:679
NET::WM2ClientMachine
@ WM2ClientMachine
Definition: netwm_def.h:688
NET::Action
Action
Actions that can be done with a window (_NET_WM_ALLOWED_ACTIONS).
Definition: netwm_def.h:553
NET::MappingState
MappingState
Client window mapping state.
Definition: netwm_def.h:533
NET::Iconic
@ Iconic
indicates that the client window is not visible, but its icon is.
Definition: netwm_def.h:547
kWarning
#define kWarning
kdebug.h
kiconloader.h
klocale.h
kwindowinfo.h
kwindowsystem.h
kxerrorhandler.h
ref
void ref()
KStandardAction::name
const char * name(StandardAction id)
This will return the internal name of a given standard action.
Definition: kstandardaction.cpp:223
netwm.h
NETExtendedStrut
Partial strut class for NET classes.
Definition: netwm_def.h:152
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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