]> Dogcows Code - chaz/openbox/blobdiff - src/Screen.cc
make desktop windows get lowered properly
[chaz/openbox] / src / Screen.cc
index 5f69d82af15025eaf2d54d5e8265c501a9c78c82..73dfeaf1bd71d91d4adac0490657c83e7fe5cd85 100644 (file)
@@ -143,6 +143,14 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
   xatom->setValue(getRootWindow(), XAtom::blackbox_pid, XAtom::cardinal,
                   (unsigned long) getpid());
 #endif // HAVE_GETPID
+  unsigned long geometry[] = { getWidth(),
+                               getHeight()};
+  xatom->setValue(getRootWindow(), XAtom::net_desktop_geometry,
+                  XAtom::cardinal, geometry, 2);
+  unsigned long viewport[] = {0,0};
+  xatom->setValue(getRootWindow(), XAtom::net_desktop_viewport,
+                  XAtom::cardinal, viewport, 2);
+                  
 
   XDefineCursor(blackbox->getXDisplay(), getRootWindow(),
                 blackbox->getSessionCursor());
@@ -245,17 +253,16 @@ 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);
 
   InitMenu();
 
-  raiseWindows(0, 0);
+  raiseWindows(0, 0);     // this also initializes the empty stacking list
   rootmenu->update();
 
+  updateClientList();     // initialize the client list, which will be empty
   updateAvailableArea();
 
   changeWorkspaceID(0);
@@ -355,10 +362,6 @@ BScreen::~BScreen(void) {
 }
 
 
-void BScreen::removeWorkspaceNames(void) {
-  workspaceNames.clear();
-}
-  
 void BScreen::saveSloppyFocus(bool s) {
   resource.sloppy_focus = s;
 
@@ -505,13 +508,17 @@ void BScreen::saveClock24Hour(Bool c) {
 
 
 void BScreen::saveWorkspaceNames() {
+  XAtom::StringVect nameList;
+  unsigned long numnames = (unsigned) -1;
   string names;
-  WorkspaceList::iterator it;
-  WorkspaceList::iterator last = workspacesList.end() - 1;
-  for (it = workspacesList.begin(); it != workspacesList.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);
 }
@@ -595,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;
@@ -1015,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);
@@ -1047,7 +1056,6 @@ unsigned int BScreen::removeLastWorkspace(void) {
   delete wkspc;
 
   saveWorkspaces(getWorkspaceCount());
-  saveWorkspaceNames();
 
   toolbar->reconfigure();
 
@@ -1083,7 +1091,6 @@ void BScreen::changeWorkspaceID(unsigned int id) {
 
     xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
                     XAtom::cardinal, id);
-    printf("%d\n", id);
 
     workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
     toolbar->redrawWorkspaceLabel(True);
@@ -1100,14 +1107,124 @@ void BScreen::changeWorkspaceID(unsigned int id) {
 }
 
 
+/*
+ * Set the _NET_CLIENT_LIST root window property.
+ */
+void BScreen::updateClientList(void) {
+  if (windowList.size() > 0) {
+    Window *windows = new Window[windowList.size()];
+    Window *win_it = windows;
+    BlackboxWindowList::iterator it = windowList.begin();
+    const BlackboxWindowList::iterator end = windowList.end();
+    for (; it != end; ++it, ++win_it)
+      *win_it = (*it)->getClientWindow();
+    xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
+                    windows, windowList.size());
+    delete [] windows;
+  } else
+    xatom->setValue(getRootWindow(), XAtom::net_client_list, XAtom::window,
+                    0, 0);
+}
+
+
+/*
+ * Set the _NET_CLIENT_LIST_STACKING root window property.
+ */
+void BScreen::updateStackingList(void) {
+
+  BlackboxWindowList stack_order;
+
+  /*
+   * Get the atacking order from all of the workspaces.
+   * We start with the current workspace so that the sticky windows will be
+   * in the right order on the current workspace.
+   * XXX: Do we need to have sticky windows in the list once for each workspace?
+   */
+  getCurrentWorkspace()->appendStackOrder(stack_order);
+  for (unsigned int i = 0; i < getWorkspaceCount(); ++i)
+    if (i != getCurrentWorkspaceID())
+      getWorkspace(i)->appendStackOrder(stack_order);
+  if (stack_order.size() > 0) {
+    // set the client list atoms
+    Window *windows = new Window[stack_order.size()];
+    Window *win_it = windows;
+    BlackboxWindowList::iterator it = stack_order.begin();
+    const BlackboxWindowList::iterator end = stack_order.end();
+    for (; it != end; ++it, ++win_it)
+      *win_it = (*it)->getClientWindow();
+    xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
+                    XAtom::window, windows, stack_order.size());
+    delete [] windows;
+  } else
+    xatom->setValue(getRootWindow(), XAtom::net_client_list_stacking,
+                    XAtom::window, 0, 0);
+}
+
+
+void BScreen::addSystrayWindow(Window window) {
+  systrayWindowList.push_back(window);
+  xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
+                  XAtom::window,
+                  &systrayWindowList[0], systrayWindowList.size());
+  blackbox->saveSystrayWindowSearch(window, this);
+}
+
+
+void BScreen::removeSystrayWindow(Window window) {
+  WindowList::iterator it = systrayWindowList.begin();
+  const WindowList::iterator end = systrayWindowList.end();
+  for (; it != end; ++it)
+    if (*it == window) {
+      systrayWindowList.erase(it);
+      xatom->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows,
+                      XAtom::window,
+                      &systrayWindowList[0], systrayWindowList.size());
+      blackbox->removeSystrayWindowSearch(window);
+      break;
+    }
+}
+
+
+void BScreen::addDesktopWindow(Window window) {
+  desktopWindowList.push_back(window);
+  XLowerWindow(blackbox->getXDisplay(), window);
+  XSelectInput(blackbox->getXDisplay(), window, StructureNotifyMask);
+  blackbox->saveDesktopWindowSearch(window, this);
+}
+
+
+void BScreen::removeDesktopWindow(Window window) {
+  WindowList::iterator it = desktopWindowList.begin();
+  const WindowList::iterator end = desktopWindowList.end();
+  for (; it != end; ++it)
+    if (*it == window) {
+      desktopWindowList.erase(it);
+      XSelectInput(blackbox->getXDisplay(), window, None);
+      blackbox->removeDesktopWindowSearch(window);
+      break;
+    }
+}
+
+
 void BScreen::manageWindow(Window w) {
   new BlackboxWindow(blackbox, w, this);
 
   BlackboxWindow *win = blackbox->searchWindow(w);
   if (! win)
     return;
+  if (win->isDesktop()) {
+    // 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
+    win->restore(True);
+    addDesktopWindow(win->getClientWindow());
+    delete win;
+    return;
+  }
 
   windowList.push_back(win);
+  updateClientList();
 
   XMapRequestEvent mre;
   mre.window = w;
@@ -1126,6 +1243,7 @@ void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
     removeIcon(w);
 
   windowList.remove(w);
+  updateClientList();
 
   if (blackbox->getFocusedWindow() == w)
     blackbox->setFocusedWindow((BlackboxWindow *) 0);
@@ -1172,6 +1290,25 @@ void BScreen::removeNetizen(Window w) {
 }
 
 
+void BScreen::updateWorkArea(void) {
+  if (workspacesList.size() > 0) {
+    unsigned long *dims = new unsigned long[4 * workspacesList.size()];
+    for (unsigned int i = 0, m = workspacesList.size(); i < m; ++i) {
+      // XXX: this could be different for each workspace
+      const Rect &area = availableArea();
+      dims[(i * 4) + 0] = area.x();
+      dims[(i * 4) + 1] = area.y();
+      dims[(i * 4) + 2] = area.width();
+      dims[(i * 4) + 3] = area.height();
+    }
+    xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
+                    dims, 4 * workspacesList.size());
+  } else
+    xatom->setValue(getRootWindow(), XAtom::net_workarea, XAtom::cardinal,
+                    0, 0);
+}
+
+
 void BScreen::updateNetizenCurrentWorkspace(void) {
   std::for_each(netizenList.begin(), netizenList.end(),
                 std::mem_fun(&Netizen::sendCurrentWorkspace));
@@ -1182,6 +1319,8 @@ void BScreen::updateNetizenWorkspaceCount(void) {
   xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
                   XAtom::cardinal, workspacesList.size());
 
+  updateWorkArea();
+  
   std::for_each(netizenList.begin(), netizenList.end(),
                 std::mem_fun(&Netizen::sendWorkspaceCount));
 }
@@ -1190,6 +1329,10 @@ void BScreen::updateNetizenWorkspaceCount(void) {
 void BScreen::updateNetizenWindowFocus(void) {
   Window f = ((blackbox->getFocusedWindow()) ?
               blackbox->getFocusedWindow()->getClientWindow() : None);
+
+  xatom->setValue(getRootWindow(), XAtom::net_active_window,
+                  XAtom::window, f);
+
   NetizenList::iterator it = netizenList.begin();
   for (; it != netizenList.end(); ++it)
     (*it)->sendWindowFocus(f);
@@ -1277,26 +1420,18 @@ void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
   XRestackWindows(blackbox->getXDisplay(), session_stack, i);
 
   delete [] session_stack;
-}
 
-
-void BScreen::addWorkspaceName(const string& name) {
-  workspaceNames.push_back(name);
+  updateStackingList();
 }
 
 
-/*
- * 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::lowerDesktops(void) {
+  if (desktopWindowList.empty()) return;
+
+  XLowerWindow(blackbox->getXDisplay(), desktopWindowList[0]);
+  if (desktopWindowList.size() > 1)
+    XRestackWindows(blackbox->getXDisplay(), &desktopWindowList[0],
+                    desktopWindowList.size());
 }
 
 
@@ -1956,6 +2091,8 @@ void BScreen::updateAvailableArea(void) {
     for (; it != end; ++it)
       if ((*it)->isMaximized()) (*it)->remaximize();
   }
+
+  updateWorkArea();  
 }
 
 
This page took 0.028192 seconds and 4 git commands to generate.