Skip to content

Macos pump events#51

Open
yibie wants to merge 2 commits intoeval-exec:mainfrom
yibie:macos-pump-events
Open

Macos pump events#51
yibie wants to merge 2 commits intoeval-exec:mainfrom
yibie:macos-pump-events

Conversation

@yibie
Copy link

@yibie yibie commented Feb 27, 2026

Neomacs PR Checklist

Compatibility Checks

  • Ran relevant vm-compat checks for changed areas (for example make -C test/neovm/vm-compat check-one-neovm, check-all-neovm, etc.).
  • Ran make -C test/neovm/vm-compat compat-progress and attached output in PR notes.
  • If stub annotations changed, ran make -C test/neovm/vm-compat check-stub-budget and confirmed explicitly annotated function stubs budget expectations.
  • If case corpus changed, attached make -C test/neovm/vm-compat check or check-neovm outputs for changed case lists.
  • If registry metadata changed, attached check-builtin-registry-* output (at least check-builtin-registry-fboundp).

yibie and others added 2 commits February 19, 2026 07:55
Port the neomacs Rust display engine (winit + wgpu/Metal) to macOS
arm64 by resolving build-time conflicts and a runtime threading
constraint.

Build fixes:
- Suppress NS/Cocoa detection when --with-neomacs is set
- Skip EGL and xkbcommon checks on macOS (Metal and native key APIs)
- Use macOS frameworks instead of -ldl for linking
- Disable WPE WebKit (Linux-only) via --no-default-features in cargo
- Guard header typedefs to prevent conflicts between nsgui.h and
  neomacsgui.h (XCharStruct, NativeRectangle, Display_Info, Emacs_Pixmap)
- Replace unavailable QCid symbol with intern_c_string(":id")
- Add xkbcommon include guard and get_keysym_name fallback for macOS

Runtime fix:
- Invert thread model on macOS where winit 0.30 requires EventLoop on
  the main thread: main() hands control to Rust via a trampoline that
  spawns Emacs on a child thread and runs the render loop on the main
  thread, coordinated through a condvar-based handoff in
  neomacs_display_init_threaded

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace the broken callback/pthread approach with a pump_app_events
design that lets Emacs stay on the main thread while driving winit.

- EventLoop and RenderApp are created on the main thread in
  neomacs_open_display (called from Lisp) and stored in thread_local!
- neomacs_read_socket calls neomacs_display_pump_macos_events(0)
  periodically to process winit events non-blockingly
- about_to_wait writes to wakeup_fd when animations are active so
  Emacs keeps calling pump during crossfade/scroll/cursor transitions
- ControlFlow::Wait (not Poll) lets Metal VSync pace frame delivery

- Rate-limit pump calls in neomacs_read_socket to ~120 Hz (8 ms)
  to avoid busy-spinning when Emacs polls rapidly
- about_to_wait uses WaitUntil(+8ms) during active rendering and
  WaitUntil(+16ms) when idle instead of the old 4ms Poll spin
- wakeup_fd is written during animations to maintain smooth frame
  delivery without stalling while Emacs waits for keyboard input

- Register atexit handler that uses try_with + std::mem::forget to
  skip RenderApp/EventLoop Drop at process exit, preventing winit's
  window_will_close ObjC callback from firing during TLS destruction
- RenderApp::Drop also forgets the Window Arc as a safety net

- Fix DO_CODESIGN detection in Makefile.in (was always empty because
  @configuration@ substituted to ""); use $(shell uname -s) instead
- Add codesign steps after temacs copy and after pdump in Makefile.in
- Remove old macOS callback globals and pthread integration code
- Fix wakeup_fd shadowing bug in neomacs_open_display

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant