From 8edb20b854320952795e033e18566e91623bf857 Mon Sep 17 00:00:00 2001 From: Candifloss Date: Wed, 29 Jul 2026 23:12:07 +0530 Subject: [PATCH] Lockscreen test --- glock/src/lockscreen.rs | 77 +++++++++++++++++++++++++++++++++++++++++ glock/src/main.rs | 8 +++-- 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 glock/src/lockscreen.rs diff --git a/glock/src/lockscreen.rs b/glock/src/lockscreen.rs new file mode 100644 index 0000000..5902340 --- /dev/null +++ b/glock/src/lockscreen.rs @@ -0,0 +1,77 @@ +use softbuffer::{Context, Surface}; +use winit::{ + dpi::PhysicalSize, + event::{Event, WindowEvent}, + event_loop::{ControlFlow, EventLoop}, + window::{Fullscreen, WindowBuilder}, +}; + +/// Show a fullscreen test window with a solid background color. +/// +/// This function is intentionally minimal and non-locking: +/// - no input grabbing +/// - no auth +/// - exits on Esc or close +pub fn show_test_window() -> Result<(), Box> { + let event_loop = EventLoop::new()?; + + // Create a borderless fullscreen window + let window = WindowBuilder::new() + .with_title("glock test window") + .with_fullscreen(Some(Fullscreen::Borderless(None))) + .build(&event_loop)?; + + let context = unsafe { Context::new(&window) }?; + let mut surface = unsafe { Surface::new(&context, &window) }?; + + event_loop.run(move |event, control_flow| { + *control_flow = ControlFlow::Wait; + + match event { + Event::WindowEvent { event, .. } => match event { + WindowEvent::CloseRequested => { + *control_flow = ControlFlow::Exit; + } + WindowEvent::KeyboardInput { input, .. } => { + if let Some(winit::event::VirtualKeyCode::Escape) = input.virtual_keycode { + *control_flow = ControlFlow::Exit; + } + } + WindowEvent::Resized(size) => { + resize_surface(&mut surface, size); + redraw(&mut surface, size); + } + _ => {} + }, + Event::RedrawRequested(_) => { + let size = window.inner_size(); + redraw(&mut surface, size); + } + Event::MainEventsCleared => { + window.request_redraw(); + } + _ => {} + } + }); +} + +/// Resize the softbuffer surface when the window size changes. +fn resize_surface(surface: &mut Surface, size: PhysicalSize) { + surface + .resize(size.width as u16, size.height as u16) + .ok(); +} + +/// Fill the window with a solid #232323 color. +fn redraw(surface: &mut Surface, size: PhysicalSize) { + let width = size.width as usize; + let height = size.height as usize; + + let color: u32 = 0xff232323; // ARGB + + let mut buffer = vec![color; width * height]; + + surface + .set_buffer(&buffer, width as u16, height as u16) + .ok(); +} diff --git a/glock/src/main.rs b/glock/src/main.rs index 3864a69..4700ad8 100644 --- a/glock/src/main.rs +++ b/glock/src/main.rs @@ -1,12 +1,13 @@ use rpassword::prompt_password; use std::error::Error; -mod auth; +//mod auth; +mod lockscreen; fn main() -> Result<(), Box> { println!("glock PAM test"); - loop { + /*loop { // Prompt for password without echo. let password = prompt_password("Password: ")?; @@ -22,5 +23,6 @@ fn main() -> Result<(), Box> { } } - Ok(()) + Ok(())*/ + lockscreen::show_test_window() }