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

kwin

  • kwin
placement.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) 1997 to 2002 Cristian Tibirna <tibirna@kde.org>
7 Copyright (C) 2003 Lubos Lunak <l.lunak@kde.org>
8 
9 You can Freely distribute this program under the GNU General Public
10 License. See the file "COPYING" for the exact licensing terms.
11 ******************************************************************/
12 
13 #include "placement.h"
14 
15 #include <tqrect.h>
16 #include <assert.h>
17 
18 #ifndef KCMRULES
19 #include "workspace.h"
20 #include "client.h"
21 #include "options.h"
22 #include "rules.h"
23 #endif
24 
25 namespace KWinInternal
26 {
27 
28 #ifndef KCMRULES
29 
30 Placement::Placement(Workspace* w)
31  {
32  m_WorkspacePtr = w;
33 
34  reinitCascading( 0 );
35  }
36 
40 void Placement::place(Client* c, TQRect& area )
41  {
42  Policy policy = c->rules()->checkPlacement( Default );
43  if( policy != Default )
44  {
45  place( c, area, policy );
46  return;
47  }
48 
49  if( c->isUtility())
50  placeUtility(c, area, options->placement );
51  else if( c->isDialog())
52  placeDialog(c, area, options->placement );
53  else if( c->isSplash())
54  placeOnMainWindow( c, area ); // on mainwindow, if any, otherwise centered
55  else
56  place(c, area, options->placement);
57  }
58 
59 void Placement::place(Client* c, TQRect& area, Policy policy, Policy nextPlacement )
60  {
61  if( policy == Unknown )
62  policy = Default;
63  if( policy == Default )
64  policy = options->placement;
65  if( policy == NoPlacement )
66  return;
67  else if (policy == Random)
68  placeAtRandom(c, area, nextPlacement);
69  else if (policy == Cascade)
70  placeCascaded(c, area, nextPlacement);
71  else if (policy == Centered)
72  placeCentered(c, area, nextPlacement);
73  else if (policy == ZeroCornered)
74  placeZeroCornered(c, area, nextPlacement);
75  else if (policy == UnderMouse)
76  placeUnderMouse(c, area, nextPlacement);
77  else if (policy == OnMainWindow)
78  placeOnMainWindow(c, area, nextPlacement);
79  else if( policy == Maximizing )
80  placeMaximizing(c, area, nextPlacement);
81  else
82  placeSmart(c, area, nextPlacement);
83  }
84 
88 void Placement::placeAtRandom(Client* c, const TQRect& area, Policy /*next*/ )
89  {
90  const int step = 24;
91  static int px = step;
92  static int py = 2 * step;
93  int tx,ty;
94 
95  const TQRect maxRect = checkArea( c, area );
96 
97  if (px < maxRect.x())
98  px = maxRect.x();
99  if (py < maxRect.y())
100  py = maxRect.y();
101 
102  px += step;
103  py += 2*step;
104 
105  if (px > maxRect.width()/2)
106  px = maxRect.x() + step;
107  if (py > maxRect.height()/2)
108  py = maxRect.y() + step;
109  tx = px;
110  ty = py;
111  if (tx + c->width() > maxRect.right())
112  {
113  tx = maxRect.right() - c->width();
114  if (tx < 0)
115  tx = 0;
116  px = maxRect.x();
117  }
118  if (ty + c->height() > maxRect.bottom())
119  {
120  ty = maxRect.bottom() - c->height();
121  if (ty < 0)
122  ty = 0;
123  py = maxRect.y();
124  }
125  c->move(tx, ty);
126  }
127 
131 void Placement::placeSmart(Client* c, const TQRect& area, Policy /*next*/ )
132  {
133  /*
134  * SmartPlacement by Cristian Tibirna (tibirna@kde.org)
135  * adapted for kwm (16-19jan98) and for kwin (16Nov1999) using (with
136  * permission) ideas from fvwm, authored by
137  * Anthony Martin (amartin@engr.csulb.edu).
138  * Xinerama supported added by Balaji Ramani (balaji@yablibli.com)
139  * with ideas from xfce.
140  */
141 
142  const int none = 0, h_wrong = -1, w_wrong = -2; // overlap types
143  long int overlap, min_overlap = 0;
144  int x_optimal, y_optimal;
145  int possible;
146  int desktop = c->desktop() == 0 || c->isOnAllDesktops() ? m_WorkspacePtr->currentDesktop() : c->desktop();
147 
148  int cxl, cxr, cyt, cyb; //temp coords
149  int xl, xr, yt, yb; //temp coords
150  int basket; //temp holder
151 
152  // get the maximum allowed windows space
153  const TQRect maxRect = checkArea( c, area );
154  int x = maxRect.left(), y = maxRect.top();
155  x_optimal = x; y_optimal = y;
156 
157  //client gabarit
158  int ch = c->height() - 1;
159  int cw = c->width() - 1;
160 
161  bool first_pass = true; //CT lame flag. Don't like it. What else would do?
162 
163  //loop over possible positions
164  do
165  {
166  //test if enough room in x and y directions
167  if (y + ch > maxRect.bottom() && ch < maxRect.height())
168  overlap = h_wrong; // this throws the algorithm to an exit
169  else if(x + cw > maxRect.right())
170  overlap = w_wrong;
171  else
172  {
173  overlap = none; //initialize
174 
175  cxl = x; cxr = x + cw;
176  cyt = y; cyb = y + ch;
177  ClientList::ConstIterator l;
178  for(l = m_WorkspacePtr->stackingOrder().begin(); l != m_WorkspacePtr->stackingOrder().end() ; ++l)
179  {
180  if((*l)->isOnDesktop(desktop) &&
181  (*l)->isShown( false ) && (*l) != c)
182  {
183 
184  xl = (*l)->x(); yt = (*l)->y();
185  xr = xl + (*l)->width(); yb = yt + (*l)->height();
186 
187  //if windows overlap, calc the overall overlapping
188  if((cxl < xr) && (cxr > xl) &&
189  (cyt < yb) && (cyb > yt))
190  {
191  xl = QMAX(cxl, xl); xr = QMIN(cxr, xr);
192  yt = QMAX(cyt, yt); yb = QMIN(cyb, yb);
193  if((*l)->keepAbove())
194  overlap += 16 * (xr - xl) * (yb - yt);
195  else if((*l)->keepBelow() && !(*l)->isDock()) // ignore KeepBelow windows
196  overlap += 0; // for placement (see Client::belongsToLayer() for Dock)
197  else
198  overlap += (xr - xl) * (yb - yt);
199  }
200  }
201  }
202  }
203 
204  //CT first time we get no overlap we stop.
205  if (overlap == none)
206  {
207  x_optimal = x;
208  y_optimal = y;
209  break;
210  }
211 
212  if (first_pass)
213  {
214  first_pass = false;
215  min_overlap = overlap;
216  }
217  //CT save the best position and the minimum overlap up to now
218  else if (overlap >= none && overlap < min_overlap)
219  {
220  min_overlap = overlap;
221  x_optimal = x;
222  y_optimal = y;
223  }
224 
225  // really need to loop? test if there's any overlap
226  if (overlap > none)
227  {
228 
229  possible = maxRect.right();
230  if (possible - cw > x) possible -= cw;
231 
232  // compare to the position of each client on the same desk
233  ClientList::ConstIterator l;
234  for(l = m_WorkspacePtr->stackingOrder().begin(); l != m_WorkspacePtr->stackingOrder().end() ; ++l)
235  {
236 
237  if ((*l)->isOnDesktop(desktop) &&
238  (*l)->isShown( false ) && (*l) != c)
239  {
240 
241  xl = (*l)->x(); yt = (*l)->y();
242  xr = xl + (*l)->width(); yb = yt + (*l)->height();
243 
244  // if not enough room above or under the current tested client
245  // determine the first non-overlapped x position
246  if((y < yb) && (yt < ch + y))
247  {
248 
249  if((xr > x) && (possible > xr)) possible = xr;
250 
251  basket = xl - cw;
252  if((basket > x) && (possible > basket)) possible = basket;
253  }
254  }
255  }
256  x = possible;
257  }
258 
259  // ... else ==> not enough x dimension (overlap was wrong on horizontal)
260  else if (overlap == w_wrong)
261  {
262  x = maxRect.left();
263  possible = maxRect.bottom();
264 
265  if (possible - ch > y) possible -= ch;
266 
267  //test the position of each window on the desk
268  ClientList::ConstIterator l;
269  for(l = m_WorkspacePtr->stackingOrder().begin(); l != m_WorkspacePtr->stackingOrder().end() ; ++l)
270  {
271  if((*l)->isOnDesktop(desktop) &&
272  (*l) != c && c->isShown( false ))
273  {
274 
275  xl = (*l)->x(); yt = (*l)->y();
276  xr = xl + (*l)->width(); yb = yt + (*l)->height();
277 
278  // if not enough room to the left or right of the current tested client
279  // determine the first non-overlapped y position
280  if((yb > y) && (possible > yb)) possible = yb;
281 
282  basket = yt - ch;
283  if((basket > y) && (possible > basket)) possible = basket;
284  }
285  }
286  y = possible;
287  }
288  }
289  while((overlap != none) && (overlap != h_wrong) && (y < maxRect.bottom()));
290 
291  if(ch>= maxRect.height())
292  y_optimal=maxRect.top();
293 
294  // place the window
295  c->move(x_optimal, y_optimal);
296 
297  }
298 
299 void Placement::reinitCascading( int desktop )
300  { // desktop == 0 - reinit all
301  if( desktop == 0 )
302  {
303  cci.clear();
304  for( int i = 0; i < m_WorkspacePtr->numberOfDesktops(); i++)
305  {
306  DesktopCascadingInfo inf;
307  inf.pos = TQPoint(-1,-1);
308  inf.col = 0;
309  inf.row = 0;
310  cci.append(inf);
311  }
312  }
313  else
314  {
315  cci[desktop - 1].pos = TQPoint(-1, -1);
316  cci[desktop - 1].col = cci[desktop - 1].row = 0;
317  }
318  }
319 
323 void Placement::placeCascaded (Client* c, TQRect& area, Policy nextPlacement)
324  {
325  /* cascadePlacement by Cristian Tibirna (tibirna@kde.org) (30Jan98)
326  */
327  // work coords
328  int xp, yp;
329 
330  //CT how do I get from the 'Client' class the size that NW squarish "handle"
331  const int delta_x = 24;
332  const int delta_y = 24;
333 
334  const int dn = c->desktop() == 0 || c->isOnAllDesktops() ? (m_WorkspacePtr->currentDesktop() - 1) : (c->desktop() - 1);
335 
336  // get the maximum allowed windows space and desk's origin
337  TQRect maxRect = checkArea( c, area );
338 
339  // initialize often used vars: width and height of c; we gain speed
340  const int ch = c->height();
341  const int cw = c->width();
342  const int X = maxRect.left();
343  const int Y = maxRect.top();
344  const int H = maxRect.height();
345  const int W = maxRect.width();
346 
347  if( nextPlacement == Unknown )
348  nextPlacement = Smart;
349 
350  //initialize if needed
351  if (cci[dn].pos.x() < 0 || cci[dn].pos.x() < X || cci[dn].pos.y() < Y )
352  {
353  cci[dn].pos = TQPoint(X, Y);
354  cci[dn].col = cci[dn].row = 0;
355  }
356 
357 
358  xp = cci[dn].pos.x();
359  yp = cci[dn].pos.y();
360 
361  //here to touch in case people vote for resize on placement
362  if ((yp + ch) > H) yp = Y;
363 
364  if ((xp + cw) > W)
365  if (!yp)
366  {
367  place(c,area,nextPlacement);
368  return;
369  }
370  else xp = X;
371 
372  //if this isn't the first window
373  if (cci[dn].pos.x() != X && cci[dn].pos.y() != Y)
374  {
375  /* The following statements cause an internal compiler error with
376  * egcs-2.91.66 on SuSE Linux 6.3. The equivalent forms compile fine.
377  * 22-Dec-1999 CS
378  *
379  * if (xp != X && yp == Y) xp = delta_x * (++(cci[dn].col));
380  * if (yp != Y && xp == X) yp = delta_y * (++(cci[dn].row));
381  */
382  if (xp != X && yp == Y)
383  {
384  ++(cci[dn].col);
385  xp = delta_x * cci[dn].col;
386  }
387  if (yp != Y && xp == X)
388  {
389  ++(cci[dn].row);
390  yp = delta_y * cci[dn].row;
391  }
392 
393  // last resort: if still doesn't fit, smart place it
394  if (((xp + cw) > W - X) || ((yp + ch) > H - Y))
395  {
396  place(c,area,nextPlacement);
397  return;
398  }
399  }
400 
401  // place the window
402  c->move(TQPoint(xp, yp));
403 
404  // new position
405  cci[dn].pos = TQPoint(xp + delta_x, yp + delta_y);
406  }
407 
411 void Placement::placeCentered (Client* c, const TQRect& area, Policy /*next*/ )
412  {
413 
414  // get the maximum allowed windows space and desk's origin
415  const TQRect maxRect = checkArea( c, area );
416 
417  const int xp = maxRect.left() + (maxRect.width() - c->width()) / 2;
418  const int yp = maxRect.top() + (maxRect.height() - c->height()) / 2;
419 
420  // place the window
421  c->move(TQPoint(xp, yp));
422  }
423 
427 void Placement::placeZeroCornered(Client* c, const TQRect& area, Policy /*next*/ )
428  {
429  // get the maximum allowed windows space and desk's origin
430  const TQRect maxRect = checkArea( c, area );
431 
432  // place the window
433  c->move(TQPoint(maxRect.left(), maxRect.top()));
434  }
435 
436 void Placement::placeUtility(Client* c, TQRect& area, Policy /*next*/ )
437  {
438 // TODO kwin should try to place utility windows next to their mainwindow,
439 // preferably at the right edge, and going down if there are more of them
440 // if there's not enough place outside the mainwindow, it should prefer
441 // top-right corner
442  // use the default placement for now
443  place( c, area, Default );
444  }
445 
446 
447 void Placement::placeDialog(Client* c, TQRect& area, Policy nextPlacement )
448  {
449  placeOnMainWindow( c, area, nextPlacement );
450  }
451 
452 void Placement::placeUnderMouse(Client* c, TQRect& area, Policy /*next*/ )
453  {
454  area = checkArea( c, area );
455  TQRect geom = c->geometry();
456  geom.moveCenter( TQCursor::pos());
457  c->move( geom.topLeft());
458  c->keepInArea( area ); // make sure it's kept inside workarea
459  }
460 
461 void Placement::placeOnMainWindow(Client* c, TQRect& area, Policy nextPlacement )
462  {
463  if( nextPlacement == Unknown )
464  nextPlacement = Centered;
465  if( nextPlacement == Maximizing ) // maximize if needed
466  placeMaximizing( c, area, NoPlacement );
467  area = checkArea( c, area );
468  ClientList mainwindows = c->mainClients();
469  Client* place_on = NULL;
470  Client* place_on2 = NULL;
471  int mains_count = 0;
472  for( ClientList::ConstIterator it = mainwindows.begin();
473  it != mainwindows.end();
474  ++it )
475  {
476  if( mainwindows.count() > 1 && (*it)->isSpecialWindow())
477  continue; // don't consider toolbars etc when placing
478  ++mains_count;
479  place_on2 = *it;
480  if( (*it)->isOnCurrentDesktop())
481  {
482  if( place_on == NULL )
483  place_on = *it;
484  else
485  { // two or more on current desktop -> center
486  // That's the default at least. However, with maximizing placement
487  // policy as the default, the dialog should be either maximized or
488  // made as large as its maximum size and then placed centered.
489  // So the nextPlacement argument allows chaining. In this case, nextPlacement
490  // is Maximizing and it will call placeCentered().
491  place( c, area, Centered );
492  return;
493  }
494  }
495  }
496  if( place_on == NULL )
497  { // 'mains_count' is used because it doesn't include ignored mainwindows
498  if( mains_count != 1 )
499  {
500  place( c, area, Centered );
501  return;
502  }
503  place_on = place_on2; // use the only window filtered together with 'mains_count'
504  }
505  if( place_on->isDesktop())
506  {
507  place( c, area, Centered );
508  return;
509  }
510  TQRect geom = c->geometry();
511  geom.moveCenter( place_on->geometry().center());
512  c->move( geom.topLeft());
513  // get area again, because the mainwindow may be on different xinerama screen
514  area = checkArea( c, TQRect());
515  c->keepInArea( area ); // make sure it's kept inside workarea
516  }
517 
518 void Placement::placeMaximizing(Client* c, TQRect& area, Policy nextPlacement )
519  {
520  if( nextPlacement == Unknown )
521  nextPlacement = Smart;
522  if( c->isMaximizable() && c->maxSize().width() >= area.width() && c->maxSize().height() >= area.height())
523  {
524  if( m_WorkspacePtr->clientArea( MaximizeArea, c ) == area )
525  c->maximize( Client::MaximizeFull );
526  else // if the geometry doesn't match default maximize area (xinerama case?),
527  { // it's probably better to use the given area
528  c->setGeometry( area );
529  }
530  }
531  else
532  {
533  c->resizeWithChecks( c->maxSize().boundedTo( area.size()));
534  place( c, area, nextPlacement );
535  }
536  }
537 
538 TQRect Placement::checkArea( const Client* c, const TQRect& area )
539  {
540  if( area.isNull())
541  return m_WorkspacePtr->clientArea( PlacementArea, c->geometry().center(), c->desktop());
542  return area;
543  }
544 
545 #endif
546 
547 
548 Placement::Policy Placement::policyFromString( const TQString& policy, bool no_special )
549  {
550  if( policy == "NoPlacement" )
551  return NoPlacement;
552  else if( policy == "Default" && !no_special )
553  return Default;
554  else if( policy == "Random" )
555  return Random;
556  else if( policy == "Cascade" )
557  return Cascade;
558  else if( policy == "Centered" )
559  return Centered;
560  else if( policy == "ZeroCornered" )
561  return ZeroCornered;
562  else if( policy == "UnderMouse" && !no_special)
563  return UnderMouse;
564  else if( policy == "OnMainWindow" && !no_special)
565  return OnMainWindow;
566  else if( policy == "Maximizing" )
567  return Maximizing;
568  else
569  return Smart;
570  }
571 
572 const char* Placement::policyToString( Policy policy )
573  {
574  const char* const policies[] =
575  { "NoPlacement", "Default", "XXX should never see", "Random", "Smart", "Cascade", "Centered",
576  "ZeroCornered", "UnderMouse", "OnMainWindow", "Maximizing" };
577  assert( policy < int( sizeof( policies ) / sizeof( policies[ 0 ] )));
578  return policies[ policy ];
579  }
580 
581 
582 #ifndef KCMRULES
583 
584 // ********************
585 // Workspace
586 // ********************
587 
591 void Workspace::slotWindowPackLeft()
592  {
593  if( active_client && active_client->isMovable())
594  active_client->move( packPositionLeft( active_client, active_client->geometry().left(), true ),
595  active_client->y());
596  }
597 
598 void Workspace::slotWindowPackRight()
599  {
600  if( active_client && active_client->isMovable())
601  active_client->move(
602  packPositionRight( active_client, active_client->geometry().right(), true )
603  - active_client->width() + 1, active_client->y());
604  }
605 
606 void Workspace::slotWindowPackUp()
607  {
608  if( active_client && active_client->isMovable())
609  active_client->move( active_client->x(),
610  packPositionUp( active_client, active_client->geometry().top(), true ));
611  }
612 
613 void Workspace::slotWindowPackDown()
614  {
615  if( active_client && active_client->isMovable())
616  active_client->move( active_client->x(),
617  packPositionDown( active_client, active_client->geometry().bottom(), true ) - active_client->height() + 1 );
618  }
619 
620 void Workspace::slotWindowGrowHorizontal()
621  {
622  if( active_client )
623  active_client->growHorizontal();
624  }
625 
626 void Client::growHorizontal()
627  {
628  if( !isResizable() || isShade())
629  return;
630  TQRect geom = geometry();
631  geom.setRight( workspace()->packPositionRight( this, geom.right(), true ));
632  TQSize adjsize = adjustedSize( geom.size(), SizemodeFixedW );
633  if( geometry().size() == adjsize && geom.size() != adjsize && xSizeHint.width_inc > 1 ) // take care of size increments
634  {
635  int newright = workspace()->packPositionRight( this, geom.right() + xSizeHint.width_inc - 1, true );
636  // check that it hasn't grown outside of the area, due to size increments
637  // TODO this may be wrong?
638  if( workspace()->clientArea( MovementArea,
639  TQPoint(( x() + newright ) / 2, geometry().center().y()), desktop()).right() >= newright )
640  geom.setRight( newright );
641  }
642  geom.setSize( adjustedSize( geom.size(), SizemodeFixedW ));
643  setGeometry( geom );
644  }
645 
646 void Workspace::slotWindowShrinkHorizontal()
647  {
648  if( active_client )
649  active_client->shrinkHorizontal();
650  }
651 
652 void Client::shrinkHorizontal()
653  {
654  if( !isResizable() || isShade())
655  return;
656  TQRect geom = geometry();
657  geom.setRight( workspace()->packPositionLeft( this, geom.right(), false ));
658  if( geom.width() <= 1 )
659  return;
660  geom.setSize( adjustedSize( geom.size(), SizemodeFixedW ));
661  if( geom.width() > 20 )
662  setGeometry( geom );
663  }
664 
665 void Workspace::slotWindowGrowVertical()
666  {
667  if( active_client )
668  active_client->growVertical();
669  }
670 
671 void Client::growVertical()
672  {
673  if( !isResizable() || isShade())
674  return;
675  TQRect geom = geometry();
676  geom.setBottom( workspace()->packPositionDown( this, geom.bottom(), true ));
677  TQSize adjsize = adjustedSize( geom.size(), SizemodeFixedH );
678  if( geometry().size() == adjsize && geom.size() != adjsize && xSizeHint.height_inc > 1 ) // take care of size increments
679  {
680  int newbottom = workspace()->packPositionDown( this, geom.bottom() + xSizeHint.height_inc - 1, true );
681  // check that it hasn't grown outside of the area, due to size increments
682  if( workspace()->clientArea( MovementArea,
683  TQPoint( geometry().center().x(), ( y() + newbottom ) / 2 ), desktop()).bottom() >= newbottom )
684  geom.setBottom( newbottom );
685  }
686  geom.setSize( adjustedSize( geom.size(), SizemodeFixedH ));
687  setGeometry( geom );
688  }
689 
690 
691 void Workspace::slotWindowShrinkVertical()
692  {
693  if( active_client )
694  active_client->shrinkVertical();
695  }
696 
697 void Client::shrinkVertical()
698  {
699  if( !isResizable() || isShade())
700  return;
701  TQRect geom = geometry();
702  geom.setBottom( workspace()->packPositionUp( this, geom.bottom(), false ));
703  if( geom.height() <= 1 )
704  return;
705  geom.setSize( adjustedSize( geom.size(), SizemodeFixedH ));
706  if( geom.height() > 20 )
707  setGeometry( geom );
708  }
709 
710 int Workspace::packPositionLeft( const Client* cl, int oldx, bool left_edge ) const
711  {
712  int newx = clientArea( MovementArea, cl ).left();
713  if( oldx <= newx ) // try another Xinerama screen
714  newx = clientArea( MovementArea,
715  TQPoint( cl->geometry().left() - 1, cl->geometry().center().y()), cl->desktop()).left();
716  if( oldx <= newx )
717  return oldx;
718  for( ClientList::ConstIterator it = clients.begin();
719  it != clients.end();
720  ++it)
721  {
722  if( !(*it)->isShown( false ) || !(*it)->isOnDesktop( active_client->desktop()))
723  continue;
724  int x = left_edge ? (*it)->geometry().right() + 1 : (*it)->geometry().left() - 1;
725  if( x > newx && x < oldx
726  && !( cl->geometry().top() > (*it)->geometry().bottom() // they overlap in Y direction
727  || cl->geometry().bottom() < (*it)->geometry().top()))
728  newx = x;
729  }
730  return newx;
731  }
732 
733 int Workspace::packPositionRight( const Client* cl, int oldx, bool right_edge ) const
734  {
735  int newx = clientArea( MovementArea, cl ).right();
736  if( oldx >= newx ) // try another Xinerama screen
737  newx = clientArea( MovementArea,
738  TQPoint( cl->geometry().right() + 1, cl->geometry().center().y()), cl->desktop()).right();
739  if( oldx >= newx )
740  return oldx;
741  for( ClientList::ConstIterator it = clients.begin();
742  it != clients.end();
743  ++it)
744  {
745  if( !(*it)->isShown( false ) || !(*it)->isOnDesktop( cl->desktop()))
746  continue;
747  int x = right_edge ? (*it)->geometry().left() - 1 : (*it)->geometry().right() + 1;
748  if( x < newx && x > oldx
749  && !( cl->geometry().top() > (*it)->geometry().bottom()
750  || cl->geometry().bottom() < (*it)->geometry().top()))
751  newx = x;
752  }
753  return newx;
754  }
755 
756 int Workspace::packPositionUp( const Client* cl, int oldy, bool top_edge ) const
757  {
758  int newy = clientArea( MovementArea, cl ).top();
759  if( oldy <= newy ) // try another Xinerama screen
760  newy = clientArea( MovementArea,
761  TQPoint( cl->geometry().center().x(), cl->geometry().top() - 1 ), cl->desktop()).top();
762  if( oldy <= newy )
763  return oldy;
764  for( ClientList::ConstIterator it = clients.begin();
765  it != clients.end();
766  ++it)
767  {
768  if( !(*it)->isShown( false ) || !(*it)->isOnDesktop( cl->desktop()))
769  continue;
770  int y = top_edge ? (*it)->geometry().bottom() + 1 : (*it)->geometry().top() - 1;
771  if( y > newy && y < oldy
772  && !( cl->geometry().left() > (*it)->geometry().right() // they overlap in X direction
773  || cl->geometry().right() < (*it)->geometry().left()))
774  newy = y;
775  }
776  return newy;
777  }
778 
779 int Workspace::packPositionDown( const Client* cl, int oldy, bool bottom_edge ) const
780  {
781  int newy = clientArea( MovementArea, cl ).bottom();
782  if( oldy >= newy ) // try another Xinerama screen
783  newy = clientArea( MovementArea,
784  TQPoint( cl->geometry().center().x(), cl->geometry().bottom() + 1 ), cl->desktop()).bottom();
785  if( oldy >= newy )
786  return oldy;
787  for( ClientList::ConstIterator it = clients.begin();
788  it != clients.end();
789  ++it)
790  {
791  if( !(*it)->isShown( false ) || !(*it)->isOnDesktop( cl->desktop()))
792  continue;
793  int y = bottom_edge ? (*it)->geometry().top() - 1 : (*it)->geometry().bottom() + 1;
794  if( y < newy && y > oldy
795  && !( cl->geometry().left() > (*it)->geometry().right()
796  || cl->geometry().right() < (*it)->geometry().left()))
797  newy = y;
798  }
799  return newy;
800  }
801 
805 void Workspace::place(Client* c, TQRect& area)
806  {
807  initPositioning->place( c, area );
808  }
809 
810 void Workspace::placeSmart(Client* c, const TQRect& area)
811  {
812  initPositioning->placeSmart( c, area );
813  }
814 
815 #endif
816 
817 } // namespace

kwin

Skip menu "kwin"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kwin

Skip menu "kwin"
  • kate
  • kwin
  •   lib
  • libkonq
Generated for kwin by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |