zed/crates/gpui/src
Thorsten Ball 64755a7aea
linux/x11: Custom run loop with mio instead of calloop (#13646)
This changes the implementation of the X11 client to use `mio`, as a
polling mechanism, and a custom run loop instead of `calloop` and its
callback-based approach.

We're doing this for one big reason: more control over how we handle
events.

With `calloop` we don't have any control over which events are processed
when and how long they're processes for. For example: we could be
blasted with 150 input events from X11 and miss a frame while processing
them, but instead of then drawing a new frame, calloop could decide to
work off the runnables that were generated from application-level code,
which would then again cause us to be behind.

We kinda worked around some of that in
https://github.com/zed-industries/zed/pull/12839 but the problem still
persists.

So what we're doing here is to use `mio` as a polling-mechanism. `mio`
notifies us if there are X11 on the XCB connection socket to be
processed. We also use its timeout mechanism to make sure that we don't
wait for events when we should render frames.

On top of `mio` we now have a custom run loop that allows us to decide
how much time to spend on what — input events, rendering windows, XDG
events, runnables — and in what order we work things off.

This custom run loop is consciously "dumb": we render all windows at the
highest frame rate right now, because we want to keep things predictable
for now while we test this approach more. We can then always switch to
more granular timings. But considering that our loop runs and checks for
windows to be redrawn whenever there's an event, this is more an
optimization than a requirement.

One reason for why we're doing this for X11 but not for Wayland is due
to how peculiar X11's event handling is: it's asynchronous and by
default X11 generates synthetic events when a key is held down. That can
lead to us being flooded with input events if someone keeps a key
pressed.

So another optimization that's in here is inspired by [GLFW's X11 input
handling](b35641f4a3/src/x11_window.c (L1321-L1349)):
based on a heuristic we detect whether a `KeyRelease` event was
auto-generated and if so, we drop it. That essentially halves the amount
of events we have to process when someone keeps a key pressed.

Release Notes:

- N/A

---------

Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Co-authored-by: Conrad <conrad@zed.dev>
2024-07-03 17:05:26 +02:00
..
app Enable linux tests (#12493) 2024-06-13 16:38:53 -07:00
elements Bump image crate (#13397) 2024-06-25 15:12:45 +02:00
keymap vim: Implement named registers (#12895) 2024-06-12 10:40:27 -06:00
platform linux/x11: Custom run loop with mio instead of calloop (#13646) 2024-07-03 17:05:26 +02:00
text_system Move from Zed fonts to IBM Plex (#13596) 2024-06-27 14:36:44 -06:00
window Merge ElementContext into WindowContext (#10979) 2024-04-25 12:54:39 +02:00
action.rs Add more menus to Zed (#12940) 2024-06-18 12:16:54 -07:00
app.rs Fix 100s freeze on boot on X11 (#13156) 2024-06-17 12:44:32 -06:00
arena.rs Log if element arena allocation is >80% 2024-01-24 11:03:28 +01:00
asset_cache.rs gpui: Add SVG rendering to img element and generic asset cache (#9931) 2024-03-29 17:09:49 -07:00
assets.rs Bump image crate (#13397) 2024-06-25 15:12:45 +02:00
bounds_tree.rs Fix flickering (#9012) 2024-03-11 10:45:57 +01:00
color.rs Introduce an outline panel (#12637) 2024-06-12 23:22:52 +03:00
element.rs gpui: Pass Style by value to request_layout (#11597) 2024-05-09 11:38:53 +02:00
executor.rs Allow canceling in-progress language server work (e.g. cargo check) (#13173) 2024-06-17 17:58:47 -07:00
geometry.rs Add limit to minimum window size (#13126) 2024-06-24 21:26:13 -06:00
global.rs Make a macro for less boilerplate when moving variables (#12182) 2024-05-22 22:07:29 -07:00
gpui.rs gpui: Improve Global ergonomics (#11923) 2024-05-16 12:47:43 -04:00
input.rs Document / lockdown more of GPUI 2024-01-21 14:26:45 -08:00
interactive.rs Pull app / OS info out of GPUI, add Linux information, make fallible window initialization (#12869) 2024-06-11 11:43:12 -07:00
key_dispatch.rs Merge ElementContext into WindowContext (#10979) 2024-04-25 12:54:39 +02:00
keymap.rs chore: Bump Rust version to 1.76 (#7592) 2024-02-09 10:45:39 +02:00
platform.rs Change window_min_size from Size<Pixels> to Option<Size<Pixels>> (#13501) 2024-06-25 12:09:08 -06:00
prelude.rs Document / lockdown more of GPUI 2024-01-21 14:26:45 -08:00
scene.rs Add an animation to the LSP checking indicator (#9463) 2024-03-19 10:16:18 -07:00
shared_string.rs Add logic for managing language and theme extensions (#7467) 2024-02-07 15:14:50 -05:00
shared_uri.rs Rework loading images from files (#7088) 2024-01-30 11:26:02 -05:00
style.rs Introduce an outline panel (#12637) 2024-06-12 23:22:52 +03:00
styled.rs Add col/row resize cursor styles (#11406) 2024-05-06 14:22:56 -07:00
subscription.rs Refine inline transformation UX (#12939) 2024-06-13 08:35:22 +02:00
svg_renderer.rs Make tests less noisy (#12463) 2024-05-29 18:06:45 -07:00
taffy.rs chore: Fix clippy for upcoming 1.79 Rust release (#12727) 2024-06-06 12:46:53 +02:00
test.rs Throttle the sending of UpdateFollowers messages (#8918) 2024-03-06 14:58:41 +01:00
text_system.rs Move from Zed fonts to IBM Plex (#13596) 2024-06-27 14:36:44 -06:00
util.rs Prompt library updates (#11988) 2024-05-22 18:04:47 -04:00
view.rs Introduce Editor::insert_flaps and Editor::remove_flaps (#12096) 2024-05-21 20:23:37 +02:00
window.rs Fix multi-keystroke shortcuts better (#13612) 2024-06-27 16:39:05 -06:00