keep electric edges 1/3" away from the corners

BUG: 318294
FIXED: 4.11
REVIEW: 110013
This commit is contained in:
Thomas Lübking 2013-04-14 20:04:05 +02:00
parent 551c9f4c22
commit 2cc6712564
2 changed files with 35 additions and 25 deletions

View file

@ -59,7 +59,7 @@ Edge::Edge(ScreenEdges *parent)
, m_action(ElectricActionNone) , m_action(ElectricActionNone)
, m_reserved(0) , m_reserved(0)
, m_approaching(false) , m_approaching(false)
, m_lastApproachingFactor(0.0) , m_lastApproachingFactor(0)
, m_blocked(false) , m_blocked(false)
{ {
} }
@ -290,8 +290,7 @@ void Edge::setGeometry(const QRect &geometry)
int y = m_geometry.y(); int y = m_geometry.y();
int width = m_geometry.width(); int width = m_geometry.width();
int height = m_geometry.height(); int height = m_geometry.height();
// TODO: better not hard coded value const int size = m_edges->cornerOffset();
const int size = 20;
if (isCorner()) { if (isCorner()) {
if (isRight()) { if (isRight()) {
x = x - size +1; x = x - size +1;
@ -365,7 +364,7 @@ void Edge::startApproaching()
} }
m_approaching = true; m_approaching = true;
doStartApproaching(); doStartApproaching();
m_lastApproachingFactor = 0.0; m_lastApproachingFactor = 0;
emit approaching(border(), 0.0, m_approachGeometry); emit approaching(border(), 0.0, m_approachGeometry);
} }
@ -380,7 +379,7 @@ void Edge::stopApproaching()
} }
m_approaching = false; m_approaching = false;
doStopApproaching(); doStopApproaching();
m_lastApproachingFactor = 0.0; m_lastApproachingFactor = 0;
emit approaching(border(), 0.0, m_approachGeometry); emit approaching(border(), 0.0, m_approachGeometry);
} }
@ -391,42 +390,42 @@ void Edge::doStopApproaching()
void Edge::updateApproaching(const QPoint &point) void Edge::updateApproaching(const QPoint &point)
{ {
if (approachGeometry().contains(point)) { if (approachGeometry().contains(point)) {
qreal factor = 0.0; int factor = 0;
const int edgeDistance = m_edges->cornerOffset();
// manhattan length for our edge // manhattan length for our edge
const qreal cornerDistance = 40.0; const int cornerDistance = 2*edgeDistance;
const qreal edgeDistance = 20.0;
switch (border()) { switch (border()) {
case ElectricTopLeft: case ElectricTopLeft:
factor = point.manhattanLength() / cornerDistance; factor = (point.manhattanLength()<<8) / cornerDistance;
break; break;
case ElectricTopRight: case ElectricTopRight:
factor = (point - approachGeometry().topRight()).manhattanLength() / cornerDistance; factor = ((point - approachGeometry().topRight()).manhattanLength()<<8) / cornerDistance;
break; break;
case ElectricBottomRight: case ElectricBottomRight:
factor = (point - approachGeometry().bottomRight()).manhattanLength() / cornerDistance; factor = ((point - approachGeometry().bottomRight()).manhattanLength()<<8) / cornerDistance;
break; break;
case ElectricBottomLeft: case ElectricBottomLeft:
factor = (point - approachGeometry().bottomLeft()).manhattanLength() / cornerDistance; factor = ((point - approachGeometry().bottomLeft()).manhattanLength()<<8) / cornerDistance;
break; break;
case ElectricTop: case ElectricTop:
factor = qAbs(point.y() - approachGeometry().y()) / edgeDistance; factor = (qAbs(point.y() - approachGeometry().y())<<8) / edgeDistance;
break; break;
case ElectricRight: case ElectricRight:
factor = qAbs(point.x() - approachGeometry().right()) / edgeDistance; factor = (qAbs(point.x() - approachGeometry().right())<<8) / edgeDistance;
break; break;
case ElectricBottom: case ElectricBottom:
factor = qAbs(point.y() - approachGeometry().bottom()) / edgeDistance; factor = (qAbs(point.y() - approachGeometry().bottom())<<8) / edgeDistance;
break; break;
case ElectricLeft: case ElectricLeft:
factor = qAbs(point.x() - approachGeometry().x()) / edgeDistance; factor = (qAbs(point.x() - approachGeometry().x())<<8) / edgeDistance;
break; break;
default: default:
break; break;
} }
factor = 1.0 - factor; factor = 256 - factor;
if (m_lastApproachingFactor != factor) { if (m_lastApproachingFactor != factor) {
m_lastApproachingFactor = factor; m_lastApproachingFactor = factor;
emit approaching(border(), m_lastApproachingFactor, m_approachGeometry); emit approaching(border(), m_lastApproachingFactor/256.0f, m_approachGeometry);
} }
} else { } else {
stopApproaching(); stopApproaching();
@ -552,6 +551,8 @@ ScreenEdges::ScreenEdges(QObject *parent)
, m_actionBottomLeft(ElectricActionNone) , m_actionBottomLeft(ElectricActionNone)
, m_actionLeft(ElectricActionNone) , m_actionLeft(ElectricActionNone)
{ {
QWidget w;
m_cornerOffset = (w.physicalDpiX() + w.physicalDpiY() + 5) / 6;
} }
ScreenEdges::~ScreenEdges() ScreenEdges::~ScreenEdges()
@ -829,15 +830,15 @@ void ScreenEdges::createVerticalEdge(ElectricBorder border, const QRect &screen,
const int x = (border == ElectricLeft) ? screen.x() : screen.x() + screen.width() -1; const int x = (border == ElectricLeft) ? screen.x() : screen.x() + screen.width() -1;
if (isTopScreen(screen, fullArea)) { if (isTopScreen(screen, fullArea)) {
// also top most screen // also top most screen
height--; height -= m_cornerOffset;
y++; y += m_cornerOffset;
// create top left/right edge // create top left/right edge
const ElectricBorder edge = (border == ElectricLeft) ? ElectricTopLeft : ElectricTopRight; const ElectricBorder edge = (border == ElectricLeft) ? ElectricTopLeft : ElectricTopRight;
m_edges << createEdge(edge, x, screen.y(), 1, 1); m_edges << createEdge(edge, x, screen.y(), 1, 1);
} }
if (isBottomScreen(screen, fullArea)) { if (isBottomScreen(screen, fullArea)) {
// also bottom most screen // also bottom most screen
height--; height -= m_cornerOffset;
// create bottom left/right edge // create bottom left/right edge
const ElectricBorder edge = (border == ElectricLeft) ? ElectricBottomLeft : ElectricBottomRight; const ElectricBorder edge = (border == ElectricLeft) ? ElectricBottomLeft : ElectricBottomRight;
m_edges << createEdge(edge, x, screen.y() + screen.height() -1, 1, 1); m_edges << createEdge(edge, x, screen.y() + screen.height() -1, 1, 1);
@ -855,12 +856,12 @@ void ScreenEdges::createHorizontalEdge(ElectricBorder border, const QRect &scree
int width = screen.width(); int width = screen.width();
if (isLeftScreen(screen, fullArea)) { if (isLeftScreen(screen, fullArea)) {
// also left most - adjust only x and width // also left most - adjust only x and width
x++; x += m_cornerOffset;
width--; width -= m_cornerOffset;
} }
if (isRightScreen(screen, fullArea)) { if (isRightScreen(screen, fullArea)) {
// also right most edge // also right most edge
width--; width -= m_cornerOffset;
} }
const int y = (border == ElectricTop) ? screen.y() : screen.y() + screen.height() - 1; const int y = (border == ElectricTop) ? screen.y() : screen.y() + screen.height() - 1;
m_edges << createEdge(border, x, y, width, 1); m_edges << createEdge(border, x, y, width, 1);

View file

@ -106,7 +106,7 @@ private:
QPoint m_triggeredPoint; QPoint m_triggeredPoint;
QHash<QObject *, QByteArray> m_callBacks; QHash<QObject *, QByteArray> m_callBacks;
bool m_approaching; bool m_approaching;
qreal m_lastApproachingFactor; int m_lastApproachingFactor;
bool m_blocked; bool m_blocked;
}; };
@ -216,6 +216,10 @@ public:
* @param forceNoPushBack needs to be called to workaround some DnD clients, don't use unless you want to chek on a DnD event * @param forceNoPushBack needs to be called to workaround some DnD clients, don't use unless you want to chek on a DnD event
*/ */
void check(const QPoint& pos, const QDateTime &now, bool forceNoPushBack = false); void check(const QPoint& pos, const QDateTime &now, bool forceNoPushBack = false);
/**
* The (dpi dependent) length, reserved for the active corners of each edge - 1/3"
*/
int cornerOffset() const;
/** /**
* Mark the specified screen edge as reserved. This method is provided for external activation * Mark the specified screen edge as reserved. This method is provided for external activation
* like effects and scripts. When the effect/script does no longer need the edge it is supposed * like effects and scripts. When the effect/script does no longer need the edge it is supposed
@ -333,6 +337,7 @@ private:
ElectricBorderAction m_actionBottom; ElectricBorderAction m_actionBottom;
ElectricBorderAction m_actionBottomLeft; ElectricBorderAction m_actionBottomLeft;
ElectricBorderAction m_actionLeft; ElectricBorderAction m_actionLeft;
int m_cornerOffset;
KWIN_SINGLETON(ScreenEdges) KWIN_SINGLETON(ScreenEdges)
}; };
@ -449,6 +454,10 @@ inline void ScreenEdges::setConfig(KSharedConfig::Ptr config)
m_config = config; m_config = config;
} }
inline int ScreenEdges::cornerOffset() const {
return m_cornerOffset;
}
inline const QSize &ScreenEdges::cursorPushBackDistance() const inline const QSize &ScreenEdges::cursorPushBackDistance() const
{ {
return m_cursorPushBackDistance; return m_cursorPushBackDistance;