Commit a65b2c06 authored by Martin Flöser's avatar Martin Flöser

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
parent b4a79d30
......@@ -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
****************************************************/
......
......@@ -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;
......
......@@ -35,7 +35,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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<xcb_client_message_event_t*>(e)))
return true;
break;
case XCB_EXPOSE: {
const auto *event = reinterpret_cast<xcb_expose_event_t*>(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<xcb_visibility_notify_event_t*>(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<xcb_randr_screen_change_notify_event_t*>(e);
......
......@@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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 <http://www.gnu.org/licenses/>.
namespace KWin {
OverlayWindowX11::OverlayWindowX11()
: OverlayWindow()
, X11EventFilter(QVector<int>{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<xcb_expose_event_t*>(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<xcb_visibility_notify_event_t*>(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
......@@ -22,9 +22,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment