]> Dogcows Code - chaz/openbox/commitdiff
properly handle workspace names, and changes to them.
authorDana Jansens <danakj@orodu.net>
Sun, 14 Jul 2002 20:54:03 +0000 (20:54 +0000)
committerDana Jansens <danakj@orodu.net>
Sun, 14 Jul 2002 20:54:03 +0000 (20:54 +0000)
src/Basemenu.cc
src/Screen.cc
src/Screen.hh
src/Toolbar.cc
src/Workspace.cc
src/Workspace.hh
src/Workspacemenu.cc
src/Workspacemenu.hh
src/blackbox.cc

index 8feb737218ee4daf61b46e37fa72a8cc425f2d72..775d49a882983f87e8b737c0cc7a22d0219a6c3a 100644 (file)
@@ -202,7 +202,7 @@ int Basemenu::insert(BasemenuItem *item, int pos) {
   if (pos < 0) {
     menuitems.push_back(item);
   } else {
-    assert(pos < static_cast<signed>(menuitems.size()));
+    assert(pos <= static_cast<signed>(menuitems.size()));
     menuitems.insert((menuitems.begin() + pos), item);
   }
   return menuitems.size();
index 0186e97bf26384db990cec7a7d2ed49500674dce..c2f52cb933b68f878d75184106c79ff6294f68f7 100644 (file)
@@ -205,17 +205,19 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
   iconmenu = new Iconmenu(this);
   configmenu = new Configmenu(this);
 
-  Workspace *wkspc = (Workspace *) 0;
   if (resource.workspaces != 0) {
     for (unsigned int i = 0; i < resource.workspaces; ++i) {
-      wkspc = new Workspace(this, workspacesList.size());
+      Workspace *wkspc = new Workspace(this, workspacesList.size());
       workspacesList.push_back(wkspc);
-      workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
+      workspacemenu->insertWorkspace(wkspc);
+      workspacemenu->update();
+
     }
   } else {
-    wkspc = new Workspace(this, workspacesList.size());
+    Workspace *wkspc = new Workspace(this, workspacesList.size());
     workspacesList.push_back(wkspc);
-    workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
+    workspacemenu->insertWorkspace(wkspc);
+    workspacemenu->update();
   }
   saveWorkspaceNames();
 
@@ -496,18 +498,14 @@ void BScreen::saveClock24Hour(Bool c) {
 
 
 void BScreen::saveWorkspaceNames() {
-  XAtom::StringVect nameList;
-  unsigned long numnames = (unsigned) -1;
   string 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];
-    }
+  for (unsigned int i = 0; i < workspacesList.size(); ++i) {
+    names += workspacesList[i]->getName();
+    if (i < workspacesList.size() - 1)
+      names += ',';
   }
+
   config->setValue(screenstr + "workspaceNames", names);
 }
 
@@ -980,9 +978,9 @@ 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);
+  workspacemenu->insertWorkspace(wkspc);
   workspacemenu->update();
 
   toolbar->reconfigure();
@@ -1004,13 +1002,14 @@ unsigned int BScreen::removeLastWorkspace(void) {
 
   wkspc->removeAll();
 
-  workspacemenu->remove(wkspc->getID() + 2);
+  workspacemenu->removeWorkspace(wkspc);
   workspacemenu->update();
 
   workspacesList.pop_back();
   delete wkspc;
 
   saveWorkspaces(getWorkspaceCount());
+  saveWorkspaceNames();
 
   toolbar->reconfigure();
 
@@ -2118,6 +2117,23 @@ void BScreen::buttonPressEvent(const XButtonEvent *xbutton) {
 }
 
 
+void BScreen::propertyNotifyEvent(const XPropertyEvent *pe) {
+  if (pe->atom == xatom->getAtom(XAtom::net_desktop_names)) {
+    // _NET_WM_DESKTOP_NAMES
+    fprintf(stderr, "UPDATING WORKSPACE NAMES\n");
+    WorkspaceList::iterator it = workspacesList.begin();
+    const WorkspaceList::iterator end = workspacesList.end();
+    for (; it != end; ++it) {
+      (*it)->readName(); // re-read its name from the window property
+      workspacemenu->changeWorkspaceLabel((*it)->getID(), (*it)->getName());
+    }
+    workspacemenu->update();
+    toolbar->reconfigure();
+    saveWorkspaceNames();
+  }
+}
+
+
 void BScreen::toggleFocusModel(FocusModel model) {
   std::for_each(windowList.begin(), windowList.end(),
                 std::mem_fun(&BlackboxWindow::ungrabButtons));
index d2175ce410442d9effa8b698c3c41204fd172b88..37946b99aea49f5db7a8c01572b471d488ba58b5 100644 (file)
@@ -344,6 +344,7 @@ public:
   void hideGeometry(void);
 
   void buttonPressEvent(const XButtonEvent *xbutton);
+  void propertyNotifyEvent(const XPropertyEvent *pe);
 
   void updateNetizenCurrentWorkspace(void);
   void updateNetizenWorkspaceCount(void);
index a2c3442b65562d72438b79bae39808989f396d5d..a1a6e118269ad96182dd8b5885c913bffdcfab53 100644 (file)
@@ -916,13 +916,9 @@ void Toolbar::keyPressEvent(const XKeyEvent *ke) {
         blackbox->setFocusedWindow(0);
       }
 
-      Workspace *wkspc = screen->getCurrentWorkspace();
-      wkspc->setName(new_workspace_name);
-      wkspc->getMenu()->hide();
-
-      screen->getWorkspacemenu()->changeItemLabel(wkspc->getID() + 2,
-                                                  wkspc->getName());
-      screen->getWorkspacemenu()->update();
+      // the toolbar will be reconfigured when the change to the workspace name
+      // gets caught in the PropertyNotify event handler
+      screen->getCurrentWorkspace()->setName(new_workspace_name);
 
       new_workspace_name.erase();
       new_name_pos = 0;
@@ -938,7 +934,6 @@ void Toolbar::keyPressEvent(const XKeyEvent *ke) {
       else
         XSetWindowBackgroundPixmap(display, frame.workspace_label,
                                    frame.wlabel);
-      reconfigure();
     } else if (! (ks == XK_Shift_L || ks == XK_Shift_R ||
                   ks == XK_Control_L || ks == XK_Control_R ||
                   ks == XK_Caps_Lock || ks == XK_Shift_Lock ||
index 65f323f15ce5ee5d5c1ed7e7e836922360e54a62..88280a1d32eaeb9260069d4e816d742c879c4129 100644 (file)
@@ -70,8 +70,7 @@ Workspace::Workspace(BScreen *scrn, unsigned int i) {
 
   lastfocus = (BlackboxWindow *) 0;
 
-  setName("");
-  fprintf(stderr, "WORKSPACE NAME: %s\n", name.c_str());
+  readName();
 }
 
 
@@ -420,43 +419,48 @@ void Workspace::setCurrent(void) {
 }
 
 
-void Workspace::setName(const string& new_name) {
-  if (! new_name.empty()) {
-    name = new_name;
+void Workspace::readName(void) {
+  XAtom::StringVect namesList;
+  unsigned long numnames = id + 1;
+    
+  // attempt to get from the _NET_WM_DESKTOP_NAMES property
+  if (xatom->getValue(screen->getRootWindow(), XAtom::net_desktop_names,
+                      XAtom::utf8, numnames, namesList) &&
+      namesList.size() > id) {
+    name = namesList[id];
+  
+    clientmenu->setLabel(name);
+    clientmenu->update();
   } else {
-    // 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;
-    }
+    /*
+       Use a default name. This doesn't actually change the class. That will
+       happen after the setName changes the root property, and that change
+       makes its way back to this function.
+    */
+    string tmp =i18n(WorkspaceSet, WorkspaceDefaultNameFormat,
+                     "Workspace %d");
+    assert(tmp.length() < 32);
+    char default_name[32];
+    sprintf(default_name, tmp.c_str(), id + 1);
+    
+    setName(default_name);  // save this into the _NET_WM_DESKTOP_NAMES property
   }
-  
-  // reset the property with the new name
+}
+
+
+void Workspace::setName(const string& new_name) {
+  // set the _NET_WM_DESKTOP_NAMES 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) &&
       namesList.size() > id)
-    namesList[id] = name;
+    namesList[id] = new_name;
   else
-    namesList.push_back(name);
+    namesList.push_back(new_name);
 
   xatom->setValue(screen->getRootWindow(), XAtom::net_desktop_names,
                   XAtom::utf8, namesList);
-
-  clientmenu->setLabel(name);
-  clientmenu->update();
-  screen->saveWorkspaceNames();
 }
 
 
index 0916dce7340825085860d24936cb6fda727db762..fcf466307a4b336070cd65fc57c1de4e27e41962 100644 (file)
@@ -104,6 +104,7 @@ public:
   void lowerWindow(BlackboxWindow *w);
   void reconfigure(void);
   void setCurrent(void);
+  void readName();
   void setName(const std::string& new_name);
 };
 
index a63251ab00c879a55e8e9423b2c81ac2a85613be..2ba73e23ae4618cbb11474ac72065fdea21057d1 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "i18n.hh"
 #include "blackbox.hh"
+#include "Clientmenu.hh"
 #include "Screen.hh"
 #include "Toolbar.hh"
 #include "Workspacemenu.hh"
@@ -51,6 +52,8 @@ void Workspacemenu::itemSelected(int button, unsigned int index) {
   } else if (index == 1) {
     getScreen()->removeLastWorkspace();
   } else {
+    // subtract 2 because the workspace menu has 2 extra items at the top before
+    // the list of the workspace names
     index -= 2;
     const Workspace* const wkspc = getScreen()->getCurrentWorkspace();
     if (wkspc->getID() != index && index < getScreen()->getWorkspaceCount())
@@ -59,3 +62,27 @@ void Workspacemenu::itemSelected(int button, unsigned int index) {
   if (! (getScreen()->getWorkspacemenu()->isTorn() || isTorn()))
     hide();
 }
+  
+
+void Workspacemenu::changeWorkspaceLabel(unsigned int index,
+                                         const std::string& label) {
+  // add 2 because the workspace menu has 2 extra items at the top before the
+  // list of the workspace names
+  changeItemLabel(index + 2, label);
+}
+  
+
+void Workspacemenu::insertWorkspace(Workspace *wkspc) {
+  assert(wkspc);
+  // add 2 because the workspace menu has 2 extra items at the top before the
+  // list of the workspace names
+  insert(wkspc->getName(), wkspc->getMenu(), wkspc->getID() + 2);
+}
+
+
+void Workspacemenu::removeWorkspace(Workspace *wkspc) {
+  assert(wkspc);
+  // add 2 because the workspace menu has 2 extra items at the top before the
+  // list of the workspace names
+  remove(wkspc->getID() + 2);
+}
index 28052a9fe899c2a80226524f05bf26094a9efc4e..15269844ddda7edc09fd2236b5c817ea855d28ad 100644 (file)
@@ -29,6 +29,7 @@
 // forward declaration
 class Workspacemenu;
 class Toolbar;
+class Workspace;
 
 class Workspacemenu : public Basemenu {
 private:
@@ -40,6 +41,10 @@ protected:
 
 public:
   Workspacemenu(BScreen *scrn);
+
+  void changeWorkspaceLabel(unsigned int index, const std::string& label);
+  void insertWorkspace(Workspace *wkspc);
+  void removeWorkspace(Workspace *wkspc);
 };
 
 
index ae3b5ead51865af7bff0b618ce94c300f3120f9b..3ec32d5208d5d1da86f47774c9ac2b54b1916d83 100644 (file)
@@ -462,9 +462,13 @@ void Blackbox::process_event(XEvent *e) {
   case PropertyNotify: {
     last_time = e->xproperty.time;
 
-    BlackboxWindow *win = searchWindow(e->xproperty.window);
-    if (win)
+    BlackboxWindow *win = (BlackboxWindow *) 0;
+    BScreen *screen = (BScreen *) 0;
+
+    if ((win = searchWindow(e->xproperty.window)))
       win->propertyNotifyEvent(&e->xproperty);
+    else if ((screen = searchScreen(e->xproperty.window)))
+      screen->propertyNotifyEvent(&e->xproperty);
     break;
   }
 
This page took 0.03581 seconds and 4 git commands to generate.