# linux/x11: handle XIM events sync to reduce lag \(\#12840\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/05b658114750e9b63717ec3d05b316a927d8378e)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 05b658114750e9b63717ec3d05b316a927d8378e

Requested commit: 05b658114750e9b63717ec3d05b316a927d8378e

Commit: 05b658114750e9b63717ec3d05b316a927d8378e

Tree: bbb655784ba960c4cfb82f4f0f6c32304a7251af

Author: Thorsten Ball

Committer: GitHub

## Message

```
linux/x11: handle XIM events sync to reduce lag (#12840)

This helps with the problem of keyboard input feeling laggy when the
event loop is under load.

What would previously happen is:

- N events from X11 arrive
- N events get forwarded to XIM
- N events are handled in N iterations of the event loop (sadly, yes: we
only seem to be getting back one `ClientMessage` per poll from XCB
connection)
- Each event is pushed into the channel
- N event loop iterations are needed to get the events off the channel
and handle them

With this change, we get rid of the last 2 steps: instead of pushing the
event onto a channel, we store it on the XIM handler itself, and then
work it off synchronously.

Usually one shouldn't block the event loop, but I think in this case -
user input! - it's better to handle the events directly instead of
re-enqueuing them again in a channel, where they can accumulate and need
multiple iterations of the loop to be worked off.

This does *not* fix the problem of input feeling choppy/slower when the
system is under load, but it makes the behavior now feel exactly the
same as when XIM is disabled.

I also think the code is easier to understand since it's more
straightforward.

Release Notes:

- N/A
```

## Parents

- [43d1a8040d107a5cc2db1adbe943e3857e5fb138](https://git.cafe/gitcafe/zed/commit/43d1a8040d107a5cc2db1adbe943e3857e5fb138?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/05b658114750e9b63717ec3d05b316a927d8378e?format=markdown)
