Allow maximizing the window by double clicking borders

It's a more intuitive way to maximize a window either horizontally or
vertically.

BUG: 480848
This commit is contained in:
Vlad Zahorodnii 2024-02-09 00:34:56 +02:00
parent bc62e7e094
commit d8e8f952a2
2 changed files with 27 additions and 60 deletions

View file

@ -52,10 +52,8 @@ private Q_SLOTS:
void cleanup();
void testAxis_data();
void testAxis();
void testDoubleClickOnAllDesktops_data();
void testDoubleClickOnAllDesktops();
void testDoubleClickClose();
void testDoubleTap_data();
void testDoubleTap();
void testHover();
void testPressToMove_data();
@ -211,16 +209,6 @@ void DecorationInputTest::testAxis()
QVERIFY(!window->keepAbove());
}
void DecorationInputTest::testDoubleClickOnAllDesktops_data()
{
QTest::addColumn<QPoint>("decoPoint");
QTest::addColumn<Qt::WindowFrameSection>("expectedSection");
QTest::newRow("topLeft") << QPoint(0, 0) << Qt::TopLeftSection;
QTest::newRow("top") << QPoint(250, 0) << Qt::TopSection;
QTest::newRow("topRight") << QPoint(499, 0) << Qt::TopRightSection;
}
void KWin::DecorationInputTest::testDoubleClickOnAllDesktops()
{
KConfigGroup group = kwinApp()->config()->group(QStringLiteral("Windows"));
@ -249,21 +237,6 @@ void KWin::DecorationInputTest::testDoubleClickOnAllDesktops()
PRESS;
RELEASE;
QVERIFY(!window->isOnAllDesktops());
// test top most deco pixel, BUG: 362860
window->move(QPoint(0, 0));
QFETCH(QPoint, decoPoint);
MOTION(decoPoint);
QVERIFY(input()->pointer()->decoration());
QCOMPARE(input()->pointer()->decoration()->window(), window);
QTEST(input()->pointer()->decoration()->decoration()->sectionUnderMouse(), "expectedSection");
// double click
PRESS;
RELEASE;
QVERIFY(!window->isOnAllDesktops());
PRESS;
RELEASE;
QVERIFY(window->isOnAllDesktops());
}
void DecorationInputTest::testDoubleClickClose()
@ -297,16 +270,6 @@ void DecorationInputTest::testDoubleClickClose()
window->unref();
}
void DecorationInputTest::testDoubleTap_data()
{
QTest::addColumn<QPoint>("decoPoint");
QTest::addColumn<Qt::WindowFrameSection>("expectedSection");
QTest::newRow("topLeft") << QPoint(10, 10) << Qt::TopLeftSection;
QTest::newRow("top") << QPoint(260, 10) << Qt::TopSection;
QTest::newRow("topRight") << QPoint(509, 10) << Qt::TopRightSection;
}
void KWin::DecorationInputTest::testDoubleTap()
{
KConfigGroup group = kwinApp()->config()->group(QStringLiteral("Windows"));
@ -335,23 +298,6 @@ void KWin::DecorationInputTest::testDoubleTap()
Test::touchDown(0, tapPoint, timestamp++);
Test::touchUp(0, timestamp++);
QVERIFY(!window->isOnAllDesktops());
// test top most deco pixel, BUG: 362860
//
// Not directly at (0, 0), otherwise ScreenEdgeInputFilter catches
// event before DecorationEventFilter.
window->move(QPoint(10, 10));
QFETCH(QPoint, decoPoint);
// double click
Test::touchDown(0, decoPoint, timestamp++);
QVERIFY(input()->touch()->decoration());
QCOMPARE(input()->touch()->decoration()->window(), window);
QTEST(input()->touch()->decoration()->decoration()->sectionUnderMouse(), "expectedSection");
Test::touchUp(0, timestamp++);
QVERIFY(!window->isOnAllDesktops());
Test::touchDown(0, decoPoint, timestamp++);
Test::touchUp(0, timestamp++);
QVERIFY(window->isOnAllDesktops());
}
void DecorationInputTest::testHover()

View file

@ -2759,14 +2759,37 @@ bool Window::processDecorationButtonPress(QMouseEvent *event, bool ignoreMenu)
}
// check whether it is a double click
if (event->button() == Qt::LeftButton && titlebarPositionUnderMouse()) {
if (event->button() == Qt::LeftButton) {
if (m_decoration.doubleClickTimer.isValid()) {
const qint64 interval = m_decoration.doubleClickTimer.elapsed();
m_decoration.doubleClickTimer.invalidate();
if (interval > QGuiApplication::styleHints()->mouseDoubleClickInterval()) {
m_decoration.doubleClickTimer.start(); // expired -> new first click and pot. init
} else {
Workspace::self()->performWindowOperation(this, options->operationTitlebarDblClick());
Options::WindowOperation operation;
switch (decoration()->sectionUnderMouse()) {
case Qt::TitleBarArea:
operation = options->operationTitlebarDblClick();
break;
case Qt::LeftSection:
case Qt::RightSection:
operation = Options::HMaximizeOp;
break;
case Qt::TopSection:
case Qt::BottomSection:
operation = Options::VMaximizeOp;
break;
case Qt::TopLeftSection:
case Qt::TopRightSection:
case Qt::BottomLeftSection:
case Qt::BottomRightSection:
operation = Options::MaximizeOp;
break;
default:
operation = Options::NoOp;
break;
}
workspace()->performWindowOperation(this, operation);
dontInteractiveMoveResize();
return false;
}
@ -2805,10 +2828,8 @@ bool Window::processDecorationButtonPress(QMouseEvent *event, bool ignoreMenu)
void Window::processDecorationButtonRelease(QMouseEvent *event)
{
if (isDecorated()) {
if (event->isAccepted() || !titlebarPositionUnderMouse()) {
invalidateDecorationDoubleClickTimer(); // click was for the deco and shall not init a doubleclick
}
if (event->isAccepted()) {
invalidateDecorationDoubleClickTimer(); // click was for the deco and shall not init a doubleclick
}
if (event->buttons() == Qt::NoButton) {