From 83b60beba6ef53a10e3fa63eb0716372268ba199 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Thu, 13 Feb 2020 05:48:58 +0300 Subject: [PATCH] on Wayland, Add HiDPI cursor support (#1454) Fixes #727. --- CHANGELOG.md | 1 + Cargo.toml | 2 +- src/platform_impl/linux/wayland/event_loop.rs | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3bcf516..5876b529 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - On Wayland, fix coordinates in touch events when scale factor isn't 1. - On Wayland, fix color from `close_button_icon_color` not applying. - Ignore locale if unsupported by X11 backend +- On Wayland, Add HiDPI cursor support # 0.21.0 (2020-02-04) diff --git a/Cargo.toml b/Cargo.toml index 47443b6f..b537dca4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,7 @@ features = [ wayland-client = { version = "0.23.0", features = [ "dlopen", "egl", "cursor", "eventloop"] } mio = "0.6" mio-extras = "2.0" -smithay-client-toolkit = "0.6" +smithay-client-toolkit = "^0.6.6" x11-dl = "2.18.3" percent-encoding = "2.0" diff --git a/src/platform_impl/linux/wayland/event_loop.rs b/src/platform_impl/linux/wayland/event_loop.rs index 1ceedf19..4a1e1959 100644 --- a/src/platform_impl/linux/wayland/event_loop.rs +++ b/src/platform_impl/linux/wayland/event_loop.rs @@ -90,6 +90,7 @@ pub struct CursorManager { locked_pointers: Vec, cursor_visible: bool, current_cursor: CursorIcon, + scale_factor: u32, } impl CursorManager { @@ -101,6 +102,7 @@ impl CursorManager { locked_pointers: Vec::new(), cursor_visible: true, current_cursor: CursorIcon::default(), + scale_factor: 1, } } @@ -145,6 +147,11 @@ impl CursorManager { } } + pub fn update_scale_factor(&mut self, scale: u32) { + self.scale_factor = scale; + self.reload_cursor_style(); + } + fn set_cursor_icon_impl(&mut self, cursor: CursorIcon) { let cursor = match cursor { CursorIcon::Alias => "link", @@ -193,7 +200,7 @@ impl CursorManager { for pointer in self.pointers.iter() { // Ignore erros, since we don't want to fail hard in case we can't find a proper cursor // in a given theme. - let _ = pointer.set_cursor(cursor, None); + let _ = pointer.set_cursor_with_scale(cursor, self.scale_factor, None); } } @@ -728,6 +735,13 @@ impl EventLoop { } if let Some(dpi) = window.new_dpi { + // Update cursor scale factor + { + self.cursor_manager + .lock() + .unwrap() + .update_scale_factor(dpi as u32); + }; let dpi = dpi as f64; let logical_size = LogicalSize::::from(*window.size); let mut new_inner_size = logical_size.to_physical(dpi); @@ -742,6 +756,8 @@ impl EventLoop { let (w, h) = new_inner_size.to_logical::(dpi).into(); frame.resize(w, h); + // Refresh frame to rescale decorations + frame.refresh(); *window.size = (w, h); } }