Skip to content

Commit bdaaf43

Browse files
authored
Try #4609:
2 parents 990d5c0 + a9ab5cc commit bdaaf43

File tree

4 files changed

+100
-2
lines changed

4 files changed

+100
-2
lines changed

crates/bevy_internal/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ filesystem_watcher = ["bevy_asset/filesystem_watcher"]
4848
serialize = ["bevy_input/serialize"]
4949

5050
# Display server protocol support (X11 is enabled by default)
51-
wayland = ["bevy_winit/wayland"]
52-
x11 = ["bevy_winit/x11"]
51+
wayland = ["bevy_winit/wayland", "bevy_window/wayland"]
52+
x11 = ["bevy_winit/x11", "bevy_window/x11"]
5353

5454
# enable rendering of font glyphs using subpixel accuracy
5555
subpixel_glyph_atlas = ["bevy_text/subpixel_glyph_atlas"]

crates/bevy_window/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ repository = "https://github.com/bevyengine/bevy"
88
license = "MIT OR Apache-2.0"
99
keywords = ["bevy"]
1010

11+
[features]
12+
wayland = []
13+
x11 = []
14+
1115
[dependencies]
1216
# bevy
1317
bevy_app = { path = "../bevy_app", version = "0.8.0-dev" }
@@ -20,3 +24,6 @@ raw-window-handle = "0.4.2"
2024

2125
[target.'cfg(target_arch = "wasm32")'.dependencies]
2226
web-sys = "0.3"
27+
28+
[package.metadata.docs.rs]
29+
features = ["x11"]

crates/bevy_window/src/window.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,26 @@ pub struct WindowDescriptor {
594594
pub resize_constraints: WindowResizeConstraints,
595595
pub scale_factor_override: Option<f64>,
596596
pub title: String,
597+
#[cfg(all(
598+
any(
599+
target_os = "linux",
600+
target_os = "freebsd",
601+
target_os = "netbsd",
602+
target_os = "openbsd"
603+
),
604+
any(feature = "x11", feature = "wayland")
605+
))]
606+
pub desktop_id: String,
607+
#[cfg(all(
608+
any(
609+
target_os = "linux",
610+
target_os = "freebsd",
611+
target_os = "netbsd",
612+
target_os = "openbsd"
613+
),
614+
feature = "x11"
615+
))]
616+
pub desktop_instance: String,
597617
#[doc(alias = "vsync")]
598618
pub present_mode: PresentMode,
599619
pub resizable: bool,
@@ -617,6 +637,26 @@ impl Default for WindowDescriptor {
617637
fn default() -> Self {
618638
WindowDescriptor {
619639
title: "app".to_string(),
640+
#[cfg(all(
641+
any(
642+
target_os = "linux",
643+
target_os = "freebsd",
644+
target_os = "netbsd",
645+
target_os = "openbsd"
646+
),
647+
any(feature = "x11", feature = "wayland")
648+
))]
649+
desktop_id: "app".to_string(),
650+
#[cfg(all(
651+
any(
652+
target_os = "linux",
653+
target_os = "freebsd",
654+
target_os = "netbsd",
655+
target_os = "openbsd"
656+
),
657+
feature = "x11"
658+
))]
659+
desktop_instance: "Main".to_string(),
620660
width: 1280.,
621661
height: 720.,
622662
position: None,

crates/bevy_winit/src/winit_windows.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ use bevy_window::{Window, WindowDescriptor, WindowId, WindowMode};
44
use raw_window_handle::HasRawWindowHandle;
55
use winit::dpi::LogicalSize;
66

7+
#[cfg(all(
8+
any(
9+
target_os = "linux",
10+
target_os = "freebsd",
11+
target_os = "netbsd",
12+
target_os = "openbsd"
13+
),
14+
any(feature = "x11", feature = "wayland")
15+
))]
16+
use winit::platform::unix::WindowBuilderExtUnix;
17+
718
#[derive(Debug, Default)]
819
pub struct WinitWindows {
920
pub windows: HashMap<winit::window::WindowId, winit::window::Window>,
@@ -102,6 +113,46 @@ impl WinitWindows {
102113
#[allow(unused_mut)]
103114
let mut winit_window_builder = winit_window_builder.with_title(&window_descriptor.title);
104115

116+
#[allow(unused_mut)]
117+
#[cfg(all(
118+
any(
119+
target_os = "linux",
120+
target_os = "freebsd",
121+
target_os = "netbsd",
122+
target_os = "openbsd"
123+
),
124+
feature = "x11"
125+
))]
126+
let mut winit_window_builder = winit_window_builder.with_class(
127+
window_descriptor.desktop_instance.clone(), // that's actually wm_instance
128+
window_descriptor.desktop_id.clone(), // and that's wm_class
129+
);
130+
/*
131+
https://github.com/rust-windowing/winit/blob/ea1c031b54438e64576353b288848c07d2068214/src/platform/unix.rs#L337
132+
337| fn with_class(self, class: String, instance: String) -> Self;
133+
https://github.com/rust-windowing/winit/blob/ea1c031b54438e64576353b288848c07d2068214/src/platform/unix.rs#L383
134+
383| fn with_class(mut self, instance: String, class: String) -> Self {
135+
136+
Because of type equality someone wrote those wrong and Rust didn't catch it!
137+
rust-analyser uses only trait declaration, therefore it shows wrong parameter names
138+
139+
This bug persists not only in 0.26.0, but also in 0.26.1
140+
The next update will be breaking, no more differentiation between x11 class and wayland appid
141+
*/
142+
143+
#[allow(unused_mut)]
144+
#[cfg(all(
145+
any(
146+
target_os = "linux",
147+
target_os = "freebsd",
148+
target_os = "netbsd",
149+
target_os = "openbsd"
150+
),
151+
feature = "wayland"
152+
))]
153+
let mut winit_window_builder =
154+
winit_window_builder.with_app_id(window_descriptor.desktop_id.clone());
155+
105156
#[cfg(target_arch = "wasm32")]
106157
{
107158
use wasm_bindgen::JsCast;

0 commit comments

Comments
 (0)