Set up keyboard handling

This commit is contained in:
Savanni D'Gerinel 2023-04-10 00:20:39 -04:00 committed by Gitea
parent 0d6cd2a247
commit dad38590f4
1 changed files with 19 additions and 3 deletions

View File

@ -2,8 +2,8 @@ use cairo::{
Context, FontSlant, FontWeight, Format, ImageSurface, LineCap, LinearGradient, Pattern, Context, FontSlant, FontWeight, Format, ImageSurface, LineCap, LinearGradient, Pattern,
TextExtents, TextExtents,
}; };
use glib::Object; use glib::{GString, Object};
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{gdk::Key, prelude::*, subclass::prelude::*, EventControllerKey};
use std::{ use std::{
cell::RefCell, cell::RefCell,
rc::Rc, rc::Rc,
@ -514,12 +514,28 @@ fn main() {
let splash = Splash::new("GTK Kifu".to_owned(), countdown.clone()); let splash = Splash::new("GTK Kifu".to_owned(), countdown.clone());
window.set_child(Some(&splash)); window.set_child(Some(&splash));
// window.fullscreen();
window.connect_maximized_notify(|window| { window.connect_maximized_notify(|window| {
window.fullscreen(); 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| { gtk_rx.attach(None, move |event| {
match event { match event {
Event::Frames(frames) => splash.tick(frames), Event::Frames(frames) => splash.tick(frames),