]> Dogcows Code - chaz/openbox/commitdiff
use the _NET_WM_DESKTOP_NAMES root property
authorDana Jansens <danakj@orodu.net>
Fri, 28 Jun 2002 01:44:47 +0000 (01:44 +0000)
committerDana Jansens <danakj@orodu.net>
Fri, 28 Jun 2002 01:44:47 +0000 (01:44 +0000)
src/Screen.cc
src/Screen.hh
src/Toolbar.cc
src/Workspace.cc
src/Workspace.hh

index 567516e7dc6fb91eae9c82f46dcc3e6e2c215ef5..4716d23a3532e56991d34a30a0f063b7d1ac0846 100644 (file)
@@ -241,7 +241,6 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
   }
   saveWorkspaceNames();
 
-  updateDesktopNames();
   updateNetizenWorkspaceCount();
 
   workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
@@ -254,8 +253,6 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
 
   workspacemenu->setItemSelected(2, True);
 
-  removeWorkspaceNames(); // do not need them any longer
-
   toolbar = new Toolbar(this);
 
   slit = new Slit(this);
@@ -365,10 +362,6 @@ BScreen::~BScreen(void) {
 }
 
 
-void BScreen::removeWorkspaceNames(void) {
-  workspaceNames.clear();
-}
-  
 void BScreen::saveSloppyFocus(bool s) {
   resource.sloppy_focus = s;
 
@@ -515,14 +508,17 @@ void BScreen::saveClock24Hour(Bool c) {
 
 
 void BScreen::saveWorkspaceNames() {
+  XAtom::StringVect nameList;
+  unsigned long numnames = (unsigned) -1;
   string names;
-  WorkspaceList::iterator it = workspacesList.begin();
-  const WorkspaceList::iterator last = workspacesList.end() - 1;
-  const WorkspaceList::iterator end = workspacesList.end();
-  for (; it != end; ++it) {
-    names += (*it)->getName();
-    if (it != last)
-      names += ',';
+  if (numnames > 0 &&
+      xatom->getValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
+                      numnames, nameList)) {
+    for (unsigned int i = 0; i < nameList.size(); ++i) {
+      if (i > 0) names += ",";
+      names += nameList[i];
+    }
   }
   config->setValue(screenstr + "workspaceNames", names);
 }
@@ -606,17 +602,20 @@ void BScreen::load_rc(void) {
   else
     resource.col_direction = TopBottom;
 
+  XAtom::StringVect workspaceNames;
   if (config->getValue(screenstr + "workspaceNames", s)) {
     string::const_iterator it = s.begin(), end = s.end();
     while(1) {
       string::const_iterator tmp = it;     // current string.begin()
       it = std::find(tmp, end, ',');       // look for comma between tmp and end
-      addWorkspaceName(string(tmp, it));   // s[tmp:it]
+      workspaceNames.push_back(string(tmp, it)); // s[tmp:it]
       if (it == end)
         break;
       ++it;
     }
   }
+  xatom->setValue(getRootWindow(), XAtom::net_desktop_names, XAtom::utf8,
+                  workspaceNames);
 
   resource.sloppy_focus = true;
   resource.auto_raise = false;
@@ -1026,7 +1025,6 @@ unsigned int BScreen::addWorkspace(void) {
   Workspace *wkspc = new Workspace(this, workspacesList.size());
   workspacesList.push_back(wkspc);
   saveWorkspaces(getWorkspaceCount());
-  saveWorkspaceNames();
 
   workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
                         wkspc->getID() + 2);
@@ -1034,7 +1032,6 @@ unsigned int BScreen::addWorkspace(void) {
 
   toolbar->reconfigure();
 
-  updateDesktopNames();
   updateNetizenWorkspaceCount();
 
   return workspacesList.size();
@@ -1059,8 +1056,6 @@ unsigned int BScreen::removeLastWorkspace(void) {
   delete wkspc;
 
   saveWorkspaces(getWorkspaceCount());
-  saveWorkspaceNames();
-  updateDesktopNames();
 
   toolbar->reconfigure();
 
@@ -1440,40 +1435,6 @@ void BScreen::lowerDesktops(void) {
 }
 
 
-void BScreen::addWorkspaceName(const string& name) {
-  workspaceNames.push_back(name);
-  updateDesktopNames();
-}
-
-
-void BScreen::updateDesktopNames(){
-  XAtom::StringVect names;
-
-  WorkspaceList::iterator it = workspacesList.begin();
-  const WorkspaceList::iterator end = workspacesList.end();
-  for (; it != end; ++it)
-    names.push_back((*it)->getName());
-
-  xatom->setValue(getRootWindow(), XAtom::net_desktop_names,
-                  XAtom::utf8, names);
-}
-
-
-/*
- * I would love to kill this function and the accompanying workspaceNames
- * list.  However, we have a chicken and egg situation.  The names are read
- * in during load_rc() which happens before the workspaces are created.
- * The current solution is to read the names into a list, then use the list
- * later for constructing the workspaces.  It is only used during initial
- * BScreen creation.
- */
-const string BScreen::getNameOfWorkspace(unsigned int id) {
-  if (id < workspaceNames.size())
-    return workspaceNames[id];
-  return string("");
-}
-
-
 void BScreen::reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
                                 bool ignore_sticky) {
   if (! w) return;
index e8c8cd7a743e9ebf0055e56239ada058b9cd5265..72e7dc0aca91f229a689297a0587e843279b5d11 100644 (file)
@@ -144,8 +144,6 @@ private:
 
   typedef std::list<Strut*> StrutList;
   StrutList strutList;
-  typedef std::vector<std::string> WorkspaceNamesList;
-  WorkspaceNamesList workspaceNames;
   typedef std::vector<Workspace*> WorkspaceList;
   WorkspaceList workspacesList;
 
@@ -308,12 +306,8 @@ public:
 
   unsigned int addWorkspace(void);
   unsigned int removeLastWorkspace(void);
-  void removeWorkspaceNames(void);
-  void addWorkspaceName(const std::string& name);
-  const std::string getNameOfWorkspace(unsigned int id);
   void changeWorkspaceID(unsigned int id);
   void saveWorkspaceNames(void);
-  void updateDesktopNames(void);
 
   void addNetizen(Netizen *n);
   void removeNetizen(Window w);
index 9c7c2fafbbce319de7ee4099302446c87145f688..55beb59de8898204a18aea5194ea5e90a227ff5d 100644 (file)
@@ -979,7 +979,6 @@ void Toolbar::keyPressEvent(XKeyEvent *ke) {
 
       Workspace *wkspc = screen->getCurrentWorkspace();
       wkspc->setName(new_workspace_name);
-      screen->updateDesktopNames();
       wkspc->getMenu()->hide();
 
       screen->getWorkspacemenu()->changeItemLabel(wkspc->getID() + 2,
index 50a9f4fbca28145bb46dd882c589d41989fd8543..309ea950f156b9c0e8945c6ff36a3ff750c6881e 100644 (file)
@@ -55,10 +55,12 @@ using std::string;
 #include "Window.hh"
 #include "Workspace.hh"
 #include "Windowmenu.hh"
+#include "XAtom.hh"
 
 
 Workspace::Workspace(BScreen *scrn, unsigned int i) {
   screen = scrn;
+  xatom = screen->getBlackbox()->getXAtom();
 
   cascade_x = cascade_y = 32;
 
@@ -68,7 +70,7 @@ Workspace::Workspace(BScreen *scrn, unsigned int i) {
 
   lastfocus = (BlackboxWindow *) 0;
 
-  setName(screen->getNameOfWorkspace(id));
+  setName("");
 }
 
 
@@ -395,6 +397,7 @@ bool Workspace::isLastWindow(const BlackboxWindow* const w) const {
   return (w == windowList.back());
 }
 
+
 void Workspace::setCurrent(void) {
   screen->changeWorkspaceID(id);
 }
@@ -404,12 +407,35 @@ void Workspace::setName(const string& new_name) {
   if (! new_name.empty()) {
     name = new_name;
   } else {
-    string tmp =i18n(WorkspaceSet, WorkspaceDefaultNameFormat, "Workspace %d");
-    assert(tmp.length() < 32);
-    char default_name[32];
-    sprintf(default_name, tmp.c_str(), id + 1);
-    name = default_name;
+    // attempt to get from the _NET_WM_DESKTOP_NAMES property
+    XAtom::StringVect namesList;
+    unsigned long numnames = id + 1;
+    if (xatom->getValue(screen->getRootWindow(), XAtom::net_desktop_names,
+                        XAtom::utf8, numnames, namesList) &&
+        namesList.size() > id) {
+      name = namesList[id];
+    } else {
+      string tmp =i18n(WorkspaceSet, WorkspaceDefaultNameFormat,
+                       "Workspace %d");
+      assert(tmp.length() < 32);
+      char default_name[32];
+      sprintf(default_name, tmp.c_str(), id + 1);
+      name = default_name;
+    }
+  }
+  
+  // reset the property with the new name
+  XAtom::StringVect namesList;
+  unsigned long numnames = (unsigned) -1;
+  if (xatom->getValue(screen->getRootWindow(), XAtom::net_desktop_names,
+                      XAtom::utf8, numnames, namesList)) {
+    if (namesList.size() > id)
+      namesList[id] = name;
+    else
+      namesList.push_back(name);
   }
+  xatom->setValue(screen->getRootWindow(), XAtom::net_desktop_names,
+                  XAtom::utf8, namesList);
 
   clientmenu->setLabel(name);
   clientmenu->update();
index 33f17b3dec9b65a6ee9e040d2d6517d37fb2e6fc..31ddace817c49dbe2dd991172b1cfe72ae1fa41d 100644 (file)
@@ -46,6 +46,7 @@ private:
   BScreen *screen;
   BlackboxWindow *lastfocus;
   Clientmenu *clientmenu;
+  XAtom *xatom;
 
   BlackboxWindowList stackingList, windowList;
 
This page took 0.034755 seconds and 4 git commands to generate.