Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional app_id field to eframe's NativeOptions for Wayland #3007

Merged
merged 4 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/eframe/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C
#### Desktop/Native:
* 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)).
* Add `eframe::run_simple_native` - a simple API for simple apps ([#2453](https://github.com/emilk/egui/pull/2453)).
* Add `NativeOptions::app_id` which allows to set the Wayland application ID under Linux ([#1600](https://github.com/emilk/egui/issues/1600)).
* Fix bug where the eframe window is never destroyed on Linux when using `run_and_return` ([#2892](https://github.com/emilk/egui/issues/2892))

#### Web:
Expand Down
40 changes: 40 additions & 0 deletions crates/eframe/src/epi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,40 @@ pub struct NativeOptions {
/// Configures wgpu instance/device/adapter/surface creation and renderloop.
#[cfg(feature = "wgpu")]
pub wgpu_options: egui_wgpu::WgpuConfiguration,

/// On Wayland: Application ID for the window.
///
/// The application ID is used in several places of the compositor, e.g. for
/// grouping windows of the same application. It is also important for
/// connecting the configuration of a `.desktop` file with the window, by
/// using the application ID as file name. This allows e.g. a proper icon
/// handling under Wayland.
///
/// See [Waylands XDG shell documentation][xdg-shell] for more information
/// on this Wayland-specific option.
///
/// [xdg-shell]: https://wayland.app/protocols/xdg-shell#xdg_toplevel:request:set_app_id
thomaskrause marked this conversation as resolved.
Show resolved Hide resolved
///
/// # Example
/// ``` no_run
/// fn main() -> eframe::Result<()> {
///
/// let mut options = eframe::NativeOptions::default();
/// // Set the application ID for Wayland only on Linux
/// #[cfg(target_os = "linux")]
/// {
/// options.app_id = Some("egui-example".to_string());
/// }
///
/// eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
/// egui::CentralPanel::default().show(ctx, |ui| {
/// ui.heading("My egui Application");
/// });
/// })
/// }
/// ```
#[cfg(all(feature = "wayland", target_os = "linux"))]
pub app_id: Option<String>,
}

#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -397,6 +431,9 @@ impl Clone for NativeOptions {
#[cfg(feature = "wgpu")]
wgpu_options: self.wgpu_options.clone(),

#[cfg(all(feature = "wayland", target_os = "linux"))]
app_id: self.app_id.clone(),

..*self
}
}
Expand Down Expand Up @@ -453,6 +490,9 @@ impl Default for NativeOptions {

#[cfg(feature = "wgpu")]
wgpu_options: egui_wgpu::WgpuConfiguration::default(),

#[cfg(all(feature = "wayland", target_os = "linux"))]
app_id: None,
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use winit::event_loop::EventLoopWindowTarget;
#[cfg(target_os = "macos")]
use winit::platform::macos::WindowBuilderExtMacOS as _;

#[cfg(all(feature = "wayland", target_os = "linux"))]
use winit::platform::wayland::WindowBuilderExtWayland as _;

#[cfg(feature = "accesskit")]
use egui::accesskit;
use egui::NumExt as _;
Expand Down Expand Up @@ -118,6 +121,11 @@ pub fn window_builder<E>(
.with_fullsize_content_view(true);
}

#[cfg(all(feature = "wayland", target_os = "linux"))]
if let Some(app_id) = &native_options.app_id {
window_builder = window_builder.with_name(app_id, "");
}

if let Some(min_size) = *min_window_size {
window_builder = window_builder.with_min_inner_size(points_to_size(min_size));
}
Expand Down