aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNephiel <nephiel@nephiel.net>2015-09-17 15:25:40 (GMT)
committerMathias Gumz <akira@fluxbox.org>2016-01-04 20:17:26 (GMT)
commit1f1d43bdbf675ff24e80e3e6bac157171eba7ca1 (patch)
treece6a5e71ddf9098e7d0161d94ce430244753da7c /src
parent3e4570becc66f868c14bef8b97edcca2d4b135bc (diff)
downloadfluxbox-1f1d43bdbf675ff24e80e3e6bac157171eba7ca1.zip
fluxbox-1f1d43bdbf675ff24e80e3e6bac157171eba7ca1.tar.bz2
Add Resize Snap
Make windows snap to edges when resizing them, as well as when moving. From http://darkshed.net/files/patches/fluxbox/fluxbox-resize-snap-try2.diff
Diffstat (limited to 'src')
-rw-r--r--src/Screen.hh2
-rw-r--r--src/ScreenResource.cc1
-rw-r--r--src/ScreenResource.hh1
-rw-r--r--src/Window.cc126
-rw-r--r--src/Window.hh2
5 files changed, 114 insertions, 18 deletions
diff --git a/src/Screen.hh b/src/Screen.hh
index 983aa81..1aeac91 100644
--- a/src/Screen.hh
+++ b/src/Screen.hh
@@ -232,6 +232,8 @@ public:
232 232
233 int getEdgeSnapThreshold() const { return *resource.edge_snap_threshold; } 233 int getEdgeSnapThreshold() const { return *resource.edge_snap_threshold; }
234 234
235 int getEdgeResizeSnapThreshold() const { return *resource.edge_resize_snap_threshold; }
236
235 void setRootColormapInstalled(bool r) { root_colormap_installed = r; } 237 void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
236 238
237 void saveTabPlacement(FbWinFrame::TabPlacement place) { *resource.tab_placement = place; } 239 void saveTabPlacement(FbWinFrame::TabPlacement place) { *resource.tab_placement = place; }
diff --git a/src/ScreenResource.cc b/src/ScreenResource.cc
index 0d8aaf7..dbf532b 100644
--- a/src/ScreenResource.cc
+++ b/src/ScreenResource.cc
@@ -97,6 +97,7 @@ ScreenResource::ScreenResource(FbTk::ResourceManager& rm,
97 typing_delay(rm, 0, scrname+".noFocusWhileTypingDelay", altscrname+".NoFocusWhileTypingDelay"), 97 typing_delay(rm, 0, scrname+".noFocusWhileTypingDelay", altscrname+".NoFocusWhileTypingDelay"),
98 workspaces(rm, 4, scrname+".workspaces", altscrname+".Workspaces"), 98 workspaces(rm, 4, scrname+".workspaces", altscrname+".Workspaces"),
99 edge_snap_threshold(rm, 10, scrname+".edgeSnapThreshold", altscrname+".EdgeSnapThreshold"), 99 edge_snap_threshold(rm, 10, scrname+".edgeSnapThreshold", altscrname+".EdgeSnapThreshold"),
100 edge_resize_snap_threshold(rm, 0, scrname+".edgeResizeSnapThreshold", altscrname+".EdgeResizeSnapThreshold"),
100 focused_alpha(rm, 255, scrname+".window.focus.alpha", altscrname+".Window.Focus.Alpha"), 101 focused_alpha(rm, 255, scrname+".window.focus.alpha", altscrname+".Window.Focus.Alpha"),
101 unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha", altscrname+".Window.Unfocus.Alpha"), 102 unfocused_alpha(rm, 255, scrname+".window.unfocus.alpha", altscrname+".Window.Unfocus.Alpha"),
102 menu_alpha(rm, 255, scrname+".menu.alpha", altscrname+".Menu.Alpha"), 103 menu_alpha(rm, 255, scrname+".menu.alpha", altscrname+".Menu.Alpha"),
diff --git a/src/ScreenResource.hh b/src/ScreenResource.hh
index 3a6eaa1..7f1e621 100644
--- a/src/ScreenResource.hh
+++ b/src/ScreenResource.hh
@@ -47,6 +47,7 @@ struct ScreenResource {
47 FbTk::Resource<unsigned int> typing_delay; 47 FbTk::Resource<unsigned int> typing_delay;
48 FbTk::Resource<int> workspaces, 48 FbTk::Resource<int> workspaces,
49 edge_snap_threshold, 49 edge_snap_threshold,
50 edge_resize_snap_threshold,
50 focused_alpha, 51 focused_alpha,
51 unfocused_alpha, 52 unfocused_alpha,
52 menu_alpha, 53 menu_alpha,
diff --git a/src/Window.cc b/src/Window.cc
index 0f91a9e..9129e7d 100644
--- a/src/Window.cc
+++ b/src/Window.cc
@@ -2526,6 +2526,82 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) {
2526 old_resize_w != m_last_resize_w || 2526 old_resize_w != m_last_resize_w ||
2527 old_resize_h != m_last_resize_h ) { 2527 old_resize_h != m_last_resize_h ) {
2528 2528
2529 if (screen().getEdgeResizeSnapThreshold() != 0) {
2530 int tx, ty;
2531 int botright_x = m_last_resize_x + m_last_resize_w;
2532 int botright_y = m_last_resize_y + m_last_resize_h;
2533
2534 switch (m_resize_corner) {
2535 case LEFTTOP:
2536 tx = m_last_resize_x;
2537 ty = m_last_resize_y;
2538
2539 doSnapping(tx, ty, true);
2540
2541 m_last_resize_x = tx;
2542 m_last_resize_y = ty;
2543
2544 m_last_resize_w = botright_x - m_last_resize_x;
2545 m_last_resize_h = botright_y - m_last_resize_y;
2546
2547 break;
2548
2549 case LEFTBOTTOM:
2550 tx = m_last_resize_x;
2551 ty = m_last_resize_y + m_last_resize_h;
2552
2553 ty += frame().window().borderWidth() * 2;
2554
2555 doSnapping(tx, ty, true);
2556
2557 ty -= frame().window().borderWidth() * 2;
2558
2559 m_last_resize_x = tx;
2560 m_last_resize_h = ty - m_last_resize_y;
2561
2562 m_last_resize_w = botright_x - m_last_resize_x;
2563
2564 break;
2565
2566 case RIGHTTOP:
2567 tx = m_last_resize_x + m_last_resize_w;
2568 ty = m_last_resize_y;
2569
2570 tx += frame().window().borderWidth() * 2;
2571
2572 doSnapping(tx, ty, true);
2573
2574 tx -= frame().window().borderWidth() * 2;
2575
2576 m_last_resize_w = tx - m_last_resize_x;
2577 m_last_resize_y = ty;
2578
2579 m_last_resize_h = botright_y - m_last_resize_y;
2580
2581 break;
2582
2583 case RIGHTBOTTOM:
2584 tx = m_last_resize_x + m_last_resize_w;
2585 ty = m_last_resize_y + m_last_resize_h;
2586
2587 tx += frame().window().borderWidth() * 2;
2588 ty += frame().window().borderWidth() * 2;
2589
2590 doSnapping(tx, ty, true);
2591
2592 tx -= frame().window().borderWidth() * 2;
2593 ty -= frame().window().borderWidth() * 2;
2594
2595 m_last_resize_w = tx - m_last_resize_x;
2596 m_last_resize_h = ty - m_last_resize_y;
2597
2598 break;
2599
2600 default:
2601 break;
2602 }
2603 }
2604
2529 // draw over old rect 2605 // draw over old rect
2530 parent().drawRectangle(screen().rootTheme()->opGC(), 2606 parent().drawRectangle(screen().rootTheme()->opGC(),
2531 old_resize_x, old_resize_y, 2607 old_resize_x, old_resize_y,
@@ -2816,7 +2892,8 @@ void FluxboxWindow::stopMoving(bool interrupted) {
2816 */ 2892 */
2817inline void snapToWindow(int &xlimit, int &ylimit, 2893inline void snapToWindow(int &xlimit, int &ylimit,
2818 int left, int right, int top, int bottom, 2894 int left, int right, int top, int bottom,
2819 int oleft, int oright, int otop, int obottom) { 2895 int oleft, int oright, int otop, int obottom,
2896 bool resize) {
2820 // Only snap if we're adjacent to the edge we're looking at 2897 // Only snap if we're adjacent to the edge we're looking at
2821 2898
2822 // for left + right, need to be in the right y range 2899 // for left + right, need to be in the right y range
@@ -2827,7 +2904,7 @@ inline void snapToWindow(int &xlimit, int &ylimit,
2827 2904
2828 // right 2905 // right
2829 if (abs(left-oright) < abs(xlimit)) xlimit = -(left-oright); 2906 if (abs(left-oright) < abs(xlimit)) xlimit = -(left-oright);
2830 if (abs(right-oright) < abs(xlimit)) xlimit = -(right-oright); 2907 if (!resize && abs(right-oright) < abs(xlimit)) xlimit = -(right-oright);
2831 } 2908 }
2832 2909
2833 // for top + bottom, need to be in the right x range 2910 // for top + bottom, need to be in the right x range
@@ -2838,7 +2915,7 @@ inline void snapToWindow(int &xlimit, int &ylimit,
2838 2915
2839 // bottom 2916 // bottom
2840 if (abs(top-obottom) < abs(ylimit)) ylimit = -(top-obottom); 2917 if (abs(top-obottom) < abs(ylimit)) ylimit = -(top-obottom);
2841 if (abs(bottom-obottom) < abs(ylimit)) ylimit = -(bottom-obottom); 2918 if (!resize && abs(bottom-obottom) < abs(ylimit)) ylimit = -(bottom-obottom);
2842 } 2919 }
2843 2920
2844} 2921}
@@ -2847,18 +2924,25 @@ inline void snapToWindow(int &xlimit, int &ylimit,
2847 * Do Whatever snapping magic is necessary, and return using the orig_left 2924 * Do Whatever snapping magic is necessary, and return using the orig_left
2848 * and orig_top variables to indicate the new x,y position 2925 * and orig_top variables to indicate the new x,y position
2849 */ 2926 */
2850void FluxboxWindow::doSnapping(int &orig_left, int &orig_top) { 2927void FluxboxWindow::doSnapping(int &orig_left, int &orig_top, bool resize) {
2851 /* 2928 /*
2852 * Snap to screen/head edges 2929 * Snap to screen/head edges
2853 * Snap to windows 2930 * Snap to windows
2854 */ 2931 */
2932 int threshold;
2933
2934 if (resize) {
2935 threshold = screen().getEdgeResizeSnapThreshold();
2936 } else {
2937 threshold = screen().getEdgeSnapThreshold();
2938 }
2855 2939
2856 if (screen().getEdgeSnapThreshold() == 0) return; 2940 if (0 == threshold) return;
2857 2941
2858 // Keep track of our best offsets so far 2942 // Keep track of our best offsets so far
2859 // We need to find things less than or equal to the threshold 2943 // We need to find things less than or equal to the threshold
2860 int dx = screen().getEdgeSnapThreshold() + 1; 2944 int dx = threshold + 1;
2861 int dy = screen().getEdgeSnapThreshold() + 1; 2945 int dy = threshold + 1;
2862 2946
2863 // we only care about the left/top etc that includes borders 2947 // we only care about the left/top etc that includes borders
2864 int borderW = 0; 2948 int borderW = 0;
@@ -2897,28 +2981,32 @@ void FluxboxWindow::doSnapping(int &orig_left, int &orig_top) {
2897 screen().maxLeft(h), 2981 screen().maxLeft(h),
2898 screen().maxRight(h), 2982 screen().maxRight(h),
2899 screen().maxTop(h), 2983 screen().maxTop(h),
2900 screen().maxBottom(h)); 2984 screen().maxBottom(h),
2985 resize);
2901 2986
2902 if (i_have_tabs) 2987 if (i_have_tabs)
2903 snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff, 2988 snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff,
2904 screen().maxLeft(h), 2989 screen().maxLeft(h),
2905 screen().maxRight(h), 2990 screen().maxRight(h),
2906 screen().maxTop(h), 2991 screen().maxTop(h),
2907 screen().maxBottom(h)); 2992 screen().maxBottom(h),
2993 resize);
2908 } 2994 }
2909 for (int h=starth; h <= screen().numHeads(); h++) { 2995 for (int h=starth; h <= screen().numHeads(); h++) {
2910 snapToWindow(dx, dy, left, right, top, bottom, 2996 snapToWindow(dx, dy, left, right, top, bottom,
2911 screen().getHeadX(h), 2997 screen().getHeadX(h),
2912 screen().getHeadX(h) + screen().getHeadWidth(h), 2998 screen().getHeadX(h) + screen().getHeadWidth(h),
2913 screen().getHeadY(h), 2999 screen().getHeadY(h),
2914 screen().getHeadY(h) + screen().getHeadHeight(h)); 3000 screen().getHeadY(h) + screen().getHeadHeight(h),
3001 resize);
2915 3002
2916 if (i_have_tabs) 3003 if (i_have_tabs)
2917 snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff, 3004 snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff,
2918 screen().getHeadX(h), 3005 screen().getHeadX(h),
2919 screen().getHeadX(h) + screen().getHeadWidth(h), 3006 screen().getHeadX(h) + screen().getHeadWidth(h),
2920 screen().getHeadY(h), 3007 screen().getHeadY(h),
2921 screen().getHeadY(h) + screen().getHeadHeight(h)); 3008 screen().getHeadY(h) + screen().getHeadHeight(h),
3009 resize);
2922 } 3010 }
2923 3011
2924 ///////////////////////////////////// 3012 /////////////////////////////////////
@@ -2942,14 +3030,16 @@ void FluxboxWindow::doSnapping(int &orig_left, int &orig_top) {
2942 (*it)->x(), 3030 (*it)->x(),
2943 (*it)->x() + (*it)->width() + 2 * bw, 3031 (*it)->x() + (*it)->width() + 2 * bw,
2944 (*it)->y(), 3032 (*it)->y(),
2945 (*it)->y() + (*it)->height() + 2 * bw); 3033 (*it)->y() + (*it)->height() + 2 * bw,
3034 resize);
2946 3035
2947 if (i_have_tabs) 3036 if (i_have_tabs)
2948 snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff, 3037 snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff,
2949 (*it)->x(), 3038 (*it)->x(),
2950 (*it)->x() + (*it)->width() + 2 * bw, 3039 (*it)->x() + (*it)->width() + 2 * bw,
2951 (*it)->y(), 3040 (*it)->y(),
2952 (*it)->y() + (*it)->height() + 2 * bw); 3041 (*it)->y() + (*it)->height() + 2 * bw,
3042 resize);
2953 3043
2954 // also snap to the box containing the tabs (don't bother with actual 3044 // also snap to the box containing the tabs (don't bother with actual
2955 // tab edges, since they're dynamic 3045 // tab edges, since they're dynamic
@@ -2958,21 +3048,23 @@ void FluxboxWindow::doSnapping(int &orig_left, int &orig_top) {
2958 (*it)->x() - (*it)->xOffset(), 3048 (*it)->x() - (*it)->xOffset(),
2959 (*it)->x() - (*it)->xOffset() + (*it)->width() + 2 * bw + (*it)->widthOffset(), 3049 (*it)->x() - (*it)->xOffset() + (*it)->width() + 2 * bw + (*it)->widthOffset(),
2960 (*it)->y() - (*it)->yOffset(), 3050 (*it)->y() - (*it)->yOffset(),
2961 (*it)->y() - (*it)->yOffset() + (*it)->height() + 2 * bw + (*it)->heightOffset()); 3051 (*it)->y() - (*it)->yOffset() + (*it)->height() + 2 * bw + (*it)->heightOffset(),
3052 resize);
2962 3053
2963 if (i_have_tabs) 3054 if (i_have_tabs)
2964 snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff, 3055 snapToWindow(dx, dy, left - xoff, right - xoff + woff, top - yoff, bottom - yoff + hoff,
2965 (*it)->x() - (*it)->xOffset(), 3056 (*it)->x() - (*it)->xOffset(),
2966 (*it)->x() - (*it)->xOffset() + (*it)->width() + 2 * bw + (*it)->widthOffset(), 3057 (*it)->x() - (*it)->xOffset() + (*it)->width() + 2 * bw + (*it)->widthOffset(),
2967 (*it)->y() - (*it)->yOffset(), 3058 (*it)->y() - (*it)->yOffset(),
2968 (*it)->y() - (*it)->yOffset() + (*it)->height() + 2 * bw + (*it)->heightOffset()); 3059 (*it)->y() - (*it)->yOffset() + (*it)->height() + 2 * bw + (*it)->heightOffset(),
3060 resize);
2969 3061
2970 } 3062 }
2971 3063
2972 // commit 3064 // commit
2973 if (dx <= screen().getEdgeSnapThreshold()) 3065 if (dx <= threshold)
2974 orig_left += dx; 3066 orig_left += dx;
2975 if (dy <= screen().getEdgeSnapThreshold()) 3067 if (dy <= threshold)
2976 orig_top += dy; 3068 orig_top += dy;
2977 3069
2978} 3070}
diff --git a/src/Window.hh b/src/Window.hh
index da126ec..c04676a 100644
--- a/src/Window.hh
+++ b/src/Window.hh
@@ -502,7 +502,7 @@ private:
502 void attachWorkAreaSig(); 502 void attachWorkAreaSig();
503 503
504 // modifies left and top if snap is necessary 504 // modifies left and top if snap is necessary
505 void doSnapping(int &left, int &top); 505 void doSnapping(int &left, int &top, bool resize = false);
506 // user_w/h return the values that should be shown to the user 506 // user_w/h return the values that should be shown to the user
507 void fixSize(); 507 void fixSize();
508 void moveResizeClient(WinClient &client); 508 void moveResizeClient(WinClient &client);