Skip to content

Commit a5e2ccd

Browse files
committed
Fix the estimated DPR to 1 on Wayland.
On Wayland, regardless of the underlying scale factor for an output, The scale factor is 1.0 until we receive the first DPRChanged event. To correctly calculate the window sizes, we must use a DPR of 1.0 as well. Ideally we would know what the DPR of the window we're being opened in is going to be, and avoid the estimation guessing game, but that doesn't seem possible with the current interfaces provided by the window systems.
1 parent 73759da commit a5e2ccd

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1919

2020
- Crash due to assertion failure on 32-bit architectures
2121
- Segmentation fault on shutdown with Wayland
22+
- Incorrect estimated DPR with Wayland
2223

2324
### Removed
2425

Diff for: alacritty/src/display/mod.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,18 @@ pub struct Display {
188188

189189
impl Display {
190190
pub fn new<E>(config: &Config, event_loop: &EventLoop<E>) -> Result<Display, Error> {
191-
// Guess DPR based on first monitor.
192-
let estimated_dpr =
193-
event_loop.available_monitors().next().map(|m| m.scale_factor()).unwrap_or(1.);
191+
#[cfg(any(not(feature = "x11"), target_os = "macos", windows))]
192+
let is_x11 = false;
193+
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
194+
let is_x11 = event_loop.is_x11();
195+
196+
// Guess DPR based on first monitor. On Wayland the initial frame always renders at a DPR
197+
// of 1.
198+
let estimated_dpr = if cfg!(any(target_os = "macos", windows)) || is_x11 {
199+
event_loop.available_monitors().next().map(|m| m.scale_factor()).unwrap_or(1.)
200+
} else {
201+
1.
202+
};
194203

195204
// Guess the target window dimensions.
196205
let metrics = GlyphCache::static_metrics(config.ui_config.font.clone(), estimated_dpr)?;
@@ -278,11 +287,6 @@ impl Display {
278287
#[cfg(target_os = "macos")]
279288
window.set_has_shadow(config.ui_config.background_opacity() >= 1.0);
280289

281-
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
282-
let is_x11 = event_loop.is_x11();
283-
#[cfg(not(any(feature = "x11", target_os = "macos", windows)))]
284-
let is_x11 = false;
285-
286290
// On Wayland we can safely ignore this call, since the window isn't visible until you
287291
// actually draw something into it and commit those changes.
288292
#[cfg(not(any(target_os = "macos", windows)))]

0 commit comments

Comments
 (0)