Re: Receiving a callback on GDK window destroy

2010-01-20 Thread Tristan Schmelcher
I do get one XID per instance, but that XID is created by Firefox's
plugin host code in GtkSocket's internal GdkWindow. So the XID is
already mapped to that GdkWindow by the time NPP_SetWindow runs, hence
gdk_window_foreign_new() just returns a pointer to that pre-existing
GdkWindow, so the parentage tree that _gdk_window_destroy_hierarchy
traverses is still hooked up.

But after some more hacking I was able to figure out a work-around.
gdk_window_foreign_new() only re-uses the existing GdkWindow if the
GdkDisplay pointers match, and gdk_display_open does _not_ re-use
existing connections! So by explicitly opening the display and using
gdk_window_foreign_new_for_display I was able to force it to really
use a foreign window, and now I get all the expected callbacks (unmap,
delete, unrealize). In fact, with the _for_display() trick I can use a
GtkPlug and get the same callbacks just fine. So the code I eventually
settled on is basically this:

// Re-open the X11 connection
gdk_display_ = gdk_display_open(XDisplayString(display));
// Create plug.
gtk_plug_ = gtk_plug_new_for_display(gdk_display_, windowId);
// Stop the browser from destroying our GtkPlug too soon.
g_signal_connect(G_OBJECT(gtk_plug_), delete-event,
   G_CALLBACK(gtk_widget_hide_on_delete), NULL);

Thanks for the help!

On 19 January 2010 20:55, Kevin DeKorte kdeko...@gmail.com wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 01/19/10 20:29, Tristan Schmelcher wrote:
  Actually, after debugging and looking at the code, it seems that
  gdk_window_foreign_new() first looks up if there is already a GdkWindow
  for that XID and re-uses it if so (gdk/x11/gdkwindow-x11.c:1008). So I
  don't think this approach will work. :(

 You must be doing something wrong since you should get one xid per
 windowed plugin instance. I've been using this method for years in both
 the mplayerplug-in plugin and the gecko-mediaplayer plugin.

 Take a look at either of those projects source code. I'm sure there is
 something there that will help you.

 Kevin
 - --
 Get my public GnuPG key from
 http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x7D0BD5D1
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.10 (GNU/Linux)
 Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

 iEYEARECAAYFAktWjNQACgkQ6w2kMH0L1dG7vACcDZNHS0dTEbXCTHD0IesjVmeF
 BCsAn3oewKsZFv/Dv6uV3vfKgR6k7iJl
 =uFlq
 -END PGP SIGNATURE-
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Receiving a callback on GDK window destroy

2010-01-19 Thread Tristan Schmelcher
Thanks Kevin! I'm trying out your suggestion and I've got the GtkWindow
hooking up to the foreign GdkWindow properly, but it looks like I still get
the same X server error when trying to draw after the browser destroys the
GtkSocket's window, and I still can't find a signal/event that gets
dispatched when that happens. :( e.g., delete, destroy, reparent, unmap, and
unrealize are not dispatched. Do you remember if there was a particular
event that you listened for to handle this case?

On 15 January 2010 16:08, Kevin DeKorte kdeko...@gmail.com wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 01/15/10 16:51, Tristan Schmelcher wrote:
  Hello,
 
  I'm a novice Gtk app developer writing a plugin for Firefox and I'm
  having trouble getting the callbacks that I need from Gtk/Gdk. The way
  the plugin architecture works is that Firefox creates a GtkSocket and
  my plugin gets passed its XID and creates the corresponding GtkPlug
  (in the same process). By and large everything works, except at
  shutdown. In some cases, Firefox happens to do a gdk_window_destroy()
  on one of the parent windows of the GtkSocket before unloading my
  plugin (for example, when closing a tab with the 'X'). That
  recursively destroys everything down to the GtkSocket and also the
  GtkPlug in _gdk_window_destroy_hierarchy(
  ). So when I try to access the underlying X11 Window handle after this
  I get an error from the X server and the program aborts. :(
 
  What I'd like to do is receive a signal from Gtk/Gdk when the
  GdkWindow inside my GtkPlug is destroyed like this so that I can
  cancel any further rendering actions. But I can't figure out how to
  receive a signal when this happens! AFAICT none of the GtkPlug signals
  or its inherited GtkWidget signals are dispatched when this happens.
 
  Any ideas?

 Tristan,

 I've had this same problem when developing
 gecko-mediaplayer/gnome-mplayer and mplayerplug-in. I was never able to
 fully use the GtkPlug interface. It just didn't work the way I needed it
 to.

 What I ended up doing is creating a normal toplevel window and then
 embedding it in the window that firefox gave me..

 Something like this where windowid is the xid I get from firefox.



window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

if (windowid  0  embedding_disabled == FALSE) {
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
GTK_WIDGET_SET_FLAGS(window, GTK_CAN_FOCUS);
}


   if (windowid != 0  embedding_disabled == FALSE) {
while (gtk_events_pending())
gtk_main_iteration();

window_container = gdk_window_foreign_new(windowid);
if (GTK_WIDGET_MAPPED(window))
gtk_widget_unmap(window);

gdk_window_reparent(window-window, window_container, 0, 0);
}


 Hope that helps.

 Kevin
 - --
 Get my public GnuPG key from
 http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x7D0BD5D1
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.10 (GNU/Linux)
 Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

 iEYEARECAAYFAktRA4AACgkQ6w2kMH0L1dFb0ACfdc7jssfzEnillFHhrUFOjDbW
 nsQAnj4Q6GCxg8H1zeoC9/NTx8kuRtDV
 =iMWg
 -END PGP SIGNATURE-

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


Re: Receiving a callback on GDK window destroy

2010-01-19 Thread Tristan Schmelcher
Actually, after debugging and looking at the code, it seems that
gdk_window_foreign_new() first looks up if there is already a GdkWindow for
that XID and re-uses it if so (gdk/x11/gdkwindow-x11.c:1008). So I don't
think this approach will work. :(

On 19 January 2010 19:09, Tristan Schmelcher tschmelc...@google.com wrote:

 Thanks Kevin! I'm trying out your suggestion and I've got the GtkWindow
 hooking up to the foreign GdkWindow properly, but it looks like I still get
 the same X server error when trying to draw after the browser destroys the
 GtkSocket's window, and I still can't find a signal/event that gets
 dispatched when that happens. :( e.g., delete, destroy, reparent, unmap, and
 unrealize are not dispatched. Do you remember if there was a particular
 event that you listened for to handle this case?


 On 15 January 2010 16:08, Kevin DeKorte kdeko...@gmail.com wrote:

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 On 01/15/10 16:51, Tristan Schmelcher wrote:
  Hello,
 
  I'm a novice Gtk app developer writing a plugin for Firefox and I'm
  having trouble getting the callbacks that I need from Gtk/Gdk. The way
  the plugin architecture works is that Firefox creates a GtkSocket and
  my plugin gets passed its XID and creates the corresponding GtkPlug
  (in the same process). By and large everything works, except at
  shutdown. In some cases, Firefox happens to do a gdk_window_destroy()
  on one of the parent windows of the GtkSocket before unloading my
  plugin (for example, when closing a tab with the 'X'). That
  recursively destroys everything down to the GtkSocket and also the
  GtkPlug in _gdk_window_destroy_hierarchy(
  ). So when I try to access the underlying X11 Window handle after this
  I get an error from the X server and the program aborts. :(
 
  What I'd like to do is receive a signal from Gtk/Gdk when the
  GdkWindow inside my GtkPlug is destroyed like this so that I can
  cancel any further rendering actions. But I can't figure out how to
  receive a signal when this happens! AFAICT none of the GtkPlug signals
  or its inherited GtkWidget signals are dispatched when this happens.
 
  Any ideas?

 Tristan,

 I've had this same problem when developing
 gecko-mediaplayer/gnome-mplayer and mplayerplug-in. I was never able to
 fully use the GtkPlug interface. It just didn't work the way I needed it
 to.

 What I ended up doing is creating a normal toplevel window and then
 embedding it in the window that firefox gave me..

 Something like this where windowid is the xid I get from firefox.



window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

if (windowid  0  embedding_disabled == FALSE) {
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
GTK_WIDGET_SET_FLAGS(window, GTK_CAN_FOCUS);
}


   if (windowid != 0  embedding_disabled == FALSE) {
while (gtk_events_pending())
gtk_main_iteration();

window_container = gdk_window_foreign_new(windowid);
if (GTK_WIDGET_MAPPED(window))
gtk_widget_unmap(window);

gdk_window_reparent(window-window, window_container, 0, 0);
}


 Hope that helps.

 Kevin
 - --
 Get my public GnuPG key from
 http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x7D0BD5D1
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.10 (GNU/Linux)
 Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

 iEYEARECAAYFAktRA4AACgkQ6w2kMH0L1dFb0ACfdc7jssfzEnillFHhrUFOjDbW
 nsQAnj4Q6GCxg8H1zeoC9/NTx8kuRtDV
 =iMWg
 -END PGP SIGNATURE-



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


Re: Receiving a callback on GDK window destroy

2010-01-19 Thread Kevin DeKorte
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 01/19/10 20:09, Tristan Schmelcher wrote:
 Thanks Kevin! I'm trying out your suggestion and I've got the GtkWindow
 hooking up to the foreign GdkWindow properly, but it looks like I still
 get the same X server error when trying to draw after the browser
 destroys the GtkSocket's window, and I still can't find a signal/event
 that gets dispatched when that happens. :( e.g., delete, destroy,
 reparent, unmap, and unrealize are not dispatched. Do you remember if
 there was a particular event that you listened for to handle this case?
 

I think I am hooking see line 5982 in gui.c in gnome-mplayer

delete_signal_id =
g_signal_connect(GTK_OBJECT(window), delete_event,
G_CALLBACK(delete_callback), NULL);


and I also have function called from the class destructor that tells my
application to quit (calls shut()   line 382 in plugin.ccp).

The source code to gecko-mediaplayer (the browser plugin) is here:

http://code.google.com/p/gecko-mediaplayer/source/checkout

And the source to gnome-mplayer is here

http://code.google.com/p/gnome-mplayer/source/checkout


Kevin

 On 15 January 2010 16:08, Kevin DeKorte kdeko...@gmail.com
 mailto:kdeko...@gmail.com wrote:
 
 On 01/15/10 16:51, Tristan Schmelcher wrote:
 Hello,
 
 I'm a novice Gtk app developer writing a plugin for Firefox and I'm
 having trouble getting the callbacks that I need from Gtk/Gdk. The way
 the plugin architecture works is that Firefox creates a GtkSocket and
 my plugin gets passed its XID and creates the corresponding GtkPlug
 (in the same process). By and large everything works, except at
 shutdown. In some cases, Firefox happens to do a gdk_window_destroy()
 on one of the parent windows of the GtkSocket before unloading my
 plugin (for example, when closing a tab with the 'X'). That
 recursively destroys everything down to the GtkSocket and also the
 GtkPlug in _gdk_window_destroy_hierarchy(
 ). So when I try to access the underlying X11 Window handle after this
 I get an error from the X server and the program aborts. :(
 
 What I'd like to do is receive a signal from Gtk/Gdk when the
 GdkWindow inside my GtkPlug is destroyed like this so that I can
 cancel any further rendering actions. But I can't figure out how to
 receive a signal when this happens! AFAICT none of the GtkPlug signals
 or its inherited GtkWidget signals are dispatched when this happens.
 
 Any ideas?
 
 Tristan,
 
 I've had this same problem when developing
 gecko-mediaplayer/gnome-mplayer and mplayerplug-in. I was never able to
 fully use the GtkPlug interface. It just didn't work the way I needed it
 to.
 
 What I ended up doing is creating a normal toplevel window and then
 embedding it in the window that firefox gave me..
 
 Something like this where windowid is the xid I get from firefox.
 
 
 
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
if (windowid  0  embedding_disabled == FALSE) {
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
GTK_WIDGET_SET_FLAGS(window, GTK_CAN_FOCUS);
}
 
 
   if (windowid != 0  embedding_disabled == FALSE) {
while (gtk_events_pending())
gtk_main_iteration();
 
window_container = gdk_window_foreign_new(windowid);
if (GTK_WIDGET_MAPPED(window))
gtk_widget_unmap(window);
 
gdk_window_reparent(window-window, window_container, 0, 0);
}
 
 
 Hope that helps.
 
 Kevin

- -- 
Get my public GnuPG key from
http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x7D0BD5D1
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAktWjEkACgkQ6w2kMH0L1dH8OwCcDrnft8U+m1vH9OkklpEHQX5T
QuYAmwehrYVDxtE7Wpxdycp7mtds1ozc
=DkC7
-END PGP SIGNATURE-
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Receiving a callback on GDK window destroy

2010-01-19 Thread Kevin DeKorte
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 01/19/10 20:29, Tristan Schmelcher wrote:
 Actually, after debugging and looking at the code, it seems that
 gdk_window_foreign_new() first looks up if there is already a GdkWindow
 for that XID and re-uses it if so (gdk/x11/gdkwindow-x11.c:1008). So I
 don't think this approach will work. :(

You must be doing something wrong since you should get one xid per
windowed plugin instance. I've been using this method for years in both
the mplayerplug-in plugin and the gecko-mediaplayer plugin.

Take a look at either of those projects source code. I'm sure there is
something there that will help you.

Kevin
- -- 
Get my public GnuPG key from
http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x7D0BD5D1
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAktWjNQACgkQ6w2kMH0L1dG7vACcDZNHS0dTEbXCTHD0IesjVmeF
BCsAn3oewKsZFv/Dv6uV3vfKgR6k7iJl
=uFlq
-END PGP SIGNATURE-
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Receiving a callback on GDK window destroy

2010-01-16 Thread David Nečas
On Fri, Jan 15, 2010 at 11:51:38PM +, Tristan Schmelcher wrote:
 I'm a novice Gtk app developer writing a plugin for Firefox and I'm
 having trouble getting the callbacks that I need from Gtk/Gdk. The way
 the plugin architecture works is that Firefox creates a GtkSocket and
 my plugin gets passed its XID and creates the corresponding GtkPlug
 (in the same process). By and large everything works, except at
 shutdown. In some cases, Firefox happens to do a gdk_window_destroy()
 on one of the parent windows of the GtkSocket before unloading my
 plugin (for example, when closing a tab with the 'X'). That
 recursively destroys everything down to the GtkSocket and also the
 GtkPlug in _gdk_window_destroy_hierarchy(
 ). So when I try to access the underlying X11 Window handle after this
 I get an error from the X server and the program aborts. :(
 
 What I'd like to do is receive a signal from Gtk/Gdk when the
 GdkWindow inside my GtkPlug is destroyed like this so that I can
 cancel any further rendering actions. But I can't figure out how to
 receive a signal when this happens! AFAICT none of the GtkPlug signals
 or its inherited GtkWidget signals are dispatched when this happens.

What about g_object_weak_ref() on the GdkWindow?  Then you can get
notified when it's finalized (if it isn't too late for you).

Yeti

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


Receiving a callback on GDK window destroy

2010-01-15 Thread Tristan Schmelcher
Hello,

I'm a novice Gtk app developer writing a plugin for Firefox and I'm
having trouble getting the callbacks that I need from Gtk/Gdk. The way
the plugin architecture works is that Firefox creates a GtkSocket and
my plugin gets passed its XID and creates the corresponding GtkPlug
(in the same process). By and large everything works, except at
shutdown. In some cases, Firefox happens to do a gdk_window_destroy()
on one of the parent windows of the GtkSocket before unloading my
plugin (for example, when closing a tab with the 'X'). That
recursively destroys everything down to the GtkSocket and also the
GtkPlug in _gdk_window_destroy_hierarchy(
). So when I try to access the underlying X11 Window handle after this
I get an error from the X server and the program aborts. :(

What I'd like to do is receive a signal from Gtk/Gdk when the
GdkWindow inside my GtkPlug is destroyed like this so that I can
cancel any further rendering actions. But I can't figure out how to
receive a signal when this happens! AFAICT none of the GtkPlug signals
or its inherited GtkWidget signals are dispatched when this happens.

Any ideas?
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Receiving a callback on GDK window destroy

2010-01-15 Thread Kevin DeKorte
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 01/15/10 16:51, Tristan Schmelcher wrote:
 Hello,
 
 I'm a novice Gtk app developer writing a plugin for Firefox and I'm
 having trouble getting the callbacks that I need from Gtk/Gdk. The way
 the plugin architecture works is that Firefox creates a GtkSocket and
 my plugin gets passed its XID and creates the corresponding GtkPlug
 (in the same process). By and large everything works, except at
 shutdown. In some cases, Firefox happens to do a gdk_window_destroy()
 on one of the parent windows of the GtkSocket before unloading my
 plugin (for example, when closing a tab with the 'X'). That
 recursively destroys everything down to the GtkSocket and also the
 GtkPlug in _gdk_window_destroy_hierarchy(
 ). So when I try to access the underlying X11 Window handle after this
 I get an error from the X server and the program aborts. :(
 
 What I'd like to do is receive a signal from Gtk/Gdk when the
 GdkWindow inside my GtkPlug is destroyed like this so that I can
 cancel any further rendering actions. But I can't figure out how to
 receive a signal when this happens! AFAICT none of the GtkPlug signals
 or its inherited GtkWidget signals are dispatched when this happens.
 
 Any ideas?

Tristan,

I've had this same problem when developing
gecko-mediaplayer/gnome-mplayer and mplayerplug-in. I was never able to
fully use the GtkPlug interface. It just didn't work the way I needed it
to.

What I ended up doing is creating a normal toplevel window and then
embedding it in the window that firefox gave me..

Something like this where windowid is the xid I get from firefox.



window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

if (windowid  0  embedding_disabled == FALSE) {
gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
GTK_WIDGET_SET_FLAGS(window, GTK_CAN_FOCUS);
}


   if (windowid != 0  embedding_disabled == FALSE) {
while (gtk_events_pending())
gtk_main_iteration();

window_container = gdk_window_foreign_new(windowid);
if (GTK_WIDGET_MAPPED(window))
gtk_widget_unmap(window);

gdk_window_reparent(window-window, window_container, 0, 0);
}


Hope that helps.

Kevin
- -- 
Get my public GnuPG key from
http://pgp.mit.edu:11371/pks/lookup?op=getsearch=0x7D0BD5D1
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAktRA4AACgkQ6w2kMH0L1dFb0ACfdc7jssfzEnillFHhrUFOjDbW
nsQAnj4Q6GCxg8H1zeoC9/NTx8kuRtDV
=iMWg
-END PGP SIGNATURE-
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list