1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library 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.
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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include <X11/Xutil.h>
34 #include "gdkprivate.h"
35 #include "gdkinputprivate.h"
37 static const GdkAxisUse gdk_input_core_axes[] = { GDK_AXIS_X, GDK_AXIS_Y };
39 const GdkDeviceInfo gdk_input_core_info =
50 /* Global variables */
52 GdkInputVTable gdk_input_vtable;
53 /* information about network port and host for gxid daemon */
54 gchar *gdk_input_gxid_host;
55 gint gdk_input_gxid_port;
56 gint gdk_input_ignore_core;
58 GList *gdk_input_devices;
59 GList *gdk_input_windows;
62 gdk_input_list_devices (void)
64 return gdk_input_devices;
68 gdk_input_set_source (guint32 deviceid, GdkInputSource source)
70 GdkDevicePrivate *gdkdev = gdk_input_find_device(deviceid);
71 g_return_if_fail (gdkdev != NULL);
73 gdkdev->info.source = source;
77 gdk_input_set_mode (guint32 deviceid, GdkInputMode mode)
79 if (deviceid == GDK_CORE_POINTER)
82 if (gdk_input_vtable.set_mode)
83 return gdk_input_vtable.set_mode(deviceid,mode);
89 gdk_input_set_axes (guint32 deviceid, GdkAxisUse *axes)
91 if (deviceid != GDK_CORE_POINTER && gdk_input_vtable.set_axes)
92 gdk_input_vtable.set_axes (deviceid, axes);
95 void gdk_input_set_key (guint32 deviceid,
98 GdkModifierType modifiers)
100 if (deviceid != GDK_CORE_POINTER && gdk_input_vtable.set_key)
101 gdk_input_vtable.set_key (deviceid, index, keyval, modifiers);
105 gdk_input_motion_events (GdkWindow *window,
109 gint *nevents_return)
112 GdkTimeCoord *coords;
115 g_return_val_if_fail (window != NULL, NULL);
116 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
118 if (GDK_WINDOW_DESTROYED (window))
121 if (deviceid == GDK_CORE_POINTER)
123 xcoords = XGetMotionEvents (GDK_DRAWABLE_XDISPLAY (window),
124 GDK_DRAWABLE_XID (window),
125 start, stop, nevents_return);
128 coords = g_new (GdkTimeCoord, *nevents_return);
129 for (i=0; i<*nevents_return; i++)
131 coords[i].time = xcoords[i].time;
132 coords[i].x = xcoords[i].x;
133 coords[i].y = xcoords[i].y;
134 coords[i].pressure = 0.5;
135 coords[i].xtilt = 0.0;
136 coords[i].ytilt = 0.0;
148 if (gdk_input_vtable.motion_events)
150 return gdk_input_vtable.motion_events(window,
151 deviceid, start, stop,
163 gdk_input_enable_window (GdkWindow *window, GdkDevicePrivate *gdkdev)
165 if (gdk_input_vtable.enable_window)
166 return gdk_input_vtable.enable_window (window, gdkdev);
172 gdk_input_disable_window (GdkWindow *window, GdkDevicePrivate *gdkdev)
174 if (gdk_input_vtable.disable_window)
175 return gdk_input_vtable.disable_window(window,gdkdev);
182 gdk_input_window_find(GdkWindow *window)
186 for (tmp_list=gdk_input_windows; tmp_list; tmp_list=tmp_list->next)
187 if (((GdkInputWindow *)(tmp_list->data))->window == window)
188 return (GdkInputWindow *)(tmp_list->data);
190 return NULL; /* Not found */
193 /* FIXME: this routine currently needs to be called between creation
194 and the corresponding configure event (because it doesn't get the
195 root_relative_geometry). This should work with
196 gtk_window_set_extension_events, but will likely fail in other
200 gdk_input_set_extension_events (GdkWindow *window, gint mask,
201 GdkExtensionMode mode)
203 GdkWindowObject *window_private;
207 g_return_if_fail (window != NULL);
208 g_return_if_fail (GDK_IS_WINDOW (window));
210 window_private = (GdkWindowObject*) window;
211 if (GDK_WINDOW_DESTROYED (window))
214 if (mode == GDK_EXTENSION_EVENTS_NONE)
219 iw = g_new(GdkInputWindow,1);
224 iw->obscuring = NULL;
225 iw->num_obscuring = 0;
228 gdk_input_windows = g_list_append(gdk_input_windows,iw);
229 window_private->extension_events = mask;
231 /* Add enter window events to the event mask */
232 /* FIXME, this is not needed for XINPUT_NONE */
233 gdk_window_set_events (window,
234 gdk_window_get_events (window) |
235 GDK_ENTER_NOTIFY_MASK);
239 iw = gdk_input_window_find (window);
242 gdk_input_windows = g_list_remove(gdk_input_windows,iw);
246 window_private->extension_events = 0;
249 for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
251 GdkDevicePrivate *gdkdev = (GdkDevicePrivate *)(tmp_list->data);
253 if (gdkdev->info.deviceid != GDK_CORE_POINTER)
255 if (mask != 0 && gdkdev->info.mode != GDK_MODE_DISABLED
256 && (gdkdev->info.has_cursor || mode == GDK_EXTENSION_EVENTS_ALL))
257 gdk_input_enable_window(window,gdkdev);
259 gdk_input_disable_window(window,gdkdev);
265 gdk_input_window_destroy (GdkWindow *window)
267 GdkInputWindow *input_window;
269 input_window = gdk_input_window_find (window);
270 g_return_if_fail (input_window != NULL);
272 gdk_input_windows = g_list_remove (gdk_input_windows,input_window);
273 g_free(input_window);
277 gdk_input_exit (void)
280 GdkDevicePrivate *gdkdev;
282 for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
284 gdkdev = (GdkDevicePrivate *)(tmp_list->data);
285 if (gdkdev->info.deviceid != GDK_CORE_POINTER)
287 gdk_input_set_mode(gdkdev->info.deviceid,GDK_MODE_DISABLED);
289 g_free(gdkdev->info.name);
291 g_free(gdkdev->axes);
293 g_free(gdkdev->info.axes);
294 g_free(gdkdev->info.keys);
299 g_list_free(gdk_input_devices);
301 for (tmp_list = gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
303 g_free(tmp_list->data);
305 g_list_free(gdk_input_windows);
309 gdk_input_find_device(guint32 id)
311 GList *tmp_list = gdk_input_devices;
312 GdkDevicePrivate *gdkdev;
315 gdkdev = (GdkDevicePrivate *)(tmp_list->data);
316 if (gdkdev->info.deviceid == id)
318 tmp_list = tmp_list->next;
324 gdk_input_window_get_pointer (GdkWindow *window,
331 GdkModifierType *mask)
333 if (gdk_input_vtable.get_pointer)
334 gdk_input_vtable.get_pointer (window, deviceid, x, y, pressure,