• 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_win.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (C) 2008 Carlo Segato (brandon.ml@gmail.com)
4  Copyright (C) 2011 Pau Garcia i Quiles (pgquiles@elpauer.org)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "kwindowinfo.h"
23 #include "kwindowsystem.h"
24 #include <windows.h>
25 #include <stdlib.h>
26 #include <QCoreApplication>
27 
28 class KWindowInfo::Private
29 {
30  public:
31  Private()
32  : properties(0),properties2(0)
33  {}
34 
35  ~Private() { }
36 
37  WId win_;
38  int ref;
39  unsigned long properties;
40  unsigned long properties2;
41  private:
42  Private( const Private& );
43  void operator=( const Private& );
44 };
45 
46 #include <QRect>
47 
48 KWindowInfo::KWindowInfo( WId win, unsigned long properties, unsigned long properties2) : d ( new Private )
49 {
50  d->ref = 1;
51  d->win_ = win;
52  d->properties = properties;
53  d->properties2 = properties2;
54 }
55 
56 KWindowInfo::KWindowInfo()
57  : d( NULL )
58 {
59 
60 }
61 
62 KWindowInfo::~KWindowInfo()
63 {
64  if( d != NULL ) {
65  if( --d->ref == 0 ) {
66  delete d;
67  }
68  }
69 }
70 
71 KWindowInfo::KWindowInfo( const KWindowInfo& wininfo )
72  : d( wininfo.d )
73 {
74  if( d != NULL )
75  ++d->ref;
76 }
77 
78 KWindowInfo& KWindowInfo::operator=( const KWindowInfo& wininfo )
79 {
80  if( d != wininfo.d ) {
81  if( d != NULL )
82  if( --d->ref == 0 )
83  delete d;
84  d = wininfo.d;
85  if( d != NULL )
86  ++d->ref;
87  }
88  return *this;
89 }
90 
91 
92 bool KWindowInfo::valid( bool withdrawn_is_valid ) const
93 {
94  return true;
95 }
96 
97 WId KWindowInfo::win() const
98 {
99  return d->win_;
100 }
101 
102 unsigned long KWindowInfo::state() const
103 {
104  unsigned long state = 0;
105 #ifndef _WIN32_WCE
106  if(IsZoomed(d->win_))
107  state |= NET::Max;
108 #endif
109  if(!IsWindowVisible(d->win_))
110  state |= NET::Hidden;
111 
112 #ifndef _WIN32_WCE
113  LONG_PTR lp = GetWindowLongPtr(d->win_, GWL_EXSTYLE);
114  if(lp & WS_EX_TOOLWINDOW)
115  state |= NET::SkipTaskbar;
116 #endif
117 
118  return state;
119 }
120 
121 bool KWindowInfo::hasState( unsigned long s ) const
122 {
123  return (state() & s);
124 }
125 
126 bool KWindowInfo::isMinimized() const
127 {
128 #ifndef _WIN32_WCE
129  return IsIconic(d->win_);
130 #else
131  return false;
132 #endif
133 }
134 
135 NET::MappingState KWindowInfo::mappingState() const
136 {
137 #ifndef _WIN32_WCE
138  if(IsIconic(d->win_))
139  return NET::Iconic;
140 #endif
141  if(!IsWindowVisible(d->win_))
142  return NET::Withdrawn;
143  return NET::Visible;
144 }
145 
146 NETExtendedStrut KWindowInfo::extendedStrut() const
147 {
148  return NETExtendedStrut();
149 }
150 
151 NET::WindowType KWindowInfo::windowType( int supported_types ) const
152 {
153  NET::WindowType wt(NET::Normal);
154 
155 
156  long windowStyle = GetWindowLong(d->win_,GWL_STYLE);
157  long windowStyleEx = GetWindowLong(d->win_,GWL_EXSTYLE);
158 
159  if(windowStyle & WS_POPUP && supported_types & NET::PopupMenuMask)
160  return NET::PopupMenu;
161  else if(windowStyleEx & WS_EX_TOOLWINDOW && supported_types & NET::TooltipMask)
162  return NET::Tooltip;
163  else if(!(windowStyle & WS_CHILD) && supported_types & NET::NormalMask)
164  return NET::Normal;
165 
166  return wt;
167 }
168 
169 QString KWindowInfo::visibleNameWithState() const
170 {
171  QString s = visibleName();
172  if ( isMinimized() ) {
173  s.prepend(QLatin1Char('('));
174  s.append(QLatin1Char(')'));
175  }
176  return s;
177 }
178 
179 QString KWindowInfo::visibleName() const
180 {
181  return name();
182 }
183 
184 QString KWindowInfo::name() const
185 {
186  QByteArray windowText = QByteArray ( (GetWindowTextLength(d->win_)+1) * sizeof(wchar_t), 0 ) ;
187  GetWindowTextW(d->win_, (LPWSTR)windowText.data(), windowText.size());
188  return QString::fromWCharArray((wchar_t*)windowText.data());
189 }
190 
191 QString KWindowInfo::visibleIconNameWithState() const
192 {
193  return QString();
194 }
195 
196 QString KWindowInfo::visibleIconName() const
197 {
198  return QString();
199 }
200 
201 QString KWindowInfo::iconName() const
202 {
203  return QString();
204 }
205 
206 bool KWindowInfo::isOnCurrentDesktop() const
207 {
208  return true;
209 }
210 
211 bool KWindowInfo::isOnDesktop( int desk ) const
212 {
213  return desk == desktop();
214 }
215 
216 bool KWindowInfo::onAllDesktops() const
217 {
218  return false;
219 }
220 
221 int KWindowInfo::desktop() const
222 {
223  return 1;
224 }
225 
226 QRect KWindowInfo::geometry() const
227 {
228  RECT wndRect;
229  memset(&wndRect,0,sizeof(wndRect));
230 
231  //fetch the geometry INCLUDING the frames
232  if (GetWindowRect(d->win_,&wndRect)) {
233  QRect result;
234  result.setCoords ( wndRect.left, wndRect.top, wndRect.right, wndRect.bottom );
235  return result;
236  }
237 
238  return QRect();
239 }
240 
241 QRect KWindowInfo::frameGeometry() const
242 {
243  RECT wndRect;
244  memset(&wndRect,0,sizeof(wndRect));
245 
246  //fetch only client area geometries ... i hope thats right
247  if(GetClientRect(d->win_,&wndRect)){
248  QRect result;
249  result.setCoords ( wndRect.left, wndRect.top, wndRect.right, wndRect.bottom );
250  return result;
251  }
252 
253  return QRect();
254 }
255 
256 bool KWindowInfo::actionSupported( NET::Action action ) const
257 {
258  return true; // no idea if it's supported or not -> pretend it is
259 }
260 
261 #if 0
262 WId KWindowInfo::transientFor() const
263 {
264  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2TransientFor ) == 0, 176 )
265  << "Pass NET::WM2TransientFor to KWindowInfo";
266  return d->info->transientFor();
267 }
268 
269 WId KWindowInfo::groupLeader() const
270 {
271  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2GroupLeader ) == 0, 176 )
272  << "Pass NET::WM2GroupLeader to KWindowInfo";
273  return d->info->groupLeader();
274 }
275 #endif
276 
277 QByteArray KWindowInfo::windowClassClass() const
278 {
279 // kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 )
280 // << "Pass NET::WM2WindowClass to KWindowInfo";
281 // return d->info->windowClassClass();
282 
283  // Implemented per http://tronche.com/gui/x/icccm/sec-4.html#WM_CLASS (but only 2nd and 3rd choices, -name ignored)
284  char* resourcenamevar;
285  resourcenamevar = getenv("RESOURCE_NAME");
286  if(resourcenamevar != NULL ) {
287  return QByteArray(resourcenamevar);
288  }
289 
290  return QCoreApplication::applicationName().toLocal8Bit();
291 }
292 
293 QByteArray KWindowInfo::windowClassName() const
294 {
295 // kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowClass ) == 0, 176 )
296 // << "Pass NET::WM2WindowClass to KWindowInfo";
297 // return d->info->windowClassName();
298 
299  // Maybe should use RealGetWindowClass instead of GetClassName? See
300  // http://blogs.msdn.com/b/oldnewthing/archive/2010/12/31/10110524.aspx
301 
302  const int max = 256; // truncate to 255 characters
303  TCHAR name[max];
304  int count = GetClassName(d->win_, name, max);
305  return QString::fromUtf16((ushort*)name).toLocal8Bit();
306 }
307 
308 #if 0
309 QByteArray KWindowInfo::windowRole() const
310 {
311  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2WindowRole ) == 0, 176 )
312  << "Pass NET::WM2WindowRole to KWindowInfo";
313  return d->info->windowRole();
314 }
315 
316 QByteArray KWindowInfo::clientMachine() const
317 {
318  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2ClientMachine ) == 0, 176 )
319  << "Pass NET::WM2ClientMachine to KWindowInfo";
320  return d->info->clientMachine();
321 }
322 
323 bool KWindowInfo::actionSupported( NET::Action action ) const
324 {
325  kWarning(( d->info->passedProperties()[ NETWinInfo::PROTOCOLS2 ] & NET::WM2AllowedActions ) == 0, 176 )
326  << "Pass NET::WM2AllowedActions to KWindowInfo";
327  if( KWindowSystem::allowedActionsSupported())
328  return d->info->allowedActions() & action;
329  else
330  return true; // no idea if it's supported or not -> pretend it is
331 }
332 #endif
QString::fromWCharArray
QString fromWCharArray(const wchar_t *string, int size)
NET::Normal
indicates that this is a normal, top-level window
Definition: netwm_def.h:313
QString::append
QString & append(QChar ch)
NET::SkipTaskbar
indicates that a window should not be included on a taskbar.
Definition: netwm_def.h:457
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
NET::PopupMenu
indicates a popup menu (a context menu typically)
Definition: netwm_def.h:361
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
NET::NormalMask
Definition: netwm_def.h:385
KWindowInfo
Information about a window.
Definition: kwindowinfo.h:35
NET::Tooltip
indicates a tooltip window
Definition: netwm_def.h:365
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::WM2GroupLeader
Definition: netwm_def.h:679
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
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
NET::Withdrawn
indicates that neither the client window nor its icon is visible.
Definition: netwm_def.h:541
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
NET::WM2WindowRole
Definition: netwm_def.h:687
NET::WM2TransientFor
Definition: netwm_def.h:678
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
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
QRect::setCoords
void setCoords(int x1, int y1, int x2, int y2)
NET::PopupMenuMask
Definition: netwm_def.h:396
QString
NET::TooltipMask
Definition: netwm_def.h:397
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
QString::toLocal8Bit
QByteArray toLocal8Bit() const
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
KStandardGuiItem::properties
KGuiItem properties()
Returns the 'Properties' gui item.
Definition: kstandardguiitem.cpp:299
NETWinInfo::PROTOCOLS2
Definition: netwm.h:835
NET::Visible
indicates the client window is visible to the user.
Definition: netwm_def.h:537
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
QByteArray::data
char * data()
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: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
NET::Max
convenience value.
Definition: netwm_def.h:449
KWindowInfo::isOnCurrentDesktop
bool isOnCurrentDesktop() const
Returns true if the window is on the currently active virtual desktop.
Definition: kwindowinfo_mac.cpp:258
QByteArray::size
int size() const
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
QCoreApplication::applicationName
QString applicationName()
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