creating a gtk window now spawns a new thread

This commit is contained in:
LunarAkai 2025-08-02 14:13:48 +02:00
commit c65b922a45
3 changed files with 18 additions and 11 deletions

View file

@ -34,6 +34,7 @@ impl Game {
pub fn add_window(&mut self) { pub fn add_window(&mut self) {
moonhare_log::info(format!("Adding window to {:?}", self)); moonhare_log::info(format!("Adding window to {:?}", self));
Window::create(); Window::create();
} }
} }

View file

@ -2,6 +2,9 @@
use std::marker; use std::marker;
#[cfg(target_os = "linux")]
use crate::platforms::gtk_window::GTKWindow;
pub mod window_config; pub mod window_config;
pub mod platforms; pub mod platforms;
@ -24,20 +27,24 @@ pub trait MoonhareWindow {
} }
pub struct Window { pub struct Window {
} }
impl Window { impl Window {
/// creates a gtk4 window /// creates a gtk4 window
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub fn create() { pub fn create() {
use std::thread;
use gtk4::gio::prelude::ApplicationExtManual; use gtk4::gio::prelude::ApplicationExtManual;
use crate::platforms::gtk_window::GTKWindow; use crate::platforms::gtk_window::GTKWindow;
thread::spawn(|| {
moonhare_log::info("Created Window thread");
let application = GTKWindow::init(); let application = GTKWindow::init();
application.get_application().run(); application.get_application().run();
});
} }
#[cfg(not(target_os = "linux"))] #[cfg(not(target_os = "linux"))]

View file

@ -1,8 +1,6 @@
use std::marker::PhantomData; use gtk4::{gio::prelude::ApplicationExt, prelude::{GtkWindowExt, WidgetExt}, Application, ApplicationWindow};
use gtk4::{gio::prelude::{ApplicationExt, ApplicationExtManual}, glib::object::ObjectExt, prelude::{GtkWindowExt, WidgetExt}, subclass::prelude::GtkApplicationImpl, Application, ApplicationWindow}; use crate::{window_config, MoonhareWindow};
use crate::{MoonhareWindow, WindowResult};
#[derive(Debug)] #[derive(Debug)]
pub struct GTKWindow { pub struct GTKWindow {
@ -18,11 +16,12 @@ impl GTKWindow {
fn build_ui(application: &Application) { fn build_ui(application: &Application) {
let window = ApplicationWindow::new(application); let window = ApplicationWindow::new(application);
window.set_title(Some("Moonhare Engine GTK")); let window_config = window_config::WindowConfig::default();
window.set_default_size(1280, 720); window.set_title(Some(format!("{} GTK", window_config.title).as_str()));
window.set_default_size(window_config.width as i32, window_config.height as i32);
window.set_visible(window_config.visble);
window.show(); window.show();
} }
} }