diff options
author | Ben Bridle <bridle.benjamin@gmail.com> | 2024-08-04 16:18:24 +1200 |
---|---|---|
committer | Ben Bridle <bridle.benjamin@gmail.com> | 2024-08-04 16:18:24 +1200 |
commit | c141d8fe8bb9115ccb953ed6ea5b0b04bc828125 (patch) | |
tree | 01a9967c607a75141a915d340185b2952a08e9f8 /src/window.rs | |
parent | e85f41bdf72b31f6d9224cb0d9f71986cc12a15e (diff) | |
download | phosphor-c141d8fe8bb9115ccb953ed6ea5b0b04bc828125.zip |
Unify is_cursor_visible and cursor_icon callbacks
It makes sense to handle all cursor icon state at once.
Diffstat (limited to 'src/window.rs')
-rw-r--r-- | src/window.rs | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/window.rs b/src/window.rs index b280a36..1b602c8 100644 --- a/src/window.rs +++ b/src/window.rs @@ -15,7 +15,7 @@ pub struct Window { #[allow(dead_code)] context: softbuffer::Context, render_request: RenderRequest, previous_cursor_position: Option<Point>, - previous_cursor_icon: CursorIcon, + previous_cursor: Option<CursorIcon>, previous_title: String, } @@ -57,7 +57,7 @@ impl Window { context, render_request: RenderRequest::REDRAW, previous_cursor_position: None, - previous_cursor_icon: CursorIcon::Default, + previous_cursor: Some(CursorIcon::Default), previous_title: String::new(), } } @@ -74,11 +74,14 @@ impl Window { } } - pub fn update_cursor_icon(&mut self) { - let icon = self.controller.cursor_icon().unwrap_or(CursorIcon::Default); - if icon != self.previous_cursor_icon { - self.window.set_cursor_icon(icon); - self.previous_cursor_icon = icon; + pub fn update_cursor(&mut self) { + let cursor = self.controller.cursor(); + if cursor != self.previous_cursor { + self.window.set_cursor_visible(cursor.is_some()); + if let Some(icon) = cursor { + self.window.set_cursor_icon(icon); + } + self.previous_cursor = cursor; } } @@ -132,10 +135,6 @@ impl Window { } } - pub fn update_cursor_visible(&mut self) { - self.window.set_cursor_visible(self.controller.is_cursor_visible()); - } - /// Resize the frame buffer and screen surface to the new size of the window. pub fn resize_buffer_and_surface(&mut self, physical_dimensions: Dimensions) { if let Some((width, height)) = dim_to_nonzero_size(physical_dimensions) { |