gdk.c 93 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/* 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
 * modify it under the terms of the GNU Library General Public
 * 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
#include "../config.h"

Elliot Lee's avatar
Elliot Lee committed
20 21
/* #define DEBUG_DND 1 */ /* Shouldn't be needed much these days */

22
#include <X11/Xlocale.h>
Elliot Lee's avatar
Elliot Lee committed
23 24 25 26 27 28
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
29 30 31
#ifdef USE_XIM
#include <stdarg.h>
#endif
Elliot Lee's avatar
Elliot Lee committed
32 33 34 35 36 37 38 39 40 41 42

#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif /* HAVE_SYS_SELECT_H_ */

#define XLIB_ILLEGAL_ACCESS
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xos.h>
#include <X11/Xutil.h>
#include <X11/Xmu/WinUtil.h>
43 44 45
#ifdef USE_XIM
#include <X11/Xresource.h>
#endif
Elliot Lee's avatar
Elliot Lee committed
46 47 48 49
#include <X11/cursorfont.h>
#include "gdk.h"
#include "gdkprivate.h"
#include "gdkinput.h"
50 51 52 53
#ifdef USE_XIM
#include "gdkx.h"
#include "gdkkeysyms.h"
#endif
54
#include "gdki18n.h"
Elliot Lee's avatar
Elliot Lee committed
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

#ifndef X_GETTIMEOFDAY
#define X_GETTIMEOFDAY(tv)  gettimeofday (tv, NULL)
#endif /* X_GETTIMEOFDAY */


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


#ifndef NO_FD_SET
#  define SELECT_MASK fd_set
#else
#  ifndef _AIX
     typedef long fd_mask;
#  endif
#  if defined(_IBMR2)
#    define SELECT_MASK void
#  else
#    define SELECT_MASK int
#  endif
#endif


typedef struct _GdkInput      GdkInput;
typedef struct _GdkPredicate  GdkPredicate;

struct _GdkInput
{
  gint tag;
  gint source;
  GdkInputCondition condition;
  GdkInputFunction function;
  gpointer data;
91
  GdkDestroyNotify destroy;
Elliot Lee's avatar
Elliot Lee committed
92 93 94 95 96 97 98 99 100 101 102
};

struct _GdkPredicate
{
  GdkEventFunc func;
  gpointer data;
};

/* 
 * Private function declarations
 */
103 104

static GdkEvent *gdk_event_new          (void);
Elliot Lee's avatar
Elliot Lee committed
105
static gint      gdk_event_wait         (void);
106 107 108
static gint      gdk_event_apply_filters (XEvent *xevent,
					  GdkEvent *event,
					  GList *filters);
Elliot Lee's avatar
Elliot Lee committed
109 110
static gint      gdk_event_translate    (GdkEvent     *event, 
				         XEvent       *xevent);
111
#if 0
Elliot Lee's avatar
Elliot Lee committed
112 113 114
static Bool      gdk_event_get_type     (Display      *display, 
					 XEvent       *xevent, 
					 XPointer      arg);
115
#endif
Elliot Lee's avatar
Elliot Lee committed
116 117 118 119 120 121
static void      gdk_synthesize_click   (GdkEvent     *event, 
					 gint          nclicks);

static void      gdk_dnd_drag_begin     (GdkWindow    *initial_window);
static void      gdk_dnd_drag_enter     (Window        dest);
static void      gdk_dnd_drag_leave     (Window        dest);
Elliot Lee's avatar
Elliot Lee committed
122
static void      gdk_dnd_drag_end       (Window        dest,
Elliot Lee's avatar
Elliot Lee committed
123 124 125
					 GdkPoint      coords);
static GdkAtom   gdk_dnd_check_types    (GdkWindow    *window,
					 XEvent       *xevent);
Elliot Lee's avatar
Elliot Lee committed
126
#ifdef DEBUG_DND
Elliot Lee's avatar
Elliot Lee committed
127
static void      gdk_print_atom         (GdkAtom       anatom);
Elliot Lee's avatar
Elliot Lee committed
128
#endif
Elliot Lee's avatar
Elliot Lee committed
129 130 131 132

/* 
 * old junk from offix, we might use it though so leave it 
 */
Elliot Lee's avatar
Elliot Lee committed
133 134 135
Window       gdk_get_client_window   (Display     *dpy, 
				      Window       win);
#ifdef WE_HAVE_MOTIF_DROPS_DONE
Elliot Lee's avatar
Elliot Lee committed
136 137 138
static GdkWindow *  gdk_drop_get_real_window     (GdkWindow   *w, 
						  guint16     *x,
						  guint16     *y);
Elliot Lee's avatar
Elliot Lee committed
139
#endif
Elliot Lee's avatar
Elliot Lee committed
140 141 142 143 144 145 146
static void         gdk_exit_func                (void);
static int          gdk_x_error                  (Display     *display, 
						  XErrorEvent *error);
static int          gdk_x_io_error               (Display     *display);
static RETSIGTYPE   gdk_signal                   (int          signum);


147 148 149 150 151 152 153 154 155
#ifdef USE_XIM
static GdkIM  gdk_im_get		(void);
static gint   gdk_im_open		(XrmDatabase db,
					 gchar* res_name,
					 gchar* rec_class);
static void   gdk_im_close		(void);
static void   gdk_ic_cleanup 		(void);
#endif /* USE_XIM */

Elliot Lee's avatar
Elliot Lee committed
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 192 193 194 195 196 197 198 199 200 201 202 203 204
/* Private variable declarations
 */
static int initialized = 0;                         /* 1 if the library is initialized,
						     * 0 otherwise.
						     */
static int connection_number = 0;                   /* The file descriptor number of our
						     *  connection to the X server. This
						     *  is used so that we may determine
						     *  when events are pending by using
						     *  the "select" system call.
						     */


static struct timeval start;                        /* The time at which the library was
						     *  last initialized.
						     */
static struct timeval timer;                        /* Timeout interval to use in the call
						     *  to "select". This is used in
						     *  conjunction with "timerp" to create
						     *  a maximum time to wait for an event
						     *  to arrive.
						     */
static struct timeval *timerp;                      /* The actual timer passed to "select"
						     *  This may be NULL, in which case
						     *  "select" will block until an event
						     *  arrives.
						     */
static guint32 timer_val;                           /* The timeout length as specified by
						     *  the user in milliseconds.
						     */
static GList *inputs;                               /* A list of the input file descriptors
						     *  that we care about. Each list node
						     *  contains a GdkInput struct that describes
						     *  when we are interested in the specified
						     *  file descriptor. That is, when it is
						     *  available for read, write or has an
						     *  exception pending.
						     */
static guint32 button_click_time[2];                /* The last 2 button click times. Used
						     *  to determine if the latest button click
						     *  is part of a double or triple click.
						     */
static GdkWindow *button_window[2];                 /* The last 2 windows to receive button presses.
						     *  Also used to determine if the latest button
						     *  click is part of a double or triple click.
						     */
static guint button_number[2];                      /* The last 2 buttons to be pressed.
						     */

205 206 207 208 209 210 211 212 213 214 215
#ifdef USE_XIM
static gint xim_using;				/* using XIM Protocol if TRUE */
static GdkIM xim_im;				/* global IM */
static XIMStyles* xim_styles;			/* im supports these styles */
static XIMStyle xim_best_allowed_style;
static GdkICPrivate *xim_ic;			/* currently using IC */
static GdkWindow* xim_window;			/* currently using Widow */
static GList* xim_ic_list;

#endif

Elliot Lee's avatar
Elliot Lee committed
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 247 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 284 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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
#define OTHER_XEVENT_BUFSIZE 4
static XEvent other_xevent[OTHER_XEVENT_BUFSIZE];   /* XEvents passed along to user  */
static int other_xevent_i = 0;
static GList *putback_events = NULL;

static gulong base_id;
static gint autorepeat;


/*
 *--------------------------------------------------------------
 * gdk_init
 *
 *   Initialize the library for use.
 *
 * Arguments:
 *   "argc" is the number of arguments.
 *   "argv" is an array of strings.
 *
 * Results:
 *   "argc" and "argv" are modified to reflect any arguments
 *   which were not handled. (Such arguments should either
 *   be handled by the application or dismissed).
 *
 * Side effects:
 *   The library is initialized.
 *
 *--------------------------------------------------------------
 */

void
gdk_init (int    *argc,
	  char ***argv)
{
  XKeyboardState keyboard_state;
  int synchronize;
  int i, j, k;
  XClassHint *class_hint;
  int argc_orig = *argc;
  char **argv_orig;

  argv_orig = malloc ((argc_orig + 1) * sizeof (char*));
  for (i = 0; i < argc_orig; i++)
    argv_orig[i] = g_strdup ((*argv)[i]);
  argv_orig[argc_orig] = NULL;

  X_GETTIMEOFDAY (&start);

  signal (SIGHUP, gdk_signal);
  signal (SIGINT, gdk_signal);
  signal (SIGQUIT, gdk_signal);
  signal (SIGBUS, gdk_signal);
  signal (SIGSEGV, gdk_signal);
  signal (SIGPIPE, gdk_signal);
  signal (SIGTERM, gdk_signal);

  gdk_display_name = NULL;

  XSetErrorHandler (gdk_x_error);
  XSetIOErrorHandler (gdk_x_io_error);

  synchronize = FALSE;

  if (argc && argv)
    {
      if (*argc > 0)
	gdk_progname = (*argv)[0];

      for (i = 1; i < *argc;)
	{
	  if (strcmp ("--display", (*argv)[i]) == 0)
	    {
	      (*argv)[i] = NULL;

	      if ((i + 1) < *argc)
		{
		  gdk_display_name = g_strdup ((*argv)[i + 1]);
		  (*argv)[i + 1] = NULL;
		  i += 1;
		}
	    }
	  else if (strcmp ("--sync", (*argv)[i]) == 0)
	    {
	      (*argv)[i] = NULL;
	      synchronize = TRUE;
	    }
	  else if (strcmp ("--show-events", (*argv)[i]) == 0)
	    {
	      (*argv)[i] = NULL;
	      gdk_show_events = TRUE;
	    }
	  else if (strcmp ("--no-show-events", (*argv)[i]) == 0)
	    {
	      (*argv)[i] = NULL;
	      gdk_show_events = FALSE;
	    }
	  else if (strcmp ("--no-xshm", (*argv)[i]) == 0)
	    {
	      (*argv)[i] = NULL;
	      gdk_use_xshm = FALSE;
	    }
	  else if (strcmp ("--debug-level", (*argv)[i]) == 0)
	    {
	      if ((i + 1) < *argc)
		{
		  (*argv)[i++] = NULL;
		  gdk_debug_level = atoi ((*argv)[i]);
		  (*argv)[i] = NULL;
		}
	    }
	  else if (strcmp ("-name", (*argv)[i]) == 0)
	    {
	      if ((i + 1) < *argc)
		{
		  (*argv)[i++] = NULL;
		  gdk_progname = (*argv)[i];
		  (*argv)[i] = NULL;
		}
	    }
	  else if (strcmp ("-class", (*argv)[i]) == 0)
	    {
	      if ((i + 1) < *argc)
		{
		  (*argv)[i++] = NULL;
		  gdk_progclass = (*argv)[i];
		  (*argv)[i] = NULL;
		}
	    }
#ifdef XINPUT_GXI
	  else if (strcmp ("--gxid_host", (*argv)[i]) == 0)
	    {
	      if ((i + 1) < *argc)
		{
		  (*argv)[i++] = NULL;
		  gdk_input_gxid_host = ((*argv)[i]);
		  (*argv)[i] = NULL;
		}
	    }
	  else if (strcmp ("--gxid_port", (*argv)[i]) == 0)
	    {
	      if ((i + 1) < *argc)
		{
		  (*argv)[i++] = NULL;
		  gdk_input_gxid_port = atoi ((*argv)[i]);
		  (*argv)[i] = NULL;
		}
	    }
#endif
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
#ifdef USE_XIM
	  else if (strcmp ("--xim-preedit", (*argv)[i]) == 0)
	    {
	      if ((i + 1) < *argc)
		{
		  (*argv)[i++] = NULL;
		  if (strcmp ("none", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMPreeditNone);
		  else if (strcmp ("nothing", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMPreeditNothing);
		  else if (strcmp ("area", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMPreeditArea);
		  else if (strcmp ("position", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMPreeditPosition);
		  else if (strcmp ("callbacks", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMPreeditCallbacks);
		}
	    }
	  else if (strcmp ("--xim-status", (*argv)[i]) == 0)
	    {
	      if ((i + 1) < *argc)
		{
		  (*argv)[i++] = NULL;
		  if (strcmp ("none", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMStatusNone);
		  else if (strcmp ("nothing", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMStatusNothing);
		  else if (strcmp ("area", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMStatusArea);
		  else if (strcmp ("callbacks", (*argv)[i]) == 0)
		    gdk_im_set_best_style (GdkIMStatusCallbacks);
		}
	    }
#endif

Elliot Lee's avatar
Elliot Lee committed
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
	  i += 1;
	}

      for (i = 1; i < *argc; i++)
	{
	  for (k = i; k < *argc; k++)
	    if ((*argv)[k] != NULL)
	      break;

	  if (k > i)
	    {
	      k -= i;
	      for (j = i + k; j < *argc; j++)
		(*argv)[j-k] = (*argv)[j];
	      *argc -= k;
	    }
	}
    }
  else
    {
      gdk_progname = "<unknown>";
    }

  gdk_display = XOpenDisplay (gdk_display_name);
  if (!gdk_display)
424 425 426 427
    {
      g_warning ("cannot open display: %s", XDisplayName (gdk_display_name));
      exit(1);
    }
Elliot Lee's avatar
Elliot Lee committed
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451

  /* This is really crappy. We have to look into the display structure
   *  to find the base resource id. This is only needed for recording
   *  and playback of events.
   */
  /* base_id = RESOURCE_BASE; */
  base_id = 0;
  if (gdk_show_events)
    g_print ("base id: %lu\n", base_id);

  connection_number = ConnectionNumber (gdk_display);
  if (gdk_debug_level >= 1)
    g_print ("connection number: %d\n", connection_number);

  if (synchronize)
    XSynchronize (gdk_display, True);

  gdk_screen = DefaultScreen (gdk_display);
  gdk_root_window = RootWindow (gdk_display, gdk_screen);

  gdk_leader_window = XCreateSimpleWindow(gdk_display, gdk_root_window,
					  10, 10, 10, 10, 0, 0 , 0);
  class_hint = XAllocClassHint();
  class_hint->res_name = gdk_progname;
452 453 454 455 456
  if (gdk_progclass == NULL)
    {
      gdk_progclass = strdup (gdk_progname);
      gdk_progclass[0] = toupper (gdk_progclass[0]);
    }
Elliot Lee's avatar
Elliot Lee committed
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
  class_hint->res_class = gdk_progclass;
  XSetClassHint(gdk_display, gdk_leader_window, class_hint);
  XSetCommand(gdk_display, gdk_leader_window, argv_orig, argc_orig);
  XFree (class_hint);

  gdk_wm_delete_window = XInternAtom (gdk_display, "WM_DELETE_WINDOW", True);
  gdk_wm_take_focus = XInternAtom (gdk_display, "WM_TAKE_FOCUS", True);
  gdk_wm_protocols = XInternAtom (gdk_display, "WM_PROTOCOLS", True);
  gdk_wm_window_protocols[0] = gdk_wm_delete_window;
  gdk_wm_window_protocols[1] = gdk_wm_take_focus;
  gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);

  gdk_dnd.gdk_XdeEnter = gdk_atom_intern("_XDE_ENTER", FALSE);
  gdk_dnd.gdk_XdeLeave = gdk_atom_intern("_XDE_LEAVE", FALSE);
  gdk_dnd.gdk_XdeRequest = gdk_atom_intern("_XDE_REQUEST", FALSE);
  gdk_dnd.gdk_XdeDataAvailable = gdk_atom_intern("_XDE_DATA_AVAILABLE", FALSE);
  gdk_dnd.gdk_XdeTypelist = gdk_atom_intern("_XDE_TYPELIST", FALSE);
  gdk_dnd.gdk_cursor_dragdefault = XCreateFontCursor(gdk_display, XC_bogosity);
  gdk_dnd.gdk_cursor_dragok = XCreateFontCursor(gdk_display, XC_heart);

  XGetKeyboardControl (gdk_display, &keyboard_state);
  autorepeat = keyboard_state.global_auto_repeat;

  timer.tv_sec = 0;
  timer.tv_usec = 0;
  timerp = NULL;

  button_click_time[0] = 0;
  button_click_time[1] = 0;
  button_window[0] = NULL;
  button_window[1] = NULL;
  button_number[0] = -1;
  button_number[1] = -1;

  if (ATEXIT (gdk_exit_func))
    g_warning ("unable to register exit function");

  gdk_visual_init ();
  gdk_window_init ();
  gdk_image_init ();
  gdk_input_init ();

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515
#ifdef USE_XIM
  /* initialize XIM Protocol variables */
  xim_using = FALSE;
  xim_im = NULL;
  xim_styles = NULL;
  if (!(xim_best_allowed_style & GdkIMPreeditMask))
    gdk_im_set_best_style (GdkIMPreeditCallbacks);
  if (!(xim_best_allowed_style & GdkIMStatusMask))
    gdk_im_set_best_style (GdkIMStatusCallbacks);
  xim_ic = NULL;
  xim_window = (GdkWindow*)NULL;

  gdk_im_open (NULL, NULL, NULL);
  if (gdk_im_get () == NULL)
    g_warning ("unable to open input method.");
#endif

Elliot Lee's avatar
Elliot Lee committed
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 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 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
  initialized = 1;
}

/*
 *--------------------------------------------------------------
 * gdk_exit
 *
 *   Restores the library to an un-itialized state and exits
 *   the program using the "exit" system call.
 *
 * Arguments:
 *   "errorcode" is the error value to pass to "exit".
 *
 * Results:
 *   Allocated structures are freed and the program exits
 *   cleanly.
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

void
gdk_exit (int errorcode)
{
 /* de-initialisation is done by the gdk_exit_funct(),
    no need to do this here (Alex J.) */
 exit (errorcode);
}

/*
 *--------------------------------------------------------------
 * gdk_set_locale
 *
 * Arguments:
 *
 * Results:
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

gchar*
gdk_set_locale ()
{
  if (!setlocale (LC_ALL,""))
    g_print ("locale not supported by C library\n");

  if (!XSupportsLocale ())
    {
      g_print ("locale not supported by Xlib, locale set to C\n");
      setlocale (LC_ALL, "C");
    }

  if (!XSetLocaleModifiers (""))
    {
      g_print ("can not set locale modifiers\n");
    }

  return setlocale (LC_ALL,NULL);
}

/*
 *--------------------------------------------------------------
 * gdk_events_pending
 *
 *   Returns the number of events pending on the queue.
 *   These events have already been read from the server
 *   connection.
 *
 * Arguments:
 *
 * Results:
 *   Returns the number of events on XLib's event queue.
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

gint
gdk_events_pending ()
{
  return XPending (gdk_display);
}

603 604 605 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 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
/*
 *--------------------------------------------------------------
 * gdk_event_get_graphics_expose
 *
 *   Waits for a GraphicsExpose or NoExpose event
 *
 * Arguments:
 *
 * Results: 
 *   For GraphicsExpose events, returns a pointer to the event
 *   converted into a GdkEvent Otherwise, returns NULL.
 *
 * Side effects:
 *
 *-------------------------------------------------------------- */

static Bool
graphics_expose_predicate  (Display  *display,
			    XEvent   *xevent,
			    XPointer  arg)
{
  GdkWindowPrivate *private = (GdkWindowPrivate *)arg;

  if ((xevent->xany.window == private->xwindow) &&
      ((xevent->xany.type == GraphicsExpose) ||
       (xevent->xany.type == NoExpose)))
    return True;
  else
    return False;
}

GdkEvent *
gdk_event_get_graphics_expose (GdkWindow *window)
{
  XEvent xevent;
  GdkEvent *event;

  XIfEvent (gdk_display, &xevent, graphics_expose_predicate, (XPointer)window);

  if (xevent.xany.type == GraphicsExpose)
    {
      event = gdk_event_new ();

      if (gdk_event_translate (event, &xevent))
	return event;
      else
	gdk_event_free (event);
    }
  
  return NULL;  
}

Elliot Lee's avatar
Elliot Lee committed
655 656 657 658 659 660 661 662 663
/*
 *--------------------------------------------------------------
 * gdk_event_get
 *
 *   Gets the next event.
 *
 * Arguments:
 *
 * Results:
664 665 666
 *   If an event was received that we care about, returns 
 *   a pointer to that event, to be freed with gdk_event_free.
 *   Otherwise, returns NULL. This function will also return
Elliot Lee's avatar
Elliot Lee committed
667 668 669 670 671 672 673 674
 *   before an event is received if the timeout interval
 *   runs out.
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

675 676
GdkEvent *
gdk_event_get (void)
Elliot Lee's avatar
Elliot Lee committed
677
{
678
  GdkEvent *event;
Elliot Lee's avatar
Elliot Lee committed
679 680 681
  GList *temp_list;
  XEvent xevent;

682
#if 0
Elliot Lee's avatar
Elliot Lee committed
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704
  if (pred)
    {
      temp_list = putback_events;
      while (temp_list)
	{
	  temp_event = temp_list->data;

	  if ((* pred) (temp_event, data))
	    {
	      if (event)
		*event = *temp_event;
	      putback_events = g_list_remove_link (putback_events, temp_list);
	      g_list_free (temp_list);
	      return TRUE;
	    }

	  temp_list = temp_list->next;
	}

      event_pred.func = pred;
      event_pred.data = data;

705
      if (XCheckIfEvent (gdk_display, &xevent, gdk_event_get_type, (XPointer) & event_pred))
Elliot Lee's avatar
Elliot Lee committed
706 707 708 709
	if (event)
	  return gdk_event_translate (event, &xevent);
    }
  else
710 711
#endif
  if (putback_events)
Elliot Lee's avatar
Elliot Lee committed
712
    {
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
      event = putback_events->data;
      
      temp_list = putback_events;
      putback_events = g_list_remove_link (putback_events, temp_list);
      g_list_free_1 (temp_list);
      
      return event;
    }
  
  /* Wait for an event to occur or the timeout to elapse.
   * If an event occurs "gdk_event_wait" will return TRUE.
   *  If the timeout elapses "gdk_event_wait" will return
   *  FALSE.
   */
  if (gdk_event_wait ())
    {
      /* If we get here we can rest assurred that an event
       *  has occurred. Read it.
Elliot Lee's avatar
Elliot Lee committed
731
       */
732
#ifdef USE_XIM
733 734 735 736
      gint filter_status;
      if (xim_using && xim_window)
	do
	  {		/* don't dispatch events used by IM */
737
	    XNextEvent (gdk_display, &xevent);
738 739 740 741 742
	    filter_status = XFilterEvent (&xevent, 
					  GDK_WINDOW_XWINDOW (xim_window));
	  } while (filter_status == True);
      else
	XNextEvent (gdk_display, &xevent);
743
#else
744
      XNextEvent (gdk_display, &xevent);
745
#endif
746
      event = gdk_event_new ();
Elliot Lee's avatar
Elliot Lee committed
747

748 749 750 751 752 753 754 755 756
      event->any.type = GDK_NOTHING;
      event->any.window = NULL;
      event->any.send_event = FALSE;
      event->any.send_event = xevent.xany.send_event;
      
      if (gdk_event_translate (event, &xevent))
	return event;
      else
	gdk_event_free (event);
Elliot Lee's avatar
Elliot Lee committed
757 758
    }

759
  return NULL;
Elliot Lee's avatar
Elliot Lee committed
760 761 762 763 764 765 766 767 768
}

void
gdk_event_put (GdkEvent *event)
{
  GdkEvent *new_event;

  g_return_if_fail (event != NULL);

769
  new_event = gdk_event_copy (event);
Elliot Lee's avatar
Elliot Lee committed
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793

  putback_events = g_list_prepend (putback_events, new_event);
}

/*
 *--------------------------------------------------------------
 * gdk_event_copy
 *
 *   Copy a event structure into new storage.
 *
 * Arguments:
 *   "event" is the event struct to copy.
 *
 * Results:
 *   A new event structure.  Free it with gdk_event_free.
 *
 * Side effects:
 *   The reference count of the window in the event is increased.
 *
 *--------------------------------------------------------------
 */

static GMemChunk *event_chunk;

794 795
static GdkEvent*
gdk_event_new (void)
Elliot Lee's avatar
Elliot Lee committed
796 797 798 799 800 801 802 803 804 805
{
  GdkEvent *new_event;
  
  if (event_chunk == NULL)
    event_chunk = g_mem_chunk_new ("events",
				   sizeof (GdkEvent),
				   4096,
				   G_ALLOC_AND_FREE);

  new_event = g_chunk_new (GdkEvent, event_chunk);
806 807 808 809 810 811 812 813 814 815 816 817 818

  return new_event;
}

GdkEvent*
gdk_event_copy (GdkEvent *event)
{
  GdkEvent *new_event;
  
  g_return_val_if_fail (event != NULL, NULL);

  new_event = gdk_event_new ();

Elliot Lee's avatar
Elliot Lee committed
819 820
  *new_event = *event;
  gdk_window_ref (new_event->any.window);
821 822 823 824 825 826 827 828 829 830

  if ((event->any.type == GDK_KEY_PRESS) ||
      (event->any.type == GDK_KEY_RELEASE))
    new_event->key.string = g_strdup (event->key.string);

  if (((event->any.type == GDK_ENTER_NOTIFY) ||
       (event->any.type == GDK_LEAVE_NOTIFY)) &&
      (event->crossing.subwindow != NULL))
    gdk_window_ref (event->crossing.subwindow);

Elliot Lee's avatar
Elliot Lee committed
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857
  return new_event;
}

/*
 *--------------------------------------------------------------
 * gdk_event_free
 *
 *   Free a event structure obtained from gdk_event_copy.  Do not use
 *   with other event structures.
 *
 * Arguments:
 *   "event" is the event struct to free.
 *
 * Results:
 *
 * Side effects:
 *   The reference count of the window in the event is decreased and
 *   might be freed, too.
 *
 *-------------------------------------------------------------- */

void
gdk_event_free (GdkEvent *event)
{
  g_assert (event_chunk != NULL);
  g_return_if_fail (event != NULL);

858 859 860 861 862 863 864 865 866 867 868 869
  if ((event->any.type == GDK_KEY_PRESS) ||
      (event->any.type == GDK_KEY_RELEASE))
    g_free (event->key.string);

  if (event->any.window)
    gdk_window_unref (event->any.window);

  if (((event->any.type == GDK_ENTER_NOTIFY) ||
       (event->any.type == GDK_LEAVE_NOTIFY)) &&
      (event->crossing.subwindow != NULL))
    gdk_window_unref (event->crossing.subwindow);

Elliot Lee's avatar
Elliot Lee committed
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 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 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 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 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
  g_mem_chunk_free (event_chunk, event);
}

/*
 *--------------------------------------------------------------
 * gdk_set_debug_level
 *
 *   Sets the debugging level.
 *
 * Arguments:
 *   "level" is the new debugging level.
 *
 * Results:
 *
 * Side effects:
 *   Other function calls to "gdk" use the debugging
 *   level to determine what kind of debugging information
 *   to print out.
 *
 *--------------------------------------------------------------
 */

void
gdk_set_debug_level (int level)
{
  gdk_debug_level = level;
}

/*
 *--------------------------------------------------------------
 * gdk_set_show_events
 *
 *   Turns on/off the showing of events.
 *
 * Arguments:
 *   "show_events" is a boolean describing whether or
 *   not to show the events gdk receives.
 *
 * Results:
 *
 * Side effects:
 *   When "show_events" is TRUE, calls to "gdk_event_get"
 *   will output debugging informatin regarding the event
 *   received to stdout.
 *
 *--------------------------------------------------------------
 */

void
gdk_set_show_events (int show_events)
{
  gdk_show_events = show_events;
}

void
gdk_set_use_xshm (gint use_xshm)
{
  gdk_use_xshm = use_xshm;
}

gint
gdk_get_debug_level ()
{
  return gdk_debug_level;
}

gint
gdk_get_show_events ()
{
  return gdk_show_events;
}

gint
gdk_get_use_xshm ()
{
  return gdk_use_xshm;
}

/*
 *--------------------------------------------------------------
 * gdk_time_get
 *
 *   Get the number of milliseconds since the library was
 *   initialized.
 *
 * Arguments:
 *
 * Results:
 *   The time since the library was initialized is returned.
 *   This time value is accurate to milliseconds even though
 *   a more accurate time down to the microsecond could be
 *   returned.
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

guint32
gdk_time_get ()
{
  struct timeval end;
  struct timeval elapsed;
  guint32 milliseconds;

  X_GETTIMEOFDAY (&end);

  if (start.tv_usec > end.tv_usec)
    {
      end.tv_usec += 1000000;
      end.tv_sec--;
    }
  elapsed.tv_sec = end.tv_sec - start.tv_sec;
  elapsed.tv_usec = end.tv_usec - start.tv_usec;

  milliseconds = (elapsed.tv_sec * 1000) + (elapsed.tv_usec / 1000);

  return milliseconds;
}

/*
 *--------------------------------------------------------------
 * gdk_timer_get
 *
 *   Returns the current timer.
 *
 * Arguments:
 *
 * Results:
 *   Returns the current timer interval. This interval is
 *   in units of milliseconds.
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

guint32
gdk_timer_get ()
{
  return timer_val;
}

/*
 *--------------------------------------------------------------
 * gdk_timer_set
 *
 *   Sets the timer interval.
 *
 * Arguments:
 *   "milliseconds" is the new value for the timer.
 *
 * Results:
 *
 * Side effects:
 *   Calls to "gdk_event_get" will last for a maximum
 *   of time of "milliseconds". However, a value of 0
 *   milliseconds will cause "gdk_event_get" to block
 *   indefinately until an event is received.
 *
 *--------------------------------------------------------------
 */

void
gdk_timer_set (guint32 milliseconds)
{
  timer_val = milliseconds;
  timer.tv_sec = milliseconds / 1000;
  timer.tv_usec = (milliseconds % 1000) * 1000;

}

void
gdk_timer_enable ()
{
  timerp = &timer;
}

void
gdk_timer_disable ()
{
  timerp = NULL;
}

gint
1055 1056 1057 1058 1059
gdk_input_add_interp (gint              source,
		      GdkInputCondition condition,
		      GdkInputFunction  function,
		      gpointer          data,
		      GdkDestroyNotify  destroy)
Elliot Lee's avatar
Elliot Lee committed
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075
{
  static gint next_tag = 1;
  GList *list;
  GdkInput *input;
  gint tag;

  tag = 0;
  list = inputs;

  while (list)
    {
      input = list->data;
      list = list->next;

      if ((input->source == source) && (input->condition == condition))
	{
1076 1077
	  if (input->destroy)
	    (input->destroy) (input->data);
Elliot Lee's avatar
Elliot Lee committed
1078 1079
	  input->function = function;
	  input->data = data;
1080
	  input->destroy = destroy;
Elliot Lee's avatar
Elliot Lee committed
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092
	  tag = input->tag;
	}
    }

  if (!tag)
    {
      input = g_new (GdkInput, 1);
      input->tag = next_tag++;
      input->source = source;
      input->condition = condition;
      input->function = function;
      input->data = data;
1093
      input->destroy = destroy;
Elliot Lee's avatar
Elliot Lee committed
1094 1095 1096 1097 1098 1099 1100 1101
      tag = input->tag;

      inputs = g_list_prepend (inputs, input);
    }

  return tag;
}

1102 1103 1104 1105 1106 1107 1108 1109 1110
gint
gdk_input_add (gint              source,
	       GdkInputCondition condition,
	       GdkInputFunction  function,
	       gpointer          data)
{
  return gdk_input_add_interp (source, condition, function, data, NULL);
}

Elliot Lee's avatar
Elliot Lee committed
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124
void
gdk_input_remove (gint tag)
{
  GList *list;
  GList *temp_list;
  GdkInput *input;

  list = inputs;
  while (list)
    {
      input = list->data;

      if (input->tag == tag)
	{
1125 1126 1127
	  if (input->destroy)
	    (input->destroy) (input->data);

Elliot Lee's avatar
Elliot Lee committed
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 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 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 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 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 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 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533
	  temp_list = list;

	  if (list->next)
	    list->next->prev = list->prev;
	  if (list->prev)
	    list->prev->next = list->next;
	  if (inputs == list)
	    inputs = list->next;

	  temp_list->next = NULL;
	  temp_list->prev = NULL;

	  g_free (temp_list->data);
	  g_list_free (temp_list);
	  break;
	}

      list = list->next;
    }
}

/*
 *--------------------------------------------------------------
 * gdk_pointer_grab
 *
 *   Grabs the pointer to a specific window
 *
 * Arguments:
 *   "window" is the window which will receive the grab
 *   "owner_events" specifies whether events will be reported as is,
 *     or relative to "window"
 *   "event_mask" masks only interesting events
 *   "confine_to" limits the cursor movement to the specified window
 *   "cursor" changes the cursor for the duration of the grab
 *   "time" specifies the time
 *
 * Results:
 *
 * Side effects:
 *   requires a corresponding call to gdk_pointer_ungrab
 *
 *--------------------------------------------------------------
 */

gint
gdk_pointer_grab (GdkWindow *     window,
		  gint            owner_events,
		  GdkEventMask    event_mask,
		  GdkWindow *     confine_to,
		  GdkCursor *     cursor,
		  guint32         time)
{
  /*  From gdkwindow.c  */
  extern int nevent_masks;
  extern int event_mask_table[];

  gint return_val;
  GdkWindowPrivate *window_private;
  GdkWindowPrivate *confine_to_private;
  GdkCursorPrivate *cursor_private;
  guint xevent_mask;
  Window xwindow;
  Window xconfine_to;
  Cursor xcursor;
  int i;

  g_return_val_if_fail (window != NULL, 0);

  window_private = (GdkWindowPrivate*) window;
  confine_to_private = (GdkWindowPrivate*) confine_to;
  cursor_private = (GdkCursorPrivate*) cursor;

  xwindow = window_private->xwindow;

  if (!confine_to)
    xconfine_to = None;
  else
    xconfine_to = confine_to_private->xwindow;

  if (!cursor)
    xcursor = None;
  else
    xcursor = cursor_private->xcursor;


  xevent_mask = 0;
  for (i = 0; i < nevent_masks; i++)
    {
      if (event_mask & (1 << (i + 1)))
	xevent_mask |= event_mask_table[i];
    }

  if (((GdkWindowPrivate *)window)->extension_events &&
      gdk_input_vtable.grab_pointer)
    return_val = gdk_input_vtable.grab_pointer (window,
						owner_events,
						event_mask,
						confine_to,
						time);
  else
    return_val = Success;;

  if (return_val == Success)
    return_val = XGrabPointer (window_private->xdisplay,
			       xwindow,
			       owner_events,
			       xevent_mask,
			       GrabModeAsync, GrabModeAsync,
			       xconfine_to,
			       xcursor,
			       time);

  return return_val;
}

/*
 *--------------------------------------------------------------
 * gdk_pointer_ungrab
 *
 *   Releases any pointer grab
 *
 * Arguments:
 *
 * Results:
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

void
gdk_pointer_ungrab (guint32 time)
{
  if (gdk_input_vtable.ungrab_pointer)
    gdk_input_vtable.ungrab_pointer (time);

  XUngrabPointer (gdk_display, time);
}

/*
 *--------------------------------------------------------------
 * gdk_keyboard_grab
 *
 *   Grabs the keyboard to a specific window
 *
 * Arguments:
 *   "window" is the window which will receive the grab
 *   "owner_events" specifies whether events will be reported as is,
 *     or relative to "window"
 *   "time" specifies the time
 *
 * Results:
 *
 * Side effects:
 *   requires a corresponding call to gdk_keyboard_ungrab
 *
 *--------------------------------------------------------------
 */

gint
gdk_keyboard_grab (GdkWindow *     window,
                   gint            owner_events,
                   guint32         time)
{
  GdkWindowPrivate *window_private;
  Window xwindow;

  g_return_val_if_fail (window != NULL, 0);

  window_private = (GdkWindowPrivate*) window;
  xwindow = window_private->xwindow;

  return XGrabKeyboard (window_private->xdisplay,
			xwindow,
			owner_events,
			GrabModeAsync, GrabModeAsync,
			time);
}

/*
 *--------------------------------------------------------------
 * gdk_keyboard_ungrab
 *
 *   Releases any keyboard grab
 *
 * Arguments:
 *
 * Results:
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

void
gdk_keyboard_ungrab (guint32 time)
{
  XUngrabKeyboard (gdk_display, time);
}

/*
 *--------------------------------------------------------------
 * gdk_screen_width
 *
 *   Return the width of the screen.
 *
 * Arguments:
 *
 * Results:
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

gint
gdk_screen_width ()
{
  gint return_val;

  return_val = DisplayWidth (gdk_display, gdk_screen);

  return return_val;
}

/*
 *--------------------------------------------------------------
 * gdk_screen_height
 *
 *   Return the height of the screen.
 *
 * Arguments:
 *
 * Results:
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

gint
gdk_screen_height ()
{
  gint return_val;

  return_val = DisplayHeight (gdk_display, gdk_screen);

  return return_val;
}

void
gdk_key_repeat_disable ()
{
  XAutoRepeatOff (gdk_display);
}

void
gdk_key_repeat_restore ()
{
  if (autorepeat)
    XAutoRepeatOn (gdk_display);
  else
    XAutoRepeatOff (gdk_display);
}


/*
 *--------------------------------------------------------------
 * gdk_flush
 *
 *   Flushes the Xlib output buffer and then waits
 *   until all requests have been received and processed
 *   by the X server. The only real use for this function
 *   is in dealing with XShm.
 *
 * Arguments:
 *
 * Results:
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

void gdk_flush ()
{
  XSync (gdk_display, False);
}


void
gdk_beep ()
{
  XBell(gdk_display, 100);
}


/*
 *--------------------------------------------------------------
 * gdk_event_wait
 *
 *   Waits until an event occurs or the timer runs out.
 *
 * Arguments:
 *
 * Results:
 *   Returns TRUE if an event is ready to be read and FALSE
 *   if the timer ran out.
 *
 * Side effects:
 *
 *--------------------------------------------------------------
 */

static gint
gdk_event_wait ()
{
  GList *list;
  GdkInput *input;
  GdkInputCondition condition;
  SELECT_MASK readfds;
  SELECT_MASK writefds;
  SELECT_MASK exceptfds;
  int max_input;
  int nfd;

  /* If there are no events pending we will wait for an event.
   * The time we wait is dependant on the "timer". If no timer
   *  has been specified then we'll block until an event arrives.
   *  If a timer has been specified we'll block until an event
   *  arrives or the timer expires. (This is all done using the
   *  "select" system call).
   */

  if (XPending (gdk_display) == 0)
    {
      FD_ZERO (&readfds);
      FD_ZERO (&writefds);
      FD_ZERO (&exceptfds);

      FD_SET (connection_number, &readfds);
      max_input = connection_number;

      list = inputs;
      while (list)
	{
	  input = list->data;
	  list = list->next;

	  if (input->condition & GDK_INPUT_READ)
	    FD_SET (input->source, &readfds);
	  if (input->condition & GDK_INPUT_WRITE)
	    FD_SET (input->source, &writefds);
	  if (input->condition & GDK_INPUT_EXCEPTION)
	    FD_SET (input->source, &exceptfds);

	  max_input = MAX (max_input, input->source);
	}

      nfd = select (max_input+1, &readfds, &writefds, &exceptfds, timerp);

      timerp = NULL;
      timer_val = 0;

      if (nfd > 0)
	{
	  if (FD_ISSET (connection_number, &readfds))
	    {
	      if (XPending (gdk_display) == 0)
		{
		  if (nfd == 1)
		    {
		      XNoOp (gdk_display);
		      XFlush (gdk_display);
		    }
		  return FALSE;
		}
	      else
		return TRUE;
	    }

	  list = inputs;
	  while (list)
	    {
	      input = list->data;
	      list = list->next;

	      condition = 0;
	      if (FD_ISSET (input->source, &readfds))
		condition |= GDK_INPUT_READ;
	      if (FD_ISSET (input->source, &writefds))
		condition |= GDK_INPUT_WRITE;
	      if (FD_ISSET (input->source, &exceptfds))
		condition |= GDK_INPUT_EXCEPTION;

	      if (condition && input->function)
		(* input->function) (input->data, input->source, condition);
	    }
	}
    }
  else
    return TRUE;

  return FALSE;
}

1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
static gint
gdk_event_apply_filters (XEvent *xevent,
			 GdkEvent *event,
			 GList *filters)
{
  GdkEventFilter *filter;
  GList *tmp_list;
  GdkFilterReturn result;

  tmp_list = filters;
  
  while (tmp_list)
    {
      filter = (GdkEventFilter *)tmp_list->data;

      result = (*filter->function)(xevent, event, filter->data);
      if (result !=  GDK_FILTER_CONTINUE)
	return result;
	
      tmp_list = tmp_list->next;
    }

  return GDK_FILTER_CONTINUE;
}

Elliot Lee's avatar
Elliot Lee committed
1559 1560 1561 1562 1563 1564 1565 1566 1567
static gint
gdk_event_translate (GdkEvent *event,
		     XEvent   *xevent)
{

  GdkWindow *window;
  GdkWindowPrivate *window_private;
  XComposeStatus compose;
  int charcount;
1568 1569 1570 1571
#ifdef USE_XIM
  static gchar* buf = NULL;
  static gint buf_len= 0;
#else
Elliot Lee's avatar
Elliot Lee committed
1572
  char buf[16];
1573
#endif
Elliot Lee's avatar
Elliot Lee committed
1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608
  gint return_val;

  /* Are static variables used for this purpose thread-safe? */
  static GdkPoint dnd_drag_start = {0,0},
		  dnd_drag_oldpos = {0,0};
  static GdkRectangle dnd_drag_dropzone = {0,0,0,0};
  static gint dnd_drag_perhaps = 0;
  static GdkWindowPrivate *real_sw = NULL;
  static Window dnd_drag_curwin = None, dnd_drag_target = None;

  return_val = FALSE;

  /* Find the GdkWindow that this event occurred in.
   * All events occur in some GdkWindow (otherwise, why
   *  would we be receiving them). It really is an error
   *  to receive an event for which we cannot find the
   *  corresponding GdkWindow. We handle events with window=None
   *  specially - they are generated by XFree86's XInput under
   *  some circumstances.
   */

  if ((xevent->xany.window == None) &&
      gdk_input_vtable.window_none_event)
    {
      return_val = gdk_input_vtable.window_none_event (event,xevent);

      if (return_val >= 0)	/* was handled */
	return return_val;
      else
	return_val = FALSE;
    }

  window = gdk_window_lookup (xevent->xany.window);
  window_private = (GdkWindowPrivate *) window;

1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627
  if (window == NULL)
    g_warning ("%#lx -> NULL\n", xevent->xany.window);
  else
    gdk_window_ref (window);


  /* Check for filters for this window */

  if (window_private)
    {
      GdkFilterReturn result;
      result = gdk_event_apply_filters (xevent, event, window_private->filters);

      if (result != GDK_FILTER_CONTINUE)
	{
	  return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
	}
    }

Elliot Lee's avatar
Elliot Lee committed
1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642
  /* 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.
   */
  /* Addendum:
   * During drag & drop you get events where the pointer is
   * in other windows. Need to just do finer-grained checking
   */
  switch (xevent->type)
    {
    case KeyPress:
      /* Lookup the string corresponding to the given keysym.
       */
1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
#ifdef USE_XIM
      if (buf_len == 0) 
        {
	  buf_len = 128;
	  buf = g_new (gchar, buf_len);
	}
      if (xim_using == TRUE && xim_ic)
	{
	  Status status;
	  
	  /* Clear keyval. Depending on status, may not be set */
	  event->key.keyval = GDK_VoidSymbol;
	  charcount = XmbLookupString(xim_ic->xic,
				      &xevent->xkey, buf, buf_len-1,
				      (KeySym*) &event->key.keyval,
				      &status);
	  if (status == XBufferOverflow)
	    {                     /* retry */
	      /* alloc adequate size of buffer */
	      if (gdk_debug_level >= 1)
1663
		g_print("XIM: overflow (required %i)\n", charcount);
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684

	      while (buf_len <= charcount)
		buf_len *= 2;
	      buf = (gchar *) g_realloc (buf, buf_len);
	     
	      charcount = XmbLookupString (xim_ic->xic,
					   &xevent->xkey, buf, buf_len-1,
					   (KeySym*) &event->key.keyval,
					   &status);
	    }
	  if (status == XLookupNone)
	    {
	      return_val = FALSE;
	      break;
	    }
	}
      else
	charcount = XLookupString (&xevent->xkey, buf, buf_len,
				   (KeySym*) &event->key.keyval,
				   &compose);
#else
Elliot Lee's avatar
Elliot Lee committed
1685 1686 1687
      charcount = XLookupString (&xevent->xkey, buf, 16,
				 (KeySym*) &event->key.keyval,
				 &compose);
1688 1689 1690 1691 1692
#endif
      if (charcount > 0 && buf[charcount-1] == '\0')
	charcount --;
      else
	buf[charcount] = '\0';
Elliot Lee's avatar
Elliot Lee committed
1693 1694 1695 1696

      /* Print debugging info.
       */
      if (gdk_show_events)
1697 1698 1699 1700 1701 1702 1703 1704 1705
	{
	  g_print ("key press:\twindow: %ld  key: %12s  %d\n",
		   xevent->xkey.window - base_id,
		   event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
		   event->key.keyval);
	  if (charcount > 0)
	    g_print ("\t\tlength: %4d string: \"%s\"\n",
		     charcount, buf);
	}
Elliot Lee's avatar
Elliot Lee committed
1706 1707 1708 1709 1710

      event->key.type = GDK_KEY_PRESS;
      event->key.window = window;
      event->key.time = xevent->xkey.time;
      event->key.state = (GdkModifierType) xevent->xkey.state;
1711
      event->key.string = g_strdup (buf);
1712
      event->key.length = charcount;
Elliot Lee's avatar
Elliot Lee committed
1713

1714
      return_val = window_private && !window_private->destroyed;
1715 1716 1717 1718
      
      if (!return_val)
	g_free (event->key.string);
      
Elliot Lee's avatar
Elliot Lee committed
1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739
      break;

    case KeyRelease:
      /* Lookup the string corresponding to the given keysym.
       */
      charcount = XLookupString (&xevent->xkey, buf, 16,
				 (KeySym*) &event->key.keyval,
				 &compose);

      /* Print debugging info.
       */
      if (gdk_show_events)
	g_print ("key release:\t\twindow: %ld  key: %12s  %d\n",
		 xevent->xkey.window - base_id,
		 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;
1740 1741
      event->key.length = 0;
      event->key.string = NULL;
Elliot Lee's avatar
Elliot Lee committed
1742

1743
      return_val = window_private && !window_private->destroyed;
Elliot Lee's avatar
Elliot Lee committed
1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843
      break;

    case ButtonPress:
      /* Print debugging info.
       */
      if (gdk_show_events)
	g_print ("button press[%d]:\t\twindow: %ld  x,y: %d %d  button: %d\n",
		 window_private?window_private->dnd_drag_enabled:0,
		 xevent->xbutton.window - base_id,
		 xevent->xbutton.x, xevent->xbutton.y,
		 xevent->xbutton.button);

      if (window_private &&
	  (window_private->extension_events != 0) &&
	  gdk_input_ignore_core)
	break;

      event->button.type = GDK_BUTTON_PRESS;
      event->button.window = window;
      event->button.time = xevent->xbutton.time;
      event->button.x = xevent->xbutton.x;
      event->button.y = xevent->xbutton.y;
      event->button.pressure = 0.5;
      event->button.xtilt = 0;
      event->button.ytilt = 0;
      event->button.state = (GdkModifierType) xevent->xbutton.state;
      event->button.button = xevent->xbutton.button;
      event->button.source = GDK_SOURCE_MOUSE;
      event->button.deviceid = GDK_CORE_POINTER;

      if ((event->button.time < (button_click_time[1] + TRIPLE_CLICK_TIME)) &&
	  (event->button.window == button_window[1]) &&
	  (event->button.button == button_number[1]))
	{
	  gdk_synthesize_click (event, 3);

	  button_click_time[1] = 0;
	  button_click_time[0] = 0;
	  button_window[1] = NULL;
	  button_window[0] = 0;
	  button_number[1] = -1;
	  button_number[0] = -1;
	}
      else if ((event->button.time < (button_click_time[0] + DOUBLE_CLICK_TIME)) &&
	       (event->button.window == button_window[0]) &&
	       (event->button.button == button_number[0]))
	{
	  gdk_synthesize_click (event, 2);

	  button_click_time[1] = button_click_time[0];
	  button_click_time[0] = event->button.time;
	  button_window[1] = button_window[0];
	  button_window[0] = event->button.window;
	  button_number[1] = button_number[0];
	  button_number[0] = event->button.button;
	}
      else
	{
	  button_click_time[1] = 0;
	  button_click_time[0] = event->button.time;
	  button_window[1] = NULL;
	  button_window[0] = event->button.window;
	  button_number[1] = -1;
	  button_number[0] = event->button.button;
	}
      if(window_private
	 && window_private->dnd_drag_enabled
	 && !dnd_drag_perhaps
	 && !gdk_dnd.drag_really)
	{
	  dnd_drag_perhaps = 1;
	  dnd_drag_start.x = xevent->xbutton.x_root;
	  dnd_drag_start.y = xevent->xbutton.y_root;
	  real_sw = window_private;
	  
	  if(gdk_dnd.drag_startwindows)
	    {
	      g_free(gdk_dnd.drag_startwindows);
	      gdk_dnd.drag_startwindows = NULL;
	    }
	  gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0;

	  {
	    /* Set motion mask for first DnD'd window, since it
	       will be the one that is actually dragged */
	    XWindowAttributes dnd_winattr;
	    XSetWindowAttributes dnd_setwinattr;

	    /* We need to get motion events while the button is down, so
	       we can know whether to really start dragging or not... */
	    XGetWindowAttributes(gdk_display, (Window)window_private->xwindow,
				 &dnd_winattr);
	    
	    window_private->dnd_drag_savedeventmask = dnd_winattr.your_event_mask;
	    dnd_setwinattr.event_mask = 
	      window_private->dnd_drag_eventmask = ButtonMotionMask;
	    XChangeWindowAttributes(gdk_display, window_private->xwindow,
				    CWEventMask, &dnd_setwinattr);
	}
      }
1844
      return_val = window_private && !window_private->destroyed;
Elliot Lee's avatar
Elliot Lee committed
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866
      break;

    case ButtonRelease:
      /* Print debugging info.
       */
      if (gdk_show_events)
	g_print ("button release[%d]:\twindow: %ld  x,y: %d %d  button: %d\n",
		 window_private?window_private->dnd_drag_enabled:0,
		 xevent->xbutton.window - base_id,
		 xevent->xbutton.x, xevent->xbutton.y,
		 xevent->xbutton.button);

      if (window_private &&
	  (window_private->extension_events != 0) &&
	  gdk_input_ignore_core)
	break;

      event->button.type = GDK_BUTTON_RELEASE;
      event->button.window = window;
      event->button.time = xevent->xbutton.time;
      event->button.x = xevent->xbutton.x;
      event->button.y = xevent->xbutton.y;
1867 1868
      event->button.x_root = xevent->xbutton.x_root;
      event->button.y_root = xevent->xbutton.y_root;
Elliot Lee's avatar
Elliot Lee committed
1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880
      event->button.pressure = 0.5;
      event->button.xtilt = 0;
      event->button.ytilt = 0;
      event->button.state = (GdkModifierType) xevent->xbutton.state;
      event->button.button = xevent->xbutton.button;
      event->button.source = GDK_SOURCE_MOUSE;
      event->button.deviceid = GDK_CORE_POINTER;

      if(dnd_drag_perhaps)
	{
	if(gdk_dnd.drag_really)
	  {
1881 1882 1883 1884
	  GdkPoint foo;
	  foo.x = xevent->xbutton.x_root;
	  foo.y = xevent->xbutton.y_root;
			  
Elliot Lee's avatar
Elliot Lee committed
1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916
	  XUngrabPointer(gdk_display, CurrentTime);

	  if(dnd_drag_target != None)
	    gdk_dnd_drag_end(dnd_drag_target, foo);
	  gdk_dnd.drag_really = 0;

	  if(gdk_dnd.drag_numwindows)
	    {
	      XSetWindowAttributes attrs;
	      /* Reset event mask to pre-drag value, assuming event_mask
		 doesn't change during drag */
	      attrs.event_mask = real_sw->dnd_drag_savedeventmask;
	      XChangeWindowAttributes(gdk_display, real_sw->xwindow,
				      CWEventMask, &attrs);
	    }

	  gdk_dnd.drag_numwindows = 0;
	  if(gdk_dnd.drag_startwindows)
	    {
	    g_free(gdk_dnd.drag_startwindows);
	    gdk_dnd.drag_startwindows = NULL;
	    }

	  real_sw = NULL;
	  }

	dnd_drag_perhaps = 0;
	dnd_drag_start.x = dnd_drag_start.y = 0;
	dnd_drag_dropzone.x = dnd_drag_dropzone.y = 0;
	dnd_drag_dropzone.width = dnd_drag_dropzone.height = 0;
	dnd_drag_curwin = None;
      }
1917
      return_val = window_private && !window_private->destroyed;
Elliot Lee's avatar
Elliot Lee committed
1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939
      break;

    case MotionNotify:
      /* Print debugging info.
       */
      if (gdk_show_events)
	g_print ("motion notify:\t\twindow: %ld  x,y: %d %d  hint: %s d:%d r%d\n",
		 xevent->xmotion.window - base_id,
		 xevent->xmotion.x, xevent->xmotion.y,
		 (xevent->xmotion.is_hint) ? "true" : "false",
		 dnd_drag_perhaps, gdk_dnd.drag_really);

      if (window_private &&
	  (window_private->extension_events != 0) &&
	  gdk_input_ignore_core)
	break;

      event->motion.type = GDK_MOTION_NOTIFY;
      event->motion.window = window;
      event->motion.time = xevent->xmotion.time;
      event->motion.x = xevent->xmotion.x;
      event->motion.y = xevent->xmotion.y;
1940 1941
      event->motion.x_root = xevent->xmotion.x_root;
      event->motion.y_root = xevent->xmotion.y_root;
Elliot Lee's avatar
Elliot Lee committed
1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960
      event->motion.pressure = 0.5;
      event->motion.xtilt = 0;
      event->motion.ytilt = 0;
      event->motion.state = (GdkModifierType) xevent->xmotion.state;
      event->motion.is_hint = xevent->xmotion.is_hint;
      event->motion.source = GDK_SOURCE_MOUSE;
      event->motion.deviceid = GDK_CORE_POINTER;

#define IS_IN_ZONE(cx, cy) (cx >= dnd_drag_dropzone.x \
     && cy >= dnd_drag_dropzone.y \
     && cx < (dnd_drag_dropzone.x + dnd_drag_dropzone.width) \
     && cy < (dnd_drag_dropzone.y + dnd_drag_dropzone.height))

      if(dnd_drag_perhaps && gdk_dnd.drag_really)
	{
	  /* First, we have to find what window the motion was in... */
	  /* XXX there has to be a better way to do this, perhaps with
	     XTranslateCoordinates or XQueryTree - I don't know how,
	     and this sort of works */
Elliot Lee's avatar
Elliot Lee committed
1961 1962
	  static Window lastwin = None, curwin = None;
	  Window childwin = gdk_root_window;
Elliot Lee's avatar
Elliot Lee committed
1963
	  int x, y;
Elliot Lee's avatar
Elliot Lee committed
1964
	  lastwin = curwin;
Elliot Lee's avatar
Elliot Lee committed
1965 1966 1967
	  while(childwin != None)
	    {
	      curwin = childwin;
Elliot Lee's avatar
Elliot Lee committed
1968 1969
	      XTranslateCoordinates(gdk_display, curwin, childwin,
				x, y, &x, &y, &childwin);
Elliot Lee's avatar
Elliot Lee committed
1970
	    }
Elliot Lee's avatar
Elliot Lee committed
1971
	  if(curwin != dnd_drag_curwin && curwin != lastwin)
Elliot Lee's avatar
Elliot Lee committed
1972 1973 1974 1975 1976 1977 1978 1979 1980 1981
	    {
	      /* We have left one window and entered another
		 (do leave & enter bits) */
	      if(dnd_drag_curwin != real_sw->xwindow && dnd_drag_curwin != None)
		gdk_dnd_drag_leave(dnd_drag_curwin);
	      dnd_drag_curwin = curwin;
	      gdk_dnd_drag_enter(dnd_drag_curwin);
	      dnd_drag_dropzone.x = dnd_drag_dropzone.y = 0;
	      dnd_drag_dropzone.width = dnd_drag_dropzone.height = 0;
	      dnd_drag_target = None;
Elliot Lee's avatar
Elliot Lee committed
1982 1983 1984 1985
#ifdef DEBUG_DND
	      g_print("curwin = %#x, lastwin = %#x, dnd_drag_curwin = %#x\n",
		      curwin, lastwin, dnd_drag_curwin);
#endif
Elliot Lee's avatar
Elliot Lee committed
1986 1987 1988 1989 1990 1991 1992 1993
	      XChangeActivePointerGrab(gdk_display,
				       ButtonMotionMask |
				       ButtonPressMask | ButtonReleaseMask |
				       EnterWindowMask | LeaveWindowMask,
				       gdk_dnd.gdk_cursor_dragdefault,
				       CurrentTime);
	    }
	  else if(dnd_drag_dropzone.width > 0
Elliot Lee's avatar
Elliot Lee committed
1994 1995
		  && dnd_drag_dropzone.height > 0
		  && curwin == dnd_drag_curwin)
Elliot Lee's avatar
Elliot Lee committed
1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010
	    {
	      /* Handle all that dropzone stuff - thanks John ;-) */
	      if(dnd_drag_target != None
		 && IS_IN_ZONE(dnd_drag_oldpos.x, dnd_drag_oldpos.y)
		 && !IS_IN_ZONE(xevent->xmotion.x_root,
				xevent->xmotion.y_root))
		{
		  /* We were in the drop zone and moved out */
		  dnd_drag_target = None;
		  gdk_dnd_drag_leave(curwin);
		}
	      else
		{
		  /* We were outside drop zone but in the window
		     - have to send enter events */
Elliot Lee's avatar
Elliot Lee committed
2011 2012
#ifdef DEBUG_DND
#endif
Elliot Lee's avatar
Elliot Lee committed
2013 2014 2015 2016 2017 2018 2019 2020 2021 2022
		  gdk_dnd_drag_enter(curwin);
		  dnd_drag_curwin = curwin;
		  dnd_drag_dropzone.x = dnd_drag_dropzone.y = 0;
		  dnd_drag_target = None;
		}
	    } else
	      dnd_drag_curwin = None;
	  return_val = FALSE;
	}
      else
Elliot Lee's avatar
Elliot Lee committed
2023
	return_val = window_private && !window_private->destroyed;
Elliot Lee's avatar
Elliot Lee committed
2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075
      break;

    case EnterNotify:
      /* Print debugging info.
       */
      if (gdk_show_events)
	g_print ("enter notify:\t\twindow: %ld  detail: %d subwin: %ld\n",
		 xevent->xcrossing.window - base_id,
		 xevent->xcrossing.detail,
		 xevent->xcrossing.subwindow - base_id);

      /* Tell XInput stuff about it if appropriate */
      if (window_private &&
	  (window_private->extension_events != 0) &&
	  gdk_input_vtable.enter_event)
	gdk_input_vtable.enter_event (&xevent->xcrossing, window);

      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)
	event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
      else
	event->crossing.subwindow = NULL;

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

Elliot Lee's avatar
Elliot Lee committed
2076 2077
#ifdef DEBUG_DND
	if(dnd_drag_perhaps)
Elliot Lee's avatar
Elliot Lee committed
2078
	{
Elliot Lee's avatar
Elliot Lee committed
2079 2080 2081
		g_print("We may[%d] have a drag into %#x = %#x\n",
			gdk_dnd.drag_really,
			xevent->xcrossing.window, real_sw->xwindow);
Elliot Lee's avatar
Elliot Lee committed
2082
	}
Elliot Lee's avatar
Elliot Lee committed
2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108