diff --git a/cyberpunk-splash/src/main.rs b/cyberpunk-splash/src/main.rs index b070c3a..e740699 100644 --- a/cyberpunk-splash/src/main.rs +++ b/cyberpunk-splash/src/main.rs @@ -2,8 +2,8 @@ use cairo::{ Context, FontSlant, FontWeight, Format, ImageSurface, LineCap, LinearGradient, Pattern, TextExtents, }; -use glib::Object; -use gtk::{prelude::*, subclass::prelude::*}; +use glib::{GString, Object}; +use gtk::{gdk::Key, prelude::*, subclass::prelude::*, EventControllerKey}; use std::{ cell::RefCell, rc::Rc, @@ -514,12 +514,28 @@ fn main() { let splash = Splash::new("GTK Kifu".to_owned(), countdown.clone()); window.set_child(Some(&splash)); - // window.fullscreen(); window.connect_maximized_notify(|window| { window.fullscreen(); }); + let keyboard_events = EventControllerKey::new(); + keyboard_events.connect_key_released({ + let window = window.clone(); + move |_, key, _, _| { + let name = key + .name() + .map(|s| s.as_str().to_owned()) + .unwrap_or("".to_owned()); + match name.as_ref() { + "Escape" => window.unfullscreen(), + "space" => println!("space pressed"), + _ => {} + } + } + }); + window.add_controller(keyboard_events); + gtk_rx.attach(None, move |event| { match event { Event::Frames(frames) => splash.tick(frames),