From cbfe71e15a11f7fcc9dc919274ef8c204b6b1a16 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20L=C3=BCbking?= <thomas.luebking@gmail.com>
Date: Mon, 16 Sep 2013 16:26:21 +0200
Subject: [PATCH] pack to client, not deco

this makes packing following the snapping behavior

REVIEW: 112807
---
 kwin/client.cpp    |  2 +-
 kwin/client.h      |  2 +-
 kwin/placement.cpp | 29 +++++++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/kwin/client.cpp b/kwin/client.cpp
index e8e20d5..4b88f22 100644
--- a/kwin/client.cpp
+++ b/kwin/client.cpp
@@ -2430,7 +2430,7 @@ QRect Client::decorationRect() const
     }
 }
 
-KDecorationDefines::Position Client::titlebarPosition()
+KDecorationDefines::Position Client::titlebarPosition() const
 {
     Position titlePos = PositionCenter; // PositionTop is returned by the default implementation
                                         // this will hint errors in the metaobject usage ;-)
diff --git a/kwin/client.h b/kwin/client.h
index 40811f2..a2b3365 100644
--- a/kwin/client.h
+++ b/kwin/client.h
@@ -603,7 +603,7 @@ public:
 
     bool decorationHasAlpha() const;
 
-    Position titlebarPosition();
+    Position titlebarPosition() const;
 
     enum CoordinateMode {
         DecorationRelative, // Relative to the top left corner of the decoration
diff --git a/kwin/placement.cpp b/kwin/placement.cpp
index 493ae15..2f5f222 100644
--- a/kwin/placement.cpp
+++ b/kwin/placement.cpp
@@ -33,6 +33,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include "client.h"
 #include "options.h"
 #include "rules.h"
+#include "screens.h"
 #endif
 
 namespace KWin
@@ -836,6 +837,13 @@ int Workspace::packPositionLeft(const Client* cl, int oldx, bool left_edge) cons
     if (oldx <= newx)   // try another Xinerama screen
         newx = clientArea(MaximizeArea,
                           QPoint(cl->geometry().left() - 1, cl->geometry().center().y()), cl->desktop()).left();
+    if (cl->titlebarPosition() != KDecorationDefines::PositionLeft) {
+        QRect geo = cl->geometry();
+        int rgt = newx - cl->clientPos().x();
+        geo.moveRight(rgt);
+        if (screens()->intersecting(geo) < 2)
+            newx = rgt;
+    }
     if (oldx <= newx)
         return oldx;
     for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) {
@@ -856,6 +864,13 @@ int Workspace::packPositionRight(const Client* cl, int oldx, bool right_edge) co
     if (oldx >= newx)   // try another Xinerama screen
         newx = clientArea(MaximizeArea,
                           QPoint(cl->geometry().right() + 1, cl->geometry().center().y()), cl->desktop()).right();
+    if (cl->titlebarPosition() != KDecorationDefines::PositionRight) {
+        QRect geo = cl->geometry();
+        int rgt = newx + cl->width() - (cl->clientSize().width() + cl->clientPos().x());
+        geo.moveRight(rgt);
+        if (screens()->intersecting(geo) < 2)
+            newx = rgt;
+    }
     if (oldx >= newx)
         return oldx;
     for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) {
@@ -876,6 +891,13 @@ int Workspace::packPositionUp(const Client* cl, int oldy, bool top_edge) const
     if (oldy <= newy)   // try another Xinerama screen
         newy = clientArea(MaximizeArea,
                           QPoint(cl->geometry().center().x(), cl->geometry().top() - 1), cl->desktop()).top();
+    if (cl->titlebarPosition() != KDecorationDefines::PositionTop) {
+        QRect geo = cl->geometry();
+        int top = newy - cl->clientPos().y();
+        geo.moveTop(top);
+        if (screens()->intersecting(geo) < 2)
+            newy = top;
+    }
     if (oldy <= newy)
         return oldy;
     for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) {
@@ -896,6 +918,13 @@ int Workspace::packPositionDown(const Client* cl, int oldy, bool bottom_edge) co
     if (oldy >= newy)   // try another Xinerama screen
         newy = clientArea(MaximizeArea,
                           QPoint(cl->geometry().center().x(), cl->geometry().bottom() + 1), cl->desktop()).bottom();
+    if (cl->titlebarPosition() != KDecorationDefines::PositionBottom) {
+        QRect geo = cl->geometry();
+        int btm = newy + cl->height() - (cl->clientSize().height() + cl->clientPos().y());
+        geo.moveBottom(btm);
+        if (screens()->intersecting(geo) < 2)
+            newy = btm;
+    }
     if (oldy >= newy)
         return oldy;
     for (ClientList::ConstIterator it = clients.constBegin(), end = clients.constEnd(); it != end; ++it) {
-- 
2.2.1

