[x11] Update X11 time stamp on Wayland

Assume that Xwayland's current X11 time stamp corresponds to the system
monotonic time. Unfortunately, we cannot make roundtrips to Xwayland and
we cannot query the time stamp asynchronously because it may introduce
regressions in the standalone X11 window manager.

Differential Revision: https://phabricator.kde.org/D29250
This commit is contained in:
Vlad Zahorodnii 2020-04-27 13:49:36 +03:00
parent 385c8d3db6
commit 0323825f76
4 changed files with 28 additions and 24 deletions

View file

@ -37,6 +37,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Server/outputconfiguration_interface.h>
#include <KWayland/Server/outputchangeset.h>
#include <QX11Info>
namespace KWin
{
@ -501,8 +503,32 @@ OverlayWindow *Platform::createOverlayWindow()
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)

View file

@ -364,13 +364,9 @@ public:
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.

View file

@ -348,22 +348,6 @@ OverlayWindow *X11StandalonePlatform::createOverlayWindow()
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

View file

@ -62,8 +62,6 @@ public:
void setupActionForGlobalAccel(QAction *action) override;
OverlayWindow *createOverlayWindow() override;
void updateXTime() override;
OutlineVisual *createOutline(Outline *outline) override;
Decoration::Renderer *createDecorationRenderer(Decoration::DecoratedClientImpl *client) override;