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

twin

  • twin
manage.cpp
1 /*****************************************************************
2  KWin - the KDE window manager
3  This file is part of the KDE project.
4 
5 Copyright (C) 1999, 2000 Matthias Ettrich <ettrich@kde.org>
6 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
7 
8 You can Freely distribute this program under the GNU General Public
9 License. See the file "COPYING" for the exact licensing terms.
10 ******************************************************************/
11 
12 /*
13 
14  This file contains things relevant to handling incoming events.
15 
16 */
17 
18 #include "client.h"
19 
20 #include <tdestartupinfo.h>
21 #include <tdeglobal.h>
22 #include <X11/extensions/shape.h>
23 
24 #include "notifications.h"
25 #include "rules.h"
26 #include "group.h"
27 
28 namespace KWinInternal
29 {
30 
36 bool Client::manage( Window w, bool isMapped )
37  {
38  XWindowAttributes attr;
39  if( !XGetWindowAttributes(tqt_xdisplay(), w, &attr))
40  return false;
41 
42  grabXServer();
43 
44  // from this place on, manage() mustn't return false
45  postpone_geometry_updates = 1;
46  pending_geometry_update = true; // force update when finishing with geometry changes
47 
48  embedClient( w, attr );
49 
50  // SELI order all these things in some sane manner
51 
52  bool init_minimize = false;
53  XWMHints * hints = XGetWMHints(tqt_xdisplay(), w );
54  if (hints && (hints->flags & StateHint) && hints->initial_state == IconicState)
55  init_minimize = true;
56  if (hints)
57  XFree(hints);
58  if( isMapped )
59  init_minimize = false; // if it's already mapped, ignore hint
60 
61  unsigned long properties[ 2 ];
62  properties[ WinInfo::PROTOCOLS ] =
63  NET::WMDesktop |
64  NET::WMState |
65  NET::WMWindowType |
66  NET::WMStrut |
67  NET::WMName |
68  NET::WMIconGeometry |
69  NET::WMIcon |
70  NET::WMPid |
71  NET::WMIconName |
72  0;
73  properties[ WinInfo::PROTOCOLS2 ] =
74  NET::WM2UserTime |
75  NET::WM2StartupId |
76  NET::WM2ExtendedStrut |
77  0;
78 
79  info = new WinInfo( this, tqt_xdisplay(), client, tqt_xrootwin(), properties, 2 );
80 
81  cmap = attr.colormap;
82 
83  XClassHint classHint;
84  if ( XGetClassHint( tqt_xdisplay(), client, &classHint ) )
85  {
86  // Qt3.2 and older had this all lowercase, Qt3.3 capitalized resource class
87  // force lowercase, so that workarounds listing resource classes still work
88  resource_name = TQCString( classHint.res_name ).lower();
89  resource_class = TQCString( classHint.res_class ).lower();
90  XFree( classHint.res_name );
91  XFree( classHint.res_class );
92  }
93  ignore_focus_stealing = options->checkIgnoreFocusStealing( this ); // TODO change to rules
94 
95  window_role = staticWindowRole( w );
96  getWmClientLeader();
97  getWmClientMachine();
98  // first only read the caption text, so that setupWindowRules() can use it for matching,
99  // and only then really set the caption using setCaption(), which checks for duplicates etc.
100  // and also relies on rules already existing
101  cap_normal = readName();
102  setupWindowRules( false );
103  setCaption( cap_normal, true );
104 
105  detectNoBorder();
106  detectShapable();
107  fetchIconicName();
108  getWMHints(); // needs to be done before readTransient() because of reading the group
109  modal = ( info->state() & NET::Modal ) != 0; // needs to be valid before handling groups
110  readTransient();
111  getIcons();
112  getWindowProtocols();
113  getWmNormalHints(); // get xSizeHint
114  getMotifHints();
115 
116  // TODO try to obey all state information from info->state()
117 
118  original_skip_taskbar = skip_taskbar = ( info->state() & NET::SkipTaskbar) != 0;
119  skip_pager = ( info->state() & NET::SkipPager) != 0;
120 
121  TDEStartupInfoId asn_id;
122  TDEStartupInfoData asn_data;
123  bool asn_valid = workspace()->checkStartupNotification( window(), asn_id, asn_data );
124 
125  workspace()->updateClientLayer( this );
126 
127  SessionInfo* session = workspace()->takeSessionInfo( this );
128 
129  if ( session )
130  {
131  if ( session->minimized )
132  init_minimize = true;
133  setUserNoBorder( session->userNoBorder , session->userNoBorderForced );
134  }
135  else
136  {
137  setUserNoBorder( false, false );
138  }
139 
140  setShortcut( rules()->checkShortcut( session ? session->shortcut : TQString::null, true ));
141 
142  init_minimize = rules()->checkMinimize( init_minimize, !isMapped );
143 
144 
145  checkAndSetInitialRuledOpacity();
146 
147  // initial desktop placement
148  if ( session )
149  {
150  desk = session->desktop;
151  if( session->onAllDesktops )
152  desk = NET::OnAllDesktops;
153  }
154  else
155  {
156  // if this window is transient, ensure that it is opened on the
157  // same window as its parent. this is necessary when an application
158  // starts up on a different desktop than is currently displayed
159  if( isTransient())
160  {
161  ClientList mainclients = mainClients();
162  bool on_current = false;
163  Client* maincl = NULL;
164  // this is slightly duplicated from Placement::placeOnMainWindow()
165  for( ClientList::ConstIterator it = mainclients.begin();
166  it != mainclients.end();
167  ++it )
168  {
169  if( mainclients.count() > 1 && (*it)->isSpecialWindow())
170  continue; // don't consider toolbars etc when placing
171  maincl = *it;
172  if( (*it)->isOnCurrentDesktop())
173  on_current = true;
174  }
175  if( on_current )
176  desk = workspace()->currentDesktop();
177  else if( maincl != NULL )
178  desk = maincl->desktop();
179  }
180  if ( info->desktop() )
181  desk = info->desktop(); // window had the initial desktop property, force it
182  if( desktop() == 0 && asn_valid && asn_data.desktop() != 0 )
183  desk = asn_data.desktop();
184  }
185  if ( desk == 0 ) // assume window wants to be visible on the current desktop
186  desk = workspace()->currentDesktop();
187  desk = rules()->checkDesktop( desk, !isMapped );
188  if( desk != NET::OnAllDesktops ) // do range check
189  desk = KMAX( 1, KMIN( workspace()->numberOfDesktops(), desk ));
190  info->setDesktop( desk );
191  workspace()->updateOnAllDesktopsOfTransients( this ); // SELI
192 // onAllDesktopsChange(); decoration doesn't exist here yet
193 
194  TQRect geom( attr.x, attr.y, attr.width, attr.height );
195  bool placementDone = false;
196 
197  if ( session )
198  geom = session->geometry;
199 
200  TQRect area;
201  bool partial_keep_in_area = isMapped || session;
202  if( isMapped || session )
203  area = workspace()->clientArea( FullArea, geom.center(), desktop());
204  else if( options->xineramaPlacementEnabled )
205  {
206  int screen = options->xineramaPlacementScreen;
207  if( screen == -1 ) // active screen
208  screen = asn_data.xinerama() == -1 ? workspace()->activeScreen() : asn_data.xinerama();
209  area = workspace()->clientArea( PlacementArea, workspace()->screenGeometry( screen ).center(), desktop());
210  }
211  else
212  area = workspace()->clientArea( PlacementArea, TQCursor::pos(), desktop());
213 
214  if( int type = checkFullScreenHack( geom ))
215  {
216  fullscreen_mode = FullScreenHack;
217  if( rules()->checkStrictGeometry( false ))
218  {
219  geom = type == 2 // 1 - it's xinerama-aware fullscreen hack, 2 - it's full area
220  ? workspace()->clientArea( FullArea, geom.center(), desktop())
221  : workspace()->clientArea( ScreenArea, geom.center(), desktop());
222  }
223  else
224  geom = workspace()->clientArea( FullScreenArea, geom.center(), desktop());
225  placementDone = true;
226  }
227 
228  if ( isDesktop() )
229  {
230  // desktops are treated slightly special
231  geom = workspace()->clientArea( FullArea, geom.center(), desktop());
232  placementDone = true;
233  }
234 
235  bool usePosition = false;
236  if ( isMapped || session || placementDone )
237  placementDone = true; // use geometry
238  else if( isTransient() && !isUtility() && !isDialog() && !isSplash())
239  usePosition = true;
240  else if( isTransient() && !hasNETSupport())
241  usePosition = true;
242  else if( isDialog() && hasNETSupport())
243  // if the dialog is actually non-NETWM transient window, don't try to apply placement to it,
244  // it breaks with too many things (xmms, display)
245  {
246  if( mainClients().count() >= 1 )
247  {
248 #if 1
249  // TODO #78082 - Ok, it seems there are after all some cases when an application has a good
250  // reason to specify a position for its dialog. Too bad other WMs have never bothered
251  // with placement for dialogs, so apps always specify positions for their dialogs,
252  // including such silly positions like always centered on the screen or under mouse.
253  // Using ignoring requested position in window-specific settings helps, but at least
254  // for Qt apps this should work better.
255  usePosition = true;
256 #else
257  ; // force using placement policy
258 #endif
259  }
260  else
261  usePosition = true;
262  }
263  else if( isSplash())
264  ; // force using placement policy
265  else
266  usePosition = true;
267  if( !rules()->checkIgnoreGeometry( !usePosition ))
268  {
269  bool ignorePPosition = ( options->ignorePositionClasses.contains(TQString::fromLatin1(resourceClass())));
270 
271  if ( ( (xSizeHint.flags & PPosition) && !ignorePPosition ) ||
272  (xSizeHint.flags & USPosition) )
273  {
274  placementDone = true;
275  // disobey xinerama placement option for now (#70943)
276  area = workspace()->clientArea( PlacementArea, geom.center(), desktop());
277  }
278  }
279  if( true ) // size is always obeyed for now, only with constraints applied
280  if ( (xSizeHint.flags & USSize) || (xSizeHint.flags & PSize) )
281  {
282  // keep in mind that we now actually have a size :-)
283  }
284 
285  if (xSizeHint.flags & PMaxSize)
286  geom.setSize( geom.size().boundedTo(
287  rules()->checkMaxSize( TQSize(xSizeHint.max_width, xSizeHint.max_height ) ) ) );
288  if (xSizeHint.flags & PMinSize)
289  geom.setSize( geom.size().expandedTo(
290  rules()->checkMinSize( TQSize(xSizeHint.min_width, xSizeHint.min_height ) ) ) );
291 
292  if( isMovable())
293  {
294  if( geom.x() > area.right() || geom.y() > area.bottom())
295  placementDone = false; // weird, do not trust.
296  }
297 
298  if ( placementDone )
299  move( geom.x(), geom.y() ); // before gravitating
300 
301  updateDecoration( false ); // also gravitates
302  // TODO is CentralGravity right here, when resizing is done after gravitating?
303  plainResize( rules()->checkSize( sizeForClientSize( geom.size()), !isMapped ));
304 
305  TQPoint forced_pos = rules()->checkPosition( invalidPoint, !isMapped );
306  if( forced_pos != invalidPoint )
307  {
308  move( forced_pos );
309  placementDone = true;
310  // don't keep inside workarea if the window has specially configured position
311  partial_keep_in_area = true;
312  area = workspace()->clientArea( FullArea, geom.center(), desktop());
313  }
314  if( !placementDone )
315  { // placement needs to be after setting size
316  workspace()->place( this, area );
317  placementDone = true;
318  }
319 
320  if(( !isSpecialWindow() || isToolbar()) && isMovable())
321  keepInArea( area, partial_keep_in_area );
322 
323  XShapeSelectInput( tqt_xdisplay(), window(), ShapeNotifyMask );
324  is_shape = Shape::hasShape( window());
325  updateShape();
326 
327  //CT extra check for stupid jdk 1.3.1. But should make sense in general
328  // if client has initial state set to Iconic and is transient with a parent
329  // window that is not Iconic, set init_state to Normal
330  if( init_minimize && isTransient())
331  {
332  ClientList mainclients = mainClients();
333  for( ClientList::ConstIterator it = mainclients.begin();
334  it != mainclients.end();
335  ++it )
336  if( (*it)->isShown( true ))
337  init_minimize = false; // SELI even e.g. for NET::Utility?
338  }
339  // if a dialog is shown for minimized window, minimize it too
340  if( !init_minimize && isTransient() && mainClients().count() > 0 )
341  {
342  bool visible_parent = false;
343  ClientList mainclients = mainClients();
344  for( ClientList::ConstIterator it = mainclients.begin();
345  it != mainclients.end();
346  ++it )
347  if( (*it)->isShown( true ))
348  visible_parent = true;
349  if( !visible_parent )
350  {
351  init_minimize = true;
352  demandAttention();
353  }
354  }
355 
356  if( init_minimize )
357  minimize( true ); // no animation
358 
359  // SELI this seems to be mainly for kstart and ksystraycmd
360  // probably should be replaced by something better
361  bool doNotShow = false;
362  if ( workspace()->isNotManaged( caption() ) )
363  doNotShow = true;
364 
365  // other settings from the previous session
366  if ( session )
367  {
368  // session restored windows are not considered to be new windows WRT rules,
369  // i.e. obey only forcing rules
370  setKeepAbove( session->keepAbove );
371  setKeepBelow( session->keepBelow );
372  setSkipTaskbar( session->skipTaskbar, true );
373  setSkipPager( session->skipPager );
374  setShade( session->shaded ? ShadeNormal : ShadeNone );
375  setShadowed( session->shadowed );
376  if( session->maximized != MaximizeRestore )
377  {
378  maximize( (MaximizeMode) session->maximized );
379  geom_restore = session->restore;
380  }
381  if( session->fullscreen == FullScreenHack )
382  ; // nothing, this should be already set again above
383  else if( session->fullscreen != FullScreenNone )
384  {
385  setFullScreen( true, false );
386  geom_fs_restore = session->fsrestore;
387  }
388  }
389  else
390  {
391  geom_restore = geometry(); // remember restore geometry
392  if ( isMaximizable()
393  && ( width() >= area.width() || height() >= area.height() ) )
394  {
395  // window is too large for the screen, maximize in the
396  // directions necessary
397  if ( width() >= area.width() && height() >= area.height() )
398  {
399  maximize( Client::MaximizeFull );
400  geom_restore = TQRect(); // use placement when unmaximizing
401  }
402  else if ( width() >= area.width() )
403  {
404  maximize( Client::MaximizeHorizontal );
405  geom_restore = TQRect(); // use placement when unmaximizing
406  geom_restore.setY( y()); // but only for horizontal direction
407  geom_restore.setHeight( height());
408  }
409  else if ( height() >= area.height() )
410  {
411  maximize( Client::MaximizeVertical );
412  geom_restore = TQRect(); // use placement when unmaximizing
413  geom_restore.setX( x()); // but only for vertical direction
414  geom_restore.setWidth( width());
415  }
416  }
417  // window may want to be maximized
418  // done after checking that the window isn't larger than the workarea, so that
419  // the restore geometry from the checks above takes precedence, and window
420  // isn't restored larger than the workarea
421  MaximizeMode maxmode = static_cast< MaximizeMode >
422  ((( info->state() & NET::MaxVert ) ? MaximizeVertical : 0 )
423  | (( info->state() & NET::MaxHoriz ) ? MaximizeHorizontal : 0 ));
424  MaximizeMode forced_maxmode = rules()->checkMaximize( maxmode, !isMapped );
425  // either hints were set to maximize, or is forced to maximize,
426  // or is forced to non-maximize and hints were set to maximize
427  if( forced_maxmode != MaximizeRestore || maxmode != MaximizeRestore )
428  maximize( forced_maxmode );
429 
430  // read other initial states
431  setShade( rules()->checkShade( info->state() & NET::Shaded ? ShadeNormal : ShadeNone, !isMapped ));
432  setKeepAbove( rules()->checkKeepAbove( info->state() & NET::KeepAbove, !isMapped ));
433  setKeepBelow( rules()->checkKeepBelow( info->state() & NET::KeepBelow, !isMapped ));
434  setSkipTaskbar( rules()->checkSkipTaskbar( info->state() & NET::SkipTaskbar, !isMapped ), true );
435  setSkipPager( rules()->checkSkipPager( info->state() & NET::SkipPager, !isMapped ));
436  if( info->state() & NET::DemandsAttention )
437  demandAttention();
438  if( info->state() & NET::Modal )
439  setModal( true );
440  if( fullscreen_mode != FullScreenHack && isFullScreenable())
441  setFullScreen( rules()->checkFullScreen( info->state() & NET::FullScreen, !isMapped ), false );
442  }
443 
444  updateAllowedActions( true );
445 
446  // TODO this should avoid flicker, because real restacking is done
447  // only after manage() finishes, but the window is shown sooner
448  // - keep it?
449  XLowerWindow( tqt_xdisplay(), frameId());
450 
451  // set initial user time directly
452  user_time = readUserTimeMapTimestamp( asn_valid ? &asn_id : NULL, asn_valid ? &asn_data : NULL, session );
453  group()->updateUserTime( user_time ); // and do what Client::updateUserTime() does
454 
455  if( isTopMenu()) // they're shown in Workspace::addClient() if their mainwindow
456  hideClient( true ); // is the active one
457 
458  if( isShown( true ) && !doNotShow )
459  {
460  if( isDialog())
461  Notify::raise( Notify::TransNew );
462  if( isNormalWindow())
463  Notify::raise( Notify::New );
464 
465  bool allow;
466  if( session )
467  allow = session->active
468  && ( !workspace()->wasUserInteraction()
469  || workspace()->activeClient() == NULL || workspace()->activeClient()->isDesktop());
470  else
471  allow = workspace()->allowClientActivation( this, userTime(), false );
472 
473  // if session saving, force showing new windows (i.e. "save file?" dialogs etc.)
474  // also force if activation is allowed
475  if( !isOnCurrentDesktop() && !isMapped && !session && ( allow || workspace()->sessionSaving()))
476  workspace()->setCurrentDesktop( desktop());
477 
478  bool belongs_to_desktop = false;
479  for( ClientList::ConstIterator it = group()->members().begin();
480  it != group()->members().end();
481  ++it )
482  if( (*it)->isDesktop())
483  {
484  belongs_to_desktop = true;
485  break;
486  }
487  if( !belongs_to_desktop && workspace()->showingDesktop())
488  workspace()->resetShowingDesktop( options->showDesktopIsMinimizeAll );
489 
490  if( isOnCurrentDesktop() && !isMapped && !allow )
491  workspace()->restackClientUnderActive( this );
492  else
493  workspace()->raiseClient( this );
494 
495  updateVisibility();
496 
497  if( !isMapped )
498  {
499  if( allow && isOnCurrentDesktop())
500  {
501  if( !isSpecialWindow())
502  if ( options->focusPolicyIsReasonable() && wantsTabFocus() )
503  workspace()->requestFocus( this );
504  }
505  else
506  {
507  if( !session && !isSpecialWindow())
508  demandAttention();
509  }
510  }
511  }
512  else if( !doNotShow ) // if( !isShown( true ) && !doNotShow )
513  {
514  updateVisibility();
515  }
516  else // doNotShow
517  { // SELI HACK !!!
518  hideClient( true );
519  setMappingState( IconicState );
520  }
521  assert( mappingState() != WithdrawnState );
522 
523  if( user_time == CurrentTime || user_time == -1U ) // no known user time, set something old
524  {
525  user_time = get_tqt_x_time() - 1000000;
526  if( user_time == CurrentTime || user_time == -1U ) // let's be paranoid
527  user_time = get_tqt_x_time() - 1000000 + 10;
528  }
529 
530  updateWorkareaDiffs();
531 
532 // sendSyntheticConfigureNotify(); done when setting mapping state
533 
534  delete session;
535 
536  ungrabXServer();
537 
538  client_rules.discardTemporary();
539  applyWindowRules(); // just in case
540  workspace()->discardUsedWindowRules( this, false ); // remove ApplyNow rules
541  updateWindowRules(); // was blocked while !isManaged()
542 
543 // Handle suspended processes
544  if (isResumeable())
545  {
546  suspendWindow(); // It won't hurt to stop the process again, and this will update the displayed captions
547  }
548 
549 // TODO there's a small problem here - isManaged() depends on the mapping state,
550 // but this client is not yet in Workspace's client list at this point, will
551 // be only done in addClient()
552  return true;
553  }
554 
555 // called only from manage()
556 void Client::embedClient( Window w, const XWindowAttributes &attr )
557  {
558  assert( client == None );
559  assert( frame == None );
560  assert( wrapper == None );
561  client = w;
562  // we don't want the window to be destroyed when we are destroyed
563  XAddToSaveSet( tqt_xdisplay(), client );
564  XSelectInput( tqt_xdisplay(), client, NoEventMask );
565  XUnmapWindow( tqt_xdisplay(), client );
566  XWindowChanges wc; // set the border width to 0
567  wc.border_width = 0; // TODO possibly save this, and also use it for initial configuring of the window
568  XConfigureWindow( tqt_xdisplay(), client, CWBorderWidth, &wc );
569 
570  XSetWindowAttributes swa;
571  swa.colormap = attr.colormap;
572  swa.background_pixmap = None;
573  swa.border_pixel = 0;
574 
575  frame = XCreateWindow( tqt_xdisplay(), tqt_xrootwin(), 0, 0, 1, 1, 0,
576  attr.depth, InputOutput, attr.visual,
577  CWColormap | CWBackPixmap | CWBorderPixel, &swa );
578  wrapper = XCreateWindow( tqt_xdisplay(), frame, 0, 0, 1, 1, 0,
579  attr.depth, InputOutput, attr.visual,
580  CWColormap | CWBackPixmap | CWBorderPixel, &swa );
581 
582  XDefineCursor( tqt_xdisplay(), frame, TQt::arrowCursor.handle());
583  // some apps are stupid and don't define their own cursor - set the arrow one for them
584  XDefineCursor( tqt_xdisplay(), wrapper, TQt::arrowCursor.handle());
585  XReparentWindow( tqt_xdisplay(), client, wrapper, 0, 0 );
586  XSelectInput( tqt_xdisplay(), frame,
587  KeyPressMask | KeyReleaseMask |
588  ButtonPressMask | ButtonReleaseMask |
589  KeymapStateMask |
590  ButtonMotionMask |
591  PointerMotionMask |
592  EnterWindowMask | LeaveWindowMask |
593  FocusChangeMask |
594  ExposureMask |
595  PropertyChangeMask |
596  StructureNotifyMask | SubstructureRedirectMask );
597  XSelectInput( tqt_xdisplay(), wrapper, ClientWinMask | SubstructureNotifyMask );
598  XSelectInput( tqt_xdisplay(), client,
599  FocusChangeMask |
600  PropertyChangeMask |
601  ColormapChangeMask |
602  EnterWindowMask | LeaveWindowMask |
603  KeyPressMask | KeyReleaseMask
604  );
605  updateMouseGrab();
606  }
607 
608 } // namespace
KWinInternal::Client
The Client class encapsulates a window decoration frame.
Definition: client.h:47
KWinInternal::Client::desktop
int desktop() const
Definition: client.h:765
KWinInternal::Client::isMovable
bool isMovable() const
Definition: geometry.cpp:1649
KWinInternal::Client::manage
bool manage(Window w, bool isMapped)
Definition: manage.cpp:36
KWinInternal::Client::minimize
void minimize(bool avoid_animation=false)
Definition: client.cpp:682
KWinInternal::Client::staticWindowRole
static TQCString staticWindowRole(WId)
Definition: client.cpp:2505
KWinInternal::Client::caption
TQString caption(bool full=true) const
Definition: client.cpp:2381
KWinInternal::Client::move
void move(int x, int y, ForceGeometry_t force=NormalGeometrySet)
Definition: geometry.cpp:1831

twin

Skip menu "twin"
  • Main Page
  • Modules
  • Alphabetical List
  • Class List
  • File List
  • Class Members

twin

Skip menu "twin"
  • kate
  • libkonq
  • twin
  •   lib
Generated for twin by doxygen 1.9.1
This website is maintained by Timothy Pearson.