]> Dogcows Code - chaz/openbox/blobdiff - src/Screen.cc
fix off-by-ones in window-to-window snapping. move the property from the blackbox...
[chaz/openbox] / src / Screen.cc
index 67033a82cfe4780cc8851fe9aa31abeec6bf098e..ba394bc95e8eb7087f2f0a53d4f633179f57a498 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,13 +138,10 @@ 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
 
   XDefineCursor(blackbox->getXDisplay(), getRootWindow(),
@@ -233,10 +233,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);
@@ -408,6 +414,30 @@ void BScreen::saveFocusLast(bool f) {
 }
 
 
+void BScreen::saveHideToolbar(bool h) {
+  resource.hide_toolbar = h;
+  if (resource.hide_toolbar)
+    toolbar->unmapToolbar();
+  else
+    toolbar->mapToolbar();
+  config->setValue(screenstr + "hideToolbar", resource.hide_toolbar);
+}
+
+
+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);
@@ -493,6 +523,9 @@ void BScreen::save_rc(void) {
   saveFullMax(resource.full_max);
   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);
@@ -529,6 +562,17 @@ void BScreen::load_rc(void) {
   if (! config->getValue(screenstr + "opaqueMove", resource.opaque_move))
     resource.opaque_move = false;
 
+  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);
@@ -664,11 +708,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();
 
@@ -949,7 +1013,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);
+  saveWorkspaces(getWorkspaceCount());
   saveWorkspaceNames();
 
   workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
@@ -981,7 +1045,7 @@ unsigned int BScreen::removeLastWorkspace(void) {
   workspacesList.pop_back();
   delete wkspc;
 
-  saveWorkspaces(getWorkspaceCount() - 1);
+  saveWorkspaces(getWorkspaceCount());
   saveWorkspaceNames();
 
   toolbar->reconfigure();
@@ -1000,15 +1064,23 @@ void BScreen::changeWorkspaceID(unsigned int id) {
 
     workspacemenu->setItemSelected(current_workspace->getID() + 2, False);
 
-    if (blackbox->getFocusedWindow() &&
-        blackbox->getFocusedWindow()->getScreen() == this &&
-        (! blackbox->getFocusedWindow()->isStuck())) {
-      current_workspace->setLastFocusedWindow(blackbox->getFocusedWindow());
+    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);
       blackbox->setFocusedWindow((BlackboxWindow *) 0);
     }
 
     current_workspace = getWorkspace(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);
 
@@ -1035,7 +1107,8 @@ void BScreen::manageWindow(Window w) {
 
   XMapRequestEvent mre;
   mre.window = w;
-  win->restoreAttributes();
+  if (blackbox->isStartup())
+    win->restoreAttributes();
   win->mapRequestEvent(&mre);
 }
 
@@ -1056,6 +1129,13 @@ void BScreen::unmanageWindow(BlackboxWindow *w, bool remap) {
 
   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;
 }
 
@@ -1096,6 +1176,9 @@ void BScreen::updateNetizenCurrentWorkspace(void) {
 
 
 void BScreen::updateNetizenWorkspaceCount(void) {
+  xatom->setValue(getRootWindow(), XAtom::net_number_of_desktops,
+                  XAtom::cardinal, workspacesList.size());
+
   std::for_each(netizenList.begin(), netizenList.end(),
                 std::mem_fun(&Netizen::sendWorkspaceCount));
 }
@@ -1927,6 +2010,18 @@ void BScreen::buttonPressEvent(XButtonEvent *xbutton) {
       blackbox->checkMenu();
       rootmenu->show();
     }
+  // mouse wheel up
+  } else if (xbutton->button == 4) {
+    if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
+      changeWorkspaceID(0);
+    else
+      changeWorkspaceID(getCurrentWorkspaceID() + 1);
+  // mouse wheel down
+  } else if (xbutton->button == 5) {
+    if (getCurrentWorkspaceID() == 0)
+      changeWorkspaceID(getWorkspaceCount() - 1);
+    else
+      changeWorkspaceID(getCurrentWorkspaceID() - 1);
   }
 }
 
This page took 0.028674 seconds and 4 git commands to generate.