At Sun, 7 Dec 2008 16:54:21 +0100
Gregor Best wrote:

> Maarten just made me aware that the previous patch didn't consider the clients
> border_width which might become a problem for large border sizes. I attached a
> fixed version of the previous patch.
> 

Here is a different version, this time the C-side is patched. I didn't bother
looking into what was wrong with the previous C code, instead I rewrote the
whole thing. One (minor) issue is that if you spawn a client, make it
fullscreen, move it to a different screen and undo the fullscreen, the client
is moved to the screen it was originally spawned on. This might be one of the
occasions where an additional pair of eyes might spot the issue easily.

-- 
    Gregor Best
From e4b839615667e65bf0957603a26897575d2285dd Mon Sep 17 00:00:00 2001
From: Gregor Best <[EMAIL PROTECTED]>
Date: Sun, 7 Dec 2008 18:03:36 +0100
Subject: [PATCH] screen.c: fix movetoscreen for different sized screens

Signed-off-by: Gregor Best <[EMAIL PROTECTED]>
---
 screen.c |  102 +++++++++++++++++++++----------------------------------------
 1 files changed, 35 insertions(+), 67 deletions(-)

diff --git a/screen.c b/screen.c
index 1ba0278..e3eacc0 100644
--- a/screen.c
+++ b/screen.c
@@ -309,88 +309,56 @@ screen_client_moveto(client_t *c, int new_screen, bool dotag, bool doresize)
     area_t from, to;
     bool wasvisible = client_isvisible(c, c->screen);
 
-    c->screen = new_screen;
+    if(new_screen == c->screen)
+        return;
 
     if(dotag && !c->issticky)
     {
         /* remove old tags */
         for(i = 0; i < old_tags->len; i++)
             untag_client(c, old_tags->tab[i]);
+    }
 
+    c->screen = new_screen;
+    
+    if(dotag && !c->issticky)
+    {
         /* add new tags */
         for(i = 0; i < new_tags->len; i++)
             if(new_tags->tab[i]->selected)
                 tag_client(c, new_tags->tab[i]);
     }
 
-    /* move and resize the windows */
-    if(doresize && old_screen != c->screen)
+    from = screen_area_get(old_screen, NULL, NULL, false);
+    to = screen_area_get(c->screen, NULL, NULL, false);
+
+    area_t new_geometry = c->geometry;
+
+    if(c->isfullscreen)
     {
-        area_t new_geometry, new_f_geometry;
-        new_f_geometry = c->geometry;
-
-        to = screen_area_get(c->screen,
-                             NULL, NULL, false);
-        from = screen_area_get(old_screen,
-                               NULL, NULL, false);
-
-        /* compute new coords in new screen */
-        new_f_geometry.x = (c->geometry.x - from.x) + to.x;
-        new_f_geometry.y = (c->geometry.y - from.y) + to.y;
-
-        /* check that new coords are still in the screen */
-        if(new_f_geometry.width > to.width)
-            new_f_geometry.width = to.width;
-        if(new_f_geometry.height > to.height)
-            new_f_geometry.height = to.height;
-        if(new_f_geometry.x + new_f_geometry.width >= to.x + to.width)
-            new_f_geometry.x = to.x + to.width - new_f_geometry.width - 2 * c->border;
-        if(new_f_geometry.y + new_f_geometry.height >= to.y + to.height)
-            new_f_geometry.y = to.y + to.height - new_f_geometry.height - 2 * c->border;
-
-        if(c->isfullscreen)
-        {
-            new_geometry = c->geometry;
-
-            /* compute new coords in new screen */
-            new_geometry.x = (c->geometry.x - from.x) + to.x;
-            new_geometry.y = (c->geometry.y - from.y) + to.y;
-
-            /* check that new coords are still in the screen */
-            if(new_geometry.width > to.width)
-                new_geometry.width = to.width;
-            if(new_geometry.height > to.height)
-                new_geometry.height = to.height;
-            if(new_geometry.x + new_geometry.width >= to.x + to.width)
-                new_geometry.x = to.x + to.width - new_geometry.width - 2 * c->border;
-            if(new_geometry.y + new_geometry.height >= to.y + to.height)
-                new_geometry.y = to.y + to.height - new_geometry.height - 2 * c->border;
-
-            /* compute new coords for max in new screen */
-            c->geometries.fullscreen.x = (c->geometries.fullscreen.x - from.x) + to.x;
-            c->geometries.fullscreen.y = (c->geometries.fullscreen.y - from.y) + to.y;
-
-            /* check that new coords are still in the screen */
-            if(c->geometries.fullscreen.width > to.width)
-                c->geometries.fullscreen.width = to.width;
-            if(c->geometries.fullscreen.height > to.height)
-                c->geometries.fullscreen.height = to.height;
-            if(c->geometries.fullscreen.x + c->geometries.fullscreen.width >= to.x + to.width)
-                c->geometries.fullscreen.x = to.x + to.width - c->geometries.fullscreen.width - 2 * c->border;
-            if(c->geometries.fullscreen.y + c->geometries.fullscreen.height >= to.y + to.height)
-                c->geometries.fullscreen.y = to.y + to.height - c->geometries.fullscreen.height - 2 * c->border;
-
-            client_resize(c, new_geometry, false);
-        }
-        /* move to this new coords */
-        else
-        {
-            client_resize(c, new_f_geometry, false);
-            if(wasvisible)
-                globalconf.screens[old_screen].need_arrange = true;
-            client_need_arrange(c);
-        }
+        new_geometry = to
+    }else
+    {   
+        new_geometry.x = to.x + new_geometry.x - from.x;
+        new_geometry.y = to.y + new_geometry.y - from.y;
+
+        /* resize the client if it doesn't fit the new screen */
+        if(new_geometry.width > to.width)
+           new_geometry.width = to.width - 2 * c->border;
+        if(new_geometry.height > to.height)
+           new_geometry.height = to.height - 2 * c->border;
+
+        /* make sure the client is still on the screen */
+        if(new_geometry.x + new_geometry.width > to.x + to.width)
+           new_geometry.x = to.x + to.width - new_geometry.width;
+        if(new_geometry.y + new_geometry.height > to.y + to.height)
+           new_geometry.y = to.y + to.height - new_geometry.height;
     }
+    /* move / resize the client */
+    client_resize(c, new_geometry, false);
+    if(wasvisible)
+        globalconf.screens[old_screen].need_arrange = true;
+    client_need_arrange(c);
 }
 
 /** Screen module.
-- 
1.6.0.4

Attachment: signature.asc
Description: PGP signature

Reply via email to