]> Dogcows Code - chaz/openbox/commitdiff
window-to-window snapping is now a run-time option.
authorDana Jansens <danakj@orodu.net>
Sun, 2 Jun 2002 00:30:55 +0000 (00:30 +0000)
committerDana Jansens <danakj@orodu.net>
Sun, 2 Jun 2002 00:30:55 +0000 (00:30 +0000)
window-corner snapping added, and also is a run-time option.

nls/C/Configmenu.m
src/Configmenu.cc
src/Window.cc
src/blackbox.cc
src/blackbox.hh

index b0c3e019078b9d237fc03e7209a1276e411fa4d6..3143c0d80a68666de9390d706ed936db02c71d6d 100644 (file)
@@ -16,6 +16,10 @@ $ #FocusNew
 # Focus New Windows
 $ #FocusLast
 # Focus Window on Workspace Change
+$ #WindowToWindowSnap
+# Window-To-Window Snapping
+$ #WindowCornerSnap
+# Window Corner Snapping
 $ #HideToolbar
 # Hide Toolbar
 $ #ClickToFocus
index 77755e27af9212cc795638725e675f41e1f04e7b..7bd90ef24ceea68b9a238f416578c462a18ab5a0 100644 (file)
@@ -53,8 +53,12 @@ Configmenu::Configmenu(BScreen *scr) : Basemenu(scr) {
               "Focus New Windows"), 4);
   insert(i18n(ConfigmenuSet, ConfigmenuFocusLast,
               "Focus Last Window on Workspace"), 5);
+  insert(i18n(ConfigmenuSet, ConfigmenuWindowToWindowSnap,
+              "Window-To-Window Snapping"), 6);
+  insert(i18n(ConfigmenuSet, ConfigmenuWindowCornerSnap,
+              "Window Corner Snapping"), 7);
   insert(i18n(ConfigmenuSet, ConfigmenuHideToolbar,
-              "Hide Toolbar"), 6);
+              "Hide Toolbar"), 8);
   update();
   setValues();
 }
@@ -66,7 +70,12 @@ void Configmenu::setValues(void) {
   setItemSelected(4, getScreen()->doFullMax());
   setItemSelected(5, getScreen()->doFocusNew());
   setItemSelected(6, getScreen()->doFocusLast());
-  setItemSelected(7, getScreen()->doHideToolbar());
+  setItemSelected(7, getScreen()->getBlackbox()->getWindowToWindowSnap());
+
+  setItemSelected(8, getScreen()->getBlackbox()->getWindowCornerSnap());
+  setItemEnabled(8, getScreen()->getBlackbox()->getWindowToWindowSnap());
+  
+  setItemSelected(9, getScreen()->doHideToolbar());
 }
 
 
@@ -92,30 +101,47 @@ void Configmenu::itemSelected(int button, unsigned int index) {
   }
 
   case 2: { // opaque move
-    getScreen()->saveOpaqueMove((! getScreen()->doOpaqueMove()));
+    getScreen()->saveOpaqueMove(! getScreen()->doOpaqueMove());
     setItemSelected(index, getScreen()->doOpaqueMove());
     break;
   }
 
   case 3: { // full maximization
-    getScreen()->saveFullMax((! getScreen()->doFullMax()));
+    getScreen()->saveFullMax(! getScreen()->doFullMax());
     setItemSelected(index, getScreen()->doFullMax());
     break;
   }
   case 4: { // focus new windows
-    getScreen()->saveFocusNew((! getScreen()->doFocusNew()));
+    getScreen()->saveFocusNew(! getScreen()->doFocusNew());
     setItemSelected(index, getScreen()->doFocusNew());
     break;
   }
 
   case 5: { // focus last window on workspace
-    getScreen()->saveFocusLast((! getScreen()->doFocusLast()));
+    getScreen()->saveFocusLast(! getScreen()->doFocusLast());
     setItemSelected(index, getScreen()->doFocusLast());
     break;
   }
 
-  case 6: { // hide toolbar
-    getScreen()->saveHideToolbar((! getScreen()->doHideToolbar()));
+  case 6: { // window-to-window snapping
+    getScreen()->getBlackbox()->
+      saveWindowToWindowSnap(! getScreen()->getBlackbox()->
+                             getWindowToWindowSnap());
+    setItemSelected(index, getScreen()->getBlackbox()->getWindowToWindowSnap());
+    setItemEnabled(index + 1,
+                   getScreen()->getBlackbox()->getWindowToWindowSnap());
+    break;
+  }
+
+  case 7: { // window corner snapping
+    getScreen()->getBlackbox()->
+      saveWindowCornerSnap(! getScreen()->getBlackbox()->getWindowCornerSnap());
+    setItemSelected(index, getScreen()->getBlackbox()->getWindowCornerSnap());
+    break;
+  }
+
+  case 8: { // hide toolbar
+    getScreen()->saveHideToolbar(! getScreen()->doHideToolbar());
     setItemSelected(index, getScreen()->doHideToolbar());
     break;
   }
index 86898d542124bd2c36166873edd9dd35b04e91b0..be03e4aab012d3c1b7f9204668be3a5e36132138 100644 (file)
@@ -2525,74 +2525,84 @@ void BlackboxWindow::motionNotifyEvent(XMotionEvent *me) {
         Workspace *w = screen->getWorkspace(getWorkspaceNumber());
         assert(w);
 
-        // try snap to another window
-        for (unsigned int i = 0, c = w->getCount(); i < c; ++i) {
-          BlackboxWindow *snapwin = w->getWindow(i);
-          if (snapwin == this)
-            continue;   // don't snap to self
-
-          const Rect &winrect = snapwin->frameRect();
-          int dleft = std::abs(wright - winrect.left()),
-             dright = std::abs(wleft - winrect.right()),
-               dtop = std::abs(wbottom - winrect.top()),
-            dbottom = std::abs(wtop - winrect.bottom());
-
-          // snap left of other window?
-          if (dleft < snap_distance && dleft <= dright) {
-            dx = winrect.left() - frame.rect.width();
-
-            // try corner-snap to its other sides
-            dtop = std::abs(wtop - winrect.top());
-            dbottom = std::abs(wbottom - winrect.bottom());
-            if (dtop < snap_distance && dtop <= dbottom)
-              dy = winrect.top();
-            else if (dbottom < snap_distance)
-              dy = winrect.bottom() - frame.rect.height();
-
-            continue;
-          }
-          // snap right of other window?
-          else if (dright < snap_distance) {
-            dx = winrect.right() + 1;
-
-            // try corner-snap to its other sides
-            dtop = std::abs(wtop - winrect.top());
-            dbottom = std::abs(wbottom - winrect.bottom());
-            if (dtop < snap_distance && dtop <= dbottom)
-              dy = winrect.top();
-            else if (dbottom < snap_distance)
-              dy = winrect.bottom() - frame.rect.height();
-
-            continue;
-          }
-
-          // snap top of other window?
-          if (dtop < snap_distance && dtop <= dbottom) {
-            dy = winrect.top() - frame.rect.height();
-
-            // try corner-snap to its other sides
-            dleft = std::abs(wleft - winrect.left());
-            dright = std::abs(wright - winrect.right());
-            if (dleft < snap_distance && dleft <= dright)
-              dx = winrect.left();
-            else if (dright < snap_distance)
-              dx = winrect.right() - frame.rect.width();
-
-            continue;
-          }
-          // snap bottom of other window?
-          else if (dbottom < snap_distance) {
-            dy = winrect.bottom() + 1;
-            
-            // try corner-snap to its other sides
-            dleft = std::abs(wleft - winrect.left());
-            dright = std::abs(wright - winrect.right());
-            if (dleft < snap_distance && dleft <= dright)
-              dx = winrect.left();
-            else if (dright < snap_distance)
-              dx = winrect.right() - frame.rect.width();
-
-            continue;
+        if (blackbox->getWindowToWindowSnap()) {
+          // try snap to another window
+          for (unsigned int i = 0, c = w->getCount(); i < c; ++i) {
+            BlackboxWindow *snapwin = w->getWindow(i);
+            if (snapwin == this)
+              continue;   // don't snap to self
+
+            const Rect &winrect = snapwin->frameRect();
+            int dleft = std::abs(wright - winrect.left()),
+               dright = std::abs(wleft - winrect.right()),
+                 dtop = std::abs(wbottom - winrect.top()),
+              dbottom = std::abs(wtop - winrect.bottom());
+
+            // snap left of other window?
+            if (dleft < snap_distance && dleft <= dright) {
+              dx = winrect.left() - frame.rect.width();
+
+              if (blackbox->getWindowCornerSnap()) {
+                // try corner-snap to its other sides
+                dtop = std::abs(wtop - winrect.top());
+                dbottom = std::abs(wbottom - winrect.bottom());
+                if (dtop < snap_distance && dtop <= dbottom)
+                  dy = winrect.top();
+                else if (dbottom < snap_distance)
+                  dy = winrect.bottom() - frame.rect.height();
+              }
+
+              continue;
+            }
+            // snap right of other window?
+            else if (dright < snap_distance) {
+              dx = winrect.right() + 1;
+
+              if (blackbox->getWindowCornerSnap()) {
+                // try corner-snap to its other sides
+                dtop = std::abs(wtop - winrect.top());
+                dbottom = std::abs(wbottom - winrect.bottom());
+                if (dtop < snap_distance && dtop <= dbottom)
+                  dy = winrect.top();
+                else if (dbottom < snap_distance)
+                  dy = winrect.bottom() - frame.rect.height();
+              }
+
+              continue;
+            }
+
+            // snap top of other window?
+            if (dtop < snap_distance && dtop <= dbottom) {
+              dy = winrect.top() - frame.rect.height();
+
+              if (blackbox->getWindowCornerSnap()) {
+                // try corner-snap to its other sides
+                dleft = std::abs(wleft - winrect.left());
+                dright = std::abs(wright - winrect.right());
+                if (dleft < snap_distance && dleft <= dright)
+                  dx = winrect.left();
+                else if (dright < snap_distance)
+                  dx = winrect.right() - frame.rect.width();
+              }
+
+              continue;
+            }
+            // snap bottom of other window?
+            else if (dbottom < snap_distance) {
+              dy = winrect.bottom() + 1;
+
+              if (blackbox->getWindowCornerSnap()) {
+                // try corner-snap to its other sides
+                dleft = std::abs(wleft - winrect.left());
+                dright = std::abs(wright - winrect.right());
+                if (dleft < snap_distance && dleft <= dright)
+                  dx = winrect.left();
+                else if (dright < snap_distance)
+                  dx = winrect.right() - frame.rect.width();
+              }
+
+              continue;
+            }
           }
         }
                 
index 72bbf7234eedccea6566109a8f107516338e2c1d..266d0e7318a6b1ffa807a48699e4e7b899eada73 100644 (file)
@@ -896,6 +896,18 @@ void Blackbox::shutdown(void) {
 }
 
 
+void Blackbox::saveWindowToWindowSnap(bool s) {
+  resource.window_to_window_snap = s;
+  config.setValue("session.windowToWindowSnap", resource.window_to_window_snap);
+}
+
+
+void Blackbox::saveWindowCornerSnap(bool s) {
+  resource.window_corner_snap = s;
+  config.setValue("session.windowCornerSnap", resource.window_corner_snap);
+}
+
+
 /*
  * Save all values as they are so that the defaults will be written to the rc
  * file
@@ -913,6 +925,8 @@ void Blackbox::save_rc(void) {
   config.setValue("session.cacheMax", resource.cache_max);
   config.setValue("session.styleFile", resource.style_file);
   config.setValue("session.titlebarLayout", resource.titlebar_layout);
+  saveWindowToWindowSnap(resource.window_to_window_snap);
+  saveWindowCornerSnap(resource.window_corner_snap);
   
   std::for_each(screenList.begin(), screenList.end(),
                 std::mem_fun(&BScreen::save_rc));
@@ -960,6 +974,14 @@ void Blackbox::load_rc(void) {
   
   if (! config.getValue("session.titlebarLayout", resource.titlebar_layout))
     resource.titlebar_layout = "ILMC";
+
+  if (! config.getValue("session.windowToWindowSnap",
+                        resource.window_to_window_snap))
+    resource.window_to_window_snap = true;
+
+  if (! config.getValue("session.windowCornerSnap",
+                        resource.window_corner_snap))
+    resource.window_corner_snap = true;
 }
 
 
index cb38dc3400ae019800703d1c19ce2f7e86bff84b..48fda8c549a594aa5f0697b541c343cf0318b5fe 100644 (file)
@@ -115,6 +115,8 @@ private:
     timeval auto_raise_delay;
     unsigned long cache_life, cache_max;
     std::string titlebar_layout;
+    bool window_to_window_snap;
+    bool window_corner_snap;
   } resource;
 
   typedef std::map<Window, BlackboxWindow*> WindowLookup;
@@ -215,6 +217,11 @@ public:
   inline unsigned long getCacheMax(void) const
     { return resource.cache_max; }
 
+  inline bool getWindowToWindowSnap(void) const
+    { return resource.window_to_window_snap; }
+  inline bool getWindowCornerSnap(void) const
+    { return resource.window_corner_snap; }
+
   inline void setNoFocus(bool f) { no_focus = f; }
 
   inline Cursor getSessionCursor(void) const
@@ -229,6 +236,8 @@ public:
   void setFocusedWindow(BlackboxWindow *w);
   void shutdown(void);
   void saveStyleFilename(const std::string& filename);
+  void saveWindowToWindowSnap(bool);
+  void saveWindowCornerSnap(bool);
   void addMenuTimestamp(const std::string& filename);
   void restart(const char *prog = 0);
   void reconfigure(void);
This page took 0.030252 seconds and 4 git commands to generate.