From af28d87b5d8398d524f77b81ba6e82f14501dd5b Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:00:04 +0300 Subject: [PATCH 01/32] Update fill.rs --- winit/examples/util/fill.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/winit/examples/util/fill.rs b/winit/examples/util/fill.rs index 0b1a4fb06a..6b4c8044eb 100644 --- a/winit/examples/util/fill.rs +++ b/winit/examples/util/fill.rs @@ -98,7 +98,13 @@ mod platform { surface.resize(width, height).expect("Failed to resize the softbuffer surface"); let mut buffer = surface.buffer_mut().expect("Failed to get the softbuffer buffer"); - buffer.fill(color); + + // error[E0599]: no method named `fill` found for struct `Buffer<'surface>` in the current scope + // buffer.fill(color); + + for pixel in buffer.iter_mut() { + *pixel = color; + } buffer.present().expect("Failed to present the softbuffer buffer"); }) } From 52e64280d09db3138b26bd5227238a3560b6bcf2 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 01:12:17 +0300 Subject: [PATCH 02/32] add new example --- winit/examples/win_with_soft.rs | 83 +++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 winit/examples/win_with_soft.rs diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs new file mode 100644 index 0000000000..fb4ea526c9 --- /dev/null +++ b/winit/examples/win_with_soft.rs @@ -0,0 +1,83 @@ +use std::error::Error; +use std::num::NonZeroU32; +use std::sync::Arc; +use winit::application::ApplicationHandler; +use winit::event::WindowEvent; +use winit::event_loop::{ActiveEventLoop, EventLoop}; +use winit::window::{Window, WindowAttributes, WindowId}; + +use softbuffer::{Context, Surface}; + +struct App { + window: Option>, + surface: Option, Arc>>, +} + +impl App { + fn new() -> Self { + Self { + window: None, + surface: None, + } + } +} + +impl ApplicationHandler for App { + fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) { + let attributes = WindowAttributes::default().with_title("Framebuffer Example"); + + let window: Arc = Arc::from(event_loop.create_window(attributes).unwrap()); + + let context = Context::new(window.clone()).expect("context except"); + let surface = Surface::new(&context, window.clone()).expect("surface except"); + + self.window = Some(window); + self.surface = Some(surface); + } + + fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _id: WindowId, event: WindowEvent) { + match event { + WindowEvent::CloseRequested => event_loop.exit(), + + WindowEvent::SurfaceResized(size) => { + if let Some(surface) = self.surface.as_mut() { + surface.resize( + NonZeroU32::new(size.width.max(1)).unwrap(), + NonZeroU32::new(size.height.max(1)).unwrap() + ).unwrap(); + } + } + + WindowEvent::RedrawRequested => { + if let (Some(window), Some(surface)) = (self.window.as_ref(), self.surface.as_mut()) { + let size = window.outer_size(); + + let mut buffer = surface.buffer_mut().expect("buffer except"); + + let width = size.width as usize; + for (index, pixel) in buffer.iter_mut().enumerate() { + let x = index % width; + let y = index / width; + let r = (x ^ y) as u32 & 0xFF; + let g = x as u32 % 255; + let b = 128; + *pixel = b | (g << 8) | (r << 16); + } + + buffer.present().unwrap(); + } + } + _ => (), + } + } +} + +fn main() -> Result<(), Box> { + let event_loop = EventLoop::new()?; + + let app = Box::leak(Box::new(App::new())); + + event_loop.run_app(app)?; + + Ok(()) +} \ No newline at end of file From ade77e9140747af972644002f9a4feac8aa41fde Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 13:45:19 +0300 Subject: [PATCH 03/32] Update win_with_soft.rs --- winit/examples/win_with_soft.rs | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index fb4ea526c9..af7f3411b9 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -24,8 +24,7 @@ impl App { impl ApplicationHandler for App { fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) { - let attributes = WindowAttributes::default().with_title("Framebuffer Example"); - + let attributes = WindowAttributes::default().with_title("framebuffer test"); let window: Arc = Arc::from(event_loop.create_window(attributes).unwrap()); let context = Context::new(window.clone()).expect("context except"); @@ -38,30 +37,25 @@ impl ApplicationHandler for App { fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _id: WindowId, event: WindowEvent) { match event { WindowEvent::CloseRequested => event_loop.exit(), - + WindowEvent::SurfaceResized(size) => { if let Some(surface) = self.surface.as_mut() { - surface.resize( - NonZeroU32::new(size.width.max(1)).unwrap(), - NonZeroU32::new(size.height.max(1)).unwrap() - ).unwrap(); + let w = NonZeroU32::new(size.width.max(1)).unwrap(); + let h = NonZeroU32::new(size.height.max(1)).unwrap(); + surface.resize(w, h).unwrap(); } } WindowEvent::RedrawRequested => { - if let (Some(window), Some(surface)) = (self.window.as_ref(), self.surface.as_mut()) { - let size = window.outer_size(); - - let mut buffer = surface.buffer_mut().expect("buffer except"); + if let Some(surface) = self.surface.as_mut() { + let mut buffer = surface.next_buffer().expect("buffer except"); - let width = size.width as usize; - for (index, pixel) in buffer.iter_mut().enumerate() { - let x = index % width; - let y = index / width; - let r = (x ^ y) as u32 & 0xFF; - let g = x as u32 % 255; - let b = 128; - *pixel = b | (g << 8) | (r << 16); + for (x, y, pixel) in buffer.pixels_iter() { + let red = (x % 255) as u8; + let green = (y % 255) as u8; + let blue = ((x * y) % 255) as u8; + + *pixel = softbuffer::Pixel::new_rgb(red, green, blue); } buffer.present().unwrap(); From 48ded9292bc259c538082f56b841517837e80142 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 13:59:50 +0300 Subject: [PATCH 04/32] Update win_with_soft.rs --- winit/examples/win_with_soft.rs | 47 ++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index af7f3411b9..fc92aa7c05 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -1,16 +1,20 @@ use std::error::Error; use std::num::NonZeroU32; use std::sync::Arc; +use std::time::{Duration, Instant}; + +use softbuffer::{Context, Surface}; use winit::application::ApplicationHandler; use winit::event::WindowEvent; use winit::event_loop::{ActiveEventLoop, EventLoop}; use winit::window::{Window, WindowAttributes, WindowId}; -use softbuffer::{Context, Surface}; - struct App { window: Option>, surface: Option, Arc>>, + last_frame_time: Instant, + frame_count: u32, + last_fps_print: Instant, } impl App { @@ -18,6 +22,9 @@ impl App { Self { window: None, surface: None, + last_frame_time: Instant::now(), + frame_count: 0, + last_fps_print: Instant::now(), } } } @@ -34,7 +41,12 @@ impl ApplicationHandler for App { self.surface = Some(surface); } - fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _id: WindowId, event: WindowEvent) { + fn window_event( + &mut self, + event_loop: &dyn ActiveEventLoop, + _id: WindowId, + event: WindowEvent, + ) { match event { WindowEvent::CloseRequested => event_loop.exit(), @@ -44,23 +56,38 @@ impl ApplicationHandler for App { let h = NonZeroU32::new(size.height.max(1)).unwrap(); surface.resize(w, h).unwrap(); } - } + }, WindowEvent::RedrawRequested => { if let Some(surface) = self.surface.as_mut() { + let now = Instant::now(); + self.frame_count += 1; + + if now.duration_since(self.last_fps_print) >= Duration::from_secs(1) { + let fps = self.frame_count; + println!("FPS: {}", fps); + + self.frame_count = 0; + self.last_fps_print = now; + } + let mut buffer = surface.next_buffer().expect("buffer except"); for (x, y, pixel) in buffer.pixels_iter() { let red = (x % 255) as u8; let green = (y % 255) as u8; let blue = ((x * y) % 255) as u8; - + *pixel = softbuffer::Pixel::new_rgb(red, green, blue); } buffer.present().unwrap(); + + if let Some(window) = self.window.as_ref() { + window.request_redraw(); + } } - } + }, _ => (), } } @@ -68,10 +95,10 @@ impl ApplicationHandler for App { fn main() -> Result<(), Box> { let event_loop = EventLoop::new()?; - + let app = Box::leak(Box::new(App::new())); - - event_loop.run_app(app)?; + + event_loop.run_app(app)?; Ok(()) -} \ No newline at end of file +} From 4cfeac9f7c5dde582459fbd2165769cdf09b3419 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:05:33 +0300 Subject: [PATCH 05/32] Update fill.rs --- winit/examples/util/fill.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/winit/examples/util/fill.rs b/winit/examples/util/fill.rs index 6b4c8044eb..c69348d9ad 100644 --- a/winit/examples/util/fill.rs +++ b/winit/examples/util/fill.rs @@ -97,11 +97,11 @@ mod platform { surface.resize(width, height).expect("Failed to resize the softbuffer surface"); - let mut buffer = surface.buffer_mut().expect("Failed to get the softbuffer buffer"); + let mut buffer = surface.next_buffer().expect("Failed to get the softbuffer buffer"); // error[E0599]: no method named `fill` found for struct `Buffer<'surface>` in the current scope // buffer.fill(color); - + for pixel in buffer.iter_mut() { *pixel = color; } From ce40fe5733f06bfd1a8ca4a93cfce1fe4960980d Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:06:26 +0300 Subject: [PATCH 06/32] Update fill.rs --- winit/examples/util/fill.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winit/examples/util/fill.rs b/winit/examples/util/fill.rs index c69348d9ad..3c13a1906a 100644 --- a/winit/examples/util/fill.rs +++ b/winit/examples/util/fill.rs @@ -102,7 +102,7 @@ mod platform { // error[E0599]: no method named `fill` found for struct `Buffer<'surface>` in the current scope // buffer.fill(color); - for pixel in buffer.iter_mut() { + for (_,_,pixel) in buffer.pixels_iter() { *pixel = color; } buffer.present().expect("Failed to present the softbuffer buffer"); From 38f85d2fa4e63b368323444db522db611d41953b Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:08:20 +0300 Subject: [PATCH 07/32] Update fill.rs --- winit/examples/util/fill.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/winit/examples/util/fill.rs b/winit/examples/util/fill.rs index 3c13a1906a..9355be8240 100644 --- a/winit/examples/util/fill.rs +++ b/winit/examples/util/fill.rs @@ -98,12 +98,16 @@ mod platform { surface.resize(width, height).expect("Failed to resize the softbuffer surface"); let mut buffer = surface.next_buffer().expect("Failed to get the softbuffer buffer"); - - // error[E0599]: no method named `fill` found for struct `Buffer<'surface>` in the current scope - // buffer.fill(color); - for (_,_,pixel) in buffer.pixels_iter() { - *pixel = color; + // error[E0599]: no method named `fill` found for struct `Buffer<'surface>` in the + // current scope buffer.fill(color); + + for (_, _, pixel) in buffer.pixels_iter() { + let red = ((color >> 16) & 0xff) as u8; + let green = ((color >> 8) & 0xff) as u8; + let blue = (color & 0xff) as u8; + + *pixel = softbuffer::Pixel::new_rgb(red, green, blue); } buffer.present().expect("Failed to present the softbuffer buffer"); }) From 858e04b6dde2e483f33c9c31ba195a6ee18bbeaf Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:12:48 +0300 Subject: [PATCH 08/32] Update win_with_soft.rs --- winit/examples/win_with_soft.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index fc92aa7c05..6fc1eeb4d0 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -41,6 +41,12 @@ impl ApplicationHandler for App { self.surface = Some(surface); } + fn about_to_wait(&mut self, _event_loop: &dyn ActiveEventLoop) { + if let Some(window) = self.window.as_ref() { + window.request_redraw(); + } + } + fn window_event( &mut self, event_loop: &dyn ActiveEventLoop, @@ -82,10 +88,6 @@ impl ApplicationHandler for App { } buffer.present().unwrap(); - - if let Some(window) = self.window.as_ref() { - window.request_redraw(); - } } }, _ => (), From ecf0a0ab555728b71a302d134e3581e341e9b275 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:16:50 +0300 Subject: [PATCH 09/32] Update win_with_soft.rs --- winit/examples/win_with_soft.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index 6fc1eeb4d0..3b0abdea14 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -66,17 +66,6 @@ impl ApplicationHandler for App { WindowEvent::RedrawRequested => { if let Some(surface) = self.surface.as_mut() { - let now = Instant::now(); - self.frame_count += 1; - - if now.duration_since(self.last_fps_print) >= Duration::from_secs(1) { - let fps = self.frame_count; - println!("FPS: {}", fps); - - self.frame_count = 0; - self.last_fps_print = now; - } - let mut buffer = surface.next_buffer().expect("buffer except"); for (x, y, pixel) in buffer.pixels_iter() { @@ -88,6 +77,18 @@ impl ApplicationHandler for App { } buffer.present().unwrap(); + + let now = Instant::now(); + self.frame_count += 1; + + if now.duration_since(self.last_fps_print) >= Duration::from_secs(1) { + let fps = self.frame_count; + println!("FPS: {}", fps); + + self.frame_count = 0; + self.last_fps_print = now; + } + } }, _ => (), From 109f1e2e1d0b635922ee4683a0b5391d3aa679ee Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:34:52 +0300 Subject: [PATCH 10/32] Update win_with_soft.rs --- winit/examples/win_with_soft.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index 3b0abdea14..6ce9d52716 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -12,7 +12,6 @@ use winit::window::{Window, WindowAttributes, WindowId}; struct App { window: Option>, surface: Option, Arc>>, - last_frame_time: Instant, frame_count: u32, last_fps_print: Instant, } @@ -22,7 +21,6 @@ impl App { Self { window: None, surface: None, - last_frame_time: Instant::now(), frame_count: 0, last_fps_print: Instant::now(), } From 85de3cdf9f9f90d1640ef4cd0122f239f65ac28f Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:37:26 +0300 Subject: [PATCH 11/32] Create win_with_soft_2.rs --- winit/examples/win_with_soft_2.rs | 95 +++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 winit/examples/win_with_soft_2.rs diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs new file mode 100644 index 0000000000..9c578d1e4e --- /dev/null +++ b/winit/examples/win_with_soft_2.rs @@ -0,0 +1,95 @@ +use std::error::Error; +use std::num::NonZeroU32; +use std::sync::Arc; +use std::time::{Duration, Instant}; + +use softbuffer::{Context, Pixel, Surface}; +use winit::application::ApplicationHandler; +use winit::event::WindowEvent; +use winit::event_loop::{ActiveEventLoop, EventLoop}; +use winit::window::{Window, WindowAttributes, WindowId}; + +struct App { + window: Option>, + surface: Option, Arc>>, + start_time: Instant, + frame_count: u32, + last_fps_print: Instant, +} + +impl ApplicationHandler for App { + fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) { + let window = Arc::from(event_loop.create_window(WindowAttributes::default()).unwrap()); + self.surface = + Some(Surface::new(&Context::new(window.clone()).unwrap(), window.clone()).unwrap()); + self.window = Some(window); + } + + fn about_to_wait(&mut self, _: &dyn ActiveEventLoop) { + self.window.as_ref().map(|w| w.request_redraw()); + } + + fn window_event( + &mut self, + event_loop: &dyn ActiveEventLoop, + _id: WindowId, + event: WindowEvent, + ) { + match event { + WindowEvent::CloseRequested => event_loop.exit(), + WindowEvent::SurfaceResized(size) => { + if let Some(s) = self.surface.as_mut() { + s.resize( + NonZeroU32::new(size.width.max(1)).unwrap(), + NonZeroU32::new(size.height.max(1)).unwrap(), + ) + .unwrap(); + } + }, + WindowEvent::RedrawRequested => { + if let (Some(window), Some(surface)) = (&self.window, self.surface.as_mut()) { + let mut buffer = surface.next_buffer().unwrap(); + let size = window.outer_size(); + + for (x, y, pixel) in buffer.pixels_iter() { + let wave = (time.sin() * 50.0) as u32; + let r = (x % 255) as u8; + let g = (y % 255).wrapping_add(wave as u32) as u8; + let b = (time * 100.0) as u8; + + if y > size.height / 3 && y < size.height / 2 { + *pixel = Pixel::new_rgb(r.wrapping_add(b), g, 255); + } else { + *pixel = Pixel::new_rgb(r, g, b); + } + } + buffer.present().unwrap(); + + let time = self.start_time.elapsed().as_secs_f32(); + + self.frame_count += 1; + if self.last_fps_print.elapsed() >= Duration::from_secs(1) { + window.set_title(&format!( + "FPS: {} | Size: {}x{}", + self.frame_count, size.width, size.height + )); + self.frame_count = 0; + self.last_fps_print = Instant::now(); + } + } + }, + _ => (), + } + } +} + +fn main() -> Result<(), Box> { + let mut app = App { + window: None, + surface: None, + start_time: Instant::now(), + frame_count: 0, + last_fps_print: Instant::now(), + }; + EventLoop::new()?.run_app(&mut app).map_err(Into::into) +} From c242f59f1085b27eac0472e0fba59a0d461124e7 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:38:28 +0300 Subject: [PATCH 12/32] Update win_with_soft_2.rs --- winit/examples/win_with_soft_2.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index 9c578d1e4e..807a37e5e8 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -50,6 +50,8 @@ impl ApplicationHandler for App { if let (Some(window), Some(surface)) = (&self.window, self.surface.as_mut()) { let mut buffer = surface.next_buffer().unwrap(); let size = window.outer_size(); + + let time = self.start_time.elapsed().as_secs_f32(); for (x, y, pixel) in buffer.pixels_iter() { let wave = (time.sin() * 50.0) as u32; @@ -65,7 +67,6 @@ impl ApplicationHandler for App { } buffer.present().unwrap(); - let time = self.start_time.elapsed().as_secs_f32(); self.frame_count += 1; if self.last_fps_print.elapsed() >= Duration::from_secs(1) { From 1030024ea9f62f31f01689a7efdcf7c8fff7d108 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:42:36 +0300 Subject: [PATCH 13/32] Update win_with_soft_2.rs --- winit/examples/win_with_soft_2.rs | 36 ++++++++++--------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index 807a37e5e8..cb118e3ffb 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -19,38 +19,27 @@ struct App { impl ApplicationHandler for App { fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) { - let window = Arc::from(event_loop.create_window(WindowAttributes::default()).unwrap()); - self.surface = - Some(Surface::new(&Context::new(window.clone()).unwrap(), window.clone()).unwrap()); + let window: Arc = Arc::from(event_loop.create_window(WindowAttributes::default()).unwrap()); + self.surface = Some(Surface::new(&Context::new(window.clone()).unwrap(), window.clone()).unwrap()); self.window = Some(window); } fn about_to_wait(&mut self, _: &dyn ActiveEventLoop) { - self.window.as_ref().map(|w| w.request_redraw()); + if let Some(w) = self.window.as_ref() { w.request_redraw(); } } - fn window_event( - &mut self, - event_loop: &dyn ActiveEventLoop, - _id: WindowId, - event: WindowEvent, - ) { + fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _id: WindowId, event: WindowEvent) { match event { WindowEvent::CloseRequested => event_loop.exit(), WindowEvent::SurfaceResized(size) => { if let Some(s) = self.surface.as_mut() { - s.resize( - NonZeroU32::new(size.width.max(1)).unwrap(), - NonZeroU32::new(size.height.max(1)).unwrap(), - ) - .unwrap(); + s.resize(NonZeroU32::new(size.width.max(1)).unwrap(), NonZeroU32::new(size.height.max(1)).unwrap()).unwrap(); } }, WindowEvent::RedrawRequested => { if let (Some(window), Some(surface)) = (&self.window, self.surface.as_mut()) { let mut buffer = surface.next_buffer().unwrap(); let size = window.outer_size(); - let time = self.start_time.elapsed().as_secs_f32(); for (x, y, pixel) in buffer.pixels_iter() { @@ -67,13 +56,9 @@ impl ApplicationHandler for App { } buffer.present().unwrap(); - self.frame_count += 1; if self.last_fps_print.elapsed() >= Duration::from_secs(1) { - window.set_title(&format!( - "FPS: {} | Size: {}x{}", - self.frame_count, size.width, size.height - )); + window.set_title(&format!("FPS: {} | Size: {}x{}", self.frame_count, size.width, size.height)); self.frame_count = 0; self.last_fps_print = Instant::now(); } @@ -85,12 +70,13 @@ impl ApplicationHandler for App { } fn main() -> Result<(), Box> { - let mut app = App { + let event_loop = EventLoop::new()?; + let app = Box::leak(Box::new(App { window: None, surface: None, start_time: Instant::now(), frame_count: 0, last_fps_print: Instant::now(), - }; - EventLoop::new()?.run_app(&mut app).map_err(Into::into) -} + })); + event_loop.run_app(app).map_err(Into::into) +} \ No newline at end of file From 60d584813f9cbcfc8fbac6a1332d05982df952a5 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 14:50:42 +0300 Subject: [PATCH 14/32] Update win_with_soft_2.rs --- winit/examples/win_with_soft_2.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index cb118e3ffb..8970e3a8a2 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -15,6 +15,7 @@ struct App { start_time: Instant, frame_count: u32, last_fps_print: Instant, + totla_frame_count: u64, } impl ApplicationHandler for App { @@ -40,6 +41,8 @@ impl ApplicationHandler for App { if let (Some(window), Some(surface)) = (&self.window, self.surface.as_mut()) { let mut buffer = surface.next_buffer().unwrap(); let size = window.outer_size(); + + let elapsed_total = self.start_time.elapsed(); let time = self.start_time.elapsed().as_secs_f32(); for (x, y, pixel) in buffer.pixels_iter() { @@ -57,8 +60,19 @@ impl ApplicationHandler for App { buffer.present().unwrap(); self.frame_count += 1; + self.totla_frame_count += 1; + if self.last_fps_print.elapsed() >= Duration::from_secs(1) { - window.set_title(&format!("FPS: {} | Size: {}x{}", self.frame_count, size.width, size.height)); + let avg_fps = self.totla_frame_count as f64 / elapsed_total.as_secs_f64(); + + window.set_title(&format!( + "FPS: {} | AVG: {:.2} | Size: {}x{}", + self.frame_count, + avg_fps, + size.width, + size.height + )); + self.frame_count = 0; self.last_fps_print = Instant::now(); } @@ -77,6 +91,7 @@ fn main() -> Result<(), Box> { start_time: Instant::now(), frame_count: 0, last_fps_print: Instant::now(), + totla_frame_count: 0 })); event_loop.run_app(app).map_err(Into::into) } \ No newline at end of file From 44c2b3fceccd1d2a6ef2f839de002c2a79d4b8ef Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 16:12:10 +0300 Subject: [PATCH 15/32] Update win_with_soft_2.rs --- winit/examples/win_with_soft_2.rs | 77 +++++++++++++++++++------------ 1 file changed, 47 insertions(+), 30 deletions(-) diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index 8970e3a8a2..898cb54017 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -15,64 +15,82 @@ struct App { start_time: Instant, frame_count: u32, last_fps_print: Instant, - totla_frame_count: u64, + total_frame_count: u64, } impl ApplicationHandler for App { fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) { - let window: Arc = Arc::from(event_loop.create_window(WindowAttributes::default()).unwrap()); - self.surface = Some(Surface::new(&Context::new(window.clone()).unwrap(), window.clone()).unwrap()); + let window: Arc = + Arc::from(event_loop.create_window(WindowAttributes::default()).unwrap()); + self.surface = + Some(Surface::new(&Context::new(window.clone()).unwrap(), window.clone()).unwrap()); self.window = Some(window); } fn about_to_wait(&mut self, _: &dyn ActiveEventLoop) { - if let Some(w) = self.window.as_ref() { w.request_redraw(); } + if let Some(w) = self.window.as_ref() { + w.request_redraw(); + } } - fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _id: WindowId, event: WindowEvent) { + fn window_event( + &mut self, + event_loop: &dyn ActiveEventLoop, + _id: WindowId, + event: WindowEvent, + ) { match event { WindowEvent::CloseRequested => event_loop.exit(), WindowEvent::SurfaceResized(size) => { if let Some(s) = self.surface.as_mut() { - s.resize(NonZeroU32::new(size.width.max(1)).unwrap(), NonZeroU32::new(size.height.max(1)).unwrap()).unwrap(); + s.resize( + NonZeroU32::new(size.width.max(1)).unwrap(), + NonZeroU32::new(size.height.max(1)).unwrap(), + ) + .unwrap(); } }, WindowEvent::RedrawRequested => { if let (Some(window), Some(surface)) = (&self.window, self.surface.as_mut()) { let mut buffer = surface.next_buffer().unwrap(); let size = window.outer_size(); + let elapsed = self.start_time.elapsed(); + let t = elapsed.as_secs_f32(); - let elapsed_total = self.start_time.elapsed(); - let time = self.start_time.elapsed().as_secs_f32(); + let ball_x = ((t * 1.5).sin() * 0.5 + 0.5) * size.width as f32; + let ball_y = ((t * 2.1).cos() * 0.5 + 0.5) * size.height as f32; for (x, y, pixel) in buffer.pixels_iter() { - let wave = (time.sin() * 50.0) as u32; - let r = (x % 255) as u8; - let g = (y % 255).wrapping_add(wave as u32) as u8; - let b = (time * 100.0) as u8; + let dx = x as f32 - ball_x; + let dy = y as f32 - ball_y; + let dist = (dx * dx + dy * dy).sqrt(); + + let p1 = (x as f32 * 0.01 + t).sin(); + let p2 = (y as f32 * 0.01 + t * 0.5).cos(); + let p3 = ((x as f32 + y as f32) * 0.005 + t).sin(); + let plasma = (p1 + p2 + p3) * 0.33; - if y > size.height / 3 && y < size.height / 2 { - *pixel = Pixel::new_rgb(r.wrapping_add(b), g, 255); + if dist < 50.0 { + *pixel = Pixel::new_rgb(255, 255, 255); + } else if (y as f32 + t * 50.0) % 20.0 < 2.0 { + *pixel = Pixel::new_rgb(0, 0, 0); } else { + let r = ((plasma + 1.0) * 127.0) as u8; + let g = (x % 255) as u8; + let b = (y % 255).wrapping_add((t * 20.0) as u8) as u8; *pixel = Pixel::new_rgb(r, g, b); } } buffer.present().unwrap(); self.frame_count += 1; - self.totla_frame_count += 1; - + self.total_frame_count += 1; if self.last_fps_print.elapsed() >= Duration::from_secs(1) { - let avg_fps = self.totla_frame_count as f64 / elapsed_total.as_secs_f64(); - + let avg = self.total_frame_count as f64 / elapsed.as_secs_f64(); window.set_title(&format!( - "FPS: {} | AVG: {:.2} | Size: {}x{}", - self.frame_count, - avg_fps, - size.width, - size.height + "FPS: {} | AVG: {:.2} | {}x{}", + self.frame_count, avg, size.width, size.height )); - self.frame_count = 0; self.last_fps_print = Instant::now(); } @@ -84,14 +102,13 @@ impl ApplicationHandler for App { } fn main() -> Result<(), Box> { - let event_loop = EventLoop::new()?; - let app = Box::leak(Box::new(App { + let mut app = App { window: None, surface: None, start_time: Instant::now(), frame_count: 0, last_fps_print: Instant::now(), - totla_frame_count: 0 - })); - event_loop.run_app(app).map_err(Into::into) -} \ No newline at end of file + total_frame_count: 0, + }; + EventLoop::new()?.run_app(app).map_err(Into::into) +} From 6310dc0f81177e2747124fd705a07f9942844108 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 16:13:10 +0300 Subject: [PATCH 16/32] Update win_with_soft_2.rs --- winit/examples/win_with_soft_2.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index 898cb54017..0f484a30a9 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -77,7 +77,7 @@ impl ApplicationHandler for App { } else { let r = ((plasma + 1.0) * 127.0) as u8; let g = (x % 255) as u8; - let b = (y % 255).wrapping_add((t * 20.0) as u8) as u8; + let b = (y % 255).wrapping_add((t * 20.0) as u32) as u8; *pixel = Pixel::new_rgb(r, g, b); } } From 74fabc5b8c9c3273be17adc47c54176039086b6b Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sat, 14 Mar 2026 16:20:05 +0300 Subject: [PATCH 17/32] Update win_with_soft_2.rs --- winit/examples/win_with_soft_2.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index 0f484a30a9..3e22014db5 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -56,6 +56,7 @@ impl ApplicationHandler for App { let size = window.outer_size(); let elapsed = self.start_time.elapsed(); let t = elapsed.as_secs_f32(); + let total_secs = elapsed.as_secs(); let ball_x = ((t * 1.5).sin() * 0.5 + 0.5) * size.width as f32; let ball_y = ((t * 2.1).cos() * 0.5 + 0.5) * size.height as f32; @@ -88,8 +89,8 @@ impl ApplicationHandler for App { if self.last_fps_print.elapsed() >= Duration::from_secs(1) { let avg = self.total_frame_count as f64 / elapsed.as_secs_f64(); window.set_title(&format!( - "FPS: {} | AVG: {:.2} | {}x{}", - self.frame_count, avg, size.width, size.height + "FPS: {} | AVG: {:.2} | TIME: {}s | {}x{}", + self.frame_count, avg, total_secs, size.width, size.height )); self.frame_count = 0; self.last_fps_print = Instant::now(); From 2a3a14a8278d67744dc1665ea4dc9c8fa8d5ddbe Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 03:04:17 +0300 Subject: [PATCH 18/32] complate keywrods and switch softbuffer source --- Cargo.toml | 2 +- winit-orbital/src/event_loop.rs | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 85dc5c30d4..dc68fbd242 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,7 +39,7 @@ tracing = { version = "0.1.40", default-features = false } # Dev dependencies. image = { version = "0.25.0", default-features = false } -softbuffer = { version = "0.4.6", default-features = false, features = [ +softbuffer = { git = "https://github.com/rust-windowing/softbuffer", branch = "master", default-features = false, features = [ "x11", "x11-dlopen", "wayland", diff --git a/winit-orbital/src/event_loop.rs b/winit-orbital/src/event_loop.rs index 0c4f962d5b..a44e4fbd6d 100644 --- a/winit-orbital/src/event_loop.rs +++ b/winit-orbital/src/event_loop.rs @@ -78,7 +78,8 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_BRACE_OPEN => (KeyCode::BracketLeft, None), orbclient::K_CAPS => (KeyCode::CapsLock, Some(NamedKey::CapsLock)), orbclient::K_COMMA => (KeyCode::Comma, None), - orbclient::K_CTRL => (KeyCode::ControlLeft, Some(NamedKey::Control)), + orbclient::K_CTRL | orbclient::K_LEFT_CTRL => (KeyCode::ControlLeft, Some(NamedKey::Control)), + orbclient::K_RIGHT_CTRL => (KeyCode::ControlRight, Some(NamedKey::Control)), orbclient::K_DEL => (KeyCode::Delete, Some(NamedKey::Delete)), orbclient::K_DOWN => (KeyCode::ArrowDown, Some(NamedKey::ArrowDown)), orbclient::K_END => (KeyCode::End, Some(NamedKey::End)), @@ -101,6 +102,7 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_LEFT => (KeyCode::ArrowLeft, Some(NamedKey::ArrowLeft)), orbclient::K_LEFT_SHIFT => (KeyCode::ShiftLeft, Some(NamedKey::Shift)), orbclient::K_MINUS => (KeyCode::Minus, None), + orbclient::K_NUM_0 => (KeyCode::Numpad0, None), orbclient::K_NUM_1 => (KeyCode::Numpad1, None), orbclient::K_NUM_2 => (KeyCode::Numpad2, None), @@ -111,16 +113,24 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_NUM_7 => (KeyCode::Numpad7, None), orbclient::K_NUM_8 => (KeyCode::Numpad8, None), orbclient::K_NUM_9 => (KeyCode::Numpad9, None), + orbclient::K_NUM_ASTERISK => (KeyCode::NumpadMultiply, None), + orbclient::K_NUM_ENTER => (KeyCode::NumpadEnter, Some(NamedKey::Enter)), + orbclient::K_NUM_MINUS => (KeyCode::NumpadSubtract, None), + orbclient::K_NUM_PLUS => (KeyCode::NumpadAdd, None), + orbclient::K_NUM_SLASH => (KeyCode::NumpadDivide, None), + orbclient::K_NUM_PERIOD => (KeyCode::NumpadDecimal, None), + orbclient::K_PERIOD => (KeyCode::Period, None), orbclient::K_PGDN => (KeyCode::PageDown, Some(NamedKey::PageDown)), orbclient::K_PGUP => (KeyCode::PageUp, Some(NamedKey::PageUp)), orbclient::K_QUOTE => (KeyCode::Quote, None), orbclient::K_RIGHT => (KeyCode::ArrowRight, Some(NamedKey::ArrowRight)), orbclient::K_RIGHT_SHIFT => (KeyCode::ShiftRight, Some(NamedKey::Shift)), + orbclient::K_RIGHT_SUPER => (KeyCode::MetaRight, Some(NamedKey::Meta)), orbclient::K_SEMICOLON => (KeyCode::Semicolon, None), orbclient::K_SLASH => (KeyCode::Slash, None), orbclient::K_SPACE => (KeyCode::Space, None), - orbclient::K_SUPER => (KeyCode::MetaLeft, Some(NamedKey::Meta)), + orbclient::K_SUPER | orbclient::K_LEFT_SUPER => (KeyCode::MetaLeft, Some(NamedKey::Meta)), orbclient::K_TAB => (KeyCode::Tab, Some(NamedKey::Tab)), orbclient::K_TICK => (KeyCode::Backquote, None), orbclient::K_UP => (KeyCode::ArrowUp, Some(NamedKey::ArrowUp)), @@ -128,6 +138,19 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_VOLUME_TOGGLE => (KeyCode::AudioVolumeMute, Some(NamedKey::AudioVolumeMute)), orbclient::K_VOLUME_UP => (KeyCode::AudioVolumeUp, Some(NamedKey::AudioVolumeUp)), + orbclient::K_INS => (KeyCode::Insert, Some(NamedKey::Insert)), + orbclient::K_PRTSC => (KeyCode::PrintScreen, Some(NamedKey::PrintScreen)), + orbclient::K_NUM => (KeyCode::NumLock, Some(NamedKey::NumLock)), + orbclient::K_SCROLL => (KeyCode::ScrollLock, Some(NamedKey::ScrollLock)), + orbclient::K_APP => (KeyCode::ContextMenu, Some(NamedKey::ContextMenu)), + + orbclient::K_MEDIA_FAST_FORWARD => (KeyCode::MediaFastForward, Some(NamedKey::MediaFastForward)), + orbclient::K_MEDIA_FAST_FORWARD => (KeyCode::MediaFastForward, Some(NamedKey::MediaFastForward)), + orbclient::K_MEDIA_REWIND => (KeyCode::MediaRewind, Some(NamedKey::MediaRewind)), + orbclient::K_MEDIA_STOP => (KeyCode::MediaStop, Some(NamedKey::MediaStop)), + + orbclient::K_POWER => (KeyCode::Power, Some(NamedKey::Power)), + _ => return (PhysicalKey::Unidentified(NativeKeyCode::Unidentified), None), }; (PhysicalKey::Code(key_code), named_key_opt) From e2297b7130793ebbad51006ea0cc31d212768f22 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 03:18:13 +0300 Subject: [PATCH 19/32] Update unreleased.md --- winit/src/changelog/unreleased.md | 1 + 1 file changed, 1 insertion(+) diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index 1a41586444..39b6499274 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -44,6 +44,7 @@ changelog entry. - Add `keyboard` support for OpenHarmony. - On iOS, add Apple Pencil support with force, altitude, and azimuth data. +- On Redox, add support for missing keyboard scancodes. ### Changed From 9838ef963e1c0daa37700518b8f0e9ce4d858c72 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 03:39:45 +0300 Subject: [PATCH 20/32] Update event_loop.rs --- winit-orbital/src/event_loop.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/winit-orbital/src/event_loop.rs b/winit-orbital/src/event_loop.rs index a44e4fbd6d..33fc575374 100644 --- a/winit-orbital/src/event_loop.rs +++ b/winit-orbital/src/event_loop.rs @@ -144,7 +144,6 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_SCROLL => (KeyCode::ScrollLock, Some(NamedKey::ScrollLock)), orbclient::K_APP => (KeyCode::ContextMenu, Some(NamedKey::ContextMenu)), - orbclient::K_MEDIA_FAST_FORWARD => (KeyCode::MediaFastForward, Some(NamedKey::MediaFastForward)), orbclient::K_MEDIA_FAST_FORWARD => (KeyCode::MediaFastForward, Some(NamedKey::MediaFastForward)), orbclient::K_MEDIA_REWIND => (KeyCode::MediaRewind, Some(NamedKey::MediaRewind)), orbclient::K_MEDIA_STOP => (KeyCode::MediaStop, Some(NamedKey::MediaStop)), From e10fcb2d198153b9d93ff608696b3a60b004af53 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 03:46:52 +0300 Subject: [PATCH 21/32] fix --- winit-orbital/src/event_loop.rs | 5 ++--- winit/examples/win_with_soft_2.rs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/winit-orbital/src/event_loop.rs b/winit-orbital/src/event_loop.rs index 33fc575374..97cb714dc6 100644 --- a/winit-orbital/src/event_loop.rs +++ b/winit-orbital/src/event_loop.rs @@ -78,8 +78,7 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_BRACE_OPEN => (KeyCode::BracketLeft, None), orbclient::K_CAPS => (KeyCode::CapsLock, Some(NamedKey::CapsLock)), orbclient::K_COMMA => (KeyCode::Comma, None), - orbclient::K_CTRL | orbclient::K_LEFT_CTRL => (KeyCode::ControlLeft, Some(NamedKey::Control)), - orbclient::K_RIGHT_CTRL => (KeyCode::ControlRight, Some(NamedKey::Control)), + orbclient::K_CTRL => (KeyCode::ControlLeft, Some(NamedKey::Control)), orbclient::K_DEL => (KeyCode::Delete, Some(NamedKey::Delete)), orbclient::K_DOWN => (KeyCode::ArrowDown, Some(NamedKey::ArrowDown)), orbclient::K_END => (KeyCode::End, Some(NamedKey::End)), @@ -130,7 +129,7 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_SEMICOLON => (KeyCode::Semicolon, None), orbclient::K_SLASH => (KeyCode::Slash, None), orbclient::K_SPACE => (KeyCode::Space, None), - orbclient::K_SUPER | orbclient::K_LEFT_SUPER => (KeyCode::MetaLeft, Some(NamedKey::Meta)), + orbclient::K_SUPER => (KeyCode::MetaLeft, Some(NamedKey::Meta)), orbclient::K_TAB => (KeyCode::Tab, Some(NamedKey::Tab)), orbclient::K_TICK => (KeyCode::Backquote, None), orbclient::K_UP => (KeyCode::ArrowUp, Some(NamedKey::ArrowUp)), diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index 3e22014db5..d9d135461b 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -103,7 +103,7 @@ impl ApplicationHandler for App { } fn main() -> Result<(), Box> { - let mut app = App { + let app = App { window: None, surface: None, start_time: Instant::now(), From c6bd46ccea44238e8ca0a2b1ca35f28b66be687a Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 03:49:14 +0300 Subject: [PATCH 22/32] fix: format --- winit-orbital/src/event_loop.rs | 6 ++++-- winit/examples/win_with_soft.rs | 8 +------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/winit-orbital/src/event_loop.rs b/winit-orbital/src/event_loop.rs index 97cb714dc6..9c9b1adc51 100644 --- a/winit-orbital/src/event_loop.rs +++ b/winit-orbital/src/event_loop.rs @@ -118,7 +118,7 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_NUM_PLUS => (KeyCode::NumpadAdd, None), orbclient::K_NUM_SLASH => (KeyCode::NumpadDivide, None), orbclient::K_NUM_PERIOD => (KeyCode::NumpadDecimal, None), - + orbclient::K_PERIOD => (KeyCode::Period, None), orbclient::K_PGDN => (KeyCode::PageDown, Some(NamedKey::PageDown)), orbclient::K_PGUP => (KeyCode::PageUp, Some(NamedKey::PageUp)), @@ -143,7 +143,9 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_SCROLL => (KeyCode::ScrollLock, Some(NamedKey::ScrollLock)), orbclient::K_APP => (KeyCode::ContextMenu, Some(NamedKey::ContextMenu)), - orbclient::K_MEDIA_FAST_FORWARD => (KeyCode::MediaFastForward, Some(NamedKey::MediaFastForward)), + orbclient::K_MEDIA_FAST_FORWARD => { + (KeyCode::MediaFastForward, Some(NamedKey::MediaFastForward)) + }, orbclient::K_MEDIA_REWIND => (KeyCode::MediaRewind, Some(NamedKey::MediaRewind)), orbclient::K_MEDIA_STOP => (KeyCode::MediaStop, Some(NamedKey::MediaStop)), diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index 6ce9d52716..770b8c6d8e 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -18,12 +18,7 @@ struct App { impl App { fn new() -> Self { - Self { - window: None, - surface: None, - frame_count: 0, - last_fps_print: Instant::now(), - } + Self { window: None, surface: None, frame_count: 0, last_fps_print: Instant::now() } } } @@ -86,7 +81,6 @@ impl ApplicationHandler for App { self.frame_count = 0; self.last_fps_print = now; } - } }, _ => (), From 909e0791a3ffc14ae96fe3a8b3a931a2a15af9e3 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 04:09:33 +0300 Subject: [PATCH 23/32] fix example file named "application.rs" --- winit/examples/application.rs | 48 ++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/winit/examples/application.rs b/winit/examples/application.rs index bc8d7dee69..ecbf55e287 100644 --- a/winit/examples/application.rs +++ b/winit/examples/application.rs @@ -964,32 +964,38 @@ impl WindowState { return Ok(()); } - let mut buffer = self.surface.buffer_mut()?; + let mut buffer = self.surface.next_buffer()?; // Draw a different color inside the safe area let surface_size = self.window.surface_size(); let insets = self.window.safe_area(); - for y in 0..surface_size.height { - for x in 0..surface_size.width { - let index = y as usize * surface_size.width as usize + x as usize; - if insets.left <= x - && x <= (surface_size.width - insets.right) - && insets.top <= y - && y <= (surface_size.height - insets.bottom) - { - // In safe area - buffer[index] = match self.theme { - Theme::Light => 0xffe8e8e8, // Light gray - Theme::Dark => 0xff525252, // Medium gray - }; - } else { - // Outside safe area - buffer[index] = match self.theme { - Theme::Light => 0xffffffff, // White - Theme::Dark => 0xff181818, // Dark gray - }; + for (x, y, pixel) in buffer.pixels_iter() { + let is_inside_safe_area = insets.left <= x + && x <= (surface_size.width - insets.right) + && insets.top <= y + && y <= (surface_size.height - insets.bottom); + + let color: u32 = if is_inside_safe_area { + // In safe area + match self.theme { + Theme::Light => 0xffe8e8e8, // Light gray + Theme::Dark => 0xff525252, // Medium gray } - } + } else { + // Outside safe area + match self.theme { + Theme::Light => 0xffffffff, // White + Theme::Dark => 0xff181818, // Dark gray + } + }; + + let red = ((color >> 16) & 0xff) as u8; + let green = ((color >> 8) & 0xff) as u8; + let blue = (color & 0xff) as u8; + + + *pixel = softbuffer::Pixel::new_rgb(red, green, blue); + } // Present the buffer From cfe55b4cdb5a587ffed3fdf9318912856ec153b7 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 04:12:20 +0300 Subject: [PATCH 24/32] format example named applicatio.rs --- winit/examples/application.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/winit/examples/application.rs b/winit/examples/application.rs index ecbf55e287..475af8e565 100644 --- a/winit/examples/application.rs +++ b/winit/examples/application.rs @@ -993,9 +993,7 @@ impl WindowState { let green = ((color >> 8) & 0xff) as u8; let blue = (color & 0xff) as u8; - *pixel = softbuffer::Pixel::new_rgb(red, green, blue); - } // Present the buffer From 284be22b770decb0cdc2294f63017002969d648a Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 18:20:05 +0300 Subject: [PATCH 25/32] remove keyboard mappings as requested --- winit-orbital/src/event_loop.rs | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/winit-orbital/src/event_loop.rs b/winit-orbital/src/event_loop.rs index 9c9b1adc51..0c4f962d5b 100644 --- a/winit-orbital/src/event_loop.rs +++ b/winit-orbital/src/event_loop.rs @@ -101,7 +101,6 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_LEFT => (KeyCode::ArrowLeft, Some(NamedKey::ArrowLeft)), orbclient::K_LEFT_SHIFT => (KeyCode::ShiftLeft, Some(NamedKey::Shift)), orbclient::K_MINUS => (KeyCode::Minus, None), - orbclient::K_NUM_0 => (KeyCode::Numpad0, None), orbclient::K_NUM_1 => (KeyCode::Numpad1, None), orbclient::K_NUM_2 => (KeyCode::Numpad2, None), @@ -112,20 +111,12 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_NUM_7 => (KeyCode::Numpad7, None), orbclient::K_NUM_8 => (KeyCode::Numpad8, None), orbclient::K_NUM_9 => (KeyCode::Numpad9, None), - orbclient::K_NUM_ASTERISK => (KeyCode::NumpadMultiply, None), - orbclient::K_NUM_ENTER => (KeyCode::NumpadEnter, Some(NamedKey::Enter)), - orbclient::K_NUM_MINUS => (KeyCode::NumpadSubtract, None), - orbclient::K_NUM_PLUS => (KeyCode::NumpadAdd, None), - orbclient::K_NUM_SLASH => (KeyCode::NumpadDivide, None), - orbclient::K_NUM_PERIOD => (KeyCode::NumpadDecimal, None), - orbclient::K_PERIOD => (KeyCode::Period, None), orbclient::K_PGDN => (KeyCode::PageDown, Some(NamedKey::PageDown)), orbclient::K_PGUP => (KeyCode::PageUp, Some(NamedKey::PageUp)), orbclient::K_QUOTE => (KeyCode::Quote, None), orbclient::K_RIGHT => (KeyCode::ArrowRight, Some(NamedKey::ArrowRight)), orbclient::K_RIGHT_SHIFT => (KeyCode::ShiftRight, Some(NamedKey::Shift)), - orbclient::K_RIGHT_SUPER => (KeyCode::MetaRight, Some(NamedKey::Meta)), orbclient::K_SEMICOLON => (KeyCode::Semicolon, None), orbclient::K_SLASH => (KeyCode::Slash, None), orbclient::K_SPACE => (KeyCode::Space, None), @@ -137,20 +128,6 @@ fn convert_scancode(scancode: u8) -> (PhysicalKey, Option) { orbclient::K_VOLUME_TOGGLE => (KeyCode::AudioVolumeMute, Some(NamedKey::AudioVolumeMute)), orbclient::K_VOLUME_UP => (KeyCode::AudioVolumeUp, Some(NamedKey::AudioVolumeUp)), - orbclient::K_INS => (KeyCode::Insert, Some(NamedKey::Insert)), - orbclient::K_PRTSC => (KeyCode::PrintScreen, Some(NamedKey::PrintScreen)), - orbclient::K_NUM => (KeyCode::NumLock, Some(NamedKey::NumLock)), - orbclient::K_SCROLL => (KeyCode::ScrollLock, Some(NamedKey::ScrollLock)), - orbclient::K_APP => (KeyCode::ContextMenu, Some(NamedKey::ContextMenu)), - - orbclient::K_MEDIA_FAST_FORWARD => { - (KeyCode::MediaFastForward, Some(NamedKey::MediaFastForward)) - }, - orbclient::K_MEDIA_REWIND => (KeyCode::MediaRewind, Some(NamedKey::MediaRewind)), - orbclient::K_MEDIA_STOP => (KeyCode::MediaStop, Some(NamedKey::MediaStop)), - - orbclient::K_POWER => (KeyCode::Power, Some(NamedKey::Power)), - _ => return (PhysicalKey::Unidentified(NativeKeyCode::Unidentified), None), }; (PhysicalKey::Code(key_code), named_key_opt) From bc3a2a61fef302a52bb984110f3a73f7d3fcae96 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 18:23:44 +0300 Subject: [PATCH 26/32] Update unreleased.md --- winit/src/changelog/unreleased.md | 1 - 1 file changed, 1 deletion(-) diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index 39b6499274..1a41586444 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -44,7 +44,6 @@ changelog entry. - Add `keyboard` support for OpenHarmony. - On iOS, add Apple Pencil support with force, altitude, and azimuth data. -- On Redox, add support for missing keyboard scancodes. ### Changed From d2bc9fe6950566e0422decce53f7597255a437f8 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 18:29:10 +0300 Subject: [PATCH 27/32] Update fill.rs --- winit/examples/util/fill.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/winit/examples/util/fill.rs b/winit/examples/util/fill.rs index 9355be8240..4777260f29 100644 --- a/winit/examples/util/fill.rs +++ b/winit/examples/util/fill.rs @@ -99,9 +99,6 @@ mod platform { let mut buffer = surface.next_buffer().expect("Failed to get the softbuffer buffer"); - // error[E0599]: no method named `fill` found for struct `Buffer<'surface>` in the - // current scope buffer.fill(color); - for (_, _, pixel) in buffer.pixels_iter() { let red = ((color >> 16) & 0xff) as u8; let green = ((color >> 8) & 0xff) as u8; From 776f63971878686b4be99520610029cf6308447c Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 23:12:27 +0300 Subject: [PATCH 28/32] fmt fill.rs and exclude android for new examples --- winit/examples/util/fill.rs | 2 +- winit/examples/win_with_soft.rs | 2 ++ winit/examples/win_with_soft_2.rs | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/winit/examples/util/fill.rs b/winit/examples/util/fill.rs index 4777260f29..ad9b488eb9 100644 --- a/winit/examples/util/fill.rs +++ b/winit/examples/util/fill.rs @@ -103,7 +103,7 @@ mod platform { let red = ((color >> 16) & 0xff) as u8; let green = ((color >> 8) & 0xff) as u8; let blue = (color & 0xff) as u8; - + *pixel = softbuffer::Pixel::new_rgb(red, green, blue); } buffer.present().expect("Failed to present the softbuffer buffer"); diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index 770b8c6d8e..bd0e84dcd1 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -1,3 +1,5 @@ +#![cfg(not(android))] + use std::error::Error; use std::num::NonZeroU32; use std::sync::Arc; diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index d9d135461b..3ec6a31a9c 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -1,3 +1,5 @@ +#![cfg(not(android))] + use std::error::Error; use std::num::NonZeroU32; use std::sync::Arc; From 5d01646d905c6167d70491e1ef23c62b1a534449 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 23:15:14 +0300 Subject: [PATCH 29/32] fix examples --- winit/examples/win_with_soft.rs | 2 +- winit/examples/win_with_soft_2.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index bd0e84dcd1..0f240bc7d9 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -1,4 +1,4 @@ -#![cfg(not(android))] +#[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform, orbital_platform))] use std::error::Error; use std::num::NonZeroU32; diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index 3ec6a31a9c..efd6966906 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -1,4 +1,4 @@ -#![cfg(not(android))] +#[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform, orbital_platform))] use std::error::Error; use std::num::NonZeroU32; From 2afb39f6e3f656198c3fb84a406a6d5da9474854 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 23:16:23 +0300 Subject: [PATCH 30/32] fmt examples --- winit/examples/win_with_soft.rs | 9 +++++++-- winit/examples/win_with_soft_2.rs | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index 0f240bc7d9..10a82b9fec 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -1,5 +1,10 @@ -#[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform, orbital_platform))] - +#[cfg(any( + windows_platform, + macos_platform, + x11_platform, + wayland_platform, + orbital_platform +))] use std::error::Error; use std::num::NonZeroU32; use std::sync::Arc; diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index efd6966906..e055e7327e 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -1,5 +1,10 @@ -#[cfg(any(windows_platform, macos_platform, x11_platform, wayland_platform, orbital_platform))] - +#[cfg(any( + windows_platform, + macos_platform, + x11_platform, + wayland_platform, + orbital_platform +))] use std::error::Error; use std::num::NonZeroU32; use std::sync::Arc; From 6ff12ebc8351e3b1aed57545aa4a5d3c85080ed5 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 23:25:06 +0300 Subject: [PATCH 31/32] fix examples --- winit/examples/win_with_soft.rs | 9 ++------- winit/examples/win_with_soft_2.rs | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index 10a82b9fec..fe86f288f4 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -1,10 +1,5 @@ -#[cfg(any( - windows_platform, - macos_platform, - x11_platform, - wayland_platform, - orbital_platform -))] +#![cfg(not(target_os = "android"))] + use std::error::Error; use std::num::NonZeroU32; use std::sync::Arc; diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index e055e7327e..460de3ea5e 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -1,10 +1,5 @@ -#[cfg(any( - windows_platform, - macos_platform, - x11_platform, - wayland_platform, - orbital_platform -))] +#![cfg(not(target_os = "android"))] + use std::error::Error; use std::num::NonZeroU32; use std::sync::Arc; From 5feb83f3db8f2938c23f1aecd4e9da77cc8e4bb7 Mon Sep 17 00:00:00 2001 From: Ali Baydur <67105447+yagizgil@users.noreply.github.com> Date: Sun, 15 Mar 2026 23:35:24 +0300 Subject: [PATCH 32/32] . --- winit/examples/win_with_soft.rs | 3 +++ winit/examples/win_with_soft_2.rs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/winit/examples/win_with_soft.rs b/winit/examples/win_with_soft.rs index fe86f288f4..167a1a8210 100644 --- a/winit/examples/win_with_soft.rs +++ b/winit/examples/win_with_soft.rs @@ -99,3 +99,6 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(target_os = "android")] +fn main() {} diff --git a/winit/examples/win_with_soft_2.rs b/winit/examples/win_with_soft_2.rs index 460de3ea5e..94447d09e6 100644 --- a/winit/examples/win_with_soft_2.rs +++ b/winit/examples/win_with_soft_2.rs @@ -115,3 +115,6 @@ fn main() -> Result<(), Box> { }; EventLoop::new()?.run_app(app).map_err(Into::into) } + +#[cfg(target_os = "android")] +fn main() {}