diff options
author | Owen Taylor <otaylor@redhat.com> | 2001-07-03 14:14:30 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2001-07-03 14:14:30 +0000 |
commit | f409cd9b7f6513acf816e5b3335231bc733f29a6 (patch) | |
tree | 1df2a5203199c8007960dacf78154650698f0a97 /tests/testsocket.c | |
parent | b6cc525fa098f0cade116e0dc29e5614237d48ab (diff) | |
download | gtk+-f409cd9b7f6513acf816e5b3335231bc733f29a6.tar.gz |
For XEMBED embedding add a _XEMBED_INFO property to the client with
Mon Jul 2 16:53:25 2001 Owen Taylor <otaylor@redhat.com>
* gtk/xembed.h gtk/gtkplug.c gtk/gtksocket.c: For
XEMBED embedding add a _XEMBED_INFO property to the
client with version number and a "mapped" flags.
Use the mapped flag instead of the racy MapRequestEvent
* gtk/gtksocket.c: Clean up the gtk_socket_steal()
code to reliably set things (when the child is a passive
embedder participating in the XEMBED protocol) intead
of just being a hack for embedding non-participating
programs. Fix various bugs and race conditions.
* gtk/gtksocket.[ch] gtk/gtkplug.[ch]: Make local embedding
work by simply making the GtkSocket the gtk parent
of the GtkPlug. Set a flag in this case and make
the GtkPlug work like a normal container by overriding
methods such as check_resize and "chaining past" GtkWindow
to GtkBin.
* gtk/gtkentry.c (gtk_entry_real_activate)
gtk/gtkmain.c (gtk_propagate_event):
Eliminate use of gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW).
* gtk/gtkwidget.c (gtk_widget_get_toplevel,
gtk_widget_get_ancestor):
Explain why gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW)
might not give the expected result and recommend
an alternative.
* tests/testsocket.c tests/testsocket_child.c
tests/testsocket_common.c tests/Makefile.am: Extended
to test different type of adding plugs to sockets
(local,active,passive), and to test mapping/unmapping
the plug.
* gdk/gdkwindow.c (_gdk_window_destroy_hierarchy): Don't
mark the window as destroyed until after we
called _gdk_windowing_window_destroy().
(_gdk_windowing_window_destroy() may use GDK functions
on the window.)
* gdk/x11/gdkinput.c: Remove the check for finalization -
devices can be finalized under some circumnstances.
* gdk/x11/gdkinput-x11.c (gdk_input_device_new): Fix
small problem with GDK_TYPE_DEVICE.
Diffstat (limited to 'tests/testsocket.c')
-rw-r--r-- | tests/testsocket.c | 134 |
1 files changed, 125 insertions, 9 deletions
diff --git a/tests/testsocket.c b/tests/testsocket.c index a775eefd38..ab71501f1e 100644 --- a/tests/testsocket.c +++ b/tests/testsocket.c @@ -10,11 +10,17 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> +#include <unistd.h> + +int n_children = 0; GtkWidget *window; GtkWidget *vbox; GtkWidget *lastsocket = NULL; +extern guint32 create_child_plug (guint32 xid, + gboolean local); + static void quit_cb (gpointer callback_data, guint callback_action, @@ -64,17 +70,66 @@ steal (GtkWidget *window, GtkEntry *entry) void remove_child (GtkWidget *window) { - if(lastsocket) + if (lastsocket) gtk_widget_destroy (lastsocket); lastsocket = NULL; } +static gboolean +child_read_watch (GIOChannel *channel, GIOCondition cond, gpointer data) +{ + GIOStatus status; + GError *error = NULL; + char *line; + gsize term; + int xid; + + status = g_io_channel_read_line (channel, &line, NULL, &term, &error); + switch (status) + { + case G_IO_STATUS_NORMAL: + line[term] = '\0'; + xid = strtol (line, NULL, 0); + if (xid == 0) + { + fprintf (stderr, "Invalid window id '%s'\n", line); + } + else + { + GtkWidget *socket = gtk_socket_new (); + gtk_box_pack_start (GTK_BOX (vbox), socket, TRUE, TRUE, 0); + gtk_widget_show (socket); + + gtk_socket_steal (GTK_SOCKET (socket), xid); + } + g_free (line); + return TRUE; + case G_IO_STATUS_AGAIN: + return TRUE; + case G_IO_STATUS_EOF: + n_children--; + g_io_channel_close (channel); + return FALSE; + case G_IO_STATUS_ERROR: + fprintf (stderr, "Error reading fd from child: %s\n", error->message); + exit (1); + return FALSE; + default: + g_assert_not_reached (); + return FALSE; + } + +} + void -add_child (GtkWidget *window) +add_child (GtkWidget *window, + gboolean active) { GtkWidget *socket; char *argv[3] = { "./testsocket_child", NULL, NULL }; char buffer[20]; + int out_fd; + GIOChannel *channel; GError *error = NULL; socket = gtk_socket_new (); @@ -83,20 +138,61 @@ add_child (GtkWidget *window) lastsocket = socket; - sprintf(buffer, "%#lx", GDK_WINDOW_XWINDOW (socket->window)); - argv[1] = buffer; + if (active) + { + sprintf(buffer, "%#lx", GDK_WINDOW_XWINDOW (socket->window)); + argv[1] = buffer; + } #if 1 - if (!g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &error)) + if (!g_spawn_async_with_pipes (NULL, argv, NULL, 0, NULL, NULL, NULL, NULL, &out_fd, NULL, &error)) { fprintf (stderr, "Can't exec testsocket_child: %s\n", error->message); exit (1); } + + n_children++; + channel = g_io_channel_unix_new (out_fd); + g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, &error); + if (error) + { + fprintf (stderr, "Error making channel non-blocking: %s\n", error->message); + exit (1); + } + + g_io_add_watch (channel, G_IO_IN | G_IO_HUP, child_read_watch, NULL); + #else fprintf(stderr,"%s\n", buffer); #endif } +void +add_active_child (GtkWidget *window) +{ + add_child (window, TRUE); +} + +void +add_passive_child (GtkWidget *window) +{ + add_child (window, FALSE); +} + +void +add_local_child (GtkWidget *window) +{ + GtkWidget *socket; + + socket = gtk_socket_new (); + gtk_box_pack_start (GTK_BOX (vbox), socket, TRUE, TRUE, 0); + gtk_widget_show (socket); + + lastsocket = socket; + + create_child_plug (GDK_WINDOW_XWINDOW (socket->window), TRUE); +} + int main (int argc, char *argv[]) { @@ -131,11 +227,25 @@ main (int argc, char *argv[]) gtk_item_factory_get_widget (item_factory, "<main>"), FALSE, FALSE, 0); - button = gtk_button_new_with_label ("Add Child"); + button = gtk_button_new_with_label ("Add Active Child"); gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); gtk_signal_connect_object (GTK_OBJECT(button), "clicked", - GTK_SIGNAL_FUNC(add_child), + GTK_SIGNAL_FUNC(add_active_child), + GTK_OBJECT(vbox)); + + button = gtk_button_new_with_label ("Add Passive Child"); + gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); + + gtk_signal_connect_object (GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(add_passive_child), + GTK_OBJECT(vbox)); + + button = gtk_button_new_with_label ("Add Local Child"); + gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); + + gtk_signal_connect_object (GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(add_local_child), GTK_OBJECT(vbox)); button = gtk_button_new_with_label ("Remove Last Child"); @@ -162,7 +272,13 @@ main (int argc, char *argv[]) gtk_main (); - return 0; -} + if (n_children) + { + g_print ("Waiting for children to exit\n"); + while (n_children) + g_main_iteration (TRUE); + } + return 0; +} |