`ColorImage` fields are now private. Use `resolution()`, `pixels()`,
`pixels_mut()`, and `source_size()` instead.
Also renames `size` to `resolution` in several texture-related APIs
(`ImageData`, `TextureHandle`, `TextureMeta`, `TextureAtlas`,
`Fonts::font_image_resolution`).
`ColorImage::new` now panics if `width * height != pixels.len()`.
## Motivation
A) Make `ColorImage` always valid
B) Stop confusing using the confusing word `size` where `resolution` is
better
The name egui_system_fonts is already taken on crates.io. The new name
matches the crate's `SystemFontProvider` type.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
eframe now remembers the window's last *normal* (not maximized, not
fullscreen) size and position. After a relaunch, un-maximizing or
leaving fullscreen goes back to that size instead of a window that is
"maximized but not maximized".
Other fixes:
* A maximized or fullscreen window no longer paints its first frame
small.
* Leaving a restored fullscreen goes straight back to the normal size,
in one step.
* The window reopens on the correct monitor, also with monitors of
different scale factors on macOS. The position is saved in pixels
together with the scale factor, and converted on restore.
* On macOS and Windows, the window is placed exactly after creation,
then maximized or made fullscreen.
* On Windows, a window restored maximized no longer flashes on screen
(shown, hidden, then shown again) during startup. winit maximizes with
`ShowWindow(SW_MAXIMIZE)`, which shows the still-hidden window before
hiding it again. The new `egui_winit::set_maximized` cloaks a hidden
window (`DWMWA_CLOAK`) while maximizing it, so it stays invisible but is
already maximized for the first frame. This is a workaround until winit
has rust-windowing/winit#4575 or rust-windowing/winit#4587.
* On X11, a window saved maximized or fullscreen now restores as such.
winit sends these as `_NET_WM_STATE` client messages, which window
managers ignore while the window is still hidden (eframe keeps it hidden
until the first frame is painted). The new
`WindowSettings::after_first_show` re-applies them right after the
window is shown. `before_first_show` replaces the macOS-only
`enter_fullscreen_after_first_frame` / `enter_deferred_fullscreen`.
The save format changed, so old saved window settings are ignored once
(the window opens at its default size).
Known limitations:
* The normal geometry is sampled on save. If you resize, maximize before
the next autosave, and quit while maximized, un-maximizing after a
relaunch goes back to the size from before the resize.
* On X11, a restored maximized window may show un-maximized for a frame
before it maximizes.
* On X11 with GNOME (mutter), un-maximizing a window that was restored
maximized puts it in the top-left corner of its monitor, not at its
saved position. The size is right. mutter places windows that get
maximized right after mapping at the work area origin.
* On Wayland, the position (and so the monitor) can't be restored,
because Wayland doesn't let clients read or set window positions. Size
and maximized/fullscreen state are restored.
* On GNOME, a restored window that is close to the screen size gets
auto-maximized by mutter (`org.gnome.mutter auto-maximize`).
Tested on macOS, wayland, x11 (XWayland on GNOME, including two
monitors) and Windows (wgpu and glow).
* [x] I have followed the instructions in the PR template
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_019yMtdim1FPCsviY1FWfdTk
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Adds `eframe::Frame::set_traffic_lights_position` for placing the native
macOS "traffic lights" (close/minimize/maximize buttons) inside a custom
title bar, e.g. when using
`ViewportBuilder::with_fullsize_content_view`.
## New API
```rust
impl eframe::Frame {
/// Center the traffic lights vertically in `title_bar_y` (measured from the top of the window),
/// with the close button `left_margin` from the left edge. Both in egui points.
/// Call it every frame. Does nothing on other platforms.
pub fn set_traffic_lights_position(
&self,
egui_ctx: &egui::Context,
title_bar_y: egui::Rangef,
left_margin: f32,
);
}
```
Usage (from the `custom_window_frame` example):
```rust
frame.set_traffic_lights_position(
ui.ctx(),
title_bar_rect.y_range(),
title_bar_rect.left() + 12.0,
);
```
## Details
* The buttons keep AppKit's native spacing.
* The native title bar is resized to cover the buttons, so they stay
clickable in title bars taller than the default.
* Units are egui points; the zoom factor is applied internally.
* It is immediate mode: AppKit resets the button positions whenever it
re-lays out the window (e.g. on resize), so call it every frame.
* No-op in fullscreen (the traffic lights live in a separate window
there) and on non-macOS platforms.
## Other changes
* `custom_window_frame` example: on macOS, uses a full-size content view
with the native traffic lights centered in the custom title bar, instead
of drawing its own buttons.
* `emath::Rangef` now supports `Rangef * f32`, `f32 * Rangef`, and
`Rangef / f32`.
* `WindowChromeMetrics::traffic_lights_size.y` now measures the top
margin from the top of the title bar (previously it was taken from the
bottom in AppKit's non-flipped coordinates), so the reported height may
change.
## Testing
Ran `custom_window_frame` on macOS: traffic lights stay centered when
resizing and zooming (cmd +/-).
* [x] I have followed the instructions in the PR template
🤖 This PR was written with Codex and Claude Code; Marten remains
responsible for the change.
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* Part of #5136
* Closes https://github.com/emilk/egui/pull/8414
On Wayland a compositor may stop sending frame callbacks to a window it
isn't showing, without telling the client that the window is occluded.
Hyprland does this when another window on the same workspace goes
fullscreen or maximized. With the glow backend, eframe then blocks in a
vsync `eglSwapBuffers` until the window is shown again. Nothing runs,
pings go unanswered, and the compositor reports the app as not
responding. With wgpu, `pre_present_notify` keeps eframe from blocking,
but `RedrawRequested` never arrives, so `App::logic` stops running.
In rust-windowing/winit#4668 the winit maintainers said that winit
should keep holding `RedrawRequested` until the frame callback arrives,
and that a timeout belongs in the toolkit. This PR adds that timeout:
* glow calls `Window::pre_present_notify` before swapping, like
egui-wgpu already does, so winit paces `RedrawRequested` by frame
callbacks.
* On Wayland, glow swaps with interval 0. The frame callbacks already
pace it. With the NVIDIA driver (egl-wayland2), a vsync swap also blocks
forever for a window that starts on a hidden workspace: the compositor
sends a frame callback for the first buffer but never presents it, and
the next swap waits for that buffer.
* If a `RedrawRequested` we asked for hasn't arrived within 250 ms,
eframe runs `App::logic` without an egui pass, the same as for other
hidden windows. Once the compositor sends a frame callback again, the
window paints normally.
`glow_options.vsync` therefore has no effect on Wayland. That's what
vsync means there anyway, and the docs now say so.
## Testing
I tested with a small probe that calls `request_repaint` on every
`App::logic` call and counts `logic` and `ui` calls. It ran on Hyprland
0.56.2 with NVIDIA and a headless output, and I counted pings and pongs
with `WAYLAND_DEBUG=1`. Each phase lasted 10 s:
| Scenario | Before | After |
| --- | --- | --- |
| Visible (glow and wgpu) | 60 fps | 60 fps |
| Covered by a fullscreen window, glow | blocked in `eglSwapBuffers`, 0
pings answered | about 4 `logic`/s, no paints, all pings answered |
| Covered by a maximized window, glow | same (Hyprland stops the
callbacks) | same as above |
| Covered, wgpu | responsive, but 0 `logic` calls | about 4 `logic`/s |
| Window on a hidden workspace | glow blocks | about 4 `logic`/s, all
pings answered |
| Started on a hidden workspace, glow | blocked on the second swap |
about 4 `logic`/s, all pings answered |
| Shown again | resumes | resumes on the next frame callback |
| Idle | 0 CPU | 0 CPU |
X11 and other platforms: I only checked that they compile. Nothing
changes there except that `run_logic` may run if a `RedrawRequested`
takes more than 250 ms to arrive, which only calls `App::logic` one
extra time.
When winit reports `Occluded` on Wayland (rust-windowing/winit#4709),
eframe's existing occluded handling takes over for hidden workspaces.
This timeout still covers windows the compositor hides without
suspending them.
* [x] I have followed the instructions in the PR template
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Lucas Meurer <hi@lucasmerlin.me>
A Wayland compositor refuses focus to a window it did not see the user
ask for. A launcher hands its own focus over instead: it asks the
compositor for an
[xdg-activation](https://wayland.app/protocols/xdg-activation-v1) token
and passes it to the child process in `XDG_ACTIVATION_TOKEN`. On X11 the
same role is played by a startup-notification id, in
`DESKTOP_STARTUP_ID`.
winit implements both —
`WindowExtStartupNotify::request_activation_token()` and
`WindowEvent::ActivationTokenDone` — but the reply arrives as a window
event that eframe consumes, so an app has no way to see it.
Two methods on `Frame`:
```rust
frame.request_activation_token(); // no-op off Linux
// ...one or more frames later:
if let Some(token) = frame.take_activation_token() {
Command::new("some-app").env("XDG_ACTIVATION_TOKEN", token).spawn()?;
}
```
Both native backends intercept `ActivationTokenDone`, hold the token on
`Frame`, and **request a repaint**: a token is single-use and
short-lived, so an idle app must not have to wait for an unrelated event
to notice it. Nothing is delivered on platforms without an activation
protocol, so an app should give up after a deadline of its own rather
than wait forever.
Nothing to add on the app side beyond these two calls — no winit
dependency, no `cfg` of its own.
### What this replaces
The first version of this PR put a
`ViewportCommand::RequestActivationToken` and an
`Event::ActivationTokenReceived` in `egui` itself. @lucasmerlin pointed
out this belongs in eframe rather than in the core, which is right:
`egui` has no business knowing what xdg-activation is, and eframe is
already where the native-specific surface lives.
### Checked
- both backends, glow and wgpu
- both arms of the `cfg_select!`: the Linux one as-is, the fallback by
temporarily pointing the predicate at another `target_os` (winit won't
build on Linux without `wayland` or `x11`)
- the real case this comes from: a launcher on GNOME/mutter spawning a
fullscreen app, which opens behind the launcher without a token and in
front with one
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!
* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
* Closes <https://github.com/emilk/egui/issues/8391>
* [x] I have followed the instructions in the PR template
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Fixes `eframe::Frame::set_wgpu_surface_config()` not changing the
present mode or frame latency.
`eframe::Frame::set_wgpu_surface_config()` wrote to the `surface_config`
of the `RenderState` inside `Frame` itself, but the one actually used to
configure the window is `egui_wgpu::winit::Painter::config.surface`.
Nothing ever propagated that write to the painter, so the two were never
synchronized.
This PR also trims the number of `SurfaceConfig`s scattered across the
structs.
## What was changed
- `RenderState` no longer stores `SurfaceConfig` **(BREAKING CHANGE)**;
- `Painter` gains `surface_config()` and `set_surface_config()`;
- `Frame::set_wgpu_surface_config()` and `Frame::wgpu_surface_config()`
now use a new field, `wgpu_surface_config: Option<SurfaceConfig>`;
- `Painter::config.surface` is now the only source of truth for the
applied `SurfaceConfig`.
* [X] I have followed the instructions in the PR template
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
## Summary
I would like to build `egui` for `wasm32-unknown-unknown`, but targeting
an environment which isn't necessarily a browser. Right now, `egui`
unconditionally depends on `web-sys` for the `DroppedFile::web_file`
function. This adds a bunch of extra dependencies and causes the export
of about 1400 `__wbindgen_*` symbols in the final WASM binary. The
existence of those symbols is causing some problems for me.
As a fix, this puts `web-sys` behind a new `web_file` feature and gates
`web_file` on it. `eframe` enables the feature on wasm32, so existing
web users are unaffected.
## Changes
- Gate `DroppedFile::web_file` behind a `web_file` feature
## Checklist
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!
* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* Keep PR description short and to the point! No long LLM slop.
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until a human has reviewed it
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
* No associated issue that I could find
* [x] I have followed the instructions in the PR template
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* Closes <https://github.com/emilk/egui/issues/5852>
* [x] I have followed the instructions in the PR template
Selecting text in a `Label` or a `TextEdit` now fills the PRIMARY
selection, and middle-clicking a `TextEdit` pastes it. This is what all
other X11 and Wayland applications do.
Testing: `tests/egui_tests/tests/test_primary_selection.rs`. Publishing
from labels and text edits, no publishing of passwords, no re-claiming
of an unchanged selection, nothing at all on non-PRIMARY platforms,
pasting at the click position rather than at the cursor, and no paste
from a click outside the widget.
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Closes#4173.
## The problem
`change_gl_context` takes an early-out when the surface is already
current, but that early-out is disabled on Windows for **every** case:
```rust
if !cfg!(target_os = "windows") {
// According to https://github.com/emilk/egui/issues/4289
// we cannot do this early-out on Windows.
```
So on Windows every frame pays `make_not_current` + `make_current` — two
`wglMakeCurrent` calls — whether or not anything changed.
## What this changes
`change_gl_context` takes a `single_viewport: bool`, and the early-out
is allowed on Windows when it is true. Call sites compute it as
`viewports.len() == 1`.
With a second viewport present the condition is false and the old path
runs unchanged, so the corruption #4289 describes is out of scope by
construction. On the `render_immediate_viewport` path the count is two
or more by definition, so it is never affected.
## Measurements
Windows 11, RTX 3060 (NVIDIA 610.74), release builds, window focused,
pointer parked off the window.
A minimal app — one viewport, one label, `request_repaint()` every
frame, i.e. the "light application" from #4173:
```rust
fn main() -> eframe::Result {
eframe::run_ui_native("bench", eframe::NativeOptions::default(), |ui, _frame| {
ui.label("bench");
ui.ctx().request_repaint();
})
}
```
Interleaved runs, alternating binaries, 8 s samples, process CPU:
| | runs (% of one core) | median |
|---|---|---|
| `main` | 104.1, 100.0, 97.0, 96.0, 98.3 | **98.3** |
| this PR | 2.3, 10.1, 20.2, 9.3, 3.1 | **9.3** |
The two sets do not overlap. `main` sits at a whole core for an
application that draws one label.
Per-scope numbers from a real application (a launcher with an animated
panel, 30 fps, `profiling` + puffin), µs of CPU per frame:
| scope | `main` | this PR |
|---|---|---|
| `change_gl_context` | 550 | **1.0** |
| egui pass (incl. the app's own `ui`) | 152 | 141 |
| `swap_buffers` | 21 | 103 |
| `update_viewport_info` | 65 | 65 |
| tessellation | 59 | 53 |
| painting | 26 | 22 |
| **whole frame** | **917** | **422** |
`swap_buffers` rises because it now does the waiting the context switch
used to absorb — a blocking wait, not work. That application went from
7.4–11.3% to 2.7–3.5% of one core.
## Checking #4289 has not come back
`examples/multiple_viewports`, forced onto the glow backend, with both
the immediate and the deferred child viewport opened from the first
frame, plus a temporary log of which branch `change_gl_context` took:
```
Count Name
----- ----
22 single_viewport=false <- three viewports open: old path
1 single_viewport=true <- first frame, before the children exist
```
Ran for 7 s with three viewports, no crash, no flicker, nothing on
stderr. Neither the log nor the forced-open change is part of this PR.
## Caveats, honestly
- One machine, one GPU vendor, one Windows version. I have no way to
test AMD or Intel, or an older Windows.
- In #4173, @gerwin3 reported that #4284 — which enabled this early-out
without the viewport-count guard — "did not noticeably decrease" CPU for
them. I cannot reproduce that; the numbers above are unambiguous on my
machine. My guess is that they were also hitting a second, unrelated
thing: `Context::request_repaint_after` subtracts `predicted_dt`, and
nothing in `egui-winit` ever assigns it, so it stays at its `1/60`
default and a throttled application still runs at vsync (see #5353).
That would put a `hello_world` measurement at the display's rate
regardless of this change. That is a hypothesis, not something I have
verified on their setup.
- `cargo fmt --all --check` is clean and `cargo clippy -p eframe
--no-default-features --features glow,default_fonts --all-targets`
reports no warnings. I have not run the full `scripts/check.sh` (wasm
toolchain).
Happy to reshape this if you would rather thread the flag differently,
or gate it on something other than the viewport count.
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
* [x] I have followed the instructions in the PR template
`DeviceEvent::MouseMotion` is device-level relative motion with no
window attached. eframe used to deliver it only to the focused viewport
and dropped it when no viewport was focused. That made raw mouse deltas
unusable in multi-viewport apps on Wayland, where another viewport can
steal focus while the pointer stays over the window the user is
interacting with.
Now eframe delivers it to the focused viewport if that viewport has the
pointer or an active drag, and otherwise to the first viewport that
does. Focus is no longer required. Only that window is repainted. glow
and wgpu behave the same.
egui-winit's guard from #7866 is kept: motion is still ignored unless
the pointer is in the window or a button is held, so moving the mouse
elsewhere on screen doesn't cause repaints.
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Preserve transparent viewport windows on Windows
Refactor window creation into create_window_for_viewport
## Description
`glutin_winit::finalize_window` may clear a window's requested
transparency when the selected GL config reports that transparency is
unsupported. On affected Windows GL paths, transparent native windows
and their GL surfaces may still composite correctly despite that report.
This can also cause a recreated root viewport to become opaque if its
transparent window is passed through `finalize_window`. Create
explicitly transparent Windows viewport windows directly instead,
including both root and child viewports. Keep using `finalize_window`
for opaque Windows windows and for windows on other platforms.
This extends the Windows workaround from the merged
[egui#8423](https://github.com/emilk/egui/pull/8423) to cover root
viewports, including when they are recreated.
eframe's glow backend asks for OpenGL 3.3 core, then for OpenGL ES 2.0.
Some Windows drivers reject both: Intel HD Graphics 3000 offers OpenGL
3.1 and lacks WGL_EXT_create_context_es2_profile, so eframe fails to
start with "extension to create ES context with wgl is not present",
although egui_glow runs fine on that hardware. A user on Windows 10 1903
got 0xC0072095 for 3.3 core, then that error for ES.
This adds a last attempt: a compatibility profile without a minimum
version, which drivers answer with the newest version they support.
egui_glow already handles GLSL 1.20 and 1.40. Every failed attempt is
logged at warn and the last error is returned.
The attempts and the try-in-order loop are small functions with unit
tests.
* [x] I have followed the instructions in the PR template
## Summary
Only the root viewport now provides window information to the native
autosave flow.
## Details
When a deferred viewport autosaves, its window size and position could
overwrite the settings used to restore the root window on the next
launch. This change passes window information to autosave only for the
root viewport in both the Glow and WGPU integrations.
Autosaving application state and egui memory remains enabled for
deferred viewports.
Add 25 new key variants to the Key enum to cover standard multimedia,
browser, launch, and Mac-specific keys:
- Browser keys: BrowserForward, BrowserRefresh, BrowserSearch,
BrowserHome, BrowserFavorites, BrowserStop
- Media keys: MediaPlayPause, MediaTrackNext, MediaTrackPrevious,
MediaStop, AudioVolumeMute, AudioVolumeDown, AudioVolumeUp
- Launch keys: LaunchMail, LaunchApp1, LaunchApp2
- Mac/system keys: Fn, Eject, Help, Power, Sleep, Clear
- Lock keys: CapsLock, NumLock, ScrollLock, PrintScreen, Pause, Menu
Also fix the 'Help' key name conflict - previously 'Help' was mapped to
Key::Insert, now it correctly maps to the new Key::Help.
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!
* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
* Closes <https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE>
* [ ] I have followed the instructions in the PR template
---------
Co-authored-by: ans1ble <ans1ble@users.noreply.github.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!
* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
* [x] I have followed the instructions in the PR template
Compiler optimization will replace these later on, but when building
without optimization they will (most often) stay divisions and divisions
are clearly slower than multiplications.
Note that the `/ 2.5` replacement is not bit-exact (since 0.4 cannot be
represented exactly, but 2.5 can), but my guess is that the
approximation is good enough. The others should be bit-exact.
(Division by 2 for unsigned numbers will be replaced to >>1 earlier in
the compile chain, so no point in doing the same there.)
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Fix: Refresh Windows title bar after theme changes
**Description**
On Windows, changing the window theme updates egui immediately, but the
native title bar may keep its previous colors until the window
activation state changes.
This sends WM_NCACTIVATE after applying ViewportCommand::SetTheme,
forcing Windows to refresh the non-client title bar state without
changing the real focus.
* Related #8299
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Lets you tell what is driving a scroll: a mouse wheel, fingers on a
trackpad (not a touch screen), or the OS continuing a trackpad swipe
with momentum.
```rust
pub enum MouseWheelSource {
Unknown,
Wheel,
Trackpad,
Momentum,
}
```
* `Event::MouseWheel` gains `source: MouseWheelSource`. Integrations set
it to `Unknown` if they don't know.
* `InputState::scroll_source() -> Option<MouseWheelSource>`: what is
driving the current scrolling, `Some` while `is_scrolling()`. For a
trackpad that covers the whole gesture (`TouchPhase::Start`…`End`); for
a mouse wheel, until the smoothing of the last notch is done. Touch
screens scroll by dragging with the pointer, not with wheel events, so
`None` there.
Use cases: a `ScrollArea` can rubber-band and hold while fingers rest on
the trackpad, but bounce during momentum (#8663, built on this). A
slider or plot can ignore `Momentum` so a flick doesn't keep changing a
value after the fingers lift.
**Where the source is known**
* macOS (eframe): `Wheel`, `Trackpad` or `Momentum`. winit folds the
macOS momentum phase into the regular `TouchPhase`, so egui-winit reads
`NSEvent::momentumPhase` itself through a local event monitor
(`macos_scroll_momentum.rs`, owned by `State`, removed on drop). Precise
deltas are `Trackpad`, line deltas `Wheel`. Goes away once we are on a
winit with rust-windowing/winit#4732; marked with TODOs.
* winit `PanGesture`: `Trackpad`.
* Everywhere else: `Unknown`. Web `WheelEvent`s carry no phase or source
at all.
**Also**: the 150 ms scroll-action timeout from #8636 is tuned for
flowing events. Fingers resting on a trackpad produce none, so a known
`Trackpad` gesture now survives a 1 s gap before being considered over.
The enum mirrors the one proposed for winit.
* [x] I have followed the instructions in the PR template
🤖 Generated with [Claude Code](https://claude.com/claude-code)
With wasm threads, `DroppedFileHandle` wasn't `Send + Sync`, so neither
was `Context`, which holds the dropped files.
That broke `egui_extras`'s `http` loader and any code moving a `Context`
to another thread, and contradicts the `context_impl_send_sync` test.
`DroppedFileHandle` is `Send + Sync` everywhere again, and eframe wraps
the `web_sys::File` in a `SendWrapper` (new dependency, `send_wrapper`
0.6).
Checked: the command from the issue, the `check_wasm_atomics` CI
command, and the regular wasm32 build of `egui_demo_app`.
This partly reverts the design of #8354, cc @grtlr.
Fixes#8401
`Context::add_glyph_rasterizer` appended a rasterizer and requested a
repaint on every call. Calling it from a setup path that runs each frame
piled up duplicates and kept the UI repainting forever (we hit this in
rerun's tests, where `apply_style_and_install_loaders` runs every frame
and the harness never settled).
* `GlyphRasterizer::new` now takes a mandatory `key`: adding a
rasterizer whose key is already installed is a no-op.
* `Context`/`Fonts`/`FontsImpl::add_glyph_rasterizer` only reload fonts,
clear caches and request a repaint when something actually changed.
`Fonts::add_glyph_rasterizer` returns whether it did.
* `SvgGlyph::into_rasterizer` is keyed by cluster, the web canvas
rasterizer by a fixed name.
Written by an LLM (Claude) together with @emilk.
* [x] I have followed the instructions in the PR template
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
An inspection request is served from a frame, and a minimized or
occluded window runs none: eframe skips the whole pass, and wgpu hands
out no surface texture. An inspector attached to a backgrounded app
could only time out.
* `ViewportCommand::RequestPaintWhileHidden` asks for a painted frame
from a hidden window. It rides the command channel, which already
reaches the integration while hidden (`run_logic` hands it the pending
commands), so `Context` needs nothing new.
* eframe paints when a pending action wants paint: that command, or a
screenshot, which asks for the same thing.
* egui-wgpu captures without a surface texture: the capture renders to
its own texture anyway, and only the present needs the surface. Pending
screenshot callbacks used to be dropped silently whenever the frame
could not be acquired, which also hit visible-but-occluded windows.
`egui_inspection` sends the command, so nothing raises or focuses the
window.
Repro and manual test: `cargo run -p test_inspection_hidden_window`.
Verified on macOS: screenshots and trees are served while the window is
minimized.
Replaces:
* https://github.com/emilk/egui/pull/8566
* [x] I have followed the instructions in the PR template
Written by Claude (LLM).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Lucas Meurer <hi@lucasmerlin.me>
`GlyphRasterizer` now has a `FontPriority`:
* `FontPriority::Highest`: asked about every cluster, before any font.
Use it to override how specific glyphs looks
* `FontPriority::Lowest` (default): a fallback, only asked about
clusters no installed font (or `FontProvider`) has. Same as before.
Several rasterizers can be installed; within a tier they are asked in
order, and the first `Some` wins.
```rust
ctx.add_glyph_rasterizer(
egui::GlyphRasterizer::new(|request| (request.cluster == "…").then(|| my_ellipsis(request)))
.with_priority(egui::FontPriority::Highest),
);
```
API changes (all unreleased): `Context::set_glyph_rasterizer(Option)` →
`add_glyph_rasterizer` / `set_glyph_rasterizers(Vec)`, same on
`epaint::Fonts`.
Follow-up to:
* https://github.com/emilk/egui/pull/8512
* [x] I have followed the instructions in the PR template
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Migration guide for the changelog:
`ViewportCommand::Screenshot` was changed to be callback based.
Previously you needed to iter the input events to check for the
screenshot (but didn't need interior mutability):
```rs
[derive(Default)]
struct MyApp {
screenshot: Option<Arc<egui::ColorImage>>,
}
impl eframe::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
if ui.button("Screenshot").clicked() {
ui.send_viewport_cmd(ViewportCommand::Screenshot(UserData::default()));
}
let image = ui.input(|i| {
i.events
.iter()
.filter_map(|e| {
if let egui::Event::Screenshot { image, .. } = e {
Some(Arc::clone(image))
} else {
None
}
})
.next_back()
});
if let Some(image) = image {
self.screenshot = Some(image);
}
}
}
```
Now you need to use a mutex, channel, or some other sync primitive to
get the result:
```rs
#[derive(Default)]
struct MyApp {
screenshot: Arc<Mutex<Option<Arc<egui::ColorImage>>>>,
}
impl eframe::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
if ui.button("Screenshot").clicked() {
let ctx = ui.ctx().clone();
let screenshot_mutex = self.screenshot.clone();
ui.request_screenshot(move |screenshot| {
screenshot_mutex.lock().replace(screenshot);
ctx.request_repaint();
});
}
}
}
```
----
This implements a callback-based screenshot api for egui
Upsides over `ViewportCommand::Screenshot`:
- More convenient api: `ctx.request_screenshot(|screnshot| ...)` (and no
need to downcast UserData)
- Reading screenshot data doesn't require rendering another frame
- Should allow us to add recording as a plugin without special hooks in
egui_kittest (otherwise capturing the last frame would have required
custom hooks in kittest)
- This was also a problem in
[kittest_inspector](https://github.com/rerun-io/kittest_inspector): When
streaming a real app, the frame seen was always a couple frames behind
when the app was idle
Adds `egui::Event::PasteImage`, emitted on Ctrl+V/Cmd+V when the
clipboard holds an
image with no usable text representation (mirrors
`OutputCommand::CopyImage` for
the opposite direction). `egui-winit::Clipboard` gains `get_image()`,
backed by
`arboard::Clipboard::get_image()` — the symmetric counterpart to the
`set_image()`
already used for copy. Wired in the winit keyboard-shortcut path and in
both the
glow and wgpu eframe backends' AccessKit-driven paste action.
Straight (unmultiplied) alpha from the OS clipboard is converted via the
existing
`ColorImage::from_rgba_unmultiplied` helper rather than reinterpreting
bytes
directly, since the two aren't bit-compatible for translucent pixels.
Not covered here: the web (wasm32) target — browser clipboard image
reads are
inherently async (`Blob::array_buffer` returns a Promise), while
`Event::PasteImage`
as designed here carries an already-decoded `ColorImage`. Bridging that
needs
either an async event payload or a deferred/queued event on `AppRunner`
— more of
a design decision than a small mirrored addition, flagging it rather
than guessing.
* Related: #2108 (not fixed: web)
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
## Problem
`ViewportBuilder::with_monitor(idx)` is a **no-op on the glow backend**.
A window
built with `.with_monitor(...)` opens on the default monitor, not
fullscreen —
while the exact same code works on wgpu.
The monitor → `Fullscreen::Borderless(Some(monitor))` resolution only
lives in
`egui_winit::create_window`, which the **wgpu** backend uses. The
**glow**
backend builds its windows straight from
`egui_winit::create_winit_window_attributes`
at two sites in `glow_integration.rs` — the initial window and
per-viewport
deferred windows — so the monitor is never applied there.
## Repro
A multi-viewport app on the glow renderer with any viewport built via
`ViewportBuilder::default().with_monitor(1)` opens that window on
monitor 0,
un-fullscreen. Switching to the wgpu renderer places it correctly. Seen
on a
3-monitor GNOME/Wayland setup where the main window and secondary
viewports all
need to land borderless-fullscreen on specific outputs.
## Fix
Extract the resolution into a public
`apply_monitor_to_window_attributes` in
`egui-winit` and call it from `create_window` (unchanged behaviour) plus
both
glow window-creation sites, so `with_monitor` behaves the same on glow
and wgpu.
No public API change beyond the new helper; no behaviour change on wgpu.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fix transparent child viewports on `Windows` with `glow`
* Closes#3632
* Related #4451
* Related #5072
* Closes#7543
* Related #8116
Transparent native child viewports could become opaque on Windows when
the
selected GL config reports that it does not support transparency.
`glutin_winit::finalize_window` clears the native transparent window
attribute
in that case. However, on affected Windows GL paths, transparent native
windows
and their GL surfaces still composite correctly.
This change preserves the transparent window attribute for explicitly
transparent non-root viewports on Windows by creating those windows
directly.
Tested manually on Windows with glow:
- root transparent viewport
- deferred native child viewport
- immediate native child viewport
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!
* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
# What it does
Addition of a new system of theme plugins which allow the user to use
different rules engine to compute the style for the available
specialised widget style.
# How to use
Create a engine implementing the trait `ThemePlugin` and `ThemeStyle<S:
StyleStruct>` and implement the necessary methods, then register this
way (example for `ButtonStyle`):
```ui.add_theme::<ButtonStyle>(&mycustomengine);```
Now all button will call the `ThemeStyle<ButtonStyle>` method to compute the correct style and later use the cached value to avoid the costly computation.
If no valid `ThemeStyle<S>` or engine is available then it fallback to the default style.
* Closes part of <https://github.com/emilk/egui/issues/3284>
* [x] I have followed the instructions in the PR template
---------
Co-authored-by: adrien <221212@umons.ac.be>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Lucas Meurer <hi@lucasmerlin.me>
Instead of opting in to pedantic lints one by one, enable the whole
group and opt out of the noisy ones.
64% of the pedantic lints were already listed individually. This deletes
90 explicit lint lines, enables 51 pedantic lints we never listed, and
picks up new pedantic lints for free. Each opt-out carries its hit
count, so the cost of turning one back on is visible.
`restriction` and `nursery` stay opt-in per lint.
Stacked on top of #8430, which fixes the one real bug the new lints
found.
* [x] I have followed the instructions in the PR template
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
`image.PNG` and `cat.SVG` were not recognized as images.
Adds `egui::load::has_extension(uri, extension)`, which ignores ASCII
case and any `#fragment`, and uses it for the `.svg`, `.gif`, `.webp`
and `.png` checks.
Note: gif/webp URIs like `a#b.gif` no longer match, since the fragment
is now excluded.
* [x] I have followed the instructions in the PR template
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Closes#8326
`check_redraw_requests` switched the event loop to `ControlFlow::Poll`
every time it called `request_redraw`, and only ever restored a sleeping
control flow when a *timed* repaint was still pending. Once the last
scheduled repaint had been consumed the `Poll` was never undone, so the
loop kept spinning.
This is most visible on Wayland, where `RedrawRequested` is only
delivered after the compositor sends a frame callback: between the
request and the callback eframe burns 100% of a CPU core, so simply
moving the mouse over a reactive app pegs a core.
`request_redraw` already wakes the event loop on its own, so the `Poll`
is not needed. Drop it, and always set an explicit sleeping control flow
at the end of `check_redraw_requests`: `WaitUntil` for the earliest
scheduled repaint, `Wait` when nothing is scheduled.
**Measured effect of this patch**
Two byte-identical eframe apps (a 400-row scrolling page, free-running
at 60fps), toggling only whether `eframe` resolves to stock 0.36.0 or
this patch. Same machine and session, native Wayland (niri,
wgpu/Vulkan). Whole-process CPU is `utime+stime` from `/proc/self/stat`,
so it counts every thread — what a system monitor sees.
| configuration | whole process |
|---|---|
| eframe 0.34.3, Wayland | ~12% of a core |
| stock 0.36.0, Wayland | **99–100% of a core** |
| stock 0.36.0, XWayland (same binary) | ~15% of a core |
| **0.36.0 + this patch, Wayland** | **15–16% of a core** |
The patch restores the 0.34 baseline and matches the XWayland figure for
the same binary — ~6.5× less CPU — with frame delivery unchanged at
60fps.
Two details worth noting: the same 0.36 binary is already fine on
XWayland, so this isn't application repaint behaviour; and the per-frame
*closure* cost rises slightly (1.55 to 2.15 ms) because those frames now
run on a CPU that isn't being held at max clocks by the spin loop.
* [X] I have followed the instructions in the PR template
* Closes <https://github.com/emilk/egui/issues/8266>
* Alternative to #8385
Not the most simple or beautiful code, but it works, and makes sense.
What makes it complex: `app.logic` should still see some input (e.g.
what viewports are visible) and emit some output (e.g. "open this link",
or "focus and repaint").
## TODO
* [x] test multiple viewports
## Clanker says
Instead of teaching egui to skip book-keeping during a pass where no ui
is shown, we simply run no pass at all. Then there is nothing to
special-case: all ui state is left untouched, and the app finds
everything where it left it when the window is shown again.
* New `Context::run_logic(&raw_input, f)`: ticks app logic without a
pass, returning the `LogicOutput` (platform output + viewport commands)
that a pass would otherwise have carried, so e.g.
`ViewportCommand::Focus` still reaches the integration.
* All three eframe backends (glow, wgpu, web) call `run_logic` instead
of `run_ui` when the viewport is minimized/occluded (and has no visible
descendant viewport) or, on web, when the tab is hidden.
* `App::logic` is still called from inside the pass when the window is
visible, so it sees the current frame's input.
While hidden, `run_logic` fills in only the window state
(`RawInput::viewports` / `focused`), so the app can tell that it is
hidden. The ui input (events, time, …) is not interpreted, and is
instead given to the next real pass.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Closes#4654
* Related #4667
* [x] I have followed the instructions in the PR template
This PR avoids materializing the contents of a file that was dragged
into an egui application on the web. It does so by storing the
`web_sys::File` handle directly on WASM.
This breaks the existing API of `DroppedFile` on the web, because there
is no way to retrieve the bytes synchronously form a `DroppedFile`
anymore, forcing handling call sites to become asynchronous.
The native API remains the same.
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Replaces `home::home_dir` with `std::env::home_dir` as these functions
do the exact same thing
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!
* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
Removes dependency home from eframe by replacing `home::home_dir` with
`std::env::home_dir`. `home` was probably originally used since
`std::env::home_dir` was once deprecated because of a bug. Post Rust
version 1.87 this has been fixed and now these two functions do exactly
the same thing.
* [X] I have followed the instructions in the PR template
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!
* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
* Closes#8371
* [x] I have followed the instructions in the PR template
Adds a `link` feature to eframe to allow disabling links on egui-winit.
The feature is enabled by default so nothing changes for existing users
of eframe.
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!
* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
* Fix [the Samsung Keyboard Korean Cheonjiin layout
bug](https://github.com/emilk/egui/pull/7967#issuecomment-4098503570)
* Partially fix (does not close) #8046
* Supersedes #7914
* Supersedes #8047
* Related: #8068
* Related: #7983
* Related: #8078
* [x] I have followed the instructions in the PR template
This PR reworks the text input handling logic in eframe's web
integration, primarily in `text_agent.rs`.
It also adds a new `ImeEvent::DeleteSurrounding` variant, along with the
corresponding handling logic in `egui` to support the changes.
## Fix: Samsung Keyboard Cheonjiin issue
This PR fixes a bug reported by @rustbasic when using Samsung Keyboard's
Cheonjiin Korean layout.
Since Samsung Keyboard is only available on Samsung devices, I wasn't
able to verify it myself. The fix is based on @rustbasic's testing and
confirmation.
The root cause is that the layout relies on the preceding text to
correctly handle batchim composition. Previously, the text agent eagerly
cleared the text input after every IME composition, removing the context
too early. This PR makes that cleanup more conservative, preserving the
text when it may still be needed.
My understanding is that this is a quirk specific to Samsung Keyboard:
The IME reports that composition has finished even though it is
effectively still active and the composed text may continue to change.
## Fix: Keystrokes resetting keyboard layout (numpad/symbols/etc.)
Partially fixes#8046.
Previously, keystrokes would cause the on-screen keyboard to switch back
to its primary layout.
One remaining issue is that tapping within the active `TextEdit` to
reposition the cursor still resets the keyboard to its primary layout.
## About text suggestions
I originally planned to include text suggestion support in this PR
because #8068 implemented it.
However, adding text suggestion support would broaden the scope of this
PR, so I think it is better addressed in a separate PR.
For reference, [the reverted
implementation](https://github.com/emilk/egui/pull/8045/commits/8a4f70859c8ba1e00186db1431e8f6906d2d1426)
works fine on Android (Gboard), but not on iOS (iPadOS 17 + SwiftKey).
We had a ton of issues around `TexturesDelta` that weren't properly
applied because we early-out of some function:
* https://github.com/emilk/egui/pull/8313
* https://github.com/emilk/egui/pull/8250
* https://github.com/emilk/egui/pull/8279
This PR changes texture updates, so that we always store them after
taking them out of `FullOutput` and keep the delta around until it's
actually applied (by passing &mut refs and draining instead of
iterating). So even if we add a new early return somewhere, that can't
break texture updates.
It also optimizes `TexturesDelta::append` by dropping any previous
deltas if there's a new `whole` delta or a `free`.
It also adds a debug assert that any `TexturesDelta` is empty when
dropped, as an additional safeguard in case the bug sneaks back in.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Follow-up to #8296, part of
<https://github.com/emilk/egui/issues/8295>
* [x] I have followed the instructions in the PR template
Stacked on #8296 (base branch), kept as a separate PR so it can be
reverted independently.
The hidden text-agent `<input>` is now inserted as a *sibling of the
canvas* (instead of appended to `document.body`) and positioned with
`offsetLeft`/`offsetTop` instead of `getBoundingClientRect`. Since the
input and the canvas share the same containing block, the input stays
anchored to the canvas top-left corner no matter how the page is
scrolled or how the canvas is embedded.
Consequences:
* Fixes the IME popup position when the host page is scrolled —
`move_to` previously wrote *viewport* coordinates from
`getBoundingClientRect` into document-absolute `left`/`top`.
* Subsumes the mobile Safari virtual-keyboard workaround (it replaced
the flapping `getBoundingClientRect` y with `offsetTop`, which is now
used everywhere), so `is_mobile_safari()` is removed.
* Removes the special-casing of document vs shadow DOM roots — sibling
insertion works uniformly in both.
* The input is `position: absolute`, so it does not participate in
flex/grid layout of the canvas' parent and causes no layout shift.
Caveat: host CSS selectors like `div > canvas:only-child` would no
longer match.
Verified with `cargo clippy -p eframe --target wasm32-unknown-unknown
--all-features` and `cargo fmt --all`.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>