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,29 +706,35 @@ void PipPanel::mouseMoveEvent(QMouseEvent *e) {
if (!_dragState if (!_dragState
&& (point - _pressPoint).manhattanLength() > distance && (point - _pressPoint).manhattanLength() > distance
&& !_dragDisabled) { && !_dragDisabled) {
if (Platform::IsWayland()) {
const auto stateEdges = RectPartToQtEdges(*_pressState);
if (stateEdges) {
if (!Platform::StartSystemResize(windowHandle(), stateEdges)) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED
windowHandle()->startSystemResize(stateEdges);
#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED
}
} else {
if (!Platform::StartSystemMove(windowHandle())) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED
windowHandle()->startSystemMove();
#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED
}
}
return;
}
_dragState = _pressState; _dragState = _pressState;
updateDecorations(); updateDecorations();
_dragStartGeometry = geometry().marginsRemoved(_padding); _dragStartGeometry = geometry().marginsRemoved(_padding);
} }
if (_dragState) { if (_dragState) {
processDrag(point); if (Platform::IsWayland()) {
startSystemDrag();
} else {
processDrag(point);
}
}
}
void PipPanel::startSystemDrag() {
Expects(_dragState.has_value());
const auto stateEdges = RectPartToQtEdges(*_dragState);
if (stateEdges) {
if (!Platform::StartSystemResize(windowHandle(), stateEdges)) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED
windowHandle()->startSystemResize(stateEdges);
#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED
}
} else {
if (!Platform::StartSystemMove(windowHandle())) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED
windowHandle()->startSystemMove();
#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED
}
} }
} }
@ -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();