]> Dogcows Code - chaz/openbox/blobdiff - src/Screen.cc
sync with blackbox-cvs
[chaz/openbox] / src / Screen.cc
index 3b2b4cb9075b78de4c40a91722a8227f79f7437a..5f69d82af15025eaf2d54d5e8265c501a9c78c82 100644 (file)
@@ -66,8 +66,11 @@ extern "C" {
 #endif // HAVE_STDARG_H
 }
 
+#include <assert.h>
+
 #include <algorithm>
 #include <functional>
+#include <string>
 using std::string;
 
 #include "i18n.hh"
@@ -242,6 +245,8 @@ 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);
@@ -421,6 +426,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);
@@ -507,6 +526,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);
@@ -546,6 +567,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);
@@ -566,7 +595,6 @@ void BScreen::load_rc(void) {
   else
     resource.col_direction = TopBottom;
 
-  removeWorkspaceNames();
   if (config->getValue(screenstr + "workspaceNames", s)) {
     string::const_iterator it = s.begin(), end = s.end();
     while(1) {
@@ -681,11 +709,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();
 
@@ -1013,17 +1061,24 @@ 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,
@@ -1056,7 +1111,7 @@ void BScreen::manageWindow(Window w) {
 
   XMapRequestEvent mre;
   mre.window = w;
-  win->restoreAttributes();
+  if (blackbox->isStartup()) win->restoreAttributes();
   win->mapRequestEvent(&mre);
 }
 
@@ -1178,7 +1233,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;
This page took 0.02469 seconds and 4 git commands to generate.