From cf7dc1049515059f1c5de79d6fead76c62bc766c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomas=20Wenstr=C3=B6m?= Date: Thu, 14 Feb 2019 15:06:46 +0100 Subject: [PATCH] Toggle fullscreen with F11 --- src/main.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7216479..9efa97d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ use sdl2::pixels::Color; use sdl2::rect::Rect; use sdl2::render::BlendMode; use sdl2::render::Canvas; +use sdl2::video::FullscreenType; use sdl2::video::Window; use time::PreciseTime; @@ -118,8 +119,10 @@ fn main() { break 'running; } Event::KeyDown { keycode: Some(Keycode::F11), .. } => { - canvas.window_mut() - .set_fullscreen(sdl2::video::FullscreenType::True).unwrap(); + match canvas.window().fullscreen_state() { + FullscreenType::Off => canvas.window_mut().set_fullscreen(FullscreenType::Desktop), + _ => canvas.window_mut().set_fullscreen(FullscreenType::Off) + }.unwrap(); } Event::KeyDown { keycode: Some(Keycode::KpPlus), .. } => { boll_size = std::cmp::min(boll_size + 1, 32) } Event::KeyDown { keycode: Some(Keycode::KpMinus), .. } => { boll_size = std::cmp::max(boll_size - 1, 1) } -- 2.11.0