Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

Sometimes GTK modal dialogs are not modal --- bug or feature?

When I create a custom dialog in GTK (both, GTK2 or GTK3) and set it to be modal, all input to other windows of my application is ignored. This works nearly always, but it fails under certain conditions.

When I add a ScrolledWindow containing a TreeView to my dialog, it still works as supposed. But if I fill the TreeView with entries until the ScrolledWindow starts to display its scroll bars --- the modality is suddenly lost and I can click on my other windows!

Here is the most basic example I was able to set up. It's written in Vala, but you'll get the idea:

class MyDialog: Gtk.Dialog {

    public MyDialog() {
        this.modal = true;

        var data = new Gtk.ListStore(1, typeof(string)); 

        // increase this number -- the dialog is not modal anymore!
        for (int i=0; i<2; ++i) {
            Gtk.TreeIter current;
            data.append(out current);
            data.set(current, 0, "Lorem Ipsum"); 
        }

        var render = new Gtk.CellRendererText();

        var column = new Gtk.TreeViewColumn();
            column.pack_start(render, true);
            column.add_attribute(render, "text", 0);

        var treeview = new Gtk.TreeView.with_model(data);
            treeview.append_column(column);
            treeview.show();

        var scroll = new Gtk.ScrolledWindow(null, null);
            scroll.set_size_request(100, 100);
            scroll.add(treeview);
            scroll.show();

        (this.get_content_area() as Gtk.Box).add(scroll);
    }
}

int main (string[] args) {
    Gtk.init (ref args);

    var window = new Gtk.Window();

    window.set_default_size(350, 170);
    window.destroy.connect(Gtk.main_quit);

    var button = new Gtk.Button.with_label("Click me!");
    button.clicked.connect(() => {
        var dialog = new MyDialog();
        dialog.set_transient_for(window);
        dialog.run();
        dialog.destroy();
    });

    window.add(button);
    window.show_all();

    Gtk.main();
    return 0;
}

Compile it with:

valac --pkg gtk+-3.0 main.vala

Am I missing something? Is this behaviour wanted? Or is it a bug? If so, is there a workaround?

EDIT: I investigated a bit further: The problem disappears when the overlay-scrollbars from Ubuntu are uninstalled. So It's not solved yet, but I know where I have to report this...

question from:https://stackoverflow.com/questions/8940687/sometimes-gtk-modal-dialogs-are-not-modal-bug-or-feature

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Definitely a bug. Post a bug report and/or upgrade your GTK+ lib.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...