Merge Window::minimize and Window::unminimize

Code of Window::minimize() and Window::unminimize() is mostly the same
with the exception of some state checks, so merge the two to tidy the
code.
This commit is contained in:
Vlad Zahorodnii 2023-03-07 12:45:02 +02:00
parent 4bc8cd6c54
commit 0c0605abb9
14 changed files with 51 additions and 78 deletions

View file

@ -146,14 +146,14 @@ void MinimizeAnimationTest::testMinimizeUnminimize()
QVERIFY(!effect->isActive());
// Start the minimize animation.
window->minimize();
window->setMinimized(true);
QVERIFY(effect->isActive());
// Eventually, the animation will be complete.
QTRY_VERIFY(!effect->isActive());
// Start the unminimize animation.
window->unminimize();
window->setMinimized(false);
QVERIFY(effect->isActive());
// Eventually, the animation will be complete.

View file

@ -199,10 +199,10 @@ void ScriptedEffectsTest::testEffectsHandler()
waitFor("stackingOrder - 1 WindowA");
// windowMinimsed
c->minimize();
c->setMinimized(true);
waitFor("windowMinimized - WindowA");
c->unminimize();
c->setMinimized(false);
waitFor("windowUnminimized - WindowA");
surface.reset();

View file

@ -169,11 +169,11 @@ void TestIdleInhibition::testDontInhibitWhenMinimized()
QCOMPARE(input()->idleInhibitors(), QList<Window *>{window});
// Minimize the window, the idle inhibitor object should not be honored.
window->minimize();
window->setMinimized(true);
QCOMPARE(input()->idleInhibitors(), QList<Window *>{});
// Unminimize the window, the idle inhibitor object should be honored back again.
window->unminimize();
window->setMinimized(false);
QCOMPARE(input()->idleInhibitors(), QList<Window *>{window});
// Destroy the test window.

View file

@ -1527,7 +1527,7 @@ void TestXdgShellWindowRules::testMinimizeApply()
QVERIFY(m_window->isMinimized());
// We should still be able to unminimize the window.
m_window->unminimize();
m_window->setMinimized(false);
QVERIFY(!m_window->isMinimized());
// If we re-open the window, it should be minimized back again.
@ -1548,7 +1548,7 @@ void TestXdgShellWindowRules::testMinimizeRemember()
QVERIFY(!m_window->isMinimized());
// Minimize the window.
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
// If we open the window again, it should be minimized.
@ -1569,7 +1569,7 @@ void TestXdgShellWindowRules::testMinimizeForce()
QVERIFY(!m_window->isMinimized());
// Any attempt to minimize the window should fail.
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(!m_window->isMinimized());
// If we re-open the window, the minimized state should still be forced.
@ -1577,7 +1577,7 @@ void TestXdgShellWindowRules::testMinimizeForce()
createTestWindow();
QVERIFY(!m_window->isMinimizable());
QVERIFY(!m_window->isMinimized());
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(!m_window->isMinimized());
destroyTestWindow();
@ -1596,7 +1596,7 @@ void TestXdgShellWindowRules::testMinimizeApplyNow()
QVERIFY(m_window->isMinimized());
// One is still able to unminimize the window.
m_window->unminimize();
m_window->setMinimized(false);
QVERIFY(!m_window->isMinimized());
// The rule should not be applied again.
@ -1616,7 +1616,7 @@ void TestXdgShellWindowRules::testMinimizeForceTemporarily()
QVERIFY(!m_window->isMinimized());
// Any attempt to minimize the window should fail until the window is closed.
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(!m_window->isMinimized());
// The rule should be discarded when the window is closed.
@ -1624,7 +1624,7 @@ void TestXdgShellWindowRules::testMinimizeForceTemporarily()
createTestWindow();
QVERIFY(m_window->isMinimizable());
QVERIFY(!m_window->isMinimized());
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
destroyTestWindow();
@ -2257,7 +2257,7 @@ void TestXdgShellWindowRules::testShortcutDontAffect()
createTestWindow();
QCOMPARE(m_window->shortcut(), QKeySequence());
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
// If we press the window shortcut, nothing should happen.
@ -2285,7 +2285,7 @@ void TestXdgShellWindowRules::testShortcutApply()
QSignalSpy minimizedChangedSpy(m_window, &Window::minimizedChanged);
quint32 timestamp = 1;
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_1}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2299,7 +2299,7 @@ void TestXdgShellWindowRules::testShortcutApply()
// One can also change the shortcut.
m_window->setShortcut(QStringLiteral("Ctrl+Alt+2"));
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_2}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2311,7 +2311,7 @@ void TestXdgShellWindowRules::testShortcutApply()
QVERIFY(!m_window->isMinimized());
// The old shortcut should do nothing.
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2344,7 +2344,7 @@ void TestXdgShellWindowRules::testShortcutRemember()
QSignalSpy minimizedChangedSpy(m_window, &Window::minimizedChanged);
quint32 timestamp = 1;
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_1}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2358,7 +2358,7 @@ void TestXdgShellWindowRules::testShortcutRemember()
// Change the window shortcut to Ctrl+Alt+2.
m_window->setShortcut(QStringLiteral("Ctrl+Alt+2"));
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_2}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2391,7 +2391,7 @@ void TestXdgShellWindowRules::testShortcutForce()
QSignalSpy minimizedChangedSpy(m_window, &Window::minimizedChanged);
quint32 timestamp = 1;
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_1}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2405,7 +2405,7 @@ void TestXdgShellWindowRules::testShortcutForce()
// Any attempt to change the window shortcut should not succeed.
m_window->setShortcut(QStringLiteral("Ctrl+Alt+2"));
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_1}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2437,7 +2437,7 @@ void TestXdgShellWindowRules::testShortcutApplyNow()
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_1}));
QSignalSpy minimizedChangedSpy(m_window, &Window::minimizedChanged);
quint32 timestamp = 1;
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2451,7 +2451,7 @@ void TestXdgShellWindowRules::testShortcutApplyNow()
// Assign a different shortcut.
m_window->setShortcut(QStringLiteral("Ctrl+Alt+2"));
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_2}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2481,7 +2481,7 @@ void TestXdgShellWindowRules::testShortcutForceTemporarily()
QSignalSpy minimizedChangedSpy(m_window, &Window::minimizedChanged);
quint32 timestamp = 1;
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_1}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);
@ -2495,7 +2495,7 @@ void TestXdgShellWindowRules::testShortcutForceTemporarily()
// Any attempt to change the window shortcut should not succeed.
m_window->setShortcut(QStringLiteral("Ctrl+Alt+2"));
QCOMPARE(m_window->shortcut(), (QKeySequence{Qt::CTRL | Qt::ALT | Qt::Key_1}));
m_window->minimize();
m_window->setMinimized(true);
QVERIFY(m_window->isMinimized());
Test::keyboardKeyPressed(KEY_LEFTCTRL, timestamp++);
Test::keyboardKeyPressed(KEY_LEFTALT, timestamp++);

View file

@ -307,7 +307,7 @@ void TestXdgShellWindow::testMinimizeActiveWindow()
QVERIFY(window->isMinimized());
// unminimize again
window->unminimize();
window->setMinimized(false);
QVERIFY(!window->isMinimized());
QVERIFY(!window->isActive());
QVERIFY(window->wantsInput());
@ -905,12 +905,12 @@ void TestXdgShellWindow::testMinimizeWindowWithTransients()
QVERIFY(window->hasTransient(transient, false));
// minimize the main window, the transient should be minimized as well
window->minimize();
window->setMinimized(true);
QVERIFY(window->isMinimized());
QVERIFY(transient->isMinimized());
// unminimize the main window, the transient should be unminimized as well
window->unminimize();
window->setMinimized(false);
QVERIFY(!window->isMinimized());
QVERIFY(!transient->isMinimized());
}

View file

@ -309,7 +309,7 @@ void Workspace::activateWindow(Window *window, bool force)
}
#endif
if (window->isMinimized()) {
window->unminimize();
window->setMinimized(false);
}
// ensure the window is really visible - could eg. be a hidden utility window, see bug #348083

View file

@ -156,10 +156,14 @@ DELEGATE(requestToggleKeepBelow, KeepBelowOp)
}
DELEGATE(requestContextHelp, showContextHelp)
DELEGATE(requestMinimize, minimize)
#undef DELEGATE
void DecoratedClientImpl::requestMinimize()
{
m_window->setMinimized(true);
}
void DecoratedClientImpl::requestClose()
{
QMetaObject::invokeMethod(m_window, &Window::closeWindow, Qt::QueuedConnection);

View file

@ -2245,14 +2245,14 @@ void EffectWindowImpl::elevate(bool elevate)
void EffectWindowImpl::minimize()
{
if (m_window->isClient()) {
m_window->minimize();
m_window->setMinimized(true);
}
}
void EffectWindowImpl::unminimize()
{
if (m_window->isClient()) {
m_window->unminimize();
m_window->setMinimized(false);
}
}

View file

@ -524,7 +524,7 @@ bool X11Window::mapRequestEvent(xcb_map_request_event_t *e)
}
// also copied in clientMessage()
if (isMinimized()) {
unminimize();
setMinimized(false);
}
if (isShade()) {
setShade(ShadeNone);
@ -590,7 +590,7 @@ void X11Window::clientMessageEvent(xcb_client_message_event_t *e)
// WM_STATE
if (e->type == atoms->wm_change_state) {
if (e->data.data32[0] == XCB_ICCCM_WM_STATE_ICONIC) {
minimize();
setMinimized(true);
}
return;
}

View file

@ -1244,7 +1244,7 @@ void Workspace::performWindowOperation(Window *window, Options::WindowOperation
takeActivity(window, ActivityFocus | ActivityRaise);
break;
case Options::MinimizeOp:
window->minimize();
window->setMinimized(true);
break;
case Options::ShadeOp:
window->performMouseCommand(Options::MouseShade, Cursors::self()->mouse()->pos());

View file

@ -1294,33 +1294,16 @@ bool Window::titlebarPositionUnderMouse() const
void Window::setMinimized(bool set)
{
set ? minimize() : unminimize();
}
void Window::minimize()
{
if (!isMinimizable() || isMinimized()) {
const bool effectiveSet = rules()->checkMinimize(set);
if (m_minimized == effectiveSet) {
return;
}
m_minimized = true;
doMinimize();
updateWindowRules(Rules::Minimize);
Q_EMIT minimizedChanged();
}
void Window::unminimize()
{
if (!isMinimized()) {
if (effectiveSet && !isMinimizable()) {
return;
}
if (rules()->checkMinimize(false)) {
return;
}
m_minimized = false;
m_minimized = effectiveSet;
doMinimize();
updateWindowRules(Rules::Minimize);
@ -2212,11 +2195,7 @@ void Window::setupWindowManagementInterface()
setFullScreen(set, false);
});
connect(w, &PlasmaWindowInterface::minimizedRequested, this, [this](bool set) {
if (set) {
minimize();
} else {
unminimize();
}
setMinimized(set);
});
connect(w, &PlasmaWindowInterface::maximizedRequested, this, [this](bool set) {
maximize(set ? MaximizeFull : MaximizeRestore);
@ -2418,7 +2397,7 @@ bool Window::performMouseCommand(Options::MouseCommand cmd, const QPointF &globa
maximize(MaximizeRestore);
break;
case Options::MouseMinimize:
minimize();
setMinimized(true);
break;
case Options::MouseAbove: {
StackingUpdatesBlocker blocker(workspace());
@ -4408,12 +4387,7 @@ void Window::applyWindowRules()
setOnActivities(activities());
// Type
maximize(requestedMaximizeMode());
// Minimize : functions don't check, and there are two functions
if (client_rules->checkMinimize(isMinimized())) {
minimize();
} else {
unminimize();
}
setMinimized(isMinimized());
setShade(shadeMode());
setOriginalSkipTaskbar(skipTaskbar());
setSkipPager(skipPager());

View file

@ -974,11 +974,6 @@ public:
QStringList desktopIds() const;
void setMinimized(bool set);
/**
* Minimizes this window plus its transients
*/
void minimize();
void unminimize();
bool isMinimized() const
{
return m_minimized;

View file

@ -2144,28 +2144,28 @@ void Workspace::updateMinimizedOfTransients(Window *window)
}
// but to keep them to eg. watch progress or whatever
if (!(*it)->isMinimized()) {
(*it)->minimize();
(*it)->setMinimized(true);
updateMinimizedOfTransients((*it));
}
}
if (window->isModal()) { // if a modal dialog is minimized, minimize its mainwindow too
const auto windows = window->mainWindows();
for (Window *main : std::as_const(windows)) {
main->minimize();
main->setMinimized(true);
}
}
} else {
// else unmiminize the transients
for (auto it = window->transients().constBegin(); it != window->transients().constEnd(); ++it) {
if ((*it)->isMinimized()) {
(*it)->unminimize();
(*it)->setMinimized(false);
updateMinimizedOfTransients((*it));
}
}
if (window->isModal()) {
const auto windows = window->mainWindows();
for (Window *main : std::as_const(windows)) {
main->unminimize();
main->setMinimized(false);
}
}
}

View file

@ -1223,7 +1223,7 @@ void XdgToplevelWindow::handleUnfullscreenRequested()
void XdgToplevelWindow::handleMinimizeRequested()
{
minimize();
setMinimized(true);
}
void XdgToplevelWindow::handleTransientForChanged()