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 )
47 , unredirectSuspend( false )
54 assert( damage_handle
== None
);
56 discardWindowPixmap();
60 kdbgstream
& operator<<( kdbgstream
& stream
, const Toplevel
* cl
)
63 return stream
<< "\'NULL\'";
68 kdbgstream
& operator<<( kdbgstream
& stream
, const ToplevelList
& list
)
72 for( ToplevelList::ConstIterator it
= list
.begin();
85 kdbgstream
& operator<<( kdbgstream
& stream
, const ConstToplevelList
& list
)
89 for( ConstToplevelList::ConstIterator it
= list
.begin();
102 void Toplevel::detectShape( Window id
)
104 is_shape
= Extensions::hasShape( id
);
107 // used only by Deleted::copy()
108 void Toplevel::copyToDeleted( Toplevel
* c
)
112 bit_depth
= c
->bit_depth
;
117 window_pix
= c
->window_pix
;
118 ready_for_painting
= c
->ready_for_painting
;
120 damage_handle
= None
;
122 damage_region
= c
->damage_region
;
123 repaints_region
= c
->repaints_region
;
124 is_shape
= c
->is_shape
;
125 effect_window
= c
->effect_window
;
126 if( effect_window
!= NULL
)
127 effect_window
->setWindow( this );
128 resource_name
= c
->resourceName();
129 resource_class
= c
->resourceClass();
130 client_machine
= c
->wmClientMachine( false );
131 wmClientLeaderWin
= c
->wmClientLeader();
132 window_role
= c
->windowRole();
133 // this needs to be done already here, otherwise 'c' could very likely
134 // call discardWindowPixmap() in something called during cleanup
135 c
->window_pix
= None
;
138 // before being deleted, remove references to everything that's now
140 void Toplevel::disownDataPassedToDeleted()
145 NET::WindowType
Toplevel::windowType( bool direct
, int supported_types
) const
147 if( supported_types
== 0 )
148 supported_types
= dynamic_cast< const Client
* >( this ) != NULL
149 ? SUPPORTED_MANAGED_WINDOW_TYPES_MASK
: SUPPORTED_UNMANAGED_WINDOW_TYPES_MASK
;
150 NET::WindowType wt
= info
->windowType( supported_types
);
153 const Client
* cl
= dynamic_cast< const Client
* >( this );
157 // NET::WindowType wt2 = rules()->checkType( wt );
158 NET::WindowType wt2
= wt
;
162 info
->setWindowType( wt
); // force hint change
165 if( wt
== NET::Menu
&& cl
!= NULL
)
167 // ugly hack to support the times when NET::Menu meant NET::TopMenu
168 // if it's as wide as the screen, not very high and has its upper-left
169 // corner a bit above the screen's upper-left cornet, it's a topmenu
170 if( x() == 0 && y() < 0 && y() > -10 && height() < 100
171 && abs( width() - workspace()->clientArea( FullArea
, cl
).width()) < 10 )
174 // TODO change this to rule
175 const char* const oo_prefix
= "openoffice.org"; // QByteArray has no startsWith()
176 // oo_prefix is lowercase, because resourceClass() is forced to be lowercase
177 if( qstrncmp( resourceClass(), oo_prefix
, strlen( oo_prefix
)) == 0 && wt
== NET::Dialog
)
178 wt
= NET::Normal
; // see bug #66065
179 if( wt
== NET::Unknown
&& cl
!= NULL
) // this is more or less suggested in NETWM spec
180 wt
= cl
->isTransient() ? NET::Dialog
: NET::Normal
;
184 void Toplevel::getWindowRole()
186 window_role
= getStringProperty( window(), atoms
->wm_window_role
).toLower();
190 Returns SM_CLIENT_ID property for a given window.
192 QByteArray
Toplevel::staticSessionId(WId w
)
194 return getStringProperty(w
, atoms
->sm_client_id
);
198 Returns WM_COMMAND property for a given window.
200 QByteArray
Toplevel::staticWmCommand(WId w
)
202 return getStringProperty(w
, XA_WM_COMMAND
, ' ');
206 Returns WM_CLIENT_LEADER property for a given window.
208 Window
Toplevel::staticWmClientLeader(WId w
)
212 unsigned long nitems
= 0;
213 unsigned long extra
= 0;
214 unsigned char *data
= 0;
217 status
= XGetWindowProperty( display(), w
, atoms
->wm_client_leader
, 0, 10000,
218 false, XA_WINDOW
, &type
, &format
,
219 &nitems
, &extra
, &data
);
220 if (status
== Success
&& !err
.error( false ))
222 if (data
&& nitems
> 0)
223 result
= *((Window
*) data
);
230 void Toplevel::getWmClientLeader()
232 wmClientLeaderWin
= staticWmClientLeader(window());
236 Returns sessionId for this client,
237 taken either from its window or from the leader window.
239 QByteArray
Toplevel::sessionId()
241 QByteArray result
= staticSessionId(window());
242 if (result
.isEmpty() && wmClientLeaderWin
&& wmClientLeaderWin
!=window())
243 result
= staticSessionId(wmClientLeaderWin
);
248 Returns command property for this client,
249 taken either from its window or from the leader window.
251 QByteArray
Toplevel::wmCommand()
253 QByteArray result
= staticWmCommand(window());
254 if (result
.isEmpty() && wmClientLeaderWin
&& wmClientLeaderWin
!=window())
255 result
= staticWmCommand(wmClientLeaderWin
);
259 void Toplevel::getWmClientMachine()
261 client_machine
= getStringProperty(window(), XA_WM_CLIENT_MACHINE
);
262 if( client_machine
.isEmpty() && wmClientLeaderWin
&& wmClientLeaderWin
!=window())
263 client_machine
= getStringProperty(wmClientLeaderWin
, XA_WM_CLIENT_MACHINE
);
264 if( client_machine
.isEmpty())
265 client_machine
= "localhost";
269 Returns client machine for this client,
270 taken either from its window or from the leader window.
272 QByteArray
Toplevel::wmClientMachine( bool use_localhost
) const
274 QByteArray result
= client_machine
;
276 { // special name for the local machine (localhost)
277 if( result
!= "localhost" && isLocalMachine( result
))
278 result
= "localhost";
284 Returns client leader window for this client.
285 Returns the client window itself if no leader window is defined.
287 Window
Toplevel::wmClientLeader() const
289 if (wmClientLeaderWin
)
290 return wmClientLeaderWin
;
294 void Toplevel::getResourceClass()
296 XClassHint classHint
;
297 if( XGetClassHint( display(), window(), &classHint
) )
299 // Qt3.2 and older had this all lowercase, Qt3.3 capitalized resource class.
300 // Force lowercase, so that workarounds listing resource classes still work.
301 resource_name
= QByteArray( classHint
.res_name
).toLower();
302 resource_class
= QByteArray( classHint
.res_class
).toLower();
303 XFree( classHint
.res_name
);
304 XFree( classHint
.res_class
);
308 resource_name
= resource_class
= QByteArray();
312 double Toplevel::opacity() const
314 if( info
->opacity() == 0xffffffff )
316 return info
->opacity() * 1.0 / 0xffffffff;
319 void Toplevel::setOpacity( double new_opacity
)
321 double old_opacity
= opacity();
322 new_opacity
= qBound( 0.0, new_opacity
, 1.0 );
323 if( old_opacity
== new_opacity
)
325 info
->setOpacity( static_cast< unsigned long >( new_opacity
* 0xffffffff ));
329 scene
->windowOpacityChanged( this );
331 static_cast<EffectsHandlerImpl
*>(effects
)->windowOpacityChanged( effectWindow(), old_opacity
);
335 void Toplevel::deleteEffectWindow()
337 delete effect_window
;
338 effect_window
= NULL
;
341 int Toplevel::screen() const
343 if( !options
->xineramaEnabled
)
345 int s
= workspace()->screenNumber( geometry().center());
348 kDebug(1212) << "Invalid screen: Center" << geometry().center() << ", screen" << s
;
354 bool Toplevel::isOnScreen( int screen
) const
356 if( !options
->xineramaEnabled
)
358 return workspace()->screenGeometry( screen
).intersects( geometry());
364 #include "toplevel.moc"