[hackers] [wmii] Add screen.c || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sat, 18 Oct 2008 16:30:27 +0000 (UTC)

changeset: 2389:6bf95d6cd825
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Sat Oct 18 12:30:10 2008 -0400
files: cmd/wmii/screen.c
description:
Add screen.c

diff -r ecfe0bf8aac8 -r 6bf95d6cd825 cmd/wmii/screen.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/cmd/wmii/screen.c Sat Oct 18 12:30:10 2008 -0400
@@ -0,0 +1,99 @@
+/* Copyright ©2006-2008 Kris Maglione <maglione.k at Gmail>
+ * See LICENSE file for license details.
+ */
+#include "dat.h"
+#include <math.h>
+#include <stdlib.h>
+#include "fns.h"
+
+#ifdef notdef
+void
+mapscreens(void) {
+ WMScreen *s, *ss;
+ Rectangle r;
+ int i, j;
+
+#define frob(left, min, max, x, y) \
+ if(Dy(r) > 0) /* If they intersect at some point on this axis */ \
+ if(ss->r.min.x < s->r.min.x) { \
+ if((!s->left) \
+ || (abs(Dy(r)) < abs(s->left.max.x - s->min.x))) \
+ s->left = ss; \
+ }
+
+ /* Variable hell? Certainly. */
+ for(i=0; i < nscreens; i++) {
+ s = screens[i];
+ for(j=0; j < nscreens; j++) {
+ if(i == j)
+ continue;
+ ss = screens[j];
+ r = rect_intersection(ss->r, s->r);
+ frob(left, min, max, x, y);
+ frob(right, max, min, x, y);
+ frob(atop, min, max, y, x);
+ frob(below, max, min, y, x);
+ }
+ }
+#undef frob
+}
+
+int findscreen(Rectangle, int);
+int
+findscreen(Rectangle rect, int direction) {
+ Rectangle r;
+ WMScreen *ss, *s;
+ int best, i, j;
+
+ best = -1;
+#define frob(min, max, x, y)
+ if(Dy(r) > 0) /* If they intersect at some point on this axis */
+ if(ss->r.min.x < rect.min.x) {
+ if(best == -1
+ || (abs(ss->r.max.x - rect.min.x) < abs(screens[best]->r.max.x - rect.min.x)))
+ best = s->idx;
+ }
+
+ /* Variable hell? Certainly. */
+ for(i=0; i < nscreens; i++) {
+ ss = screens[j];
+ r = rect_intersection(ss->r, rect);
+ switch(direction) {
+ default:
+ return -1;
+ case West:
+ frob(min, max, x, y);
+ break;
+ case East:
+ frob(max, min, x, y);
+ break;
+ case North:
+ frob(min, max, y, x);
+ break;
+ case South:
+ frob(max, min, y, x);
+ break;
+ }
+ }
+#undef frob
+}
+#endif
+
+int
+ownerscreen(Rectangle r) {
+ Rectangle isect;
+ int s, a, best, besta;
+
+ SET(besta);
+ best = -1;
+ for(s=0; s < nscreens; s++) {
+ isect = rect_intersection(r, screens[s]->r);
+ a = Dx(isect) * Dy(isect);
+ if(best < 0 || a > besta) {
+ besta = a;
+ best = s;
+ }
+ }
+ return best;
+}
+
Received on Sat Oct 18 2008 - 16:30:27 UTC

This archive was generated by hypermail 2.2.0 : Sat Oct 18 2008 - 16:36:05 UTC