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 *********************************************************************/
23 #include <kxerrorhandler.h>
32 Toplevel::Toplevel( Workspace
* ws
)
35 , ready_for_painting( true )
41 , damage_handle( None
)
44 , effect_window( NULL
)
45 , wmClientLeaderWin( 0 )
52 assert( damage_handle
== None
);
54 discardWindowPixmap();
58 kdbgstream
& operator<<( kdbgstream
& stream
, const Toplevel
* cl
)
61 return stream
<< "\'NULL\'";
66 kdbgstream
& operator<<( kdbgstream
& stream
, const ToplevelList
& list
)
70 for( ToplevelList::ConstIterator it
= list
.begin();
83 kdbgstream
& operator<<( kdbgstream
& stream
, const ConstToplevelList
& list
)
87 for( ConstToplevelList::ConstIterator it
= list
.begin();
100 void Toplevel::detectShape( Window id
)
102 is_shape
= Extensions::hasShape( id
);
105 // used only by Deleted::copy()
106 void Toplevel::copyToDeleted( Toplevel
* c
)
110 bit_depth
= c
->bit_depth
;
115 window_pix
= c
->window_pix
;
116 ready_for_painting
= c
->ready_for_painting
;
118 damage_handle
= None
;
120 damage_region
= c
->damage_region
;
121 repaints_region
= c
->repaints_region
;
122 is_shape
= c
->is_shape
;
123 effect_window
= c
->effect_window
;
124 if( effect_window
!= NULL
)
125 effect_window
->setWindow( this );
126 resource_name
= c
->resourceName();
127 resource_class
= c
->resourceClass();
128 client_machine
= c
->wmClientMachine( false );
129 wmClientLeaderWin
= c
->wmClientLeader();
130 window_role
= c
->windowRole();
131 // this needs to be done already here, otherwise 'c' could very likely
132 // call discardWindowPixmap() in something called during cleanup
133 c
->window_pix
= None
;
136 // before being deleted, remove references to everything that's now
138 void Toplevel::disownDataPassedToDeleted()
143 NET::WindowType
Toplevel::windowType( bool direct
, int supported_types
) const
145 if( supported_types
== 0 )
146 supported_types
= dynamic_cast< const Client
* >( this ) != NULL
147 ? SUPPORTED_MANAGED_WINDOW_TYPES_MASK
: SUPPORTED_UNMANAGED_WINDOW_TYPES_MASK
;
148 NET::WindowType wt
= info
->windowType( supported_types
);
151 const Client
* cl
= dynamic_cast< const Client
* >( this );
153 // NET::WindowType wt2 = rules()->checkType( wt );
154 NET::WindowType wt2
= wt
;
158 info
->setWindowType( wt
); // force hint change
161 if( wt
== NET::Menu
&& cl
!= NULL
)
163 // ugly hack to support the times when NET::Menu meant NET::TopMenu
164 // if it's as wide as the screen, not very high and has its upper-left
165 // corner a bit above the screen's upper-left cornet, it's a topmenu
166 if( x() == 0 && y() < 0 && y() > -10 && height() < 100
167 && abs( width() - workspace()->clientArea( FullArea
, cl
).width()) < 10 )
170 // TODO change this to rule
171 const char* const oo_prefix
= "openoffice.org"; // QByteArray has no startsWith()
172 // oo_prefix is lowercase, because resourceClass() is forced to be lowercase
173 if( qstrncmp( resourceClass(), oo_prefix
, strlen( oo_prefix
)) == 0 && wt
== NET::Dialog
)
174 wt
= NET::Normal
; // see bug #66065
175 if( wt
== NET::Unknown
&& cl
!= NULL
) // this is more or less suggested in NETWM spec
176 wt
= cl
->isTransient() ? NET::Dialog
: NET::Normal
;
180 void Toplevel::getWindowRole()
182 window_role
= getStringProperty( window(), atoms
->wm_window_role
).toLower();
186 Returns SM_CLIENT_ID property for a given window.
188 QByteArray
Toplevel::staticSessionId(WId w
)
190 return getStringProperty(w
, atoms
->sm_client_id
);
194 Returns WM_COMMAND property for a given window.
196 QByteArray
Toplevel::staticWmCommand(WId w
)
198 return getStringProperty(w
, XA_WM_COMMAND
, ' ');
202 Returns WM_CLIENT_LEADER property for a given window.
204 Window
Toplevel::staticWmClientLeader(WId w
)
208 unsigned long nitems
= 0;
209 unsigned long extra
= 0;
210 unsigned char *data
= 0;
213 status
= XGetWindowProperty( display(), w
, atoms
->wm_client_leader
, 0, 10000,
214 false, XA_WINDOW
, &type
, &format
,
215 &nitems
, &extra
, &data
);
216 if (status
== Success
&& !err
.error( false ))
218 if (data
&& nitems
> 0)
219 result
= *((Window
*) data
);
226 void Toplevel::getWmClientLeader()
228 wmClientLeaderWin
= staticWmClientLeader(window());
232 Returns sessionId for this client,
233 taken either from its window or from the leader window.
235 QByteArray
Toplevel::sessionId()
237 QByteArray result
= staticSessionId(window());
238 if (result
.isEmpty() && wmClientLeaderWin
&& wmClientLeaderWin
!=window())
239 result
= staticSessionId(wmClientLeaderWin
);
244 Returns command property for this client,
245 taken either from its window or from the leader window.
247 QByteArray
Toplevel::wmCommand()
249 QByteArray result
= staticWmCommand(window());
250 if (result
.isEmpty() && wmClientLeaderWin
&& wmClientLeaderWin
!=window())
251 result
= staticWmCommand(wmClientLeaderWin
);
255 void Toplevel::getWmClientMachine()
257 client_machine
= getStringProperty(window(), XA_WM_CLIENT_MACHINE
);
258 if( client_machine
.isEmpty() && wmClientLeaderWin
&& wmClientLeaderWin
!=window())
259 client_machine
= getStringProperty(wmClientLeaderWin
, XA_WM_CLIENT_MACHINE
);
260 if( client_machine
.isEmpty())
261 client_machine
= "localhost";
265 Returns client machine for this client,
266 taken either from its window or from the leader window.
268 QByteArray
Toplevel::wmClientMachine( bool use_localhost
) const
270 QByteArray result
= client_machine
;
272 { // special name for the local machine (localhost)
273 if( result
!= "localhost" && isLocalMachine( result
))
274 result
= "localhost";
280 Returns client leader window for this client.
281 Returns the client window itself if no leader window is defined.
283 Window
Toplevel::wmClientLeader() const
285 if (wmClientLeaderWin
)
286 return wmClientLeaderWin
;
290 void Toplevel::getResourceClass()
292 XClassHint classHint
;
293 if( XGetClassHint( display(), window(), &classHint
) )
295 // Qt3.2 and older had this all lowercase, Qt3.3 capitalized resource class.
296 // Force lowercase, so that workarounds listing resource classes still work.
297 resource_name
= QByteArray( classHint
.res_name
).toLower();
298 resource_class
= QByteArray( classHint
.res_class
).toLower();
299 XFree( classHint
.res_name
);
300 XFree( classHint
.res_class
);
304 resource_name
= resource_class
= QByteArray();
308 double Toplevel::opacity() const
310 if( info
->opacity() == 0xffffffff )
312 return info
->opacity() * 1.0 / 0xffffffff;
315 void Toplevel::setOpacity( double new_opacity
)
317 double old_opacity
= opacity();
318 new_opacity
= qBound( 0.0, new_opacity
, 1.0 );
319 if( old_opacity
== new_opacity
)
321 info
->setOpacity( static_cast< unsigned long >( new_opacity
* 0xffffffff ));
325 scene
->windowOpacityChanged( this );
327 static_cast<EffectsHandlerImpl
*>(effects
)->windowOpacityChanged( effectWindow(), old_opacity
);
333 #include "toplevel.moc"