Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 834
Simme Avatar asked Jan 20 '12 11:01

Simme


1 Answers

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

like image 195
Michael Slade Avatar answered Nov 13 '22 04:11

Michael Slade