Skip to content
Open
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
28 changes: 28 additions & 0 deletions src/app_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ impl ApplicationHandle {
mac_os_config,
web_config,
font_embolden,
app_id,
}: WindowConfig,
) {
let logical_size = size.map(|size| LogicalSize::new(size.width, size.height));
Expand All @@ -338,6 +339,33 @@ impl ApplicationHandle {
.with_resizable(resizable)
.with_enabled_buttons(enabled_buttons);

// Set the application name so desktop environments can associate the
// window with its .desktop entry (dock icon, window grouping, etc).
// Without this, winit never calls set_app_id() on Wayland and windows
// have no identity at all (see lapce#2199).
#[cfg(target_os = "linux")]
if let Some(app_id) = app_id.as_deref() {
use winit::platform::x11::WindowAttributesExtX11;
window_attributes = WindowAttributesExtX11::with_name(window_attributes, app_id, app_id);
}
#[cfg(target_os = "linux")]
if let Some(app_id) = app_id.as_deref() {
use winit::platform::wayland::WindowAttributesExtWayland;
window_attributes =
WindowAttributesExtWayland::with_name(window_attributes, app_id, app_id);
}
#[cfg(target_os = "linux")]
{
// Consume the launcher's activation/startup token so the desktop
// shell immediately associates the new window with this app
// (dock icon, focus) instead of waiting for its timeout.
use winit::platform::startup_notify::EventLoopExtStartupNotify;
if let Some(token) = event_loop.read_token_from_env() {
use winit::platform::startup_notify::WindowAttributesExtStartupNotify;
window_attributes = window_attributes.with_activation_token(token);
}
}

#[cfg(target_arch = "wasm32")]
{
use wgpu::web_sys::wasm_bindgen::JsCast;
Expand Down
19 changes: 19 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub struct WindowConfig {
#[allow(dead_code)]
pub(crate) mac_os_config: Option<MacOSWindowConfig>,
pub(crate) web_config: Option<WebWindowConfig>,
/// Application identity for the desktop environment (Wayland `app_id` /
/// X11 `WM_CLASS`). Should match the application's `.desktop` file id so
/// docks/taskbars can associate windows with the app.
#[allow(dead_code)]
pub(crate) app_id: Option<String>,
}

impl Default for WindowConfig {
Expand All @@ -66,6 +71,7 @@ impl Default for WindowConfig {
font_embolden: if cfg!(target_os = "macos") { 0.2 } else { 0. },
mac_os_config: None,
web_config: None,
app_id: None,
}
}
}
Expand Down Expand Up @@ -166,6 +172,19 @@ impl WindowConfig {
self
}

/// Sets the application identity used by desktop environments to
/// associate this window with its `.desktop` entry (Wayland `app_id`,
/// X11 `WM_CLASS`).
///
/// It should match the id of the application's `.desktop` file, e.g.
/// `org.gnome.Designer`. When unset, no app_id is requested and X11
/// falls back to the binary name.
#[inline]
pub fn app_id(mut self, app_id: impl Into<String>) -> Self {
self.app_id = Some(app_id.into());
self
}

/// Sets the enabled window buttons.
///
/// The default is `WindowButtons::all()`.
Expand Down