From 36a31898631601d07374b0ffbbad4f65aaf77156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Thu, 17 Aug 2017 19:10:45 +0200 Subject: [PATCH] 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 --- CMakeLists.txt | 1 + events.cpp | 6 ----- was_user_interaction_x11_filter.cpp | 38 +++++++++++++++++++++++++++++ was_user_interaction_x11_filter.h | 37 ++++++++++++++++++++++++++++ workspace.cpp | 18 ++++++++++++++ workspace.h | 6 +---- 6 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 was_user_interaction_x11_filter.cpp create mode 100644 was_user_interaction_x11_filter.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c5bca4d6fe..2f8e31a2ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/events.cpp b/events.cpp index d93214612a..74c0d155db 100644 --- a/events.cpp +++ b/events.cpp @@ -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(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(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(e)); @@ -644,12 +641,10 @@ bool Client::windowEvent(xcb_generic_event_t *e) break; case XCB_KEY_PRESS: updateUserTime(reinterpret_cast(e)->time); - workspace()->setWasUserInteraction(); break; case XCB_BUTTON_PRESS: { const auto *event = reinterpret_cast(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() diff --git a/was_user_interaction_x11_filter.cpp b/was_user_interaction_x11_filter.cpp new file mode 100644 index 0000000000..1cc33710a2 --- /dev/null +++ b/was_user_interaction_x11_filter.cpp @@ -0,0 +1,38 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2017 Martin Flöser + +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 . +*********************************************************************/ +#include "was_user_interaction_x11_filter.h" +#include "workspace.h" +#include + +namespace KWin +{ +WasUserInteractionX11Filter::WasUserInteractionX11Filter() + : X11EventFilter(QVector{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; +} + +} diff --git a/was_user_interaction_x11_filter.h b/was_user_interaction_x11_filter.h new file mode 100644 index 0000000000..b1212b713c --- /dev/null +++ b/was_user_interaction_x11_filter.h @@ -0,0 +1,37 @@ +/******************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2017 Martin Flöser + +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 . +*********************************************************************/ +#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 diff --git a/workspace.cpp b/workspace.cpp index 4c2d5f7551..189afada39 100644 --- a/workspace.cpp +++ b/workspace.cpp @@ -54,6 +54,7 @@ along with this program. If not, see . #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 diff --git a/workspace.h b/workspace.h index 2030043068..c883f74b32 100644 --- a/workspace.h +++ b/workspace.h @@ -571,6 +571,7 @@ private: GroupList groups; bool was_user_interaction; + QScopedPointer 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;