2

I have been scratching my head on Why is below code triggers on-draw callback three times as opposed to just once.

#include <iostream>
#include <gtk/gtk.h>

using namespace std;

void on_draw(){
    cout << "drawing"<<endl;
}

int main( int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *drgArea;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  drgArea = gtk_drawing_area_new();
//  gtk_widget_set_redraw_on_allocate(drgArea, -1);
  gtk_container_add(GTK_CONTAINER(window), drgArea);
  gtk_widget_show_all(window);
  g_signal_connect(drgArea, "expose-event",
            G_CALLBACK(on_draw), NULL);
  gtk_main();

  return 0;
}
drahnr
  • 6,782
  • 5
  • 48
  • 75
duckduckgo
  • 1,280
  • 1
  • 18
  • 32
  • I guess gtk+-2.xx? You should always add that when asking questions related to libraries that have a long version history with major differences between major versions. – drahnr Jan 16 '14 at 08:01
  • i have another gtk+-3xx in my pc and when i switched my code to use that, callback count jumped to 4 ! – duckduckgo Jan 16 '14 at 08:40
  • In gtk3 you should use the "draw" signal, if you have further questions regarding that please open another question. – drahnr Jan 16 '14 at 08:43
  • no i just tried it because you were suspicious about version numbers so i tried with another, definitely i used "draw" signal. – duckduckgo Jan 16 '14 at 08:45

1 Answers1

2

This is probably related to your compositor/window manager.

Using cinnamon [2.0.14] shows 2 redraws when starting up the application (no matter if I use gtk3/3.10.6/"draw" or gtk2/2.24.22/"expose-event").

drahnr
  • 6,782
  • 5
  • 48
  • 75
  • i thought like this, maybe those events like "realize" and "map" are routed as a normal expose events but when i added getchar() or sleep(1) just inside on_draw() function, number of callback reduce to just one! – duckduckgo Jan 16 '14 at 09:30
  • this works properly on a different version of ubuntu, is there any way i can prevent multiple event queue on my development machine, thanks – duckduckgo Jan 17 '14 at 01:32
  • 1
    Did you try to use a oldschool 2D non-composited windowmanager - I am not that familiar with the dirty details. – drahnr Jan 17 '14 at 07:04
  • i think, i need to study on what is "non-composited windowmanager" thanks much – duckduckgo Jan 19 '14 at 04:05