Re:Help replacing GtkDrawingArea with GtkLayout

2014-03-03 Thread Richard Shann
I have constructed the following minimal example, it creates a GtkLayout
with one label inside it, sets the GDK_STRUCTURE_MASK on the GdkWindow
of the GtkLayout and connects the configure-event signal to a routine
that would just exit the main loop. Instead of exiting, the window is
created without the configure-event signal firing. The GdkWindow and its
mask are printed out and appear to be set as per the documentation.
Please can someone explain what is wrong!

#include gtk/gtk.h
static gboolean
configure_event ()
{
fprintf (stderr, configure-event\n);
gtk_main_quit ();
return FALSE;
}

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

gtk_init (argc, argv);

window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   
layout = gtk_layout_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (window), layout);
   

label1 = gtk_label_new (label 1);

gtk_layout_put (GTK_LAYOUT (layout), label1, 10, 50);
  

gtk_widget_show_all (window);

GdkWindow *win = gtk_widget_get_window(layout); 
g_print(win is %p initial mask 0x%x\n, win, gdk_window_get_events (win));
gdk_window_set_events (win, gdk_window_get_events (win) | 
GDK_STRUCTURE_MASK);
g_print(After adding GDK_STRUCTURE_MASK mask 0x%x\n, 
gdk_window_get_events (win));
gtk_widget_add_events (layout, GDK_ALL_EVENTS_MASK);
g_signal_connect (layout, configure-event, G_CALLBACK (configure_event), 
NULL);

gtk_main ();

return 0;
}


Richard Shann

 From: Richard Shann rich...@rshann.plus.com
 To: gtk-app-devel-list@gnome.org
 Subject: Help replacing GtkDrawingArea with GtkLayout
 Message-ID: 1393771664.4221.117.ca...@debianbox.loc
 Content-Type: text/plain; charset=UTF-8
 
 I want to replace the existing GtkDrawingArea with a GtkLayout in a
 large application (GNU Denemo).
 When I do this just by substituting gtk_drawing_area_new() with
 gtk_layout_new(NULL, NULL) I do not receive the configure_event and
 scroll_event signals, although the code gtk_widget_add_events ..
 GDK_EXPOSURE_MASK is still in place.
 
 I suspect this is to do with the cryptic note that drawing has to be
 done to the bin_window instead of window, but beyond that I am stumped.
 The draw event is being handled fine, and mouse button clicks etc are
 all working.
 
 Any help in migrating from GtkDrawingArea to GtkLayout would be much
 appreciated.
 
 Richard Shann


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Re:Help replacing GtkDrawingArea with GtkLayout

2014-03-03 Thread Stefan Salewski
On Mon, 2014-03-03 at 15:17 +, Richard Shann wrote:
 I have constructed the following minimal example,

Yes indeed,

https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-events

This function must be called while a widget is unrealized.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Re:Help replacing GtkDrawingArea with GtkLayout

2014-03-03 Thread Stefan Salewski
On Mon, 2014-03-03 at 15:17 +, Richard Shann wrote:
 gtk_widget_show_all (window);
 
 GdkWindow *win = gtk_widget_get_window(layout); 
 g_print(win is %p initial mask 0x%x\n, win,
 gdk_window_get_events (win));
 gdk_window_set_events (win, gdk_window_get_events (win) |
 GDK_STRUCTURE_MASK);
 g_print(After adding GDK_STRUCTURE_MASK mask 0x%x\n,
 gdk_window_get_events (win));
 gtk_widget_add_events (layout, GDK_ALL_EVENTS_MASK);


Just a stupid guess, sorry:

May it be necessary to set event mask BEFORE displaying the window with

gtk_widget_show_all (window);


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Re:Help replacing GtkDrawingArea with GtkLayout

2014-03-03 Thread Richard Shann
On Mon, 2014-03-03 at 16:49 +0100, Stefan Salewski wrote:
 On Mon, 2014-03-03 at 15:17 +, Richard Shann wrote:
  I have constructed the following minimal example,
 
 Yes indeed,
 
 https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-events
 
 This function must be called while a widget is unrealized.

Thank you for giving this some thought. I think it is not the case
however that the gtk_widget_show_all() call causes the widget to be
realized in gtk-speak, it just sets a flag on the widget to say it
should be visible (I am guessing).

I think I have just made a breakthrough with my problem however -
setting the configure-event signal handler on the parent GtkWindow
widget instead of the GtkLayout window it contains causes it to fire
off. I have tried this with the scroll-event too and that works. Why
this should be different from the case where I use a GtkDrawingArea I
have no idea, but it looks like I am cooking with gas!

Thank you once more

Richard



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Re:Help replacing GtkDrawingArea with GtkLayout

2014-03-03 Thread Bernhard Schuster
On Mon, Mar 3, 2014 at 5:26 PM, Richard Shann rich...@rshann.plus.com 
wrote:

On Mon, 2014-03-03 at 16:49 +0100, Stefan Salewski wrote:

 On Mon, 2014-03-03 at 15:17 +, Richard Shann wrote:
  I have constructed the following minimal example,
 
 Yes indeed,
 
 
https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-events
 
 This function must be called while a widget is unrealized.



Thank you for giving this some thought. I think it is not the case
however that the gtk_widget_show_all() call causes the widget to be
realized in gtk-speak, it just sets a flag on the widget to say it
should be visible (I am guessing).

I think I have just made a breakthrough with my problem however -
setting the configure-event signal handler on the parent GtkWindow
widget instead of the GtkLayout window it contains causes it to fire
off. I have tried this with the scroll-event too and that works. Why
this should be different from the case where I use a GtkDrawingArea I
have no idea, but it looks like I am cooking with gas!


Either - I strongly recommend to stick to

   gdk_window_add_events (win, GDK_STRUCTURE_MASK);

which does not have any dependency on widget/window realization. (I 
found myself in that very same pit some time ago).



Best


Bernhard
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Re:Help replacing GtkDrawingArea with GtkLayout

2014-03-03 Thread Richard Shann
On Mon, 2014-03-03 at 16:38 +0001, Bernhard Schuster wrote:
 On Mon, Mar 3, 2014 at 5:26 PM, Richard Shann
 rich...@rshann.plus.com wrote:
  On Mon, 2014-03-03 at 16:49 +0100, Stefan Salewski wrote: 
  On Mon, 2014-03-03 at 15:17 +, Richard Shann wrote:  I
  have constructed the following minimal example, Yes indeed,
  
  https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-set-events
   This function must be called while a widget is unrealized.
  Thank you for giving this some thought. I think it is not the case
  however that the gtk_widget_show_all() call causes the widget to be
  realized in gtk-speak, it just sets a flag on the widget to say it
  should be visible (I am guessing). I think I have just made a
  breakthrough with my problem however - setting the configure-event
  signal handler on the parent GtkWindow widget instead of the
  GtkLayout window it contains causes it to fire off. I have tried
  this with the scroll-event too and that works. Why this should be
  different from the case where I use a GtkDrawingArea I have no idea,
  but it looks like I am cooking with gas!
 
 Either - I strongly recommend to stick to
 
 
 gdk_window_add_events (win, GDK_STRUCTURE_MASK);
 
 
 which does not have any dependency on widget/window realization. (I
 found myself in that very same pit some time ago).

The docs indicate that this may be set anyway:

The ::configure-event signal will be emitted when the size, position or
stacking of the widget's window has changed. 
To receive this signal, the GdkWindow associated to the widget needs to
enable the GDK_STRUCTURE_MASK mask. GDK will enable this mask
automatically for all new windows.

Once I moved the signal handler attachment upwards in the widget
hierarchy it sprang into life without any explicit setting of the
GdkWindow mask.

Richard


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list