-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 name
to bevy::window::Window
#7650
Conversation
8569e8a
to
80d04b6
Compare
crates/bevy_window/src/window.rs
Outdated
@@ -191,6 +193,7 @@ impl Default for Window { | |||
fn default() -> Self { | |||
Self { | |||
title: "Bevy App".to_owned(), | |||
app_id: "bevy.app".to_owned(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it an issue if several apps running at the same time have the same app_id
? Would it be better as an option, and only set it when the user actually put a value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drive-by comment: It's not semantically invalid, but it's not useful to have a bunch of unrelated programs with the same app_id
. So I'd say that it should be an Option
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made this an Option<String>
type and None
by default now.
winit_window_builder = winit::platform::wayland::WindowBuilderExtWayland::with_name( | ||
winit_window_builder, | ||
window.app_id.clone(), | ||
"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value should be explained
winit_window_builder = winit::platform::x11::WindowBuilderExtX11::with_name( | ||
winit_window_builder, | ||
window.app_id.clone(), | ||
"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this value should be explained
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the docs on the field be already enough?
is it an issue to have both x11 and wayland features enabled, and have both methods called? |
From looking at the winit code, no: both of them set |
8e7f1e3
to
c7fc907
Compare
I'm very sorry for such a long delay! After almost a year, I finally remembered this PR. I've rebased it onto the latest bevy and updated some documentation. The concept of application ID or |
The equivalent of this on Windows is window class names, which |
@musjj Thanks! Didn't find this before. I will update this patch ASAP. |
Co-authored-by: François <mockersf@gmail.com>
Co-authored-by: François <mockersf@gmail.com>
app_id
to bevy::window::Window
name
to bevy::window::Window
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unable to test, but code looks good
/// - **`macOS`**, **`iOS`**, **`Android`**, and **`Web`**: not applicable. | ||
/// | ||
/// Notes: Changing this field during runtime will have no effect for now. | ||
pub name: Option<String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be a &'static str instead? Given that it's not supposed to be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Done in the following commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh it failed to build after turning the type of name
into Option<&'static str>
:
error: implementation of `cursor::_::_serde::Deserialize` is not general enough
--> crates/bevy_window/src/window.rs:121:35
|
121 | #[derive(Component, Debug, Clone, Reflect)]
| ^^^^^^^ implementation of `cursor::_::_serde::Deserialize` is not general enough
|
= note: `window::Window` must implement `cursor::_::_serde::Deserialize<'0>`, for any lifetime `'0`...
= note: ...but it actually implements `cursor::_::_serde::Deserialize<'static>`
= note: this error originates in the derive macro `Reflect` (in Nightly builds, run with -Z macro-backtrace for more info)
error: could not compile `bevy_window` (lib) due to previous error
How to #[derive(Reflect)]
a type with a component whose type is Option<&'static str>
? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bevy_reflect
supports type with 'static
lifetimes, but the situation here seems more complex. Reverted it because I'm not familiar with the mechanism of bevy_reflect
. Maybe add this optimization later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I see, no worries. It seems like Reflect
was implemented for &'static str
in #11686 so it's a bit strange that it still won't work.
# Objective - Fixes bevyengine#4188, make users could set application ID for bevy apps. ## Solution - Add `name` field to `bevy::window::Window`. Specifying this field adds different properties to the window: application ID on `Wayland`, `WM_CLASS` on `X11`, or window class name on Windows. It has no effect on other platforms. --- ## Changelog ### Added - Add `name` to `bevy::window::Window`. ## Migration Guide - Set the `bevy_window::Window`'s `name` field when needed: ```rust App::new() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "I am a window!".into(), name: Some("SpaceGameCompany.SpaceShooter".into()), ..default() }), ..default() })) .run(); ``` --------- Co-authored-by: François <mockersf@gmail.com>
# Objective - Fixes bevyengine#4188, make users could set application ID for bevy apps. ## Solution - Add `name` field to `bevy::window::Window`. Specifying this field adds different properties to the window: application ID on `Wayland`, `WM_CLASS` on `X11`, or window class name on Windows. It has no effect on other platforms. --- ## Changelog ### Added - Add `name` to `bevy::window::Window`. ## Migration Guide - Set the `bevy_window::Window`'s `name` field when needed: ```rust App::new() .add_plugins(DefaultPlugins.set(WindowPlugin { primary_window: Some(Window { title: "I am a window!".into(), name: Some("SpaceGameCompany.SpaceShooter".into()), ..default() }), ..default() })) .run(); ``` --------- Co-authored-by: François <mockersf@gmail.com>
Objective
.with_class()
inWindowDescriptor
after new winit release to allow setting window class on X11 and app_id on Wayland. #4188, make users could set application ID for bevy apps.Solution
name
field tobevy::window::Window
. Specifying this field adds different properties to the window: application ID onWayland
,WM_CLASS
onX11
, or window class name on Windows. It has no effect on other platforms.Changelog
Added
name
tobevy::window::Window
.Migration Guide
bevy_window::Window
'sname
field when needed: