]> Dogcows Code - chaz/openbox/blobdiff - src/Screen.cc
removing old Makefile.in, rolling back Makefile.am to before the mappable muse button...
[chaz/openbox] / src / Screen.cc
index e744ab4cb821f38aee12dc6a364338a2817f7ec8..775254c66d3147c67a23e9ab9b36d5539d52d499 100644 (file)
@@ -21,9 +21,7 @@
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 // DEALINGS IN THE SOFTWARE.
 
-#ifdef    HAVE_CONFIG_H
-#  include "../config.h"
-#endif // HAVE_CONFIG_H
+#include "../config.h"
 
 extern "C" {
 #include <X11/Xatom.h>
@@ -68,8 +66,11 @@ extern "C" {
 #endif // HAVE_STDARG_H
 }
 
+#include <assert.h>
+
 #include <algorithm>
 #include <functional>
+#include <string>
 using std::string;
 
 #include "i18n.hh"
@@ -86,6 +87,7 @@ using std::string;
 #include "Window.hh"
 #include "Workspace.hh"
 #include "Workspacemenu.hh"
+#include "XAtom.hh"
 
 #ifndef   FONT_ELEMENT_SIZE
 #define   FONT_ELEMENT_SIZE 50
@@ -110,6 +112,7 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
   blackbox = bb;
   screenstr = (string)"session.screen" + itostring(scrn) + '.';
   config = blackbox->getConfig();
+  xatom = blackbox->getXAtom();
 
   event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
     SubstructureRedirectMask | ButtonPressMask | ButtonReleaseMask;
@@ -135,14 +138,19 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
   resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
     resource.wstyle.font = (XFontStruct *) 0;
 
+  xatom->setSupported(this);    // set-up netwm support
 #ifdef    HAVE_GETPID
-  pid_t bpid = getpid();
-
-  XChangeProperty(blackbox->getXDisplay(), getRootWindow(),
-                  blackbox->getBlackboxPidAtom(), XA_CARDINAL,
-                  sizeof(pid_t) * 8, PropModeReplace,
-                  (unsigned char *) &bpid, 1);
+  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());
@@ -233,10 +241,16 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
   }
   saveWorkspaceNames();
 
+  updateNetizenWorkspaceCount();
+
   workspacemenu->insert(i18n(IconSet, IconIcons, "Icons"), iconmenu);
   workspacemenu->update();
 
   current_workspace = workspacesList.front();
+  
+  xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
+                  XAtom::cardinal, 0); //first workspace
+
   workspacemenu->setItemSelected(2, True);
 
   toolbar = new Toolbar(this);
@@ -245,9 +259,10 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(bb, scrn) {
 
   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);
@@ -347,10 +362,6 @@ BScreen::~BScreen(void) {
 }
 
 
-void BScreen::removeWorkspaceNames(void) {
-  workspaceNames.clear();
-}
-  
 void BScreen::saveSloppyFocus(bool s) {
   resource.sloppy_focus = s;
 
@@ -418,6 +429,20 @@ void BScreen::saveHideToolbar(bool h) {
 }
 
 
+void BScreen::saveWindowToWindowSnap(bool s) {
+  resource.window_to_window_snap = s;
+  config->setValue(screenstr + "windowToWindowSnap",
+                   resource.window_to_window_snap);
+}
+
+
+void BScreen::saveWindowCornerSnap(bool s) {
+  resource.window_corner_snap = s;
+  config->setValue(screenstr + "windowCornerSnap",
+                   resource.window_corner_snap);
+}
+
+
 void BScreen::saveWorkspaces(unsigned int w) {
   resource.workspaces = w;
   config->setValue(screenstr + "workspaces", resource.workspaces);
@@ -483,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);
 }
@@ -504,6 +533,8 @@ void BScreen::save_rc(void) {
   saveFocusNew(resource.focus_new);
   saveFocusLast(resource.focus_last);
   saveHideToolbar(resource.hide_toolbar);
+  saveWindowToWindowSnap(resource.window_to_window_snap);
+  saveWindowCornerSnap(resource.window_corner_snap);
   saveWorkspaces(resource.workspaces);
   savePlacementPolicy(resource.placement_policy);
   saveEdgeSnapThreshold(resource.edge_snap_threshold);
@@ -543,6 +574,14 @@ void BScreen::load_rc(void) {
   if (! config->getValue(screenstr + "hideToolbar", resource.hide_toolbar))
     resource.hide_toolbar = false;
 
+  if (! config->getValue(screenstr + "windowToWindowSnap",
+                         resource.window_to_window_snap))
+    resource.window_to_window_snap = true;
+
+  if (! config->getValue(screenstr + "windowCornerSnap",
+                         resource.window_corner_snap))
+    resource.window_corner_snap = true;
+
   if (! config->getValue(screenstr + "imageDither", b))
     b = true;
   image_control->setDither(b);
@@ -563,18 +602,20 @@ void BScreen::load_rc(void) {
   else
     resource.col_direction = TopBottom;
 
-  removeWorkspaceNames();
+  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;
@@ -678,11 +719,31 @@ void BScreen::reconfigure(void) {
   workspacemenu->reconfigure();
   iconmenu->reconfigure();
 
-  int remember_sub = rootmenu->getCurrentSubmenu();
+  typedef std::vector<int> SubList;
+  SubList remember_subs;
+
+  // save the current open menus
+  Basemenu *menu = rootmenu;
+  int submenu;
+  while ((submenu = menu->getCurrentSubmenu()) >= 0) {
+    remember_subs.push_back(submenu);
+    menu = menu->find(submenu)->submenu();
+    assert(menu);
+  }
+  
   InitMenu();
   raiseWindows(0, 0);
   rootmenu->reconfigure();
-  rootmenu->drawSubmenu(remember_sub);
+
+  // reopen the saved menus
+  menu = rootmenu;
+  const SubList::iterator subs_end = remember_subs.end();
+  for (SubList::iterator it = remember_subs.begin(); it != subs_end; ++it) {
+    menu->drawSubmenu(*it);
+    menu = menu->find(*it)->submenu();
+    if (! menu)
+      break;
+  }
 
   configmenu->reconfigure();
 
@@ -963,8 +1024,7 @@ BlackboxWindow *BScreen::getIcon(unsigned int index) {
 unsigned int BScreen::addWorkspace(void) {
   Workspace *wkspc = new Workspace(this, workspacesList.size());
   workspacesList.push_back(wkspc);
-  saveWorkspaces(getWorkspaceCount() + 1);
-  saveWorkspaceNames();
+  saveWorkspaces(getWorkspaceCount());
 
   workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
                         wkspc->getID() + 2);
@@ -995,8 +1055,7 @@ unsigned int BScreen::removeLastWorkspace(void) {
   workspacesList.pop_back();
   delete wkspc;
 
-  saveWorkspaces(getWorkspaceCount() - 1);
-  saveWorkspaceNames();
+  saveWorkspaces(getWorkspaceCount());
 
   toolbar->reconfigure();
 
@@ -1010,19 +1069,29 @@ void BScreen::changeWorkspaceID(unsigned int id) {
   if (! current_workspace) return;
 
   if (id != current_workspace->getID()) {
+    BlackboxWindow *focused = blackbox->getFocusedWindow();
+    if (focused && focused->getScreen() == this && ! focused->isStuck()) {
+      if (focused->getWorkspaceNumber() != current_workspace->getID()) {
+        fprintf(stderr, "%s is on the wrong workspace, aborting\n",
+                focused->getTitle());
+        abort();
+      }
+      current_workspace->setLastFocusedWindow(focused);
+    } else {
+      // if no window had focus, no need to store a last focus
+      current_workspace->setLastFocusedWindow((BlackboxWindow *) 0);
+    }
+    // when we switch workspaces, unfocus whatever was focused
+    blackbox->setFocusedWindow((BlackboxWindow *) 0);
+    
     current_workspace->hideAll();
-
     workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
 
-    if (blackbox->getFocusedWindow() &&
-        blackbox->getFocusedWindow()->getScreen() == this &&
-        (! blackbox->getFocusedWindow()->isStuck())) {
-      current_workspace->setLastFocusedWindow(blackbox->getFocusedWindow());
-      blackbox->setFocusedWindow((BlackboxWindow *) 0);
-    }
-
     current_workspace = getWorkspace(id);
 
+    xatom->setValue(getRootWindow(), XAtom::net_current_desktop,
+                    XAtom::cardinal, id);
+
     workspacemenu->setItemSelected(current_workspace->getID() + 2, True);
     toolbar->redrawWorkspaceLabel(True);
 
@@ -1038,18 +1107,128 @@ 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;
-  win->restoreAttributes();
+  if (blackbox->isStartup()) win->restoreAttributes();
   win->mapRequestEvent(&mre);
 }
 
@@ -1064,12 +1243,20 @@ void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
     removeIcon(w);
 
   windowList.remove(w);
+  updateClientList();
 
   if (blackbox->getFocusedWindow() == w)
     blackbox->setFocusedWindow((BlackboxWindow *) 0);
 
   removeNetizen(w->getClientWindow());
 
+  /*
+    some managed windows can also be window group controllers.  when
+    unmanaging such windows, we should also delete the window group.
+  */
+  BWindowGroup *group = blackbox->searchGroup(w->getClientWindow());
+  delete group;
+
   delete w;
 }
 
@@ -1103,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));
@@ -1110,6 +1316,11 @@ void BScreen::updateNetizenCurrentWorkspace(void) {
 
 
 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));
 }
@@ -1118,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);
@@ -1161,7 +1376,7 @@ void BScreen::updateNetizenConfigNotify(XEvent *e) {
 
 
 void BScreen::raiseWindows(Window *workspace_stack, unsigned int num) {
-  // XXX: why 13??
+  // the 13 represents the number of blackbox windows such as menus
   Window *session_stack = new
     Window[(num + workspacesList.size() + rootmenuList.size() + 13)];
   unsigned int i = 0, k = num;
@@ -1205,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());
 }
 
 
@@ -1884,6 +2091,8 @@ void BScreen::updateAvailableArea(void) {
     for (; it != end; ++it)
       if ((*it)->isMaximized()) (*it)->remaximize();
   }
+
+  updateWorkArea();  
 }
 
 
@@ -1961,9 +2170,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();
This page took 0.033243 seconds and 4 git commands to generate.