From 3683d721c7ced5dd6a8f68286a1d1d5ae62cf17d Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Mon, 14 Jul 2025 17:16:54 +0300 Subject: [PATCH] colors: add surface resize event --- userspace/graphics/colors/src/main.rs | 9 +++++++++ userspace/graphics/colors/src/sys/mod.rs | 1 + userspace/graphics/colors/src/sys/unix.rs | 8 +++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/userspace/graphics/colors/src/main.rs b/userspace/graphics/colors/src/main.rs index 65d5a77c..f3a42b02 100644 --- a/userspace/graphics/colors/src/main.rs +++ b/userspace/graphics/colors/src/main.rs @@ -301,6 +301,15 @@ impl WindowServer for Server<'_> { Command::new("/bin/colors-bar").spawn().ok(); } + fn handle_display_resize(&mut self, tx: &mut ServerSender, mut surface: DisplaySurface) { + log::info!("Display resize: {}x{}", surface.width(), surface.height()); + self.display + .resize(surface.width() as u32, surface.height() as u32); + surface.fill(self.background); + self.redraw_all(tx); + surface.present(); + } + fn handle_client_message( &mut self, mut surface: DisplaySurface, diff --git a/userspace/graphics/colors/src/sys/mod.rs b/userspace/graphics/colors/src/sys/mod.rs index 642dd080..37db5036 100644 --- a/userspace/graphics/colors/src/sys/mod.rs +++ b/userspace/graphics/colors/src/sys/mod.rs @@ -32,6 +32,7 @@ pub struct Point(pub T, pub T); pub trait WindowServer { fn handle_initial(&mut self, surface: DisplaySurface); + fn handle_display_resize(&mut self, tx: &mut ServerSender, surface: DisplaySurface); fn handle_client_message( &mut self, surface: DisplaySurface, diff --git a/userspace/graphics/colors/src/sys/unix.rs b/userspace/graphics/colors/src/sys/unix.rs index e52cdbf1..db65e7c5 100644 --- a/userspace/graphics/colors/src/sys/unix.rs +++ b/userspace/graphics/colors/src/sys/unix.rs @@ -174,7 +174,13 @@ impl ApplicationHandler for Backend { let width = NonZero::new(size.width).unwrap(); let height = NonZero::new(size.height).unwrap(); surface.resize(width, height).unwrap(); - surface.buffer_mut().unwrap().present().unwrap(); + let display_surface = DisplaySurface { + inner: surface.buffer_mut().unwrap(), + width: size.width as usize, + height: size.height as usize, + }; + self.server + .handle_display_resize(&mut self.tx, display_surface); } WindowEvent::KeyboardInput { event, .. } => { if let Some(event) = convert_key_event(event) {