26 #include "twinmodule.h"
28 #include <X11/Xatom.h>
29 #include "tdeapplication.h"
32 #include <tqptrlist.h>
34 #include <dcopclient.h>
37 static KWinModulePrivate* static_d = 0;
39 static unsigned long windows_properties[ 2 ] = { NET::ClientList | NET::ClientListStacking |
40 NET::NumberOfDesktops |
41 NET::DesktopGeometry |
42 NET::DesktopViewport |
47 NET::KDESystemTrayWindows,
50 static unsigned long desktop_properties[ 2 ] = {
51 NET::NumberOfDesktops |
52 NET::DesktopGeometry |
53 NET::DesktopViewport |
58 NET::KDESystemTrayWindows,
61 class KWinModulePrivate :
public TQWidget,
public NETRootInfo4
64 KWinModulePrivate(
int _what)
65 : TQWidget(0,0), NETRootInfo4( tqt_xdisplay(),
67 windows_properties : desktop_properties,
71 strutSignalConnected( false ),
74 kapp->installX11EventFilter(
this );
75 (void ) kapp->desktop();
77 updateStackingOrder();
82 TQPtrList<KWinModule> modules;
84 TQValueList<WId> windows;
85 TQValueList<WId> stackingOrder;
86 TQValueList<WId> systemTrayWindows;
90 StrutData( WId window_,
const NETStrut& strut_,
int desktop_ )
91 : window( window_ ), strut( strut_ ), desktop( desktop_ ) {};
97 TQValueList<StrutData> strutWindows;
98 TQValueList<WId> possibleStrutWindows;
99 bool strutSignalConnected;
102 void addClient(Window);
103 void removeClient(Window);
104 void addSystemTrayWin(Window);
105 void removeSystemTrayWin(Window);
107 bool x11Event( XEvent * ev );
109 void updateStackingOrder();
110 bool removeStrutWindow( WId );
112 TQSize numberOfViewports(
int desktop)
const;
113 TQPoint currentViewport(
int desktop)
const;
117 : TQObject( parent,
"twin_module" )
123 : TQObject( parent,
"twin_module" )
128 void KWinModule::init(
int what)
130 if (what >= INFO_WINDOWS)
137 static_d =
new KWinModulePrivate(what);
139 else if (static_d->what < what)
141 TQPtrList<KWinModule> modules = static_d->modules;
143 static_d =
new KWinModulePrivate(what);
144 static_d->modules = modules;
145 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
146 (*mit)->d = static_d;
150 d->modules.append(
this );
155 d->modules.removeRef(
this );
156 if ( d->modules.isEmpty() ) {
169 return d->stackingOrder;
175 return d->windows.findIndex( w ) != -1;
180 return d->systemTrayWindows;
183 TQSize KWinModulePrivate::numberOfViewports(
int desktop)
const
185 NETSize netdesktop = desktopGeometry(desktop);
186 TQSize s(netdesktop.
width / TQApplication::desktop()->width(),
187 netdesktop.
height / TQApplication::desktop()->height());
190 if (s.width() < 1) s.setWidth(1);
191 if (s.height() < 1) s.setHeight(1);
195 TQPoint KWinModulePrivate::currentViewport(
int desktop)
const
197 NETPoint netviewport = desktopViewport(desktop);
199 return TQPoint(1+(netviewport.
x / TQApplication::desktop()->width()),
200 1+(netviewport.
y / TQApplication::desktop()->height()));
203 bool KWinModulePrivate::x11Event( XEvent * ev )
205 if ( ev->xany.window == tqt_xrootwin() ) {
206 int old_current_desktop = currentDesktop();
207 WId old_active_window = activeWindow();
208 int old_number_of_desktops = numberOfDesktops();
209 bool old_showing_desktop = showingDesktop();
210 unsigned long m[ 5 ];
211 NETRootInfo::event( ev, m, 5 );
213 if (( m[ PROTOCOLS ] & CurrentDesktop ) && currentDesktop() != old_current_desktop )
214 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
215 emit (*mit)->currentDesktopChanged( currentDesktop() );
216 if (( m[ PROTOCOLS ] & ActiveWindow ) && activeWindow() != old_active_window )
217 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
218 emit (*mit)->activeWindowChanged( activeWindow() );
219 if ( m[ PROTOCOLS ] & DesktopViewport ) {
220 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
221 emit (*mit)->currentDesktopViewportChanged(currentDesktop(),
222 currentViewport(currentDesktop()));
224 if ( m[ PROTOCOLS ] & DesktopGeometry ) {
225 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
226 emit (*mit)->desktopGeometryChanged(currentDesktop());
228 if ( m[ PROTOCOLS ] & DesktopNames )
229 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
230 emit (*mit)->desktopNamesChanged();
231 if (( m[ PROTOCOLS ] & NumberOfDesktops ) && numberOfDesktops() != old_number_of_desktops )
232 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
233 emit (*mit)->numberOfDesktopsChanged( numberOfDesktops() );
234 if ( m[ PROTOCOLS ] & WorkArea )
235 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
236 emit (*mit)->workAreaChanged();
237 if ( m[ PROTOCOLS ] & ClientListStacking ) {
238 updateStackingOrder();
239 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
240 emit (*mit)->stackingOrderChanged();
242 if(( m[ PROTOCOLS2 ] & WM2ShowingDesktop ) && showingDesktop() != old_showing_desktop ) {
243 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
244 emit (*mit)->showingDesktopChanged( showingDesktop());
246 }
else if ( windows.findIndex( ev->xany.window ) != -1 ){
247 NETWinInfo ni( tqt_xdisplay(), ev->xany.window, tqt_xrootwin(), 0 );
248 unsigned long dirty[ 2 ];
249 ni.event( ev, dirty, 2 );
250 if ( ev->type ==PropertyNotify ) {
251 if( ev->xproperty.atom == XA_WM_HINTS )
252 dirty[ NETWinInfo::PROTOCOLS ] |= NET::WMIcon;
253 else if( ev->xproperty.atom == XA_WM_NAME )
254 dirty[ NETWinInfo::PROTOCOLS ] |= NET::WMName;
255 else if( ev->xproperty.atom == XA_WM_ICON_NAME )
256 dirty[ NETWinInfo::PROTOCOLS ] |= NET::WMIconName;
258 if ( (dirty[ NETWinInfo::PROTOCOLS ] & NET::WMStrut) != 0 ) {
259 removeStrutWindow( ev->xany.window );
260 if ( possibleStrutWindows.findIndex( ev->xany.window ) == -1 )
261 possibleStrutWindows.append( ev->xany.window );
263 if ( dirty[ NETWinInfo::PROTOCOLS ] || dirty[ NETWinInfo::PROTOCOLS2 ] ) {
264 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit ) {
265 emit (*mit)->windowChanged( ev->xany.window );
266 emit (*mit)->windowChanged( ev->xany.window, dirty );
267 emit (*mit)->windowChanged( ev->xany.window, dirty[ NETWinInfo::PROTOCOLS ] );
268 if ( (dirty[ NETWinInfo::PROTOCOLS ] & NET::WMStrut) != 0 )
269 emit (*mit)->strutChanged();
277 bool KWinModulePrivate::removeStrutWindow( WId w )
279 for( TQValueList< StrutData >::Iterator it = strutWindows.begin();
280 it != strutWindows.end();
282 if( (*it).window == w ) {
283 strutWindows.remove( it );
289 void KWinModulePrivate::updateStackingOrder()
291 stackingOrder.clear();
292 for (
int i = 0; i < clientListStackingCount(); i++ )
293 stackingOrder.append( clientListStacking()[i] );
296 void KWinModulePrivate::addClient(Window w)
298 if ( (what >= KWinModule::INFO_WINDOWS) && !TQWidget::find( w ) )
299 XSelectInput( tqt_xdisplay(), w, PropertyChangeMask | StructureNotifyMask );
300 bool emit_strutChanged =
false;
301 if( strutSignalConnected && modules.count() > 0 ) {
302 NETWinInfo info( tqt_xdisplay(), w, tqt_xrootwin(), NET::WMStrut | NET::WMDesktop );
305 strutWindows.append( StrutData( w, strut, info.desktop()));
306 emit_strutChanged =
true;
309 possibleStrutWindows.append( w );
311 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit ) {
312 emit (*mit)->windowAdded( w );
313 if ( emit_strutChanged )
314 emit (*mit)->strutChanged();
318 void KWinModulePrivate::removeClient(Window w)
320 bool emit_strutChanged = removeStrutWindow( w );
321 if( strutSignalConnected && possibleStrutWindows.findIndex( w ) != -1 && modules.count() > 0 ) {
322 NETWinInfo info( tqt_xdisplay(), w, tqt_xrootwin(), NET::WMStrut );
325 emit_strutChanged =
true;
328 possibleStrutWindows.remove( w );
330 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit ) {
331 emit (*mit)->windowRemoved( w );
332 if ( emit_strutChanged )
333 emit (*mit)->strutChanged();
337 void KWinModulePrivate::addSystemTrayWin(Window w)
339 systemTrayWindows.append( w );
340 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
341 emit (*mit)->systemTrayWindowAdded( w );
344 void KWinModulePrivate::removeSystemTrayWin(Window w)
346 systemTrayWindows.remove( w );
347 for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
348 emit (*mit)->systemTrayWindowRemoved( w );
353 return d->currentDesktop();
358 return d->numberOfDesktops();
363 return d->numberOfViewports(desktop);
368 return d->currentViewport(desktop);
373 return d->activeWindow();
378 return d->showingDesktop();
383 int desk = (desktop > 0 && desktop <= (int) d->numberOfDesktops() ) ? desktop :
currentDesktop();
385 return TQApplication::desktop()->geometry();
386 NETRect r = d->workArea( desk );
388 return TQApplication::desktop()->geometry();
394 TQRect all = TQApplication::desktop()->geometry();
398 desktop = d->currentDesktop();
400 TQValueList<WId>::ConstIterator it1;
401 for( it1 = d->windows.begin(); it1 != d->windows.end(); ++it1 ) {
403 if(exclude.findIndex(*it1) != -1)
continue;
409 TQValueList< KWinModulePrivate::StrutData >::Iterator it2 = d->strutWindows.begin();
411 it2 != d->strutWindows.end();
413 if( (*it2).window == *it1 )
415 if( it2 != d->strutWindows.end()) {
416 if(!((*it2).desktop == desktop || (*it2).desktop == NETWinInfo::OnAllDesktops ))
418 strut = (*it2).strut;
419 }
else if( d->possibleStrutWindows.findIndex( *it1 ) != -1 ) {
420 NETWinInfo info( tqt_xdisplay(), (*it1), tqt_xrootwin(), NET::WMStrut | NET::WMDesktop);
421 strut = info.strut();
422 d->possibleStrutWindows.remove( *it1 );
423 d->strutWindows.append( KWinModulePrivate::StrutData( *it1, info.strut(), info.desktop()));
424 if(!(info.desktop() == desktop || info.desktop() == NETWinInfo::OnAllDesktops))
430 if ( strut.
left > 0 )
431 r.setLeft( r.left() + (
int) strut.
left );
433 r.setTop( r.top() + (
int) strut.
top );
434 if ( strut.
right > 0 )
435 r.setRight( r.right() - (
int) strut.
right );
437 r.setBottom( r.bottom() - (
int) strut.
bottom );
440 tmp = a.intersect(r);
446 void KWinModule::connectNotify(
const char* signal )
448 if( !d->strutSignalConnected && qstrcmp( signal, TQ_SIGNAL(
strutChanged())) == 0 )
449 d->strutSignalConnected =
true;
450 TQObject::connectNotify( signal );
455 const char*
name = d->desktopName( (desktop > 0 && desktop <= (
int) d->numberOfDesktops() ) ? desktop :
currentDesktop() );
456 if ( name && name[0] )
457 return TQString::fromUtf8( name );
458 return i18n(
"Desktop %1").arg( desktop );
463 if (desktop <= 0 || desktop > (
int) d->numberOfDesktops() )
465 d->setDesktopName( desktop,
name.utf8().data() );
471 if ( !kapp->dcopClient()->isAttached() )
472 kapp->dcopClient()->attach();
473 TQByteArray data, replyData;
475 TQDataStream arg(data, IO_WriteOnly);
477 kapp->dcopClient()->call(
"twin",
"",
"doNotManage(TQString)",
478 data, replyType, replyData);
481 #include "twinmodule.moc"
The class KWinModule provides information about the state of the window manager as required by window...
TQPoint currentViewport(int desktop) const
Returns the current viewport on the given virtual desktop.
int numberOfDesktops() const
Returns the number of virtual desktops.
void strutChanged()
Something changed with the struts, may or may not have changed the work area.
TQRect workArea(int desktop=- 1) const
Returns the workarea for the specified desktop, or the current work area if no desktop has been speci...
WId activeWindow() const
Returns the currently active window, or 0 if no window is active.
void doNotManage(const TQString &title)
Informs twin via dcop to not manage a window with the specified title.
KWinModule(TQObject *parent, int what)
Creates a KWinModule object and connects to the window manager.
const TQValueList< WId > & systemTrayWindows() const
Returns a list of the system tray windows.
const TQValueList< WId > & stackingOrder() const
Returns the list of all toplevel windows currently managed by the window manager in the current stack...
bool showingDesktop() const
Returns the state of showing the desktop.
const TQValueList< WId > & windows() const
Returns the list of all toplevel windows currently managed by the window manager in the order of crea...
bool hasWId(WId id) const
Test to see if id still managed at present.
int currentDesktop() const
Returns the current virtual desktop.
void setDesktopName(int desktop, const TQString &name)
Sets the name of the specified desktop.
TQSize numberOfViewports(int desktop) const
Returns the number of viewports in x and y direction on the virtual desktop.
TQString desktopName(int desktop) const
Returns the name of the specified desktop.
const char * name(StdAction id)
Simple point class for NET classes.
Simple rectangle class for NET classes.
NETPoint pos
Position of the rectangle.
NETSize size
Size of the rectangle.
Simple size class for NET classes.
int bottom
Bottom border of the strut.
int left
Left border of the strut.
int right
Right border of the strut.
int top
Top border of the strut.