1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* By Owen Taylor <otaylor@gtk.org> 98/4/4 */
22 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include "gtksocket.h"
34 #include "gdk/gdkkeysyms.h"
36 #include "gtkmarshalers.h"
37 #include "gtksizerequest.h"
38 #include "gtkwindow.h"
40 #include "gtkprivate.h"
41 #include "gtksocketprivate.h"
49 * @Short_description: Container for widgets from other processes
51 * @See_also: #GtkPlug, <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
53 * Together with #GtkPlug, #GtkSocket provides the ability
54 * to embed widgets from one process into another process
55 * in a fashion that is transparent to the user. One
56 * process creates a #GtkSocket widget and passes
57 * that widget's window ID to the other process,
58 * which then creates a #GtkPlug with that window ID.
59 * Any widgets contained in the #GtkPlug then will appear
60 * inside the first application's window.
62 * The socket's window ID is obtained by using
63 * gtk_socket_get_id(). Before using this function,
64 * the socket must have been realized, and for hence,
65 * have been added to its parent.
68 * <title>Obtaining the window ID of a socket.</title>
70 * GtkWidget *socket = gtk_socket_new (<!-- -->);
71 * gtk_widget_show (socket);
72 * gtk_container_add (GTK_CONTAINER (parent), socket);
74 * /<!---->* The following call is only necessary if one of
75 * * the ancestors of the socket is not yet visible.
77 * gtk_widget_realize (socket);
78 * g_print ("The ID of the sockets window is %#x\n",
79 * gtk_socket_get_id (socket));
83 * Note that if you pass the window ID of the socket to another
84 * process that will create a plug in the socket, you
85 * must make sure that the socket widget is not destroyed
86 * until that plug is created. Violating this rule will
87 * cause unpredictable consequences, the most likely
88 * consequence being that the plug will appear as a
89 * separate toplevel window. You can check if the plug
90 * has been created by using gtk_socket_get_plug_window(). If
91 * it returns a non-%NULL value, then the plug has been
92 * successfully created inside of the socket.
94 * When GTK+ is notified that the embedded window has been
95 * destroyed, then it will destroy the socket as well. You
96 * should always, therefore, be prepared for your sockets
97 * to be destroyed at any time when the main event loop
98 * is running. To prevent this from happening, you can
99 * connect to the #GtkSocket::plug-removed signal.
101 * The communication between a #GtkSocket and a #GtkPlug follows the
102 * <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
103 * protocol. This protocol has also been implemented in other toolkits, e.g.
104 * <application>Qt</application>, allowing the same level of integration
105 * when embedding a <application>Qt</application> widget in GTK or vice versa.
108 * The #GtkPlug and #GtkSocket widgets are currently not available
109 * on all platforms supported by GTK+.
113 /* Forward declararations */
115 static void gtk_socket_finalize (GObject *object);
116 static void gtk_socket_notify (GObject *object,
118 static void gtk_socket_realize (GtkWidget *widget);
119 static void gtk_socket_unrealize (GtkWidget *widget);
120 static void gtk_socket_size_request (GtkWidget *widget,
121 GtkRequisition *requisition);
122 static void gtk_socket_size_allocate (GtkWidget *widget,
123 GtkAllocation *allocation);
124 static void gtk_socket_hierarchy_changed (GtkWidget *widget,
125 GtkWidget *old_toplevel);
126 static void gtk_socket_grab_notify (GtkWidget *widget,
127 gboolean was_grabbed);
128 static gboolean gtk_socket_key_event (GtkWidget *widget,
130 static gboolean gtk_socket_focus (GtkWidget *widget,
131 GtkDirectionType direction);
132 static void gtk_socket_remove (GtkContainer *container,
134 static void gtk_socket_forall (GtkContainer *container,
135 gboolean include_internals,
136 GtkCallback callback,
137 gpointer callback_data);
145 GdkModifierType accel_mods;
154 static guint socket_signals[LAST_SIGNAL] = { 0 };
157 * _gtk_socket_get_private:
159 * @socket: a #GtkSocket
161 * Returns the private data associated with a GtkSocket, creating it
162 * first if necessary.
165 _gtk_socket_get_private (GtkSocket *socket)
167 return G_TYPE_INSTANCE_GET_PRIVATE (socket, GTK_TYPE_SOCKET, GtkSocketPrivate);
170 G_DEFINE_TYPE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER)
173 gtk_socket_finalize (GObject *object)
175 GtkSocket *socket = GTK_SOCKET (object);
177 g_object_unref (socket->accel_group);
178 socket->accel_group = NULL;
180 G_OBJECT_CLASS (gtk_socket_parent_class)->finalize (object);
184 gtk_socket_class_init (GtkSocketClass *class)
186 GtkWidgetClass *widget_class;
187 GtkContainerClass *container_class;
188 GObjectClass *gobject_class;
190 gobject_class = (GObjectClass *) class;
191 widget_class = (GtkWidgetClass*) class;
192 container_class = (GtkContainerClass*) class;
194 gobject_class->finalize = gtk_socket_finalize;
195 gobject_class->notify = gtk_socket_notify;
197 widget_class->realize = gtk_socket_realize;
198 widget_class->unrealize = gtk_socket_unrealize;
199 widget_class->size_request = gtk_socket_size_request;
200 widget_class->size_allocate = gtk_socket_size_allocate;
201 widget_class->hierarchy_changed = gtk_socket_hierarchy_changed;
202 widget_class->grab_notify = gtk_socket_grab_notify;
203 widget_class->key_press_event = gtk_socket_key_event;
204 widget_class->key_release_event = gtk_socket_key_event;
205 widget_class->focus = gtk_socket_focus;
207 /* We don't want to show_all the in-process plug, if any.
209 widget_class->show_all = gtk_widget_show;
211 container_class->remove = gtk_socket_remove;
212 container_class->forall = gtk_socket_forall;
215 * GtkSocket::plug-added:
216 * @socket_: the object which received the signal
218 * This signal is emitted when a client is successfully
219 * added to the socket.
221 socket_signals[PLUG_ADDED] =
222 g_signal_new (I_("plug-added"),
223 G_OBJECT_CLASS_TYPE (class),
225 G_STRUCT_OFFSET (GtkSocketClass, plug_added),
227 _gtk_marshal_VOID__VOID,
231 * GtkSocket::plug-removed:
232 * @socket_: the object which received the signal
234 * This signal is emitted when a client is removed from the socket.
235 * The default action is to destroy the #GtkSocket widget, so if you
236 * want to reuse it you must add a signal handler that returns %TRUE.
238 * Return value: %TRUE to stop other handlers from being invoked.
240 socket_signals[PLUG_REMOVED] =
241 g_signal_new (I_("plug-removed"),
242 G_OBJECT_CLASS_TYPE (class),
244 G_STRUCT_OFFSET (GtkSocketClass, plug_removed),
245 _gtk_boolean_handled_accumulator, NULL,
246 _gtk_marshal_BOOLEAN__VOID,
249 g_type_class_add_private (gobject_class, sizeof (GtkSocketPrivate));
253 gtk_socket_init (GtkSocket *socket)
255 socket->request_width = 0;
256 socket->request_height = 0;
257 socket->current_width = 0;
258 socket->current_height = 0;
260 socket->plug_window = NULL;
261 socket->plug_widget = NULL;
262 socket->focus_in = FALSE;
263 socket->have_size = FALSE;
264 socket->need_map = FALSE;
265 socket->active = FALSE;
267 socket->accel_group = gtk_accel_group_new ();
268 g_object_set_data (G_OBJECT (socket->accel_group), I_("gtk-socket"), socket);
274 * Create a new empty #GtkSocket.
276 * Return value: the new #GtkSocket.
279 gtk_socket_new (void)
283 socket = g_object_new (GTK_TYPE_SOCKET, NULL);
285 return GTK_WIDGET (socket);
290 * @socket_: a #GtkSocket
291 * @window_id: the window ID of a client participating in the XEMBED protocol.
293 * Adds an XEMBED client, such as a #GtkPlug, to the #GtkSocket. The
294 * client may be in the same process or in a different process.
296 * To embed a #GtkPlug in a #GtkSocket, you can either create the
297 * #GtkPlug with <literal>gtk_plug_new (0)</literal>, call
298 * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
299 * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
300 * window ID for the socket, and call gtk_plug_new() passing in that
303 * The #GtkSocket must have already be added into a toplevel window
304 * before you can make this call.
307 gtk_socket_add_id (GtkSocket *socket,
308 GdkNativeWindow window_id)
310 g_return_if_fail (GTK_IS_SOCKET (socket));
311 g_return_if_fail (_gtk_widget_get_anchored (GTK_WIDGET (socket)));
313 if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
314 gtk_widget_realize (GTK_WIDGET (socket));
316 _gtk_socket_add_window (socket, window_id, TRUE);
321 * @socket_: a #GtkSocket.
323 * Gets the window ID of a #GtkSocket widget, which can then
324 * be used to create a client embedded inside the socket, for
325 * instance with gtk_plug_new().
327 * The #GtkSocket must have already be added into a toplevel window
328 * before you can make this call.
330 * Return value: the window ID for the socket
333 gtk_socket_get_id (GtkSocket *socket)
335 g_return_val_if_fail (GTK_IS_SOCKET (socket), 0);
336 g_return_val_if_fail (_gtk_widget_get_anchored (GTK_WIDGET (socket)), 0);
338 if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
339 gtk_widget_realize (GTK_WIDGET (socket));
341 return _gtk_socket_windowing_get_id (socket);
345 * gtk_socket_get_plug_window:
346 * @socket_: a #GtkSocket.
348 * Retrieves the window of the plug. Use this to check if the plug has
349 * been created inside of the socket.
351 * Return value: (transfer none): the window of the plug if available, or %NULL
356 gtk_socket_get_plug_window (GtkSocket *socket)
358 g_return_val_if_fail (GTK_IS_SOCKET (socket), NULL);
360 return socket->plug_window;
364 gtk_socket_realize (GtkWidget *widget)
366 GtkAllocation allocation;
367 GtkSocket *socket = GTK_SOCKET (widget);
369 GdkWindowAttr attributes;
370 gint attributes_mask;
372 gtk_widget_set_realized (widget, TRUE);
374 gtk_widget_get_allocation (widget, &allocation);
376 attributes.window_type = GDK_WINDOW_CHILD;
377 attributes.x = allocation.x;
378 attributes.y = allocation.y;
379 attributes.width = allocation.width;
380 attributes.height = allocation.height;
381 attributes.wclass = GDK_INPUT_OUTPUT;
382 attributes.visual = gtk_widget_get_visual (widget);
383 attributes.event_mask = GDK_FOCUS_CHANGE_MASK;
385 attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
387 window = gdk_window_new (gtk_widget_get_parent_window (widget),
388 &attributes, attributes_mask);
389 gtk_widget_set_window (widget, window);
390 gdk_window_set_user_data (window, socket);
392 gtk_widget_style_attach (widget);
393 gtk_style_set_background (gtk_widget_get_style (widget),
394 window, GTK_STATE_NORMAL);
396 _gtk_socket_windowing_realize_window (socket);
398 gdk_window_add_filter (window,
399 _gtk_socket_windowing_filter_func,
402 /* We sync here so that we make sure that if the XID for
403 * our window is passed to another application, SubstructureRedirectMask
404 * will be set by the time the other app creates its window.
406 gdk_display_sync (gtk_widget_get_display (widget));
410 * _gtk_socket_end_embedding:
412 * @socket: a #GtkSocket
414 * Called to end the embedding of a plug in the socket.
417 _gtk_socket_end_embedding (GtkSocket *socket)
419 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
420 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
422 if (GTK_IS_WINDOW (toplevel))
423 _gtk_socket_windowing_end_embedding_toplevel (socket);
425 g_object_unref (socket->plug_window);
426 socket->plug_window = NULL;
427 socket->current_width = 0;
428 socket->current_height = 0;
429 private->resize_count = 0;
431 gtk_accel_group_disconnect (socket->accel_group, NULL);
435 gtk_socket_unrealize (GtkWidget *widget)
437 GtkSocket *socket = GTK_SOCKET (widget);
439 gtk_widget_set_realized (widget, FALSE);
441 if (socket->plug_widget)
443 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
445 else if (socket->plug_window)
447 _gtk_socket_end_embedding (socket);
450 GTK_WIDGET_CLASS (gtk_socket_parent_class)->unrealize (widget);
454 gtk_socket_size_request (GtkWidget *widget,
455 GtkRequisition *requisition)
457 GtkSocket *socket = GTK_SOCKET (widget);
459 if (socket->plug_widget)
461 gtk_widget_get_preferred_size (socket->plug_widget, requisition, NULL);
465 if (socket->is_mapped && !socket->have_size && socket->plug_window)
466 _gtk_socket_windowing_size_request (socket);
468 if (socket->is_mapped && socket->have_size)
470 requisition->width = MAX (socket->request_width, 1);
471 requisition->height = MAX (socket->request_height, 1);
475 requisition->width = 1;
476 requisition->height = 1;
482 gtk_socket_size_allocate (GtkWidget *widget,
483 GtkAllocation *allocation)
485 GtkSocket *socket = GTK_SOCKET (widget);
487 gtk_widget_set_allocation (widget, allocation);
488 if (gtk_widget_get_realized (widget))
490 gdk_window_move_resize (gtk_widget_get_window (widget),
491 allocation->x, allocation->y,
492 allocation->width, allocation->height);
494 if (socket->plug_widget)
496 GtkAllocation child_allocation;
498 child_allocation.x = 0;
499 child_allocation.y = 0;
500 child_allocation.width = allocation->width;
501 child_allocation.height = allocation->height;
503 gtk_widget_size_allocate (socket->plug_widget, &child_allocation);
505 else if (socket->plug_window)
507 GtkSocketPrivate *private = _gtk_socket_get_private (socket);
509 gdk_error_trap_push ();
511 if (allocation->width != socket->current_width ||
512 allocation->height != socket->current_height)
514 gdk_window_move_resize (socket->plug_window,
516 allocation->width, allocation->height);
517 if (private->resize_count)
518 private->resize_count--;
520 GTK_NOTE (PLUGSOCKET,
521 g_message ("GtkSocket - allocated: %d %d",
522 allocation->width, allocation->height));
523 socket->current_width = allocation->width;
524 socket->current_height = allocation->height;
527 if (socket->need_map)
529 gdk_window_show (socket->plug_window);
530 socket->need_map = FALSE;
533 while (private->resize_count)
535 _gtk_socket_windowing_send_configure_event (socket);
536 private->resize_count--;
537 GTK_NOTE (PLUGSOCKET,
538 g_message ("GtkSocket - sending synthetic configure: %d %d",
539 allocation->width, allocation->height));
542 gdk_error_trap_pop_ignored ();
548 activate_key (GtkAccelGroup *accel_group,
549 GObject *acceleratable,
551 GdkModifierType accel_mods,
552 GrabbedKey *grabbed_key)
554 GdkEvent *gdk_event = gtk_get_current_event ();
556 GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
557 gboolean retval = FALSE;
559 if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
561 _gtk_socket_windowing_send_key_event (socket, gdk_event, FALSE);
566 gdk_event_free (gdk_event);
572 find_accel_key (GtkAccelKey *key,
576 GrabbedKey *grabbed_key = data;
578 return (key->accel_key == grabbed_key->accel_key &&
579 key->accel_mods == grabbed_key->accel_mods);
583 * _gtk_socket_add_grabbed_key:
585 * @socket: a #GtkSocket
587 * @modifiers: modifiers for the key
589 * Called from the GtkSocket platform-specific backend when the
590 * corresponding plug has told the socket to grab a key.
593 _gtk_socket_add_grabbed_key (GtkSocket *socket,
595 GdkModifierType modifiers)
598 GrabbedKey *grabbed_key;
600 grabbed_key = g_new (GrabbedKey, 1);
602 grabbed_key->accel_key = keyval;
603 grabbed_key->accel_mods = modifiers;
605 if (gtk_accel_group_find (socket->accel_group,
609 g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
611 g_free (grabbed_key);
615 closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
617 gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
622 * _gtk_socket_remove_grabbed_key:
624 * @socket: a #GtkSocket
626 * @modifiers: modifiers for the key
628 * Called from the GtkSocket backend when the corresponding plug has
629 * told the socket to remove a key grab.
632 _gtk_socket_remove_grabbed_key (GtkSocket *socket,
634 GdkModifierType modifiers)
636 if (!gtk_accel_group_disconnect_key (socket->accel_group, keyval, modifiers))
637 g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
642 socket_update_focus_in (GtkSocket *socket)
644 gboolean focus_in = FALSE;
646 if (socket->plug_window)
648 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
650 if (gtk_widget_is_toplevel (toplevel) &&
651 gtk_window_has_toplevel_focus (GTK_WINDOW (toplevel)) &&
652 gtk_widget_is_focus (GTK_WIDGET (socket)))
656 if (focus_in != socket->focus_in)
658 socket->focus_in = focus_in;
660 _gtk_socket_windowing_focus_change (socket, focus_in);
665 socket_update_active (GtkSocket *socket)
667 gboolean active = FALSE;
669 if (socket->plug_window)
671 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
673 if (gtk_widget_is_toplevel (toplevel) &&
674 gtk_window_is_active (GTK_WINDOW (toplevel)))
678 if (active != socket->active)
680 socket->active = active;
682 _gtk_socket_windowing_update_active (socket, active);
687 gtk_socket_hierarchy_changed (GtkWidget *widget,
688 GtkWidget *old_toplevel)
690 GtkSocket *socket = GTK_SOCKET (widget);
691 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
693 if (toplevel && !GTK_IS_WINDOW (toplevel))
696 if (toplevel != socket->toplevel)
698 if (socket->toplevel)
700 gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
701 g_signal_handlers_disconnect_by_func (socket->toplevel,
702 socket_update_focus_in,
704 g_signal_handlers_disconnect_by_func (socket->toplevel,
705 socket_update_active,
709 socket->toplevel = toplevel;
713 gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
714 g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
715 G_CALLBACK (socket_update_focus_in), socket);
716 g_signal_connect_swapped (socket->toplevel, "notify::is-active",
717 G_CALLBACK (socket_update_active), socket);
720 socket_update_focus_in (socket);
721 socket_update_active (socket);
726 gtk_socket_grab_notify (GtkWidget *widget,
727 gboolean was_grabbed)
729 GtkSocket *socket = GTK_SOCKET (widget);
731 if (!socket->same_app)
732 _gtk_socket_windowing_update_modality (socket, !was_grabbed);
736 gtk_socket_key_event (GtkWidget *widget,
739 GtkSocket *socket = GTK_SOCKET (widget);
741 if (gtk_widget_has_focus (widget) && socket->plug_window && !socket->plug_widget)
743 _gtk_socket_windowing_send_key_event (socket, (GdkEvent *) event, FALSE);
752 gtk_socket_notify (GObject *object,
755 if (!strcmp (pspec->name, "is-focus"))
757 socket_update_focus_in (GTK_SOCKET (object));
761 * _gtk_socket_claim_focus:
763 * @socket: a #GtkSocket
766 * Claims focus for the socket. XXX send_event?
769 _gtk_socket_claim_focus (GtkSocket *socket,
772 GtkWidget *widget = GTK_WIDGET (socket);
775 socket->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
777 /* Oh, the trickery... */
779 gtk_widget_set_can_focus (widget, TRUE);
780 gtk_widget_grab_focus (widget);
781 gtk_widget_set_can_focus (widget, FALSE);
785 gtk_socket_focus (GtkWidget *widget,
786 GtkDirectionType direction)
788 GtkSocket *socket = GTK_SOCKET (widget);
790 if (socket->plug_widget)
791 return gtk_widget_child_focus (socket->plug_widget, direction);
793 if (!gtk_widget_is_focus (widget))
795 _gtk_socket_windowing_focus (socket, direction);
796 _gtk_socket_claim_focus (socket, FALSE);
805 gtk_socket_remove (GtkContainer *container,
808 GtkSocket *socket = GTK_SOCKET (container);
810 g_return_if_fail (child == socket->plug_widget);
812 _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
816 gtk_socket_forall (GtkContainer *container,
817 gboolean include_internals,
818 GtkCallback callback,
819 gpointer callback_data)
821 GtkSocket *socket = GTK_SOCKET (container);
823 if (socket->plug_widget)
824 (* callback) (socket->plug_widget, callback_data);
828 * _gtk_socket_add_window:
830 * @socket: a #GtkSocket
831 * @xid: the native identifier for a window
832 * @need_reparent: whether the socket's plug's window needs to be
833 * reparented to the socket
835 * Adds a window to a GtkSocket.
838 _gtk_socket_add_window (GtkSocket *socket,
840 gboolean need_reparent)
842 GtkWidget *widget = GTK_WIDGET (socket);
843 GdkDisplay *display = gtk_widget_get_display (widget);
844 gpointer user_data = NULL;
846 socket->plug_window = gdk_window_lookup_for_display (display, xid);
848 if (socket->plug_window)
850 g_object_ref (socket->plug_window);
851 gdk_window_get_user_data (socket->plug_window, &user_data);
854 if (user_data) /* A widget's window in this process */
856 GtkWidget *child_widget = user_data;
858 if (!GTK_IS_PLUG (child_widget))
860 g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
861 socket->plug_window = NULL;
862 gdk_error_trap_pop_ignored ();
867 _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
869 else /* A foreign window */
872 GdkDragProtocol protocol;
874 gdk_error_trap_push ();
876 if (!socket->plug_window)
878 socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
879 if (!socket->plug_window) /* was deleted before we could get it */
881 gdk_error_trap_pop_ignored ();
886 _gtk_socket_windowing_select_plug_window_input (socket);
888 if (gdk_error_trap_pop ())
890 g_object_unref (socket->plug_window);
891 socket->plug_window = NULL;
895 /* OK, we now will reliably get destroy notification on socket->plug_window */
897 gdk_error_trap_push ();
901 gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
902 gdk_window_reparent (socket->plug_window,
903 gtk_widget_get_window (widget),
907 socket->have_size = FALSE;
909 _gtk_socket_windowing_embed_get_info (socket);
911 socket->need_map = socket->is_mapped;
913 if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
914 gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
917 gdk_error_trap_pop_ignored ();
919 gdk_window_add_filter (socket->plug_window,
920 _gtk_socket_windowing_filter_func,
923 /* Add a pointer to the socket on our toplevel window */
925 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
926 if (GTK_IS_WINDOW (toplevel))
927 gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
929 _gtk_socket_windowing_embed_notify (socket);
931 socket_update_active (socket);
932 socket_update_focus_in (socket);
934 gtk_widget_queue_resize (GTK_WIDGET (socket));
937 if (socket->plug_window)
938 g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
942 * _gtk_socket_handle_map_request:
944 * @socket: a #GtkSocket
946 * Called from the GtkSocket backend when the plug has been mapped.
949 _gtk_socket_handle_map_request (GtkSocket *socket)
951 if (!socket->is_mapped)
953 socket->is_mapped = TRUE;
954 socket->need_map = TRUE;
956 gtk_widget_queue_resize (GTK_WIDGET (socket));
961 * _gtk_socket_unmap_notify:
963 * @socket: a #GtkSocket
965 * Called from the GtkSocket backend when the plug has been unmapped ???
968 _gtk_socket_unmap_notify (GtkSocket *socket)
970 if (socket->is_mapped)
972 socket->is_mapped = FALSE;
973 gtk_widget_queue_resize (GTK_WIDGET (socket));
978 * _gtk_socket_advance_toplevel_focus:
980 * @socket: a #GtkSocket
981 * @direction: a direction
983 * Called from the GtkSocket backend when the corresponding plug
984 * has told the socket to move the focus.
987 _gtk_socket_advance_toplevel_focus (GtkSocket *socket,
988 GtkDirectionType direction)
992 GtkContainer *container;
994 GtkWidget *focus_widget;
996 GtkWidget *old_focus_child;
999 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
1003 if (!gtk_widget_is_toplevel (toplevel) || GTK_IS_PLUG (toplevel))
1005 gtk_widget_child_focus (toplevel,direction);
1009 container = GTK_CONTAINER (toplevel);
1010 window = GTK_WINDOW (toplevel);
1011 bin = GTK_BIN (toplevel);
1013 /* This is a copy of gtk_window_focus(), modified so that we
1014 * can detect wrap-around.
1016 old_focus_child = gtk_container_get_focus_child (container);
1018 if (old_focus_child)
1020 if (gtk_widget_child_focus (old_focus_child, direction))
1023 /* We are allowed exactly one wrap-around per sequence of focus
1026 if (_gtk_socket_windowing_embed_get_focus_wrapped ())
1029 _gtk_socket_windowing_embed_set_focus_wrapped ();
1032 focus_widget = gtk_window_get_focus (window);
1035 /* Wrapped off the end, clear the focus setting for the toplevel */
1036 parent = gtk_widget_get_parent (focus_widget);
1039 gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
1040 parent = gtk_widget_get_parent (parent);
1043 gtk_window_set_focus (GTK_WINDOW (container), NULL);
1046 /* Now try to focus the first widget in the window */
1047 child = gtk_bin_get_child (bin);
1050 if (gtk_widget_child_focus (child, direction))