Blame gdk/x11/gdkxid.c

Packit 98cdb6
/* GDK - The GIMP Drawing Kit
Packit 98cdb6
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
Packit 98cdb6
 *
Packit 98cdb6
 * This library is free software; you can redistribute it and/or
Packit 98cdb6
 * modify it under the terms of the GNU Lesser General Public
Packit 98cdb6
 * License as published by the Free Software Foundation; either
Packit 98cdb6
 * version 2 of the License, or (at your option) any later version.
Packit 98cdb6
 *
Packit 98cdb6
 * This library is distributed in the hope that it will be useful,
Packit 98cdb6
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 98cdb6
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 98cdb6
 * Lesser General Public License for more details.
Packit 98cdb6
 *
Packit 98cdb6
 * You should have received a copy of the GNU Lesser General Public
Packit 98cdb6
 * License along with this library; if not, write to the
Packit 98cdb6
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 98cdb6
 * Boston, MA 02111-1307, USA.
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
/*
Packit 98cdb6
 * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
Packit 98cdb6
 * file for a list of people on the GTK+ Team.  See the ChangeLog
Packit 98cdb6
 * files for a list of changes.  These files are distributed with
Packit 98cdb6
 * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
Packit 98cdb6
 */
Packit 98cdb6
Packit 98cdb6
#include "config.h"
Packit 98cdb6
#include "gdkx.h"
Packit 98cdb6
#include "gdkprivate-x11.h"
Packit 98cdb6
#include "gdkdisplay-x11.h"
Packit 98cdb6
#include "gdkalias.h"
Packit 98cdb6
#include <stdio.h>
Packit 98cdb6
Packit 98cdb6
static guint     gdk_xid_hash  (XID *xid);
Packit 98cdb6
static gboolean  gdk_xid_equal (XID *a,
Packit 98cdb6
				XID *b);
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
/* The 3 high bits of XIDs are unused. We use one to mark fonts, 
Packit 98cdb6
 * since we must be able to skip fonts when iterating over all XIDs.
Packit 98cdb6
 */
Packit 98cdb6
#define XID_FONT_BIT (1<<31)
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
_gdk_xid_table_insert (GdkDisplay *display,
Packit 98cdb6
		       XID	  *xid,
Packit 98cdb6
		       gpointer    data)
Packit 98cdb6
{
Packit 98cdb6
  GdkDisplayX11 *display_x11;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (xid != NULL);
Packit 98cdb6
  g_return_if_fail (GDK_IS_DISPLAY (display));
Packit 98cdb6
Packit 98cdb6
  display_x11 = GDK_DISPLAY_X11 (display);
Packit 98cdb6
Packit 98cdb6
  if (!display_x11->xid_ht)
Packit 98cdb6
    display_x11->xid_ht = g_hash_table_new ((GHashFunc) gdk_xid_hash,
Packit 98cdb6
					    (GEqualFunc) gdk_xid_equal);
Packit 98cdb6
Packit 98cdb6
  if (g_hash_table_lookup (display_x11->xid_ht, xid))
Packit 98cdb6
    g_warning ("XID collision, trouble ahead");
Packit 98cdb6
Packit 98cdb6
  g_hash_table_insert (display_x11->xid_ht, xid, data);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
void
Packit 98cdb6
_gdk_xid_table_remove (GdkDisplay *display,
Packit 98cdb6
		       XID	   xid)
Packit 98cdb6
{
Packit 98cdb6
  GdkDisplayX11 *display_x11;
Packit 98cdb6
Packit 98cdb6
  g_return_if_fail (GDK_IS_DISPLAY (display));
Packit 98cdb6
Packit 98cdb6
  display_x11 = GDK_DISPLAY_X11 (display);
Packit 98cdb6
Packit 98cdb6
  if (display_x11->xid_ht)
Packit 98cdb6
    g_hash_table_remove (display_x11->xid_ht, &xid;;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_xid_table_lookup_for_display:
Packit 98cdb6
 * @display: the #GdkDisplay.
Packit 98cdb6
 * @xid: an X id.
Packit 98cdb6
 *
Packit 98cdb6
 * Returns the GDK object associated with the given X id.
Packit 98cdb6
 *
Packit 98cdb6
 * Return value: the associated Gdk object, which may be a #GdkPixmap,
Packit 98cdb6
 *     a #GdkWindow or a #GdkFont or %NULL if no object is associated
Packit 98cdb6
 *     with the X id.
Packit 98cdb6
 *
Packit 98cdb6
 * Since: 2.2
Packit 98cdb6
 *
Packit 98cdb6
 * Deprecated:2.24: This function will be removed in GTK+ 3.0. GTK+
Packit 98cdb6
 *     only stores windows in its X id table nowadays, so use
Packit 98cdb6
 *     gdk_x11_window_lookup_for_display() instead.
Packit 98cdb6
 */
Packit 98cdb6
gpointer
Packit 98cdb6
gdk_xid_table_lookup_for_display (GdkDisplay  *display,
Packit 98cdb6
				  XID	       xid)
Packit 98cdb6
{
Packit 98cdb6
  GdkDisplayX11 *display_x11;
Packit 98cdb6
  gpointer data = NULL;
Packit 98cdb6
  
Packit 98cdb6
  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
Packit 98cdb6
  
Packit 98cdb6
  display_x11 = GDK_DISPLAY_X11 (display);
Packit 98cdb6
Packit 98cdb6
  if (display_x11->xid_ht)
Packit 98cdb6
    data = g_hash_table_lookup (display_x11->xid_ht, &xid;;
Packit 98cdb6
  
Packit 98cdb6
  return data;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
Packit 98cdb6
/**
Packit 98cdb6
 * gdk_xid_table_lookup:
Packit 98cdb6
 * @xid: an X id.
Packit 98cdb6
 *
Packit 98cdb6
 * Returns the Gdk object associated with the given X id for the default
Packit 98cdb6
 * display.
Packit 98cdb6
 *
Packit 98cdb6
 * Return value: the associated Gdk object, which may be a #GdkPixmap,
Packit 98cdb6
 *     a #GdkWindow or a #GdkFont or %NULL if no object is associated
Packit 98cdb6
 *     with the X id.
Packit 98cdb6
 *
Packit 98cdb6
 * Deprecated:2.24: This function will be removed in GTK+ 3.0. GTK+
Packit 98cdb6
 *     only stores windows in its X id table nowadays, so use
Packit 98cdb6
 *     gdk_x11_window_lookup_for_display() instead.
Packit 98cdb6
 */
Packit 98cdb6
gpointer
Packit 98cdb6
gdk_xid_table_lookup (XID xid)
Packit 98cdb6
{
Packit 98cdb6
  return gdk_xid_table_lookup_for_display (gdk_display_get_default (), xid);
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static guint
Packit 98cdb6
gdk_xid_hash (XID *xid)
Packit 98cdb6
{
Packit 98cdb6
  return *xid;
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
static gboolean
Packit 98cdb6
gdk_xid_equal (XID *a,
Packit 98cdb6
	       XID *b)
Packit 98cdb6
{
Packit 98cdb6
  return ((*a & ~XID_FONT_BIT) == (*b & ~XID_FONT_BIT));
Packit 98cdb6
}
Packit 98cdb6
Packit 98cdb6
#define __GDK_XID_C__
Packit 98cdb6
#include "gdkaliasdef.c"