window-to-window snapping is now a run-time option. window-corner snapping added, and also is a run-time option.
Dana Jansens danakj@orodu.net
5 files changed,
137 insertions(+),
66 deletions(-)
M
src/Window.cc
→
src/Window.cc
@@ -2525,74 +2525,84 @@ // function!!
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 + 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()); + 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(); + // 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(); + 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; + 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(); + 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; - } + continue; + } - // snap top of other window? - if (dtop < snap_distance && dtop <= dbottom) { - dy = winrect.top() - frame.rect.height(); + // 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(); + 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; - 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(); + 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; + continue; + } } }
M
src/blackbox.cc
→
src/blackbox.cc
@@ -896,6 +896,18 @@ XSync(getXDisplay(), False);
} +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 @@ config.setValue("session.cacheLife", resource.cache_life / 60000);
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 @@ resource.cache_max = 200;
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; }
M
src/blackbox.hh
→
src/blackbox.hh
@@ -115,6 +115,8 @@ int colors_per_channel;
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 @@ { return resource.cache_life; }
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 @@
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);