diff --git a/platform.h b/platform.h --- a/platform.h +++ b/platform.h @@ -364,13 +364,9 @@ virtual OverlayWindow *createOverlayWindow(); /** - * Allows a platform to update the X11 timestamp. - * Mostly for the X11 standalone platform to interact with QX11Info. - * - * Default implementation does nothing. This means code relying on the X timestamp being up to date, - * might not be working. E.g. synced X11 window resizing + * Queries the current X11 time stamp of the X server. */ - virtual void updateXTime(); + void updateXTime(); /** * Creates the OutlineVisual for the given @p outline. diff --git a/platform.cpp b/platform.cpp --- a/platform.cpp +++ b/platform.cpp @@ -37,6 +37,8 @@ #include #include +#include + namespace KWin { @@ -501,8 +503,32 @@ return nullptr; } +static quint32 monotonicTime() +{ + timespec ts; + + const int result = clock_gettime(CLOCK_MONOTONIC, &ts); + if (result) + qCWarning(KWIN_CORE, "Failed to query monotonic time: %s", strerror(errno)); + + return ts.tv_sec * 1000 + ts.tv_nsec / 1000000L; +} + void Platform::updateXTime() { + switch (kwinApp()->operationMode()) { + case Application::OperationModeX11: + kwinApp()->setX11Time(QX11Info::getTimestamp(), Application::TimestampUpdate::Always); + break; + + case Application::OperationModeXwayland: + kwinApp()->setX11Time(monotonicTime(), Application::TimestampUpdate::Always); + break; + + default: + // Do not update the current X11 time stamp if it's the Wayland only session. + break; + } } OutlineVisual *Platform::createOutline(Outline *outline) diff --git a/plugins/platforms/x11/standalone/x11_platform.h b/plugins/platforms/x11/standalone/x11_platform.h --- a/plugins/platforms/x11/standalone/x11_platform.h +++ b/plugins/platforms/x11/standalone/x11_platform.h @@ -62,8 +62,6 @@ void setupActionForGlobalAccel(QAction *action) override; OverlayWindow *createOverlayWindow() override; - - void updateXTime() override; OutlineVisual *createOutline(Outline *outline) override; Decoration::Renderer *createDecorationRenderer(Decoration::DecoratedClientImpl *client) override; diff --git a/plugins/platforms/x11/standalone/x11_platform.cpp b/plugins/platforms/x11/standalone/x11_platform.cpp --- a/plugins/platforms/x11/standalone/x11_platform.cpp +++ b/plugins/platforms/x11/standalone/x11_platform.cpp @@ -348,22 +348,6 @@ return new OverlayWindowX11(); } -/* - Updates xTime(). This used to simply fetch current timestamp from the server, - but that can cause xTime() to be newer than timestamp of events that are - still in our events queue, thus e.g. making XSetInputFocus() caused by such - event to be ignored. Therefore events queue is searched for first - event with timestamp, and extra PropertyNotify is generated in order to make - sure such event is found. -*/ -void X11StandalonePlatform::updateXTime() -{ - // NOTE: QX11Info::getTimestamp does not yet search the event queue as the old - // solution did. This means there might be regressions currently. See the - // documentation above on how it should be done properly. - kwinApp()->setX11Time(QX11Info::getTimestamp(), Application::TimestampUpdate::Always); -} - OutlineVisual *X11StandalonePlatform::createOutline(Outline *outline) { // first try composited Outline