diff --git a/qemu-gtk4/data/resources.gresource.xml b/qemu-gtk4/data/resources.gresource.xml index b8abc9a..2d1b48c 100644 --- a/qemu-gtk4/data/resources.gresource.xml +++ b/qemu-gtk4/data/resources.gresource.xml @@ -2,6 +2,7 @@ resources/ui/shortcuts.ui + resources/ui/console.ui resources/ui/window.ui resources/style.css diff --git a/qemu-gtk4/data/resources/ui/console.ui b/qemu-gtk4/data/resources/ui/console.ui new file mode 100644 index 0000000..9b04e69 --- /dev/null +++ b/qemu-gtk4/data/resources/ui/console.ui @@ -0,0 +1,30 @@ + + + + diff --git a/qemu-gtk4/data/resources/ui/window.ui b/qemu-gtk4/data/resources/ui/window.ui index be3fb3c..fc67b39 100644 --- a/qemu-gtk4/data/resources/ui/window.ui +++ b/qemu-gtk4/data/resources/ui/window.ui @@ -1,3 +1,4 @@ +
@@ -29,11 +30,7 @@ - - Hello world! - + diff --git a/qemu-gtk4/po/POTFILES.in b/qemu-gtk4/po/POTFILES.in index 8ead562..b85657c 100644 --- a/qemu-gtk4/po/POTFILES.in +++ b/qemu-gtk4/po/POTFILES.in @@ -1,4 +1,5 @@ data/resources/ui/shortcuts.ui +data/resources/ui/console.ui.in data/resources/ui/window.ui.in data/org.qemu.gtk4.desktop.in.in data/org.qemu.gtk4.gschema.xml.in diff --git a/qemu-gtk4/src/console.rs b/qemu-gtk4/src/console.rs new file mode 100644 index 0000000..ed5808d --- /dev/null +++ b/qemu-gtk4/src/console.rs @@ -0,0 +1,67 @@ +use glib::subclass::prelude::*; +use gtk::prelude::*; +use gtk::subclass::widget::WidgetImplExt; +use gtk::{gio, glib, CompositeTemplate}; + +mod imp { + use super::*; + use glib::subclass; + use gtk::subclass::prelude::*; + + #[derive(Debug, CompositeTemplate)] + #[template(resource = "/org/qemu/gtk4/console.ui")] + pub struct QemuConsole { + #[template_child] + pub label: TemplateChild, + } + + impl ObjectSubclass for QemuConsole { + const NAME: &'static str = "QemuConsole"; + type Type = super::QemuConsole; + type ParentType = gtk::Widget; + type Interfaces = (); + type Instance = subclass::simple::InstanceStruct; + type Class = subclass::simple::ClassStruct; + + glib::object_subclass!(); + + fn new() -> Self { + Self { + label: TemplateChild::default(), + } + } + + fn class_init(klass: &mut Self::Class) { + Self::bind_template(klass); + } + + fn instance_init(obj: &glib::subclass::InitializingObject) { + obj.init_template(); + } + } + + impl ObjectImpl for QemuConsole { + fn constructed(&self, obj: &Self::Type) { + self.parent_constructed(obj); + } + + // Needed for direct subclasses of GtkWidget; + // Here you need to unparent all direct children + // of your template. + fn dispose(&self, obj: &Self::Type) { + while let Some(child) = obj.get_first_child() { + child.unparent(); + } + } + } + + impl WidgetImpl for QemuConsole { + fn size_allocate(&self, widget: &Self::Type, width: i32, height: i32, baseline: i32) { + self.parent_size_allocate(widget, width, height, baseline); + } + } +} + +glib::wrapper! { + pub struct QemuConsole(ObjectSubclass) @extends gtk::Widget; +} diff --git a/qemu-gtk4/src/main.rs b/qemu-gtk4/src/main.rs index 5fdbe5f..feac1c5 100644 --- a/qemu-gtk4/src/main.rs +++ b/qemu-gtk4/src/main.rs @@ -4,6 +4,7 @@ mod application; #[rustfmt::skip] mod config; mod window; +mod console; use application::QemuApplication; use config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE}; diff --git a/qemu-gtk4/src/window.rs b/qemu-gtk4/src/window.rs index e06f365..a7f78f4 100644 --- a/qemu-gtk4/src/window.rs +++ b/qemu-gtk4/src/window.rs @@ -1,4 +1,5 @@ use crate::application::QemuApplication; +use crate::console::QemuConsole; use crate::config::{APP_ID, PROFILE}; use glib::clone; use glib::signal::Inhibit; @@ -7,7 +8,7 @@ use gtk::{self, prelude::*}; use gtk::{gio, glib, CompositeTemplate}; use log::warn; -use qemu_display_listener::Console; +use qemu_display_listener::{Console as ConsoleListener, Event}; mod imp { use super::*; @@ -19,7 +20,11 @@ mod imp { #[template_child] pub headerbar: TemplateChild, #[template_child] - pub label: TemplateChild, + pub console: TemplateChild, + // #[template_child] + // pub glarea: TemplateChild, + // #[template_child] + // pub label: TemplateChild, pub settings: gio::Settings, } @@ -36,7 +41,9 @@ mod imp { fn new() -> Self { Self { headerbar: TemplateChild::default(), - label: TemplateChild::default(), + console: TemplateChild::default(), + // label: TemplateChild::default(), + // glarea: TemplateChild::default(), settings: gio::Settings::new(APP_ID), } } @@ -89,10 +96,16 @@ glib::wrapper! { } impl QemuApplicationWindow { - pub fn new(app: &QemuApplication, console: Console) -> Self { + pub fn new(app: &QemuApplication, console: ConsoleListener) -> Self { let window: Self = glib::Object::new(&[]).expect("Failed to create QemuApplicationWindow"); window.set_application(Some(app)); + let win = &imp::QemuApplicationWindow::from_instance(&window); + // win.glarea.connect_render(clone!(@weak window as win => move |area, ctxt| { + // dbg!("render"); + // Inhibit(false) + // })); + // Set icons for shell gtk::Window::set_default_icon_name(APP_ID); @@ -102,8 +115,14 @@ impl QemuApplicationWindow { rx.attach( None, clone!(@weak window as win => move |t| { - let label = &imp::QemuApplicationWindow::from_instance(&win).label; - label.set_text(&format!("{:?}", t)); + let win = &imp::QemuApplicationWindow::from_instance(&win); + match t { + Event::Scanout { .. } => { + // win.label.set_text(&format!("{:?}", t)); + // win.glarea.queue_render(); + } + _ => () + } Continue(true) }), );