]> Dogcows Code - chaz/openbox/blobdiff - src/Screen.cc
add capability to stick a window from input, and make close buttons work.
[chaz/openbox] / src / Screen.cc
index 1bea9bae9999b4ebd3edd6c3b32723dcc850c89b..88cba6733fbc24e2df1fabfc56c6e2294dbf7ff7 100644 (file)
@@ -88,6 +88,7 @@ using std::string;
 #include "Workspace.hh"
 #include "Workspacemenu.hh"
 #include "XAtom.hh"
+#include "Input.hh"
 
 #ifndef   FONT_ELEMENT_SIZE
 #define   FONT_ELEMENT_SIZE 50
@@ -241,7 +242,6 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
   }
   saveWorkspaceNames();
 
-  updateDesktopNames();
   updateNetizenWorkspaceCount();
 
   workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
@@ -254,8 +254,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);
@@ -316,6 +314,7 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
 
   // call this again just in case a window we found updates the Strut list
   updateAvailableArea();
+  updateFocusModel();
 }
 
 
@@ -365,10 +364,6 @@ BScreen::~BScreen(void) {
 }
 
 
-void BScreen::removeWorkspaceNames(void) {
-  workspaceNames.clear();
-}
-  
 void BScreen::saveSloppyFocus(bool s) {
   resource.sloppy_focus = s;
 
@@ -515,14 +510,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 +604,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 +1027,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 +1034,6 @@ unsigned int BScreen::addWorkspace(void) {
 
   toolbar->reconfigure();
 
-  updateDesktopNames();
   updateNetizenWorkspaceCount();
 
   return workspacesList.size();
@@ -1059,8 +1058,6 @@ unsigned int BScreen::removeLastWorkspace(void) {
   delete wkspc;
 
   saveWorkspaces(getWorkspaceCount());
-  saveWorkspaceNames();
-  updateDesktopNames();
 
   toolbar->reconfigure();
 
@@ -1222,8 +1219,8 @@ void BScreen::manageWindow(Window w) {
     // desktop windows cant do anything, so we remove all the normal window
     // stuff from them, they are only kept around so that we can keep them on
     // the bottom of the z-order
-    addDesktopWindow(win->getClientWindow());
     win->restore(True);
+    addDesktopWindow(win->getClientWindow());
     delete win;
     return;
   }
@@ -1431,6 +1428,8 @@ void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
 
 
 void BScreen::lowerDesktops(void) {
+  if (desktopWindowList.empty()) return;
+
   XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
   if (desktopWindowList.size() > 1)
     XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
@@ -1438,40 +1437,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;
@@ -2207,9 +2172,10 @@ void BScreen::toggleFocusModel(FocusModel model) {
   if (model == SloppyFocus) {
     saveSloppyFocus(True);
   } else {
+    // we're cheating here to save writing the config file 3 times
+    resource.auto_raise = False;
+    resource.click_raise = False;
     saveSloppyFocus(False);
-    saveAutoRaise(False);
-    saveClickRaise(False);
   }
 
   updateFocusModel();
@@ -2218,8 +2184,31 @@ void BScreen::toggleFocusModel(FocusModel model) {
 
 void BScreen::updateFocusModel()
 {
-  std::for_each(workspacesList.begin(), workspacesList.end(),
-                std::mem_fun(&Workspace::updateFocusModel));
+  std::for_each(iconList.begin(), iconList.end(),
+                std::mem_fun(&BlackboxWindow::ungrabButtons));
+  std::for_each(windowList.begin(), windowList.end(),
+                std::mem_fun(&BlackboxWindow::ungrabButtons));
+  
+  if (! resource.sloppy_focus) {
+    blackbox->getInput()->add(Button1, 0, BInput::WindowClientPress,
+                              BInput::Raise);
+    blackbox->getInput()->add(Button1, 0, BInput::WindowClientPress,
+                              BInput::Focus);
+  } else {
+    if (resource.click_raise)
+      blackbox->getInput()->add(Button1, 0, BInput::WindowClientPress,
+                                BInput::Raise);
+    else
+      blackbox->getInput()->remove(Button1, 0, BInput::WindowClientPress,
+                                   BInput::Raise);
+    blackbox->getInput()->remove(Button1, 0, BInput::WindowClientPress,
+                                 BInput::Focus);
+  }
+  
+  std::for_each(iconList.begin(), iconList.end(),
+                std::mem_fun(&BlackboxWindow::grabButtons));
+  std::for_each(windowList.begin(), windowList.end(),
+                std::mem_fun(&BlackboxWindow::grabButtons));
 }
 
 
This page took 0.025213 seconds and 4 git commands to generate.