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 | |
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')
-rw-r--r-- | src/window.rs | 21 | ||||
-rw-r--r-- | src/window_controller.rs | 3 | ||||
-rw-r--r-- | src/window_manager.rs | 3 |
3 files changed, 12 insertions, 15 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) { diff --git a/src/window_controller.rs b/src/window_controller.rs index fe23f53..848730d 100644 --- a/src/window_controller.rs +++ b/src/window_controller.rs @@ -13,11 +13,10 @@ pub trait WindowController { fn fullscreen(&self) -> bool { false } fn pixel_scale(&self) -> NonZeroU32 { NON_ZERO_ONE } - fn cursor_icon(&mut self) -> Option<CursorIcon> { None } + fn cursor(&mut self) -> Option<CursorIcon> { Some(CursorIcon::Default) } fn render_request(&mut self) -> RenderRequest { RenderRequest::None } fn is_visible(&self) -> bool { true } - fn is_cursor_visible(&self) -> bool { true } fn on_init(&mut self) {} fn on_resize(&mut self, _size: Dimensions) {} diff --git a/src/window_manager.rs b/src/window_manager.rs index a5d2038..8999bcf 100644 --- a/src/window_manager.rs +++ b/src/window_manager.rs @@ -114,8 +114,7 @@ impl WindowManager { window.controller.on_process(); window.update_title(); window.update_window_size(); - window.update_cursor_icon(); - window.update_cursor_visible(); + window.update_cursor(); window.handle_render_request(); } } |