]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix focus changing when unminimising on X11
authorFelix Ernst <felixernst@zohomail.eu>
Sat, 4 Jan 2025 17:58:22 +0000 (18:58 +0100)
committerFelix Ernst <felixernst@kde.org>
Mon, 6 Jan 2025 15:09:14 +0000 (15:09 +0000)
In f220e3b0783a24a6c7195f170297cf4b12a29d85 I made the keyboard
focus move to the places and terminal panel whenever they are
toggled visible. Unfortunately the QDockWidget::visibilityChanged()
signal is also emitted (at least on X11) simply when the window
containing that panel is minimized or restored. This commit
overrides the QDockWidget::event() method to ignore such
spontaneous show or hide events so QDockWidget won't emit the
visibilityChanged() signal then.

BUG: 497803

src/dolphindockwidget.cpp
src/dolphindockwidget.h

index 930c38e355d8d6c7151e46a3bc8ca6d679067d80..5e79e03163c530439edc314f58bb134eb83969f7 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "dolphindockwidget.h"
 
+#include <QEvent>
 #include <QStyle>
 
 namespace
@@ -77,5 +78,21 @@ bool DolphinDockWidget::isLocked() const
     return m_locked;
 }
 
+bool DolphinDockWidget::event(QEvent *event)
+{
+    switch (event->type()) {
+    case QEvent::Show:
+    case QEvent::Hide:
+        if (event->spontaneous()) {
+            // The Dolphin window has been minimized or restored. We do not want this to be interpreted like a user was toggling the visibility of this widget.
+            // We return here so no QDockWidget::visibilityChanged() signal is emitted. This does not seem to happen either way on Wayland.
+            return true;
+        }
+        [[fallthrough]];
+    default:
+        return QDockWidget::event(event);
+    }
+}
+
 #include "dolphindockwidget.moc"
 #include "moc_dolphindockwidget.cpp"
index 114a11b55f6b4b9c9e94ef805e1ff8d3371560c6..127525b5aa602f5f56cd4c3a39520764e783e1df 100644 (file)
@@ -27,6 +27,12 @@ public:
     void setLocked(bool lock);
     bool isLocked() const;
 
+protected:
+    /**
+     * Make sure we do not emit QDockWidget::visibilityChanged() signals whenever Dolphin's window is minimized or restored.
+     */
+    bool event(QEvent *event) override;
+
 private:
     bool m_locked;
     QWidget *m_dockTitleBar;