]> Dogcows Code - chaz/openbox/blobdiff - src/Screen.cc
moved menu from a rc file option to a command line option
[chaz/openbox] / src / Screen.cc
index e7f6f6f3f8c6f5ac0b8fd63c38e1edd5c7a194ae..7338f118ad292948d8cafa5302ef9624e595ef3f 100644 (file)
@@ -49,6 +49,7 @@
 #include "Window.h"
 #include "Workspace.h"
 #include "Workspacemenu.h"
+#include "Util.h"
 
 #ifdef    HAVE_STDLIB_H
 #  include <stdlib.h>
 #include <strstream>
 #include <string>
 #include <algorithm>
+#include <functional>
+using std::ends;
 
 static Bool running = True;
 
@@ -213,11 +216,16 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn),
     resource.tstyle.fontset = resource.wstyle.fontset = NULL;
   resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
     resource.wstyle.font = NULL;
+  resource.root_command = NULL;
+#ifdef    HAVE_STRFTIME
+  resource.strftime_format = NULL;
+#endif // HAVE_STRFTIME
 
 #ifdef   SLIT
   slit = NULL;
 #endif // SLIT
   toolbar = NULL;
+  current_workspace = (Workspace *) 0;
 
 #ifdef    HAVE_GETPID
   pid_t bpid = getpid();
@@ -231,20 +239,12 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn),
   XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
                 openbox.getSessionCursor());
 
-  workspaceNames = new LinkedList<char>;
-  workspacesList = new LinkedList<Workspace>;
-  rootmenuList = new LinkedList<Rootmenu>;
-  netizenList = new LinkedList<Netizen>;
-  iconList = new LinkedList<OpenboxWindow>;
-
   image_control =
     new BImageControl(openbox, *this, True, openbox.getColorsPerChannel(),
                       openbox.getCacheLife(), openbox.getCacheMax());
   image_control->installRootColormap();
   root_colormap_installed = True;
 
-  image_control->setDither(resource.image_dither);
-
   load();       // load config options from Resources
   LoadStyle();
 
@@ -401,23 +401,23 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn),
   Workspace *wkspc = NULL;
   if (resource.workspaces != 0) {
     for (int i = 0; i < resource.workspaces; ++i) {
-      wkspc = new Workspace(*this, workspacesList->count());
-      workspacesList->insert(wkspc);
-      saveWorkspaceNames();
+      wkspc = new Workspace(*this, workspacesList.size());
+      workspacesList.push_back(wkspc);
       workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
     }
   } else {
-    wkspc = new Workspace(*this, workspacesList->count());
-    workspacesList->insert(wkspc);
-    saveWorkspaceNames();
+    setWorkspaceCount(1);
+    wkspc = new Workspace(*this, workspacesList.size());
+    workspacesList.push_back(wkspc);
     workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
   }
+  saveWorkspaceNames();
 
   workspacemenu->insert(i18n->getMessage(IconSet, IconIcons, "Icons"),
                        iconmenu);
   workspacemenu->update();
 
-  current_workspace = workspacesList->first();
+  current_workspace = workspacesList.front();
   workspacemenu->setItemSelected(2, True);
 
   toolbar = new Toolbar(*this, config);
@@ -484,10 +484,6 @@ BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn),
     }
   }
 
-  if (! resource.sloppy_focus)
-    XSetInputFocus(getBaseDisplay().getXDisplay(), toolbar->getWindowID(),
-                  RevertToParent, CurrentTime);
-
   XFree(children);
   XFlush(getBaseDisplay().getXDisplay());
 }
@@ -504,17 +500,10 @@ BScreen::~BScreen(void) {
 
   removeWorkspaceNames();
 
-  while (workspacesList->count())
-    delete workspacesList->remove(0);
-
-  while (rootmenuList->count())
-    rootmenuList->remove(0);
-
-  while (iconList->count())
-    delete iconList->remove(0);
-
-  while (netizenList->count())
-    delete netizenList->remove(0);
+  std::for_each(workspacesList.begin(), workspacesList.end(),
+                PointerAssassin());
+  std::for_each(iconList.begin(), iconList.end(), PointerAssassin());
+  std::for_each(netizenList.begin(), netizenList.end(), PointerAssassin());
 
 #ifdef    HAVE_STRFTIME
   if (resource.strftime_format)
@@ -533,12 +522,6 @@ BScreen::~BScreen(void) {
   delete toolbar;
   delete image_control;
 
-  delete workspacesList;
-  delete workspaceNames;
-  delete rootmenuList;
-  delete iconList;
-  delete netizenList;
-
   if (resource.wstyle.fontset)
     XFreeFontSet(getBaseDisplay().getXDisplay(), resource.wstyle.fontset);
   if (resource.mstyle.t_fontset)
@@ -591,6 +574,108 @@ BScreen::~BScreen(void) {
          resource.tstyle.b_pic_gc);
 }
 
+
+Rect BScreen::availableArea() const {
+  // the following code is temporary and will be taken care of by Screen in the
+  // future (with the NETWM 'strut')
+  Rect space(0, 0, size().w(), size().h());
+  if (!resource.full_max) {
+#ifdef    SLIT
+    int slit_x = slit->autoHide() ? slit->hiddenOrigin().x() : slit->area().x(),
+    slit_y = slit->autoHide() ? slit->hiddenOrigin().y() : slit->area().y();
+    unsigned int tbarh = resource.hide_toolbar ? 0 :
+      toolbar->getExposedHeight() + resource.border_width * 2;
+    bool tbartop;
+    switch (toolbar->placement()) {
+    case Toolbar::TopLeft:
+    case Toolbar::TopCenter:
+    case Toolbar::TopRight:
+      tbartop = true;
+      break;
+    case Toolbar::BottomLeft:
+    case Toolbar::BottomCenter:
+    case Toolbar::BottomRight:
+      tbartop = false;
+      break;
+    default:
+      ASSERT(false);      // unhandled placement
+    }
+    if ((slit->direction() == Slit::Horizontal &&
+         (slit->placement() == Slit::TopLeft ||
+          slit->placement() == Slit::TopRight)) ||
+        slit->placement() == Slit::TopCenter) {
+      // exclude top
+      if (tbartop && slit_y + slit->area().h() < tbarh) {
+        space.setY(space.y() + tbarh);
+        space.setH(space.h() - tbarh);
+      } else {
+        space.setY(space.y() + (slit_y + slit->area().h() +
+                                resource.border_width * 2));
+        space.setH(space.h() - (slit_y + slit->area().h() +
+                                resource.border_width * 2));
+        if (!tbartop)
+          space.setH(space.h() - tbarh);
+      }
+    } else if ((slit->direction() == Slit::Vertical &&
+                (slit->placement() == Slit::TopRight ||
+                 slit->placement() == Slit::BottomRight)) ||
+               slit->placement() == Slit::CenterRight) {
+      // exclude right
+      space.setW(space.w() - (size().w() - slit_x));
+      if (tbartop)
+        space.setY(space.y() + tbarh);
+      space.setH(space.h() - tbarh);
+    } else if ((slit->direction() == Slit::Horizontal &&
+                (slit->placement() == Slit::BottomLeft ||
+                 slit->placement() == Slit::BottomRight)) ||
+               slit->placement() == Slit::BottomCenter) {
+      // exclude bottom
+      if (!tbartop && (size().h() - slit_y) < tbarh) {
+        space.setH(space.h() - tbarh);
+      } else {
+        space.setH(space.h() - (size().h() - slit_y));
+        if (tbartop) {
+          space.setY(space.y() + tbarh);
+          space.setH(space.h() - tbarh);
+        }
+      }
+    } else {// if ((slit->direction() == Slit::Vertical &&
+      //      (slit->placement() == Slit::TopLeft ||
+      //       slit->placement() == Slit::BottomLeft)) ||
+      //     slit->placement() == Slit::CenterLeft)
+      // exclude left
+      space.setX(slit_x + slit->area().w() +
+                 resource.border_width * 2);
+      space.setW(space.w() - (slit_x + slit->area().w() +
+                              resource.border_width * 2));
+      if (tbartop)
+        space.setY(space.y() + tbarh);
+      space.setH(space.h() - tbarh);
+    }
+#else // !SLIT
+    int tbarh = resource.hide_toolbar() ? 0 :
+      toolbar->getExposedHeight() + resource.border_width * 2;
+    switch (toolbar->placement()) {
+    case Toolbar::TopLeft:
+    case Toolbar::TopCenter:
+    case Toolbar::TopRight:
+      space.setY(toolbar->getExposedHeight());
+      space.setH(space.h() - toolbar->getExposedHeight());
+      break;
+    case Toolbar::BottomLeft:
+    case Toolbar::BottomCenter:
+    case Toolbar::BottomRight:
+      space.setH(space.h() - tbarh);
+      break;
+    default:
+      ASSERT(false);      // unhandled placement
+    }
+#endif // SLIT
+  }
+  return space;
+}
+
+
 void BScreen::readDatabaseTexture(const char *rname, const char *rclass,
                                  BTexture *texture,
                                  unsigned long default_pixel)
@@ -697,7 +782,7 @@ void BScreen::readDatabaseColor(const char *rname, const  char *rclass,
   if (resource.styleconfig.getValue(rname, rclass, s))
     image_control->parseColor(color, s.c_str());
   else {
-    // parsing with no color string just deallocates the color, if it has
+    // parsing with no color std::string just deallocates the color, if it has
     // been previously allocated
     image_control->parseColor(color);
     color->setPixel(default_pixel);
@@ -851,13 +936,13 @@ void BScreen::setAutoRaise(bool a) {
 
 
 void BScreen::setImageDither(bool d, bool reconfig) {
-  resource.image_dither = d;
+  image_control->setDither(d);
   std::ostrstream s;
   s << "session.screen" << getScreenNumber() << ".imageDither" << ends;
-  config.setValue(s.str(), resource.image_dither);
-  s.rdbuf()->freeze(0);
+  config.setValue(s.str(), imageDither());
   if (reconfig)
-    openbox.reconfigure();
+    reconfigure();
+  s.rdbuf()->freeze(0);
 }
 
 
@@ -924,6 +1009,8 @@ void BScreen::setPlacementPolicy(int p) {
   case CascadePlacement: placement = "CascadePlacement"; break;
   case BestFitPlacement: placement = "BestFitPlacement"; break;
   case ColSmartPlacement: placement = "ColSmartPlacement"; break;
+  case UnderMousePlacement: placement = "UnderMousePlacement"; break;
+  case ClickMousePlacement: placement = "ClickMousePlacement"; break;
   default:
   case RowSmartPlacement: placement = "RowSmartPlacement"; break;
   }
@@ -944,8 +1031,7 @@ void BScreen::setEdgeSnapThreshold(int t) {
 void BScreen::setRowPlacementDirection(int d) {
   resource.row_direction = d;
   std::ostrstream s;
-  s << "session.screen" << getScreenNumber() << ".rowPlacementDirection" <<
-    ends;
+  s << "session.screen" << getScreenNumber() << ".rowPlacementDirection" << ends;
   config.setValue(s.str(),
                   resource.row_direction == LeftRight ?
                   "LeftToRight" : "RightToLeft");
@@ -956,8 +1042,7 @@ void BScreen::setRowPlacementDirection(int d) {
 void BScreen::setColPlacementDirection(int d) {
   resource.col_direction = d;
   std::ostrstream s;
-  s << "session.screen" << getScreenNumber() << ".colPlacementDirection" <<
-    ends;
+  s << "session.screen" << getScreenNumber() << ".colPlacementDirection" << ends;
   config.setValue(s.str(),
                   resource.col_direction == TopBottom ?
                   "TopToBottom" : "BottomToTop");
@@ -991,6 +1076,7 @@ void BScreen::setStrftimeFormat(const char *f) {
 }
 
 #else // !HAVE_STRFTIME
+
 void BScreen::setDateFormat(int f) {
   resource.date_format = f;
   std::ostrstream s;
@@ -1000,6 +1086,7 @@ void BScreen::setDateFormat(int f) {
   s.rdbuf()->freeze(0);
 }
 
+
 void BScreen::setClock24Hour(Bool c) {
   resource.clock24hour = c;
   std::ostrstream s;
@@ -1009,6 +1096,7 @@ void BScreen::setClock24Hour(Bool c) {
 }
 #endif // HAVE_STRFTIME
 
+
 void BScreen::setHideToolbar(bool b) {
   resource.hide_toolbar = b;
   if (resource.hide_toolbar)
@@ -1021,16 +1109,16 @@ void BScreen::setHideToolbar(bool b) {
   s.rdbuf()->freeze(0);
 }
 
+
 void BScreen::saveWorkspaceNames() {
   std::ostrstream rc, names;
 
-  for (int i = 0; i < resource.workspaces; i++) {
-    Workspace *w = getWorkspace(i);
-    if (w != NULL) {
-      names << w->getName();
-      if (i < resource.workspaces-1)
-        names << ',';
-    }
+  wkspList::iterator it;
+  wkspList::iterator last = workspacesList.end() - 1;
+  for (it = workspacesList.begin(); it != workspacesList.end(); ++it) {
+    names << (*it)->getName();
+    if (it != last)
+      names << ",";
   }
   names << ends;
 
@@ -1043,7 +1131,7 @@ void BScreen::saveWorkspaceNames() {
 void BScreen::save() {
   setSloppyFocus(resource.sloppy_focus);
   setAutoRaise(resource.auto_raise);
-  setImageDither(resource.image_dither, false);
+  setImageDither(imageDither(), false);
   setOpaqueMove(resource.opaque_move);
   setFullMax(resource.full_max);
   setFocusNew(resource.focus_new);
@@ -1065,8 +1153,14 @@ void BScreen::save() {
   setClock24Hour(resource.clock24hour);
 #endif // HAVE_STRFTIME
   setHideToolbar(resource.hide_toolbar);
+    
+  toolbar->save();
+#ifdef    SLIT
+  slit->save();
+#endif // SLIT
 }
 
+
 void BScreen::load() {
   std::ostrstream rscreen, rname, rclass;
   std::string s;
@@ -1089,6 +1183,7 @@ void BScreen::load() {
   }
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "fullMaximization" << ends;
   rclass << rscreen.str() << "FullMaximization" << ends;
   if (config.getValue(rname.str(), rclass.str(), b))
@@ -1097,6 +1192,7 @@ void BScreen::load() {
     resource.full_max = false;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "focusNewWindows" << ends;
   rclass << rscreen.str() << "FocusNewWindows" << ends;
   if (config.getValue(rname.str(), rclass.str(), b))
@@ -1105,6 +1201,7 @@ void BScreen::load() {
     resource.focus_new = false;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "focusLastWindow" << ends;
   rclass << rscreen.str() << "FocusLastWindow" << ends;
   if (config.getValue(rname.str(), rclass.str(), b))
@@ -1113,37 +1210,41 @@ void BScreen::load() {
     resource.focus_last = false;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "rowPlacementDirection" << ends;
   rclass << rscreen.str() << "RowPlacementDirection" << ends;
   if (config.getValue(rname.str(), rclass.str(), s)) {
     if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length()))
       resource.row_direction = RightLeft;
-    else if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
+    else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
       resource.row_direction = LeftRight;
   } else
     resource.row_direction = LeftRight;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "colPlacementDirection" << ends;
   rclass << rscreen.str() << "ColPlacementDirection" << ends;
   if (config.getValue(rname.str(), rclass.str(), s)) {
     if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length()))
       resource.col_direction = BottomTop;
-    else if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
+    else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
       resource.col_direction = TopBottom;
   } else
     resource.col_direction = TopBottom;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "workspaces" << ends;
   rclass << rscreen.str() << "Workspaces" << ends;
-  if (config.getValue(rname.str(), rclass.str(), l))
+  if (config.getValue(rname.str(), rclass.str(), l)) {
     resource.workspaces = l;
-  else
+  }  else
     resource.workspaces = 1;
 
   removeWorkspaceNames();
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "workspaceNames" << ends;
   rclass << rscreen.str() << "WorkspaceNames" << ends;
   if (config.getValue(rname.str(), rclass.str(), s)) {
@@ -1160,6 +1261,7 @@ void BScreen::load() {
   }
   
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "focusModel" << ends;
   rclass << rscreen.str() << "FocusModel" << ends;
   if (config.getValue(rname.str(), rclass.str(), s)) {
@@ -1170,7 +1272,7 @@ void BScreen::load() {
                                 s.length())) {
       resource.sloppy_focus = true;
       resource.auto_raise = true;
-    } else if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
+    } else { //if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
       resource.sloppy_focus = true;
       resource.auto_raise = false;
     }
@@ -1180,6 +1282,7 @@ void BScreen::load() {
   }
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "windowZones" << ends;
   rclass << rscreen.str() << "WindowZones" << ends;
   if (config.getValue(rname.str(), rclass.str(), l))
@@ -1188,6 +1291,7 @@ void BScreen::load() {
     resource.zones = 4;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "windowPlacement" << ends;
   rclass << rscreen.str() << "WindowPlacement" << ends;
   if (config.getValue(rname.str(), rclass.str(), s)) {
@@ -1197,13 +1301,18 @@ void BScreen::load() {
       resource.placement_policy = ColSmartPlacement;
     else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length()))
       resource.placement_policy = BestFitPlacement;
-    else if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
+    else if (0 == strncasecmp(s.c_str(), "UnderMousePlacement", s.length()))
+      resource.placement_policy = UnderMousePlacement;
+    else if (0 == strncasecmp(s.c_str(), "ClickMousePlacement", s.length()))
+      resource.placement_policy = ClickMousePlacement;
+    else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
       resource.placement_policy = CascadePlacement;
   } else
     resource.placement_policy = CascadePlacement;
 
 #ifdef    HAVE_STRFTIME
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "strftimeFormat" << ends;
   rclass << rscreen.str() << "StrftimeFormat" << ends;
 
@@ -1216,17 +1325,19 @@ void BScreen::load() {
     resource.strftime_format = bstrdup("%I:%M %p");
 #else // !HAVE_STRFTIME
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "dateFormat" << ends;
   rclass << rscreen.str() << "DateFormat" << ends;
   if (config.getValue(rname.str(), rclass.str(), s)) {
     if (strncasecmp(s.c_str(), "European", s.length()))
       resource.date_format = B_EuropeanDate;
-    else if (strncasecmp(s.c_str(), "American", s.length()))
+    else //if (strncasecmp(s.c_str(), "American", s.length()))
       resource.date_format = B_AmericanDate;
   } else
     resource.date_format = B_AmericanDate;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "clockFormat" << ends;
   rclass << rscreen.str() << "ClockFormat" << ends;
   if (config.getValue(rname.str(), rclass.str(), l)) {
@@ -1239,6 +1350,7 @@ void BScreen::load() {
 #endif // HAVE_STRFTIME
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "edgeSnapThreshold" << ends;
   rclass << rscreen.str() << "EdgeSnapThreshold" << ends;
   if (config.getValue(rname.str(), rclass.str(), l))
@@ -1247,14 +1359,16 @@ void BScreen::load() {
     resource.edge_snap_threshold = 4;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "imageDither" << ends;
   rclass << rscreen.str() << "ImageDither" << ends;
   if (config.getValue(rname.str(), rclass.str(), b))
-    resource.image_dither = b;
+    image_control->setDither(b);
   else
-    resource.image_dither = true;
+    image_control->setDither(true);
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "rootCommand" << ends;
   rclass << rscreen.str() << "RootCommand" << ends;
 
@@ -1267,6 +1381,7 @@ void BScreen::load() {
     resource.root_command = NULL;
 
   rname.seekp(0); rclass.seekp(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
   rname << rscreen.str() << "opaqueMove" << ends;
   rclass << rscreen.str() << "OpaqueMove" << ends;
   if (config.getValue(rname.str(), rclass.str(), b))
@@ -1275,8 +1390,7 @@ void BScreen::load() {
     resource.opaque_move = false;
 
   rscreen.rdbuf()->freeze(0);
-  rname.rdbuf()->freeze(0);
-  rclass.rdbuf()->freeze(0);
+  rname.rdbuf()->freeze(0); rclass.rdbuf()->freeze(0);
 }
 
 void BScreen::reconfigure(void) {
@@ -1430,14 +1544,12 @@ void BScreen::reconfigure(void) {
   slit->reconfigure();
 #endif // SLIT
 
-  LinkedListIterator<Workspace> wit(workspacesList);
-  for (Workspace *w = wit.current(); w; wit++, w = wit.current())
-    w->reconfigure();
+  std::for_each(workspacesList.begin(), workspacesList.end(),
+                std::mem_fun(&Workspace::reconfigure));
 
-  LinkedListIterator<OpenboxWindow> iit(iconList);
-  for (OpenboxWindow *bw = iit.current(); bw; iit++, bw = iit.current())
-    if (bw->validateClient())
-      bw->reconfigure();
+  for (winList::iterator it = iconList.begin(); it != iconList.end(); ++it)
+    if ((*it)->validateClient())
+      (*it)->reconfigure();
 
   image_control->timeout();
 }
@@ -1452,8 +1564,7 @@ void BScreen::rereadMenu(void) {
 
 
 void BScreen::removeWorkspaceNames(void) {
-  while (workspaceNames->count())
-    delete [] workspaceNames->remove(0);
+  workspaceNames.clear();
 }
 
 
@@ -1725,7 +1836,7 @@ void BScreen::LoadStyle(void) {
 
   // load bevel, border and handle widths
   if (conf.getValue("handleWidth", "HandleWidth", l)) {
-    if (l <= size().w() / 2 && l != 0)
+    if (l <= (signed)size().w() / 2 && l != 0)
       resource.handle_width = l;
     else
       resource.handle_width = 6;
@@ -1738,7 +1849,7 @@ void BScreen::LoadStyle(void) {
     resource.border_width = 1;
 
   if (conf.getValue("bevelWidth", "BevelWidth", l)) {
-    if (l <= size().w() / 2 && l != 0)
+    if (l <= (signed)size().w() / 2 && l != 0)
       resource.bevel_width = l;
     else
       resource.bevel_width = 3;
@@ -1746,7 +1857,7 @@ void BScreen::LoadStyle(void) {
     resource.bevel_width = 3;
 
   if (conf.getValue("frameWidth", "FrameWidth", l)) {
-    if (l <= size().w() / 2)
+    if (l <= (signed)size().w() / 2)
       resource.frame_width = l;
     else
       resource.frame_width = resource.bevel_width;
@@ -1777,9 +1888,9 @@ void BScreen::addIcon(OpenboxWindow *w) {
   if (! w) return;
 
   w->setWorkspace(-1);
-  w->setWindowNumber(iconList->count());
+  w->setWindowNumber(iconList.size());
 
-  iconList->insert(w);
+  iconList.push_back(w);
 
   iconmenu->insert((const char **) w->getIconTitle());
   iconmenu->update();
@@ -1789,29 +1900,31 @@ void BScreen::addIcon(OpenboxWindow *w) {
 void BScreen::removeIcon(OpenboxWindow *w) {
   if (! w) return;
 
-  iconList->remove(w->getWindowNumber());
+  iconList.remove(w);
 
   iconmenu->remove(w->getWindowNumber());
   iconmenu->update();
 
-  LinkedListIterator<OpenboxWindow> it(iconList);
-  OpenboxWindow *bw = it.current();
-  for (int i = 0; bw; it++, bw = it.current())
-    bw->setWindowNumber(i++);
+  winList::iterator it = iconList.begin();
+  for (int i = 0; it != iconList.end(); ++it, ++i)
+    (*it)->setWindowNumber(i);
 }
 
 
 OpenboxWindow *BScreen::getIcon(int index) {
-  if (index >= 0 && index < iconList->count())
-    return iconList->find(index);
+  if (index < 0 || index >= (signed)iconList.size())
+    return (OpenboxWindow *) 0;
 
-  return NULL;
+  winList::iterator it = iconList.begin();
+  for (; index > 0; --index, ++it);     // increment to index
+  return *it;
 }
 
 
 int BScreen::addWorkspace(void) {
-  Workspace *wkspc = new Workspace(*this, workspacesList->count());
-  workspacesList->insert(wkspc);
+  Workspace *wkspc = new Workspace(*this, workspacesList.size());
+  workspacesList.push_back(wkspc);
+  setWorkspaceCount(workspaceCount()+1);
   saveWorkspaceNames();
 
   workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
@@ -1822,15 +1935,15 @@ int BScreen::addWorkspace(void) {
 
   updateNetizenWorkspaceCount();
 
-  return workspacesList->count();
+  return workspacesList.size();
 }
 
 
 int BScreen::removeLastWorkspace(void) {
-  if (workspacesList->count() == 1)
+  if (workspacesList.size() == 1)
     return 0;
 
-  Workspace *wkspc = workspacesList->last();
+  Workspace *wkspc = workspacesList.back();
 
   if (current_workspace->getWorkspaceID() == wkspc->getWorkspaceID())
     changeWorkspaceID(current_workspace->getWorkspaceID() - 1);
@@ -1840,14 +1953,17 @@ int BScreen::removeLastWorkspace(void) {
   workspacemenu->remove(wkspc->getWorkspaceID() + 2);
   workspacemenu->update();
 
-  workspacesList->remove(wkspc);
+  workspacesList.pop_back();
   delete wkspc;
+  
+  setWorkspaceCount(workspaceCount()-1);
+  saveWorkspaceNames();
 
   toolbar->reconfigure();
 
   updateNetizenWorkspaceCount();
 
-  return workspacesList->count();
+  return workspacesList.size();
 }
 
 
@@ -1860,11 +1976,10 @@ void BScreen::changeWorkspaceID(int id) {
     workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
                                   False);
 
-    if (openbox.getFocusedWindow() &&
-       openbox.getFocusedWindow()->getScreen() == this &&
-        (! openbox.getFocusedWindow()->isStuck())) {
-      current_workspace->setLastFocusedWindow(openbox.getFocusedWindow());
-      openbox.setFocusedWindow(NULL);
+    if (openbox.focusedWindow() &&
+       openbox.focusedWindow()->getScreen() == this &&
+        (! openbox.focusedWindow()->isStuck())) {
+      openbox.focusWindow(0);
     }
 
     current_workspace = getWorkspace(id);
@@ -1875,9 +1990,9 @@ void BScreen::changeWorkspaceID(int id) {
 
     current_workspace->showAll();
 
-    if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
+    if (resource.focus_last && current_workspace->lastFocusedWindow()) {
       XSync(openbox.getXDisplay(), False);
-      current_workspace->getLastFocusedWindow()->setInputFocus();
+      current_workspace->lastFocusedWindow()->setInputFocus();
     }
   }
 
@@ -1886,107 +2001,106 @@ void BScreen::changeWorkspaceID(int id) {
 
 
 void BScreen::addNetizen(Netizen *n) {
-  netizenList->insert(n);
+  netizenList.push_back(n);
 
   n->sendWorkspaceCount();
   n->sendCurrentWorkspace();
 
-  LinkedListIterator<Workspace> it(workspacesList);
-  for (Workspace *w = it.current(); w; it++, w = it.current()) {
-    for (int i = 0; i < w->getCount(); i++)
-      n->sendWindowAdd(w->getWindow(i)->getClientWindow(),
-                      w->getWorkspaceID());
+  wkspList::iterator it;
+  for (it = workspacesList.begin(); it != workspacesList.end(); ++it) {
+    for (int i = 0; i < (*it)->getCount(); i++)
+      n->sendWindowAdd((*it)->getWindow(i)->getClientWindow(),
+                      (*it)->getWorkspaceID());
   }
 
-  Window f = ((openbox.getFocusedWindow()) ?
-              openbox.getFocusedWindow()->getClientWindow() : None);
+  Window f = ((openbox.focusedWindow()) ?
+              openbox.focusedWindow()->getClientWindow() : None);
   n->sendWindowFocus(f);
 }
 
 
 void BScreen::removeNetizen(Window w) {
-  LinkedListIterator<Netizen> it(netizenList);
-  int i = 0;
+  netList::iterator it;
 
-  for (Netizen *n = it.current(); n; it++, i++, n = it.current())
-    if (n->getWindowID() == w) {
-      Netizen *tmp = netizenList->remove(i);
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    if ((*it)->getWindowID() == w) {
+      Netizen *tmp = *it;
+      netizenList.erase(it);
       delete tmp;
-
       break;
     }
 }
 
 
 void BScreen::updateNetizenCurrentWorkspace(void) {
-  LinkedListIterator<Netizen> it(netizenList);
-  for (Netizen *n = it.current(); n; it++, n = it.current())
-    n->sendCurrentWorkspace();
+  netList::iterator it;
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    (*it)->sendCurrentWorkspace();
 }
 
 
 void BScreen::updateNetizenWorkspaceCount(void) {
-  LinkedListIterator<Netizen> it(netizenList);
-  for (Netizen *n = it.current(); n; it++, n = it.current())
-    n->sendWorkspaceCount();
+  netList::iterator it;
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    (*it)->sendWorkspaceCount();
 }
 
 
 void BScreen::updateNetizenWindowFocus(void) {
-  Window f = ((openbox.getFocusedWindow()) ?
-              openbox.getFocusedWindow()->getClientWindow() : None);
-  LinkedListIterator<Netizen> it(netizenList);
-  for (Netizen *n = it.current(); n; it++, n = it.current())
-    n->sendWindowFocus(f);
+  Window f = ((openbox.focusedWindow()) ?
+              openbox.focusedWindow()->getClientWindow() : None);
+  netList::iterator it;
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    (*it)->sendWindowFocus(f);
 }
 
 
 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
-  LinkedListIterator<Netizen> it(netizenList);
-  for (Netizen *n = it.current(); n; it++, n = it.current())
-    n->sendWindowAdd(w, p);
+  netList::iterator it;
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    (*it)->sendWindowAdd(w, p);
 }
 
 
 void BScreen::updateNetizenWindowDel(Window w) {
-  LinkedListIterator<Netizen> it(netizenList);
-  for (Netizen *n = it.current(); n; it++, n = it.current())
-    n->sendWindowDel(w);
+  netList::iterator it;
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    (*it)->sendWindowDel(w);
 }
 
 
 void BScreen::updateNetizenWindowRaise(Window w) {
-  LinkedListIterator<Netizen> it(netizenList);
-  for (Netizen *n = it.current(); n; it++, n = it.current())
-    n->sendWindowRaise(w);
+  netList::iterator it;
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    (*it)->sendWindowRaise(w);
 }
 
 
 void BScreen::updateNetizenWindowLower(Window w) {
-  LinkedListIterator<Netizen> it(netizenList);
-  for (Netizen *n = it.current(); n; it++, n = it.current())
-    n->sendWindowLower(w);
+  netList::iterator it;
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    (*it)->sendWindowLower(w);
 }
 
 
 void BScreen::updateNetizenConfigNotify(XEvent *e) {
-  LinkedListIterator<Netizen> it(netizenList);
-  for (Netizen *n = it.current(); n; it++, n = it.current())
-    n->sendConfigNotify(e);
+  netList::iterator it;
+  for (it = netizenList.begin(); it != netizenList.end(); ++it)
+    (*it)->sendConfigNotify(e);
 }
 
 
 void BScreen::raiseWindows(Window *workspace_stack, int num) {
   Window *session_stack = new
-    Window[(num + workspacesList->count() + rootmenuList->count() + 13)];
+    Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
   int i = 0, k = num;
 
   XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu->getWindowID());
   *(session_stack + i++) = iconmenu->getWindowID();
 
-  LinkedListIterator<Workspace> wit(workspacesList);
-  for (Workspace *tmp = wit.current(); tmp; wit++, tmp = wit.current())
-    *(session_stack + i++) = tmp->getMenu()->getWindowID();
+  wkspList::iterator it;
+  for (it = workspacesList.begin(); it != workspacesList.end(); ++it)
+    *(session_stack + i++) = (*it)->getMenu()->getWindowID();
 
   *(session_stack + i++) = workspacemenu->getWindowID();
 
@@ -2004,9 +2118,9 @@ void BScreen::raiseWindows(Window *workspace_stack, int num) {
     toolbar->getMenu()->getPlacementmenu()->getWindowID();
   *(session_stack + i++) = toolbar->getMenu()->getWindowID();
 
-  LinkedListIterator<Rootmenu> rit(rootmenuList);
-  for (Rootmenu *tmp = rit.current(); tmp; rit++, tmp = rit.current())
-    *(session_stack + i++) = tmp->getWindowID();
+  menuList::iterator rit;
+  for (rit = rootmenuList.begin(); rit != rootmenuList.end(); ++rit)
+    *(session_stack + i++) = (*rit)->getWindowID();
   *(session_stack + i++) = rootmenu->getWindowID();
 
   if (toolbar->onTop())
@@ -2027,19 +2141,14 @@ void BScreen::raiseWindows(Window *workspace_stack, int num) {
 
 
 void BScreen::addWorkspaceName(const char *name) {
-  workspaceNames->insert(bstrdup(name));
+  workspaceNames.push_back(name);
 }
 
-char* BScreen::getNameOfWorkspace(int id) {
-  char *name = NULL;
-
-  if (id >= 0 && id < workspaceNames->count()) {
-    char *wkspc_name = workspaceNames->find(id);
 
-    if (wkspc_name)
-      name = wkspc_name;
-  }
-  return name;
+const char *BScreen::getNameOfWorkspace(int id) {
+  if (id < 0 || id >= (signed)workspaceNames.size())
+    return (const char *) 0;
+  return workspaceNames[id].c_str();
 }
 
 
@@ -2067,11 +2176,11 @@ void BScreen::nextFocus(void) {
   int focused_window_number = -1;
   OpenboxWindow *next;
 
-  if (openbox.getFocusedWindow()) {
-    if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
+  if (openbox.focusedWindow()) {
+    if (openbox.focusedWindow()->getScreen()->getScreenNumber() ==
        getScreenNumber()) {
       have_focused = True;
-      focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
+      focused_window_number = openbox.focusedWindow()->getWindowNumber();
     }
   }
 
@@ -2101,11 +2210,11 @@ void BScreen::prevFocus(void) {
   int focused_window_number = -1;
   OpenboxWindow *prev;
 
-  if (openbox.getFocusedWindow()) {
-    if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
+  if (openbox.focusedWindow()) {
+    if (openbox.focusedWindow()->getScreen()->getScreenNumber() ==
        getScreenNumber()) {
       have_focused = True;
-      focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
+      focused_window_number = openbox.focusedWindow()->getWindowNumber();
     }
   }
 
@@ -2134,83 +2243,94 @@ void BScreen::raiseFocus(void) {
   Bool have_focused = False;
   int focused_window_number = -1;
 
-  if (openbox.getFocusedWindow()) {
-    if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
+  if (openbox.focusedWindow()) {
+    if (openbox.focusedWindow()->getScreen()->getScreenNumber() ==
        getScreenNumber()) {
       have_focused = True;
-      focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
+      focused_window_number = openbox.focusedWindow()->getWindowNumber();
     }
   }
 
   if ((getCurrentWorkspace()->getCount() > 1) && have_focused)
-    getWorkspace(openbox.getFocusedWindow()->getWorkspaceNumber())->
-      raiseWindow(openbox.getFocusedWindow());
+    getWorkspace(openbox.focusedWindow()->getWorkspaceNumber())->
+      raiseWindow(openbox.focusedWindow());
 }
 
 
 void BScreen::InitMenu(void) {
   if (rootmenu) {
-    while (rootmenuList->count())
-      rootmenuList->remove(0);
-
+    rootmenuList.clear();
     while (rootmenu->getCount())
       rootmenu->remove(0);
   } else {
     rootmenu = new Rootmenu(*this);
   }
-  Bool defaultMenu = True;
+  bool defaultMenu = true;
 
-  if (openbox.getMenuFilename()) {
-    FILE *menu_file = fopen(openbox.getMenuFilename(), "r");
+  FILE *menu_file;
+  const char *menu_filename = openbox.getMenuFilename();
 
-    if (!menu_file) {
-      perror(openbox.getMenuFilename());
+  if (!(menu_file = fopen(menu_filename, "r"))) {
+    perror(menu_filename);
+    menu_filename = (char *) 0;
+  }
+  if (menu_filename == (char *) 0) {
+    // opening the menu file failed, try the DEFAULTMENU
+    menu_filename = DEFAULTMENU;
+    if (!(menu_file = fopen(menu_filename, "r"))) {
+      perror(menu_filename);
+      menu_filename = (char *) 0;
+    }
+  }
+      
+  if (menu_filename) { 
+    if (feof(menu_file)) {
+      fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
+                                      "%s: Empty menu file"), menu_filename);
+      menu_filename = (char *) 0;
     } else {
-      if (feof(menu_file)) {
-       fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
-                                        "%s: Empty menu file"),
-               openbox.getMenuFilename());
-      } else {
-       char line[1024], label[1024];
-       memset(line, 0, 1024);
-       memset(label, 0, 1024);
-
-       while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
-         if (line[0] != '#') {
-           int i, key = 0, index = -1, len = strlen(line);
-
-           key = 0;
-           for (i = 0; i < len; i++) {
-             if (line[i] == '[') index = 0;
-             else if (line[i] == ']') break;
-             else if (line[i] != ' ')
-               if (index++ >= 0)
-                 key += tolower(line[i]);
-           }
+      // successsfully opened a menu file
+      char line[1024], label[1024];
+      memset(line, 0, 1024);
+      memset(label, 0, 1024);
+
+      while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
+        if (line[0] != '#') {
+          int i, key = 0, index = -1, len = strlen(line);
+
+          key = 0;
+          for (i = 0; i < len; i++) {
+            if (line[i] == '[') index = 0;
+            else if (line[i] == ']') break;
+            else if (line[i] != ' ')
+              if (index++ >= 0)
+                key += tolower(line[i]);
+          }
 
-           if (key == 517) {
-             index = -1;
-             for (i = index; i < len; i++) {
-               if (line[i] == '(') index = 0;
-               else if (line[i] == ')') break;
-               else if (index++ >= 0) {
-                 if (line[i] == '\\' && i < len - 1) i++;
-                 label[index - 1] = line[i];
-               }
-             }
+          if (key == 517) {
+            index = -1;
+            for (i = index; i < len; i++) {
+              if (line[i] == '(') index = 0;
+              else if (line[i] == ')') break;
+              else if (index++ >= 0) {
+                if (line[i] == '\\' && i < len - 1) i++;
+                label[index - 1] = line[i];
+              }
+            }
 
-             if (index == -1) index = 0;
-             label[index] = '\0';
+            if (index == -1) index = 0;
+            label[index] = '\0';
 
-             rootmenu->setLabel(label);
-             defaultMenu = parseMenuFile(menu_file, rootmenu);
-             break;
-           }
-         }
-       }
+            rootmenu->setLabel(label);
+            defaultMenu = parseMenuFile(menu_file, rootmenu);
+            if (!defaultMenu)
+              openbox.addMenuTimestamp(menu_filename);
+            break;
+          }
+        }
       }
-      fclose(menu_file);
     }
+    fclose(menu_file);
   }
 
   if (defaultMenu) {
@@ -2222,8 +2342,6 @@ void BScreen::InitMenu(void) {
                     BScreen::Restart);
     rootmenu->insert(i18n->getMessage(ScreenSet, ScreenExit, "Exit"),
                     BScreen::Exit);
-  } else {
-    openbox.setMenuFilename(openbox.getMenuFilename());
   }
 }
 
@@ -2423,10 +2541,9 @@ Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
                 }
 
                if (! feof(submenufile)) {
-                 if (! parseMenuFile(submenufile, menu))
-                   openbox.setMenuFilename(newfile);
-
-                 fclose(submenufile);
+                 if (!parseMenuFile(submenufile, menu))
+                    openbox.addMenuTimestamp(newfile);
+                  fclose(submenufile);
                }
              } else
                perror(newfile);
@@ -2454,7 +2571,7 @@ Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
            parseMenuFile(file, submenu);
            submenu->update();
            menu->insert(label, submenu);
-           rootmenuList->insert(submenu);
+           rootmenuList.push_back(submenu);
          }
 
          break;
@@ -2554,7 +2671,7 @@ Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
 
                closedir(d);
 
-               std::sort(ls, ls + entries, dcmp());
+                std::sort(ls, ls + entries, dcmp());
 
                 int n, slen = strlen(stylesdir);
                 for (n = 0; n < entries; n++) {
@@ -2580,10 +2697,9 @@ Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
                 if (newmenu) {
                   stylesmenu->setLabel(label);
                   menu->insert(label, stylesmenu);
-                  rootmenuList->insert(stylesmenu);
+                  rootmenuList.push_back(stylesmenu);
                 }
-
-                openbox.setMenuFilename(stylesdir);
+                openbox.addMenuTimestamp(stylesdir);
               } else {
                 fprintf(stderr, i18n->getMessage(ScreenSet,
                                                 ScreenSTYLESDIRErrorNotDir,
@@ -2630,14 +2746,11 @@ void BScreen::shutdown(void) {
   XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask);
   XSync(getBaseDisplay().getXDisplay(), False);
 
-  LinkedListIterator<Workspace> it(workspacesList);
-  for (Workspace *w = it.current(); w; it++, w = it.current())
-    w->shutdown();
+  std::for_each(workspacesList.begin(), workspacesList.end(),
+                std::mem_fun(&Workspace::shutdown));
 
-  while (iconList->count()) {
-    iconList->first()->restore();
-    delete iconList->first();
-  }
+  while (!iconList.empty())
+    iconList.front()->restore();
 
 #ifdef    SLIT
   slit->shutdown();
This page took 0.051977 seconds and 4 git commands to generate.