GtkGlArea conflicts with gtk_window_set_titlebar()

I am writing a sudoku application using GtkGlArea and prefer menu buttons on title bar.
But appears that this is impossible, because the window becomes very very very buggy (visually).

I made two videos to clarify this issue.

Not using gtk_window_set_title_bar() : GtkGlArea normal menus - YouTube
And using it (bugged) : BUGGED GtkGlArea with menu butoon on header_bar. - YouTube

Does someone know what is the problem ?

Can’t really say this reproduces anywhere.

It would probably help if you could write a small, self-contained test case. As things stands, this could be:

  • a driver bug
  • a compositor issue
  • an application issue

For instance, you may be drawing on the wrong framebuffer and nuking what GTK is going to draw, and it randomly just happens to work with a menu bar because of ordering issues.

Hello, Bassi, thanks for your reply.

I just wrote the test case (a simple do-nothing app) and the issue still there.

  • Commenting out the packing of the GtkGlarea (a do-nothing with menu button in title bar) runs ok.

  • Commenting out the creation of the menu (a do-nothing with GtkGlArea) runs ok.

But still can’t use then both.

#include <gtk/gtk.h>

static gboolean realize(GtkGLArea *area, gpointer udata)
{
    gtk_gl_area_set_has_depth_buffer(area, true);

    gtk_gl_area_make_current(area);
    if(gtk_gl_area_get_error(area) != nullptr)
    {
      printf("  failed to initialize buffers...\n");
      return false;
    }
    return true;
}
static gboolean render(GtkGLArea *area, GdkGLContext *context, gpointer udata)
{
    return true;
}


int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);

    // the main Widget/Window
    GtkWidget *pMainWidget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    auto *mainWin = GTK_WINDOW(pMainWidget);
    gtk_window_set_title(mainWin, "GtkGL1");

    // gl_area widget
    GtkWidget *pGlWidget = gtk_gl_area_new();

    // The header_bar with menu_button to become title_bar
    GtkWidget *pHeader = gtk_header_bar_new();
    auto *hBar = GTK_HEADER_BAR(pHeader);
    GtkWidget *pMenuButton1 = gtk_menu_button_new();
    gtk_header_bar_pack_end(hBar, pMenuButton1);
    gtk_header_bar_set_show_close_button(hBar, true);
    gtk_window_set_titlebar(mainWin, pHeader);

    // boxing glarea_widget
    GtkWidget *pHBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_box_pack_start(GTK_BOX(pHBox), pGlWidget, true, true, 0);
    gtk_container_add(GTK_CONTAINER(mainWin), pHBox);

    // signals connection
    g_signal_connect(pMainWidget,  "delete-event", G_CALLBACK(gtk_main_quit), nullptr);
    g_signal_connect(pGlWidget, "realize", G_CALLBACK(realize), nullptr);
    g_signal_connect(pGlWidget, "render", G_CALLBACK(render), nullptr);


    gtk_widget_show_all(pMainWidget);

    gtk_main();

    return 0;
}

By the way, anyone can test it by himself.

Just copy the code above to any hello.cpp and compile with

gcc `pkg-config --cflags gtk+-3.0` hello.cpp -o hello `pkg-config --libs gtk+-3.0`

If running ‘hello’ gives you the correct result, I will need investigate it in other sphere.
But I guess it will be run as buggy as mine.

In your example code, it seems to be C.
If so, what are you expecting from the above line to happen?

Hi, Michael.

The whole project is c++.
Maybe it looks like a C code because is a simple test isolating the problem in one single source file (and the fact that I prefer gtk_* stuff instead gtkmm).

If you try to compile it, it compiles ok.

Thanks for looking at this.

Hi there, Michael !

Well, hoping to get some help, I converted everything to pure C.

Here are the 5 steps to bug (A.K.A. the source code)

#include <gtk/gtk.h>

// ===================================================
// A do-minimum GtkGlArea realize_callback
// ===================================================
gboolean realize_cb(GtkGLArea *area, gpointer udata)
{
    gtk_gl_area_make_current(area);
    if(gtk_gl_area_get_error(area) != NULL)
    {
      printf("  failed to initialiize buffers...\n");
      return FALSE;
    }
    return TRUE;
}

// ===================================================
// A don't touch anything  GtkGlArea render_callback
// ===================================================
gboolean render_cb(GtkGLArea *area, GdkGLContext *context, gpointer udata)
{
    return TRUE;
}

// ===================================================
// main
// ===================================================
int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);

    // 1. The main widget
    GtkWidget *pMainWidget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_default_size(GTK_WINDOW(pMainWidget), 400, 400);

    // 2. The gl_area widget
    GtkWidget *pGlWidget = gtk_gl_area_new();
    gtk_gl_area_set_has_depth_buffer(GTK_GL_AREA(pGlWidget), TRUE);

    // 3. the header_bar wishing to become title_bar
    GtkWidget *pHeaderBar = gtk_header_bar_new();
    gtk_header_bar_set_show_close_button(GTK_HEADER_BAR(pHeaderBar), TRUE);
    gtk_window_set_titlebar(GTK_WINDOW(pMainWidget), pHeaderBar);
    gtk_window_set_title(GTK_WINDOW(pMainWidget), "simple bug");

    // 4. add glarea_widget to main
    gtk_container_add(GTK_CONTAINER(pMainWidget), pGlWidget);

    // 5. and finally, connect the signals
    g_signal_connect(pMainWidget,  "delete-event", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(pGlWidget, "realize", G_CALLBACK(realize_cb), NULL);
    g_signal_connect(pGlWidget, "render", G_CALLBACK(render_cb), NULL);

    gtk_widget_show_all(pMainWidget);

    // Ok, lets bug !!!!
    gtk_main();
    return 0;
}

If you have a linux machine and want help, please :

  • copy the source code to a empty hello.c text file and compile with
gcc `pkg-config --cflags gtk+-3.0` hello.c -o hello `pkg-config --libs gtk+-3.0`
  • then execute with
./hello

I guess it will show a bugged window. If not (and of course, if yes) please let me know.

What happened here ?

  • commenting only the line 43 (gtk_window_set_titlebar(…)) causes the program to show a black glarea and not the header_bar (as expected).

  • commenting only the line 47 (gtk_container_add(…)) causes the program to show the header_bar and not the glarea (also, as expected).

  • uncommenting both lines, causes the program to show some garbage that remotely resembles a window (not as expected).

Please someone shed some light on this problem. Or, at least, check if this behavior is observed on a machine other than mine.

Regards,
Chimp.

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