From a65b2c062cb0c02497d593aa535150fd23b5651c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Tue, 8 Aug 2017 07:10:55 +0200 Subject: [PATCH] Move event filtering for overlay window into an X11EventFilter Summary: The OverlayWindowX11 also inherits from X11EventFilter and performs the filtering itself. Test Plan: Compiles, not yet tested as I'm on Wayland Reviewers: #kwin, #plasma Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D7197 --- composite.cpp | 18 ------------ composite.h | 8 ------ events.cpp | 24 ---------------- .../x11/standalone/overlaywindow_x11.cpp | 28 +++++++++++++++++++ .../x11/standalone/overlaywindow_x11.h | 5 +++- 5 files changed, 32 insertions(+), 51 deletions(-) diff --git a/composite.cpp b/composite.cpp index 4c848f04d5..50791a87e8 100644 --- a/composite.cpp +++ b/composite.cpp @@ -905,17 +905,6 @@ bool Compositor::checkForOverlayWindow(WId w) const return w == m_scene->overlayWindow()->window(); } -WId Compositor::overlayWindow() const -{ - if (!hasScene()) { - return None; - } - if (!m_scene->overlayWindow()) { - return None; - } - return m_scene->overlayWindow()->window(); -} - bool Compositor::isOverlayWindowVisible() const { if (!hasScene()) { @@ -927,13 +916,6 @@ bool Compositor::isOverlayWindowVisible() const return m_scene->overlayWindow()->isVisible(); } -void Compositor::setOverlayWindowVisibility(bool visible) -{ - if (hasScene() && m_scene->overlayWindow()) { - m_scene->overlayWindow()->setVisibility(visible); - } -} - /***************************************************** * Workspace ****************************************************/ diff --git a/composite.h b/composite.h index a7aee56416..ccff306a9e 100644 --- a/composite.h +++ b/composite.h @@ -78,18 +78,10 @@ public: * Checks whether @p w is the Scene's overlay window. **/ bool checkForOverlayWindow(WId w) const; - /** - * @returns The Scene's Overlay X Window. - **/ - WId overlayWindow() const; /** * @returns Whether the Scene's Overlay X Window is visible. **/ bool isOverlayWindowVisible() const; - /** - * Set's the Scene's Overlay X Window visibility to @p visible. - **/ - void setOverlayWindowVisibility(bool visible); Scene *scene() { return m_scene; diff --git a/events.cpp b/events.cpp index 931c95c5a7..d93214612a 100644 --- a/events.cpp +++ b/events.cpp @@ -35,7 +35,6 @@ along with this program. If not, see . #include "tabbox.h" #endif #include "group.h" -#include "overlaywindow.h" #include "rules.h" #include "unmanaged.h" #include "useractions.h" @@ -506,29 +505,6 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e) if (ScreenEdges::self()->isEntered(reinterpret_cast(e))) return true; break; - case XCB_EXPOSE: { - const auto *event = reinterpret_cast(e); - if (compositing() - && (event->window == rootWindow() // root window needs repainting - || (m_compositor->overlayWindow() != XCB_WINDOW_NONE && event->window == m_compositor->overlayWindow()))) { // overlay needs repainting - m_compositor->addRepaint(event->x, event->y, event->width, event->height); - } - break; - } - case XCB_VISIBILITY_NOTIFY: { - const auto *event = reinterpret_cast(e); - if (compositing() && m_compositor->overlayWindow() != XCB_WINDOW_NONE && event->window == m_compositor->overlayWindow()) { - bool was_visible = m_compositor->isOverlayWindowVisible(); - m_compositor->setOverlayWindowVisibility((event->state != XCB_VISIBILITY_FULLY_OBSCURED)); - if (!was_visible && m_compositor->isOverlayWindowVisible()) { - // hack for #154825 - m_compositor->addRepaintFull(); - QTimer::singleShot(2000, m_compositor, SLOT(addRepaintFull())); - } - m_compositor->scheduleRepaint(); - } - break; - } default: if (eventType == Xcb::Extensions::self()->randrNotifyEvent() && Xcb::Extensions::self()->isRandrAvailable()) { auto *event = reinterpret_cast(e); diff --git a/plugins/platforms/x11/standalone/overlaywindow_x11.cpp b/plugins/platforms/x11/standalone/overlaywindow_x11.cpp index c1e4fe9dae..5a787665fb 100644 --- a/plugins/platforms/x11/standalone/overlaywindow_x11.cpp +++ b/plugins/platforms/x11/standalone/overlaywindow_x11.cpp @@ -21,6 +21,7 @@ along with this program. If not, see . #include "overlaywindow_x11.h" #include "kwinglobals.h" +#include "composite.h" #include "screens.h" #include "utils.h" #include "xcbutils.h" @@ -38,6 +39,7 @@ along with this program. If not, see . namespace KWin { OverlayWindowX11::OverlayWindowX11() : OverlayWindow() + , X11EventFilter(QVector{XCB_EXPOSE, XCB_VISIBILITY_NOTIFY}) , m_visible(true) , m_shown(false) , m_window(XCB_WINDOW_NONE) @@ -181,5 +183,31 @@ xcb_window_t OverlayWindowX11::window() const return m_window; } +bool OverlayWindowX11::event(xcb_generic_event_t *event) +{ + const uint8_t eventType = event->response_type & ~0x80; + if (eventType == XCB_EXPOSE) { + const auto *expose = reinterpret_cast(event); + if (expose->window == rootWindow() // root window needs repainting + || (m_window != XCB_WINDOW_NONE && expose->window == m_window)) { // overlay needs repainting + Compositor::self()->addRepaint(expose->x, expose->y, expose->width, expose->height); + } + } else if (eventType == XCB_VISIBILITY_NOTIFY) { + const auto *visibility = reinterpret_cast(event); + if (m_window != XCB_WINDOW_NONE && visibility->window == m_window) { + bool was_visible = isVisible(); + setVisibility((visibility->state != XCB_VISIBILITY_FULLY_OBSCURED)); + auto compositor = Compositor::self(); + if (!was_visible && m_visible) { + // hack for #154825 + compositor->addRepaintFull(); + QTimer::singleShot(2000, compositor, &Compositor::addRepaintFull); + } + compositor->scheduleRepaint(); + } + } + return false; +} + } // namespace KWin diff --git a/plugins/platforms/x11/standalone/overlaywindow_x11.h b/plugins/platforms/x11/standalone/overlaywindow_x11.h index 2cb562ae55..0ca5b143c7 100644 --- a/plugins/platforms/x11/standalone/overlaywindow_x11.h +++ b/plugins/platforms/x11/standalone/overlaywindow_x11.h @@ -22,9 +22,10 @@ along with this program. If not, see . #define KWIN_OVERLAYWINDOW_X11_H #include "../../../../overlaywindow.h" +#include "../../../../x11eventfilter.h" namespace KWin { -class KWIN_EXPORT OverlayWindowX11 : public OverlayWindow { +class KWIN_EXPORT OverlayWindowX11 : public OverlayWindow, public X11EventFilter { public: OverlayWindowX11(); ~OverlayWindowX11(); @@ -41,6 +42,8 @@ public: xcb_window_t window() const override; bool isVisible() const override; void setVisibility(bool visible) override; + + bool event(xcb_generic_event_t *event) override; private: void setNoneBackgroundPixmap(xcb_window_t window); void setupInputShape(xcb_window_t window);