Subject: attraction patch

From: [email-masked]
Date: Fri, 13 Nov 1998 12:56:11 +0100

Tim, if I remember correctly you had the window attraction
merged into 47d. Can you integrate it into CVS?

Bye

Dominik
-- 
Dominik Vogt, Hewlett-Packard GmbH, Dept. BVS
Herrenberger Str.130, 71034 Boeblingen, Germany
phone: 07031/14-4596, fax: 07031/14-3883, [email-masked]
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Tim Phipps <[email-masked]>
Date: Fri, 13 Nov 1998 12:02:52 +0000

> merged into 47d. Can you integrate it into CVS?
OK I'll try topost one this afternoon
Cheers,
Tim.

---

From: Tim Phipps <[email-masked]>
Date: Fri, 13 Nov 1998 14:43:27 +0000

> merged into 47d. Can you integrate it into CVS?
Here it is. Seems to work and I can't see any memory leaks in it.
Cheers,
Tim.

Index: fvwm2.1
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm2.1,v
retrieving revision 1.8
diff -u -r1.8 fvwm2.1
--- fvwm2.1	1998/11/12 01:52:09	1.8
+++ fvwm2.1	1998/11/13 14:33:52
@@ -1904,6 +1904,10 @@
 If the letter "p" is appended to each coordinate (horizontal and/or
 vertical), then the scroll amount will be measured in pixels.
 
+.IP "SnapAttraction \fIproximity\fP"
+If during an interactive move the window comes within \fIproximity\fP
+pixels of another the window will be moved to make the borders
+adjoin. The default of zero means that no snapping will happen.
 
 .IP "Stick"
 Makes a window sticky if it is not already sticky, or non-sticky if it
Index: builtins.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/builtins.c,v
retrieving revision 1.17
diff -u -r1.17 builtins.c
--- builtins.c	1998/11/11 13:09:55	1.17
+++ builtins.c	1998/11/13 14:34:16
@@ -1240,6 +1240,22 @@
     Scr.ClickTime = val1;
 }
 
+void SetSnapAttraction(XEvent *eventp,Window w,FvwmWindow *tmp_win,
+              unsigned long context, char *action,int* Module)
+{
+  int val1;
+  int val1_unit,n;
+
+  n = GetOneArgument(action, &val1, &val1_unit);
+  if(n != 1)
+  {
+    fvwm_msg(ERR,"SetSnapAttraction","SnapAttraction requires 1 argument");
+    return;
+  }
+
+  Scr.SnapAttraction = val1;
+}
+
 void SetXOR(XEvent *eventp,Window w,FvwmWindow *tmp_win,
             unsigned long context, char *action,int* Module)
 {
Index: functions.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/functions.c,v
retrieving revision 1.5
diff -u -r1.5 functions.c
--- functions.c	1998/11/07 15:16:04	1.5
+++ functions.c	1998/11/13 14:34:30
@@ -138,6 +138,7 @@
   {"SetAnimation", set_animation,    F_SET_ANIMATION,	    FUNC_NO_WINDOW},
   {"SetEnv",       SetEnv,           F_SETENV,              FUNC_NO_WINDOW},
   {"SetMenuDelay", set_menudelay,    F_SET_MENUDELAY,	    FUNC_NO_WINDOW},
+  {"SnapAttraction",SetSnapAttraction,F_SNAP_ATT,           FUNC_NO_WINDOW},
   {"Stick",        stick_function,   F_STICK,               FUNC_NEEDS_WINDOW},
   {"Style",        ProcessNewStyle,  F_STYLE,               FUNC_NO_WINDOW},
   {"Title",        Nop_func,         F_TITLE,               FUNC_TITLE},
Index: fvwm.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm.c,v
retrieving revision 1.10
diff -u -r1.10 fvwm.c
--- fvwm.c	1998/11/12 01:52:09	1.10
+++ fvwm.c	1998/11/13 14:34:49
@@ -1246,6 +1246,7 @@
 
   Scr.EdgeScrollX = Scr.EdgeScrollY = 100;
   Scr.ScrollResistance = Scr.MoveResistance = 0;
+  Scr.SnapAttraction = 0;
   Scr.OpaqueSize = 5;
   Scr.ClickTime = 150;
   Scr.ColormapFocus = COLORMAP_FOLLOWS_MOUSE;
Index: misc.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/misc.h,v
retrieving revision 1.10
diff -u -r1.10 misc.h
--- misc.h	1998/11/11 13:09:56	1.10
+++ misc.h	1998/11/13 14:35:05
@@ -514,6 +514,8 @@
 	       unsigned long context, char *action,int* Module);
 void SetClick(XEvent *eventp,Window w,FvwmWindow *tmp_win,
 	       unsigned long context, char *action,int* Module);
+void SetSnapAttraction(XEvent *eventp,Window w,FvwmWindow *tmp_win,
+			unsigned long context, char *action,int* Module);
 void NextFunc(XEvent *eventp,Window w,FvwmWindow *tmp_win,
 	      unsigned long context, char *action,int* Module);
 void PrevFunc(XEvent *eventp,Window w,FvwmWindow *tmp_win,
Index: move.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/move.c,v
retrieving revision 1.14
diff -u -r1.14 move.c
--- move.c	1998/11/12 10:01:41	1.14
+++ move.c	1998/11/13 14:35:21
@@ -253,6 +253,11 @@
 	      int Height, int *FinalX, int *FinalY,Bool opaque_move,
 	      Bool AddWindow)
 {
+      Window root, parent, *children;
+      FvwmWindow *tmp;
+      unsigned int nchildren;
+      int i,j;
+      int nyt,nxl,dist,closestLeft,closestRight,closestBottom,closestTop;
   Bool finished = False;
   Bool done;
   Bool fButtonDown;
@@ -343,6 +348,83 @@
 	  xl = Event.xmotion.x_root + XOffset;
 	  yt = Event.xmotion.y_root + YOffset;
 
+        /* resist based on window edges */
+        tmp = Scr.FvwmRoot.next;
+        closestTop = Scr.SnapAttraction;
+        closestBottom = Scr.SnapAttraction;
+        closestRight = Scr.SnapAttraction;
+        closestLeft = Scr.SnapAttraction;
+        nxl = xl;
+        nyt = yt;
+        while(tmp)
+        {
+                if (tmp_win != tmp && (tmp_win->Desk == tmp->Desk))
+                {
+                        if(!(   (tmp->frame_y + tmp->frame_height) < (yt) ||
+                                        (tmp->frame_y) > (yt + Height) ))
+                        {
+                                dist = abs(tmp->frame_x - (xl + Width));
+                                if(dist < closestRight)
+                                {
+                                        closestRight = dist;
+                                        if(((xl + Width) >= tmp->frame_x)&&
+                                                ((xl + Width) < tmp->frame_x+Scr.SnapAttraction))
+                                                nxl = tmp->frame_x - Width - tmp_win->bw;
+                                        if(((xl + Width) >= tmp->frame_x-Scr.SnapAttraction)&&
+                                                ((xl + Width) < tmp->frame_x))
+                                                nxl = tmp->frame_x - Width - tmp_win->bw;
+                                }
+                                dist = abs(tmp->frame_x + tmp->frame_width - xl);
+                                if(dist < closestLeft)
+                                {
+                                        closestLeft = dist;
+                                        if((xl <= tmp->frame_x + tmp->frame_width)&&
+                                                (xl > tmp->frame_x + tmp->frame_width-Scr.SnapAttraction))
+                                                nxl = tmp->frame_x + tmp->frame_width;
+                                        if((xl <= tmp->frame_x + tmp->frame_width+Scr.SnapAttraction)&&
+                                                (xl > tmp->frame_x + tmp->frame_width))
+                                                nxl = tmp->frame_x + tmp->frame_width;
+                                }
+                        }
+                        if(!(   (tmp->frame_x + tmp->frame_width) < (xl) ||
+                                        (tmp->frame_x) > (xl + Width) ))
+                        {
+                                dist = abs(tmp->frame_y - (yt + Height));
+                                if(dist < closestBottom)
+                                {
+                                        closestBottom = dist;
+                                        if(((yt + Height) >= tmp->frame_y)&&
+                                                ((yt + Height) < tmp->frame_y+Scr.SnapAttraction))
+                                                nyt = tmp->frame_y - Height - tmp_win->bw;
+                                        if(((yt + Height) >= tmp->frame_y-Scr.SnapAttraction)&&
+                                                ((yt + Height) < tmp->frame_y))
+                                                nyt = tmp->frame_y - Height - tmp_win->bw;
+                                }
+                                dist = abs(tmp->frame_y + tmp->frame_height - yt);
+                                if(dist < closestTop)
+                                {
+                                        closestTop = dist;
+                                        if((yt <= tmp->frame_y + tmp->frame_height)&&
+                                                (yt > tmp->frame_y + tmp->frame_height-Scr.SnapAttraction))
+                                                nyt = tmp->frame_y + tmp->frame_height;
+                                        if((yt <= tmp->frame_y + tmp->frame_height+Scr.SnapAttraction)&&
+                                                (yt > tmp->frame_y + tmp->frame_height))
+                                                nyt = tmp->frame_y + tmp->frame_height;
+                                }
+                        }
+#if 0
+                        if(((yt + Height) >= Scr.MyDisplayHeight)&&
+                                ((yt + Height) < Scr.MyDisplayHeight+Scr.MoveResistance))
+                                yt = Scr.MyDisplayHeight - Height - tmp_win->bw;
+                        if((yt <= 0)&&(yt > -Scr.MoveResistance))
+                                yt = 0;
+#endif
+                }
+                tmp = tmp->next;
+        }
+        xl = nxl;
+        yt = nyt;
+  
 	  /* Resist moving windows over the edge of the screen! */
 	  if(((xl + Width) >= Scr.MyDisplayWidth)&&
 	     ((xl + Width) < Scr.MyDisplayWidth+Scr.MoveResistance))
@@ -370,6 +452,83 @@
 	  /* redraw the rubberband */
 	  xl += XOffset;
 	  yt += YOffset;
+
+         /* resist based on window edges */
+         tmp = Scr.FvwmRoot.next;
+         closestTop = Scr.SnapAttraction;
+         closestBottom = Scr.SnapAttraction;
+         closestRight = Scr.SnapAttraction;
+         closestLeft = Scr.SnapAttraction;
+         nxl = xl;
+         nyt = yt;
+         while(tmp)
+         {
+                 if (tmp_win != tmp && (tmp_win->Desk == tmp->Desk))
+                 {
+                         if(!(   (tmp->frame_y + tmp->frame_height) < (yt) ||
+                                         (tmp->frame_y) > (yt + Height) ))
+                         {
+                                 dist = abs(tmp->frame_x - (xl + Width));
+                                 if(dist < closestRight)
+                                 {
+                                         closestRight = dist;
+                                         if(((xl + Width) >= tmp->frame_x)&&
+                                                 ((xl + Width) < tmp->frame_x+Scr.SnapAttraction))
+                                                 nxl = tmp->frame_x - Width - tmp_win->bw;
+                                         if(((xl + Width) >= tmp->frame_x-Scr.SnapAttraction)&&
+                                                 ((xl + Width) < tmp->frame_x))
+                                                 nxl = tmp->frame_x - Width - tmp_win->bw;
+                                 }
+                                 dist = abs(tmp->frame_x + tmp->frame_width - xl);
+                                 if(dist < closestLeft)
+                                 {
+                                         closestLeft = dist;
+                                         if((xl <= tmp->frame_x + tmp->frame_width)&&
+                                                 (xl > tmp->frame_x + tmp->frame_width-Scr.SnapAttraction))
+                                                 nxl = tmp->frame_x + tmp->frame_width;
+                                         if((xl <= tmp->frame_x + tmp->frame_width+Scr.SnapAttraction)&&
+                                                 (xl > tmp->frame_x + tmp->frame_width))
+                                                 nxl = tmp->frame_x + tmp->frame_width;
+                                 }
+                         }
+                         if(!(   (tmp->frame_x + tmp->frame_width) < (xl) ||
+                                         (tmp->frame_x) > (xl + Width) ))
+                         {
+                                 dist = abs(tmp->frame_y - (yt + Height));
+                                 if(dist < closestBottom)
+                                 {
+                                         closestBottom = dist;
+                                         if(((yt + Height) >= tmp->frame_y)&&
+                                                 ((yt + Height) < tmp->frame_y+Scr.SnapAttraction))
+                                                 nyt = tmp->frame_y - Height - tmp_win->bw;
+                                         if(((yt + Height) >= tmp->frame_y-Scr.SnapAttraction)&&
+                                                 ((yt + Height) < tmp->frame_y))
+                                                 nyt = tmp->frame_y - Height - tmp_win->bw;
+                                 }
+                                 dist = abs(tmp->frame_y + tmp->frame_height - yt);
+                                 if(dist < closestTop)
+                                 {
+                                         closestTop = dist;
+                                         if((yt <= tmp->frame_y + tmp->frame_height)&&
+                                                 (yt > tmp->frame_y + tmp->frame_height-Scr.SnapAttraction))
+                                                 nyt = tmp->frame_y + tmp->frame_height;
+                                         if((yt <= tmp->frame_y + tmp->frame_height+Scr.SnapAttraction)&&
+                                                 (yt > tmp->frame_y + tmp->frame_height))
+                                                 nyt = tmp->frame_y + tmp->frame_height;
+                                 }
+                         }
+#if 0
+                         if(((yt + Height) >= Scr.MyDisplayHeight)&&
+                                 ((yt + Height) < Scr.MyDisplayHeight+Scr.MoveResistance))
+                                 yt = Scr.MyDisplayHeight - Height - tmp_win->bw;
+                         if((yt <= 0)&&(yt > -Scr.MoveResistance))
+                                 yt = 0;
+#endif
+                 }
+                 tmp = tmp->next;
+         }
+         xl = nxl;
+         yt = nyt;
 
 	  /* Resist moving windows over the edge of the screen! */
 	  if(((xl + Width) >= Scr.MyDisplayWidth)&&
Index: parse.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/parse.h,v
retrieving revision 1.2
diff -u -r1.2 parse.h
--- parse.h	1998/10/30 21:19:36	1.2
+++ parse.h	1998/11/13 14:35:35
@@ -80,6 +80,7 @@
     F_SETENV,
     F_SET_ANIMATION,
     F_SET_MENUDELAY,
+    F_SNAP_ATT,
 /* Functions which require a target window */
     F_RESIZE = 100,
     F_RAISE,
Index: screen.h
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/screen.h,v
retrieving revision 1.3
diff -u -r1.3 screen.h
--- screen.h	1998/11/05 07:00:09	1.3
+++ screen.h	1998/11/13 14:35:49
@@ -317,6 +317,7 @@
   int ClickTime;               /*Max button-click delay for Function built-in*/
   int ScrollResistance;        /* resistance to scrolling in desktop */
   int MoveResistance;          /* res to moving windows over viewport edge */
+  int SnapAttraction;          /* attractiveness of window edges */
   int OpaqueSize;
   int CurrentDesk;             /* The current desktop number */
   int ColormapFocus;           /* colormap focus style */

---

From: Brad Giaccio <[email-masked]>
Date: Fri, 13 Nov 1998 11:45:28 -0500 (EST)

> Here it is. Seems to work and I can't see any memory leaks in it.

Seems to work as advertized, from the patch, so he has my vote to commit
it.

Brad

-- 
--- There are two kinds of knowledge, you either know the answer or
			you know where to find it
		      -Kane, Johnson, and anonymous

---

From: [email-masked]
Date: Fri, 13 Nov 1998 09:02:45 -0800

> Here it is. Seems to work and I can't see any memory leaks in it.

This patch is one rev behind.

to:
> +                if (tmp_win != tmp && !(tmp->flags&ICONIFIED) && (tmp_win->Desk == tmp->Desk))

This line needs to be changes in two locations, the MotionNotify and the
ButtonRelease cases.  My patch is for 2.0.46, so thats why I'm just notifying
this tweak instead of reposting the patch itself.

---

From: [email-masked]
Date: Mon, 16 Nov 1998 11:42:22 +0100

So, could someone commit this?

Dominik

---

From: [email-masked]
Date: Tue, 17 Nov 1998 19:59:11 +0100

> So, could someone commit this?

Well, if nobody volunteers I will commit it tomorrow (wednesday).

BTW, Tim, I thought you had commit privileges by now, don't you.

Dominik

---

From: Tim Phipps <[email-masked]>
Date: Wed, 18 Nov 1998 09:04:05 +0000

> BTW, Tim, I thought you had commit privileges by now, don't you.
Nope, I don't want it either, I'm not planning on doing anything big and
I like having patches looked at before getting committed. Besides, I'd
like to stay anonymous if possible.
Cheers,
Tim. (Stealth FVWM Evangelist)
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Dominik Vogt <[email-masked]>
Date: Thu, 19 Nov 1998 17:40:52 +0100

On Wed, Nov 18, 1998 at 09:04:05AM +0000, [email-masked] wrote:
> ... Besides, I'd like to stay anonymous if possible.

Did you look at the last lines of the manpage recently? ;-)

Bye

Dominik

---

From: Tim Phipps <[email-masked]>
Date: Tue, 24 Nov 1998 10:31:17 +0000

> Did you look at the last lines of the manpage recently? ;-)

Yes, patch attached.  I don't mind being in the AUTHORS file (that's
geek territory) but I'm not keen on the great unwashed banging on my
door.

Cheers,
Tim.

Index: fvwm2.1
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm2.1,v
retrieving revision 1.13
diff -u -B -b -r1.13 fvwm2.1
--- fvwm2.1	1998/11/20 10:18:37	1.13
+++ fvwm2.1	1998/11/24 10:29:34
@@ -2486,5 +2486,5 @@
 which was written by Tom LaStrange.  After Robert Nation came Charles Hines,
 followed by Brady Montz. Currently fvwm is maintained by the fvwm-workers
 mailing list temporarily led by Dominik Vogt but with help from many people
-(Dan Espen, Steve Robbins, Paul Smith, Tim Phipps, Jason Tibbitts and others).
+(Dan Espen, Steve Robbins, Paul Smith, Jason Tibbitts and others).

---

From: Dominik Vogt <[email-masked]>
Date: Tue, 24 Nov 1998 11:44:53 +0100

> geek territory) but I'm not keen on the great unwashed banging on my

*Sigh* And you are absolutely sure I can't convice you to get
commit priviledge? I'm spending nearly 50% of my work for fvwm
on applying your patches or testing them or working on your bug
reports ;-)

Bye

Dominik

---

From: Tim Phipps <[email-masked]>
Date: Tue, 24 Nov 1998 10:46:23 +0000

> on applying your patches or testing them or working on your bug

Completely, I'm done now.
Cheers,
Tim.