mirror of
https://gitlab.com/marcandre.lureau/qemu-display.git
synced 2025-03-07 15:25:04 +00:00
gtk: start a custom Console widget
This commit is contained in:
parent
edaffdb868
commit
54f299599f
@ -2,6 +2,7 @@
|
||||
<gresources>
|
||||
<gresource prefix="/org/qemu/gtk4/">
|
||||
<file compressed="true" preprocess="xml-stripblanks" alias="shortcuts.ui">resources/ui/shortcuts.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks" alias="console.ui">resources/ui/console.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks" alias="window.ui">resources/ui/window.ui</file>
|
||||
|
||||
<file compressed="true" alias="style.css">resources/style.css</file>
|
||||
|
30
qemu-gtk4/data/resources/ui/console.ui
Normal file
30
qemu-gtk4/data/resources/ui/console.ui
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<template class="QemuConsole" parent="GtkWidget">
|
||||
<property name="layout-manager">
|
||||
<object class="GtkBinLayout"/>
|
||||
</property>
|
||||
<child>
|
||||
<object class="GtkNotebook">
|
||||
<child>
|
||||
<object class="GtkGLArea" id="glarea"/>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel" id="notebook-tab">
|
||||
<property name="label">Console</property>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label">
|
||||
<property name="label" translatable="yes">Hello world2!</property>
|
||||
</object>
|
||||
</child>
|
||||
<child type="tab">
|
||||
<object class="GtkLabel" id="notebook-tab2">
|
||||
<property name="label">Tab2</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<menu id="primary_menu">
|
||||
<section>
|
||||
@ -29,11 +30,7 @@
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="label">
|
||||
<property name="label" translatable="yes">Hello world!</property>
|
||||
<style>
|
||||
<class name="title-header"/>
|
||||
</style>
|
||||
<object class="QemuConsole" id="console">
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
|
@ -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
|
||||
|
67
qemu-gtk4/src/console.rs
Normal file
67
qemu-gtk4/src/console.rs
Normal file
@ -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<gtk::Label>,
|
||||
}
|
||||
|
||||
impl ObjectSubclass for QemuConsole {
|
||||
const NAME: &'static str = "QemuConsole";
|
||||
type Type = super::QemuConsole;
|
||||
type ParentType = gtk::Widget;
|
||||
type Interfaces = ();
|
||||
type Instance = subclass::simple::InstanceStruct<Self>;
|
||||
type Class = subclass::simple::ClassStruct<Self>;
|
||||
|
||||
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<Self::Type>) {
|
||||
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<imp::QemuConsole>) @extends gtk::Widget;
|
||||
}
|
@ -4,6 +4,7 @@ mod application;
|
||||
#[rustfmt::skip]
|
||||
mod config;
|
||||
mod window;
|
||||
mod console;
|
||||
|
||||
use application::QemuApplication;
|
||||
use config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE};
|
||||
|
@ -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<gtk::HeaderBar>,
|
||||
#[template_child]
|
||||
pub label: TemplateChild<gtk::Label>,
|
||||
pub console: TemplateChild<QemuConsole>,
|
||||
// #[template_child]
|
||||
// pub glarea: TemplateChild<gtk::GLArea>,
|
||||
// #[template_child]
|
||||
// pub label: TemplateChild<gtk::Label>,
|
||||
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)
|
||||
}),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user