diff --git a/qemu-display-listener/src/console.rs b/qemu-display-listener/src/console.rs index 36f5965..2c58408 100644 --- a/qemu-display-listener/src/console.rs +++ b/qemu-display-listener/src/console.rs @@ -12,6 +12,18 @@ pub trait Console { /// RegisterListener method fn register_listener(&self, listener: Fd) -> zbus::Result<()>; + /// SetUIInfo method + #[dbus_proxy(name = "SetUIInfo")] + fn set_ui_info( + &self, + width_mm: u16, + height_mm: u16, + xoff: i32, + yoff: i32, + width: u32, + height: u32, + ) -> zbus::Result<()>; + #[dbus_proxy(property)] fn label(&self) -> zbus::Result; diff --git a/qemu-gtk4/src/console.rs b/qemu-gtk4/src/console.rs index e8e1967..92046ef 100644 --- a/qemu-gtk4/src/console.rs +++ b/qemu-gtk4/src/console.rs @@ -114,6 +114,19 @@ mod imp { self.area.set_sensitive(true); self.area.set_focusable(true); self.area.set_focus_on_click(true); + + unsafe { + self.area.connect_notify_unsafe( + Some("resize-hack"), + clone!(@weak obj => move |_, _| { + let priv_ = imp::QemuConsole::from_instance(&obj); + let alloc = priv_.area.get_allocation(); + if let Err(e) = obj.qemu_console().proxy.set_ui_info(0, 0, 0, 0, alloc.width as u32, alloc.height as u32) { + eprintln!("Failed to SetUIInfo: {}", e); + } + }), + ); + } } // Needed for direct subclasses of GtkWidget; @@ -126,11 +139,7 @@ mod imp { } } - 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); - } - } + impl WidgetImpl for QemuConsole {} } glib::wrapper! { diff --git a/qemu-gtk4/src/console_area.rs b/qemu-gtk4/src/console_area.rs index 26f26e7..6f3252b 100644 --- a/qemu-gtk4/src/console_area.rs +++ b/qemu-gtk4/src/console_area.rs @@ -63,6 +63,29 @@ mod imp { fn constructed(&self, obj: &Self::Type) { self.parent_constructed(obj); } + + fn properties() -> &'static [glib::ParamSpec] { + use once_cell::sync::Lazy; + static PROPERTIES: Lazy> = Lazy::new(|| { + vec![glib::ParamSpec::boolean( + "resize-hack", + "resize-hack", + "Resize hack to notify parent", + false, + glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT, + )] + }); + PROPERTIES.as_ref() + } + + fn set_property( + &self, + _obj: &Self::Type, + _id: usize, + _value: &glib::Value, + _pspec: &glib::ParamSpec, + ) { + } } impl WidgetImpl for QemuConsoleArea { @@ -79,6 +102,11 @@ mod imp { widget.set_error(Some(&e)); } } + + fn size_allocate(&self, widget: &Self::Type, width: i32, height: i32, baseline: i32) { + self.parent_size_allocate(widget, width, height, baseline); + widget.notify("resize-hack"); + } } impl GLAreaImpl for QemuConsoleArea {