Ergonomic default value for `Window.name` when registering `DefaultPlugins`
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## What problem does this solve or what need does it fill?
Currently, the default behavior of the `WindowPlugin` is to set the default value of `name` to none. For people who care about app_id, having a standard name for all bevy_window would probably be a good idea.
Note that the "name" is different from the "title" of the window, i.e. what is displayed in window managers. The name is not displayed to the user. The "name" is useful to me because I can use my window manager to treat windows differently based on their "name", which allows to treat all bevy apps that are in development similarly (for example put them in the scratchpad on startup).
On Linux setting a default value common to every window is pretty much standard practice. I opened slay the spire and Godot was mentioned in the window information.
For games that don't have default values, It looks like steam just does this: (instance: "steam_app_2066020", class: "steam_app_2066020"). I don't have a steam game that opens multiple windows to test what it does.
## What solution would you like?
It would probably be a good idea to have a default app_id for bevy winit windows, something like "bevy_window".
## Problems:
As stated by mockersf:
> must be unique inside an application on Windows (https://learn.microsoft.com/en-us/windows/win32/winmsg/about-window-classes#class-name)
>
> So setting a default value common to every window can't work
This seems to be a big issue, because it means (as I understand) that if people want to open multiple windows on the windows operating system and don't change the default class-name, there might be undefined behavior (the website does not exactly say what happens when this is not the case and I don't have a windows machine to test this, afaik this might prevent winit from opening the window, or the error might just be handled silently by winit I don't know).
## Platforms
### For wayland:
The desktop entry specification contains information about the desktop file ID (which is specific to the executable name), not the the wm class. I believe the `StartupWMClass` key in desktop entries is what is relevant here for desktop entries and it does not need to be unique as far as i know.
I believe treating all Bevy apps as a single WMclass would be quite nice from a developer perspective, to be able to setup developer environments that treat all Bevy games similarly.
Once a game gets closer to release, it would be good practice to customize Winit configuration anyway, to set custom icons, generate a .desktop entry, etc... This would also include changing the class name to something else.
### For X:
It's not so different here, except X has two different variables: instance name and class name.
I looked at what Godot does when releasing a game, and it sets:
- `instance` to `Godot_engine` (even after release)
- `class` AND `title` to the name of your game by default.
This is quite good and should probably be copied.
### For Windows:
Unfortunately, this looks like a pain point. I did not see that `WM_CLASS` has to be process unique on Windows. I guess the only solution is to then leave the default value to `None` for windows and populate it correctly for each window.
## What to do
If the window class needs to be platform specific anyway since it will not work on windows, and it's acceptable to implement default values in a platform specific way, I believe the following default values would be quite good:
- **Wayland**: I believe its still worth setting it to "bevy_window" or "bevy_"+`DEFAULT_WINDOW_TITLE` (So it's unique) instead of none.
- **X**: Having "bevy_window" in the instance and `DEFAULT_WINDOW_TITLE` in the class seems like a reasonable default
- **Windows**: Stay at `None`
However, this is a problem in itself since `crates/bevy_window/src/window.rs`, which is where the default value is set, is platform independent. I believe adding a platform switch to this file would probably be a bad idea but I don't know what is the consensus among maintainers.
If anyone can point me on the right way to implement this while keeping `windows.rs` platform independent, or tell me that it's ok if the file becomes platform dependent, I would be ok with opening a PR for this.
## What alternative(s) have you considered?
Manually set the window name everytime I register `DefaultPlugins`.
https://taintedcoders.com/bevy/how-to/change-window-title
The tainted coder guide on how to change the window title, and its the same idea with the window name.
Contributor guide
Research direction
Read crates/bevy_window/src/window.rs and trace the WindowPlugin registration through DefaultPlugins. Then inspect how winit handles window names on Wayland, X, and Windows. Done means a platform-compatible default is established or the proposal is narrowed, while custom window names remain possible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, game-dev, operating-systems
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100