Skip to content

Commit 313d3f5

Browse files
committed
Add an optional app_id field to eframe's NativeOptions (emilk#1600).
This is used in the window builder to set the application ID, which is e.g. important for a proper configuration in `.desktop` files under Wayland. When no application ID is explicitly set, it defaults to the title of the window.
1 parent 7b76161 commit 313d3f5

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

crates/eframe/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C
88
#### Desktop/Native:
99
* Add `Frame::request_screenshot` and `Frame::screenshot` to communicate to the backend that a screenshot of the current frame should be exposed by `Frame` during `App::post_rendering` ([#2676](https://github.com/emilk/egui/pull/2676)).
1010
* Add `eframe::run_simple_native` - a simple API for simple apps ([#2453](https://github.com/emilk/egui/pull/2453)).
11+
* Add `NativeOptions::app_id` which allows to set the Wayland application ID ([#1600](https://github.com/emilk/egui/issues/1600)).
1112
* Fix bug where the eframe window is never destroyed on Linux when using `run_and_return` ([#2892](https://github.com/emilk/egui/issues/2892))
1213

1314
#### Web:

crates/eframe/src/epi/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,21 @@ pub struct NativeOptions {
383383
/// Configures wgpu instance/device/adapter/surface creation and renderloop.
384384
#[cfg(feature = "wgpu")]
385385
pub wgpu_options: egui_wgpu::WgpuConfiguration,
386+
387+
/// On Wayland: Application ID for the window.
388+
///
389+
/// The application ID is used in several places of the compositor, e.g. for
390+
/// grouping windows of the same application. It is also important for
391+
/// connecting the configuration of a `.desktop` file with the window, by
392+
/// using the application ID as file name. This allows e.g. a proper icon
393+
/// handling under Wayland.
394+
///
395+
/// See [Waylands XDG shell documentation][xdg-shell] for more information
396+
/// on this Wayland-specific option.
397+
///
398+
/// [xdg-shell]: https://wayland.app/protocols/xdg-shell#xdg_toplevel:request:set_app_id
399+
#[cfg(feature = "wayland")]
400+
pub app_id: Option<String>,
386401
}
387402

388403
#[cfg(not(target_arch = "wasm32"))]
@@ -397,6 +412,9 @@ impl Clone for NativeOptions {
397412
#[cfg(feature = "wgpu")]
398413
wgpu_options: self.wgpu_options.clone(),
399414

415+
#[cfg(feature = "wayland")]
416+
app_id: self.app_id.clone(),
417+
400418
..*self
401419
}
402420
}
@@ -453,6 +471,9 @@ impl Default for NativeOptions {
453471

454472
#[cfg(feature = "wgpu")]
455473
wgpu_options: egui_wgpu::WgpuConfiguration::default(),
474+
475+
#[cfg(feature = "wayland")]
476+
app_id: None,
456477
}
457478
}
458479
}

crates/eframe/src/native/epi_integration.rs

+9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ use winit::event_loop::EventLoopWindowTarget;
33
#[cfg(target_os = "macos")]
44
use winit::platform::macos::WindowBuilderExtMacOS as _;
55

6+
#[cfg(feature = "wayland")]
7+
use winit::platform::wayland::WindowBuilderExtWayland as _;
8+
69
#[cfg(feature = "accesskit")]
710
use egui::accesskit;
811
use egui::NumExt as _;
@@ -118,6 +121,12 @@ pub fn window_builder<E>(
118121
.with_fullsize_content_view(true);
119122
}
120123

124+
#[cfg(feature = "wayland")]
125+
{
126+
window_builder =
127+
window_builder.with_name(native_options.app_id.as_deref().unwrap_or(title), "");
128+
}
129+
121130
if let Some(min_size) = *min_window_size {
122131
window_builder = window_builder.with_min_inner_size(points_to_size(min_size));
123132
}

0 commit comments

Comments
 (0)