Create a dedicated X11EventFilter for recognizing first user interaction

Summary:
Workspace monitors the X11 events to detect when the user first
interacts with the system. This is only required on X11 for activating
the same client from previous session. So far this was spread over many
parts in the long event switch statement. To make this more contained a
dedicated event filter is introduced which also gets deleted again once
the first user interaction got recognized.

Test Plan: Compiles

Reviewers: #kwin, #plasma

Subscribers: plasma-devel, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D7371
This commit is contained in:
Martin Flöser 2017-08-17 19:10:45 +02:00
parent 34de2c2b5c
commit 36a3189863
6 changed files with 95 additions and 11 deletions

View file

@ -455,6 +455,7 @@ set(kwin_KDEINIT_SRCS
popup_input_filter.cpp
abstract_opengl_context_attribute_builder.cpp
egl_context_attribute_builder.cpp
was_user_interaction_x11_filter.cpp
)
if(KWIN_BUILD_TABBOX)

View file

@ -265,7 +265,6 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e)
switch (eventType) {
case XCB_BUTTON_PRESS:
case XCB_BUTTON_RELEASE: {
was_user_interaction = true;
auto *mouseEvent = reinterpret_cast<xcb_button_press_event_t*>(e);
#ifdef KWIN_BUILD_TABBOX
if (TabBox::TabBox::self()->isGrabbed()) {
@ -301,7 +300,6 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e)
break;
}
case XCB_KEY_PRESS: {
was_user_interaction = true;
int keyQt;
xcb_key_press_event_t *event = reinterpret_cast<xcb_key_press_event_t*>(e);
KKeyServer::xcbKeyPressEventToQt(event, &keyQt);
@ -319,7 +317,6 @@ bool Workspace::workspaceEvent(xcb_generic_event_t *e)
break;
}
case XCB_KEY_RELEASE:
was_user_interaction = true;
#ifdef KWIN_BUILD_TABBOX
if (TabBox::TabBox::self()->isGrabbed()) {
TabBox::TabBox::self()->keyRelease(reinterpret_cast<xcb_key_release_event_t*>(e));
@ -644,12 +641,10 @@ bool Client::windowEvent(xcb_generic_event_t *e)
break;
case XCB_KEY_PRESS:
updateUserTime(reinterpret_cast<xcb_key_press_event_t*>(e)->time);
workspace()->setWasUserInteraction();
break;
case XCB_BUTTON_PRESS: {
const auto *event = reinterpret_cast<xcb_button_press_event_t*>(e);
updateUserTime(event->time);
workspace()->setWasUserInteraction();
buttonPressEvent(event->event, event->detail, event->state,
event->event_x, event->event_y, event->root_x, event->root_y, event->time);
break;
@ -1068,7 +1063,6 @@ bool Client::buttonPressEvent(xcb_window_t w, int button, int state, int x, int
if (w == wrapperId() || w == frameId() || w == inputId()) {
// FRAME neco s tohohle by se melo zpracovat, nez to dostane dekorace
updateUserTime(time);
workspace()->setWasUserInteraction();
const bool bModKeyHeld = modKeyDown(state);
if (isSplash()

View file

@ -0,0 +1,38 @@
/********************************************************************
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 "was_user_interaction_x11_filter.h"
#include "workspace.h"
#include <xcb/xcb.h>
namespace KWin
{
WasUserInteractionX11Filter::WasUserInteractionX11Filter()
: X11EventFilter(QVector<int>{XCB_KEY_PRESS, XCB_KEY_RELEASE, XCB_BUTTON_PRESS, XCB_BUTTON_RELEASE})
{
}
bool WasUserInteractionX11Filter::event(xcb_generic_event_t *event)
{
Q_UNUSED(event);
workspace()->setWasUserInteraction();
return false;
}
}

View file

@ -0,0 +1,37 @@
/********************************************************************
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_WAS_USER_INTERACTION_X11_FILTER_H
#define KWIN_WAS_USER_INTERACTION_X11_FILTER_H
#include "x11eventfilter.h"
namespace KWin
{
class WasUserInteractionX11Filter : public X11EventFilter
{
public:
explicit WasUserInteractionX11Filter();
bool event(xcb_generic_event_t *event) override;
};
}
#endif

View file

@ -54,6 +54,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "useractions.h"
#include "virtualdesktops.h"
#include "shell_client.h"
#include "was_user_interaction_x11_filter.h"
#include "wayland_server.h"
#include "xcbutils.h"
#include "main.h"
@ -214,6 +215,9 @@ Workspace::Workspace(const QString &sessionKey)
void Workspace::init()
{
if (kwinApp()->operationMode() == Application::OperationModeX11) {
m_wasUserInteractionFilter.reset(new WasUserInteractionX11Filter);
}
updateXTime(); // Needed for proper initialization of user_time in Client ctor
KSharedConfigPtr config = kwinApp()->config();
kwinApp()->createScreens();
@ -1786,5 +1790,19 @@ void Workspace::markXStackingOrderAsDirty()
m_xStackingQueryTree.reset(new Xcb::Tree(rootWindow()));
}
void Workspace::setWasUserInteraction()
{
if (was_user_interaction) {
return;
}
was_user_interaction = true;
// might be called from within the filter, so delay till we now the filter returned
QTimer::singleShot(0, this,
[this] {
m_wasUserInteractionFilter.reset();
}
);
}
} // namespace

View file

@ -571,6 +571,7 @@ private:
GroupList groups;
bool was_user_interaction;
QScopedPointer<X11EventFilter> m_wasUserInteractionFilter;
bool session_saving;
int session_active_client;
int session_desktop;
@ -691,11 +692,6 @@ inline const ToplevelList& Workspace::stackingOrder() const
return stacking_order;
}
inline void Workspace::setWasUserInteraction()
{
was_user_interaction = true;
}
inline bool Workspace::wasUserInteraction() const
{
return was_user_interaction;