Introduce explicit id field to Settings
... and use it to set the application id of the window on Unix systems, instead of relying on the title of the application.
This commit is contained in:
parent
e3bc050aae
commit
7337ab63bc
4 changed files with 25 additions and 3 deletions
|
|
@ -58,6 +58,7 @@ where
|
||||||
&application.title(),
|
&application.title(),
|
||||||
application.mode(),
|
application.mode(),
|
||||||
event_loop.primary_monitor(),
|
event_loop.primary_monitor(),
|
||||||
|
settings.id,
|
||||||
)
|
)
|
||||||
.with_menu(Some(conversion::menu(&application.menu())));
|
.with_menu(Some(conversion::menu(&application.menu())));
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,12 +4,18 @@ use crate::window;
|
||||||
/// The settings of an application.
|
/// The settings of an application.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Settings<Flags> {
|
pub struct Settings<Flags> {
|
||||||
|
/// The identifier of the application.
|
||||||
|
///
|
||||||
|
/// If provided, this identifier may be used to identify the application or
|
||||||
|
/// communicate with it through the windowing system.
|
||||||
|
pub id: Option<String>,
|
||||||
|
|
||||||
/// The window settings.
|
/// The window settings.
|
||||||
///
|
///
|
||||||
/// They will be ignored on the Web.
|
/// They will be ignored on the Web.
|
||||||
pub window: window::Settings,
|
pub window: window::Settings,
|
||||||
|
|
||||||
/// The data needed to initialize an [`Application`].
|
/// The data needed to initialize the [`Application`].
|
||||||
///
|
///
|
||||||
/// [`Application`]: crate::Application
|
/// [`Application`]: crate::Application
|
||||||
pub flags: Flags,
|
pub flags: Flags,
|
||||||
|
|
@ -58,6 +64,7 @@ impl<Flags> Settings<Flags> {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
flags,
|
flags,
|
||||||
|
id: default_settings.id,
|
||||||
window: default_settings.window,
|
window: default_settings.window,
|
||||||
default_font: default_settings.default_font,
|
default_font: default_settings.default_font,
|
||||||
default_text_size: default_settings.default_text_size,
|
default_text_size: default_settings.default_text_size,
|
||||||
|
|
@ -74,8 +81,9 @@ where
|
||||||
{
|
{
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
flags: Default::default(),
|
id: None,
|
||||||
window: Default::default(),
|
window: Default::default(),
|
||||||
|
flags: Default::default(),
|
||||||
default_font: Default::default(),
|
default_font: Default::default(),
|
||||||
default_text_size: 20,
|
default_text_size: 20,
|
||||||
text_multithreading: false,
|
text_multithreading: false,
|
||||||
|
|
@ -89,6 +97,7 @@ where
|
||||||
impl<Flags> From<Settings<Flags>> for iced_winit::Settings<Flags> {
|
impl<Flags> From<Settings<Flags>> for iced_winit::Settings<Flags> {
|
||||||
fn from(settings: Settings<Flags>) -> iced_winit::Settings<Flags> {
|
fn from(settings: Settings<Flags>) -> iced_winit::Settings<Flags> {
|
||||||
iced_winit::Settings {
|
iced_winit::Settings {
|
||||||
|
id: settings.id,
|
||||||
window: settings.window.into(),
|
window: settings.window.into(),
|
||||||
flags: settings.flags,
|
flags: settings.flags,
|
||||||
exit_on_close_request: settings.exit_on_close_request,
|
exit_on_close_request: settings.exit_on_close_request,
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,7 @@ where
|
||||||
&application.title(),
|
&application.title(),
|
||||||
application.mode(),
|
application.mode(),
|
||||||
event_loop.primary_monitor(),
|
event_loop.primary_monitor(),
|
||||||
|
settings.id,
|
||||||
)
|
)
|
||||||
.with_menu(Some(conversion::menu(&application.menu())))
|
.with_menu(Some(conversion::menu(&application.menu())))
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,12 @@ use winit::window::WindowBuilder;
|
||||||
/// The settings of an application.
|
/// The settings of an application.
|
||||||
#[derive(Debug, Clone, Default)]
|
#[derive(Debug, Clone, Default)]
|
||||||
pub struct Settings<Flags> {
|
pub struct Settings<Flags> {
|
||||||
|
/// The identifier of the application.
|
||||||
|
///
|
||||||
|
/// If provided, this identifier may be used to identify the application or
|
||||||
|
/// communicate with it through the windowing system.
|
||||||
|
pub id: Option<String>,
|
||||||
|
|
||||||
/// The [`Window`] settings
|
/// The [`Window`] settings
|
||||||
pub window: Window,
|
pub window: Window,
|
||||||
|
|
||||||
|
|
@ -70,6 +76,7 @@ impl Window {
|
||||||
title: &str,
|
title: &str,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
primary_monitor: Option<MonitorHandle>,
|
primary_monitor: Option<MonitorHandle>,
|
||||||
|
_id: Option<String>,
|
||||||
) -> WindowBuilder {
|
) -> WindowBuilder {
|
||||||
let mut window_builder = WindowBuilder::new();
|
let mut window_builder = WindowBuilder::new();
|
||||||
|
|
||||||
|
|
@ -112,7 +119,10 @@ impl Window {
|
||||||
))]
|
))]
|
||||||
{
|
{
|
||||||
use ::winit::platform::unix::WindowBuilderExtUnix;
|
use ::winit::platform::unix::WindowBuilderExtUnix;
|
||||||
window_builder = window_builder.with_app_id(title.to_string());
|
|
||||||
|
if let Some(id) = _id {
|
||||||
|
window_builder = window_builder.with_app_id(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
|
|
@ -122,6 +132,7 @@ impl Window {
|
||||||
if let Some(parent) = self.platform_specific.parent {
|
if let Some(parent) = self.platform_specific.parent {
|
||||||
window_builder = window_builder.with_parent_window(parent);
|
window_builder = window_builder.with_parent_window(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
window_builder = window_builder
|
window_builder = window_builder
|
||||||
.with_drag_and_drop(self.platform_specific.drag_and_drop);
|
.with_drag_and_drop(self.platform_specific.drag_and_drop);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue