Create a dedicated X11EventFilter for the events used by RootInfo

Summary:
Splitting out the handling from events.cpp and moves it into a
dedicated class created together with RootInfo.

Test Plan:
Test case for NET window move which goes through this
code path still passes.

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D7808
This commit is contained in:
Martin Flöser 2017-09-13 21:44:07 +02:00
parent d29d181e7c
commit cea7a189c8
6 changed files with 93 additions and 10 deletions

View file

@ -470,6 +470,7 @@ set(kwin_KDEINIT_SRCS
moving_client_x11_filter.cpp
effects_mouse_interception_x11_filter.cpp
window_property_notify_x11_filter.cpp
rootinfo_filter.cpp
)
if(KWIN_BUILD_TABBOX)

View file

@ -247,16 +247,6 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e)
&& (eventType == XCB_KEY_PRESS || eventType == XCB_KEY_RELEASE))
return false; // let Qt process it, it'll be intercepted again in eventFilter()
if (eventType == XCB_PROPERTY_NOTIFY || eventType == XCB_CLIENT_MESSAGE) {
NET::Properties dirtyProtocols;
NET::Properties2 dirtyProtocols2;
rootInfo()->event(e, &dirtyProtocols, &dirtyProtocols2);
if (dirtyProtocols & NET::DesktopNames)
VirtualDesktopManager::self()->save();
if (dirtyProtocols2 & NET::WM2DesktopLayout)
VirtualDesktopManager::self()->updateLayout();
}
// events that should be handled before Clients can get them
switch (eventType) {
case XCB_CONFIGURE_NOTIFY:

View file

@ -23,6 +23,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "netinfo.h"
// kwin
#include "client.h"
#include "rootinfo_filter.h"
#include "virtualdesktops.h"
#include "workspace.h"
// Qt
@ -139,6 +140,7 @@ RootInfo::RootInfo(xcb_window_t w, const char *name, NET::Properties properties,
NET::States states, NET::Properties2 properties2, NET::Actions actions, int scr)
: NETRootInfo(connection(), w, name, properties, types, states, properties2, actions, scr)
, m_activeWindow(activeWindow())
, m_eventFilter(std::make_unique<RootInfoFilter>(this))
{
}

View file

@ -26,12 +26,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <NETWM>
#include <xcb/xcb.h>
#include <memory>
namespace KWin
{
class AbstractClient;
class Client;
class RootInfoFilter;
/**
* NET WM Protocol handler class
@ -65,6 +67,7 @@ private:
friend RootInfo *rootInfo();
xcb_window_t m_activeWindow;
std::unique_ptr<RootInfoFilter> m_eventFilter;
};
inline RootInfo *rootInfo()

45
rootinfo_filter.cpp Normal file
View file

@ -0,0 +1,45 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "rootinfo_filter.h"
#include "netinfo.h"
#include "virtualdesktops.h"
namespace KWin
{
RootInfoFilter::RootInfoFilter(RootInfo *parent)
: X11EventFilter(QVector<int>{XCB_PROPERTY_NOTIFY, XCB_CLIENT_MESSAGE})
, m_rootInfo(parent)
{
}
bool RootInfoFilter::event(xcb_generic_event_t *event)
{
NET::Properties dirtyProtocols;
NET::Properties2 dirtyProtocols2;
m_rootInfo->event(event, &dirtyProtocols, &dirtyProtocols2);
if (dirtyProtocols & NET::DesktopNames)
VirtualDesktopManager::self()->save();
if (dirtyProtocols2 & NET::WM2DesktopLayout)
VirtualDesktopManager::self()->updateLayout();
return false;
}
}

42
rootinfo_filter.h Normal file
View file

@ -0,0 +1,42 @@
/********************************************************************
KWin - the KDE window manager
This file is part of the KDE project.
Copyright (C) 2017 Martin Flöser <mgraesslin@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_ROOTINFO_FILTER_H
#define KWIN_ROOTINFO_FILTER_H
#include "x11eventfilter.h"
namespace KWin
{
class RootInfo;
class RootInfoFilter : public X11EventFilter
{
public:
explicit RootInfoFilter(RootInfo *parent);
bool event(xcb_generic_event_t *event) override;
private:
RootInfo *m_rootInfo;
};
}
#endif