1

I want to create a child window, bind it with its parent and make it on top and center of the main window, like the usual about dialog. However, I still got two separate windows like this:

Image Link

Here is the demo's code:

use adw::prelude::*;
use adw::{Application, ApplicationWindow, HeaderBar, Window};
use gtk::gio::ApplicationFlags;
use gtk::{Box, Label, Orientation};

fn main() {
    let app = Application::new(None, ApplicationFlags::FLAGS_NONE);
    app.connect_activate(|app| {
        let window = ApplicationWindow::builder()
            .application(app)
            .default_width(320)
            .default_height(200)
            .title("Hello, World!")
            .build();
        let parent_box = Box::new(Orientation::Vertical, 0);
        window.set_content(Some(&parent_box));

        parent_box.append(
            &HeaderBar::builder()
                .title_widget(&Label::new(Some("Gtk Demo")))
                .build(),
        );

        let child_window = Window::builder()
            .transient_for(&window)
            .default_width(180)
            .default_height(120)
            .build();
        let child_box = Box::new(Orientation::Vertical, 0);
        child_window.set_content(Some(&child_box));

        child_box.append(
            &HeaderBar::builder()
                .title_widget(&Label::new(Some("Gtk Demo")))
                .build(),
        );

        window.present();
        child_window.present();
    });
    app.run();
}

Info:

  • OS: Manjaro Linux x86_64
  • Desktop: GNOME 42.1
  • Windowing System: X11
Lomírus
  • 29
  • 5
  • Your code works fine for me on macos. This might be a bug with your specific desktop setup? Maybe you could add your OS and desktop versions. – frankenapps Jun 06 '22 at 09:21

0 Answers0