From 60d36c0753254bf26ca01678b14ed8b7d770848a Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 19 Mar 2024 14:12:25 +0200 Subject: [PATCH] Move X11Window::findModal() to Window and remove boolean trap --- src/internalwindow.cpp | 5 ----- src/internalwindow.h | 1 - src/waylandwindow.cpp | 5 ----- src/waylandwindow.h | 1 - src/window.cpp | 16 ++++++++++++++++ src/window.h | 3 +-- src/x11window.cpp | 16 ---------------- src/x11window.h | 1 - 8 files changed, 17 insertions(+), 31 deletions(-) diff --git a/src/internalwindow.cpp b/src/internalwindow.cpp index 1f6cdc8de0..9894bf2398 100644 --- a/src/internalwindow.cpp +++ b/src/internalwindow.cpp @@ -260,11 +260,6 @@ void InternalWindow::moveResizeInternal(const QRectF &rect, MoveResizeMode mode) } } -Window *InternalWindow::findModal(bool allow_itself) -{ - return nullptr; -} - bool InternalWindow::takeFocus() { return false; diff --git a/src/internalwindow.h b/src/internalwindow.h index c60e44c9df..e039b13dad 100644 --- a/src/internalwindow.h +++ b/src/internalwindow.h @@ -54,7 +54,6 @@ public: bool isLockScreen() const override; bool isOutline() const override; QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &size) override; - Window *findModal(bool allow_itself = false) override; bool takeFocus() override; void setNoBorder(bool set) override; void invalidateDecoration() override; diff --git a/src/waylandwindow.cpp b/src/waylandwindow.cpp index e95c2273a2..614119bab3 100644 --- a/src/waylandwindow.cpp +++ b/src/waylandwindow.cpp @@ -83,11 +83,6 @@ bool WaylandWindow::isLocalhost() const return true; } -Window *WaylandWindow::findModal(bool allow_itself) -{ - return nullptr; -} - QRectF WaylandWindow::resizeWithChecks(const QRectF &geometry, const QSizeF &size) { const QRectF area = workspace()->clientArea(WorkArea, this, geometry.center()); diff --git a/src/waylandwindow.h b/src/waylandwindow.h index 7ba82b0e34..d30ef620be 100644 --- a/src/waylandwindow.h +++ b/src/waylandwindow.h @@ -24,7 +24,6 @@ public: bool isClient() const override; bool isLockScreen() const override; bool isLocalhost() const override; - Window *findModal(bool allow_itself = false) override; QRectF resizeWithChecks(const QRectF &geometry, const QSizeF &size) override; void killWindow() override; QString windowRole() const override; diff --git a/src/window.cpp b/src/window.cpp index b76b8692e2..259c1cef70 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -2277,6 +2277,22 @@ bool Window::isModal() const return m_modal; } +Window *Window::findModal() const +{ + for (Window *transient : m_transients) { + if (transient->isDeleted()) { + continue; + } + if (transient->isModal()) { + return transient; + } + if (Window *modal = transient->findModal()) { + return modal; + } + } + return nullptr; +} + bool Window::isTransient() const { return false; diff --git a/src/window.h b/src/window.h index 03bcc8e76a..36ea2cc773 100644 --- a/src/window.h +++ b/src/window.h @@ -938,8 +938,7 @@ public: void setHidden(bool hidden); bool isHiddenByShowDesktop() const; void setHiddenByShowDesktop(bool hidden); - // TODO: remove boolean trap - virtual Window *findModal(bool allow_itself = false) = 0; + Window *findModal() const; virtual bool isTransient() const; /** * @returns Whether there is a hint available to place the Window on it's parent, default @c false. diff --git a/src/x11window.cpp b/src/x11window.cpp index 0cf7bdac13..37c8862f8b 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -3476,22 +3476,6 @@ QList X11Window::mainWindows() const return result; } -Window *X11Window::findModal(bool allow_itself) -{ - if (isDeleted()) { - return nullptr; - } - for (auto it = transients().constBegin(); it != transients().constEnd(); ++it) { - if (Window *ret = (*it)->findModal(true)) { - return ret; - } - } - if (isModal() && allow_itself) { - return this; - } - return nullptr; -} - // X11Window::window_group only holds the contents of the hint, // but it should be used only to find the group, not for anything else // Argument is only when some specific group needs to be set. diff --git a/src/x11window.h b/src/x11window.h index 0ec33fb4af..af70970f98 100644 --- a/src/x11window.h +++ b/src/x11window.h @@ -117,7 +117,6 @@ public: QList mainWindows() const override; // Call once before loop , is not indirect bool hasTransient(const Window *c, bool indirect) const override; void checkTransient(xcb_window_t w); - Window *findModal(bool allow_itself = false) override; const Group *group() const override; Group *group() override; void checkGroup(Group *gr = nullptr, bool force = false);