Lockscreen test
This commit is contained in:
parent
cbfbcf0fc1
commit
8edb20b854
77
glock/src/lockscreen.rs
Normal file
77
glock/src/lockscreen.rs
Normal file
@ -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<dyn std::error::Error>> {
|
||||||
|
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<u32>) {
|
||||||
|
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<u32>) {
|
||||||
|
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();
|
||||||
|
}
|
||||||
@ -1,12 +1,13 @@
|
|||||||
use rpassword::prompt_password;
|
use rpassword::prompt_password;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
mod auth;
|
//mod auth;
|
||||||
|
mod lockscreen;
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
println!("glock PAM test");
|
println!("glock PAM test");
|
||||||
|
|
||||||
loop {
|
/*loop {
|
||||||
// Prompt for password without echo.
|
// Prompt for password without echo.
|
||||||
let password = prompt_password("Password: ")?;
|
let password = prompt_password("Password: ")?;
|
||||||
|
|
||||||
@ -22,5 +23,6 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())*/
|
||||||
|
lockscreen::show_test_window()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user