A comparison in translate_device_event() does not account for the fact that X’s clock wraps about every 49.7 days. When triggered, this causes an unresponsive GUI. Replace simple less-than comparison with XSERVER_TIME_IS_BEFORE macro, which accounts for the wrapping of X’s clock.
commit 942883577ea700f0f419c335185891ff9a02e07b Author: Jonas Ådahl <jadahl@gmail.com> Date: Fri Oct 25 10:06:55 2019 +0200
x11: Limit touch replay pointer events to when replaying
When a touch sequence was rejected, the emulated pointer events would be replayed with old timestamps. This caused issues with grabs as they would be ignored due to being too old. This was mitigated by making sure device event timestamps never travelled back in time by tampering with any event that had a timestamp seemingly in the past.
This failed when the most recent timestamp that had been received were much older than the timestamp of the new event. This could for example happen when a session was left not interacted with for 40+ days or so; when interacted with again, as any new timestamp would according to XSERVER_TIME_IS_BEFORE() still be in the past compared to the "most recent" one. The effect is that we'd always use the `latest_evtime` for all new device events without ever updating it.
The end result of this was that passive grabs would become active when interacted with, but would then newer be released, as the timestamps to XIAllowEvents() would out of date, resulting in the desktop effectively freezing, as the Shell would have an active pointer grab.
To avoid the situation where we get stuck with an old `latest_evtime` timestamp, limit the tampering with device event timestamp to 1) only pointer events, and 2) only during the replay sequence. The second part is implemented by sending an asynchronous message via the X server after rejecting a touch sequence, only potentially tampering with the device event timestamps until the reply. This should avoid the stuck timestamp as in those situations, we'll always have a relatively up to date `latest_evtime` meaning XSERVER_TIME_IS_BEFORE() will not get confused.
if (!device_event->send_event && device_event->time != CurrentTime) { - if (device_event->time < priv->latest_evtime) + if (XSERVER_TIME_IS_BEFORE (device_event->time, priv->latest_evtime)) { /* Emulated pointer events received after XIRejectTouch is received * on a passive touch grab will contain older timestamps, update those * so we dont get InvalidTime at grabs. */ device_event->time = priv->latest_evtime; }
/* Update the internal latest evtime, for any possible later use */ priv->latest_evtime = device_event->time; } }
/* Xserver time can wraparound, thus comparing two timestamps needs to take * this into account. Here's a little macro to help out. If no wraparound * has occurred, this is equivalent to * time1 < time2 * Of course, the rest of the ugliness of this macro comes from accounting * for the fact that wraparound can occur and the fact that a timestamp of * 0 must be special-cased since it means older than anything else. * * Note that this is NOT an equivalent for time1 <= time2; if that's what * you need then you'll need to swap the order of the arguments and negate * the result. */ #define XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) \ ( (( (time1) < (time2) ) && ( (time2) - (time1) < ((guint32)-1)/2 )) || \ (( (time1) > (time2) ) && ( (time1) - (time2) > ((guint32)-1)/2 )) \ ) #define XSERVER_TIME_IS_BEFORE(time1, time2) \ ( (time1) == 0 || \ (XSERVER_TIME_IS_BEFORE_ASSUMING_REAL_TIMESTAMPS(time1, time2) && \ (time2) != 0) \ )
根据patch的修改,如果时间戳不对,则窗口不响应。
X服务器对时间戳的使用例子:
1 2 3 4
time = ClientTimeToServerTime(ctime); if ((CompareTimeStamps(time, currentTime) == LATER) || (CompareTimeStamps(time, grabInfo->grabTime) == EARLIER) xxx
/* To avoid time running backwards, we must call GetTimeInMillis before * calling ProcessInputEvents. */ systime.months = currentTime.months; systime.milliseconds = GetTimeInMillis(); if (systime.milliseconds < currentTime.milliseconds) systime.months++; if (InputCheckPending()) ProcessInputEvents(); if (CompareTimeStamps(systime, currentTime) == LATER) currentTime = systime; }