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
gdk_xid_hash(XID * xid)33 gdk_xid_hash (XID *xid)
34 {
35 return *xid;
36 }
37
38 static gboolean
gdk_xid_equal(XID * a,XID * b)39 gdk_xid_equal (XID *a, XID *b)
40 {
41 return (*a == *b);
42 }
43
44 void
_gdk_x11_display_add_window(GdkDisplay * display,XID * xid,GdkSurface * data)45 _gdk_x11_display_add_window (GdkDisplay *display,
46 XID *xid,
47 GdkSurface *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 display_x11->toplevels = g_list_prepend (display_x11->toplevels, data);
66 }
67
68 void
_gdk_x11_display_remove_window(GdkDisplay * display,XID xid)69 _gdk_x11_display_remove_window (GdkDisplay *display,
70 XID xid)
71 {
72 GdkX11Display *display_x11;
73 GdkSurface *surface;
74
75 g_return_if_fail (GDK_IS_DISPLAY (display));
76
77 display_x11 = GDK_X11_DISPLAY (display);
78
79 if (!display_x11->xid_ht)
80 return;
81
82 surface = g_hash_table_lookup (display_x11->xid_ht, &xid);
83 if (surface)
84 display_x11->toplevels = g_list_remove (display_x11->toplevels, surface);
85
86 g_hash_table_remove (display_x11->xid_ht, &xid);
87 }
88
89 /**
90 * gdk_x11_surface_lookup_for_display:
91 * @display: (type GdkX11Display): the `GdkDisplay` corresponding to the
92 * window handle
93 * @window: an Xlib Window
94 *
95 * Looks up the `GdkSurface` that wraps the given native window handle.
96 *
97 * Returns: (transfer none) (type GdkX11Surface): the `GdkSurface` wrapper
98 * for the native window
99 */
100 GdkSurface *
gdk_x11_surface_lookup_for_display(GdkDisplay * display,Window window)101 gdk_x11_surface_lookup_for_display (GdkDisplay *display,
102 Window window)
103 {
104 GdkX11Display *display_x11;
105 GdkSurface *data = NULL;
106
107 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
108
109 display_x11 = GDK_X11_DISPLAY (display);
110
111 if (display_x11->xid_ht)
112 data = g_hash_table_lookup (display_x11->xid_ht, &window);
113
114 return data;
115 }
116