aboutsummaryrefslogtreecommitdiff
path: root/src/Window.cc
diff options
context:
space:
mode:
authorMichael Abbott <michael@araneidae.co.uk>2012-09-29 07:10:48 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2012-10-04 07:36:23 (GMT)
commit391712b9805eda9d56a100f49d69b38863910565 (patch)
tree05d5a6eea9fef53a371676f76ec4c1e1ef0893a1 /src/Window.cc
parent7b6ab828c7e5453a2720462156d165707935c9ef (diff)
downloadfluxbox-391712b9805eda9d56a100f49d69b38863910565.zip
fluxbox-391712b9805eda9d56a100f49d69b38863910565.tar.bz2
Add support for nearest corner or edge resizing
Diffstat (limited to 'src/Window.cc')
-rw-r--r--src/Window.cc66
1 files changed, 46 insertions, 20 deletions
diff --git a/src/Window.cc b/src/Window.cc
index 33a4c9e..0b8d1e5 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -251,6 +251,18 @@ private:
251 int m_mode; 251 int m_mode;
252}; 252};
253 253
254
255// Helper class for getResizeDirection below
256// Tests whether a point is on an edge or the corner.
257struct TestEdgeHelper {
258 int corner_size_px, corner_size_pc;
259 inline bool operator()(int xy, int wh)
260 {
261 /* The % checking must be right: 0% must fail, 100% must succeed. */
262 return xy < corner_size_px || 100 * xy < corner_size_pc * wh;
263 }
264};
265
254} 266}
255 267
256 268
@@ -3004,30 +3016,44 @@ void FluxboxWindow::doSnapping(int &orig_left, int &orig_top) {
3004 3016
3005} 3017}
3006 3018
3019
3007FluxboxWindow::ReferenceCorner FluxboxWindow::getResizeDirection(int x, int y, 3020FluxboxWindow::ReferenceCorner FluxboxWindow::getResizeDirection(int x, int y,
3008 ResizeModel model) const { 3021 ResizeModel model, int corner_size_px, int corner_size_pc) const
3022{
3023 if (model == TOPLEFTRESIZE) return LEFTTOP;
3024 if (model == TOPRESIZE) return TOP;
3025 if (model == TOPRIGHTRESIZE) return RIGHTTOP;
3026 if (model == LEFTRESIZE) return LEFT;
3027 if (model == RIGHTRESIZE) return RIGHT;
3028 if (model == BOTTOMLEFTRESIZE) return LEFTBOTTOM;
3029 if (model == BOTTOMRESIZE) return BOTTOM;
3030 if (model == CENTERRESIZE) return CENTER;
3031
3032 if (model == EDGEORCORNERRESIZE)
3033 {
3034 int w = frame().width();
3035 int h = frame().height();
3036 int cx = w / 2;
3037 int cy = h / 2;
3038 TestEdgeHelper test_edge = { corner_size_px, corner_size_pc };
3039 if (x < cx && test_edge(x, cx)) {
3040 if (y < cy && test_edge(y, cy))
3041 return LEFTTOP;
3042 else if (test_edge(h - y - 1, h - cy))
3043 return LEFTBOTTOM;
3044 } else if (test_edge(w - x - 1, w - cx)) {
3045 if (y < cy && test_edge(y, cy))
3046 return RIGHTTOP;
3047 else if (test_edge(h - y - 1, h - cy))
3048 return RIGHTBOTTOM;
3049 }
3009 3050
3010 int cx = frame().width() / 2; 3051 /* Nope, not a corner; find the nearest edge instead. */
3011 int cy = frame().height() / 2;
3012 if (model == CENTERRESIZE)
3013 return CENTER;
3014 if (model == NEARESTEDGERESIZE) {
3015 if (cy - abs(y - cy) < cx - abs(x - cx)) // y is nearest 3052 if (cy - abs(y - cy) < cx - abs(x - cx)) // y is nearest
3016 return (y > cy) ? BOTTOM : TOP; 3053 return (y > cy) ? BOTTOM : TOP;
3017 return (x > cx) ? RIGHT : LEFT; 3054 else
3018 } 3055 return (x > cx) ? RIGHT : LEFT;
3019 if (model == QUADRANTRESIZE) { 3056 }
3020 if (x < cx)
3021 return (y < cy) ? LEFTTOP : LEFTBOTTOM;
3022 return (y < cy) ? RIGHTTOP : RIGHTBOTTOM;
3023 }
3024 if (model == TOPLEFTRESIZE) return LEFTTOP;
3025 if (model == TOPRESIZE) return TOP;
3026 if (model == TOPRIGHTRESIZE) return RIGHTTOP;
3027 if (model == LEFTRESIZE) return LEFT;
3028 if (model == RIGHTRESIZE) return RIGHT;
3029 if (model == BOTTOMLEFTRESIZE) return LEFTBOTTOM;
3030 if (model == BOTTOMRESIZE) return BOTTOM;
3031 return RIGHTBOTTOM; 3057 return RIGHTBOTTOM;
3032} 3058}
3033 3059