| 1 |
/* GDK - The GIMP Drawing Kit |
| 2 |
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
| 3 |
* |
| 4 |
* This library is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU Lesser General Public |
| 6 |
* License as published by the Free Software Foundation; either |
| 7 |
* version 2 of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This library is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* Lesser General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU Lesser General Public |
| 15 |
* License along with this library. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
/* |
| 19 |
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS |
| 20 |
* file for a list of people on the GTK+ Team. See the ChangeLog |
| 21 |
* files for a list of changes. These files are distributed with |
| 22 |
* GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "config.h" |
| 26 |
|
| 27 |
#include "gdkprivate-x11.h" |
| 28 |
#include "gdkdisplay-x11.h" |
| 29 |
|
| 30 |
#include <stdio.h> |
| 31 |
|
| 32 |
static guint |
| 33 |
gdk_xid_hash (XID *xid) |
| 34 |
{ |
| 35 |
return *xid; |
| 36 |
} |
| 37 |
|
| 38 |
static gboolean |
| 39 |
gdk_xid_equal (XID *a, XID *b) |
| 40 |
{ |
| 41 |
return (*a == *b); |
| 42 |
} |
| 43 |
|
| 44 |
void |
| 45 |
_gdk_x11_display_add_window (GdkDisplay *display, |
| 46 |
XID *xid, |
| 47 |
GdkWindow *data) |
| 48 |
{ |
| 49 |
GdkX11Display *display_x11; |
| 50 |
|
| 51 |
g_return_if_fail (xid != NULL); |
| 52 |
g_return_if_fail (GDK_IS_DISPLAY (display)); |
| 53 |
|
| 54 |
display_x11 = GDK_X11_DISPLAY (display); |
| 55 |
|
| 56 |
if (!display_x11->xid_ht) |
| 57 |
display_x11->xid_ht = g_hash_table_new ((GHashFunc) gdk_xid_hash, |
| 58 |
(GEqualFunc) gdk_xid_equal); |
| 59 |
|
| 60 |
if (g_hash_table_lookup (display_x11->xid_ht, xid)) |
| 61 |
g_warning ("XID collision, trouble ahead"); |
| 62 |
|
| 63 |
g_hash_table_insert (display_x11->xid_ht, xid, data); |
| 64 |
} |
| 65 |
|
| 66 |
void |
| 67 |
_gdk_x11_display_remove_window (GdkDisplay *display, |
| 68 |
XID xid) |
| 69 |
{ |
| 70 |
GdkX11Display *display_x11; |
| 71 |
|
| 72 |
g_return_if_fail (GDK_IS_DISPLAY (display)); |
| 73 |
|
| 74 |
display_x11 = GDK_X11_DISPLAY (display); |
| 75 |
|
| 76 |
if (display_x11->xid_ht) |
| 77 |
g_hash_table_remove (display_x11->xid_ht, &xid); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* gdk_x11_window_lookup_for_display: |
| 82 |
* @display: (type GdkX11Display): the #GdkDisplay corresponding to the |
| 83 |
* window handle |
| 84 |
* @window: an Xlib Window |
| 85 |
* |
| 86 |
* Looks up the #GdkWindow that wraps the given native window handle. |
| 87 |
* |
| 88 |
* Returns: (transfer none) (type GdkX11Window): the #GdkWindow wrapper for the native |
| 89 |
* window, or %NULL if there is none. |
| 90 |
* |
| 91 |
* Since: 2.24 |
| 92 |
*/ |
| 93 |
GdkWindow * |
| 94 |
gdk_x11_window_lookup_for_display (GdkDisplay *display, |
| 95 |
Window window) |
| 96 |
{ |
| 97 |
GdkX11Display *display_x11; |
| 98 |
GdkWindow *data = NULL; |
| 99 |
|
| 100 |
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); |
| 101 |
|
| 102 |
display_x11 = GDK_X11_DISPLAY (display); |
| 103 |
|
| 104 |
if (display_x11->xid_ht) |
| 105 |
data = g_hash_table_lookup (display_x11->xid_ht, &window); |
| 106 |
|
| 107 |
return data; |
| 108 |
} |