Subject: Maximize patch

From: Tomas Ogren <[email-masked]>
Date: Sun, 21 Mar 1999 00:59:43 +0100

I've hacked up a patch for Maximize to allow "adaptive" maximizing.. it
expands window to maximum available space until it hits something. You
can combine it with any other maximize flags.

Maximize 0 -1     - Increase height to max avail
Maximize -1 500p  - _first_ set height to 500p, then inc width
Maximize 500p -1  - _first_ set width to 500p, then inc height
Maximize -1 -1    - _first_ inc height, then inc width
...

The idea has been taken from enlightenment (a useful function too 8)

Would be nice if people could test this with funky setups.. I haven't
been able to make it freak out yet.. (only in e 8)

/Tomas
-- 
Tomas Ögren, [email-masked], http://www.ing.umu.se/~stric/
|- Student of Computer Science at the University of Umeå
`- Sysadmin at {cs,ing,acc}.umu.se
Index: AUTHORS
===================================================================
RCS file: /home/cvs/fvwm/fvwm/AUTHORS,v
retrieving revision 1.18
diff -u -r1.18 AUTHORS
--- AUTHORS	1999/03/19 05:00:17	1.18
+++ AUTHORS	1999/03/20 23:18:35
@@ -57,7 +57,7 @@
 StartsOnPage style, Stacking Order chain.
 
 Tomas Ogren:
-Animated windowshading, various bugfixes.
+Animated windowshading, "adaptive maximize", various bugfixes.

 Along with a cast of thousands (well, dozens) mentioned in old
Index: ChangeLog
===================================================================
RCS file: /home/cvs/fvwm/fvwm/ChangeLog,v
retrieving revision 1.239
diff -u -r1.239 ChangeLog
--- ChangeLog	1999/03/20 23:04:29	1.239
+++ ChangeLog	1999/03/20 23:18:38
@@ -1,5 +1,11 @@
 1999-03-21  Tomas Ogren  <[email-masked]>
 
+	* fvwm/builtins.c: Maximize can now expand until hitting some other
+	window (with the arg(s) -1). Ideas taken from enlightenment.
+	* fvwm/builtins.c: Fixed various compiler warnings.
+
+1999-03-21  Tomas Ogren  <[email-masked]>
+
 	* fvwm/builtins.c: Fixed various compiler warnings.
 
 Sat Mar 20 15:22:02 1999  DanEspen  <dje@blue>
Index: NEWS
===================================================================
RCS file: /home/cvs/fvwm/fvwm/NEWS,v
retrieving revision 1.58
diff -u -r1.58 NEWS
--- NEWS	1999/03/19 15:40:24	1.58
+++ NEWS	1999/03/20 23:18:39
@@ -1,5 +1,8 @@
 Changes in alpha release 2.3.0 (February 1999)
 
+* Maximize can now expand until some other window is found to fully utilize
+  available screen space.
+
 * FvwmWinList option *FvwmWinListFollowWindowList to display the order that
   fvwm keeps windows in. You can now see the order that Next/Prev will take,
   Prev goes down the list, Next goes up (from the bottom).
Index: fvwm/builtins.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/builtins.c,v
retrieving revision 1.86
diff -u -r1.86 builtins.c
--- fvwm/builtins.c	1999/03/20 23:04:30	1.86
+++ fvwm/builtins.c	1999/03/20 23:18:42
@@ -30,6 +30,8 @@
 static void FreeMenuFace(Display *dpy, MenuFace *mf);
 static void ApplyIconFont(void);
 static void ApplyWindowFont(FvwmDecor *fl);
+void MaximizeHeight(FvwmWindow *win, int height, int x, int *ret_height, int *ret_y);
+void MaximizeWidth(FvwmWindow *win, int *ret_width, int *ret_x, int height, int y);
 
 static char *exec_shell_name="/bin/sh";
 /* button state strings must match the enumerated states */
@@ -244,13 +246,14 @@
   }
   else
   {
-    new_width = tmp_win->frame_width;
 #ifdef WINDOWSHADE
     if (tmp_win->buttons & WSHADE)
 	new_height = tmp_win->orig_ht;
     else
 #endif
-    new_height = tmp_win->frame_height;
+        new_height = tmp_win->frame_height;
+    new_width = tmp_win->frame_width;
+
     new_x = tmp_win->frame_x;
     new_y = tmp_win->frame_y;
     if(val1 >0)
@@ -263,6 +266,14 @@
       new_height = val2*val2_unit/100-2;
       new_y = 0;
     }
+    if (val2 < 0)
+    {
+      MaximizeHeight(tmp_win, new_width, new_x, &new_height, &new_y);
+    }
+    if (val1 < 0)
+    {
+      MaximizeWidth(tmp_win, &new_width, &new_x, new_height, new_y);
+    }
     if((val1==0)&&(val2==0))
     {
       new_x = 0;
@@ -280,6 +291,96 @@
     SetupFrame(tmp_win,new_x,new_y,new_width,new_height,TRUE,False);
     /*   SetBorder(tmp_win,Scr.Hilite == tmp_win,True,True,None);*/
   }
+}
+
+void MaximizeHeight(FvwmWindow *win, int win_width, int win_x, int *win_height, int *win_y) {
+    FvwmWindow *cwin;
+    int x11, x12, x21, x22;
+    int y11, y12, y21, y22;
+    int new_y1, new_y2;
+
+    x11 = win_x;             /* Start x */
+    y11 = *win_y;            /* Start y */
+    x12 = x11 + win_width;   /* End x   */
+    y12 = y11 + *win_height; /* End y   */
+    new_y1 = 0;
+    new_y2 = Scr.MyDisplayHeight;
+
+    for (cwin = Scr.FvwmRoot.next; cwin != NULL; cwin = cwin->next) {
+        if ((cwin == win) ||
+                ((cwin->Desk != win->Desk) && (!(cwin->flags & STICKY)))) {
+                    continue;
+        }
+        if (cwin->flags & ICONIFIED) {
+            if(cwin->icon_w == None || cwin->flags & ICON_UNMAPPED)
+                continue;
+            x21 = cwin->icon_x_loc;
+            y21 = cwin->icon_y_loc;
+            x22 = x21 + cwin->icon_p_width;
+            y22 = y21 + cwin->icon_p_height + cwin->icon_w_height;
+        } else {
+            x21 = cwin->frame_x;
+            y21 = cwin->frame_y;
+            x22 = x21 + cwin->frame_width;
+            y22 = y21 + cwin->frame_height;
+        }
+
+        /* Are they in the same X space? */
+        if (!((x22 <= x11) || (x21 >= x12))) {
+            if ((y22 <= y11) && (y22 >= new_y1)) {
+                new_y1 = y22;
+            } else if ((y12 <= y21) && (new_y2 >= y21)) {
+                new_y2 = y21;
+            }
+        }
+    }
+    *win_height = new_y2 - new_y1;
+    *win_y = new_y1;
+}
+
+void MaximizeWidth(FvwmWindow *win, int *win_width, int *win_x, int win_height, int win_y) {
+    FvwmWindow *cwin;
+    int x11, x12, x21, x22;
+    int y11, y12, y21, y22;
+    int new_x1, new_x2;
+
+    x11 = *win_x;            /* Start x */
+    y11 = win_y;             /* Start y */
+    x12 = x11 + *win_width;  /* End x   */
+    y12 = y11 + win_height;  /* End y   */
+    new_x1 = 0;
+    new_x2 = Scr.MyDisplayWidth;
+
+    for (cwin = Scr.FvwmRoot.next; cwin != NULL; cwin = cwin->next) {
+        if ((cwin == win) ||
+                ((cwin->Desk != win->Desk) && (!(cwin->flags & STICKY)))) {
+                    continue;
+        }
+        if (cwin->flags & ICONIFIED) {
+            if(cwin->icon_w == None || cwin->flags & ICON_UNMAPPED)
+                continue;
+            x21 = cwin->icon_x_loc;
+            y21 = cwin->icon_y_loc;
+            x22 = x21 + cwin->icon_p_width;
+            y22 = y21 + cwin->icon_p_height + cwin->icon_w_height;
+        } else {
+            x21 = cwin->frame_x;
+            y21 = cwin->frame_y;
+            x22 = x21 + cwin->frame_width;
+            y22 = y21 + cwin->frame_height;
+        }
+
+        /* Are they in the same Y space? */
+        if (!((y22 <= y11) || (y21 >= y12))) {
+            if ((x22 <= x11) && (x22 >= new_x1)) {
+                new_x1 = x22;
+            } else if ((x12 <= x21) && (new_x2 >= x21)) {
+                new_x2 = x21;
+            }
+        }
+    }
+    *win_width  = new_x2 - new_x1;
+    *win_x = new_x1;
 }
 
 #ifdef WINDOWSHADE
Index: fvwm/fvwm2.1
===================================================================
RCS file: /home/cvs/fvwm/fvwm/fvwm/fvwm2.1,v
retrieving revision 1.79
diff -u -r1.79 fvwm2.1
--- fvwm/fvwm2.1	1999/03/20 22:43:58	1.79
+++ fvwm/fvwm2.1	1999/03/20 23:18:45
@@ -1559,9 +1559,12 @@
 expressed as percentage of a full screen, the user can control the new
 size of the window.  If horizontal is greater than 0 then the
 horizontal dimension of the window will be set to
-horizontal*screen_width/100.  The vertical resizing is similar.  For
-example, the following will add a title-bar button to switch a window
-to the full vertical size of the screen:
+horizontal*screen_width/100.  If horizontal is -1, it will maximize to
+current available space until finding any obstacle.  The vertical resizing
+is similar.  If both horizontal and vertical values are -1, it will expand
+horizontally first, then vertically to find space.  For example, the
+following will add a title-bar button to switch a window to the full
+vertical size of the screen:
 .EX
 Mouse 0 4 A Maximize 0 100
 .EE
@@ -1573,6 +1576,11 @@
 .EX
 Mouse 0 4 A Maximize 50 50
 .EE
+To expand a window horizontally until any other window is found:
+.EX
+Mouse 0 4 A Maximize 0 -1
+.EE
+
 Values larger than 100 can be used with caution.
 
 If the letter "p" is appended to each coordinate (horizontal and/or

---

From: Matthias Clasen <[email-masked]>
Date: Sun, 21 Mar 1999 01:43:01 +0100

Nice patch, I like it!

Comments:

With the recent move from numeric arguments to strings for the
toggling arguments, wouldn't it be more reasonable to use 
a string like "available" instead of the rather arbitrary -1.
I also seem to remember that there is a note in the TODO file
about using negative arguments for something else.

I guess we need some options to influence which windows are 
obstructions to maximization. Things like: ignore lower layers.
But it would also be useful to maximize "under" some clients in
higher layers (for eg a clock), so we might also want to mark
windows for this with a style option like 
"MaximizeUnder/DontMaximizeUnder".
"MaximizeOver/DontMaximizeOver" might also be useful

But the patch still won't help with the Gnome panel, since it
is override-redirect, no? How does Enlightenment deal with that?
(probably with some quick-and-dirty root property blessed as a 
 Gnome wm hint?!)

Matthias

PS Speaking about maximization, I notice that with current cvs
the maximize title button stays depressed after unmaximizing. 

-- 
Matthias Clasen, 
Tel. 0761/203-5606
Email: [email-masked]
Mathematisches Institut, Albert-Ludwigs-Universitaet Freiburg
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
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: Sun, 21 Mar 1999 14:18:36 +0100

> about using negative arguments for something else.

Yes, a string argument would be much better, even though parsing
gets a bit more difficult.

Bye

Dominik

--
Dominik Vogt, [email-masked]
Reply-To: [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
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: Mon, 22 Mar 1999 23:37:28 +0100

> been able to make it freak out yet.. (only in e 8)

Hey, this one is great! I can run under different resolutions and
still have my windows where I want them. There is a bug however:

The feature does not work if applied to windows on a different
than the current page. That should really be fixed. If you do
that, please remember to consider 'sticky' windows too.

Bye

Dominik ^_^

P.S.: The patch is already in CVS.

---

From: Matthias Clasen <[email-masked]>
Date: Tue, 23 Mar 1999 00:21:09 +0100

> that, please remember to consider 'sticky' windows too.

But Maximize without the patch doesn't work on offscreen windows either.
It always moves them to the current page.

Matthias

---

From: Dominik Vogt <[email-masked]>
Date: Tue, 23 Mar 1999 10:04:05 +0100

> It always moves them to the current page.

Eh? Didn't you fix this a while ago?

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.fvwm.org/>.
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: Matthias Clasen <[email-masked]>
Date: Tue, 23 Mar 1999 11:05:48 +0100

> Eh? Didn't you fix this a while ago?

That was pre-2.2. Obviously, the fix didn't get in CVS up to now.
I'll investigate later.

---

From: Tomas Ogren <[email-masked]>
Date: Tue, 30 Mar 1999 23:09:22 +0200

On 21 March, 1999 - Matthias Clasen sent me these 1,2K bytes:

[...]
> (probably with some quick-and-dirty root property blessed as a 

I just tried with the gnome-hints, both smart window placement and
"funky maximize" sees the panel and avoids it as any other window.
FvwmPager sees it too..

There seems to be some issues when you fiddle some when both fvwm and
gnome pagers are running..

/Tomas