aboutsummaryrefslogtreecommitdiffstats
path: root/client.c
diff options
context:
space:
mode:
authorokan2011-06-24 06:06:24 +0000
committerokan2011-06-24 06:06:24 +0000
commitab4a3c9a9f59f702603e19f3eb3508a815521d6c (patch)
treeac1d554c262b5b74f3aaca048f357f87469c49c7 /client.c
parentc94e1a5dfb1df6ef5292efe8116084f95220d1a1 (diff)
downloadcwm-ab4a3c9a9f59f702603e19f3eb3508a815521d6c.tar.gz
introduce a new config option to snap to the screen edge. 'snapdist'
keyword taken from a diff from Sviatoslav Chagaev to do the same thing, but implemented in a completely way (based on some very old code from mk@). default set to 0, so no behavior change. ok oga@ (who would also like to take it further...)
Diffstat (limited to '')
-rw-r--r--client.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/client.c b/client.c
index d366f30..523a3b6 100644
--- a/client.c
+++ b/client.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: client.c,v 1.84 2011/06/24 06:01:47 okan Exp $
+ * $OpenBSD: client.c,v 1.85 2011/06/24 06:06:24 okan Exp $
*/
#include <sys/param.h>
@@ -842,3 +842,32 @@ client_inbound(struct client_ctx *cc, int x, int y)
return (x < cc->geom.width && x >= 0 &&
y < cc->geom.height && y >= 0);
}
+
+int
+client_snapcalc(int n, int dn, int nmax, int bwidth, int snapdist)
+{
+ int n0, n1, s0, s1;
+
+ s0 = s1 = 0;
+ n0 = n;
+ n1 = n + dn + (bwidth * 2);
+
+ if (abs(n0) <= snapdist)
+ s0 = -n0;
+
+ if (nmax - snapdist <= n1 && n1 <= nmax + snapdist)
+ s1 = nmax - n1;
+
+ /* possible to snap in both directions */
+ if (s0 != 0 && s1 != 0)
+ if (abs(s0) < abs(s1))
+ return s0;
+ else
+ return s1;
+ else if (s0 != 0)
+ return s0;
+ else if (s1 != 0)
+ return s1;
+ else
+ return 0;
+}