diff --git a/CHANGELOG.md b/CHANGELOG.md index ac200b61..79e770e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Unreleased - On X11, fixed panic caused by dropping the window before running the event loop. +- Introduce `WindowBuilderExt::with_app_id` to allow setting the application ID on Wayland. # Version 0.18.0 (2018-11-07) diff --git a/src/os/unix.rs b/src/os/unix.rs index e166da73..3d1525b3 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -225,6 +225,13 @@ pub trait WindowBuilderExt { fn with_resize_increments(self, increments: LogicalSize) -> WindowBuilder; /// Build window with base size hint. Only implemented on X11. fn with_base_size(self, base_size: LogicalSize) -> WindowBuilder; + + /// Build window with a given application ID. It should match the `.desktop` file distributed with + /// your program. Only relevant on Wayland. + /// + /// For details about application ID conventions, see the + /// [Desktop Entry Spec](https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id) + fn with_app_id(self, app_id: String) -> WindowBuilder; } impl WindowBuilderExt for WindowBuilder { @@ -277,6 +284,12 @@ impl WindowBuilderExt for WindowBuilder { self.platform_specific.gtk_theme_variant = Some(variant); self } + + #[inline] + fn with_app_id(mut self, app_id: String) -> WindowBuilder { + self.platform_specific.app_id = Some(app_id); + self + } } /// Additional methods on `MonitorId` that are specific to Linux. diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 65eabe1e..01233354 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -46,6 +46,7 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub override_redirect: bool, pub x11_window_type: x11::util::WindowType, pub gtk_theme_variant: Option, + pub app_id: Option } lazy_static!( @@ -128,7 +129,7 @@ impl Window { ) -> Result { match *events_loop { EventsLoop::Wayland(ref events_loop) => { - wayland::Window::new(events_loop, attribs).map(Window::Wayland) + wayland::Window::new(events_loop, attribs, pl_attribs).map(Window::Wayland) }, EventsLoop::X(ref events_loop) => { x11::Window::new(events_loop, attribs, pl_attribs).map(Window::X) diff --git a/src/platform/linux/wayland/window.rs b/src/platform/linux/wayland/window.rs index 6d9da8b0..b7d5d6d9 100644 --- a/src/platform/linux/wayland/window.rs +++ b/src/platform/linux/wayland/window.rs @@ -3,7 +3,7 @@ use std::sync::{Arc, Mutex, Weak}; use {CreationError, MouseCursor, WindowAttributes}; use dpi::{LogicalPosition, LogicalSize}; -use platform::MonitorId as PlatformMonitorId; +use platform::{MonitorId as PlatformMonitorId, PlatformSpecificWindowBuilderAttributes as PlAttributes}; use window::MonitorId as RootMonitorId; use sctk::window::{ConceptFrame, Event as WEvent, Window as SWindow}; @@ -28,7 +28,7 @@ pub struct Window { } impl Window { - pub fn new(evlp: &EventsLoop, attributes: WindowAttributes) -> Result { + pub fn new(evlp: &EventsLoop, attributes: WindowAttributes, pl_attribs: PlAttributes) -> Result { let (width, height) = attributes.dimensions.map(Into::into).unwrap_or((800, 600)); // Create the window let size = Arc::new(Mutex::new((width, height))); @@ -106,6 +106,10 @@ impl Window { }, ).unwrap(); + if let Some(app_id) = pl_attribs.app_id { + frame.set_app_id(app_id); + } + for &(_, ref seat) in evlp.seats.lock().unwrap().iter() { frame.new_seat(seat); }