]> Dogcows Code - chaz/openbox/blobdiff - src/Workspace.cc
merged with 2_1-merged-to-HEAD-2002-09-30
[chaz/openbox] / src / Workspace.cc
index 85f9cdcad6ba169adbf1071926b5fa6a398e7f94..67e191107ccb851cf01987cf28fcd77bcb5de1e6 100644 (file)
@@ -84,12 +84,19 @@ void Workspace::addWindow(BlackboxWindow *w, bool place, bool sticky) {
   if (place) placeWindow(w);
 
   stackingList.push_front(w);
-    
-  if (w->isNormal()) {
+
+  if (! sticky)
+    w->setWorkspace(id);
+  
+  if (! w->isNormal()) {
     if (! sticky) {
-      w->setWorkspace(id);
-      w->setWindowNumber(windowList.size());
+      // just give it some number, else bad things happen as it is assumed to
+      // not be on a workspace
+      w->setWindowNumber(0);
     }
+  } else {
+    if (! sticky)
+      w->setWindowNumber(windowList.size());
 
     windowList.push_back(w);
 
@@ -101,9 +108,7 @@ void Workspace::addWindow(BlackboxWindow *w, bool place, bool sticky) {
 
     if (screen->doFocusNew() || (w->isTransient() && w->getTransientFor() &&
                                  w->getTransientFor()->isFocused())) {
-      if (id == screen->getCurrentWorkspaceID())
-        w->setInputFocus();
-      else {
+      if (id != screen->getCurrentWorkspaceID()) {
         /*
            not on the focused workspace, so the window is not going to get focus
            but if the user wants new windows focused, then it should get focus
@@ -222,14 +227,20 @@ void Workspace::setFocused(const BlackboxWindow *w, bool focused) {
 }
 
 
+void Workspace::removeAll(void) {
+  while (! windowList.empty())
+    windowList.front()->iconify();
+}
+
 void Workspace::showAll(void) {
   BlackboxWindowList::iterator it = stackingList.begin();
   const BlackboxWindowList::iterator end = stackingList.end();
   for (; it != end; ++it) {
     BlackboxWindow *bw = *it;
-    // not normal windows cant focus from mouse enters anyways, so we dont
-    // need to unmap/remap them on workspace changes
-    if (! bw->isStuck() || bw->isNormal())
+    // sticky windows arent unmapped on a workspace change so we don't have ot
+    // map them, but sometimes on a restart, another app can unmap our sticky
+    // windows, so we map on startup always
+    if (! bw->isStuck() || screen->getBlackbox()->isStartup())
       bw->show();
   }
 }
@@ -244,32 +255,29 @@ void Workspace::hideAll(void) {
   const BlackboxWindowList::iterator end = lst.end();
   for (; it != end; ++it) {
     BlackboxWindow *bw = *it;
-    // not normal windows cant focus from mouse enters anyways, so we dont
-    // need to unmap/remap them on workspace changes
-    if (! bw->isStuck() || bw->isNormal())
+    // don't hide sticky windows, or they'll end up flickering on a workspace
+    // change
+    if (! bw->isStuck())
       bw->withdraw();
   }
 }
 
 
-void Workspace::removeAll(void) {
-  while (! windowList.empty())
-    windowList.front()->iconify();
-}
-
 
 /*
  * returns the number of transients for win, plus the number of transients
  * associated with each transient of win
  */
-static int countTransients(const BlackboxWindow * const win) {
-  int ret = win->getTransients().size();
-  if (ret > 0) {
-    BlackboxWindowList::const_iterator it, end = win->getTransients().end();
-    for (it = win->getTransients().begin(); it != end; ++it) {
-      ret += countTransients(*it);
-    }
-  }
+static unsigned int countTransients(const BlackboxWindow * const win) {
+  BlackboxWindowList transients = win->getTransients();
+  if (transients.empty()) return 0;
+
+  unsigned int ret = transients.size();
+  BlackboxWindowList::const_iterator it = transients.begin(),
+    end = transients.end();
+  for (; it != end; ++it)
+    ret += countTransients(*it);
+
   return ret;
 }
 
@@ -282,48 +290,48 @@ static int countTransients(const BlackboxWindow * const win) {
  */
 void Workspace::raiseTransients(const BlackboxWindow * const win,
                                 StackVector::iterator &stack) {
-  if (win->getTransients().size() == 0) return; // nothing to do
+  if (win->getTransients().empty()) return; // nothing to do
 
   // put win's transients in the stack
   BlackboxWindowList::const_iterator it, end = win->getTransients().end();
   for (it = win->getTransients().begin(); it != end; ++it) {
-    *stack++ = (*it)->getFrameWindow();
-    screen->updateNetizenWindowRaise((*it)->getClientWindow());
-
-    if (! (*it)->isIconic()) {
-      Workspace *wkspc = screen->getWorkspace((*it)->getWorkspaceNumber());
-      wkspc->stackingList.remove((*it));
-      wkspc->stackingList.push_front((*it));
+    BlackboxWindow *w = *it;
+    *stack++ = w->getFrameWindow();
+    screen->updateNetizenWindowRaise(w->getClientWindow());
+
+    if (! w->isIconic()) {
+      Workspace *wkspc = screen->getWorkspace(w->getWorkspaceNumber());
+      wkspc->stackingList.remove(w);
+      wkspc->stackingList.push_front(w);
     }
   }
 
   // put transients of win's transients in the stack
-  for (it = win->getTransients().begin(); it != end; ++it) {
+  for (it = win->getTransients().begin(); it != end; ++it)
     raiseTransients(*it, stack);
-  }
 }
 
 
 void Workspace::lowerTransients(const BlackboxWindow * const win,
                                 StackVector::iterator &stack) {
-  if (win->getTransients().size() == 0) return; // nothing to do
+  if (win->getTransients().empty()) return; // nothing to do
 
   // put transients of win's transients in the stack
   BlackboxWindowList::const_reverse_iterator it,
     end = win->getTransients().rend();
-  for (it = win->getTransients().rbegin(); it != end; ++it) {
+  for (it = win->getTransients().rbegin(); it != end; ++it)
     lowerTransients(*it, stack);
-  }
 
   // put win's transients in the stack
   for (it = win->getTransients().rbegin(); it != end; ++it) {
-    *stack++ = (*it)->getFrameWindow();
-    screen->updateNetizenWindowLower((*it)->getClientWindow());
-
-    if (! (*it)->isIconic()) {
-      Workspace *wkspc = screen->getWorkspace((*it)->getWorkspaceNumber());
-      wkspc->stackingList.remove((*it));
-      wkspc->stackingList.push_back((*it));
+    BlackboxWindow *w = *it;
+    *stack++ = w->getFrameWindow();
+    screen->updateNetizenWindowLower(w->getClientWindow());
+
+    if (! w->isIconic()) {
+      Workspace *wkspc = screen->getWorkspace(w->getWorkspaceNumber());
+      wkspc->stackingList.remove(w);
+      wkspc->stackingList.push_back(w);
     }
   }
 }
@@ -335,10 +343,8 @@ void Workspace::raiseWindow(BlackboxWindow *w) {
   if (win->isDesktop()) return;
 
   // walk up the transient_for's to the window that is not a transient
-  while (win->isTransient() && ! win->isDesktop()) {
-    if (! win->getTransientFor()) break;
+  while (win->isTransient() && win->getTransientFor())
     win = win->getTransientFor();
-  }
 
   // get the total window count (win and all transients)
   unsigned int i = 1 + countTransients(win);
@@ -365,10 +371,8 @@ void Workspace::lowerWindow(BlackboxWindow *w) {
   BlackboxWindow *win = w;
 
   // walk up the transient_for's to the window that is not a transient
-  while (win->isTransient() && ! win->isDesktop()) {
-    if (! win->getTransientFor()) break;
+  while (win->isTransient() && win->getTransientFor())
     win = win->getTransientFor();
-  }
 
   // get the total window count (win and all transients)
   unsigned int i = 1 + countTransients(win);
@@ -401,9 +405,11 @@ void Workspace::reconfigure(void) {
 BlackboxWindow *Workspace::getWindow(unsigned int index) {
   if (index < windowList.size()) {
     BlackboxWindowList::iterator it = windowList.begin();
-    for(; index > 0; --index, ++it); /* increment to index */
+    while (index-- > 0) // increment to index
+      ++it;
     return *it;
   }
+
   return 0;
 }
 
@@ -435,6 +441,7 @@ BlackboxWindow* Workspace::getPrevWindowInList(BlackboxWindow *w) {
 
 
 BlackboxWindow* Workspace::getTopWindowOnStack(void) const {
+  assert(! stackingList.empty());
   return stackingList.front();
 }
 
@@ -456,10 +463,12 @@ void Workspace::appendStackOrder(BlackboxWindowList &stack_order) const {
   BlackboxWindowList::const_reverse_iterator it = stackingList.rbegin();
   const BlackboxWindowList::const_reverse_iterator end = stackingList.rend();
   for (; it != end; ++it)
-    if ((*it)->isNormal())
+    // don't add desktop wnidows, or sticky windows more than once
+    if (! ( (*it)->isDesktop() ||
+            ((*it)->isStuck() && id != screen->getCurrentWorkspaceID())))
       stack_order.push_back(*it);
 }
-  
+
 
 bool Workspace::isCurrent(void) const {
   return (id == screen->getCurrentWorkspaceID());
@@ -524,9 +533,8 @@ void Workspace::setName(const string& new_name) {
 /*
  * Calculate free space available for window placement.
  */
-typedef std::vector<Rect> rectList;
-
-static rectList calcSpace(const Rect &win, const rectList &spaces) {
+Workspace::rectList Workspace::calcSpace(const Rect &win,
+                                         const rectList &spaces) const {
   Rect isect, extra;
   rectList result;
   rectList::const_iterator siter, end = spaces.end();
@@ -547,21 +555,21 @@ static rectList calcSpace(const Rect &win, const rectList &spaces) {
 
     // left
     extra.setCoords(curr.left(), curr.top(),
-                    isect.left() - 1, curr.bottom());
+                    isect.left() - screen->getSnapOffset(), curr.bottom());
     if (extra.valid()) result.push_back(extra);
 
     // top
     extra.setCoords(curr.left(), curr.top(),
-                    curr.right(), isect.top() - 1);
+                    curr.right(), isect.top() - screen->getSnapOffset());
     if (extra.valid()) result.push_back(extra);
 
     // right
-    extra.setCoords(isect.right() + 1, curr.top(),
+    extra.setCoords(isect.right() + screen->getSnapOffset(), curr.top(),
                     curr.right(), curr.bottom());
     if (extra.valid()) result.push_back(extra);
 
     // bottom
-    extra.setCoords(curr.left(), isect.bottom() + 1,
+    extra.setCoords(curr.left(), isect.bottom() + screen->getSnapOffset(),
                     curr.right(), curr.bottom());
     if (extra.valid()) result.push_back(extra);
   }
@@ -628,11 +636,24 @@ bool Workspace::smartPlacement(Rect& win) {
     RectList availableAreas = screen->allAvailableAreas();
     RectList::iterator it, end = availableAreas.end();
 
-    for (it = availableAreas.begin(); it != end; ++it)
+    for (it = availableAreas.begin(); it != end; ++it) {
+      Rect r = *it;
+      r.setRect(r.x() + screen->getSnapOffset(),
+                r.y() + screen->getSnapOffset(),
+                r.width() - screen->getSnapOffset(),
+                r.height() - screen->getSnapOffset());
       spaces.push_back(*it);
+    }
   } else
 #endif // XINERAMA
-    spaces.push_back(screen->availableArea());
+  {
+    Rect r = screen->availableArea();
+    r.setRect(r.x() + screen->getSnapOffset(),
+              r.y() + screen->getSnapOffset(),
+              r.width() - screen->getSnapOffset(),
+              r.height() - screen->getSnapOffset());
+    spaces.push_back(r);
+  }
 
   //Find Free Spaces
   BlackboxWindowList::const_iterator wit = windowList.begin(),
This page took 0.02719 seconds and 4 git commands to generate.