events.c 59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */

/*
 * Copyright (C) 2001 Havoc Pennington
 * Copyright (C) 2002, 2003, 2004 Red Hat, Inc.
 * Copyright (C) 2003, 2004 Rob Adams
 * Copyright (C) 2004-2006 Elijah Newren
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include "config.h"
#include "x11/events.h"

#include <X11/Xatom.h>
#include <X11/extensions/Xdamage.h>
#include <X11/extensions/shape.h>

#include <meta/errors.h>
31
#include "meta/meta-backend.h"
32 33 34 35
#include "bell.h"
#include "display-private.h"
#include "window-private.h"
#include "workspace-private.h"
36
#include "backends/x11/meta-backend-x11.h"
37
#include "x11/meta-x11-display-private.h"
38 39
#include "x11/window-x11.h"
#include "x11/xprops.h"
40 41

#ifdef HAVE_WAYLAND
42 43
#include "wayland/meta-xwayland.h"
#include "wayland/meta-wayland-private.h"
44
#include "wayland/meta-xwayland-private.h"
45
#endif
46 47 48 49 50 51

static XIEvent *
get_input_event (MetaDisplay *display,
                 XEvent      *event)
{
  if (event->type == GenericEvent &&
52
      event->xcookie.extension == display->x11_display->xinput_opcode)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
    {
      XIEvent *input_event;

      /* NB: GDK event filters already have generic events
       * allocated, so no need to do XGetEventData() on our own
       */
      input_event = (XIEvent *) event->xcookie.data;

      switch (input_event->evtype)
        {
        case XI_Motion:
        case XI_ButtonPress:
        case XI_ButtonRelease:
          if (((XIDeviceEvent *) input_event)->deviceid == META_VIRTUAL_CORE_POINTER_ID)
            return input_event;
          break;
        case XI_KeyPress:
        case XI_KeyRelease:
          if (((XIDeviceEvent *) input_event)->deviceid == META_VIRTUAL_CORE_KEYBOARD_ID)
            return input_event;
          break;
        case XI_FocusIn:
        case XI_FocusOut:
          if (((XIEnterEvent *) input_event)->deviceid == META_VIRTUAL_CORE_KEYBOARD_ID)
            return input_event;
          break;
        case XI_Enter:
        case XI_Leave:
          if (((XIEnterEvent *) input_event)->deviceid == META_VIRTUAL_CORE_POINTER_ID)
            return input_event;
          break;
#ifdef HAVE_XI23
        case XI_BarrierHit:
        case XI_BarrierLeave:
          if (((XIBarrierEvent *) input_event)->deviceid == META_VIRTUAL_CORE_POINTER_ID)
            return input_event;
          break;
#endif /* HAVE_XI23 */
        default:
          break;
        }
    }

  return NULL;
}

static Window
xievent_get_modified_window (MetaDisplay *display,
                             XIEvent *input_event)
{
  switch (input_event->evtype)
    {
    case XI_Motion:
    case XI_ButtonPress:
    case XI_ButtonRelease:
    case XI_KeyPress:
    case XI_KeyRelease:
      return ((XIDeviceEvent *) input_event)->event;
    case XI_FocusIn:
    case XI_FocusOut:
    case XI_Enter:
    case XI_Leave:
      return ((XIEnterEvent *) input_event)->event;
#ifdef HAVE_XI23
    case XI_BarrierHit:
    case XI_BarrierLeave:
      return ((XIBarrierEvent *) input_event)->event;
#endif /* HAVE_XI23 */
    }

  return None;
}

/* Return the window this has to do with, if any, rather
 * than the frame or root window that was selecting
 * for substructure
 */
static Window
event_get_modified_window (MetaDisplay *display,
                           XEvent *event)
{
  XIEvent *input_event = get_input_event (display, event);

  if (input_event)
    return xievent_get_modified_window (display, input_event);

  switch (event->type)
    {
    case KeymapNotify:
    case Expose:
    case GraphicsExpose:
    case NoExpose:
    case VisibilityNotify:
    case ResizeRequest:
    case PropertyNotify:
    case SelectionClear:
    case SelectionRequest:
    case SelectionNotify:
    case ColormapNotify:
    case ClientMessage:
      return event->xany.window;

    case CreateNotify:
      return event->xcreatewindow.window;

    case DestroyNotify:
      return event->xdestroywindow.window;

    case UnmapNotify:
      return event->xunmap.window;

    case MapNotify:
      return event->xmap.window;

    case MapRequest:
      return event->xmaprequest.window;

    case ReparentNotify:
     return event->xreparent.window;

    case ConfigureNotify:
      return event->xconfigure.window;

    case ConfigureRequest:
      return event->xconfigurerequest.window;

    case GravityNotify:
      return event->xgravity.window;

    case CirculateNotify:
      return event->xcirculate.window;

    case CirculateRequest:
      return event->xcirculaterequest.window;

    case MappingNotify:
      return None;

    default:
192 193
      if (META_X11_DISPLAY_HAS_SHAPE (display->x11_display) &&
          event->type == (display->x11_display->shape_event_base + ShapeNotify))
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
        {
          XShapeEvent *sev = (XShapeEvent*) event;
          return sev->window;
        }

      return None;
    }
}

static guint32
event_get_time (MetaDisplay *display,
                XEvent      *event)
{
  XIEvent *input_event = get_input_event (display, event);

  if (input_event)
    return input_event->time;

  switch (event->type)
    {
    case PropertyNotify:
      return event->xproperty.time;

    case SelectionClear:
    case SelectionRequest:
    case SelectionNotify:
      return event->xselection.time;

    case KeymapNotify:
    case Expose:
    case GraphicsExpose:
    case NoExpose:
    case MapNotify:
    case UnmapNotify:
    case VisibilityNotify:
    case ResizeRequest:
    case ColormapNotify:
    case ClientMessage:
    case CreateNotify:
    case DestroyNotify:
    case MapRequest:
    case ReparentNotify:
    case ConfigureNotify:
    case ConfigureRequest:
    case GravityNotify:
    case CirculateNotify:
    case CirculateRequest:
    case MappingNotify:
    default:
      return CurrentTime;
    }
}

247
const char*
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
meta_event_detail_to_string (int d)
{
  const char *detail = "???";
  switch (d)
    {
      /* We are an ancestor in the A<->B focus change relationship */
    case XINotifyAncestor:
      detail = "NotifyAncestor";
      break;
    case XINotifyDetailNone:
      detail = "NotifyDetailNone";
      break;
      /* We are a descendant in the A<->B focus change relationship */
    case XINotifyInferior:
      detail = "NotifyInferior";
      break;
    case XINotifyNonlinear:
      detail = "NotifyNonlinear";
      break;
    case XINotifyNonlinearVirtual:
      detail = "NotifyNonlinearVirtual";
      break;
    case XINotifyPointer:
      detail = "NotifyPointer";
      break;
    case XINotifyPointerRoot:
      detail = "NotifyPointerRoot";
      break;
    case XINotifyVirtual:
      detail = "NotifyVirtual";
      break;
    }

  return detail;
}

284
const char*
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
meta_event_mode_to_string (int m)
{
  const char *mode = "???";
  switch (m)
    {
    case XINotifyNormal:
      mode = "NotifyNormal";
      break;
    case XINotifyGrab:
      mode = "NotifyGrab";
      break;
    case XINotifyUngrab:
      mode = "NotifyUngrab";
      break;
    case XINotifyWhileGrabbed:
      mode = "NotifyWhileGrabbed";
      break;
    }

  return mode;
}

G_GNUC_UNUSED static const char*
stack_mode_to_string (int mode)
{
  switch (mode)
    {
    case Above:
      return "Above";
    case Below:
      return "Below";
    case TopIf:
      return "TopIf";
    case BottomIf:
      return "BottomIf";
    case Opposite:
      return "Opposite";
    }

  return "Unknown";
}

327
static gint64
328 329 330 331 332 333 334 335 336 337
sync_value_to_64 (const XSyncValue *value)
{
  gint64 v;

  v = XSyncValueLow32 (*value);
  v |= (((gint64)XSyncValueHigh32 (*value)) << 32);

  return v;
}

338
static const char*
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
alarm_state_to_string (XSyncAlarmState state)
{
  switch (state)
    {
    case XSyncAlarmActive:
      return "Active";
    case XSyncAlarmInactive:
      return "Inactive";
    case XSyncAlarmDestroyed:
      return "Destroyed";
    default:
      return "(unknown)";
    }
}

354
static void
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
meta_spew_xi2_event (MetaDisplay *display,
                     XIEvent     *input_event,
                     const char **name_p,
                     char       **extra_p)
{
  const char *name = NULL;
  char *extra = NULL;

  XIEnterEvent *enter_event = (XIEnterEvent *) input_event;

  switch (input_event->evtype)
    {
    case XI_FocusIn:
      name = "XI_FocusIn";
      break;
    case XI_FocusOut:
      name = "XI_FocusOut";
      break;
    case XI_Enter:
      name = "XI_Enter";
      break;
    case XI_Leave:
      name = "XI_Leave";
      break;
#ifdef HAVE_XI23
    case XI_BarrierHit:
      name = "XI_BarrierHit";
      break;
    case XI_BarrierLeave:
      name = "XI_BarrierLeave";
      break;
#endif /* HAVE_XI23 */
    }

  switch (input_event->evtype)
    {
    case XI_FocusIn:
    case XI_FocusOut:
      extra = g_strdup_printf ("detail: %s mode: %s\n",
                               meta_event_detail_to_string (enter_event->detail),
                               meta_event_mode_to_string (enter_event->mode));
      break;
    case XI_Enter:
    case XI_Leave:
      extra = g_strdup_printf ("win: 0x%lx root: 0x%lx mode: %s detail: %s focus: %d x: %g y: %g",
                               enter_event->event,
                               enter_event->root,
                               meta_event_mode_to_string (enter_event->mode),
                               meta_event_detail_to_string (enter_event->detail),
                               enter_event->focus,
                               enter_event->root_x,
                               enter_event->root_y);
      break;
    }

  *name_p = name;
  *extra_p = extra;
}

414
static void
415 416 417 418 419 420 421 422 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 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
meta_spew_core_event (MetaDisplay *display,
                      XEvent      *event,
                      const char **name_p,
                      char       **extra_p)
{
  const char *name = NULL;
  char *extra = NULL;

  switch (event->type)
    {
    case KeymapNotify:
      name = "KeymapNotify";
      break;
    case Expose:
      name = "Expose";
      break;
    case GraphicsExpose:
      name = "GraphicsExpose";
      break;
    case NoExpose:
      name = "NoExpose";
      break;
    case VisibilityNotify:
      name = "VisibilityNotify";
      break;
    case CreateNotify:
      name = "CreateNotify";
      extra = g_strdup_printf ("parent: 0x%lx window: 0x%lx",
                               event->xcreatewindow.parent,
                               event->xcreatewindow.window);
      break;
    case DestroyNotify:
      name = "DestroyNotify";
      extra = g_strdup_printf ("event: 0x%lx window: 0x%lx",
                               event->xdestroywindow.event,
                               event->xdestroywindow.window);
      break;
    case UnmapNotify:
      name = "UnmapNotify";
      extra = g_strdup_printf ("event: 0x%lx window: 0x%lx from_configure: %d",
                               event->xunmap.event,
                               event->xunmap.window,
                               event->xunmap.from_configure);
      break;
    case MapNotify:
      name = "MapNotify";
      extra = g_strdup_printf ("event: 0x%lx window: 0x%lx override_redirect: %d",
                               event->xmap.event,
                               event->xmap.window,
                               event->xmap.override_redirect);
      break;
    case MapRequest:
      name = "MapRequest";
      extra = g_strdup_printf ("window: 0x%lx parent: 0x%lx\n",
                               event->xmaprequest.window,
                               event->xmaprequest.parent);
      break;
    case ReparentNotify:
      name = "ReparentNotify";
      extra = g_strdup_printf ("window: 0x%lx parent: 0x%lx event: 0x%lx\n",
                               event->xreparent.window,
                               event->xreparent.parent,
                               event->xreparent.event);
      break;
    case ConfigureNotify:
      name = "ConfigureNotify";
      extra = g_strdup_printf ("x: %d y: %d w: %d h: %d above: 0x%lx override_redirect: %d",
                               event->xconfigure.x,
                               event->xconfigure.y,
                               event->xconfigure.width,
                               event->xconfigure.height,
                               event->xconfigure.above,
                               event->xconfigure.override_redirect);
      break;
    case ConfigureRequest:
      name = "ConfigureRequest";
      extra = g_strdup_printf ("parent: 0x%lx window: 0x%lx x: %d %sy: %d %sw: %d %sh: %d %sborder: %d %sabove: %lx %sstackmode: %s %s",
                               event->xconfigurerequest.parent,
                               event->xconfigurerequest.window,
                               event->xconfigurerequest.x,
                               event->xconfigurerequest.value_mask &
                               CWX ? "" : "(unset) ",
                               event->xconfigurerequest.y,
                               event->xconfigurerequest.value_mask &
                               CWY ? "" : "(unset) ",
                               event->xconfigurerequest.width,
                               event->xconfigurerequest.value_mask &
                               CWWidth ? "" : "(unset) ",
                               event->xconfigurerequest.height,
                               event->xconfigurerequest.value_mask &
                               CWHeight ? "" : "(unset) ",
                               event->xconfigurerequest.border_width,
                               event->xconfigurerequest.value_mask &
                               CWBorderWidth ? "" : "(unset)",
                               event->xconfigurerequest.above,
                               event->xconfigurerequest.value_mask &
                               CWSibling ? "" : "(unset)",
                               stack_mode_to_string (event->xconfigurerequest.detail),
                               event->xconfigurerequest.value_mask &
                               CWStackMode ? "" : "(unset)");
      break;
    case GravityNotify:
      name = "GravityNotify";
      break;
    case ResizeRequest:
      name = "ResizeRequest";
      extra = g_strdup_printf ("width = %d height = %d",
                               event->xresizerequest.width,
                               event->xresizerequest.height);
      break;
    case CirculateNotify:
      name = "CirculateNotify";
      break;
    case CirculateRequest:
      name = "CirculateRequest";
      break;
    case PropertyNotify:
      {
        char *str;
        const char *state;

        name = "PropertyNotify";

538
        meta_error_trap_push (display->x11_display);
539
        str = XGetAtomName (display->x11_display->xdisplay,
540
                            event->xproperty.atom);
541
        meta_error_trap_pop (display->x11_display);
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571

        if (event->xproperty.state == PropertyNewValue)
          state = "PropertyNewValue";
        else if (event->xproperty.state == PropertyDelete)
          state = "PropertyDelete";
        else
          state = "???";

        extra = g_strdup_printf ("atom: %s state: %s",
                                 str ? str : "(unknown atom)",
                                 state);
        meta_XFree (str);
      }
      break;
    case SelectionClear:
      name = "SelectionClear";
      break;
    case SelectionRequest:
      name = "SelectionRequest";
      break;
    case SelectionNotify:
      name = "SelectionNotify";
      break;
    case ColormapNotify:
      name = "ColormapNotify";
      break;
    case ClientMessage:
      {
        char *str;
        name = "ClientMessage";
572
        meta_error_trap_push (display->x11_display);
573
        str = XGetAtomName (display->x11_display->xdisplay,
574
                            event->xclient.message_type);
575
        meta_error_trap_pop (display->x11_display);
576 577 578 579 580 581 582 583 584 585
        extra = g_strdup_printf ("type: %s format: %d\n",
                                 str ? str : "(unknown atom)",
                                 event->xclient.format);
        meta_XFree (str);
      }
      break;
    case MappingNotify:
      name = "MappingNotify";
      break;
    default:
586 587
      if (META_X11_DISPLAY_HAS_XSYNC (display->x11_display) &&
          event->type == (display->x11_display->xsync_event_base + XSyncAlarmNotify))
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
        {
          XSyncAlarmNotifyEvent *aevent = (XSyncAlarmNotifyEvent*) event;

          name = "XSyncAlarmNotify";
          extra =
            g_strdup_printf ("alarm: 0x%lx"
                             " counter_value: %" G_GINT64_FORMAT
                             " alarm_value: %" G_GINT64_FORMAT
                             " time: %u alarm state: %s",
                             aevent->alarm,
                             (gint64) sync_value_to_64 (&aevent->counter_value),
                             (gint64) sync_value_to_64 (&aevent->alarm_value),
                             (unsigned int)aevent->time,
                             alarm_state_to_string (aevent->state));
        }
      else
604 605
        if (META_X11_DISPLAY_HAS_SHAPE (display->x11_display) &&
            event->type == (display->x11_display->shape_event_base + ShapeNotify))
606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
          {
            XShapeEvent *sev = (XShapeEvent*) event;

            name = "ShapeNotify";

            extra =
              g_strdup_printf ("kind: %s "
                               "x: %d y: %d w: %u h: %u "
                               "shaped: %d",
                               sev->kind == ShapeBounding ?
                               "ShapeBounding" :
                               (sev->kind == ShapeClip ?
                                "ShapeClip" : "(unknown)"),
                               sev->x, sev->y, sev->width, sev->height,
                               sev->shaped);
          }
        else
          {
            name = "(Unknown event)";
            extra = g_strdup_printf ("type: %d", event->xany.type);
          }
      break;
    }

  *name_p = name;
  *extra_p = extra;
}

634
static char *
635 636 637 638 639 640
meta_spew_event (MetaDisplay *display,
                 XEvent      *event)
{
  const char *name = NULL;
  char *extra = NULL;
  char *winname;
641
  char *ret;
642 643 644 645 646 647 648 649 650
  XIEvent *input_event;

  input_event = get_input_event (display, event);

  if (input_event)
    meta_spew_xi2_event (display, input_event, &name, &extra);
  else
    meta_spew_core_event (display, event, &name, &extra);

651
  if (event->xany.window == display->x11_display->xroot)
Jonas Ådahl's avatar
Jonas Ådahl committed
652
    winname = g_strdup_printf ("root");
653 654 655
  else
    winname = g_strdup_printf ("0x%lx", event->xany.window);

656 657 658 659
  ret = g_strdup_printf ("%s on %s%s %s %sserial %lu", name, winname,
                         extra ? ":" : "", extra ? extra : "",
                         event->xany.send_event ? "SEND " : "",
                         event->xany.serial);
660 661

  g_free (winname);
662
  g_free (extra);
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677

  return ret;
}

G_GNUC_UNUSED static void
meta_spew_event_print (MetaDisplay *display,
                       XEvent      *event)
{
  char *event_str;

  /* filter overnumerous events */
  if (event->type == Expose || event->type == MotionNotify ||
      event->type == NoExpose)
    return;

678
  if (event->type == (display->x11_display->damage_event_base + XDamageNotify))
679 680
    return;

681
  if (event->type == (display->x11_display->xsync_event_base + XSyncAlarmNotify))
682 683
    return;

684 685
  if (event->type == PropertyNotify &&
      event->xproperty.atom == display->x11_display->atom__NET_WM_USER_TIME)
686 687 688 689 690
    return;

  event_str = meta_spew_event (display, event);
  g_print ("%s\n", event_str);
  g_free (event_str);
691 692
}

693
static gboolean
694 695
handle_window_focus_event (MetaDisplay  *display,
                           MetaWindow   *window,
696 697
                           XIEnterEvent *event,
                           unsigned long serial)
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
{
  MetaWindow *focus_window;
#ifdef WITH_VERBOSE_MODE
  const char *window_type;

  /* Note the event can be on either the window or the frame,
   * we focus the frame for shaded windows
   */
  if (window)
    {
      if (event->event == window->xwindow)
        window_type = "client window";
      else if (window->frame && event->event == window->frame->xwindow)
        window_type = "frame window";
      else
        window_type = "unknown client window";
    }
  else if (meta_display_xwindow_is_a_no_focus_window (display, event->event))
    window_type = "no_focus_window";
717
  else if (event->event == display->x11_display->xroot)
718 719 720 721 722 723 724 725 726 727 728 729 730 731
    window_type = "root window";
  else
    window_type = "unknown window";

  meta_topic (META_DEBUG_FOCUS,
              "Focus %s event received on %s 0x%lx (%s) "
              "mode %s detail %s serial %lu\n",
              event->evtype == XI_FocusIn ? "in" :
              event->evtype == XI_FocusOut ? "out" :
              "???",
              window ? window->desc : "",
              event->event, window_type,
              meta_event_mode_to_string (event->mode),
              meta_event_detail_to_string (event->mode),
732
              serial);
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
#endif

  /* FIXME our pointer tracking is broken; see how
   * gtk+/gdk/x11/gdkevents-x11.c or XFree86/xc/programs/xterm/misc.c
   * for how to handle it the correct way.  In brief you need to track
   * pointer focus and regular focus, and handle EnterNotify in
   * PointerRoot mode with no window manager.  However as noted above,
   * accurate focus tracking will break things because we want to keep
   * windows "focused" when using keybindings on them, and also we
   * sometimes "focus" a window by focusing its frame or
   * no_focus_window; so this all needs rethinking massively.
   *
   * My suggestion is to change it so that we clearly separate
   * actual keyboard focus tracking using the xterm algorithm,
   * and mutter's "pretend" focus window, and go through all
   * the code and decide which one should be used in each place;
   * a hard bit is deciding on a policy for that.
   *
   * http://bugzilla.gnome.org/show_bug.cgi?id=90382
   */

  /* We ignore grabs, though this is questionable. It may be better to
   * increase the intelligence of the focus window tracking.
   *
   * The problem is that keybindings for windows are done with
   * XGrabKey, which means focus_window disappears and the front of
   * the MRU list gets confused from what the user expects once a
   * keybinding is used.
   */

  if (event->mode == XINotifyGrab ||
      event->mode == XINotifyUngrab ||
      /* From WindowMaker, ignore all funky pointer root events */
      event->detail > XINotifyNonlinearVirtual)
    {
      meta_topic (META_DEBUG_FOCUS,
                  "Ignoring focus event generated by a grab or other weirdness\n");
770
      return FALSE;
771 772 773 774 775
    }

  if (event->evtype == XI_FocusIn)
    {
      display->server_focus_window = event->event;
776
      display->server_focus_serial = serial;
777 778 779 780 781 782 783 784 785
      focus_window = window;
    }
  else if (event->evtype == XI_FocusOut)
    {
      if (event->detail == XINotifyInferior)
        {
          /* This event means the client moved focus to a subwindow */
          meta_topic (META_DEBUG_FOCUS,
                      "Ignoring focus out with NotifyInferior\n");
786
          return FALSE;
787 788 789
        }

      display->server_focus_window = None;
790
      display->server_focus_serial = serial;
791 792 793
      focus_window = NULL;
    }
  else
794
    g_assert_not_reached ();
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809

  /* If display->focused_by_us, then the focus_serial will be used only
   * for a focus change we made and have already accounted for.
   * (See request_xserver_input_focus_change().) Otherwise, we can get
   * multiple focus events with the same serial.
   */
  if (display->server_focus_serial > display->focus_serial ||
      (!display->focused_by_us &&
       display->server_focus_serial == display->focus_serial))
    {
      meta_display_update_focus_window (display,
                                        focus_window,
                                        focus_window ? focus_window->xwindow : None,
                                        display->server_focus_serial,
                                        FALSE);
810 811 812 813 814
      return TRUE;
    }
  else
    {
      return FALSE;
815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
    }
}

static gboolean
crossing_serial_is_ignored (MetaDisplay  *display,
                            unsigned long serial)
{
  int i;

  i = 0;
  while (i < N_IGNORED_CROSSING_SERIALS)
    {
      if (display->ignored_crossing_serials[i] == serial)
        return TRUE;
      ++i;
    }
  return FALSE;
}

static gboolean
835 836 837
handle_input_xevent (MetaDisplay  *display,
                     XIEvent      *input_event,
                     unsigned long serial)
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
{
  XIEnterEvent *enter_event = (XIEnterEvent *) input_event;
  Window modified;
  MetaWindow *window;
  MetaScreen *screen = display->screen;

  if (input_event == NULL)
    return FALSE;

  switch (input_event->evtype)
    {
    case XI_Enter:
    case XI_Leave:
    case XI_FocusIn:
    case XI_FocusOut:
      break;
    default:
      return FALSE;
    }

  modified = xievent_get_modified_window (display, input_event);
859 860 861
  window = modified != None ?
           meta_x11_display_lookup_x_window (display->x11_display, modified) :
           NULL;
862 863 864 865 866 867 868 869

  /* If this is an event for a GTK+ widget, let GTK+ handle it. */
  if (meta_ui_window_is_widget (display->screen->ui, modified))
    return FALSE;

  switch (input_event->evtype)
    {
    case XI_Enter:
870
      if (display->event_route != META_EVENT_ROUTE_NORMAL)
871 872 873 874 875
        break;

      /* Check if we've entered a window; do this even if window->has_focus to
       * avoid races.
       */
876
      if (window && !crossing_serial_is_ignored (display, serial) &&
877 878 879 880 881 882 883 884 885 886 887 888
          enter_event->mode != XINotifyGrab &&
          enter_event->mode != XINotifyUngrab &&
          enter_event->detail != XINotifyInferior &&
          meta_display_focus_sentinel_clear (display))
        {
          meta_window_handle_enter (window,
                                    enter_event->time,
                                    enter_event->root_x,
                                    enter_event->root_y);
        }
      break;
    case XI_Leave:
889
      if (display->event_route != META_EVENT_ROUTE_NORMAL)
890 891 892 893 894 895 896 897 898 899 900
        break;

      if (window != NULL &&
          enter_event->mode != XINotifyGrab &&
          enter_event->mode != XINotifyUngrab)
        {
          meta_window_handle_leave (window);
        }
      break;
    case XI_FocusIn:
    case XI_FocusOut:
901
      if (handle_window_focus_event (display, window, enter_event, serial) &&
902
          enter_event->event == enter_event->root)
903 904
        {
          if (enter_event->evtype == XI_FocusIn &&
905
              enter_event->detail == XINotifyDetailNone)
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 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
            {
              meta_topic (META_DEBUG_FOCUS,
                          "Focus got set to None, probably due to "
                          "brain-damage in the X protocol (see bug "
                          "125492).  Setting the default focus window.\n");
              meta_workspace_focus_default_window (screen->active_workspace,
                                                   NULL,
                                                   meta_display_get_current_time_roundtrip (display));
            }
          else if (enter_event->evtype == XI_FocusIn &&
                   enter_event->mode == XINotifyNormal &&
                   enter_event->detail == XINotifyInferior)
            {
              meta_topic (META_DEBUG_FOCUS,
                          "Focus got set to root window, probably due to "
                          "gnome-session logout dialog usage (see bug "
                          "153220).  Setting the default focus window.\n");
              meta_workspace_focus_default_window (screen->active_workspace,
                                                   NULL,
                                                   meta_display_get_current_time_roundtrip (display));
            }
        }
      break;
    }

  /* Don't eat events for GTK frames (we need to update the :hover state on buttons) */
  if (window && window->frame && modified == window->frame->xwindow)
    return FALSE;

  /* Don't pass these events through to Clutter / GTK+ */
  return TRUE;
}

static void
process_request_frame_extents (MetaDisplay    *display,
                               XEvent         *event)
{
  /* The X window whose frame extents will be set. */
  Window xwindow = event->xclient.window;
  unsigned long data[4] = { 0, 0, 0, 0 };

  MotifWmHints *hints = NULL;
  gboolean hints_set = FALSE;

  meta_verbose ("Setting frame extents for 0x%lx\n", xwindow);

  /* See if the window is decorated. */
  hints_set = meta_prop_get_motif_hints (display,
                                         xwindow,
955
                                         display->x11_display->atom__MOTIF_WM_HINTS,
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976
                                         &hints);
  if ((hints_set && hints->decorations) || !hints_set)
    {
      MetaFrameBorders borders;

      /* Return estimated frame extents for a normal window. */
      meta_ui_theme_get_frame_borders (display->screen->ui,
                                       META_FRAME_TYPE_NORMAL,
                                       0,
                                       &borders);
      data[0] = borders.visible.left;
      data[1] = borders.visible.right;
      data[2] = borders.visible.top;
      data[3] = borders.visible.bottom;
    }

  meta_topic (META_DEBUG_GEOMETRY,
              "Setting _NET_FRAME_EXTENTS on unmanaged window 0x%lx "
              "to top = %lu, left = %lu, bottom = %lu, right = %lu\n",
              xwindow, data[0], data[1], data[2], data[3]);

977
  meta_error_trap_push (display->x11_display);
978 979
  XChangeProperty (display->x11_display->xdisplay, xwindow,
                   display->x11_display->atom__NET_FRAME_EXTENTS,
980 981
                   XA_CARDINAL,
                   32, PropModeReplace, (guchar*) data, 4);
982
  meta_error_trap_pop (display->x11_display);
983 984 985 986 987 988 989 990 991 992 993 994

  meta_XFree (hints);
}

/* from fvwm2, Copyright Matthias Clasen, Dominik Vogt */
static gboolean
convert_property (MetaDisplay *display,
                  MetaScreen  *screen,
                  Window       w,
                  Atom         target,
                  Atom         property)
{
995
  MetaX11Display *x11_display = display->x11_display;
996 997 998 999
#define N_TARGETS 4
  Atom conversion_targets[N_TARGETS];
  long icccm_version[] = { 2, 0 };

1000 1001 1002 1003
  conversion_targets[0] = x11_display->atom_TARGETS;
  conversion_targets[1] = x11_display->atom_MULTIPLE;
  conversion_targets[2] = x11_display->atom_TIMESTAMP;
  conversion_targets[3] = x11_display->atom_VERSION;
1004

1005
  meta_error_trap_push (x11_display);
1006 1007
  if (target == x11_display->atom_TARGETS)
    XChangeProperty (x11_display->xdisplay, w, property,
1008 1009
		     XA_ATOM, 32, PropModeReplace,
		     (unsigned char *)conversion_targets, N_TARGETS);
1010 1011
  else if (target == x11_display->atom_TIMESTAMP)
    XChangeProperty (x11_display->xdisplay, w, property,
1012 1013
		     XA_INTEGER, 32, PropModeReplace,
		     (unsigned char *)&screen->wm_sn_timestamp, 1);
1014 1015
  else if (target == x11_display->atom_VERSION)
    XChangeProperty (x11_display->xdisplay, w, property,
1016 1017 1018 1019
		     XA_INTEGER, 32, PropModeReplace,
		     (unsigned char *)icccm_version, 2);
  else
    {
1020
      meta_error_trap_pop_with_return (x11_display);
1021 1022 1023
      return FALSE;
    }

1024
  if (meta_error_trap_pop_with_return (x11_display) != Success)
1025 1026 1027 1028 1029 1030 1031
    return FALSE;

  /* Be sure the PropertyNotify has arrived so we
   * can send SelectionNotify
   */
  /* FIXME the error trap pop synced anyway, right? */
  meta_topic (META_DEBUG_SYNC, "Syncing on %s\n", G_STRFUNC);
1032
  XSync (x11_display->xdisplay, False);
1033 1034 1035 1036 1037 1038 1039 1040 1041

  return TRUE;
}

/* from fvwm2, Copyright Matthias Clasen, Dominik Vogt */
static void
process_selection_request (MetaDisplay   *display,
                           XEvent        *event)
{
1042
  MetaX11Display *x11_display = display->x11_display;
1043 1044 1045 1046 1047 1048 1049 1050
  MetaScreen *screen = display->screen;
  XSelectionEvent reply;

  if (screen->wm_sn_selection_window != event->xselectionrequest.owner ||
      screen->wm_sn_atom != event->xselectionrequest.selection)
    {
      char *str;

1051
      meta_error_trap_push (x11_display);
1052
      str = XGetAtomName (x11_display->xdisplay,
1053
                          event->xselectionrequest.selection);
1054
      meta_error_trap_pop (x11_display);
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064

      meta_verbose ("Selection request with selection %s window 0x%lx not a WM_Sn selection we recognize\n",
                    str ? str : "(bad atom)", event->xselectionrequest.owner);

      meta_XFree (str);

      return;
    }

  reply.type = SelectionNotify;
1065
  reply.display = x11_display->xdisplay;
1066 1067 1068 1069 1070 1071
  reply.requestor = event->xselectionrequest.requestor;
  reply.selection = event->xselectionrequest.selection;
  reply.target = event->xselectionrequest.target;
  reply.property = None;
  reply.time = event->xselectionrequest.time;

1072
  if (event->xselectionrequest.target == x11_display->atom_MULTIPLE)
1073 1074 1075 1076 1077 1078 1079 1080
    {
      if (event->xselectionrequest.property != None)
        {
          Atom type, *adata;
          int i, format;
          unsigned long num, rest;
          unsigned char *data;

1081
          meta_error_trap_push (x11_display);
1082
          if (XGetWindowProperty (x11_display->xdisplay,
1083 1084
                                  event->xselectionrequest.requestor,
                                  event->xselectionrequest.property, 0, 256, False,
1085
                                  x11_display->atom_ATOM_PAIR,
1086 1087
                                  &type, &format, &num, &rest, &data) != Success)
            {
1088
              meta_error_trap_pop_with_return (x11_display);
1089 1090 1091
              return;
            }

1092
          if (meta_error_trap_pop_with_return (x11_display) == Success)
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
            {
              /* FIXME: to be 100% correct, should deal with rest > 0,
               * but since we have 4 possible targets, we will hardly ever
               * meet multiple requests with a length > 8
               */
              adata = (Atom*)data;
              i = 0;
              while (i < (int) num)
                {
                  if (!convert_property (display, screen,
                                         event->xselectionrequest.requestor,
                                         adata[i], adata[i+1]))
                    adata[i+1] = None;
                  i += 2;
                }

1109
              meta_error_trap_push (x11_display);
1110
              XChangeProperty (x11_display->xdisplay,
1111 1112
                               event->xselectionrequest.requestor,
                               event->xselectionrequest.property,
1113
                               x11_display->atom_ATOM_PAIR,
1114
                               32, PropModeReplace, data, num);
1115
              meta_error_trap_pop (x11_display);
1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
              meta_XFree (data);
            }
        }
    }
  else
    {
      if (event->xselectionrequest.property == None)
        event->xselectionrequest.property = event->xselectionrequest.target;

      if (convert_property (display, screen,
                            event->xselectionrequest.requestor,
                            event->xselectionrequest.target,
                            event->xselectionrequest.property))
        reply.property = event->xselectionrequest.property;
    }

1132
  XSendEvent (x11_display->xdisplay,
1133 1134 1135 1136 1137 1138
              event->xselectionrequest.requestor,
              False, 0L, (XEvent*)&reply);

  meta_verbose ("Handled selection request\n");
}

1139
static gboolean
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149
process_selection_clear (MetaDisplay   *display,
                         XEvent        *event)
{
  MetaScreen *screen = display->screen;

  if (screen->wm_sn_selection_window != event->xselectionclear.window ||
      screen->wm_sn_atom != event->xselectionclear.selection)
    {
      char *str;

1150
      meta_error_trap_push (display->x11_display);
1151
      str = XGetAtomName (display->x11_display->xdisplay,
1152
                          event->xselectionclear.selection);
1153
      meta_error_trap_pop (display->x11_display);
1154 1155 1156 1157 1158 1159

      meta_verbose ("Selection clear with selection %s window 0x%lx not a WM_Sn selection we recognize\n",
                    str ? str : "(bad atom)", event->xselectionclear.window);

      meta_XFree (str);

1160
      return FALSE;
1161 1162
    }

Jonas Ådahl's avatar
Jonas Ådahl committed
1163
  meta_verbose ("Got selection clear for on display %s\n",
1164
                display->x11_display->name);
1165 1166 1167

  meta_display_unmanage_screen (display, display->screen,
                                event->xselectionclear.time);
1168
  return TRUE;
1169 1170
}

1171 1172 1173 1174 1175 1176 1177
static void
notify_bell (MetaDisplay *display,
             XkbAnyEvent *xkb_ev)
{
  XkbBellNotifyEvent *xkb_bell_event = (XkbBellNotifyEvent*) xkb_ev;
  MetaWindow *window;

1178 1179
  window = meta_x11_display_lookup_x_window (display->x11_display,
                                             xkb_bell_event->window);
1180 1181 1182 1183 1184 1185 1186 1187
  if (!window && display->focus_window && display->focus_window->frame)
    window = display->focus_window;

  display->last_bell_time = xkb_ev->time;
  if (!meta_bell_notify (display, window) &&
      meta_prefs_bell_is_audible ())
    {
      /* Force a classic bell if the libcanberra bell failed. */
1188
      XkbForceDeviceBell (display->x11_display->xdisplay,
1189 1190 1191 1192 1193 1194 1195
                          xkb_bell_event->device,
                          xkb_bell_event->bell_class,
                          xkb_bell_event->bell_id,
                          xkb_bell_event->percent);
    }
}

1196 1197 1198 1199
static gboolean
handle_other_xevent (MetaDisplay *display,
                     XEvent      *event)
{
1200
  MetaX11Display *x11_display = display->x11_display;
1201 1202 1203 1204 1205 1206 1207
  Window modified;
  MetaWindow *window;
  MetaWindow *property_for_window;
  gboolean frame_was_receiver;
  gboolean bypass_gtk = FALSE;

  modified = event_get_modified_window (display, event);
1208
  window = modified != None ? meta_x11_display_lookup_x_window (x11_display, modified) : NULL;
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
  frame_was_receiver = (window && window->frame && modified == window->frame->xwindow);

  /* We only want to respond to _NET_WM_USER_TIME property notify
   * events on _NET_WM_USER_TIME_WINDOW windows; in particular,
   * responding to UnmapNotify events is kind of bad.
   */
  property_for_window = NULL;
  if (window && modified == window->user_time_window)
    {
      property_for_window = window;
      window = NULL;
    }

1222 1223
  if (META_X11_DISPLAY_HAS_XSYNC (x11_display) &&
      event->type == (x11_display->xsync_event_base + XSyncAlarmNotify))
1224
    {
1225 1226
      MetaWindow *alarm_window = meta_x11_display_lookup_sync_alarm (x11_display,
                                                                     ((XSyncAlarmNotifyEvent*)event)->alarm);
1227 1228 1229 1230 1231 1232 1233 1234 1235

      if (alarm_window != NULL)
        {
          XSyncValue value = ((XSyncAlarmNotifyEvent*)event)->counter_value;
          gint64 new_counter_value;
          new_counter_value = XSyncValueLow32 (value) + ((gint64)XSyncValueHigh32 (value) << 32);
          meta_window_x11_update_sync_request_counter (alarm_window, new_counter_value);
          bypass_gtk = TRUE; /* GTK doesn't want to see this really */
        }
1236 1237
      else
        {
1238 1239 1240 1241
          if (x11_display->alarm_filter &&
              x11_display->alarm_filter (x11_display,
                                         (XSyncAlarmNotifyEvent*)event,
                                          x11_display->alarm_filter_data))
1242 1243
            bypass_gtk = TRUE;
        }
1244 1245 1246 1247

      goto out;
    }

1248 1249
  if (META_X11_DISPLAY_HAS_SHAPE (x11_display) &&
      event->type == (x11_display->shape_event_base + ShapeNotify))
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
    {
      bypass_gtk = TRUE; /* GTK doesn't want to see this really */

      if (window && !frame_was_receiver)
        {
          XShapeEvent *sev = (XShapeEvent*) event;

          if (sev->kind == ShapeBounding)
            meta_window_x11_update_shape_region (window);
          else if (sev->kind == ShapeInput)
            meta_window_x11_update_input_region (window);
        }
      else
        {
          meta_topic (META_DEBUG_SHAPES,
                      "ShapeNotify not on a client window (window %s frame_was_receiver = %d)\n",
                      window ? window->desc : "(none)",
                      frame_was_receiver);
        }

      goto out;
    }

  switch (event->type)
    {
    case KeymapNotify:
      break;
    case Expose:
      break;
    case GraphicsExpose:
      break;
    case NoExpose:
      break;
    case VisibilityNotify:
      break;
    case CreateNotify:
      {
1287
        if (event->xcreatewindow.parent == x11_display->xroot)
1288 1289 1290 1291 1292 1293 1294
          meta_stack_tracker_create_event (display->screen->stack_tracker,
                                           &event->xcreatewindow);
      }
      break;

    case DestroyNotify:
      {
1295
        if (event->xdestroywindow.event == x11_display->xroot)
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315
          meta_stack_tracker_destroy_event (display->screen->stack_tracker,
                                            &event->xdestroywindow);
      }
      if (window)
        {
          /* FIXME: It sucks that DestroyNotify events don't come with
           * a timestamp; could we do something better here?  Maybe X
           * will change one day?
           */
          guint32 timestamp;
          timestamp = meta_display_get_current_time_roundtrip (display);

          if (display->grab_op != META_GRAB_OP_NONE &&
              display->grab_window == window)
            meta_display_end_grab_op (display, timestamp);

          if (frame_was_receiver)
            {
              meta_warning ("Unexpected destruction of frame 0x%lx, not sure if this should silently fail or be considered a bug\n",
                            window->frame->xwindow);
1316
              meta_error_trap_push (x11_display);
1317
              meta_window_destroy_frame (window->frame->window);
1318
              meta_error_trap_pop (x11_display);
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
            }
          else
            {
              /* Unmanage destroyed window */
              meta_window_unmanage (window, timestamp);
              window = NULL;
            }
        }
      break;
    case UnmapNotify:
      if (window)
        {
          /* FIXME: It sucks that UnmapNotify events don't come with
           * a timestamp; could we do something better here?  Maybe X
           * will change one day?
           */
          guint32 timestamp;
          timestamp = meta_display_get_current_time_roundtrip (display);

          if (display->grab_op != META_GRAB_OP_NONE &&
              display->grab_window == window &&
              window->frame == NULL)
            meta_display_end_grab_op (display, timestamp);

          if (!frame_was_receiver)
            {
              if (window->unmaps_pending == 0)
                {
                  meta_topic (META_DEBUG_WINDOW_STATE,
                              "Window %s withdrawn\n",
                              window->desc);

                  /* Unmanage withdrawn window */
                  window->withdrawn = TRUE;
                  meta_window_unmanage (window, timestamp);
                  window = NULL;
                }
              else
                {
                  window->unmaps_pending -= 1;
                  meta_topic (META_DEBUG_WINDOW_STATE,
                              "Received pending unmap, %d now pending\n",
                              window->unmaps_pending);
                }
            }
        }
      break;
    case MapNotify:
      /* NB: override redirect windows wont cause a map request so we
       * watch out for map notifies against any root windows too if a
       * compositor is enabled: */
1370
      if (window == NULL && event->xmap.event == x11_display->xroot)
1371 1372 1373 1374 1375 1376 1377 1378 1379 1380
        {
          window = meta_window_x11_new (display, event->xmap.window,
                                        FALSE, META_COMP_EFFECT_CREATE);
        }
      break;
    case MapRequest:
      if (window == NULL)
        {
          window = meta_window_x11_new (display, event->xmaprequest.window,
                                        FALSE, META_COMP_EFFECT_CREATE);
1381 1382 1383 1384
          /* The window might have initial iconic state, but this is a
           * MapRequest, fall through to ensure it is unminimized in
           * that case.
           */
1385
        }
1386
      else if (frame_was_receiver)
1387
        {
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
          meta_warning ("Map requests on the frame window are unexpected\n");
          break;
        }

      /* Double check that creating the MetaWindow succeeded */
      if (window == NULL)
        break;

      meta_verbose ("MapRequest on %s mapped = %d minimized = %d\n",
                    window->desc, window->mapped, window->minimized);

      if (window->minimized)
        {
          meta_window_unminimize (window);
          if (window->workspace != window->screen->active_workspace)
1403
            {
1404 1405 1406 1407
              meta_verbose ("Changing workspace due to MapRequest mapped = %d minimized = %d\n",
                            window->mapped, window->minimized);
              meta_window_change_workspace (window,
                                            window->screen->active_workspace);
1408 1409 1410 1411 1412
            }
        }
      break;
    case ReparentNotify:
      {
1413
        if (event->xreparent.event == x11_display->xroot)
1414 1415 1416 1417 1418 1419 1420
          meta_stack_tracker_reparent_event (display->screen->stack_tracker,
                                             &event->xreparent);
      }
      break;
    case ConfigureNotify:
      if (event->xconfigure.event != event->xconfigure.window)
        {
1421
          if (event->xconfigure.event == x11_display->xroot &&
1422
              event->xconfigure.window != display->screen->composite_overlay_window)
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
            meta_stack_tracker_configure_event (display->screen->stack_tracker,
                                                &event->xconfigure);
        }

      if (window && window->override_redirect)
        meta_window_x11_configure_notify (window, &event->xconfigure);

      break;
    case ConfigureRequest:
      /* This comment and code is found in both twm and fvwm */
      /*
       * According to the July 27, 1988 ICCCM draft, we should ignore size and
       * position fields in the WM_NORMAL_HINTS property when we map a window.
       * Instead, we'll read the current geometry.  Therefore, we should respond
       * to configuration requests for windows which have never been mapped.
       */
      if (window == NULL)
        {
          unsigned int xwcm;
          XWindowChanges xwc;

          xwcm = event->xconfigurerequest.value_mask &
            (CWX | CWY | CWWidth | CWHeight | CWBorderWidth);

          xwc.x = event->xconfigurerequest.x;
          xwc.y = event->xconfigurerequest.y;
          xwc.width = event->xconfigurerequest.width;
          xwc.height = event->xconfigurerequest.height;
          xwc.border_width = event->xconfigurerequest.border_width;

          meta_verbose ("Configuring withdrawn window to %d,%d %dx%d border %d (some values may not be in mask)\n",
                        xwc.x, xwc.y, xwc.width, xwc.height, xwc.border_width);
1455
          meta_error_trap_push (x11_display);
1456
          XConfigureWindow (x11_display->xdisplay, event->xconfigurerequest.window,
1457
                            xwcm, &xwc);
1458
          meta_error_trap_pop (x11_display);
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482
        }
      else
        {
          if (!frame_was_receiver)
            meta_window_x11_configure_request (window, event);
        }
      break;
    case GravityNotify:
      break;
    case ResizeRequest:
      break;
    case CirculateNotify:
      break;
    case CirculateRequest:
      break;
    case PropertyNotify: