Update winit to 0.28

Hopefully works better on wayland!
This commit is contained in:
Imbris 2023-08-23 00:45:36 -04:00
parent 6fbca74e88
commit f5445774de
6 changed files with 302 additions and 424 deletions

629
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -157,6 +157,8 @@ clap = { version = "4.2", features = ["derive"]}
[patch.crates-io] [patch.crates-io]
vek = { git = "https://github.com/yoanlcq/vek.git", rev = "84d5cb65841d46599a986c5477341bea4456be26" } vek = { git = "https://github.com/yoanlcq/vek.git", rev = "84d5cb65841d46599a986c5477341bea4456be26" }
# patch winit to support older raw-window-handle that works with old wgpu
winit = { git = "https://github.com/Imberflur/winit.git", tag = "raw-window-handle-0.4-retro-support-v1" }
# patch wgpu so we can use wgpu-profiler crate # patch wgpu so we can use wgpu-profiler crate
# wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "a92b8549a8e2cb9dac781bafc5ed32828f3caf46" } # wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "a92b8549a8e2cb9dac781bafc5ed32828f3caf46" }
wgpu = { git = "https://github.com/pythonesque/wgpu.git", rev = "179ea209374a92837cde252f1d9ee01f628cae08" } wgpu = { git = "https://github.com/pythonesque/wgpu.git", rev = "179ea209374a92837cde252f1d9ee01f628cae08" }
@ -174,6 +176,9 @@ ntapi = { git = "https://github.com/MSxDOS/ntapi.git", rev = "9f56b149c9e2579673
# gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" } # gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" }
# gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" } # gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" }
# # Uncomment this to use a local fork of winit (for testing purposes)
# winit = { path = "../winit" }
# # Uncomment this to use a local fork of wgpu (for testing purposes) # # Uncomment this to use a local fork of wgpu (for testing purposes)
# [patch.'https://github.com/gfx-rs/wgpu'] # [patch.'https://github.com/gfx-rs/wgpu']
# wgpu-core = { path = "../wgpu/wgpu-core" } # wgpu-core = { path = "../wgpu/wgpu-core" }

View File

@ -56,7 +56,7 @@ i18n-helpers = {package = "veloren-voxygen-i18n-helpers", path = "i18n-helpers"}
voxygen-egui = {package = "veloren-voxygen-egui", path = "egui", optional = true } voxygen-egui = {package = "veloren-voxygen-egui", path = "egui", optional = true }
# Graphics # Graphics
winit = {version = "0.25.0", features = ["serde"]} winit = {version = "0.28.6", features = ["serde"]}
wgpu = { version = "=0.8.0", features = ["trace", "cross"] } wgpu = { version = "=0.8.0", features = ["trace", "cross"] }
wgpu-profiler = { git = "https://github.com/Imberflur/wgpu-profiler", tag = "wgpu-0.8" } wgpu-profiler = { git = "https://github.com/Imberflur/wgpu-profiler", tag = "wgpu-0.8" }
bytemuck = { version="1.4", features=["derive"] } bytemuck = { version="1.4", features=["derive"] }
@ -71,16 +71,16 @@ cmake = "=0.1.45"
conrod_core = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"} conrod_core = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
conrod_winit = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"} conrod_winit = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
euc = "0.5.0" euc = "0.5.0"
iced = {package = "iced_native", git = "https://github.com/Imberflur/iced", tag = "winit-0.25"} iced = {package = "iced_native", git = "https://github.com/Imberflur/iced", tag = "veloren-winit-0.28"}
iced_winit = {git = "https://github.com/Imberflur/iced", tag = "winit-0.25"} iced_winit = {git = "https://github.com/Imberflur/iced", tag = "veloren-winit-0.28"}
window_clipboard = "0.2" window_clipboard = "0.3"
glyph_brush = "0.7.0" glyph_brush = "0.7.0"
keyboard-keynames = "0.1.2" # https://gitlab.com/Frinksy/keyboard-keynames/-/merge_requests/8
keyboard-keynames = { git = "https://gitlab.com/Imbris/keyboard-keynames.git", tag = "veloren-winit-0.28" }
# EGUI # EGUI
egui = {version = "0.12", optional = true } egui = {version = "0.12", optional = true }
egui_wgpu_backend = {git = "https://github.com/hasenbanck/egui_wgpu_backend.git", rev = "63a002c6a9b6c016e45806dd065864431caab621", optional = true } egui_wgpu_backend = {git = "https://github.com/hasenbanck/egui_wgpu_backend.git", rev = "63a002c6a9b6c016e45806dd065864431caab621", optional = true }
egui_winit_platform = {version = "0.8", optional = true } egui_winit_platform = { git = "https://github.com/Imberflur/egui_winit_platform.git", tag = "veloren-winit-0.28", optional = true }
# ECS # ECS
specs = { workspace = true, features = ["serde", "storage-event-control"] } specs = { workspace = true, features = ["serde", "storage-event-control"] }
@ -104,6 +104,7 @@ backtrace = "0.3.40"
bincode = { workspace = true } bincode = { workspace = true }
chrono = { workspace = true } chrono = { workspace = true }
chumsky = "0.9" chumsky = "0.9"
# TODO: unused
cpal = "0.14" cpal = "0.14"
crossbeam-utils = { workspace = true } crossbeam-utils = { workspace = true }
crossbeam-channel = { workspace = true } crossbeam-channel = { workspace = true }

View File

@ -12,7 +12,7 @@ be-dyn-lib = []
client = {package = "veloren-client", path = "../../client"} client = {package = "veloren-client", path = "../../client"}
common = {package = "veloren-common", path = "../../common"} common = {package = "veloren-common", path = "../../common"}
egui = "0.12" egui = "0.12"
egui_winit_platform = "0.8" egui_winit_platform = { git = "https://github.com/Imberflur/egui_winit_platform.git", tag = "veloren-winit-0.28" }
lazy_static = { workspace = true } lazy_static = { workspace = true }
common-dynlib = {package = "veloren-common-dynlib", path = "../../common/dynlib", optional = true} common-dynlib = {package = "veloren-common-dynlib", path = "../../common/dynlib", optional = true}

View File

@ -1548,11 +1548,12 @@ impl<'a> Widget for Video<'a> {
let bit_depths: Vec<u16> = correct_res let bit_depths: Vec<u16> = correct_res
.iter() .iter()
.filter( .filter(
|mode| match self.global_state.settings.graphics.fullscreen.refresh_rate { |mode| match self.global_state.settings.graphics.fullscreen.refresh_rate_millihertz {
Some(refresh_rate) => mode.refresh_rate() == refresh_rate, Some(rate) => mode.refresh_rate_millihertz() == rate,
None => true, None => true,
}, },
) )
// TODO: why do we sort by this and then map to it?
.sorted_by_key(|mode| mode.bit_depth()) .sorted_by_key(|mode| mode.bit_depth())
.map(|mode| mode.bit_depth()) .map(|mode| mode.bit_depth())
.rev() .rev()
@ -1601,7 +1602,7 @@ impl<'a> Widget for Video<'a> {
} }
// Refresh Rate // Refresh Rate
let refresh_rates: Vec<u16> = correct_res let refresh_rates: Vec<u32> = correct_res
.into_iter() .into_iter()
.filter( .filter(
|mode| match self.global_state.settings.graphics.fullscreen.bit_depth { |mode| match self.global_state.settings.graphics.fullscreen.bit_depth {
@ -1609,8 +1610,9 @@ impl<'a> Widget for Video<'a> {
None => true, None => true,
}, },
) )
.sorted_by_key(|mode| mode.refresh_rate()) // TODO: why do we sort by this and then map to it?
.map(|mode| mode.refresh_rate()) .sorted_by_key(|mode| mode.refresh_rate_millihertz())
.map(|mode| mode.refresh_rate_millihertz())
.rev() .rev()
.dedup() .dedup()
.collect(); .collect();
@ -1627,10 +1629,20 @@ impl<'a> Widget for Video<'a> {
once(String::from( once(String::from(
self.localized_strings.get_msg("common-automatic"), self.localized_strings.get_msg("common-automatic"),
)) ))
.chain(refresh_rates.iter().map(|rate| format!("{}", rate))) .chain(
refresh_rates
.iter()
.map(|&rate| format!("{:.1}", rate as f32 / 1000.0)),
)
.collect::<Vec<String>>() .collect::<Vec<String>>()
.as_slice(), .as_slice(),
match self.global_state.settings.graphics.fullscreen.refresh_rate { match self
.global_state
.settings
.graphics
.fullscreen
.refresh_rate_millihertz
{
Some(refresh_rate) => refresh_rates Some(refresh_rate) => refresh_rates
.iter() .iter()
.position(|rate| rate == &refresh_rate) .position(|rate| rate == &refresh_rate)
@ -1647,7 +1659,7 @@ impl<'a> Widget for Video<'a> {
.set(state.ids.refresh_rate, ui) .set(state.ids.refresh_rate, ui)
{ {
events.push(GraphicsChange::ChangeFullscreenMode(FullScreenSettings { events.push(GraphicsChange::ChangeFullscreenMode(FullScreenSettings {
refresh_rate: if clicked == 0 { refresh_rate_millihertz: if clicked == 0 {
None None
} else { } else {
Some(refresh_rates[clicked - 1]) Some(refresh_rates[clicked - 1])

View File

@ -1028,9 +1028,21 @@ impl Window {
pub fn is_cursor_grabbed(&self) -> bool { self.cursor_grabbed } pub fn is_cursor_grabbed(&self) -> bool { self.cursor_grabbed }
pub fn grab_cursor(&mut self, grab: bool) { pub fn grab_cursor(&mut self, grab: bool) {
use winit::window::CursorGrabMode;
self.cursor_grabbed = grab; self.cursor_grabbed = grab;
self.window.set_cursor_visible(!grab); self.window.set_cursor_visible(!grab);
let _ = self.window.set_cursor_grab(grab); let res = if grab {
self.window
.set_cursor_grab(CursorGrabMode::Confined)
.or_else(|_e| self.window.set_cursor_grab(CursorGrabMode::Locked))
} else {
self.window.set_cursor_grab(CursorGrabMode::None)
};
if let Err(e) = res {
error!(?e, ?grab, "Failed to toggle cursor grab");
}
} }
/// Moves mouse cursor to center of screen /// Moves mouse cursor to center of screen
@ -1073,7 +1085,7 @@ impl Window {
&self, &self,
resolution: [u16; 2], resolution: [u16; 2],
bit_depth: Option<u16>, bit_depth: Option<u16>,
refresh_rate: Option<u16>, refresh_rate_millihertz: Option<u32>,
correct_res: Option<Vec<VideoMode>>, correct_res: Option<Vec<VideoMode>>,
correct_depth: Option<Option<VideoMode>>, correct_depth: Option<Option<VideoMode>>,
correct_rate: Option<Option<VideoMode>>, correct_rate: Option<Option<VideoMode>>,
@ -1103,14 +1115,14 @@ impl Window {
.cloned() .cloned()
}); });
match refresh_rate { match refresh_rate_millihertz {
// A bit depth and a refresh rate is given // A bit depth and a refresh rate is given
Some(rate) => { Some(rate) => {
// analogous to correct_res // analogous to correct_res
let correct_rate = correct_rate.unwrap_or_else(|| { let correct_rate = correct_rate.unwrap_or_else(|| {
correct_res correct_res
.iter() .iter()
.find(|mode| mode.refresh_rate() == rate) .find(|mode| mode.refresh_rate_millihertz() == rate)
.cloned() .cloned()
}); });
@ -1121,7 +1133,7 @@ impl Window {
correct_res correct_res
.iter() .iter()
.filter(|mode| mode.bit_depth() == depth) .filter(|mode| mode.bit_depth() == depth)
.find(|mode| mode.refresh_rate() == rate) .find(|mode| mode.refresh_rate_millihertz() == rate)
.cloned() .cloned()
.or_else(|| { .or_else(|| {
if correct_depth.is_none() && correct_rate.is_none() { if correct_depth.is_none() && correct_rate.is_none() {
@ -1166,14 +1178,14 @@ impl Window {
} }
}, },
// No bit depth is given // No bit depth is given
None => match refresh_rate { None => match refresh_rate_millihertz {
// No bit depth and a refresh rate is given // No bit depth and a refresh rate is given
Some(rate) => { Some(rate) => {
// analogous to correct_res // analogous to correct_res
let correct_rate = correct_rate.unwrap_or_else(|| { let correct_rate = correct_rate.unwrap_or_else(|| {
correct_res correct_res
.iter() .iter()
.find(|mode| mode.refresh_rate() == rate) .find(|mode| mode.refresh_rate_millihertz() == rate)
.cloned() .cloned()
}); });
@ -1205,7 +1217,7 @@ impl Window {
.into_iter() .into_iter()
// Prefer bit depth over refresh rate // Prefer bit depth over refresh rate
.sorted_by_key(|mode| mode.bit_depth()) .sorted_by_key(|mode| mode.bit_depth())
.max_by_key(|mode| mode.refresh_rate()), .max_by_key(|mode| mode.refresh_rate_millihertz()),
}, },
} }
} }
@ -1214,7 +1226,7 @@ impl Window {
&self, &self,
resolution: [u16; 2], resolution: [u16; 2],
bit_depth: Option<u16>, bit_depth: Option<u16>,
refresh_rate: Option<u16>, refresh_rate_millihertz: Option<u32>,
) -> Option<VideoMode> { ) -> Option<VideoMode> {
// (resolution, bit depth, refresh rate) represents a video mode // (resolution, bit depth, refresh rate) represents a video mode
// spec: as specified // spec: as specified
@ -1225,7 +1237,14 @@ impl Window {
// (spec, spec, max), (spec, max, spec) // (spec, spec, max), (spec, max, spec)
// (spec, max, max) // (spec, max, max)
// (max, max, max) // (max, max, max)
match self.select_video_mode_rec(resolution, bit_depth, refresh_rate, None, None, None) { match self.select_video_mode_rec(
resolution,
bit_depth,
refresh_rate_millihertz,
None,
None,
None,
) {
Some(mode) => Some(mode), Some(mode) => Some(mode),
// if there is no video mode with the specified resolution, // if there is no video mode with the specified resolution,
// fall back to the video mode with max resolution, bit depth and refresh rate // fall back to the video mode with max resolution, bit depth and refresh rate
@ -1238,7 +1257,7 @@ impl Window {
let mode = monitor let mode = monitor
.video_modes() .video_modes()
// Prefer bit depth over refresh rate // Prefer bit depth over refresh rate
.sorted_by_key(|mode| mode.refresh_rate()) .sorted_by_key(|mode| mode.refresh_rate_millihertz())
.sorted_by_key(|mode| mode.bit_depth()) .sorted_by_key(|mode| mode.bit_depth())
.max_by_key(|mode| mode.size().width); .max_by_key(|mode| mode.size().width);
@ -1263,7 +1282,7 @@ impl Window {
if let Some(video_mode) = self.select_video_mode( if let Some(video_mode) = self.select_video_mode(
fullscreen.resolution, fullscreen.resolution,
fullscreen.bit_depth, fullscreen.bit_depth,
fullscreen.refresh_rate, fullscreen.refresh_rate_millihertz,
) { ) {
winit::window::Fullscreen::Exclusive(video_mode) winit::window::Fullscreen::Exclusive(video_mode)
} else { } else {
@ -1411,7 +1430,7 @@ pub struct FullScreenSettings {
pub mode: FullscreenMode, pub mode: FullscreenMode,
pub resolution: [u16; 2], pub resolution: [u16; 2],
pub bit_depth: Option<u16>, pub bit_depth: Option<u16>,
pub refresh_rate: Option<u16>, pub refresh_rate_millihertz: Option<u32>,
} }
impl Default for FullScreenSettings { impl Default for FullScreenSettings {
@ -1421,7 +1440,7 @@ impl Default for FullScreenSettings {
mode: FullscreenMode::Borderless, mode: FullscreenMode::Borderless,
resolution: [1920, 1080], resolution: [1920, 1080],
bit_depth: None, bit_depth: None,
refresh_rate: None, refresh_rate_millihertz: None,
} }
} }
} }