Port KillWindow to X11EventFilter

Summary:
Removes the special handling from events.cpp for KillWindow. The same
functionality can be provided through the X11EventFilter.

This is a preparation step for moving the interactive window selection
into the Platform and to support KillWindow also for Wayland.

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D3362
This commit is contained in:
Martin Gräßlin 2016-11-15 08:53:18 +01:00
parent 9f976a4b8d
commit 52cf47ff53
3 changed files with 26 additions and 28 deletions

View file

@ -63,7 +63,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif
#include "composite.h"
#include "killwindow.h"
#include "x11eventfilter.h"
#include "wayland_server.h"
@ -253,12 +252,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 (!m_windowKiller.isNull() && m_windowKiller->isActive() && m_windowKiller->isResponsibleForEvent(eventType)) {
m_windowKiller->processEvent(e);
// filter out the event
return true;
}
if (eventType == XCB_PROPERTY_NOTIFY || eventType == XCB_CLIENT_MESSAGE) {
NET::Properties dirtyProtocols;
NET::Properties2 dirtyProtocols2;

View file

@ -35,7 +35,17 @@ namespace KWin
{
KillWindow::KillWindow()
: m_active(false)
: X11EventFilter(QVector<int>{XCB_BUTTON_PRESS,
XCB_BUTTON_RELEASE,
XCB_MOTION_NOTIFY,
XCB_ENTER_NOTIFY,
XCB_LEAVE_NOTIFY,
XCB_KEY_PRESS,
XCB_KEY_RELEASE,
XCB_FOCUS_IN,
XCB_FOCUS_OUT
})
, m_active(false)
{
}
@ -89,24 +99,6 @@ xcb_cursor_t KillWindow::createCursor()
return cursor;
}
bool KillWindow::isResponsibleForEvent(int eventType) const
{
switch (eventType) {
case XCB_BUTTON_PRESS:
case XCB_BUTTON_RELEASE:
case XCB_MOTION_NOTIFY:
case XCB_ENTER_NOTIFY:
case XCB_LEAVE_NOTIFY:
case XCB_KEY_PRESS:
case XCB_KEY_RELEASE:
case XCB_FOCUS_IN:
case XCB_FOCUS_OUT:
return true;
default:
return false;
}
}
void KillWindow::processEvent(xcb_generic_event_t *event)
{
if (event->response_type == XCB_BUTTON_RELEASE) {
@ -118,6 +110,16 @@ void KillWindow::processEvent(xcb_generic_event_t *event)
}
}
bool KillWindow::event(xcb_generic_event_t *event)
{
if (!m_active) {
return false;
}
processEvent(event);
return true;
}
void KillWindow::handleButtonRelease(xcb_button_t button, xcb_window_t window)
{
if (button == XCB_BUTTON_INDEX_3) {

View file

@ -23,12 +23,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef KWIN_KILLWINDOW_H
#define KWIN_KILLWINDOW_H
#include "x11eventfilter.h"
#include <xcb/xcb.h>
namespace KWin
{
class KillWindow
class KillWindow : public X11EventFilter
{
public:
@ -39,9 +41,10 @@ public:
bool isActive() const {
return m_active;
}
bool isResponsibleForEvent(int eventType) const;
void processEvent(xcb_generic_event_t *event);
bool event(xcb_generic_event_t *event) override;
private:
xcb_cursor_t createCursor();
void release();