* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.Free
*/
/* By Owen Taylor <otaylor@gtk.org> 98/4/4 */
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include "gdk/gdkkeysyms.h"
-#include "gtkmain.h"
-#include "gtkwindow.h"
-#include "gtksignal.h"
-#include "gtksocket.h"
+#include "config.h"
+
+#include "gtksocketprivate.h"
+
+#include <string.h>
+
+#include "gtkmarshalers.h"
+#include "gtksizerequest.h"
+#include "gtkplug.h"
+#include "gtkprivate.h"
#include "gtkdnd.h"
+#include "gtkdebug.h"
+#include "gtkintl.h"
+#include "gtkmain.h"
+#include "gtkwidgetprivate.h"
+
+#include <gdk/gdkx.h>
+#include <gdk/gdkprivate.h>
+
+#ifdef HAVE_XFIXES
+#include <X11/extensions/Xfixes.h>
+#endif
+
+#include "gtkxembed.h"
-#include "x11/gdkx.h"
-#include "xembed.h"
+/**
+ * SECTION:gtksocket
+ * @Short_description: Container for widgets from other processes
+ * @Title: GtkSocket
+ * @include: gtk/gtkx.h
+ * @See_also: #GtkPlug, <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
+ *
+ * Together with #GtkPlug, #GtkSocket provides the ability to embed
+ * widgets from one process into another process in a fashion that
+ * is transparent to the user. One process creates a #GtkSocket widget
+ * and passes that widget's window ID to the other process, which then
+ * creates a #GtkPlug with that window ID. Any widgets contained in the
+ * #GtkPlug then will appear inside the first application's window.
+ *
+ * The socket's window ID is obtained by using gtk_socket_get_id().
+ * Before using this function, the socket must have been realized,
+ * and for hence, have been added to its parent.
+ *
+ * <example>
+ * <title>Obtaining the window ID of a socket.</title>
+ * <programlisting>
+ * GtkWidget *socket = gtk_socket_new (<!-- -->);
+ * gtk_widget_show (socket);
+ * gtk_container_add (GTK_CONTAINER (parent), socket);
+ *
+ * /* The following call is only necessary if one of
+ * * the ancestors of the socket is not yet visible.
+ * */
+ * gtk_widget_realize (socket);
+ * g_print ("The ID of the sockets window is %#x\n",
+ * gtk_socket_get_id (socket));
+ * </programlisting>
+ * </example>
+ *
+ * Note that if you pass the window ID of the socket to another
+ * process that will create a plug in the socket, you must make
+ * sure that the socket widget is not destroyed until that plug
+ * is created. Violating this rule will cause unpredictable
+ * consequences, the most likely consequence being that the plug
+ * will appear as a separate toplevel window. You can check if
+ * the plug has been created by using gtk_socket_get_plug_window().
+ * If it returns a non-%NULL value, then the plug has been
+ * successfully created inside of the socket.
+ *
+ * When GTK+ is notified that the embedded window has been destroyed,
+ * then it will destroy the socket as well. You should always,
+ * therefore, be prepared for your sockets to be destroyed at any
+ * time when the main event loop is running. To prevent this from
+ * happening, you can connect to the #GtkSocket::plug-removed signal.
+ *
+ * The communication between a #GtkSocket and a #GtkPlug follows the
+ * <ulink url="http://www.freedesktop.org/Standards/xembed-spec">XEmbed</ulink>
+ * protocol. This protocol has also been implemented in other toolkits,
+ * e.g. <application>Qt</application>, allowing the same level of
+ * integration when embedding a <application>Qt</application> widget
+ * in GTK or vice versa.
+ *
+ * <note>
+ * The #GtkPlug and #GtkSocket widgets are only available when GTK+
+ * is compiled for the X11 platform and %GDK_WINDOWING_X11 is defined.
+ * They can only be used on a #GdkX11Display. To use #GtkPlug and
+ * #GtkSocket, you need to include the <filename>gtk/gtkx.h</filename>
+ * header.
+ * </note>
+ */
/* Forward declararations */
-static void gtk_socket_class_init (GtkSocketClass *klass);
-static void gtk_socket_init (GtkSocket *socket);
-static void gtk_socket_realize (GtkWidget *widget);
-static void gtk_socket_unrealize (GtkWidget *widget);
-static void gtk_socket_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void gtk_socket_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
-static void gtk_socket_hierarchy_changed (GtkWidget *widget);
-static void gtk_socket_grab_notify (GtkWidget *widget,
- gboolean was_grabbed);
-static gboolean gtk_socket_key_press_event (GtkWidget *widget,
- GdkEventKey *event);
-static gboolean gtk_socket_focus_in_event (GtkWidget *widget,
- GdkEventFocus *event);
-static void gtk_socket_claim_focus (GtkSocket *socket);
-static gboolean gtk_socket_focus_out_event (GtkWidget *widget,
- GdkEventFocus *event);
-static void gtk_socket_send_configure_event (GtkSocket *socket);
-static gboolean gtk_socket_focus (GtkContainer *container,
- GtkDirectionType direction);
-static GdkFilterReturn gtk_socket_filter_func (GdkXEvent *gdk_xevent,
- GdkEvent *event,
- gpointer data);
-
-static void send_xembed_message (GtkSocket *socket,
- glong message,
- glong detail,
- glong data1,
- glong data2,
- guint32 time);
+static void gtk_socket_finalize (GObject *object);
+static void gtk_socket_notify (GObject *object,
+ GParamSpec *pspec);
+static void gtk_socket_realize (GtkWidget *widget);
+static void gtk_socket_unrealize (GtkWidget *widget);
+static void gtk_socket_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+static void gtk_socket_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
+static void gtk_socket_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
+static void gtk_socket_hierarchy_changed (GtkWidget *widget,
+ GtkWidget *old_toplevel);
+static void gtk_socket_grab_notify (GtkWidget *widget,
+ gboolean was_grabbed);
+static gboolean gtk_socket_key_event (GtkWidget *widget,
+ GdkEventKey *event);
+static gboolean gtk_socket_focus (GtkWidget *widget,
+ GtkDirectionType direction);
+static void gtk_socket_remove (GtkContainer *container,
+ GtkWidget *widget);
+static void gtk_socket_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data);
+static void gtk_socket_add_window (GtkSocket *socket,
+ Window xid,
+ gboolean need_reparent);
+static GdkFilterReturn gtk_socket_filter_func (GdkXEvent *gdk_xevent,
+ GdkEvent *event,
+ gpointer data);
+
+static gboolean xembed_get_info (GdkWindow *gdk_window,
+ unsigned long *version,
+ unsigned long *flags);
/* From Tk */
#define EMBEDDED_APP_WANTS_FOCUS NotifyNormal+20
+
/* Local data */
-static GtkWidgetClass *parent_class = NULL;
+typedef struct
+{
+ guint accel_key;
+ GdkModifierType accel_mods;
+} GrabbedKey;
+
+enum {
+ PLUG_ADDED,
+ PLUG_REMOVED,
+ LAST_SIGNAL
+};
+
+static guint socket_signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (GtkSocket, gtk_socket, GTK_TYPE_CONTAINER)
-GtkType
-gtk_socket_get_type (void)
+static void
+gtk_socket_finalize (GObject *object)
{
- static GtkType socket_type = 0;
+ GtkSocket *socket = GTK_SOCKET (object);
+ GtkSocketPrivate *priv = socket->priv;
- if (!socket_type)
- {
- static const GTypeInfo socket_info =
- {
- sizeof (GtkSocketClass),
- NULL, /* base_init */
- NULL, /* base_finalize */
- (GClassInitFunc) gtk_socket_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (GtkSocket),
- 16, /* n_preallocs */
- (GInstanceInitFunc) gtk_socket_init,
- };
-
- socket_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkSocket", &socket_info, 0);
- }
+ g_object_unref (priv->accel_group);
- return socket_type;
+ G_OBJECT_CLASS (gtk_socket_parent_class)->finalize (object);
}
static void
{
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
+ GObjectClass *gobject_class;
+ gobject_class = (GObjectClass *) class;
widget_class = (GtkWidgetClass*) class;
container_class = (GtkContainerClass*) class;
- parent_class = gtk_type_class (GTK_TYPE_CONTAINER);
+ gobject_class->finalize = gtk_socket_finalize;
+ gobject_class->notify = gtk_socket_notify;
widget_class->realize = gtk_socket_realize;
widget_class->unrealize = gtk_socket_unrealize;
- widget_class->size_request = gtk_socket_size_request;
+ widget_class->get_preferred_width = gtk_socket_get_preferred_width;
+ widget_class->get_preferred_height = gtk_socket_get_preferred_height;
widget_class->size_allocate = gtk_socket_size_allocate;
widget_class->hierarchy_changed = gtk_socket_hierarchy_changed;
-#if 0
widget_class->grab_notify = gtk_socket_grab_notify;
-#endif
- widget_class->key_press_event = gtk_socket_key_press_event;
- widget_class->focus_in_event = gtk_socket_focus_in_event;
- widget_class->focus_out_event = gtk_socket_focus_out_event;
+ widget_class->key_press_event = gtk_socket_key_event;
+ widget_class->key_release_event = gtk_socket_key_event;
+ widget_class->focus = gtk_socket_focus;
+
+ /* We don't want to show_all the in-process plug, if any.
+ */
+ widget_class->show_all = gtk_widget_show;
+
+ container_class->remove = gtk_socket_remove;
+ container_class->forall = gtk_socket_forall;
- container_class->focus = gtk_socket_focus;
+ /**
+ * GtkSocket::plug-added:
+ * @socket_: the object which received the signal
+ *
+ * This signal is emitted when a client is successfully
+ * added to the socket.
+ */
+ socket_signals[PLUG_ADDED] =
+ g_signal_new (I_("plug-added"),
+ G_OBJECT_CLASS_TYPE (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkSocketClass, plug_added),
+ NULL, NULL,
+ _gtk_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+
+ /**
+ * GtkSocket::plug-removed:
+ * @socket_: the object which received the signal
+ *
+ * This signal is emitted when a client is removed from the socket.
+ * The default action is to destroy the #GtkSocket widget, so if you
+ * want to reuse it you must add a signal handler that returns %TRUE.
+ *
+ * Return value: %TRUE to stop other handlers from being invoked.
+ */
+ socket_signals[PLUG_REMOVED] =
+ g_signal_new (I_("plug-removed"),
+ G_OBJECT_CLASS_TYPE (class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkSocketClass, plug_removed),
+ _gtk_boolean_handled_accumulator, NULL,
+ _gtk_marshal_BOOLEAN__VOID,
+ G_TYPE_BOOLEAN, 0);
+
+ g_type_class_add_private (gobject_class, sizeof (GtkSocketPrivate));
}
static void
gtk_socket_init (GtkSocket *socket)
{
- socket->request_width = 0;
- socket->request_height = 0;
- socket->current_width = 0;
- socket->current_height = 0;
-
- socket->plug_window = NULL;
- socket->same_app = FALSE;
- socket->focus_in = FALSE;
- socket->have_size = FALSE;
- socket->need_map = FALSE;
+ GtkSocketPrivate *priv;
+
+ priv = G_TYPE_INSTANCE_GET_PRIVATE (socket,
+ GTK_TYPE_SOCKET,
+ GtkSocketPrivate);
+ socket->priv = priv;
+ priv->request_width = 0;
+ priv->request_height = 0;
+ priv->current_width = 0;
+ priv->current_height = 0;
+
+ priv->plug_window = NULL;
+ priv->plug_widget = NULL;
+ priv->focus_in = FALSE;
+ priv->have_size = FALSE;
+ priv->need_map = FALSE;
+ priv->active = FALSE;
+
+ priv->accel_group = gtk_accel_group_new ();
+ g_object_set_data (G_OBJECT (priv->accel_group), I_("gtk-socket"), socket);
}
+/**
+ * gtk_socket_new:
+ *
+ * Create a new empty #GtkSocket.
+ *
+ * Return value: the new #GtkSocket.
+ **/
GtkWidget*
gtk_socket_new (void)
{
return GTK_WIDGET (socket);
}
+/**
+ * gtk_socket_add_id:
+ * @socket_: a #GtkSocket
+ * @window: the Window of a client participating in the XEMBED protocol.
+ *
+ * Adds an XEMBED client, such as a #GtkPlug, to the #GtkSocket. The
+ * client may be in the same process or in a different process.
+ *
+ * To embed a #GtkPlug in a #GtkSocket, you can either create the
+ * #GtkPlug with <literal>gtk_plug_new (0)</literal>, call
+ * gtk_plug_get_id() to get the window ID of the plug, and then pass that to the
+ * gtk_socket_add_id(), or you can call gtk_socket_get_id() to get the
+ * window ID for the socket, and call gtk_plug_new() passing in that
+ * ID.
+ *
+ * The #GtkSocket must have already be added into a toplevel window
+ * before you can make this call.
+ **/
void
-gtk_socket_steal (GtkSocket *socket, GdkNativeWindow id)
+gtk_socket_add_id (GtkSocket *socket,
+ Window window)
{
- GtkWidget *widget;
- gpointer user_data = NULL;
-
- widget = GTK_WIDGET (socket);
-
- socket->plug_window = gdk_window_lookup (id);
+ g_return_if_fail (GTK_IS_SOCKET (socket));
+ g_return_if_fail (_gtk_widget_get_anchored (GTK_WIDGET (socket)));
- gdk_error_trap_push ();
-
- if (socket->plug_window)
- gdk_window_get_user_data (socket->plug_window,
- &user_data);
-
- if (user_data)
- {
- /*
- GtkWidget *child_widget;
+ if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
+ gtk_widget_realize (GTK_WIDGET (socket));
- child_widget = GTK_WIDGET (socket->plug_window->user_data);
- */
+ gtk_socket_add_window (socket, window, TRUE);
+}
- g_warning("Stealing from same app not yet implemented");
-
- socket->same_app = TRUE;
- }
- else
- {
- socket->plug_window = gdk_window_foreign_new (id);
- if (!socket->plug_window) /* was deleted before we could get it */
- {
- gdk_error_trap_pop ();
- return;
- }
-
- socket->same_app = FALSE;
- socket->have_size = FALSE;
+/**
+ * gtk_socket_get_id:
+ * @socket_: a #GtkSocket.
+ *
+ * Gets the window ID of a #GtkSocket widget, which can then
+ * be used to create a client embedded inside the socket, for
+ * instance with gtk_plug_new().
+ *
+ * The #GtkSocket must have already be added into a toplevel window
+ * before you can make this call.
+ *
+ * Return value: the window ID for the socket
+ **/
+Window
+gtk_socket_get_id (GtkSocket *socket)
+{
+ g_return_val_if_fail (GTK_IS_SOCKET (socket), 0);
+ g_return_val_if_fail (_gtk_widget_get_anchored (GTK_WIDGET (socket)), 0);
- XSelectInput (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW(socket->plug_window),
- StructureNotifyMask | PropertyChangeMask);
+ if (!gtk_widget_get_realized (GTK_WIDGET (socket)))
+ gtk_widget_realize (GTK_WIDGET (socket));
- gtk_widget_queue_resize (widget);
- }
+ return GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (socket)));
+}
- gdk_window_hide (socket->plug_window);
- gdk_window_reparent (socket->plug_window, widget->window, 0, 0);
+/**
+ * gtk_socket_get_plug_window:
+ * @socket_: a #GtkSocket.
+ *
+ * Retrieves the window of the plug. Use this to check if the plug has
+ * been created inside of the socket.
+ *
+ * Return value: (transfer none): the window of the plug if available, or %NULL
+ *
+ * Since: 2.14
+ **/
+GdkWindow*
+gtk_socket_get_plug_window (GtkSocket *socket)
+{
+ g_return_val_if_fail (GTK_IS_SOCKET (socket), NULL);
- gdk_flush ();
- gdk_error_trap_pop ();
-
- socket->need_map = TRUE;
+ return socket->priv->plug_window;
}
static void
gtk_socket_realize (GtkWidget *widget)
{
- GtkSocket *socket;
+ GtkAllocation allocation;
+ GdkWindow *window;
GdkWindowAttr attributes;
- gint attributes_mask;
XWindowAttributes xattrs;
+ gint attributes_mask;
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_SOCKET (widget));
+ gtk_widget_set_realized (widget, TRUE);
- socket = GTK_SOCKET (widget);
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ gtk_widget_get_allocation (widget, &allocation);
attributes.window_type = GDK_WINDOW_CHILD;
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
- attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = GDK_FOCUS_CHANGE_MASK;
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+ attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL;
- widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
- &attributes, attributes_mask);
- gdk_window_set_user_data (widget->window, socket);
+ window = gdk_window_new (gtk_widget_get_parent_window (widget),
+ &attributes, attributes_mask);
+ gtk_widget_set_window (widget, window);
+ gtk_widget_register_window (widget, window);
- widget->style = gtk_style_attach (widget->style, widget->window);
- gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
+ gtk_style_context_set_background (gtk_widget_get_style_context (widget),
+ window);
- XGetWindowAttributes (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (widget->window),
+ XGetWindowAttributes (GDK_WINDOW_XDISPLAY (window),
+ GDK_WINDOW_XID (window),
&xattrs);
- XSelectInput (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW(widget->window),
- xattrs.your_event_mask |
+ /* Sooooo, it turns out that mozilla, as per the gtk2xt code selects
+ for input on the socket with a mask of 0x0fffff (for god knows why)
+ which includes ButtonPressMask causing a BadAccess if someone else
+ also selects for this. As per the client-side windows merge we always
+ normally selects for button press so we can emulate it on client
+ side children that selects for button press. However, we don't need
+ this for GtkSocket, so we unselect it here, fixing the crashes in
+ firefox. */
+ XSelectInput (GDK_WINDOW_XDISPLAY (window),
+ GDK_WINDOW_XID (window),
+ (xattrs.your_event_mask & ~ButtonPressMask) |
SubstructureNotifyMask | SubstructureRedirectMask);
- gdk_window_add_filter (widget->window, gtk_socket_filter_func, widget);
-
- GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+ gdk_window_add_filter (window,
+ gtk_socket_filter_func,
+ widget);
/* We sync here so that we make sure that if the XID for
* our window is passed to another application, SubstructureRedirectMask
* will be set by the time the other app creates its window.
*/
- gdk_flush();
+ gdk_display_sync (gtk_widget_get_display (widget));
+}
+
+/**
+ * gtk_socket_end_embedding:
+ * @socket: a #GtkSocket
+ *
+ * Called to end the embedding of a plug in the socket.
+ */
+static void
+gtk_socket_end_embedding (GtkSocket *socket)
+{
+ GtkSocketPrivate *private = socket->priv;
+
+ g_object_unref (private->plug_window);
+ private->plug_window = NULL;
+ private->current_width = 0;
+ private->current_height = 0;
+ private->resize_count = 0;
+
+ gtk_accel_group_disconnect (private->accel_group, NULL);
}
static void
gtk_socket_unrealize (GtkWidget *widget)
{
- GtkSocket *socket;
-
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_SOCKET (widget));
+ GtkSocket *socket = GTK_SOCKET (widget);
+ GtkSocketPrivate *private = socket->priv;
- socket = GTK_SOCKET (widget);
+ gtk_widget_set_realized (widget, FALSE);
- if (socket->plug_window)
+ if (private->plug_widget)
{
- GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- if (toplevel && GTK_IS_WINDOW (toplevel))
- gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel),
- GDK_WINDOW_XWINDOW (socket->plug_window));
-
- socket->plug_window = NULL;
+ _gtk_plug_remove_from_socket (GTK_PLUG (private->plug_widget), socket);
}
-
-#if 0
- if (socket->grabbed_keys)
+ else if (private->plug_window)
{
- g_hash_table_foreach (socket->grabbed_keys, (GHFunc)g_free, NULL);
- g_hash_table_destroy (socket->grabbed_keys);
- socket->grabbed_keys = NULL;
+ gtk_socket_end_embedding (socket);
}
-#endif
-
- if (GTK_WIDGET_CLASS (parent_class)->unrealize)
- (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
+
+ GTK_WIDGET_CLASS (gtk_socket_parent_class)->unrealize (widget);
}
-
-static void
-gtk_socket_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
+
+static void
+gtk_socket_size_request (GtkSocket *socket)
{
- GtkSocket *socket;
+ GtkSocketPrivate *private = socket->priv;
+ XSizeHints hints;
+ long supplied;
+
+ gdk_error_trap_push ();
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_SOCKET (widget));
- g_return_if_fail (requisition != NULL);
+ private->request_width = 1;
+ private->request_height = 1;
+
+ if (XGetWMNormalHints (GDK_WINDOW_XDISPLAY (private->plug_window),
+ GDK_WINDOW_XID (private->plug_window),
+ &hints, &supplied))
+ {
+ if (hints.flags & PMinSize)
+ {
+ private->request_width = MAX (hints.min_width, 1);
+ private->request_height = MAX (hints.min_height, 1);
+ }
+ else if (hints.flags & PBaseSize)
+ {
+ private->request_width = MAX (hints.base_width, 1);
+ private->request_height = MAX (hints.base_height, 1);
+ }
+ }
+ private->have_size = TRUE;
- socket = GTK_SOCKET (widget);
+ gdk_error_trap_pop_ignored ();
+}
- if (!socket->have_size && socket->plug_window)
+static void
+gtk_socket_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkSocket *socket = GTK_SOCKET (widget);
+ GtkSocketPrivate *private = socket->priv;
+
+ if (private->plug_widget)
{
- XSizeHints hints;
- long supplied;
+ gtk_widget_get_preferred_width (private->plug_widget, minimum, natural);
+ }
+ else
+ {
+ if (private->is_mapped && !private->have_size && private->plug_window)
+ gtk_socket_size_request (socket);
- gdk_error_trap_push ();
-
- if (XGetWMNormalHints (GDK_DISPLAY(),
- GDK_WINDOW_XWINDOW (socket->plug_window),
- &hints, &supplied))
- {
- /* This is obsolete, according the X docs, but many programs
- * still use it */
- if (hints.flags & (PSize | USSize))
- {
- socket->request_width = hints.width;
- socket->request_height = hints.height;
- }
- else if (hints.flags & PMinSize)
- {
- socket->request_width = hints.min_width;
- socket->request_height = hints.min_height;
- }
- else if (hints.flags & PBaseSize)
- {
- socket->request_width = hints.base_width;
- socket->request_height = hints.base_height;
- }
- }
- socket->have_size = TRUE; /* don't check again? */
+ if (private->is_mapped && private->have_size)
+ *minimum = *natural = MAX (private->request_width, 1);
+ else
+ *minimum = *natural = 1;
+ }
+}
- gdk_error_trap_pop ();
+static void
+gtk_socket_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural)
+{
+ GtkSocket *socket = GTK_SOCKET (widget);
+ GtkSocketPrivate *private = socket->priv;
+
+ if (private->plug_widget)
+ {
+ gtk_widget_get_preferred_height (private->plug_widget, minimum, natural);
}
+ else
+ {
+ if (private->is_mapped && !private->have_size && private->plug_window)
+ gtk_socket_size_request (socket);
- requisition->width = MAX (socket->request_width, 1);
- requisition->height = MAX (socket->request_height, 1);
+ if (private->is_mapped && private->have_size)
+ *minimum = *natural = MAX (private->request_height, 1);
+ else
+ *minimum = *natural = 1;
+ }
}
static void
-gtk_socket_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
+gtk_socket_send_configure_event (GtkSocket *socket)
{
- GtkSocket *socket;
+ GtkAllocation allocation;
+ XConfigureEvent xconfigure;
+ gint x, y;
+
+ g_return_if_fail (socket->priv->plug_window != NULL);
+
+ memset (&xconfigure, 0, sizeof (xconfigure));
+ xconfigure.type = ConfigureNotify;
- g_return_if_fail (widget != NULL);
- g_return_if_fail (GTK_IS_SOCKET (widget));
- g_return_if_fail (allocation != NULL);
+ xconfigure.event = GDK_WINDOW_XID (socket->priv->plug_window);
+ xconfigure.window = GDK_WINDOW_XID (socket->priv->plug_window);
+
+ /* The ICCCM says that synthetic events should have root relative
+ * coordinates. We still aren't really ICCCM compliant, since
+ * we don't send events when the real toplevel is moved.
+ */
+ gdk_error_trap_push ();
+ gdk_window_get_origin (socket->priv->plug_window, &x, &y);
+ gdk_error_trap_pop_ignored ();
+
+ gtk_widget_get_allocation (GTK_WIDGET(socket), &allocation);
+ xconfigure.x = x;
+ xconfigure.y = y;
+ xconfigure.width = allocation.width;
+ xconfigure.height = allocation.height;
+
+ xconfigure.border_width = 0;
+ xconfigure.above = None;
+ xconfigure.override_redirect = False;
+
+ gdk_error_trap_push ();
+ XSendEvent (GDK_WINDOW_XDISPLAY (socket->priv->plug_window),
+ GDK_WINDOW_XID (socket->priv->plug_window),
+ False, NoEventMask, (XEvent *)&xconfigure);
+ gdk_error_trap_pop_ignored ();
+}
- socket = GTK_SOCKET (widget);
+static void
+gtk_socket_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GtkSocket *socket = GTK_SOCKET (widget);
+ GtkSocketPrivate *private = socket->priv;
- widget->allocation = *allocation;
- if (GTK_WIDGET_REALIZED (widget))
+ gtk_widget_set_allocation (widget, allocation);
+ if (gtk_widget_get_realized (widget))
{
- gdk_window_move_resize (widget->window,
+ gdk_window_move_resize (gtk_widget_get_window (widget),
allocation->x, allocation->y,
allocation->width, allocation->height);
- if (socket->plug_window)
+ if (private->plug_widget)
+ {
+ GtkAllocation child_allocation;
+
+ child_allocation.x = 0;
+ child_allocation.y = 0;
+ child_allocation.width = allocation->width;
+ child_allocation.height = allocation->height;
+
+ gtk_widget_size_allocate (private->plug_widget, &child_allocation);
+ }
+ else if (private->plug_window)
{
gdk_error_trap_push ();
-
- if (!socket->need_map &&
- (allocation->width == socket->current_width) &&
- (allocation->height == socket->current_height))
- {
- gtk_socket_send_configure_event (socket);
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - allocated no change: %d %d",
- allocation->width, allocation->height));
- }
- else
+
+ if (allocation->width != private->current_width ||
+ allocation->height != private->current_height)
{
- gdk_window_move_resize (socket->plug_window,
+ gdk_window_move_resize (private->plug_window,
0, 0,
allocation->width, allocation->height);
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - allocated: %d %d",
- allocation->width, allocation->height));
- socket->current_width = allocation->width;
- socket->current_height = allocation->height;
+ if (private->resize_count)
+ private->resize_count--;
+
+ GTK_NOTE (PLUGSOCKET,
+ g_message ("GtkSocket - allocated: %d %d",
+ allocation->width, allocation->height));
+ private->current_width = allocation->width;
+ private->current_height = allocation->height;
}
- if (socket->need_map)
+ if (private->need_map)
{
- gdk_window_show (socket->plug_window);
- socket->need_map = FALSE;
+ gdk_window_show (private->plug_window);
+ private->need_map = FALSE;
}
- gdk_flush ();
- gdk_error_trap_pop ();
+ while (private->resize_count)
+ {
+ gtk_socket_send_configure_event (socket);
+ private->resize_count--;
+ GTK_NOTE (PLUGSOCKET,
+ g_message ("GtkSocket - sending synthetic configure: %d %d",
+ allocation->width, allocation->height));
+ }
+
+ gdk_error_trap_pop_ignored ();
}
}
}
-#if 0
-
-typedef struct
+static void
+gtk_socket_send_key_event (GtkSocket *socket,
+ GdkEvent *gdk_event,
+ gboolean mask_key_presses)
{
- guint accelerator_key;
- GdkModifierType accelerator_mods;
-} GrabbedKey;
+ XKeyEvent xkey;
+ GdkScreen *screen = gdk_window_get_screen (socket->priv->plug_window);
+
+ memset (&xkey, 0, sizeof (xkey));
+ xkey.type = (gdk_event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
+ xkey.window = GDK_WINDOW_XID (socket->priv->plug_window);
+ xkey.root = GDK_WINDOW_XID (gdk_screen_get_root_window (screen));
+ xkey.subwindow = None;
+ xkey.time = gdk_event->key.time;
+ xkey.x = 0;
+ xkey.y = 0;
+ xkey.x_root = 0;
+ xkey.y_root = 0;
+ xkey.state = gdk_event->key.state;
+ xkey.keycode = gdk_event->key.hardware_keycode;
+ xkey.same_screen = True;/* FIXME ? */
+
+ gdk_error_trap_push ();
+ XSendEvent (GDK_WINDOW_XDISPLAY (socket->priv->plug_window),
+ GDK_WINDOW_XID (socket->priv->plug_window),
+ False,
+ (mask_key_presses ? KeyPressMask : NoEventMask),
+ (XEvent *)&xkey);
+ gdk_error_trap_pop_ignored ();
+}
-static guint
-grabbed_key_hash (gconstpointer a)
+static gboolean
+activate_key (GtkAccelGroup *accel_group,
+ GObject *acceleratable,
+ guint accel_key,
+ GdkModifierType accel_mods,
+ GrabbedKey *grabbed_key)
{
- const GrabbedKey *key = a;
- guint h;
+ GdkEvent *gdk_event = gtk_get_current_event ();
- h = key->accelerator_key << 16;
- h ^= key->accelerator_key >> 16;
- h ^= key->accelerator_mods;
+ GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
+ gboolean retval = FALSE;
- return h;
+ if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->priv->plug_window)
+ {
+ gtk_socket_send_key_event (socket, gdk_event, FALSE);
+ retval = TRUE;
+ }
+
+ if (gdk_event)
+ gdk_event_free (gdk_event);
+
+ return retval;
}
static gboolean
-grabbed_key_equal (gconstpointer a, gconstpointer b)
+find_accel_key (GtkAccelKey *key,
+ GClosure *closure,
+ gpointer data)
{
- const GrabbedKey *keya = a;
- const GrabbedKey *keyb = b;
-
- return (keya->accelerator_key == keyb->accelerator_key &&
- keya->accelerator_mods == keyb->accelerator_mods);
+ GrabbedKey *grabbed_key = data;
+
+ return (key->accel_key == grabbed_key->accel_key &&
+ key->accel_mods == grabbed_key->accel_mods);
}
+/**
+ * gtk_socket_add_grabbed_key:
+ * @socket: a #GtkSocket
+ * @keyval: a key
+ * @modifiers: modifiers for the key
+ *
+ * Called from the GtkSocket platform-specific backend when the
+ * corresponding plug has told the socket to grab a key.
+ */
static void
-add_grabbed_key (GtkSocket *socket,
- guint hardware_keycode,
- GdkModifierType mods)
+gtk_socket_add_grabbed_key (GtkSocket *socket,
+ guint keyval,
+ GdkModifierType modifiers)
{
- GrabbedKey key;
- GrabbedKey *new_key;
- GrabbedKey *found_key;
+ GClosure *closure;
+ GrabbedKey *grabbed_key;
- if (socket->grabbed_keys)
- {
- key.accelerator_key = hardware_keycode;
- key.accelerator_mods = mods;
-
- found_key = g_hash_table_lookup (socket->grabbed_keys, &key);
+ grabbed_key = g_new (GrabbedKey, 1);
+
+ grabbed_key->accel_key = keyval;
+ grabbed_key->accel_mods = modifiers;
- if (found_key)
- {
- g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
- hardware_keycode, mods);
- return;
- }
+ if (gtk_accel_group_find (socket->priv->accel_group,
+ find_accel_key,
+ &grabbed_key))
+ {
+ g_warning ("GtkSocket: request to add already present grabbed key %u,%#x\n",
+ keyval, modifiers);
+ g_free (grabbed_key);
+ return;
}
-
- if (!socket->grabbed_keys)
- socket->grabbed_keys = g_hash_table_new (grabbed_key_hash, grabbed_key_equal);
- new_key = g_new (GrabbedKey, 1);
-
- new_key->accelerator_key = hardware_keycode;
- new_key->accelerator_mods = mods;
+ closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
+
+ gtk_accel_group_connect (socket->priv->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
+ closure);
+}
- g_hash_table_insert (socket->grabbed_keys, new_key, new_key);
+/**
+ * gtk_socket_remove_grabbed_key:
+ * @socket: a #GtkSocket
+ * @keyval: a key
+ * @modifiers: modifiers for the key
+ *
+ * Called from the GtkSocket backend when the corresponding plug has
+ * told the socket to remove a key grab.
+ */
+static void
+gtk_socket_remove_grabbed_key (GtkSocket *socket,
+ guint keyval,
+ GdkModifierType modifiers)
+{
+ if (!gtk_accel_group_disconnect_key (socket->priv->accel_group, keyval, modifiers))
+ g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
+ keyval, modifiers);
}
static void
-remove_grabbed_key (GtkSocket *socket,
- guint hardware_keycode,
- GdkModifierType mods)
+socket_update_focus_in (GtkSocket *socket)
{
- GrabbedKey key;
- GrabbedKey *found_key = NULL;
+ GtkSocketPrivate *private = socket->priv;
+ gboolean focus_in = FALSE;
- if (socket->grabbed_keys)
+ if (private->plug_window)
{
- key.accelerator_key = hardware_keycode;
- key.accelerator_mods = mods;
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- found_key = g_hash_table_lookup (socket->grabbed_keys, &key);
+ if (gtk_widget_is_toplevel (toplevel) &&
+ gtk_window_has_toplevel_focus (GTK_WINDOW (toplevel)) &&
+ gtk_widget_is_focus (GTK_WIDGET (socket)))
+ focus_in = TRUE;
}
- if (found_key)
+ if (focus_in != private->focus_in)
{
- g_hash_table_remove (socket->grabbed_keys, &key);
- g_free (found_key);
+ private->focus_in = focus_in;
+
+ if (focus_in)
+ _gtk_xembed_send_focus_message (private->plug_window,
+ XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT);
+ else
+ _gtk_xembed_send_message (private->plug_window,
+ XEMBED_FOCUS_OUT, 0, 0, 0);
}
- else
- g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
- hardware_keycode, mods);
}
-static gboolean
-toplevel_key_press_handler (GtkWidget *toplevel,
- GdkEventKey *event,
- GtkSocket *socket)
+static void
+socket_update_active (GtkSocket *socket)
{
- GrabbedKey search_key;
-
- search_key.accelerator_key = event->hardware_keycode;
- search_key.accelerator_mods = event->state;
+ GtkSocketPrivate *private = socket->priv;
+ gboolean active = FALSE;
- if (socket->grabbed_keys &&
- g_hash_table_lookup (socket->grabbed_keys, &search_key))
+ if (private->plug_window)
{
- gtk_socket_key_press_event (GTK_WIDGET (socket), event);
- gtk_signal_emit_stop_by_name (GTK_OBJECT (toplevel), "key_press_event");
+ GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- return TRUE;
+ if (gtk_widget_is_toplevel (toplevel) &&
+ gtk_window_is_active (GTK_WINDOW (toplevel)))
+ active = TRUE;
}
- else
- return FALSE;
-}
-
-#endif
-static void
-toplevel_focus_in_handler (GtkWidget *toplevel,
- GdkEventFocus *event,
- GtkSocket *socket)
-{
- /* It appears spurious focus in events can occur when
- * the window is hidden. So we'll just check to see if
- * the window is visible before actually handling the
- * event. (Comment from gtkwindow.c)
- */
- if (GTK_WIDGET_VISIBLE (toplevel))
- send_xembed_message (socket, XEMBED_WINDOW_ACTIVATE, 0, 0, 0,
- gtk_get_current_event_time ()); /* Will be GDK_CURRENT_TIME */
-}
+ if (active != private->active)
+ {
+ private->active = active;
-static void
-toplevel_focus_out_handler (GtkWidget *toplevel,
- GdkEventFocus *event,
- GtkSocket *socket)
-{
- send_xembed_message (socket, XEMBED_WINDOW_DEACTIVATE, 0, 0, 0,
- gtk_get_current_event_time ()); /* Will be GDK_CURRENT_TIME */
+ _gtk_xembed_send_message (private->plug_window,
+ active ? XEMBED_WINDOW_ACTIVATE : XEMBED_WINDOW_DEACTIVATE,
+ 0, 0, 0);
+ }
}
static void
-gtk_socket_hierarchy_changed (GtkWidget *widget)
+gtk_socket_hierarchy_changed (GtkWidget *widget,
+ GtkWidget *old_toplevel)
{
GtkSocket *socket = GTK_SOCKET (widget);
+ GtkSocketPrivate *private = socket->priv;
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
if (toplevel && !GTK_IS_WINDOW (toplevel))
toplevel = NULL;
- if (toplevel != socket->toplevel)
+ if (toplevel != private->toplevel)
{
- if (socket->toplevel)
+ if (private->toplevel)
{
-#if 0
- gtk_signal_disconnect_by_func (GTK_OBJECT (socket->toplevel), GTK_SIGNAL_FUNC (toplevel_key_press_handler), socket);
-#endif
- gtk_signal_disconnect_by_func (GTK_OBJECT (socket->toplevel), GTK_SIGNAL_FUNC (toplevel_focus_in_handler), socket);
- gtk_signal_disconnect_by_func (GTK_OBJECT (socket->toplevel), GTK_SIGNAL_FUNC (toplevel_focus_out_handler), socket);
+ gtk_window_remove_accel_group (GTK_WINDOW (private->toplevel), private->accel_group);
+ g_signal_handlers_disconnect_by_func (private->toplevel,
+ socket_update_focus_in,
+ socket);
+ g_signal_handlers_disconnect_by_func (private->toplevel,
+ socket_update_active,
+ socket);
}
- socket->toplevel = toplevel;
+ private->toplevel = toplevel;
if (toplevel)
{
-#if 0
- gtk_signal_connect (GTK_OBJECT (socket->toplevel), "key_press_event",
- GTK_SIGNAL_FUNC (toplevel_key_press_handler), socket);
-#endif
- gtk_signal_connect (GTK_OBJECT (socket->toplevel), "focus_in_event",
- GTK_SIGNAL_FUNC (toplevel_focus_in_handler), socket);
- gtk_signal_connect (GTK_OBJECT (socket->toplevel), "focus_out_event",
- GTK_SIGNAL_FUNC (toplevel_focus_out_handler), socket);
+ gtk_window_add_accel_group (GTK_WINDOW (private->toplevel), private->accel_group);
+ g_signal_connect_swapped (private->toplevel, "notify::has-toplevel-focus",
+ G_CALLBACK (socket_update_focus_in), socket);
+ g_signal_connect_swapped (private->toplevel, "notify::is-active",
+ G_CALLBACK (socket_update_active), socket);
}
+
+ socket_update_focus_in (socket);
+ socket_update_active (socket);
}
}
gtk_socket_grab_notify (GtkWidget *widget,
gboolean was_grabbed)
{
- send_xembed_message (GTK_SOCKET (widget),
- was_grabbed ? XEMBED_MODALITY_OFF : XEMBED_MODALITY_ON,
- 0, 0, 0, gtk_get_current_event_time ());
+ GtkSocket *socket = GTK_SOCKET (widget);
+
+ if (!socket->priv->same_app)
+ _gtk_xembed_send_message (socket->priv->plug_window,
+ was_grabbed ? XEMBED_MODALITY_OFF : XEMBED_MODALITY_ON,
+ 0, 0, 0);
}
static gboolean
-gtk_socket_key_press_event (GtkWidget *widget,
- GdkEventKey *event)
+gtk_socket_key_event (GtkWidget *widget,
+ GdkEventKey *event)
{
GtkSocket *socket = GTK_SOCKET (widget);
+ GtkSocketPrivate *private = socket->priv;
- if (socket->plug_window)
+ if (gtk_widget_has_focus (widget) && private->plug_window && !private->plug_widget)
{
- XEvent xevent;
-
- xevent.xkey.type = KeyPress;
- xevent.xkey.display = GDK_WINDOW_XDISPLAY (event->window);
- xevent.xkey.window = GDK_WINDOW_XWINDOW (socket->plug_window);
- xevent.xkey.root = GDK_ROOT_WINDOW ();
- xevent.xkey.time = event->time;
- /* FIXME, the following might cause problems for non-GTK apps */
- xevent.xkey.x = 0;
- xevent.xkey.y = 0;
- xevent.xkey.x_root = 0;
- xevent.xkey.y_root = 0;
- xevent.xkey.state = event->state;
- xevent.xkey.keycode = event->hardware_keycode;
- xevent.xkey.same_screen = TRUE; /* FIXME ? */
-
- gdk_error_trap_push ();
- XSendEvent (gdk_display,
- GDK_WINDOW_XWINDOW (socket->plug_window),
- False, NoEventMask, &xevent);
- gdk_flush ();
- gdk_error_trap_pop ();
-
+ gtk_socket_send_key_event (socket, (GdkEvent *) event, FALSE);
+
return TRUE;
}
else
return FALSE;
}
-static gboolean
-gtk_socket_focus_in_event (GtkWidget *widget, GdkEventFocus *event)
+static void
+gtk_socket_notify (GObject *object,
+ GParamSpec *pspec)
{
- GtkSocket *socket = GTK_SOCKET (widget);
+ if (strcmp (pspec->name, "is-focus") == 0)
+ socket_update_focus_in (GTK_SOCKET (object));
- if (!GTK_WIDGET_HAS_FOCUS (widget))
- {
- GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);
-
- if (socket->plug_window)
- {
- send_xembed_message (socket, XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT, 0, 0,
- gtk_get_current_event_time ());
- }
- }
+ if (G_OBJECT_CLASS (gtk_socket_parent_class)->notify)
+ G_OBJECT_CLASS (gtk_socket_parent_class)->notify (object, pspec);
+}
+
+/**
+ * gtk_socket_claim_focus:
+ * @socket: a #GtkSocket
+ * @send_event: huh?
+ *
+ * Claims focus for the socket. XXX send_event?
+ */
+static void
+gtk_socket_claim_focus (GtkSocket *socket,
+ gboolean send_event)
+{
+ GtkWidget *widget = GTK_WIDGET (socket);
+ GtkSocketPrivate *private = socket->priv;
+
+ if (!send_event)
+ private->focus_in = TRUE; /* Otherwise, our notify handler will send FOCUS_IN */
+
+ /* Oh, the trickery... */
- return TRUE;
+ gtk_widget_set_can_focus (widget, TRUE);
+ gtk_widget_grab_focus (widget);
+ gtk_widget_set_can_focus (widget, FALSE);
}
static gboolean
-gtk_socket_focus_out_event (GtkWidget *widget, GdkEventFocus *event)
+gtk_socket_focus (GtkWidget *widget,
+ GtkDirectionType direction)
{
GtkSocket *socket = GTK_SOCKET (widget);
+ GtkSocketPrivate *private = socket->priv;
- GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);
+ if (private->plug_widget)
+ return gtk_widget_child_focus (private->plug_widget, direction);
-#if 0
- GtkWidget *toplevel;
- toplevel = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
-
- if (toplevel)
+ if (!gtk_widget_is_focus (widget))
{
- XSetInputFocus (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (toplevel->window),
- RevertToParent, CurrentTime); /* FIXME? */
+ gint detail = -1;
+
+ switch (direction)
+ {
+ case GTK_DIR_UP:
+ case GTK_DIR_LEFT:
+ case GTK_DIR_TAB_BACKWARD:
+ detail = XEMBED_FOCUS_LAST;
+ break;
+ case GTK_DIR_DOWN:
+ case GTK_DIR_RIGHT:
+ case GTK_DIR_TAB_FORWARD:
+ detail = XEMBED_FOCUS_FIRST;
+ break;
+ }
+
+ _gtk_xembed_send_focus_message (private->plug_window, XEMBED_FOCUS_IN, detail);
+ gtk_socket_claim_focus (socket, FALSE);
+
+ return TRUE;
}
+ else
+ return FALSE;
+}
-#endif
+static void
+gtk_socket_remove (GtkContainer *container,
+ GtkWidget *child)
+{
+ GtkSocket *socket = GTK_SOCKET (container);
+ GtkSocketPrivate *private = socket->priv;
- if (socket->plug_window)
- {
- send_xembed_message (socket, XEMBED_FOCUS_OUT, 0, 0, 0,
- gtk_get_current_event_time ());
- }
+ g_return_if_fail (child == private->plug_widget);
- socket->focus_in = FALSE;
-
- return TRUE;
+ _gtk_plug_remove_from_socket (GTK_PLUG (private->plug_widget), socket);
}
static void
-gtk_socket_claim_focus (GtkSocket *socket)
+gtk_socket_forall (GtkContainer *container,
+ gboolean include_internals,
+ GtkCallback callback,
+ gpointer callback_data)
{
-
- socket->focus_in = TRUE;
-
- /* Oh, the trickery... */
-
- GTK_WIDGET_SET_FLAGS (socket, GTK_CAN_FOCUS);
- gtk_widget_grab_focus (GTK_WIDGET (socket));
- GTK_WIDGET_UNSET_FLAGS (socket, GTK_CAN_FOCUS);
-
- /* FIXME: we might grab the focus even if we don't have
- * it as an app... (and see _focus_in ()) */
- if (socket->plug_window)
- {
-#if 0
- gdk_error_trap_push ();
- XSetInputFocus (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (socket->plug_window),
- RevertToParent, GDK_CURRENT_TIME);
- gdk_flush ();
- gdk_error_trap_pop ();
-#endif
- }
+ GtkSocket *socket = GTK_SOCKET (container);
+ GtkSocketPrivate *private = socket->priv;
+
+ if (private->plug_widget)
+ (* callback) (private->plug_widget, callback_data);
}
-static gboolean
-gtk_socket_focus (GtkContainer *container, GtkDirectionType direction)
+/**
+ * gtk_socket_add_window:
+ * @socket: a #GtkSocket
+ * @xid: the native identifier for a window
+ * @need_reparent: whether the socket's plug's window needs to be
+ * reparented to the socket
+ *
+ * Adds a window to a GtkSocket.
+ */
+static void
+gtk_socket_add_window (GtkSocket *socket,
+ Window xid,
+ gboolean need_reparent)
{
- GtkSocket *socket;
- gint detail = -1;
+ GtkWidget *widget = GTK_WIDGET (socket);
+ GdkDisplay *display = gtk_widget_get_display (widget);
+ gpointer user_data = NULL;
+ GtkSocketPrivate *private = socket->priv;
+ unsigned long version;
+ unsigned long flags;
- g_return_val_if_fail (GTK_IS_SOCKET (container), FALSE);
-
- socket = GTK_SOCKET (container);
+ if (GDK_IS_X11_DISPLAY (display))
+ private->plug_window = gdk_x11_window_lookup_for_display (display, xid);
+ else
+ private->plug_window = NULL;
- if (!GTK_WIDGET_HAS_FOCUS (container))
+ if (private->plug_window)
{
- switch (direction)
- {
- case GTK_DIR_UP:
- case GTK_DIR_LEFT:
- case GTK_DIR_TAB_BACKWARD:
- detail = XEMBED_FOCUS_LAST;
- break;
- case GTK_DIR_DOWN:
- case GTK_DIR_RIGHT:
- case GTK_DIR_TAB_FORWARD:
- detail = XEMBED_FOCUS_FIRST;
- break;
- }
-
- send_xembed_message (socket, XEMBED_FOCUS_IN, detail, 0, 0,
- gtk_get_current_event_time ());
-
- GTK_WIDGET_SET_FLAGS (container, GTK_HAS_FOCUS);
- gtk_widget_grab_focus (GTK_WIDGET (container));
-
- return TRUE;
+ g_object_ref (private->plug_window);
+ gdk_window_get_user_data (private->plug_window, &user_data);
}
- else
- return FALSE;
-#if 0
- if (!socket->focus_in && socket->plug_window)
+ if (user_data) /* A widget's window in this process */
{
- XEvent xevent;
+ GtkWidget *child_widget = user_data;
+
+ if (!GTK_IS_PLUG (child_widget))
+ {
+ g_warning (G_STRLOC ": Can't add non-GtkPlug to GtkSocket");
+ private->plug_window = NULL;
+ gdk_error_trap_pop_ignored ();
- gtk_socket_claim_focus (socket);
+ return;
+ }
+
+ _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
+ }
+ else /* A foreign window */
+ {
+ GdkDragProtocol protocol;
+
+ gdk_error_trap_push ();
+
+ if (!private->plug_window)
+ {
+ if (GDK_IS_X11_DISPLAY (display))
+ private->plug_window = gdk_x11_window_foreign_new_for_display (display, xid);
+ if (!private->plug_window) /* was deleted before we could get it */
+ {
+ gdk_error_trap_pop_ignored ();
+ return;
+ }
+ }
+
+ XSelectInput (GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (socket))),
+ GDK_WINDOW_XID (private->plug_window),
+ StructureNotifyMask | PropertyChangeMask);
+
+ if (gdk_error_trap_pop ())
+ {
+ g_object_unref (private->plug_window);
+ private->plug_window = NULL;
+ return;
+ }
- xevent.xkey.type = KeyPress;
- xevent.xkey.display = GDK_DISPLAY ();
- xevent.xkey.window = GDK_WINDOW_XWINDOW (socket->plug_window);
- xevent.xkey.root = GDK_ROOT_WINDOW (); /* FIXME */
- xevent.xkey.time = GDK_CURRENT_TIME; /* FIXME */
- /* FIXME, the following might cause big problems for
- * non-GTK apps */
- xevent.xkey.x = 0;
- xevent.xkey.y = 0;
- xevent.xkey.x_root = 0;
- xevent.xkey.y_root = 0;
- xevent.xkey.state = 0;
- xevent.xkey.same_screen = TRUE; /* FIXME ? */
+ /* OK, we now will reliably get destroy notification on socket->plug_window */
- switch (direction)
+ gdk_error_trap_push ();
+
+ if (need_reparent)
{
- case GTK_DIR_UP:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Up);
- break;
- case GTK_DIR_DOWN:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Down);
- break;
- case GTK_DIR_LEFT:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Left);
- break;
- case GTK_DIR_RIGHT:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Right);
- break;
- case GTK_DIR_TAB_FORWARD:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Tab);
- break;
- case GTK_DIR_TAB_BACKWARD:
- xevent.xkey.keycode = XKeysymToKeycode(GDK_DISPLAY(), GDK_Tab);
- xevent.xkey.state = ShiftMask;
- break;
+ gdk_window_hide (private->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
+ gdk_window_reparent (private->plug_window,
+ gtk_widget_get_window (widget),
+ 0, 0);
}
+ private->have_size = FALSE;
+
+ private->xembed_version = -1;
+ if (xembed_get_info (private->plug_window, &version, &flags))
+ {
+ private->xembed_version = MIN (GTK_XEMBED_PROTOCOL_VERSION, version);
+ private->is_mapped = (flags & XEMBED_MAPPED) != 0;
+ }
+ else
+ {
+ /* FIXME, we should probably actually check the state before we started */
+ private->is_mapped = TRUE;
+ }
+
+ private->need_map = private->is_mapped;
+
+ protocol = gdk_window_get_drag_protocol (private->plug_window, NULL);
+ if (protocol)
+ gtk_drag_dest_set_proxy (GTK_WIDGET (socket), private->plug_window,
+ protocol, TRUE);
+
+ gdk_error_trap_pop_ignored ();
+
+ gdk_window_add_filter (private->plug_window,
+ gtk_socket_filter_func,
+ socket);
+#ifdef HAVE_XFIXES
gdk_error_trap_push ();
- XSendEvent (gdk_display,
- GDK_WINDOW_XWINDOW (socket->plug_window),
- False, NoEventMask, &xevent);
- gdk_flush();
- gdk_error_trap_pop ();
-
- return TRUE;
- }
- else
- {
- return FALSE;
+ XFixesChangeSaveSet (GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (GTK_WIDGET (socket))),
+ GDK_WINDOW_XID (private->plug_window),
+ SetModeInsert, SaveSetRoot, SaveSetUnmap);
+ gdk_error_trap_pop_ignored ();
+#endif
+ _gtk_xembed_send_message (private->plug_window,
+ XEMBED_EMBEDDED_NOTIFY, 0,
+ GDK_WINDOW_XID (gtk_widget_get_window (GTK_WIDGET (socket))),
+ private->xembed_version);
+
+ socket_update_active (socket);
+ socket_update_focus_in (socket);
+
+ gtk_widget_queue_resize (GTK_WIDGET (socket));
}
-#endif
+
+ if (private->plug_window)
+ g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
}
+/**
+ * gtk_socket_handle_map_request:
+ * @socket: a #GtkSocket
+ *
+ * Called from the GtkSocket backend when the plug has been mapped.
+ */
static void
-gtk_socket_send_configure_event (GtkSocket *socket)
+gtk_socket_handle_map_request (GtkSocket *socket)
{
- XEvent event;
-
- g_return_if_fail (socket->plug_window != NULL);
-
- event.xconfigure.type = ConfigureNotify;
- event.xconfigure.display = gdk_display;
-
- event.xconfigure.event = GDK_WINDOW_XWINDOW (socket->plug_window);
- event.xconfigure.window = GDK_WINDOW_XWINDOW (socket->plug_window);
-
- event.xconfigure.x = 0;
- event.xconfigure.y = 0;
- event.xconfigure.width = GTK_WIDGET(socket)->allocation.width;
- event.xconfigure.height = GTK_WIDGET(socket)->allocation.height;
+ GtkSocketPrivate *private = socket->priv;
+ if (!private->is_mapped)
+ {
+ private->is_mapped = TRUE;
+ private->need_map = TRUE;
- event.xconfigure.border_width = 0;
- event.xconfigure.above = None;
- event.xconfigure.override_redirect = False;
+ gtk_widget_queue_resize (GTK_WIDGET (socket));
+ }
+}
- gdk_error_trap_push ();
- XSendEvent (gdk_display,
- GDK_WINDOW_XWINDOW (socket->plug_window),
- False, NoEventMask, &event);
- gdk_flush ();
- gdk_error_trap_pop ();
+/**
+ * gtk_socket_unmap_notify:
+ * @socket: a #GtkSocket
+ *
+ * Called from the GtkSocket backend when the plug has been unmapped ???
+ */
+static void
+gtk_socket_unmap_notify (GtkSocket *socket)
+{
+ GtkSocketPrivate *private = socket->priv;
+ if (private->is_mapped)
+ {
+ private->is_mapped = FALSE;
+ gtk_widget_queue_resize (GTK_WIDGET (socket));
+ }
}
+/**
+ * gtk_socket_advance_toplevel_focus:
+ * @socket: a #GtkSocket
+ * @direction: a direction
+ *
+ * Called from the GtkSocket backend when the corresponding plug
+ * has told the socket to move the focus.
+ */
static void
-gtk_socket_add_window (GtkSocket *socket, GdkNativeWindow xid)
+gtk_socket_advance_toplevel_focus (GtkSocket *socket,
+ GtkDirectionType direction)
{
- socket->plug_window = gdk_window_lookup (xid);
- socket->same_app = TRUE;
+ GtkBin *bin;
+ GtkWindow *window;
+ GtkContainer *container;
+ GtkWidget *child;
+ GtkWidget *focus_widget;
+ GtkWidget *toplevel;
+ GtkWidget *old_focus_child;
+ GtkWidget *parent;
- if (!socket->plug_window)
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
+ if (!toplevel)
+ return;
+
+ if (!gtk_widget_is_toplevel (toplevel) || GTK_IS_PLUG (toplevel))
{
- GtkWidget *toplevel;
- GdkDragProtocol protocol;
-
- socket->plug_window = gdk_window_foreign_new (xid);
- if (!socket->plug_window) /* Already gone */
- return;
-
- socket->same_app = FALSE;
+ gtk_widget_child_focus (toplevel,direction);
+ return;
+ }
- gdk_error_trap_push ();
- XSelectInput (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW(socket->plug_window),
- StructureNotifyMask | PropertyChangeMask);
-
- if (gdk_drag_get_protocol (xid, &protocol))
- gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window,
- protocol, TRUE);
- gdk_flush ();
- gdk_error_trap_pop ();
+ container = GTK_CONTAINER (toplevel);
+ window = GTK_WINDOW (toplevel);
+ bin = GTK_BIN (toplevel);
- gdk_window_add_filter (socket->plug_window,
- gtk_socket_filter_func, socket);
+ /* This is a copy of gtk_window_focus(), modified so that we
+ * can detect wrap-around.
+ */
+ old_focus_child = gtk_container_get_focus_child (container);
+
+ if (old_focus_child)
+ {
+ if (gtk_widget_child_focus (old_focus_child, direction))
+ return;
- /* Add a pointer to the socket on our toplevel window */
+ /* We are allowed exactly one wrap-around per sequence of focus
+ * events
+ */
+ if (_gtk_xembed_get_focus_wrapped ())
+ return;
+ else
+ _gtk_xembed_set_focus_wrapped ();
+ }
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- if (toplevel && GTK_IS_WINDOW (toplevel))
+ focus_widget = gtk_window_get_focus (window);
+ if (window)
+ {
+ /* Wrapped off the end, clear the focus setting for the toplevel */
+ parent = gtk_widget_get_parent (focus_widget);
+ while (parent)
{
- gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
+ gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
+ parent = gtk_widget_get_parent (parent);
}
+
+ gtk_window_set_focus (GTK_WINDOW (container), NULL);
+ }
- gtk_widget_queue_resize (GTK_WIDGET (socket));
+ /* Now try to focus the first widget in the window */
+ child = gtk_bin_get_child (bin);
+ if (child)
+ {
+ if (gtk_widget_child_focus (child, direction))
+ return;
}
}
-
-static void
-send_xembed_message (GtkSocket *socket,
- glong message,
- glong detail,
- glong data1,
- glong data2,
- guint32 time)
+static gboolean
+xembed_get_info (GdkWindow *window,
+ unsigned long *version,
+ unsigned long *flags)
{
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket: Sending XEMBED message of type %d", message));
+ GdkDisplay *display = gdk_window_get_display (window);
+ Atom xembed_info_atom = gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED_INFO");
+ Atom type;
+ int format;
+ unsigned long nitems, bytes_after;
+ unsigned char *data;
+ unsigned long *data_long;
+ int status;
- if (socket->plug_window)
- {
- XEvent xevent;
-
- xevent.xclient.window = GDK_WINDOW_XWINDOW (socket->plug_window);
- xevent.xclient.type = ClientMessage;
- xevent.xclient.message_type = gdk_atom_intern ("_XEMBED", FALSE);
- xevent.xclient.format = 32;
- xevent.xclient.data.l[0] = time;
- xevent.xclient.data.l[1] = message;
- xevent.xclient.data.l[2] = detail;
- xevent.xclient.data.l[3] = data1;
- xevent.xclient.data.l[4] = data2;
+ gdk_error_trap_push ();
+ status = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
+ GDK_WINDOW_XID (window),
+ xembed_info_atom,
+ 0, 2, False,
+ xembed_info_atom, &type, &format,
+ &nitems, &bytes_after, &data);
+ gdk_error_trap_pop_ignored ();
+
+ if (status != Success)
+ return FALSE; /* Window vanished? */
+
+ if (type == None) /* No info property */
+ return FALSE;
- gdk_error_trap_push ();
- XSendEvent (gdk_display,
- GDK_WINDOW_XWINDOW (socket->plug_window),
- False, NoEventMask, &xevent);
- gdk_flush ();
- gdk_error_trap_pop ();
+ if (type != xembed_info_atom)
+ {
+ g_warning ("_XEMBED_INFO property has wrong type\n");
+ return FALSE;
}
+
+ if (nitems < 2)
+ {
+ g_warning ("_XEMBED_INFO too short\n");
+ XFree (data);
+ return FALSE;
+ }
+
+ data_long = (unsigned long *)data;
+ if (version)
+ *version = data_long[0];
+ if (flags)
+ *flags = data_long[1] & XEMBED_MAPPED;
+
+ XFree (data);
+ return TRUE;
}
static void
-handle_xembed_message (GtkSocket *socket,
- glong message,
- glong detail,
- glong data1,
- glong data2,
- guint32 time)
+handle_xembed_message (GtkSocket *socket,
+ XEmbedMessageType message,
+ glong detail,
+ glong data1,
+ glong data2,
+ guint32 time)
{
+ GTK_NOTE (PLUGSOCKET,
+ g_message ("GtkSocket: %s received", _gtk_xembed_message_name (message)));
+
switch (message)
{
case XEMBED_EMBEDDED_NOTIFY:
case XEMBED_MODALITY_OFF:
case XEMBED_FOCUS_IN:
case XEMBED_FOCUS_OUT:
- g_warning ("GtkSocket: Invalid _XEMBED message of type %ld received", message);
+ g_warning ("GtkSocket: Invalid _XEMBED message %s received", _gtk_xembed_message_name (message));
break;
case XEMBED_REQUEST_FOCUS:
- gtk_socket_claim_focus (socket);
+ gtk_socket_claim_focus (socket, TRUE);
break;
case XEMBED_FOCUS_NEXT:
case XEMBED_FOCUS_PREV:
- {
- GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- if (toplevel && GTK_IS_CONTAINER (toplevel))
- {
- gtk_container_focus (GTK_CONTAINER (toplevel),
- (message == XEMBED_FOCUS_NEXT ?
- GTK_DIR_TAB_FORWARD : GTK_DIR_TAB_BACKWARD));
- }
- break;
- }
+ gtk_socket_advance_toplevel_focus (socket,
+ (message == XEMBED_FOCUS_NEXT ?
+ GTK_DIR_TAB_FORWARD : GTK_DIR_TAB_BACKWARD));
+ break;
- case XEMBED_GRAB_KEY:
-#if 0
- add_grabbed_key (socket, data1, data2);
-#endif
+ case XEMBED_GTK_GRAB_KEY:
+ gtk_socket_add_grabbed_key (socket, data1, data2);
break;
+ case XEMBED_GTK_UNGRAB_KEY:
+ gtk_socket_remove_grabbed_key (socket, data1, data2);
+ break;
+
+ case XEMBED_GRAB_KEY:
case XEMBED_UNGRAB_KEY:
-#if 0
- remove_grabbed_key (socket, data1, data2);
-#endif
break;
default:
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket: Ignoring unknown _XEMBED message of type %ld", message));
+ GTK_NOTE (PLUGSOCKET,
+ g_message ("GtkSocket: Ignoring unknown _XEMBED message of type %d", message));
break;
}
}
static GdkFilterReturn
-gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
+gtk_socket_filter_func (GdkXEvent *gdk_xevent,
+ GdkEvent *event,
+ gpointer data)
{
GtkSocket *socket;
GtkWidget *widget;
+ GdkDisplay *display;
XEvent *xevent;
+ GtkSocketPrivate *private;
GdkFilterReturn return_val;
-
+
socket = GTK_SOCKET (data);
- widget = GTK_WIDGET (socket);
- xevent = (XEvent *)gdk_xevent;
+ private = socket->priv;
return_val = GDK_FILTER_CONTINUE;
+ if (private->plug_widget)
+ return return_val;
+
+ widget = GTK_WIDGET (socket);
+ xevent = (XEvent *)gdk_xevent;
+ display = gtk_widget_get_display (widget);
+
switch (xevent->type)
{
+ case ClientMessage:
+ if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED"))
+ {
+ _gtk_xembed_push_message (xevent);
+ handle_xembed_message (socket,
+ xevent->xclient.data.l[1],
+ xevent->xclient.data.l[2],
+ xevent->xclient.data.l[3],
+ xevent->xclient.data.l[4],
+ xevent->xclient.data.l[0]);
+ _gtk_xembed_pop_message ();
+
+ return_val = GDK_FILTER_REMOVE;
+ }
+ break;
+
case CreateNotify:
{
XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
- if (!socket->plug_window)
+ if (!private->plug_window)
{
- gtk_socket_add_window (socket, xcwe->window);
-
- gdk_error_trap_push ();
- gdk_window_move_resize(socket->plug_window,
- 0, 0,
- widget->allocation.width,
- widget->allocation.height);
- gdk_flush ();
- gdk_error_trap_pop ();
-
- socket->request_width = xcwe->width;
- socket->request_height = xcwe->height;
- socket->have_size = TRUE;
-
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - window created with size: %d %d",
- socket->request_width,
- socket->request_height));
+ gtk_socket_add_window (socket, xcwe->window, FALSE);
+
+ if (private->plug_window)
+ {
+ GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - window created"));
+ }
}
return_val = GDK_FILTER_REMOVE;
{
XConfigureRequestEvent *xcre = &xevent->xconfigurerequest;
- if (!socket->plug_window)
- gtk_socket_add_window (socket, xcre->window);
+ if (!private->plug_window)
+ gtk_socket_add_window (socket, xcre->window, FALSE);
- if (xcre->window == GDK_WINDOW_XWINDOW (socket->plug_window))
+ if (private->plug_window)
{
if (xcre->value_mask & (CWWidth | CWHeight))
{
- socket->request_width = xcre->width;
- socket->request_height = xcre->height;
- socket->have_size = TRUE;
-
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - configure request: %d %d",
- socket->request_width,
- socket->request_height));
-
+ GTK_NOTE (PLUGSOCKET,
+ g_message ("GtkSocket - configure request: %d %d",
+ private->request_width,
+ private->request_height));
+
+ private->resize_count++;
gtk_widget_queue_resize (widget);
}
else if (xcre->value_mask & (CWX | CWY))
{
XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
- if (socket->plug_window &&
- (xdwe->window == GDK_WINDOW_XWINDOW (socket->plug_window)))
+ /* Note that we get destroy notifies both from SubstructureNotify on
+ * our window and StructureNotify on socket->plug_window
+ */
+ if (private->plug_window && (xdwe->window == GDK_WINDOW_XID (private->plug_window)))
{
- GtkWidget *toplevel;
-
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - destroy notify"));
+ gboolean result;
- toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
- if (toplevel && GTK_IS_WINDOW (toplevel))
- gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel), xdwe->window);
+ GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - destroy notify"));
- gdk_window_destroy_notify (socket->plug_window);
- gtk_widget_destroy (widget);
-
- socket->plug_window = NULL;
+ gdk_window_destroy_notify (private->plug_window);
+ gtk_socket_end_embedding (socket);
+
+ g_object_ref (widget);
+ g_signal_emit_by_name (widget, "plug-removed", &result);
+ if (!result)
+ gtk_widget_destroy (widget);
+ g_object_unref (widget);
return_val = GDK_FILTER_REMOVE;
}
case FocusIn:
if (xevent->xfocus.mode == EMBEDDED_APP_WANTS_FOCUS)
{
- gtk_socket_claim_focus (socket);
- }
- else if (xevent->xfocus.detail == NotifyInferior)
- {
-#if 0
- GtkWidget *toplevel;
- toplevel = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
-
- if (toplevel)
- {
- XSetInputFocus (GDK_DISPLAY (),
- GDK_WINDOW_XWINDOW (toplevel->window),
- RevertToParent, CurrentTime); /* FIXME? */
- }
-#endif
+ gtk_socket_claim_focus (socket, TRUE);
}
return_val = GDK_FILTER_REMOVE;
break;
return_val = GDK_FILTER_REMOVE;
break;
case MapRequest:
- if (!socket->plug_window)
- gtk_socket_add_window (socket, xevent->xmaprequest.window);
+ if (!private->plug_window)
+ {
+ gtk_socket_add_window (socket, xevent->xmaprequest.window, FALSE);
+ }
- if (xevent->xmaprequest.window ==
- GDK_WINDOW_XWINDOW (socket->plug_window))
+ if (private->plug_window)
{
- GTK_NOTE(PLUGSOCKET,
- g_message ("GtkSocket - Map Request"));
-
- gdk_error_trap_push ();
- gdk_window_show (socket->plug_window);
- gdk_flush ();
- gdk_error_trap_pop ();
+ GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - Map Request"));
+ gtk_socket_handle_map_request (socket);
return_val = GDK_FILTER_REMOVE;
}
break;
case PropertyNotify:
- if (xevent->xproperty.window ==
- GDK_WINDOW_XWINDOW (socket->plug_window))
+ if (private->plug_window &&
+ xevent->xproperty.window == GDK_WINDOW_XID (private->plug_window))
{
GdkDragProtocol protocol;
- if ((xevent->xproperty.atom == gdk_atom_intern ("XdndAware", FALSE)) ||
- (xevent->xproperty.atom == gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE)))
+ if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_NORMAL_HINTS"))
+ {
+ GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - received PropertyNotify for plug's WM_NORMAL_HINTS"));
+ private->have_size = FALSE;
+ gtk_widget_queue_resize (widget);
+ return_val = GDK_FILTER_REMOVE;
+ }
+ else if ((xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "XdndAware")) ||
+ (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_MOTIF_DRAG_RECEIVER_INFO")))
{
gdk_error_trap_push ();
- if (gdk_drag_get_protocol (xevent->xproperty.window, &protocol))
+ protocol = gdk_window_get_drag_protocol (private->plug_window, NULL);
+ if (protocol)
gtk_drag_dest_set_proxy (GTK_WIDGET (socket),
- socket->plug_window,
+ private->plug_window,
protocol, TRUE);
- gdk_flush ();
- gdk_error_trap_pop ();
+
+ gdk_error_trap_pop_ignored ();
+ return_val = GDK_FILTER_REMOVE;
+ }
+ else if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED_INFO"))
+ {
+ unsigned long flags;
+
+ if (xembed_get_info (private->plug_window, NULL, &flags))
+ {
+ gboolean was_mapped = private->is_mapped;
+ gboolean is_mapped = (flags & XEMBED_MAPPED) != 0;
+
+ if (was_mapped != is_mapped)
+ {
+ if (is_mapped)
+ gtk_socket_handle_map_request (socket);
+ else
+ {
+ gdk_error_trap_push ();
+ gdk_window_show (private->plug_window);
+ gdk_error_trap_pop_ignored ();
+
+ gtk_socket_unmap_notify (socket);
+ }
+ }
+ }
+ return_val = GDK_FILTER_REMOVE;
}
- return_val = GDK_FILTER_REMOVE;
}
break;
- case ClientMessage:
- if (xevent->xclient.message_type == gdk_atom_intern ("_XEMBED", FALSE))
+ case ReparentNotify:
+ {
+ GdkWindow *window;
+ XReparentEvent *xre = &xevent->xreparent;
+
+ window = gtk_widget_get_window (widget);
+
+ GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - ReparentNotify received"));
+ if (!private->plug_window &&
+ xre->parent == GDK_WINDOW_XID (window))
+ {
+ gtk_socket_add_window (socket, xre->window, FALSE);
+
+ if (private->plug_window)
+ {
+ GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - window reparented"));
+ }
+
+ return_val = GDK_FILTER_REMOVE;
+ }
+ else
+ {
+ if (private->plug_window &&
+ xre->window == GDK_WINDOW_XID (private->plug_window) &&
+ xre->parent != GDK_WINDOW_XID (window))
+ {
+ gboolean result;
+
+ gtk_socket_end_embedding (socket);
+
+ g_object_ref (widget);
+ g_signal_emit_by_name (widget, "plug-removed", &result);
+ if (!result)
+ gtk_widget_destroy (widget);
+ g_object_unref (widget);
+
+ return_val = GDK_FILTER_REMOVE;
+ }
+ }
+
+ break;
+ }
+ case UnmapNotify:
+ if (private->plug_window &&
+ xevent->xunmap.window == GDK_WINDOW_XID (private->plug_window))
{
- handle_xembed_message (socket,
- xevent->xclient.data.l[1],
- xevent->xclient.data.l[2],
- xevent->xclient.data.l[3],
- xevent->xclient.data.l[4],
- xevent->xclient.data.l[0]);
-
-
+ GTK_NOTE (PLUGSOCKET, g_message ("GtkSocket - Unmap notify"));
+
+ gtk_socket_unmap_notify (socket);
return_val = GDK_FILTER_REMOVE;
}
break;
+
}
return return_val;