gdkevents-x11.c 66.4 KB
Newer Older
1 2 3 4
/* GDK - The GIMP Drawing Kit
 * 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
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

20
/*
21
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22 23 24 25 26
 * 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/. 
 */

27
#include "gdk.h"
28 29
#include "gdkprivate-x11.h"
#include "gdkinternals.h"
Owen Taylor's avatar
Started  
Owen Taylor committed
30
#include "gdkx.h"
31 32
#include "gdkscreen-x11.h"
#include "gdkdisplay-x11.h"
Owen Taylor's avatar
Started  
Owen Taylor committed
33

34 35
#include "gdkkeysyms.h"

36 37
#include "xsettings-client.h"

38 39 40 41 42 43 44
#if HAVE_CONFIG_H
#  include <config.h>
#  if STDC_HEADERS
#    include <string.h>
#  endif
#endif

Owen Taylor's avatar
Started  
Owen Taylor committed
45
#include "gdkinputprivate.h"
46

Havoc Pennington's avatar
Havoc Pennington committed
47 48 49 50
#ifdef HAVE_XKB
#include <X11/XKBlib.h>
#endif

Havoc Pennington's avatar
Havoc Pennington committed
51 52
#include <X11/Xatom.h>

53
typedef struct _GdkIOClosure GdkIOClosure;
54
typedef struct _GdkEventPrivate GdkEventPrivate;
55
typedef struct _GdkDisplaySource GdkDisplaySource;
56 57 58 59 60 61

#define DOUBLE_CLICK_TIME      250
#define TRIPLE_CLICK_TIME      500
#define DOUBLE_CLICK_DIST      5
#define TRIPLE_CLICK_DIST      5

62 63
typedef enum
{
64 65 66 67 68 69
  /* Following flag is set for events on the event queue during
   * translation and cleared afterwards.
   */
  GDK_EVENT_PENDING = 1 << 0
} GdkEventFlags;

70 71
struct _GdkIOClosure
{
72 73 74 75 76 77
  GdkInputFunction function;
  GdkInputCondition condition;
  GdkDestroyNotify notify;
  gpointer data;
};

78 79
struct _GdkEventPrivate
{
80 81 82 83
  GdkEvent event;
  guint    flags;
};

84 85 86 87 88 89 90 91
struct _GdkDisplaySource
{
  GSource source;
  
  GdkDisplay *display;
  GPollFD event_poll_fd;
};

92 93 94 95
/* 
 * Private function declarations
 */

96
static gint	 gdk_event_apply_filters (XEvent   *xevent,
97
					  GdkEvent *event,
98
					  GList    *filters);
99 100 101 102
static gboolean	 gdk_event_translate	 (GdkDisplay *display,
					  GdkEvent   *event, 
					  XEvent     *xevent,
					  gboolean    return_exposes);
103

104 105 106 107 108 109
static gboolean gdk_event_prepare  (GSource     *source,
				    gint        *timeout);
static gboolean gdk_event_check    (GSource     *source);
static gboolean gdk_event_dispatch (GSource     *source,
				    GSourceFunc  callback,
				    gpointer     user_data);
110

111 112 113
static GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
						GdkEvent  *event,
						gpointer   data);
114

115 116 117
static GSource *gdk_display_source_new (GdkDisplay *display);
static gboolean gdk_check_xpending     (GdkDisplay *display);

118 119 120 121 122 123 124 125 126
static void gdk_xsettings_watch_cb  (Window            window,
				     Bool              is_start,
				     long              mask,
				     void             *cb_data);
static void gdk_xsettings_notify_cb (const char       *name,
				     XSettingsAction   action,
				     XSettingsSetting *setting,
				     void             *data);

127 128 129
/* Private variable declarations
 */

130
static GList *display_sources;
131 132 133 134 135

static GSourceFuncs event_funcs = {
  gdk_event_prepare,
  gdk_event_check,
  gdk_event_dispatch,
136
  NULL
137 138
};

139 140 141 142 143 144 145 146 147 148
static GSource *
gdk_display_source_new (GdkDisplay *display)
{
  GSource *source = g_source_new (&event_funcs, sizeof (GdkDisplaySource));
  GdkDisplaySource *display_source = (GdkDisplaySource *)source;
  
  display_source->display = display;
  
  return source;
}
149

150 151 152 153 154
static gboolean
gdk_check_xpending (GdkDisplay *display)
{
  return XPending (GDK_DISPLAY_XDISPLAY (display));
}
155

156 157 158 159
/*********************************************
 * Functions for maintaining the event queue *
 *********************************************/

160 161 162 163 164 165 166 167 168 169 170 171
void
_gdk_x11_events_init_screen (GdkScreen *screen)
{
  GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
  
  screen_x11->xsettings_client = xsettings_client_new (screen_x11->xdisplay,
						       screen_x11->screen_num,
						       gdk_xsettings_notify_cb,
						       gdk_xsettings_watch_cb,
						       screen);
}

172
void 
173
_gdk_events_init (GdkDisplay *display)
174
{
175
  GSource *source;
176 177
  GdkDisplaySource *display_source;
  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
178
  
179 180
  int connection_number = ConnectionNumber (display_x11->xdisplay);
  GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
181 182


183 184
  source = gdk_display_source_new (display);
  display_source = (GdkDisplaySource*) source;
185 186
  g_source_set_priority (source, GDK_PRIORITY_EVENTS);
  
187 188
  display_source->event_poll_fd.fd = connection_number;
  display_source->event_poll_fd.events = G_IO_IN;
189
  
190
  g_source_add_poll (source, &display_source->event_poll_fd);
191 192
  g_source_set_can_recurse (source, TRUE);
  g_source_attach (source, NULL);
193

194 195 196 197 198 199 200
  display_sources = g_list_prepend (display_sources,display_source);

  gdk_display_add_client_message_filter (
	display,
	gdk_atom_intern ("WM_PROTOCOLS", FALSE), 
	gdk_wm_protocols_filter,   
	NULL);
201

202
  _gdk_x11_events_init_screen (display_x11->default_screen);
203 204 205
}


206 207 208 209 210 211 212
/**
 * gdk_events_pending:
 * 
 * Checks if any events are ready to be processed for any display.
 * 
 * Return value:  %TRUE if any events are pending.
 **/
213
gboolean
214 215
gdk_events_pending (void)
{
216
  GList *tmp_list;
217

218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
  for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
    {
      GdkDisplaySource *tmp_source = tmp_list->data;
      GdkDisplay *display = tmp_source->display;
      
      if (_gdk_event_queue_find_first (display))
	return TRUE;
    }

  for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
    {
      GdkDisplaySource *tmp_source = tmp_list->data;
      GdkDisplay *display = tmp_source->display;
      
      if (gdk_check_xpending (display))
	return TRUE;
    }
  
  return FALSE;
}
238 239

static Bool
240 241 242
graphics_expose_predicate (Display  *display,
			   XEvent   *xevent,
			   XPointer  arg)
243
{
244
  if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
245 246
      (xevent->xany.type == GraphicsExpose ||
       xevent->xany.type == NoExpose))
247 248 249 250 251
    return True;
  else
    return False;
}

252 253 254 255 256 257 258 259 260 261 262
/**
 * gdk_event_get_graphics_expose:
 * @window: the #GdkWindow to wait for the events for.
 * 
 * Waits for a GraphicsExpose or NoExpose event from the X server.
 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
 * GraphicsExpose events are handled before the widget is scrolled.
 *
 * Return value:  a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
 * NoExpose event was received.
 **/
263
GdkEvent*
264 265 266 267 268 269 270
gdk_event_get_graphics_expose (GdkWindow *window)
{
  XEvent xevent;
  GdkEvent *event;
  
  g_return_val_if_fail (window != NULL, NULL);
  
271 272
  XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent, 
	    graphics_expose_predicate, (XPointer) window);
273 274 275
  
  if (xevent.xany.type == GraphicsExpose)
    {
276
      event = _gdk_event_new ();
277
      
278 279
      if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
			       &xevent, TRUE))
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
	return event;
      else
	gdk_event_free (event);
    }
  
  return NULL;	
}

static gint
gdk_event_apply_filters (XEvent *xevent,
			 GdkEvent *event,
			 GList *filters)
{
  GList *tmp_list;
  GdkFilterReturn result;
  
  tmp_list = filters;
  
  while (tmp_list)
    {
300
      GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
301
      
302 303
      tmp_list = tmp_list->next;
      result = filter->function (xevent, event, filter->data);
304 305 306 307 308 309 310
      if (result !=  GDK_FILTER_CONTINUE)
	return result;
    }
  
  return GDK_FILTER_CONTINUE;
}

311 312 313 314 315 316 317 318 319 320 321 322
/**
 * gdk_display_add_client_message_filter:
 * @display: a #GdkDisplay for which this message filter applies
 * @message_type: the type of ClientMessage events to receive.
 *   This will be checked against the @message_type field 
 *   of the XClientMessage event struct.
 * @func: the function to call to process the event.
 * @data: user data to pass to @func.
 *
 * Adds a filter to be called when X ClientMessage events are received.
 *
 **/ 
323
void 
324 325 326 327
gdk_display_add_client_message_filter (GdkDisplay   *display,
				       GdkAtom       message_type,
				       GdkFilterFunc func,
				       gpointer      data)
328
{
329 330 331
  GdkClientFilter *filter;
  g_return_if_fail (GDK_IS_DISPLAY (display));
  filter = g_new (GdkClientFilter, 1);
332 333 334 335 336

  filter->type = message_type;
  filter->function = func;
  filter->data = data;
  
337 338 339
  GDK_DISPLAY_X11(display)->client_filters = 
    g_list_prepend (GDK_DISPLAY_X11 (display)->client_filters,
		    filter);
340 341
}

342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
/**
 * gdk_add_client_message_filter:
 * @message_type: the type of ClientMessage events to receive. This will be
 *     checked against the <structfield>message_type</structfield> field of the
 *     XClientMessage event struct.
 * @func: the function to call to process the event.
 * @data: user data to pass to @func. 
 * 
 * Adds a filter to the default display to be called when X ClientMessage events
 * are received. See gdk_display_add_client_message_filter().
 **/
void 
gdk_add_client_message_filter (GdkAtom       message_type,
			       GdkFilterFunc func,
			       gpointer      data)
{
  gdk_display_add_client_message_filter (gdk_get_default_display (),
					 message_type, func, data);
}
Havoc Pennington's avatar
Havoc Pennington committed
361 362 363 364 365 366 367 368

static void
gdk_check_wm_state_changed (GdkWindow *window)
{  
  Atom type;
  gint format;
  gulong nitems;
  gulong bytes_after;
369
  Atom *atoms = NULL;
Havoc Pennington's avatar
Havoc Pennington committed
370 371 372
  gulong i;
  gboolean found_sticky, found_maxvert, found_maxhorz;
  GdkWindowState old_state;
373
  GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
Havoc Pennington's avatar
Havoc Pennington committed
374 375 376 377
  
  if (GDK_WINDOW_DESTROYED (window))
    return;
  
378 379 380
  found_sticky = FALSE;
  found_maxvert = FALSE;
  found_maxhorz = FALSE;
Havoc Pennington's avatar
Havoc Pennington committed
381 382
  
  XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
383 384
		      gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
		      0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
Havoc Pennington's avatar
Havoc Pennington committed
385 386 387 388
		      &bytes_after, (guchar **)&atoms);

  if (type != None)
    {
389 390 391
      Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
      Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
      Atom maxhorz_atom	= gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
Havoc Pennington's avatar
Havoc Pennington committed
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416

      i = 0;
      while (i < nitems)
        {
          if (atoms[i] == sticky_atom)
            found_sticky = TRUE;
          else if (atoms[i] == maxvert_atom)
            found_maxvert = TRUE;
          else if (atoms[i] == maxhorz_atom)
            found_maxhorz = TRUE;

          ++i;
        }

      XFree (atoms);
    }

  /* For found_sticky to remain TRUE, we have to also be on desktop
   * 0xFFFFFFFF
   */

  if (found_sticky)
    {
      gulong *desktop;
      
417 418 419 420 421 422
      XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), 
			  GDK_WINDOW_XID (window),
                          gdk_x11_get_xatom_by_name_for_display 
			  (display, "_NET_WM_DESKTOP"),
			  0, G_MAXLONG, False, XA_CARDINAL, &type, 
			  &format, &nitems,
Havoc Pennington's avatar
Havoc Pennington committed
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
                          &bytes_after, (guchar **)&desktop);

      if (type != None)
        {
          if (*desktop != 0xFFFFFFFF)
            found_sticky = FALSE;
          XFree (desktop);
        }
    }
          
  old_state = gdk_window_get_state (window);

  if (old_state & GDK_WINDOW_STATE_STICKY)
    {
      if (!found_sticky)
        gdk_synthesize_window_state (window,
                                     GDK_WINDOW_STATE_STICKY,
                                     0);
    }
  else
    {
      if (found_sticky)
        gdk_synthesize_window_state (window,
                                     0,
                                     GDK_WINDOW_STATE_STICKY);
    }

  /* Our "maximized" means both vertical and horizontal; if only one,
   * we don't expose that via GDK
   */
  if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
    {
      if (!(found_maxvert && found_maxhorz))
        gdk_synthesize_window_state (window,
                                     GDK_WINDOW_STATE_MAXIMIZED,
                                     0);
    }
  else
    {
      if (found_maxvert && found_maxhorz)
        gdk_synthesize_window_state (window,
                                     0,
                                     GDK_WINDOW_STATE_MAXIMIZED);
    }
}

469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
#define HAS_FOCUS(window_impl)                           \
  ((window_impl)->has_focus || (window_impl)->has_pointer_focus)

static void
generate_focus_event (GdkWindow *window,
		      gboolean   in)
{
  GdkEvent event;
  
  event.type = GDK_FOCUS_CHANGE;
  event.focus_change.window = window;
  event.focus_change.send_event = FALSE;
  event.focus_change.in = in;
  
  gdk_event_put (&event);
}

486 487 488 489 490
static gboolean
gdk_event_translate (GdkDisplay *display,
		     GdkEvent   *event,
		     XEvent     *xevent,
		     gboolean    return_exposes)
491 492 493
{
  
  GdkWindow *window;
494
  GdkWindowObject *window_private;
495
  GdkWindowImplX11 *window_impl = NULL;
496 497 498 499 500
  static XComposeStatus compose;
  KeySym keysym;
  int charcount;
  char buf[16];
  gint return_val;
501
  gint xoffset, yoffset;
502 503 504
  GdkScreen *screen = NULL;
  GdkScreenX11 *screen_x11 = NULL;
  GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
505 506
  
  return_val = FALSE;
507 508 509 510 511

  /* init these, since the done: block uses them */
  window = NULL;
  window_private = NULL;
  event->any.window = NULL;
512

513
  if (_gdk_default_filters)
514 515 516 517
    {
      /* Apply global filters */
      GdkFilterReturn result;
      result = gdk_event_apply_filters (xevent, event,
518
                                        _gdk_default_filters);
519 520 521 522 523 524 525 526 527 528 529 530 531
      
      if (result != GDK_FILTER_CONTINUE)
        {
          return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
          goto done;
        }
    }  

   /* We handle events with window=None
    *  specially - they are generated by XFree86's XInput under
    *  some circumstances. This handling for obvious reasons
    * goes before we bother to lookup the event window.
    */
532
  
533
  if (xevent->xany.window == None)
534
    {
535
      return_val = _gdk_input_window_none_event (event, xevent);
536 537 538 539 540 541
      
      if (return_val >= 0)	/* was handled */
	return return_val;
      else
	return_val = FALSE;
    }
542 543

  /* Find the GdkWindow that this event occurred in. */
544
  
545
  window = gdk_window_lookup_for_display (display, xevent->xany.window);
546
  window_private = (GdkWindowObject *) window;
547 548 549 550 551 552 553

  if (window)
    {
      screen = GDK_WINDOW_SCREEN (window);
      screen_x11 = GDK_SCREEN_X11 (screen);
    }
    
554 555
  if (window != NULL)
    {
556 557 558 559 560 561 562 563
      /* Window may be a pixmap, so check its type.
       * (This check is probably too expensive unless
       *  GLib short-circuits an exact type match,
       *  which has been proposed)
       */
      if (GDK_IS_WINDOW (window))
        {
          window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
564
	  
565 566 567 568 569 570 571 572 573 574 575
          if (xevent->xany.window != GDK_WINDOW_XID (window))
            {
              g_assert (xevent->xany.window == window_impl->focus_window);
              
              switch (xevent->type)
                {
                case KeyPress:
                case KeyRelease:
                  xevent->xany.window = GDK_WINDOW_XID (window);
                  break;
                default:
576
                  return FALSE;
577 578 579
                }
            }
        }
580

581
      g_object_ref (G_OBJECT (window));
582 583
    }

584
  event->any.window = window;
585
  event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
586
  
587
  if (window_private && GDK_WINDOW_DESTROYED (window))
588 589
    {
      if (xevent->type != DestroyNotify)
590 591 592 593
	{
	  return_val = FALSE;
	  goto done;
	}
594
    }
595
  else if (window_private)
596
    {
597
      /* Apply per-window filters */
598 599
      GdkFilterReturn result;
      result = gdk_event_apply_filters (xevent, event,
600
					window_private->filters);
601 602 603
      
      if (result != GDK_FILTER_CONTINUE)
	{
Owen Taylor's avatar
Owen Taylor committed
604 605
	  return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
	  goto done;
606 607
	}
    }
608
      
609 610
  if (screen_x11 && screen_x11->wmspec_check_window != None &&
      xevent->xany.window == screen_x11->wmspec_check_window)
611 612
    {
      if (xevent->type == DestroyNotify)
613
        screen_x11->wmspec_check_window = None;
614 615 616 617 618
      
      /* Eat events on this window unless someone had wrapped
       * it as a foreign window
       */
      if (window == NULL)
619 620 621 622
	{
	  return_val = FALSE;
	  goto done;
	}
623
    }
624

625 626 627 628
  if (window &&
      (xevent->xany.type == MotionNotify ||
       xevent->xany.type == ButtonRelease))
    {
629 630 631 632 633
      if (_gdk_moveresize_handle_event (xevent))
	{
          return_val = FALSE;
          goto done;
        }
634 635
    }
  
636 637 638 639 640 641 642 643 644
  /* We do a "manual" conversion of the XEvent to a
   *  GdkEvent. The structures are mostly the same so
   *  the conversion is fairly straightforward. We also
   *  optionally print debugging info regarding events
   *  received.
   */

  return_val = TRUE;

645 646 647 648 649 650 651 652 653
  if (window)
    {
      _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
    }
  else
    {
      xoffset = 0;
      yoffset = 0;
    }
654

655 656 657
  switch (xevent->type)
    {
    case KeyPress:
658 659 660 661 662 663
      if (window_private == NULL)
        {
          return_val = FALSE;
          break;
        }
      
664 665
      /* Lookup the string corresponding to the given keysym.
       */
666

667 668 669
      charcount = XLookupString (&xevent->xkey, buf, 16,
				 &keysym, &compose);
      event->key.keyval = keysym;
Havoc Pennington's avatar
Havoc Pennington committed
670
      event->key.hardware_keycode = xevent->xkey.keycode;
671 672 673 674 675 676 677
      
      if (charcount > 0 && buf[charcount-1] == '\0')
	charcount --;
      else
	buf[charcount] = '\0';
      
#ifdef G_ENABLE_DEBUG
678
      if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
679 680 681 682 683 684 685 686 687 688
	{
	  g_message ("key press:\twindow: %ld  key: %12s  %d",
		     xevent->xkey.window,
		     event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
		     event->key.keyval);
	  if (charcount > 0)
	    g_message ("\t\tlength: %4d string: \"%s\"",
		       charcount, buf);
	}
#endif /* G_ENABLE_DEBUG */
Havoc Pennington's avatar
Havoc Pennington committed
689

690 691 692 693 694 695
      event->key.type = GDK_KEY_PRESS;
      event->key.window = window;
      event->key.time = xevent->xkey.time;
      event->key.state = (GdkModifierType) xevent->xkey.state;
      event->key.string = g_strdup (buf);
      event->key.length = charcount;
Havoc Pennington's avatar
Havoc Pennington committed
696

697 698 699 700
      /* bits 13 and 14 in the "state" field are the keyboard group */
#define KEYBOARD_GROUP_SHIFT 13
#define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
      
701
      event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
702 703 704 705
      
      break;
      
    case KeyRelease:
706 707 708 709 710 711
      if (window_private == NULL)
        {
          return_val = FALSE;
          break;
        }
      
712 713
      /* Lookup the string corresponding to the given keysym.
       */
714 715 716 717 718 719

      /* Emulate detectable auto-repeat by checking to see
       * if the next event is a key press with the same
       * keycode and timestamp, and if so, ignoring the event.
       */

720
      if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
721 722 723
	{
	  XEvent next_event;

724
	  XPeekEvent (xevent->xkey.display, &next_event);
725 726 727 728 729 730 731

	  if (next_event.type == KeyPress &&
	      next_event.xkey.keycode == xevent->xkey.keycode &&
	      next_event.xkey.time == xevent->xkey.time)
	    break;
	}
      
732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
      keysym = GDK_VoidSymbol;
      charcount = XLookupString (&xevent->xkey, buf, 16,
				 &keysym, &compose);
      event->key.keyval = keysym;      
      
      GDK_NOTE (EVENTS, 
		g_message ("key release:\t\twindow: %ld	 key: %12s  %d",
			   xevent->xkey.window,
			   XKeysymToString (event->key.keyval),
			   event->key.keyval));
      
      event->key.type = GDK_KEY_RELEASE;
      event->key.window = window;
      event->key.time = xevent->xkey.time;
      event->key.state = (GdkModifierType) xevent->xkey.state;
      event->key.length = 0;
      event->key.string = NULL;
      
750 751
      event->key.group = (xevent->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;

752 753 754 755 756 757 758 759 760
      break;
      
    case ButtonPress:
      GDK_NOTE (EVENTS, 
		g_message ("button press:\t\twindow: %ld  x,y: %d %d  button: %d",
			   xevent->xbutton.window,
			   xevent->xbutton.x, xevent->xbutton.y,
			   xevent->xbutton.button));
      
761 762
      if (window_private == NULL || 
	  ((window_private->extension_events != 0) &&
763
           display_x11->input_ignore_core))
764 765 766 767 768
	{
	  return_val = FALSE;
	  break;
	}
      
769 770
      /* If we get a ButtonPress event where the button is 4 or 5,
	 it's a Scroll event */
771 772 773 774 775 776
      switch (xevent->xbutton.button)
        {
        case 4: /* up */
        case 5: /* down */
        case 6: /* left */
        case 7: /* right */
777
	  event->scroll.type = GDK_SCROLL;
778 779 780 781 782 783 784 785 786 787

          if (xevent->xbutton.button == 4)
            event->scroll.direction = GDK_SCROLL_UP;
          else if (xevent->xbutton.button == 5)
            event->scroll.direction = GDK_SCROLL_DOWN;
          else if (xevent->xbutton.button == 6)
            event->scroll.direction = GDK_SCROLL_LEFT;
          else
            event->scroll.direction = GDK_SCROLL_RIGHT;

788
	  event->scroll.window = window;
789
	  event->scroll.time = xevent->xbutton.time;
790 791
	  event->scroll.x = xevent->xbutton.x + xoffset;
	  event->scroll.y = xevent->xbutton.y + yoffset;
792 793 794
	  event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
	  event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
	  event->scroll.state = (GdkModifierType) xevent->xbutton.state;
795
	  event->scroll.device = _gdk_core_pointer;
796 797 798
          break;
          
        default:
799 800 801
	  event->button.type = GDK_BUTTON_PRESS;
	  event->button.window = window;
	  event->button.time = xevent->xbutton.time;
802 803
	  event->button.x = xevent->xbutton.x + xoffset;
	  event->button.y = xevent->xbutton.y + yoffset;
804 805
	  event->button.x_root = (gfloat)xevent->xbutton.x_root;
	  event->button.y_root = (gfloat)xevent->xbutton.y_root;
806
	  event->button.axes = NULL;
807 808
	  event->button.state = (GdkModifierType) xevent->xbutton.state;
	  event->button.button = xevent->xbutton.button;
809
	  event->button.device = _gdk_core_pointer;
810
	  
811
	  _gdk_event_button_generate (display, event);
812
          break;
813
	}
814 815 816 817 818 819 820 821 822 823

      break;
      
    case ButtonRelease:
      GDK_NOTE (EVENTS, 
		g_message ("button release:\twindow: %ld  x,y: %d %d  button: %d",
			   xevent->xbutton.window,
			   xevent->xbutton.x, xevent->xbutton.y,
			   xevent->xbutton.button));
      
824 825
      if (window_private == NULL ||
	  ((window_private->extension_events != 0) &&
826
           display_x11->input_ignore_core))
827 828 829 830 831
	{
	  return_val = FALSE;
	  break;
	}
      
832
      /* We treat button presses as scroll wheel events, so ignore the release */
833 834
      if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
          xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
835 836 837 838 839
	{
	  return_val = FALSE;
	  break;
	}

840 841 842
      event->button.type = GDK_BUTTON_RELEASE;
      event->button.window = window;
      event->button.time = xevent->xbutton.time;
843 844
      event->button.x = xevent->xbutton.x + xoffset;
      event->button.y = xevent->xbutton.y + yoffset;
845 846
      event->button.x_root = (gfloat)xevent->xbutton.x_root;
      event->button.y_root = (gfloat)xevent->xbutton.y_root;
847
      event->button.axes = NULL;
848 849
      event->button.state = (GdkModifierType) xevent->xbutton.state;
      event->button.button = xevent->xbutton.button;
850
      event->button.device = _gdk_core_pointer;
851 852 853 854 855 856 857 858 859 860
      
      break;
      
    case MotionNotify:
      GDK_NOTE (EVENTS,
		g_message ("motion notify:\t\twindow: %ld  x,y: %d %d  hint: %s", 
			   xevent->xmotion.window,
			   xevent->xmotion.x, xevent->xmotion.y,
			   (xevent->xmotion.is_hint) ? "true" : "false"));
      
861 862
      if (window_private == NULL ||
	  ((window_private->extension_events != 0) &&
863
           display_x11->input_ignore_core))
864 865 866 867 868 869 870 871
	{
	  return_val = FALSE;
	  break;
	}
      
      event->motion.type = GDK_MOTION_NOTIFY;
      event->motion.window = window;
      event->motion.time = xevent->xmotion.time;
872 873
      event->motion.x = xevent->xmotion.x + xoffset;
      event->motion.y = xevent->xmotion.y + yoffset;
874 875
      event->motion.x_root = (gfloat)xevent->xmotion.x_root;
      event->motion.y_root = (gfloat)xevent->xmotion.y_root;
876
      event->motion.axes = NULL;
877 878
      event->motion.state = (GdkModifierType) xevent->xmotion.state;
      event->motion.is_hint = xevent->xmotion.is_hint;
879
      event->motion.device = _gdk_core_pointer;
880 881 882 883 884 885 886 887 888
      
      break;
      
    case EnterNotify:
      GDK_NOTE (EVENTS,
		g_message ("enter notify:\t\twindow: %ld  detail: %d subwin: %ld",
			   xevent->xcrossing.window,
			   xevent->xcrossing.detail,
			   xevent->xcrossing.subwindow));
889 890 891 892 893 894 895
 
      if (window_private == NULL)
        {
          return_val = FALSE;
          break;
        }
      
896
      /* Handle focusing (in the case where no window manager is running */
897 898
      if (window &&
	  GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
899 900 901 902 903 904 905 906 907 908 909
	  xevent->xcrossing.detail != NotifyInferior &&
	  xevent->xcrossing.focus && !window_impl->has_focus)
	{
	  gboolean had_focus = HAS_FOCUS (window_impl);
	  
	  window_impl->has_pointer_focus = TRUE;

	  if (HAS_FOCUS (window_impl) != had_focus)
	    generate_focus_event (window, TRUE);
	}

910 911
      /* Tell XInput stuff about it if appropriate */
      if (window_private &&
912
	  !GDK_WINDOW_DESTROYED (window) &&
913 914
	  window_private->extension_events != 0)
	_gdk_input_enter_event (&xevent->xcrossing, window);
915 916 917 918 919 920 921 922
      
      event->crossing.type = GDK_ENTER_NOTIFY;
      event->crossing.window = window;
      
      /* If the subwindow field of the XEvent is non-NULL, then
       *  lookup the corresponding GdkWindow.
       */
      if (xevent->xcrossing.subwindow != None)
923
	event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
924 925 926 927
      else
	event->crossing.subwindow = NULL;
      
      event->crossing.time = xevent->xcrossing.time;
928 929
      event->crossing.x = xevent->xcrossing.x + xoffset;
      event->crossing.y = xevent->xcrossing.y + yoffset;
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
      event->crossing.x_root = xevent->xcrossing.x_root;
      event->crossing.y_root = xevent->xcrossing.y_root;
      
      /* Translate the crossing mode into Gdk terms.
       */
      switch (xevent->xcrossing.mode)
	{
	case NotifyNormal:
	  event->crossing.mode = GDK_CROSSING_NORMAL;
	  break;
	case NotifyGrab:
	  event->crossing.mode = GDK_CROSSING_GRAB;
	  break;
	case NotifyUngrab:
	  event->crossing.mode = GDK_CROSSING_UNGRAB;
	  break;
	};
      
      /* Translate the crossing detail into Gdk terms.
       */
      switch (xevent->xcrossing.detail)
	{
	case NotifyInferior:
	  event->crossing.detail = GDK_NOTIFY_INFERIOR;
	  break;
	case NotifyAncestor:
	  event->crossing.detail = GDK_NOTIFY_ANCESTOR;
	  break;
	case NotifyVirtual:
	  event->crossing.detail = GDK_NOTIFY_VIRTUAL;
	  break;
	case NotifyNonlinear:
	  event->crossing.detail = GDK_NOTIFY_NONLINEAR;
	  break;
	case NotifyNonlinearVirtual:
	  event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
	  break;
	default:
	  event->crossing.detail = GDK_NOTIFY_UNKNOWN;
	  break;
	}
      
      event->crossing.focus = xevent->xcrossing.focus;
      event->crossing.state = xevent->xcrossing.state;
  
      break;
      
    case LeaveNotify:
      GDK_NOTE (EVENTS, 
		g_message ("leave notify:\t\twindow: %ld  detail: %d subwin: %ld",
			   xevent->xcrossing.window,
			   xevent->xcrossing.detail, xevent->xcrossing.subwindow));
982 983 984 985 986 987

      if (window_private == NULL)
        {
          return_val = FALSE;
          break;
        }
988
      
989
      /* Handle focusing (in the case where no window manager is running */
990 991
      if (window &&
	  GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
992 993 994 995 996 997 998 999 1000 1001 1002
	  xevent->xcrossing.detail != NotifyInferior &&
	  xevent->xcrossing.focus && !window_impl->has_focus)
	{
	  gboolean had_focus = HAS_FOCUS (window_impl);
	  
	  window_impl->has_pointer_focus = FALSE;

	  if (HAS_FOCUS (window_impl) != had_focus)
	    generate_focus_event (window, FALSE);
	}

1003 1004 1005 1006 1007 1008 1009
      event->crossing.type = GDK_LEAVE_NOTIFY;
      event->crossing.window = window;
      
      /* If the subwindow field of the XEvent is non-NULL, then
       *  lookup the corresponding GdkWindow.
       */
      if (xevent->xcrossing.subwindow != None)
1010
	event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1011 1012 1013 1014
      else
	event->crossing.subwindow = NULL;
      
      event->crossing.time = xevent->xcrossing.time;
1015 1016
      event->crossing.x = xevent->xcrossing.x + xoffset;
      event->crossing.y = xevent->xcrossing.y + yoffset;
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
      event->crossing.x_root = xevent->xcrossing.x_root;
      event->crossing.y_root = xevent->xcrossing.y_root;
      
      /* Translate the crossing mode into Gdk terms.
       */
      switch (xevent->xcrossing.mode)
	{
	case NotifyNormal:
	  event->crossing.mode = GDK_CROSSING_NORMAL;
	  break;
	case NotifyGrab:
	  event->crossing.mode = GDK_CROSSING_GRAB;
	  break;
	case NotifyUngrab:
	  event->crossing.mode = GDK_CROSSING_UNGRAB;
	  break;
	};
      
      /* Translate the crossing detail into Gdk terms.
       */
      switch (xevent->xcrossing.detail)
	{
	case NotifyInferior:
	  event->crossing.detail = GDK_NOTIFY_INFERIOR;
	  break;
	case NotifyAncestor:
	  event->crossing.detail = GDK_NOTIFY_ANCESTOR;
	  break;
	case NotifyVirtual:
	  event->crossing.detail = GDK_NOTIFY_VIRTUAL;
	  break;
	case NotifyNonlinear:
	  event->crossing.detail = GDK_NOTIFY_NONLINEAR;
	  break;
	case NotifyNonlinearVirtual:
	  event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
	  break;
	default:
	  event->crossing.detail = GDK_NOTIFY_UNKNOWN;
	  break;
	}
      
      event->crossing.focus = xevent->xcrossing.focus;
      event->crossing.state = xevent->xcrossing.state;
      
      break;
      
      /* We only care about focus events that indicate that _this_
       * window (not a ancestor or child) got or lost the focus
       */
1067 1068 1069 1070
    case FocusIn:
      GDK_NOTE (EVENTS,
		g_message ("focus in:\t\twindow: %ld", xevent->xfocus.window));
      
1071
      if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1072
	{
1073
	  gboolean had_focus = HAS_FOCUS (window_impl);
1074
	  
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
	  switch (xevent->xfocus.detail)
	    {
	    case NotifyAncestor:
	    case NotifyNonlinear:
	    case NotifyVirtual:
	    case NotifyNonlinearVirtual:
	      window_impl->has_focus = TRUE;
	      break;
	    case NotifyPointer:
	      window_impl->has_pointer_focus = TRUE;
	      break;
	    case NotifyInferior:
	    case NotifyPointerRoot:
	    case NotifyDetailNone:
	      break;
	    }

	  if (HAS_FOCUS (window_impl) != had_focus)
	    generate_focus_event (window, TRUE);
	}
      break;
    case FocusOut:
      GDK_NOTE (EVENTS,
		g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));

1100
      if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
	{
	  gboolean had_focus = HAS_FOCUS (window_impl);
	    
	  switch (xevent->xfocus.detail)
	    {
	    case NotifyAncestor:
	    case NotifyNonlinear:
	    case NotifyVirtual:
	    case NotifyNonlinearVirtual:
	      window_impl->has_focus = FALSE;
	      break;
	    case NotifyPointer:
	      window_impl->has_pointer_focus = FALSE;
	    break;
	    case NotifyInferior:
	    case NotifyPointerRoot:
	    case NotifyDetailNone:
	      break;
	    }

	  if (HAS_FOCUS (window_impl) != had_focus)
	    generate_focus_event (window, FALSE);
	}
      break;

#if 0      
1127 1128 1129 1130 1131 1132
 	  /* gdk_keyboard_grab() causes following events. These events confuse
 	   * the XIM focus, so ignore them.
 	   */
 	  if (xevent->xfocus.mode == NotifyGrab ||
 	      xevent->xfocus.mode == NotifyUngrab)
 	    break;
1133
#endif
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144

    case KeymapNotify:
      GDK_NOTE (EVENTS,
		g_message ("keymap notify"));

      /* Not currently handled */
      return_val = FALSE;
      break;
      
    case Expose:
      GDK_NOTE (EVENTS,
1145
		g_message ("expose:\t\twindow: %ld  %d	x,y: %d %d  w,h: %d %d%s",
1146 1147
			   xevent->xexpose.window, xevent->xexpose.count,
			   xevent->xexpose.x, xevent->xexpose.y,
1148 1149
			   xevent->xexpose.width, xevent->xexpose.height,
			   event->any.send_event ? " (send)" : ""));
1150 1151 1152 1153 1154 1155 1156
      
      if (window_private == NULL)
        {
          return_val = FALSE;
          break;
        }
      
1157 1158 1159 1160 1161 1162 1163 1164
      {
	GdkRectangle expose_rect;

	expose_rect.x = xevent->xexpose.x + xoffset;
	expose_rect.y = xevent->xexpose.y + yoffset;
	expose_rect.width = xevent->xexpose.width;
	expose_rect.height = xevent->xexpose.height;

1165 1166 1167 1168
	if (return_exposes)
	  {
	    event->expose.type = GDK_EXPOSE;
	    event->expose.area = expose_rect;
1169
	    event->expose.region = gdk_region_rectangle (&expose_rect);
1170
	    event->expose.window = window;
1171
	    event->expose.count = xevent->xexpose.count;
1172 1173 1174 1175 1176 1177 1178 1179 1180

	    return_val = TRUE;
	  }
	else
	  {
	    _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
	    return_val = FALSE;
	  }
	
1181 1182 1183
	return_val = FALSE;
      }
	
1184 1185 1186
      break;
      
    case GraphicsExpose:
1187 1188 1189 1190 1191 1192
      {
	GdkRectangle expose_rect;

        GDK_NOTE (EVENTS,
		  g_message ("graphics expose:\tdrawable: %ld",
			     xevent->xgraphicsexpose.drawable));
1193 1194 1195 1196 1197 1198 1199
 
        if (window_private == NULL)
          {
            return_val = FALSE;
            break;
          }
        
1200 1201 1202 1203
	expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
	expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
	expose_rect.width = xevent->xgraphicsexpose.width;
	expose_rect.height = xevent->xgraphicsexpose.height;
1204 1205 1206 1207 1208
	    
	if (return_exposes)
	  {
	    event->expose.type = GDK_EXPOSE;
	    event->expose.area = expose_rect;
1209
	    event->expose.region = gdk_region_rectangle (&expose_rect);
1210
	    event->expose.window = window;
1211
	    event->expose.count = xevent->xgraphicsexpose.count;
1212

1213 1214 1215 1216 1217 1218 1219 1220 1221
	    return_val = TRUE;
	  }
	else
	  {
	    _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
	    
	    return_val = FALSE;
	  }
	
1222
      }
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236
      break;
      
    case NoExpose:
      GDK_NOTE (EVENTS,
		g_message ("no expose:\t\tdrawable: %ld",
			   xevent->xnoexpose.drawable));
      
      event->no_expose.type = GDK_NO_EXPOSE;
      event->no_expose.window = window;
      
      break;
      
    case VisibilityNotify:
#ifdef G_ENABLE_DEBUG
1237
      if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
	switch (xevent->xvisibility.state)
	  {
	  case VisibilityFullyObscured:
	    g_message ("visibility notify:\twindow: %ld	 none",
		       xevent->xvisibility.window);
	    break;
	  case VisibilityPartiallyObscured:
	    g_message ("visibility notify:\twindow: %ld	 partial",
		       xevent->xvisibility.window);
	    break;
	  case VisibilityUnobscured:
	    g_message ("visibility notify:\twindow: %ld	 full",
		       xevent->xvisibility.window);
	    break;
	  }
#endif /* G_ENABLE_DEBUG */
      
1255 1256 1257 1258 1259 1260
      if (window_private == NULL)
        {
          return_val = FALSE;
          break;
        }
      
1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
      event->visibility.type = GDK_VISIBILITY_NOTIFY;
      event->visibility.window = window;
      
      switch (xevent->xvisibility.state)
	{
	case VisibilityFullyObscured:
	  event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
	  break;
	  
	case VisibilityPartiallyObscured:
	  event->visibility.state = GDK_VISIBILITY_PARTIAL;
	  break;
	  
	case VisibilityUnobscured:
	  event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
	  break;
	}
      
      break;
      
    case CreateNotify:
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292
      GDK_NOTE (EVENTS,
		g_message ("create notify:\twindow: %ld  x,y: %d %d	w,h: %d %d  b-w: %d  parent: %ld	 ovr: %d",
			   xevent->xcreatewindow.window,
			   xevent->xcreatewindow.x,
			   xevent->xcreatewindow.y,
			   xevent->xcreatewindow.width,
			   xevent->xcreatewindow.height,
			   xevent->xcreatewindow.border_width,
			   xevent->xcreatewindow.parent,
			   xevent->xcreatewindow.override_redirect));
      /* not really handled */
1293 1294 1295 1296 1297 1298
      break;
      
    case DestroyNotify:
      GDK_NOTE (EVENTS,
		g_message ("destroy notify:\twindow: %ld",
			   xevent->xdestroywindow.window));
1299 1300 1301 1302 1303 1304 1305 1306 1307

      /* Ignore DestroyNotify from SubstructureNotifyMask */
      if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
	{
	  event->any.type = GDK_DESTROY;
	  event->any.window = window;
	  
	  return_val = window_private && !GDK_WINDOW_DESTROYED (window);
	  
1308
	  if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1309 1310 1311 1312
	    gdk_window_destroy_notify (window);
	}
      else
	return_val = FALSE;
1313
      
1314 1315 1316 1317 1318 1319 1320 1321
      break;
      
    case UnmapNotify:
      GDK_NOTE (EVENTS,
		g_message ("unmap notify:\t\twindow: %ld",
			   xevent->xmap.window));
      
      event->any.type = GDK_UNMAP;
Havoc Pennington's avatar
Havoc Pennington committed
1322 1323 1324 1325 1326 1327 1328
      event->any.window = window;      

      /* If we are shown (not withdrawn) and get an unmap, it means we
       * were iconified in the X sense. If we are withdrawn, and get
       * an unmap, it means we hid the window ourselves, so we
       * will have already flipped the iconified bit off.
       */
1329 1330 1331 1332 1333 1334
      if (window)
	{
	  if (GDK_WINDOW_IS_MAPPED (window))
	    gdk_synthesize_window_state (window,
					 0,
					 GDK_WINDOW_STATE_ICONIFIED);
1335

1336 1337
	  _gdk_xgrab_check_unmap (window, xevent->xany.serial);
	}
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347
      
      break;
      
    case MapNotify:
      GDK_NOTE (EVENTS,
		g_message ("map notify:\t\twindow: %ld",
			   xevent->xmap.window));
      
      event->any.type = GDK_MAP;
      event->any.window = window;
Havoc Pennington's avatar
Havoc Pennington committed
1348 1349

      /* Unset iconified if it was set */
1350
      if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
Havoc Pennington's avatar
Havoc Pennington committed
1351 1352 1353
        gdk_synthesize_window_state (window,
                                     GDK_WINDOW_STATE_ICONIFIED,
                                     0);
1354 1355 1356 1357 1358
      
      break;
      
    case ReparentNotify:
      GDK_NOTE (EVENTS,
1359 1360 1361 1362 1363 1364
		g_message ("reparent notify:\twindow: %ld  x,y: %d %d  parent: %ld	ovr: %d",
			   xevent->xreparent.window,
			   xevent->xreparent.x,
			   xevent->xreparent.y,
			   xevent->xreparent.parent,
			   xevent->xreparent.override_redirect));
1365 1366 1367 1368 1369 1370 1371

      /* Not currently handled */
      return_val = FALSE;
      break;
      
    case ConfigureNotify:
      GDK_NOTE (EVENTS,
1372
		g_message ("configure notify:\twindow: %ld  x,y: %d %d	w,h: %d %d  b-w: %d  above: %ld	 ovr: %d%s",
1373 1374 1375 1376 1377 1378 1379
			   xevent->xconfigure.window,
			   xevent->xconfigure.x,
			   xevent->xconfigure.y,
			   xevent->xconfigure.width,
			   xevent->xconfigure.height,
			   xevent->xconfigure.border_width,
			   xevent->xconfigure.above,
1380 1381 1382
			   xevent->xconfigure.override_redirect,
			   !window
			   ? " (discarding)"
1383
			   : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1384
			   ? " (discarding child)"
1385 1386
			   : xevent->xconfigure.event != xevent->xconfigure.window
			   ? " (discarding substructure)"
1387 1388
			   : ""));
      if (window &&
1389
	  xevent->xconfigure.event == xevent->xconfigure.window &&
1390
	  !GDK_WINDOW_DESTROYED (window) &&
1391 1392
	  (window_private->extension_events != 0))
	_gdk_input_configure_event (&xevent->xconfigure, window);
1393

Havoc Pennington's avatar
Havoc Pennington committed
1394
      if (!window ||
1395
	  xevent->xconfigure.event != xevent->xconfigure.window ||
Havoc Pennington's avatar
Havoc Pennington committed
1396 1397
          GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
          GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1398 1399 1400 1401 1402 1403 1404 1405
	return_val = FALSE;
      else
	{
	  event->configure.type = GDK_CONFIGURE;
	  event->configure.window = window;
	  event->configure.width = xevent->xconfigure.width;
	  event->configure.height = xevent->xconfigure.height;
	  
Havoc Pennington's avatar
Havoc Pennington committed
1406
	  if (!xevent->xconfigure.send_event && 
1407
	      !GDK_WINDOW_DESTROYED (window))
1408 1409 1410 1411
	    {
	      gint tx = 0;
	      gint ty = 0;
	      Window child_window = 0;
1412 1413

	      gdk_error_trap_push ();
1414 1415
	      if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
					 GDK_DRAWABLE_XID (window),
1416
					 screen_x11->xroot_window,
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428
					 0, 0,
					 &tx, &ty,
					 &child_window))
		{
		  if (!gdk_error_trap_pop ())
		    {
		      event->configure.x = tx;
		      event->configure.y = ty;
		    }
		}
	      else
		gdk_error_trap_pop ();
1429 1430 1431 1432 1433 1434 1435 1436
	    }
	  else
	    {
	      event->configure.x = xevent->xconfigure.x;
	      event->configure.y = xevent->xconfigure.y;
	    }
	  window_private->x = event->configure.x;
	  window_private->y = event->configure.y;
1437 1438
	  GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
	  GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
Owen Taylor's avatar
Owen Taylor committed
1439 1440 1441 1442
	  if (window_private->resize_count >= 1)
	    {
	      window_private->resize_count -= 1;

1443 1444
	      if (window_private->resize_count == 0)
		_gdk_moveresize_configure_done (display, window);
Owen Taylor's avatar
Owen Taylor committed
1445
	    }
1446 1447 1448 1449 1450
	}
      break;
      
    case PropertyNotify:
      GDK_NOTE (EVENTS,
1451 1452 1453
		g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
			   xevent->xproperty.window,
			   xevent->xproperty.atom,
1454
			   "\"",
1455
			   gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1456
			   "\""));
1457 1458 1459

      if (window_private == NULL)
        {
1460
	  return_val = FALSE;
1461 1462
          break;
        }
1463
      
1464 1465
      if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE") ||
	  xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
Havoc Pennington's avatar
Havoc Pennington committed
1466 1467
        {
          /* If window state changed, then synthesize those events. */
1468
          gdk_check_wm_state_changed (window);
Havoc Pennington's avatar
Havoc Pennington committed
1469
        }
1470
      
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
      if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK) 
	{
	  event->property.type = GDK_PROPERTY_NOTIFY;
	  event->property.window = window;
	  event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
	  event->property.time = xevent->xproperty.time;
	  event->property.state = xevent->xproperty.state;
	}
      else
	return_val = FALSE;

1482 1483 1484 1485 1486