Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:57:53+00:00 2026-05-23T11:57:53+00:00

I’m reusing a modal dialog in GTK+ — I set it’s parent dialog using

  • 0

I’m reusing a modal dialog in GTK+ — I set it’s parent dialog using gtk_window_set_transient_for, run it, and later reset it’s parent to another dialog and run it again.

On Linux everything is fine but on MS Windows the second time this dialog is displayed all GTK windows get confused which one is active.

This is a test program:

#include <gtk/gtk.h>

GtkWidget* main_window;

void run_reused_dialog(
    GtkWidget* reused_dialog,
    const gchar *parent_title,
    const gchar *reused_dialog_title
) {
    GtkWidget* parent_dialog = gtk_dialog_new_with_buttons(
        parent_title,
        GTK_WINDOW(main_window),
        GTK_DIALOG_MODAL,
        GTK_STOCK_OK,
        GTK_RESPONSE_ACCEPT,
        NULL
    );
    gtk_container_add(
        GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(parent_dialog))),
        gtk_label_new(parent_title)
    );
    gtk_widget_show_all(parent_dialog);
    gtk_dialog_run(GTK_DIALOG(parent_dialog));

    gtk_window_set_transient_for(GTK_WINDOW(reused_dialog),GTK_WINDOW(parent_dialog));
    gtk_window_set_title(GTK_WINDOW(reused_dialog), reused_dialog_title);
    GtkWidget* reused_dialog_label = gtk_label_new(GTK_WINDOW(reused_dialog)->title);
    gtk_container_add(
        GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(reused_dialog))),
        reused_dialog_label
    );
    gtk_widget_show_all(reused_dialog);
    gtk_dialog_run(GTK_DIALOG(reused_dialog));
    gtk_widget_hide(reused_dialog);
    gtk_container_remove(
        GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(reused_dialog))),
        reused_dialog_label
    );
    gtk_widget_hide(parent_dialog);
    gtk_widget_destroy(parent_dialog);
}

int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);
    main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    g_signal_connect(main_window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
    gtk_widget_show_all(main_window);

    /* This is a dialog which will be reused */
    GtkWidget* reused_dialog = gtk_dialog_new_with_buttons(
        "Reused dialog",
        GTK_WINDOW(main_window),
        GTK_DIALOG_MODAL,
        GTK_STOCK_OK,
        GTK_RESPONSE_ACCEPT,
        NULL
    );
    gtk_container_add(
        GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(reused_dialog))),
        gtk_label_new(GTK_WINDOW(reused_dialog)->title)
    );

    /* Show first dialog which will display reused dialog */
    run_reused_dialog(
        reused_dialog,
        "First dialog. Click OK to display reused dialog",
        "Reused dialog. Click OK to close"
    );

    /* Show second dialog which will display reused dialog */
    run_reused_dialog(
        reused_dialog,
        "Second dialog. Click OK to display reused dialog",
        "Reused dialog. Switch to another application and switch back"
    );

    gtk_main();
    return 0;
}

When “Reused dialog. Switch to another application and switch back” dialog is displayed, it ignores mouse, but reacts to keyboard input. Sometimes switching to another application and back triggers this problem.


Questions:

  1. Am I doing something wrong or is it a bug in Windows GTK port?

  2. How to work around it without recreating this dialog every time it is used?

  3. Am I allowed to reuse GTK dialogs at all?


The sample program source and compiled executable with required GTK libraries is here. This is cross-compiled using i686-pc-mingw32-gcc gtk-reused-dialog.c $(mingw32-pkg-config --cflags --libs gtk+-2.0) -mwindows on Fedora Linux 15 with mingw32-gtk2 package and it dependencies installed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:57:53+00:00Added an answer on May 23, 2026 at 11:57 am

    This is my guess:

    1. the problem is related to focus grabbing;
    2. the window widget calls grab APIs only when the modal flag changes its state;
    3. differences between platforms are mostly due to implementation details;
    4. you cannot have more than a single modal window.

    At the time you show reused_dialog, it is not clear which dialog is modal (parent_window is still alive).

    The right solution: I suspect if you refactor your code to show reused_dialog from a callback (using the response signal, for example), you’ll get the desired result because this is the usual way™.

    If you don’t want to refactor you could try one of these solutions/work-arounds (roughly in order of what I think is better):

    • always disactivate the modal state of reused_dialog before running it; gtk_dialog_run() will set it again, triggering what requested:

      ...
      gtk_window_set_modal(GTK_WINDOW(reused_dialog), FALSE);
      gtk_dialog_run(GTK_DIALOG(reused_dialog));
      ...
      
    • manually grab the focus in reused_dialog before running it:

      ...
      gtk_grab_add(reused_dialog);
      gtk_dialog_run(GTK_DIALOG(reused_dialog));
      ...
      
    • deactivate the modal status of the parent_window after run:

      ...
      gtk_dialog_run(GTK_DIALOG(parent_dialog));
      gtk_window_set_modal(GTK_WINDOW(parent_dialog), FALSE);
      ...
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.