Split system drag to a separate method in PiP

This commit is contained in:
Ilya Fedin 2020-10-19 05:23:30 +04:00 committed by John Preston
parent 44c24f9fff
commit b8018f5a7f
2 changed files with 28 additions and 18 deletions

View file

@ -706,8 +706,23 @@ void PipPanel::mouseMoveEvent(QMouseEvent *e) {
if (!_dragState if (!_dragState
&& (point - _pressPoint).manhattanLength() > distance && (point - _pressPoint).manhattanLength() > distance
&& !_dragDisabled) { && !_dragDisabled) {
_dragState = _pressState;
updateDecorations();
_dragStartGeometry = geometry().marginsRemoved(_padding);
}
if (_dragState) {
if (Platform::IsWayland()) { if (Platform::IsWayland()) {
const auto stateEdges = RectPartToQtEdges(*_pressState); startSystemDrag();
} else {
processDrag(point);
}
}
}
void PipPanel::startSystemDrag() {
Expects(_dragState.has_value());
const auto stateEdges = RectPartToQtEdges(*_dragState);
if (stateEdges) { if (stateEdges) {
if (!Platform::StartSystemResize(windowHandle(), stateEdges)) { if (!Platform::StartSystemResize(windowHandle(), stateEdges)) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED
@ -721,15 +736,6 @@ void PipPanel::mouseMoveEvent(QMouseEvent *e) {
#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED #endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED
} }
} }
return;
}
_dragState = _pressState;
updateDecorations();
_dragStartGeometry = geometry().marginsRemoved(_padding);
}
if (_dragState) {
processDrag(point);
}
} }
void PipPanel::processDrag(QPoint point) { void PipPanel::processDrag(QPoint point) {
@ -783,6 +789,9 @@ void PipPanel::finishDrag(QPoint point) {
const auto position = pos(); const auto position = pos();
const auto clamped = [&] { const auto clamped = [&] {
auto result = position; auto result = position;
if (Platform::IsWayland()) {
return result;
}
if (result.x() > screen.x() + screen.width() - inner.width()) { if (result.x() > screen.x() + screen.width() - inner.width()) {
result.setX(screen.x() + screen.width() - inner.width()); result.setX(screen.x() + screen.width() - inner.width());
} }

View file

@ -83,6 +83,7 @@ private:
void setPositionOnScreen(Position position, QRect available); void setPositionOnScreen(Position position, QRect available);
QScreen *myScreen() const; QScreen *myScreen() const;
void startSystemDrag();
void processDrag(QPoint point); void processDrag(QPoint point);
void finishDrag(QPoint point); void finishDrag(QPoint point);
void updatePositionAnimated(); void updatePositionAnimated();