1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #ifndef KWIN_TOPLEVEL_H
22 #define KWIN_TOPLEVEL_H
24 #include <config-X11.h>
28 #include <kdecoration.h>
32 #include "workspace.h"
35 #include <X11/extensions/Xdamage.h>
44 class EffectWindowImpl
;
47 : public QObject
, public KDecorationDefines
51 Toplevel( Workspace
*ws
);
52 Window
frameId() const;
53 Window
window() const;
54 Workspace
* workspace() const;
55 QRect
geometry() const;
63 bool isOnScreen( int screen
) const; // true if it's at least partially there
64 int screen() const; // the screen where the center is
65 virtual QPoint
clientPos() const = 0; // inside of geometry()
66 virtual QSize
clientSize() const = 0;
68 // prefer isXXX() instead
69 // 0 for supported types means default for managed/unmanaged types
70 NET::WindowType
windowType( bool direct
= false, int supported_types
= 0 ) const;
71 bool hasNETSupport() const;
72 bool isDesktop() const;
74 bool isToolbar() const;
75 bool isTopMenu() const;
77 bool isNormalWindow() const; // normal as in 'NET::Normal or NET::Unknown non-transient'
78 bool isDialog() const;
79 bool isSplash() const;
80 bool isUtility() const;
81 bool isDropdownMenu() const;
82 bool isPopupMenu() const; // a context popup, not dropdown, not torn-off
83 bool isTooltip() const;
84 bool isNotification() const;
85 bool isComboBox() const;
86 bool isDNDIcon() const;
88 virtual int desktop() const = 0;
89 bool isOnDesktop( int d
) const;
90 bool isOnCurrentDesktop() const;
91 bool isOnAllDesktops() const;
93 QByteArray
windowRole() const;
94 QByteArray
sessionId();
95 QByteArray
resourceName() const;
96 QByteArray
resourceClass() const;
97 QByteArray
wmCommand();
98 QByteArray
wmClientMachine( bool use_localhost
) const;
99 Window
wmClientLeader() const;
101 static bool resourceMatch( const Toplevel
* c1
, const Toplevel
* c2
);
103 Pixmap
windowPixmap( bool allow_create
= true ); // may return None (e.g. at a bad moment while resizing)
104 bool readyForPainting() const; // true if the window has been already painted its contents
105 Visual
* visual() const;
107 void setOpacity( double opacity
);
108 double opacity() const;
110 bool hasAlpha() const;
111 virtual void setupCompositing();
112 virtual void finishCompositing();
113 bool updateUnredirectedState();
114 bool unredirected() const;
115 void suspendUnredirect( bool suspend
);
116 void addRepaint( const QRect
& r
);
117 void addRepaint( int x
, int y
, int w
, int h
);
118 void addRepaintFull();
119 // these call workspace->addRepaint(), but first transform the damage if needed
120 void addWorkspaceRepaint( const QRect
& r
);
121 void addWorkspaceRepaint( int x
, int y
, int w
, int h
);
122 QRegion
repaints() const;
123 void resetRepaints( const QRect
& r
);
124 QRegion
damage() const;
125 void resetDamage( const QRect
& r
);
126 EffectWindowImpl
* effectWindow();
130 void setWindowHandles( Window client
, Window frame
);
131 void detectShape( Window id
);
132 virtual void propertyNotifyEvent( XPropertyEvent
* e
);
134 virtual void damageNotifyEvent( XDamageNotifyEvent
* e
);
136 Pixmap
createWindowPixmap();
137 void discardWindowPixmap();
138 void addDamage( const QRect
& r
);
139 void addDamage( int x
, int y
, int w
, int h
);
140 void addDamageFull();
141 void getWmClientLeader();
142 void getWmClientMachine();
143 void getResourceClass();
144 void getWindowRole();
145 virtual void debug( kdbgstream
& stream
) const = 0;
146 void copyToDeleted( Toplevel
* c
);
147 void disownDataPassedToDeleted();
148 friend kdbgstream
& operator<<( kdbgstream
& stream
, const Toplevel
* );
149 void deleteEffectWindow();
150 virtual bool shouldUnredirect() const = 0;
155 bool ready_for_painting
;
157 static QByteArray
staticWindowRole(WId
);
158 static QByteArray
staticSessionId(WId
);
159 static QByteArray
staticWmCommand(WId
);
160 static QByteArray
staticWmClientMachine(WId
);
161 static Window
staticWmClientLeader(WId
);
162 // when adding new data members, check also copyToDeleted()
168 Damage damage_handle
;
170 QRegion damage_region
; // damage is really damaged window (XDamage) and texture needs
171 QRegion repaints_region
; // updating, repaint just requires repaint of that area
173 EffectWindowImpl
* effect_window
;
174 QByteArray resource_name
;
175 QByteArray resource_class
;
176 QByteArray client_machine
;
177 WId wmClientLeaderWin
;
178 QByteArray window_role
;
180 bool unredirectSuspend
; // when unredirected, but pixmap is needed temporarily
181 // when adding new data members, check also copyToDeleted()
184 inline Window
Toplevel::window() const
189 inline Window
Toplevel::frameId() const
194 inline void Toplevel::setWindowHandles( Window w
, Window f
)
196 assert( client
== None
&& w
!= None
);
198 assert( frame
== None
&& f
!= None
);
202 inline Workspace
* Toplevel::workspace() const
207 inline QRect
Toplevel::geometry() const
212 inline QSize
Toplevel::size() const
217 inline QPoint
Toplevel::pos() const
219 return geom
.topLeft();
222 inline int Toplevel::x() const
227 inline int Toplevel::y() const
232 inline int Toplevel::width() const
237 inline int Toplevel::height() const
239 return geom
.height();
242 inline QRect
Toplevel::rect() const
244 return QRect( 0, 0, width(), height());
247 inline bool Toplevel::readyForPainting() const
249 return ready_for_painting
;
252 inline Visual
* Toplevel::visual() const
257 inline bool Toplevel::isDesktop() const
259 return windowType() == NET::Desktop
;
262 inline bool Toplevel::isDock() const
264 return windowType() == NET::Dock
;
267 inline bool Toplevel::isTopMenu() const
269 return windowType() == NET::TopMenu
;
272 inline bool Toplevel::isMenu() const
274 return windowType() == NET::Menu
&& !isTopMenu(); // because of backwards comp.
277 inline bool Toplevel::isToolbar() const
279 return windowType() == NET::Toolbar
;
282 inline bool Toplevel::isSplash() const
284 return windowType() == NET::Splash
;
287 inline bool Toplevel::isUtility() const
289 return windowType() == NET::Utility
;
292 inline bool Toplevel::isDialog() const
294 return windowType() == NET::Dialog
;
297 inline bool Toplevel::isNormalWindow() const
299 return windowType() == NET::Normal
;
302 inline bool Toplevel::isDropdownMenu() const
304 return windowType() == NET::DropdownMenu
;
307 inline bool Toplevel::isPopupMenu() const
309 return windowType() == NET::PopupMenu
;
312 inline bool Toplevel::isTooltip() const
314 return windowType() == NET::Tooltip
;
317 inline bool Toplevel::isNotification() const
319 return windowType() == NET::Notification
;
322 inline bool Toplevel::isComboBox() const
324 return windowType() == NET::ComboBox
;
327 inline bool Toplevel::isDNDIcon() const
329 return windowType() == NET::DNDIcon
;
332 inline Pixmap
Toplevel::windowPixmap( bool allow_create
)
334 if( window_pix
== None
&& allow_create
)
335 window_pix
= createWindowPixmap();
339 inline QRegion
Toplevel::damage() const
341 return damage_region
;
344 inline QRegion
Toplevel::repaints() const
346 return repaints_region
;
349 inline bool Toplevel::shape() const
354 inline int Toplevel::depth() const
359 inline bool Toplevel::hasAlpha() const
361 return depth() == 32;
365 EffectWindowImpl
* Toplevel::effectWindow()
367 return effect_window
;
370 inline bool Toplevel::isOnAllDesktops() const
372 return desktop() == NET::OnAllDesktops
;
375 inline bool Toplevel::isOnDesktop( int d
) const
377 return desktop() == d
|| /*desk == 0 ||*/ isOnAllDesktops();
380 inline bool Toplevel::isOnCurrentDesktop() const
382 return isOnDesktop( workspace()->currentDesktop());
385 inline QByteArray
Toplevel::resourceName() const
387 return resource_name
; // it is always lowercase
390 inline QByteArray
Toplevel::resourceClass() const
392 return resource_class
; // it is always lowercase
395 inline QByteArray
Toplevel::windowRole() const
400 inline pid_t
Toplevel::pid() const
405 inline bool Toplevel::unredirected() const
410 kdbgstream
& operator<<( kdbgstream
& stream
, const Toplevel
* );
411 kdbgstream
& operator<<( kdbgstream
& stream
, const ToplevelList
& );
412 kdbgstream
& operator<<( kdbgstream
& stream
, const ConstToplevelList
& );
414 KWIN_COMPARE_PREDICATE( WindowMatchPredicate
, Toplevel
, Window
, cl
->window() == value
);
415 KWIN_COMPARE_PREDICATE( FrameIdMatchPredicate
, Toplevel
, Window
, cl
->frameId() == value
);