Widgets does not work in new window under win10


Hello all again.
I need help with my app (in gtk4 in C) under win10.

In my testing app, after pressing button btnOpen is opened new window.
At new window is button to close this new window (its called btnClose).

In linux everything works as I expect. But in win10 after creating new window are not any widget in new window active or does not respond to any action.
I have found that I must activate any other window in system and than activate newly created window - then its widgets works.

I have installed gnome into win10 according this tutorial:How to Install GTK3/GTK4 on Windows 10 - YouTube

and here is code of my testing app:

#include <gtk/gtk.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <ctime>
#include <vector>

using namespace std;

void CloseWin (GtkWidget* wid, GtkWidget* data) {
    cout << "CloseWin" << endl;

    //do something

  gtk_window_close (GTK_WINDOW(data));

void OpenNewWin (GtkWidget* wid, GtkWidget* data) {
    cout << "opening"<< endl;

    GtkWidget *windowDetail = gtk_window_new ();
    gtk_widget_set_size_request (windowDetail, 220, 220);

    GtkWidget  *vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,10);
    gtk_window_set_child (GTK_WINDOW (windowDetail), vBox);

    GtkWidget *labText = gtk_label_new("text text text");
    gtk_box_append (GTK_BOX (vBox), labText);

    GtkWidget *btnClose = gtk_button_new_with_label("Close");
    gtk_box_append  (GTK_BOX (vBox), btnClose);
    g_signal_connect(G_OBJECT(btnClose), "clicked", G_CALLBACK(CloseWin), windowDetail);


    gtk_widget_show (windowDetail);

static void appActivate (GApplication *app, gpointer user_data) {
    GtkWidget *win = gtk_application_window_new (GTK_APPLICATION (app));
    gtk_window_set_title (GTK_WINDOW (win), "Title");
    gtk_window_set_default_size (GTK_WINDOW (win), 400, 300);

    GtkWidget  *vBox = gtk_box_new (GTK_ORIENTATION_VERTICAL,10);

    gtk_window_set_child (GTK_WINDOW (win), vBox);

    GtkWidget *labText = gtk_label_new("label");
    gtk_box_append (GTK_BOX (vBox), labText);

    GtkWidget *btnOpen = gtk_button_new_with_label("Open new win");
    gtk_box_append  (GTK_BOX (vBox), btnOpen);
    g_signal_connect_swapped(GTK_BUTTON(btnOpen), "clicked", G_CALLBACK(OpenNewWin), win);

    GtkWidget *btnBack = gtk_button_new_with_label("Close");
    gtk_box_append  (GTK_BOX (vBox), btnBack);
    g_signal_connect_swapped(GTK_BUTTON(btnBack), "clicked", G_CALLBACK(gtk_window_destroy), win);

    gtk_widget_show (win);

int main(int argc, char **argv) {
    GtkApplication *app;
    app = gtk_application_new ("testing.app", G_APPLICATION_FLAGS_NONE);
    g_signal_connect (app, "activate", G_CALLBACK (appActivate), NULL);
    return g_application_run (G_APPLICATION (app), NULL, NULL);
    g_object_unref (app);

    return 0;

I have tested with setting focus to nely created window, but it does not helps.

Please could anybady advice me, what could helps?
Thanks a lot.

Can you record a screencast showing the bug, and file this as an issue in gtk? I experienced a similar bug but I was unable to reproduce it reliably.

1 Like

so I have uploaded video to (about 3.5 MB):

Can you create an issue with your system information, the example code you are using, and an upload of that video? Or you can post it all here and I can file issue, if I can reproduce.

How can I upload video here (only images and pdf is allowed here (for me))?

Don’t upload it to Discourse. You would need to upload it to the gitlab, AFAICT it should allow video uploading.

I’m very sorry that I don’t understand (my English is not very good). Do you mean in https://gitlab.gnome.org/
create an issue? For what project? Or should I create a new project there?

Create a new issue here: Issues · GNOME / gtk · GitLab

1 Like

Hi @fik236! Your sample is working fine here, can I ask which version of GTK4 is that? There are two ways to find it out:

  • Open Start > MSYS2 64Bit > MSYS2 MSYS and type the command pacman -Q | grep gtk4
  • Find libgtk-4-1.dll with File Explorer, then right-click and look for Properties > Details > File Version

Reminds me a lot of this old issue: GTK4 windows - gtk4-icon-browser unresposive. (#4188) · Issues · GNOME / gtk · GitLab

msys answers me:
$ pacman -Q | grep gtk4
mingw-w64-x86_64-gtk4 4.6.1-1

Ok, it’s definitely that! You can either upgrade your msys2 bundle as written in Updating MSYS2 - MSYS2 (recommended) or just upgrade the gtk4 package to 4.6.2:

so I have called: pacman -Suy
everything was updated and now I have version of gtk4:
$ pacman -Q | grep gtk4
mingw-w64-x86_64-gtk4 4.10.1-1

and problem dissapear!
Thanks a lot

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.