Set up keyboard handling
This commit is contained in:
parent
0d6cd2a247
commit
dad38590f4
|
@ -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),
|
||||
|
|
Loading…
Reference in New Issue