RE: Opening a background window in a separate thread

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Ian Puleston
> 
> I tried simply creating and showing the dialog window and then
> letting the thread return to the main loop. But with this I find that
> although the main window does respond to mouse clicks, it stays behind
> the dialog window while that is open. Is there something that I need to
> do to bring it to the front when its clicked on?

I hacked up a little program to demo this problem. Click the button in the main window and a non-modal dialog opens. You can click it numerous times and open many dialogs at the same time, and all respond to clicking their buttons fine. But when they are open the main window cannot be brought to the front.

Here's the code. What's missing?:

#include <gtk/gtk.h>

GtkWidget *mainWin;

/*============================================================================*/
/* The signal handler for responses from the dialog */
void dlgResponse(GtkDialog *dlgWin, gint responseId, gpointer data)
{
    switch (responseId)
    {
    case GTK_RESPONSE_ACCEPT:
    case GTK_RESPONSE_DELETE_EVENT:
        gtk_widget_destroy(GTK_WIDGET(dlgWin));
        break;
    }
}

/*============================================================================*/
/* Event handler for the delete event */
static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data)
{
    gtk_main_quit();

    /* Let GTK process the destroy and terminate us */
    return FALSE;
}

/*============================================================================*/
void btnClick(GtkWidget *btn, gpointer data)
{
    GtkWidget *dlgWin;

    dlgWin = gtk_dialog_new_with_buttons("test", GTK_WINDOW(mainWin),
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
                                         NULL);
    g_signal_connect(G_OBJECT(dlgWin), "response", G_CALLBACK(dlgResponse), NULL);
    gtk_widget_show(dlgWin);
}

/*============================================================================*/
int main(int argc, char *argv[])
{
    GtkWidget *vBox, *hBox; 
    GtkWidget *button;

    gtk_init(&argc, &argv);

    mainWin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(mainWin), "Test Application");
    gtk_window_set_position(GTK_WINDOW(mainWin), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(mainWin), 500, 500);

    vBox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(mainWin), vBox);
    hBox = gtk_hbox_new(FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vBox), hBox, FALSE, FALSE, 20);
    gtk_widget_show(hBox);

    button = gtk_button_new_with_label("Click me");
    gtk_box_pack_start(GTK_BOX(hBox), button, TRUE, FALSE, 0);
    g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(btnClick), NULL);
    gtk_widget_show(button);

    gtk_widget_show(vBox);

    g_signal_connect(G_OBJECT(mainWin), "delete_event", G_CALLBACK(delete_event), NULL);
    gtk_container_set_border_width(GTK_CONTAINER(mainWin), 10);
    gtk_widget_show(mainWin);
    gtk_main();

    return 0;
}

/*============================================================================*/



_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux