gtksocket.c 39 KB
Newer Older
1 2 3 4
/* GTK - The GIMP Toolkit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6 7 8 9 10 11
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15 16 17 18 19 20
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/* By Owen Taylor <otaylor@gtk.org>              98/4/4 */

21
/*
22
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23 24 25 26 27
 * file for a list of people on the GTK+ Team.  See the ChangeLog
 * files for a list of changes.  These files are distributed with
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
 */

28
#include <config.h>
29 30
#include <string.h>

31
#include "gdk/gdkkeysyms.h"
32
#include "gtkalias.h"
33
#include "gtkmain.h"
34
#include "gtkmarshalers.h"
35
#include "gtkwindow.h"
36
#include "gtkplug.h"
37
#include "gtkprivate.h"
38 39 40
#include "gtksocket.h"
#include "gtkdnd.h"

41
#include "x11/gdkx.h"
42

43
#include "gtkxembed.h"
44

45 46 47 48 49 50 51
typedef struct _GtkSocketPrivate GtkSocketPrivate;

struct _GtkSocketPrivate
{
  gint resize_count;
};

52 53
/* Forward declararations */

54 55
static void     gtk_socket_class_init           (GtkSocketClass   *klass);
static void     gtk_socket_init                 (GtkSocket        *socket);
56
static void     gtk_socket_finalize             (GObject          *object);
57 58
static void     gtk_socket_notify               (GObject          *object,
						 GParamSpec       *pspec);
59 60 61 62 63 64 65 66 67 68
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,
						 GtkWidget        *old_toplevel);
static void     gtk_socket_grab_notify          (GtkWidget        *widget,
						 gboolean          was_grabbed);
69
static gboolean gtk_socket_key_event            (GtkWidget        *widget,
70
						 GdkEventKey      *event);
71 72
static void     gtk_socket_claim_focus          (GtkSocket        *socket,
						 gboolean          send_event);
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
static void     gtk_socket_send_configure_event (GtkSocket        *socket);
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,
					       GdkNativeWindow  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);
94 95 96 97 98 99

/* From Tk */
#define EMBEDDED_APP_WANTS_FOCUS NotifyNormal+20

/* Local data */

100 101 102 103 104 105 106 107
enum {
  PLUG_ADDED,
  PLUG_REMOVED,
  LAST_SIGNAL
}; 

static guint socket_signals[LAST_SIGNAL] = { 0 };

108 109
static GtkWidgetClass *parent_class = NULL;

110
static GtkSocketPrivate *
111 112 113 114 115 116 117 118 119 120 121 122 123
gtk_socket_get_private (GtkSocket *socket)
{
  GtkSocketPrivate *private;
  static GQuark private_quark = 0;

  if (!private_quark)
    private_quark = g_quark_from_static_string ("gtk-socket-private");

  private = g_object_get_qdata (G_OBJECT (socket), private_quark);

  if (!private)
    {
      private = g_new0 (GtkSocketPrivate, 1);
124 125
      private->resize_count = 0;
      
126 127 128 129 130 131 132
      g_object_set_qdata_full (G_OBJECT (socket), private_quark,
			       private, (GDestroyNotify) g_free);
    }

  return private;
}

Manish Singh's avatar
Manish Singh committed
133
GType
Tim Janik's avatar
Tim Janik committed
134
gtk_socket_get_type (void)
135
{
Manish Singh's avatar
Manish Singh committed
136
  static GType socket_type = 0;
137 138 139

  if (!socket_type)
    {
140
      static const GTypeInfo socket_info =
141 142
      {
	sizeof (GtkSocketClass),
143 144 145 146 147 148 149 150
	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,
151 152
      };

Manish Singh's avatar
Manish Singh committed
153 154
      socket_type = g_type_register_static (GTK_TYPE_CONTAINER, "GtkSocket",
					    &socket_info, 0);
155 156 157 158 159
    }

  return socket_type;
}

160 161 162 163 164 165 166 167 168 169 170
static void
gtk_socket_finalize (GObject *object)
{
  GtkSocket *socket = GTK_SOCKET (object);
  
  g_object_unref (socket->accel_group);
  socket->accel_group = NULL;

  G_OBJECT_CLASS (parent_class)->finalize (object);
}

171 172 173 174 175
static void
gtk_socket_class_init (GtkSocketClass *class)
{
  GtkWidgetClass *widget_class;
  GtkContainerClass *container_class;
176
  GObjectClass *gobject_class;
177

178
  gobject_class = (GObjectClass *) class;
179 180 181
  widget_class = (GtkWidgetClass*) class;
  container_class = (GtkContainerClass*) class;

Manish Singh's avatar
Manish Singh committed
182
  parent_class = g_type_class_peek_parent (class);
183

184
  gobject_class->finalize = gtk_socket_finalize;
185
  gobject_class->notify = gtk_socket_notify;
186

187 188 189 190
  widget_class->realize = gtk_socket_realize;
  widget_class->unrealize = gtk_socket_unrealize;
  widget_class->size_request = gtk_socket_size_request;
  widget_class->size_allocate = gtk_socket_size_allocate;
191 192
  widget_class->hierarchy_changed = gtk_socket_hierarchy_changed;
  widget_class->grab_notify = gtk_socket_grab_notify;
193 194
  widget_class->key_press_event = gtk_socket_key_event;
  widget_class->key_release_event = gtk_socket_key_event;
195
  widget_class->focus = gtk_socket_focus;
196 197 198 199 200 201

  /* We don't want to show_all/hide_all the in-process
   * plug, if any.
   */
  widget_class->show_all = gtk_widget_show;
  widget_class->hide_all = gtk_widget_hide;
202 203 204
  
  container_class->remove = gtk_socket_remove;
  container_class->forall = gtk_socket_forall;
205 206 207 208 209 210 211

  socket_signals[PLUG_ADDED] =
    g_signal_new ("plug_added",
		  G_OBJECT_CLASS_TYPE (class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkSocketClass, plug_added),
		  NULL, NULL,
212
		  _gtk_marshal_VOID__VOID,
Manish Singh's avatar
Manish Singh committed
213
		  G_TYPE_NONE, 0);
214 215 216 217 218 219
  socket_signals[PLUG_REMOVED] =
    g_signal_new ("plug_removed",
		  G_OBJECT_CLASS_TYPE (class),
		  G_SIGNAL_RUN_LAST,
		  G_STRUCT_OFFSET (GtkSocketClass, plug_removed),
                  _gtk_boolean_handled_accumulator, NULL,
220
		  _gtk_marshal_BOOLEAN__VOID,
221
		  G_TYPE_BOOLEAN, 0);
222 223 224 225 226 227 228 229 230 231 232
}

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;
233
  socket->plug_widget = NULL;
234 235 236
  socket->focus_in = FALSE;
  socket->have_size = FALSE;
  socket->need_map = FALSE;
237
  socket->active = FALSE;
238 239 240

  socket->accel_group = gtk_accel_group_new ();
  g_object_set_data (G_OBJECT (socket->accel_group), "gtk-socket", socket);
241 242
}

243 244 245 246 247 248 249
/**
 * gtk_socket_new:
 * 
 * Create a new empty #GtkSocket.
 * 
 * Return value:  the new #GtkSocket.
 **/
250
GtkWidget*
Tim Janik's avatar
Tim Janik committed
251
gtk_socket_new (void)
252 253 254
{
  GtkSocket *socket;

255
  socket = g_object_new (GTK_TYPE_SOCKET, NULL);
256 257 258 259

  return GTK_WIDGET (socket);
}

260 261
/**
 * gtk_socket_steal:
262
 * @socket_: a #GtkSocket
263
 * @wid: the window ID of an existing toplevel window.
264 265 266 267 268 269 270 271 272
 * 
 * Reparents a pre-existing toplevel window into a #GtkSocket. This is
 * meant to embed clients that do not know about embedding into a
 * #GtkSocket, however doing so is inherently unreliable, and using
 * this function is not recommended.
 *
 * The #GtkSocket must have already be added into a toplevel window
 *  before you can make this call.
 **/
273
void           
274
gtk_socket_steal (GtkSocket *socket, GdkNativeWindow wid)
275
{
276 277 278 279 280 281
  g_return_if_fail (GTK_IS_SOCKET (socket));
  g_return_if_fail (GTK_WIDGET_ANCHORED (socket));

  if (!GTK_WIDGET_REALIZED (socket))
    gtk_widget_realize (GTK_WIDGET (socket));

282
  gtk_socket_add_window (socket, wid, TRUE);
283 284
}

285 286
/**
 * gtk_socket_add_id:
287
 * @socket_: a #GtkSocket
288
 * @window_id: the window ID of a client participating in the XEMBED protocol.
289 290 291 292 293
 *
 * 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
294 295
 * #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
296 297 298 299 300 301 302 303
 * 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           
304
gtk_socket_add_id (GtkSocket *socket, GdkNativeWindow window_id)
305 306 307 308 309 310 311
{
  g_return_if_fail (GTK_IS_SOCKET (socket));
  g_return_if_fail (GTK_WIDGET_ANCHORED (socket));

  if (!GTK_WIDGET_REALIZED (socket))
    gtk_widget_realize (GTK_WIDGET (socket));

312
  gtk_socket_add_window (socket, window_id, TRUE);
313 314 315 316
}

/**
 * gtk_socket_get_id:
317
 * @socket_: a #GtkSocket.
318 319 320
 * 
 * Gets the window ID of a #GtkSocket widget, which can then
 * be used to create a client embedded inside the socket, for
321
 * instance with gtk_plug_new(). 
Matthias Clasen's avatar
Matthias Clasen committed
322 323 324
 *
 * The #GtkSocket must have already be added into a toplevel window 
 * before you can make this call.
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
 * 
 * Return value: the window ID for the socket
 **/
GdkNativeWindow
gtk_socket_get_id (GtkSocket *socket)
{
  g_return_val_if_fail (GTK_IS_SOCKET (socket), 0);
  g_return_val_if_fail (GTK_WIDGET_ANCHORED (socket), 0);

  if (!GTK_WIDGET_REALIZED (socket))
    gtk_widget_realize (GTK_WIDGET (socket));

  return GDK_WINDOW_XWINDOW (GTK_WIDGET (socket)->window);
}

340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
static void
gtk_socket_realize (GtkWidget *widget)
{
  GtkSocket *socket;
  GdkWindowAttr attributes;
  gint attributes_mask;
  XWindowAttributes xattrs;

  g_return_if_fail (GTK_IS_SOCKET (widget));

  socket = GTK_SOCKET (widget);
  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  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.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;

  widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), 
				   &attributes, attributes_mask);
  gdk_window_set_user_data (widget->window, socket);

  widget->style = gtk_style_attach (widget->style, widget->window);
  gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);

372
  XGetWindowAttributes (GDK_WINDOW_XDISPLAY (widget->window),
373 374 375
			GDK_WINDOW_XWINDOW (widget->window),
			&xattrs);

376 377
  XSelectInput (GDK_WINDOW_XDISPLAY (widget->window),
		GDK_WINDOW_XWINDOW (widget->window), 
378 379 380 381 382 383 384 385 386 387 388
		xattrs.your_event_mask | 
		SubstructureNotifyMask | SubstructureRedirectMask);

  gdk_window_add_filter (widget->window, gtk_socket_filter_func, widget);

  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);

  /* 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.
   */
389
  gdk_display_sync (gtk_widget_get_display (widget));
390 391
}

392 393 394
static void
gtk_socket_end_embedding (GtkSocket *socket)
{
395
  GtkSocketPrivate *private = gtk_socket_get_private (socket);
396 397 398 399 400 401 402 403 404
  GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
  gint i;
  
  if (toplevel && GTK_IS_WINDOW (toplevel))
    gtk_window_remove_embedded_xid (GTK_WINDOW (toplevel), 
				    GDK_WINDOW_XWINDOW (socket->plug_window));

  g_object_unref (socket->plug_window);
  socket->plug_window = NULL;
405 406
  socket->current_width = 0;
  socket->current_height = 0;
407
  private->resize_count = 0;
408

409 410
  /* Remove from end to avoid indexes shifting. This is evil */
  for (i = socket->accel_group->n_accels - 1; i >= 0; i--)
411 412 413 414 415 416
    {
      GtkAccelGroupEntry *accel_entry = &socket->accel_group->priv_accels[i];
      gtk_accel_group_disconnect (socket->accel_group, accel_entry->closure);
    }
}

417 418 419
static void
gtk_socket_unrealize (GtkWidget *widget)
{
420
  GtkSocket *socket = GTK_SOCKET (widget);
421

422 423
  GTK_WIDGET_UNSET_FLAGS (widget, GTK_REALIZED);

424 425 426 427 428
  if (socket->plug_widget)
    {
      _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
    }
  else if (socket->plug_window)
429
    {
430
      gtk_socket_end_embedding (socket);
431 432 433 434 435 436 437 438 439 440
    }

  if (GTK_WIDGET_CLASS (parent_class)->unrealize)
    (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget);
}
  
static void 
gtk_socket_size_request (GtkWidget      *widget,
			 GtkRequisition *requisition)
{
441
  GtkSocket *socket = GTK_SOCKET (widget);
442

443
  if (socket->plug_widget)
444
    {
445 446 447 448 449
      gtk_widget_size_request (socket->plug_widget, requisition);
    }
  else
    {
      if (socket->is_mapped && !socket->have_size && socket->plug_window)
450
	{
451 452 453 454
	  XSizeHints hints;
	  long supplied;
	  
	  gdk_error_trap_push ();
455 456 457

	  socket->request_width = 1;
	  socket->request_height = 1;
458
	  
459
	  if (XGetWMNormalHints (GDK_WINDOW_XDISPLAY (socket->plug_window),
460 461
				 GDK_WINDOW_XWINDOW (socket->plug_window),
				 &hints, &supplied))
462
	    {
463
	      if (hints.flags & PMinSize)
464 465 466 467 468 469 470 471 472
		{
		  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;
		}
473
	    }
474
	  socket->have_size = TRUE;
475 476
	  
	  gdk_error_trap_pop ();
477
	}
478

479 480 481 482 483 484 485 486 487 488
      if (socket->is_mapped && socket->have_size)
	{
	  requisition->width = MAX (socket->request_width, 1);
	  requisition->height = MAX (socket->request_height, 1);
	}
      else
	{
	  requisition->width = 1;
	  requisition->height = 1;
	}
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
    }
}

static void
gtk_socket_size_allocate (GtkWidget     *widget,
			  GtkAllocation *allocation)
{
  GtkSocket *socket;

  g_return_if_fail (GTK_IS_SOCKET (widget));
  g_return_if_fail (allocation != NULL);

  socket = GTK_SOCKET (widget);

  widget->allocation = *allocation;
  if (GTK_WIDGET_REALIZED (widget))
    {
      gdk_window_move_resize (widget->window,
			      allocation->x, allocation->y,
			      allocation->width, allocation->height);

510 511 512 513 514 515 516 517 518 519 520 521
      if (socket->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 (socket->plug_widget, &child_allocation);
	}
      else if (socket->plug_window)
522
	{
523 524
	  GtkSocketPrivate *private = gtk_socket_get_private (socket);
	  
525 526
	  gdk_error_trap_push ();
	  
527 528
	  if (allocation->width != socket->current_width ||
	      allocation->height != socket->current_height)
529 530 531 532
	    {
	      gdk_window_move_resize (socket->plug_window,
				      0, 0,
				      allocation->width, allocation->height);
533 534 535
	      if (private->resize_count)
		private->resize_count--;
	      
536 537 538
	      GTK_NOTE(PLUGSOCKET,
		       g_message ("GtkSocket - allocated: %d %d",
				  allocation->width, allocation->height));
539 540 541 542 543 544 545 546 547 548
	      socket->current_width = allocation->width;
	      socket->current_height = allocation->height;
	    }

	  if (socket->need_map)
	    {
	      gdk_window_show (socket->plug_window);
	      socket->need_map = FALSE;
	    }

549 550 551 552 553 554 555 556 557
	  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));
 	    }
	  
558
	  gdk_display_sync (gtk_widget_get_display (widget));
559
	  gdk_error_trap_pop ();
560 561 562 563
	}
    }
}

564
typedef struct
565
{
566 567
  guint			 accel_key;
  GdkModifierType	 accel_mods;
568 569
} GrabbedKey;

570 571 572 573 574 575
static gboolean
activate_key (GtkAccelGroup  *accel_group,
	      GObject        *acceleratable,
	      guint           accel_key,
	      GdkModifierType accel_mods,
	      GrabbedKey     *grabbed_key)
576
{
577 578
  XEvent xevent;
  GdkEvent *gdk_event = gtk_get_current_event ();
579
  
580
  GtkSocket *socket = g_object_get_data (G_OBJECT (accel_group), "gtk-socket");
581
  GdkScreen *screen = gdk_drawable_get_screen (socket->plug_window);
582
  gboolean retval = FALSE;
583

584 585 586 587
  if (gdk_event && gdk_event->type == GDK_KEY_PRESS && socket->plug_window)
    {
      xevent.xkey.type = KeyPress;
      xevent.xkey.window = GDK_WINDOW_XWINDOW (socket->plug_window);
588
      xevent.xkey.root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
589 590 591 592 593 594 595 596 597 598 599
      xevent.xkey.subwindow = None;
      xevent.xkey.time = gdk_event->key.time;
      xevent.xkey.x = 0;
      xevent.xkey.y = 0;
      xevent.xkey.x_root = 0;
      xevent.xkey.y_root = 0;
      xevent.xkey.state = gdk_event->key.state;
      xevent.xkey.keycode = gdk_event->key.hardware_keycode;
      xevent.xkey.same_screen = True;

      gdk_error_trap_push ();
600
      XSendEvent (GDK_WINDOW_XDISPLAY (socket->plug_window),
601 602
		  GDK_WINDOW_XWINDOW (socket->plug_window),
		  False, KeyPressMask, &xevent);
603
      gdk_display_sync (gdk_screen_get_display (screen));
604
      gdk_error_trap_pop ();
605 606

      retval = TRUE;
607 608 609 610
    }

  if (gdk_event)
    gdk_event_free (gdk_event);
611 612

  return retval;
613 614 615
}

static gboolean
616 617 618
find_accel_key (GtkAccelKey *key,
		GClosure    *closure,
		gpointer     data)
619
{
620 621 622 623
  GrabbedKey *grabbed_key = data;
  
  return (key->accel_key == grabbed_key->accel_key &&
	  key->accel_mods == grabbed_key->accel_mods);
624 625 626
}

static void
627 628 629
add_grabbed_key (GtkSocket       *socket,
		 guint            keyval,
		 GdkModifierType  modifiers)
630
{
631 632
  GClosure *closure;
  GrabbedKey *grabbed_key;
633

634 635 636 637
  grabbed_key = g_new (GrabbedKey, 1);
  
  grabbed_key->accel_key = keyval;
  grabbed_key->accel_mods = modifiers;
638

639 640 641 642 643 644 645 646
  if (gtk_accel_group_find (socket->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;
647 648
    }

649
  closure = g_cclosure_new (G_CALLBACK (activate_key), grabbed_key, (GClosureNotify)g_free);
650

651 652
  gtk_accel_group_connect (socket->accel_group, keyval, modifiers, GTK_ACCEL_LOCKED,
			   closure);
653 654 655 656
}

static void
remove_grabbed_key (GtkSocket      *socket,
657 658
		    guint           keyval,
		    GdkModifierType modifiers)
659
{
660
  gint i;
661

662
  for (i = 0; i < socket->accel_group->n_accels; i++)
663
    {
664 665 666 667 668 669 670 671
      GtkAccelGroupEntry *accel_entry = &socket->accel_group->priv_accels[i];
      if (accel_entry->key.accel_key == keyval &&
	  accel_entry->key.accel_mods == modifiers)
	{
	  gtk_accel_group_disconnect (socket->accel_group,
				      accel_entry->closure);
	  return;
	}
672 673
    }

674 675
  g_warning ("GtkSocket: request to remove non-present grabbed key %u,%#x\n",
	     keyval, modifiers);
676 677
}

678 679
static void
socket_update_focus_in (GtkSocket *socket)
680
{
681 682 683 684 685 686 687 688 689 690 691 692 693 694
  gboolean focus_in = FALSE;

  if (socket->plug_window)
    {
      GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
      if (GTK_WIDGET_TOPLEVEL (toplevel) &&
	  GTK_WINDOW (toplevel)->has_toplevel_focus &&
	  gtk_widget_is_focus (GTK_WIDGET (socket)))
	focus_in = TRUE;
    }

  if (focus_in != socket->focus_in)
    {
      socket->focus_in = focus_in;
695

696
      if (focus_in)
697 698
	_gtk_xembed_send_focus_message (socket->plug_window,
					XEMBED_FOCUS_IN, XEMBED_FOCUS_CURRENT);
699
      else
700 701
	_gtk_xembed_send_message (socket->plug_window,
				  XEMBED_FOCUS_OUT, 0, 0, 0);
702
    }
703 704
}

705 706
static void
socket_update_active (GtkSocket *socket)
707
{
708
  gboolean active = FALSE;
709

710 711 712 713 714 715 716 717 718 719 720 721
  if (socket->plug_window)
    {
      GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
      if (GTK_WIDGET_TOPLEVEL (toplevel) &&
	  GTK_WINDOW (toplevel)->is_active)
	active = TRUE;
    }

  if (active != socket->active)
    {
      socket->active = active;

722 723 724
      _gtk_xembed_send_message (socket->plug_window,
				active ? XEMBED_WINDOW_ACTIVATE : XEMBED_WINDOW_DEACTIVATE,
				0, 0, 0);
725
    }
726 727 728
}

static void
729 730
gtk_socket_hierarchy_changed (GtkWidget *widget,
			      GtkWidget *old_toplevel)
731 732 733 734 735 736 737 738 739 740 741
{
  GtkSocket *socket = GTK_SOCKET (widget);
  GtkWidget *toplevel = gtk_widget_get_toplevel (widget);

  if (toplevel && !GTK_IS_WINDOW (toplevel))
    toplevel = NULL;

  if (toplevel != socket->toplevel)
    {
      if (socket->toplevel)
	{
742
	  gtk_window_remove_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
743
	  g_signal_handlers_disconnect_by_func (socket->toplevel,
Manish Singh's avatar
Manish Singh committed
744 745
						socket_update_focus_in,
						socket);
746
	  g_signal_handlers_disconnect_by_func (socket->toplevel,
Manish Singh's avatar
Manish Singh committed
747 748
						socket_update_active,
						socket);
749 750 751 752 753 754
	}

      socket->toplevel = toplevel;

      if (toplevel)
	{
755
	  gtk_window_add_accel_group (GTK_WINDOW (socket->toplevel), socket->accel_group);
756
	  g_signal_connect_swapped (socket->toplevel, "notify::has-toplevel-focus",
757
				    G_CALLBACK (socket_update_focus_in), socket);
758
	  g_signal_connect_swapped (socket->toplevel, "notify::is-active",
759
				    G_CALLBACK (socket_update_active), socket);
760
	}
761 762 763

      socket_update_focus_in (socket);
      socket_update_active (socket);
764 765 766 767 768 769 770
    }
}

static void
gtk_socket_grab_notify (GtkWidget *widget,
			gboolean   was_grabbed)
{
771 772 773
  GtkSocket *socket = GTK_SOCKET (widget);

  if (!socket->same_app)
774 775 776
    _gtk_xembed_send_message (GTK_SOCKET (widget)->plug_window,
			      was_grabbed ? XEMBED_MODALITY_OFF : XEMBED_MODALITY_ON,
			      0, 0, 0);
777 778 779
}

static gboolean
780 781
gtk_socket_key_event (GtkWidget   *widget,
                      GdkEventKey *event)
782 783 784
{
  GtkSocket *socket = GTK_SOCKET (widget);
  
785
  if (GTK_WIDGET_HAS_FOCUS (socket) && socket->plug_window && !socket->plug_widget)
786
    {
787
      GdkScreen *screen = gdk_drawable_get_screen (socket->plug_window);
788 789
      XEvent xevent;
      
790
      xevent.xkey.type = (event->type == GDK_KEY_PRESS) ? KeyPress : KeyRelease;
791
      xevent.xkey.window = GDK_WINDOW_XWINDOW (socket->plug_window);
792
      xevent.xkey.root = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen));
793 794 795 796 797 798 799 800 801 802
      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 ? */
      
803
      gdk_error_trap_push ();
804
      XSendEvent (GDK_WINDOW_XDISPLAY (socket->plug_window),
805 806
		  GDK_WINDOW_XWINDOW (socket->plug_window),
		  False, NoEventMask, &xevent);
807
      gdk_display_sync (gtk_widget_get_display (widget));
808
      gdk_error_trap_pop ();
809 810 811 812 813 814 815
      
      return TRUE;
    }
  else
    return FALSE;
}

816 817 818
static void
gtk_socket_notify (GObject    *object,
		   GParamSpec *pspec)
819
{
820 821
  if (!strcmp (pspec->name, "is_focus"))
    return;
822

823
  socket_update_focus_in (GTK_SOCKET (object));
824 825 826
}

static void
827 828
gtk_socket_claim_focus (GtkSocket *socket,
			gboolean   send_event)
829
{
830 831
  if (!send_event)
    socket->focus_in = TRUE;	/* Otherwise, our notify handler will send FOCUS_IN  */
832 833 834 835 836 837 838 839
      
  /* 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);
}

840
static gboolean
841
gtk_socket_focus (GtkWidget *widget, GtkDirectionType direction)
842 843
{
  GtkSocket *socket;
844
  gint detail = -1;
845

846
  g_return_val_if_fail (GTK_IS_SOCKET (widget), FALSE);
847
  
848
  socket = GTK_SOCKET (widget);
849

850 851 852
  if (socket->plug_widget)
    return gtk_widget_child_focus (socket->plug_widget, direction);

853
  if (!gtk_widget_is_focus (widget))
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868
    {
      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;
	}
      
869 870
      _gtk_xembed_send_focus_message (socket->plug_window,
				      XEMBED_FOCUS_IN, detail);
871

872
      gtk_socket_claim_focus (socket, FALSE);
873 874 875 876 877
 
      return TRUE;
    }
  else
    return FALSE;
878 879
}

880 881 882 883 884 885 886 887
static void
gtk_socket_remove (GtkContainer *container,
		   GtkWidget    *child)
{
  GtkSocket *socket = GTK_SOCKET (container);

  g_return_if_fail (child == socket->plug_widget);

888
  _gtk_plug_remove_from_socket (GTK_PLUG (socket->plug_widget), socket);
889 890 891 892 893 894 895 896 897 898 899 900 901 902
}

static void
gtk_socket_forall (GtkContainer *container,
		   gboolean      include_internals,
		   GtkCallback   callback,
		   gpointer      callback_data)
{
  GtkSocket *socket = GTK_SOCKET (container);

  if (socket->plug_widget)
    (* callback) (socket->plug_widget, callback_data);
}

903 904 905 906
static void
gtk_socket_send_configure_event (GtkSocket *socket)
{
  XEvent event;
907
  gint x, y;
908 909 910 911 912 913 914 915

  g_return_if_fail (socket->plug_window != NULL);

  event.xconfigure.type = ConfigureNotify;

  event.xconfigure.event = GDK_WINDOW_XWINDOW (socket->plug_window);
  event.xconfigure.window = GDK_WINDOW_XWINDOW (socket->plug_window);

916 917 918 919 920 921 922 923 924 925
  /* 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->plug_window, &x, &y);
  gdk_error_trap_pop ();
			 
  event.xconfigure.x = x;
  event.xconfigure.y = y;
926 927 928 929 930 931
  event.xconfigure.width = GTK_WIDGET(socket)->allocation.width;
  event.xconfigure.height = GTK_WIDGET(socket)->allocation.height;

  event.xconfigure.border_width = 0;
  event.xconfigure.above = None;
  event.xconfigure.override_redirect = False;
932 933

  gdk_error_trap_push ();
934
  XSendEvent (GDK_WINDOW_XDISPLAY (socket->plug_window),
935 936
	      GDK_WINDOW_XWINDOW (socket->plug_window),
	      False, NoEventMask, &event);
937
  gdk_display_sync (gtk_widget_get_display (GTK_WIDGET (socket)));
938
  gdk_error_trap_pop ();
939 940 941
}

static void
942 943 944
gtk_socket_add_window (GtkSocket        *socket,
		       GdkNativeWindow   xid,
		       gboolean          need_reparent)
945
{
946
  GtkWidget *widget = GTK_WIDGET (socket);
947
  GdkDisplay *display = gtk_widget_get_display (widget);
948 949
  gpointer user_data = NULL;
  
950
  socket->plug_window = gdk_window_lookup_for_display (display, xid);
951

952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973
  if (socket->plug_window)
    {
      g_object_ref (socket->plug_window);
      gdk_window_get_user_data (socket->plug_window, &user_data);
    }

  if (user_data)		/* A widget's window in this process */
    {
      GtkWidget *child_widget = user_data;

      if (!GTK_IS_PLUG (child_widget))
	{
	  g_warning (G_STRLOC "Can't add non-GtkPlug to GtkSocket");
	  socket->plug_window = NULL;
	  gdk_error_trap_pop ();
	  
	  return;
	}

      _gtk_plug_add_to_socket (GTK_PLUG (child_widget), socket);
    }
  else				/* A foreign window */
974 975 976
    {
      GtkWidget *toplevel;
      GdkDragProtocol protocol;
977 978
      unsigned long version;
      unsigned long flags;
979 980

      gdk_error_trap_push ();
981 982 983

      if (!socket->plug_window)
	{  
984
	  socket->plug_window = gdk_window_foreign_new_for_display (display, xid);
985 986 987 988 989 990 991
	  if (!socket->plug_window) /* was deleted before we could get it */
	    {
	      gdk_error_trap_pop ();
	      return;
	    }
	}
	
992 993
      XSelectInput (GDK_DISPLAY_XDISPLAY (display),
		    GDK_WINDOW_XWINDOW (socket->plug_window),
994
		    StructureNotifyMask | PropertyChangeMask);
995
      
996 997
      if (gdk_error_trap_pop ())
	{
Manish Singh's avatar
Manish Singh committed
998
	  g_object_unref (socket->plug_window);
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
	  socket->plug_window = NULL;
	  return;
	}
      
      /* OK, we now will reliably get destroy notification on socket->plug_window */

      gdk_error_trap_push ();

      if (need_reparent)
	{
	  gdk_window_hide (socket->plug_window); /* Shouldn't actually be necessary for XEMBED, but just in case */
	  gdk_window_reparent (socket->plug_window, widget->window, 0, 0);
	}

      socket->have_size = FALSE;

      socket->xembed_version = -1;
      if (xembed_get_info (socket->plug_window, &version, &flags))
	{
1018
	  socket->xembed_version = MIN (GTK_XEMBED_PROTOCOL_VERSION, version);
1019 1020 1021 1022 1023 1024
	  socket->is_mapped = (flags & XEMBED_MAPPED) != 0;
	}
      else
	{
	  /* FIXME, we should probably actually check the state before we started */
	  
1025
	  socket->is_mapped = TRUE;
1026 1027 1028 1029
	}
      
      socket->need_map = socket->is_mapped;

1030
      if (gdk_drag_get_protocol_for_display (display, xid, &protocol))
1031 1032
	gtk_drag_dest_set_proxy (GTK_WIDGET (socket), socket->plug_window, 
				 protocol, TRUE);
1033 1034

      gdk_display_sync (display);
1035
      gdk_error_trap_pop ();
1036 1037 1038 1039 1040 1041 1042 1043

      gdk_window_add_filter (socket->plug_window, 
			     gtk_socket_filter_func, socket);

      /* Add a pointer to the socket on our toplevel window */

      toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
      if (toplevel && GTK_IS_WINDOW (toplevel))
1044
	gtk_window_add_embedded_xid (GTK_WINDOW (toplevel), xid);
1045

1046 1047 1048 1049
      _gtk_xembed_send_message (socket->plug_window,
				XEMBED_EMBEDDED_NOTIFY, 0,
				GDK_WINDOW_XWINDOW (widget->window),
				socket->xembed_version);
1050 1051 1052
      socket_update_active (socket);
      socket_update_focus_in (socket);

1053 1054
      gtk_widget_queue_resize (GTK_WIDGET (socket));
    }
1055 1056

  if (socket->plug_window)
Manish Singh's avatar
Manish Singh committed
1057
    g_signal_emit (socket, socket_signals[PLUG_ADDED], 0);
1058 1059
}

1060
static gboolean
1061
xembed_get_info (GdkWindow     *window,
1062 1063 1064
		 unsigned long *version,
		 unsigned long *flags)
{
1065 1066
  GdkDisplay *display = gdk_drawable_get_display (window);
  Atom xembed_info_atom = gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED_INFO");
1067 1068 1069 1070 1071 1072 1073 1074
  Atom type;
  int format;
  unsigned long nitems, bytes_after;
  unsigned char *data;
  unsigned long *data_long;
  int status;
  
  gdk_error_trap_push();
1075 1076
  status = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
			       GDK_WINDOW_XWINDOW (window),
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
			       xembed_info_atom,
			       0, 2, False,
			       xembed_info_atom, &type, &format,
			       &nitems, &bytes_after, &data);
  gdk_error_trap_pop();

  if (status != Success)
    return FALSE;		/* Window vanished? */

  if (type == None)		/* No info property */
    return FALSE;

  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;
}

1112
static void
1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183
advance_toplevel_focus (GtkSocket        *socket,
			GtkDirectionType  direction)
{
  GtkBin *bin;
  GtkWindow *window;
  GtkContainer *container;
  GtkWidget *toplevel;
  GtkWidget *old_focus_child;
  GtkWidget *parent;

  toplevel = gtk_widget_get_toplevel (GTK_WIDGET (socket));
  if (!toplevel)
    return;

  if (!GTK_WIDGET_TOPLEVEL (toplevel) || GTK_IS_PLUG (toplevel))
    {
      gtk_widget_child_focus (toplevel,direction);
      return;
    }

  container = GTK_CONTAINER (toplevel);
  window = GTK_WINDOW (toplevel);
  bin = GTK_BIN (toplevel);

  /* This is a copy of gtk_window_focus(), modified so that we
   * can detect wrap-around.
   */
  old_focus_child = container->focus_child;
  
  if (old_focus_child)
    {
      if (gtk_widget_child_focus (old_focus_child, direction))
	return;

      /* 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 ();
    }

  if (window->focus_widget)
    {
      /* Wrapped off the end, clear the focus setting for the toplevel */
      parent = window->focus_widget->parent;
      while (parent)
	{
	  gtk_container_set_focus_child (GTK_CONTAINER (parent), NULL);
	  parent = GTK_WIDGET (parent)->parent;
	}
      
      gtk_window_set_focus (GTK_WINDOW (container), NULL);
    }

  /* Now try to focus the first widget in the window */
  if (bin->child)
    {
      if (gtk_widget_child_focus (bin->child, direction))
        return;
    }
}

static void
handle_xembed_message (GtkSocket        *socket,
		       XEmbedMessageType message,
		       glong             detail,
		       glong             data1,
		       glong             data2,
		       guint32           time)
1184
{
1185
  GTK_NOTE (PLUGSOCKET,
1186
	    g_message ("GtkSocket: Message of type %d received", message));
1187
  
1188 1189 1190 1191 1192 1193 1194 1195 1196
  switch (message)
    {
    case XEMBED_EMBEDDED_NOTIFY:
    case XEMBED_WINDOW_ACTIVATE:
    case XEMBED_WINDOW_DEACTIVATE:
    case XEMBED_MODALITY_ON:
    case XEMBED_MODALITY_OFF:
    case XEMBED_FOCUS_IN:
    case XEMBED_FOCUS_OUT:
1197
      g_warning ("GtkSocket: Invalid _XEMBED message of type %d received", message);
1198 1199 1200
      break;
      
    case XEMBED_REQUEST_FOCUS:
1201
      gtk_socket_claim_focus (socket, TRUE);
1202 1203 1204 1205
      break;

    case XEMBED_FOCUS_NEXT:
    case XEMBED_FOCUS_PREV:
1206 1207 1208 1209
      advance_toplevel_focus (socket,
			      (message == XEMBED_FOCUS_NEXT ?
			       GTK_DIR_TAB_FORWARD : GTK_DIR_TAB_BACKWARD));
      break;
1210
      
1211
    case XEMBED_GTK_GRAB_KEY:
1212 1213
      add_grabbed_key (socket, data1, data2);
      break; 
1214
    case XEMBED_GTK_UNGRAB_KEY:
1215
      remove_grabbed_key (socket, data1, data2);
1216 1217 1218 1219
      break;

    case XEMBED_GRAB_KEY:
    case XEMBED_UNGRAB_KEY:
1220 1221 1222
      break;
      
    default:
1223
      GTK_NOTE (PLUGSOCKET,
1224
		g_message ("GtkSocket: Ignoring unknown _XEMBED message of type %d", message));
1225
      break;
1226 1227 1228
    }
}

1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
static void
map_request (GtkSocket *socket)
{
  if (!socket->is_mapped)
    {
      socket->is_mapped = TRUE;
      socket->need_map = TRUE;

      gtk_widget_queue_resize (GTK_WIDGET (socket));
    }
}

static void
unmap_notify (GtkSocket *socket)
{
  if (socket->is_mapped)
    {
      socket->is_mapped = FALSE;
      gtk_widget_queue_resize (GTK_WIDGET (socket));
    }
}

1251 1252 1253 1254 1255
static GdkFilterReturn
gtk_socket_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
{
  GtkSocket *socket;
  GtkWidget *widget;
1256
  GdkDisplay *display;
1257 1258 1259 1260 1261 1262 1263
  XEvent *xevent;

  GdkFilterReturn return_val;
  
  socket = GTK_SOCKET (data);
  widget = GTK_WIDGET (socket);
  xevent = (XEvent *)gdk_xevent;
1264
  display = gtk_widget_get_display (widget);
1265 1266 1267

  return_val = GDK_FILTER_CONTINUE;

1268 1269 1270
  if (socket->plug_widget)
    return return_val;

1271 1272
  switch (xevent->type)
    {
1273
    case ClientMessage:
1274
      if (xevent->xclient.message_type == gdk_x11_get_xatom_by_name_for_display (display, "_XEMBED"))
1275
	{
1276
	  _gtk_xembed_push_message (xevent);
1277 1278 1279 1280 1281 1282
	  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]);
1283
	  _gtk_xembed_pop_message ();
1284 1285 1286 1287 1288
	  
	  return_val = GDK_FILTER_REMOVE;
	}
      break;

1289 1290 1291 1292 1293
    case CreateNotify:
      {
	XCreateWindowEvent *xcwe = &xevent->xcreatewindow;

	if (!socket->plug_window)
1294
	  {
1295
	    gtk_socket_add_window (socket, xcwe->window, FALSE);
1296

1297 1298 1299
	    if (socket->plug_window)
	      {
		GTK_NOTE(PLUGSOCKET,
1300
			 g_message ("GtkSocket - window created"));
1301
	      }
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
	  }
	
	return_val = GDK_FILTER_REMOVE;
	
	break;
      }

    case ConfigureRequest:
      {
	XConfigureRequestEvent *xcre = &xevent->xconfigurerequest;
	
	if (!socket->plug_window)
1314
	  gtk_socket_add_window (socket, xcre->window, FALSE);
1315
	
1316
	if (socket->plug_window)
1317
	  {
1318 1319
	    GtkSocketPrivate *private = gtk_socket_get_private (socket);
	    
1320 1321
	    if (xcre->value_mask & (CWWidth | CWHeight))
	      {
1322 1323 1324 1325
		GTK_NOTE(PLUGSOCKET,
			 g_message ("GtkSocket - configure request: %d %d",
				    socket->request_width,
				    socket->request_height));
1326 1327

		private->resize_count++;
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
		gtk_widget_queue_resize (widget);
	      }
	    else if (xcre->value_mask & (CWX | CWY))
	      {
		gtk_socket_send_configure_event (socket);
	      }
	    /* Ignore stacking requests. */
	    
	    return_val = GDK_FILTER_REMOVE;
	  }
	break;
      }

    case DestroyNotify:
      {
	XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;