• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
twinmodule.cpp
1 /*
2  $Id$
3 
4  This file is part of the KDE libraries
5  Copyright (C) 1999 Matthias Ettrich (ettrich@kde.org)
6 
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public
10  License as published by the Free Software Foundation; either
11  version 2 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public License
19  along with this library; see the file COPYING.LIB. If not, write to
20  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #include <tqwidget.h>
25 #ifdef Q_WS_X11 //FIXME
26 #include "twinmodule.h"
27 #include "twin.h"
28 #include <X11/Xatom.h>
29 #include "tdeapplication.h"
30 #include "kdebug.h"
31 #include <tqtl.h>
32 #include <tqptrlist.h>
33 #include <tdelocale.h>
34 #include <dcopclient.h>
35 #include "netwm.h"
36 
37 static KWinModulePrivate* static_d = 0;
38 
39 static unsigned long windows_properties[ 2 ] = { NET::ClientList | NET::ClientListStacking |
40  NET::NumberOfDesktops |
41  NET::DesktopGeometry |
42  NET::DesktopViewport |
43  NET::CurrentDesktop |
44  NET::DesktopNames |
45  NET::ActiveWindow |
46  NET::WorkArea |
47  NET::KDESystemTrayWindows,
48  NET::WM2ShowingDesktop };
49 
50 static unsigned long desktop_properties[ 2 ] = {
51  NET::NumberOfDesktops |
52  NET::DesktopGeometry |
53  NET::DesktopViewport |
54  NET::CurrentDesktop |
55  NET::DesktopNames |
56  NET::ActiveWindow |
57  NET::WorkArea |
58  NET::KDESystemTrayWindows,
59  NET::WM2ShowingDesktop };
60 
61 class KWinModulePrivate : public TQWidget, public NETRootInfo4
62 {
63 public:
64  KWinModulePrivate(int _what)
65  : TQWidget(0,0), NETRootInfo4( tqt_xdisplay(),
66  _what >= KWinModule::INFO_WINDOWS ?
67  windows_properties : desktop_properties,
68  2,
69  -1, false
70  ),
71  strutSignalConnected( false ),
72  what( _what )
73  {
74  kapp->installX11EventFilter( this );
75  (void ) kapp->desktop(); //trigger desktop widget creation to select root window events
76  activate();
77  updateStackingOrder();
78  }
79  ~KWinModulePrivate()
80  {
81  }
82  TQPtrList<KWinModule> modules;
83 
84  TQValueList<WId> windows;
85  TQValueList<WId> stackingOrder;
86  TQValueList<WId> systemTrayWindows;
87 
88  struct StrutData
89  {
90  StrutData( WId window_, const NETStrut& strut_, int desktop_ )
91  : window( window_ ), strut( strut_ ), desktop( desktop_ ) {};
92  StrutData() {}; // for TQValueList to be happy
93  WId window;
94  NETStrut strut;
95  int desktop;
96  };
97  TQValueList<StrutData> strutWindows;
98  TQValueList<WId> possibleStrutWindows;
99  bool strutSignalConnected;
100  int what;
101 
102  void addClient(Window);
103  void removeClient(Window);
104  void addSystemTrayWin(Window);
105  void removeSystemTrayWin(Window);
106 
107  bool x11Event( XEvent * ev );
108 
109  void updateStackingOrder();
110  bool removeStrutWindow( WId );
111 
112  TQSize numberOfViewports(int desktop) const;
113  TQPoint currentViewport(int desktop) const;
114 };
115 
116 KWinModule::KWinModule( TQObject* parent )
117  : TQObject( parent, "twin_module" )
118 {
119  init(INFO_ALL);
120 }
121 
122 KWinModule::KWinModule( TQObject* parent, int what )
123  : TQObject( parent, "twin_module" )
124 {
125  init(what);
126 }
127 
128 void KWinModule::init(int what)
129 {
130  if (what >= INFO_WINDOWS)
131  what = INFO_WINDOWS;
132  else
133  what = INFO_DESKTOP;
134 
135  if ( !static_d )
136  {
137  static_d = new KWinModulePrivate(what);
138  }
139  else if (static_d->what < what)
140  {
141  TQPtrList<KWinModule> modules = static_d->modules;
142  delete static_d;
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;
147  }
148 
149  d = static_d;
150  d->modules.append( this );
151 }
152 
153 KWinModule::~KWinModule()
154 {
155  d->modules.removeRef( this );
156  if ( d->modules.isEmpty() ) {
157  delete d;
158  static_d = 0;
159  }
160 }
161 
162 const TQValueList<WId>& KWinModule::windows() const
163 {
164  return d->windows;
165 }
166 
167 const TQValueList<WId>& KWinModule::stackingOrder() const
168 {
169  return d->stackingOrder;
170 }
171 
172 
173 bool KWinModule::hasWId(WId w) const
174 {
175  return d->windows.findIndex( w ) != -1;
176 }
177 
178 const TQValueList<WId>& KWinModule::systemTrayWindows() const
179 {
180  return d->systemTrayWindows;
181 }
182 
183 TQSize KWinModulePrivate::numberOfViewports(int desktop) const
184 {
185  NETSize netdesktop = desktopGeometry(desktop);
186  TQSize s(netdesktop.width / TQApplication::desktop()->width(),
187  netdesktop.height / TQApplication::desktop()->height());
188 
189  // workaround some twin bugs
190  if (s.width() < 1) s.setWidth(1);
191  if (s.height() < 1) s.setHeight(1);
192  return s;
193 }
194 
195 TQPoint KWinModulePrivate::currentViewport(int desktop) const
196 {
197  NETPoint netviewport = desktopViewport(desktop);
198 
199  return TQPoint(1+(netviewport.x / TQApplication::desktop()->width()),
200  1+(netviewport.y / TQApplication::desktop()->height()));
201 }
202 
203 bool KWinModulePrivate::x11Event( XEvent * ev )
204 {
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 );
212 
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()));
223  }
224  if ( m[ PROTOCOLS ] & DesktopGeometry ) {
225  for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
226  emit (*mit)->desktopGeometryChanged(currentDesktop());
227  }
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();
241  }
242  if(( m[ PROTOCOLS2 ] & WM2ShowingDesktop ) && showingDesktop() != old_showing_desktop ) {
243  for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
244  emit (*mit)->showingDesktopChanged( showingDesktop());
245  }
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; // support for old icons
253  else if( ev->xproperty.atom == XA_WM_NAME )
254  dirty[ NETWinInfo::PROTOCOLS ] |= NET::WMName; // support for old name
255  else if( ev->xproperty.atom == XA_WM_ICON_NAME )
256  dirty[ NETWinInfo::PROTOCOLS ] |= NET::WMIconName; // support for old iconic name
257  }
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 );
262  }
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();
270  }
271  }
272  }
273 
274  return false;
275 }
276 
277 bool KWinModulePrivate::removeStrutWindow( WId w )
278 {
279  for( TQValueList< StrutData >::Iterator it = strutWindows.begin();
280  it != strutWindows.end();
281  ++it )
282  if( (*it).window == w ) {
283  strutWindows.remove( it );
284  return true;
285  }
286  return false;
287 }
288 
289 void KWinModulePrivate::updateStackingOrder()
290 {
291  stackingOrder.clear();
292  for ( int i = 0; i < clientListStackingCount(); i++ )
293  stackingOrder.append( clientListStacking()[i] );
294 }
295 
296 void KWinModulePrivate::addClient(Window w)
297 {
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 );
303  NETStrut strut = info.strut();
304  if ( strut.left || strut.top || strut.right || strut.bottom ) {
305  strutWindows.append( StrutData( w, strut, info.desktop()));
306  emit_strutChanged = true;
307  }
308  } else
309  possibleStrutWindows.append( w );
310  windows.append( w );
311  for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit ) {
312  emit (*mit)->windowAdded( w );
313  if ( emit_strutChanged )
314  emit (*mit)->strutChanged();
315  }
316 }
317 
318 void KWinModulePrivate::removeClient(Window w)
319 {
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 );
323  NETStrut strut = info.strut();
324  if ( strut.left || strut.top || strut.right || strut.bottom ) {
325  emit_strutChanged = true;
326  }
327  }
328  possibleStrutWindows.remove( w );
329  windows.remove( w );
330  for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit ) {
331  emit (*mit)->windowRemoved( w );
332  if ( emit_strutChanged )
333  emit (*mit)->strutChanged();
334  }
335 }
336 
337 void KWinModulePrivate::addSystemTrayWin(Window w)
338 {
339  systemTrayWindows.append( w );
340  for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
341  emit (*mit)->systemTrayWindowAdded( w );
342 }
343 
344 void KWinModulePrivate::removeSystemTrayWin(Window w)
345 {
346  systemTrayWindows.remove( w );
347  for ( TQPtrListIterator<KWinModule> mit( modules ); mit.current(); ++mit )
348  emit (*mit)->systemTrayWindowRemoved( w );
349 }
350 
351 int KWinModule::currentDesktop() const
352 {
353  return d->currentDesktop();
354 }
355 
356 int KWinModule::numberOfDesktops() const
357 {
358  return d->numberOfDesktops();
359 }
360 
361 TQSize KWinModule::numberOfViewports(int desktop) const
362 {
363  return d->numberOfViewports(desktop);
364 }
365 
366 TQPoint KWinModule::currentViewport(int desktop) const
367 {
368  return d->currentViewport(desktop);
369 }
370 
371 WId KWinModule::activeWindow() const
372 {
373  return d->activeWindow();
374 }
375 
376 bool KWinModule::showingDesktop() const
377 {
378  return d->showingDesktop();
379 }
380 
381 TQRect KWinModule::workArea( int desktop ) const
382 {
383  int desk = (desktop > 0 && desktop <= (int) d->numberOfDesktops() ) ? desktop : currentDesktop();
384  if ( desk <= 0 )
385  return TQApplication::desktop()->geometry();
386  NETRect r = d->workArea( desk );
387  if( r.size.width <= 0 || r.size.height <= 0 ) // not set
388  return TQApplication::desktop()->geometry();
389  return TQRect( r.pos.x, r.pos.y, r.size.width, r.size.height );
390 }
391 
392 TQRect KWinModule::workArea( const TQValueList<WId>& exclude, int desktop ) const
393 {
394  TQRect all = TQApplication::desktop()->geometry();
395  TQRect a = all;
396 
397  if (desktop == -1)
398  desktop = d->currentDesktop();
399 
400  TQValueList<WId>::ConstIterator it1;
401  for( it1 = d->windows.begin(); it1 != d->windows.end(); ++it1 ) {
402 
403  if(exclude.findIndex(*it1) != -1) continue;
404 
405 // Kicker (very) extensively calls this function, causing hundreds of roundtrips just
406 // to repeatedly find out struts of all windows. Therefore strut values for strut
407 // windows are cached here.
408  NETStrut strut;
409  TQValueList< KWinModulePrivate::StrutData >::Iterator it2 = d->strutWindows.begin();
410  for( ;
411  it2 != d->strutWindows.end();
412  ++it2 )
413  if( (*it2).window == *it1 )
414  break;
415  if( it2 != d->strutWindows.end()) {
416  if(!((*it2).desktop == desktop || (*it2).desktop == NETWinInfo::OnAllDesktops ))
417  continue;
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))
425  continue;
426  } else
427  continue; // not a strut window
428 
429  TQRect r = all;
430  if ( strut.left > 0 )
431  r.setLeft( r.left() + (int) strut.left );
432  if ( strut.top > 0 )
433  r.setTop( r.top() + (int) strut.top );
434  if ( strut.right > 0 )
435  r.setRight( r.right() - (int) strut.right );
436  if ( strut.bottom > 0 )
437  r.setBottom( r.bottom() - (int) strut.bottom );
438 
439  TQRect tmp;
440  tmp = a.intersect(r);
441  a = tmp;
442  }
443  return a;
444 }
445 
446 void KWinModule::connectNotify( const char* signal )
447 {
448  if( !d->strutSignalConnected && qstrcmp( signal, TQT_SIGNAL(strutChanged())) == 0 )
449  d->strutSignalConnected = true;
450  TQObject::connectNotify( signal );
451 }
452 
453 TQString KWinModule::desktopName( int desktop ) const
454 {
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 );
459 }
460 
461 void KWinModule::setDesktopName( int desktop, const TQString& name )
462 {
463  if (desktop <= 0 || desktop > (int) d->numberOfDesktops() )
464  desktop = currentDesktop();
465  d->setDesktopName( desktop, name.utf8().data() );
466 }
467 
468 
469 void KWinModule::doNotManage( const TQString& title )
470 {
471  if ( !kapp->dcopClient()->isAttached() )
472  kapp->dcopClient()->attach();
473  TQByteArray data, replyData;
474  TQCString replyType;
475  TQDataStream arg(data, IO_WriteOnly);
476  arg << title;
477  kapp->dcopClient()->call("twin", "", "doNotManage(TQString)",
478  data, replyType, replyData);
479 }
480 
481 #include "twinmodule.moc"
482 #endif
KWinModule::workArea
TQRect workArea(int desktop=-1) const
Returns the workarea for the specified desktop, or the current work area if no desktop has been speci...
NETStrut
Definition: netwm_def.h:195
NETStrut::bottom
int bottom
Bottom border of the strut.
Definition: netwm_def.h:219
KWinModule::setDesktopName
void setDesktopName(int desktop, const TQString &name)
Sets the name of the specified desktop.
NETStrut::right
int right
Right border of the strut.
Definition: netwm_def.h:209
NET::WM2ShowingDesktop
Definition: netwm_def.h:612
KWinModule::hasWId
bool hasWId(WId id) const
Test to see if id still managed at present.
NETPoint::y
int y
y coordinate
Definition: netwm_def.h:53
KWinModule::currentDesktop
int currentDesktop() const
Returns the current virtual desktop.
KWinModule::systemTrayWindows
const TQValueList< WId > & systemTrayWindows() const
Returns a list of the system tray windows.
NETStrut::left
int left
Left border of the strut.
Definition: netwm_def.h:204
NETRect::size
NETSize size
Size of the rectangle.
Definition: netwm_def.h:107
KWinModule::currentViewport
TQPoint currentViewport(int desktop) const
Returns the current viewport on the given virtual desktop.
KWinModule
The class KWinModule provides information about the state of the window manager as required by window...
Definition: twinmodule.h:56
tdelocale.h
NETPoint::x
int x
x coordinate.
Definition: netwm_def.h:53
KWin::Info::strut
NETStrut strut
The strut.
Definition: twin.h:480
KWinModule::stackingOrder
const TQValueList< WId > & stackingOrder() const
Returns the list of all toplevel windows currently managed by the window manager in the current stack...
NETRect::pos
NETPoint pos
Position of the rectangle.
Definition: netwm_def.h:100
KWinModule::numberOfDesktops
int numberOfDesktops() const
Returns the number of virtual desktops.
NETPoint
Simple point class for NET classes.
Definition: netwm_def.h:44
KWin::info
static Info info(WId win) KDE_DEPRECATED
Definition: twin.cpp:347
KWin::numberOfDesktops
static int numberOfDesktops()
Convenience function to access the number of desktops.
Definition: twin.cpp:653
KStdAction::name
const char * name(StdAction id)
NETRect
Simple rectangle class for NET classes.
Definition: netwm_def.h:94
KWinModule::activeWindow
WId activeWindow() const
Returns the currently active window, or 0 if no window is active.
KWin::currentDesktop
static int currentDesktop()
Convenience function to access the current desktop.
Definition: twin.cpp:641
KWinModule::showingDesktop
bool showingDesktop() const
Returns the state of showing the desktop.
KWinModule::KWinModule
KWinModule(TQObject *parent, int what)
Creates a KWinModule object and connects to the window manager.
NETSize::width
int width
Width.
Definition: netwm_def.h:80
NETSize::height
int height
Height.
Definition: netwm_def.h:80
KWinModule::numberOfViewports
TQSize numberOfViewports(int desktop) const
Returns the number of viewports in x and y direction on the virtual desktop.
KWinModule::desktopName
TQString desktopName(int desktop) const
Returns the name of the specified desktop.
KWinModule::windows
const TQValueList< WId > & windows() const
Returns the list of all toplevel windows currently managed by the window manager in the order of crea...
KWinModule::~KWinModule
~KWinModule()
Destructor.
NETStrut::top
int top
Top border of the strut.
Definition: netwm_def.h:214
KWin::Info::desktop
int desktop
The number of the window's desktop.
Definition: twin.h:488
NETSize
Simple size class for NET classes.
Definition: netwm_def.h:71
KWinModule::doNotManage
void doNotManage(const TQString &title)
Informs twin via dcop to not manage a window with the specified title.

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.