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 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.
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.
14 * You should have received a copy of the GNU Lesser 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-2000. 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/.
31 #include <X11/Xutil.h>
35 #include "gdkprivate.h"
36 #include "gdkinputprivate.h"
37 #include "gdkscreen-x11.h"
38 #include "gdkdisplay-x11.h"
41 static GdkDeviceAxis gdk_input_core_axes[] = {
47 _gdk_init_input_core (GdkDisplay *display)
49 GdkDevicePrivate *private;
51 display->core_pointer = g_object_new (GDK_TYPE_DEVICE, NULL);
52 private = (GdkDevicePrivate *)display->core_pointer;
54 display->core_pointer->name = "Core Pointer";
55 display->core_pointer->source = GDK_SOURCE_MOUSE;
56 display->core_pointer->mode = GDK_MODE_SCREEN;
57 display->core_pointer->has_cursor = TRUE;
58 display->core_pointer->num_axes = 2;
59 display->core_pointer->axes = gdk_input_core_axes;
60 display->core_pointer->num_keys = 0;
61 display->core_pointer->keys = NULL;
63 private->display = display;
67 gdk_device_get_type (void)
69 static GType object_type = 0;
73 static const GTypeInfo object_info =
75 sizeof (GdkDeviceClass),
77 (GBaseFinalizeFunc) NULL,
78 (GClassInitFunc) NULL,
79 NULL, /* class_finalize */
80 NULL, /* class_data */
81 sizeof (GdkDevicePrivate),
83 (GInstanceInitFunc) NULL,
86 object_type = g_type_register_static (G_TYPE_OBJECT,
97 * Returns the list of available input devices for the default display.
98 * The list is statically allocated and should not be freed.
100 * Return value: a list of #GdkDevice
103 gdk_devices_list (void)
105 return gdk_display_list_devices (gdk_display_get_default ());
109 * gdk_display_list_devices:
110 * @display: a #GdkDisplay
112 * Returns the list of available input devices attached to @display.
113 * The list is statically allocated and should not be freed.
115 * Return value: a list of #GdkDevice
120 gdk_display_list_devices (GdkDisplay *display)
122 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
124 return GDK_DISPLAY_X11 (display)->input_devices;
128 gdk_device_set_source (GdkDevice *device,
129 GdkInputSource source)
131 g_return_if_fail (device != NULL);
133 device->source = source;
137 gdk_device_set_key (GdkDevice *device,
140 GdkModifierType modifiers)
142 g_return_if_fail (device != NULL);
143 g_return_if_fail (index < device->num_keys);
145 device->keys[index].keyval = keyval;
146 device->keys[index].modifiers = modifiers;
150 gdk_device_set_axis_use (GdkDevice *device,
154 g_return_if_fail (device != NULL);
155 g_return_if_fail (index < device->num_axes);
157 device->axes[index].use = use;
163 device->axes[index].min = 0.;
164 device->axes[index].max = 0.;
168 device->axes[index].min = -1.;
169 device->axes[index].max = 1;
172 device->axes[index].min = 0.;
173 device->axes[index].max = 1;
179 * gdk_device_get_history:
180 * @device: a #GdkDevice
181 * @window: the window with respect to which which the event coordinates will be reported
182 * @start: starting timestamp for range of events to return
183 * @stop: ending timestamp for the range of events to return
184 * @events: location to store a newly-allocated array of #GdkTimeCoord, or %NULL
185 * @n_events: location to store the length of @events, or %NULL
187 * Obtains the motion history for a device; given a starting and
188 * ending timestamp, return all events in the motion history for
189 * the device in the given range of time. Some windowing systems
190 * do not support motion history, in which case, %FALSE will
191 * be returned. (This is not distinguishable from the case where
192 * motion history is supported and no events were found.)
194 * Return value: %TRUE if the windowing system supports motion history and
195 * at least one event was found.
198 gdk_device_get_history (GdkDevice *device,
202 GdkTimeCoord ***events,
205 GdkTimeCoord **coords = NULL;
206 gboolean result = FALSE;
207 int tmp_n_events = 0;
210 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
212 if (GDK_WINDOW_DESTROYED (window))
214 else if (GDK_IS_CORE (device))
218 xcoords = XGetMotionEvents (GDK_DRAWABLE_XDISPLAY (window),
219 GDK_DRAWABLE_XID (window),
220 start, stop, &tmp_n_events);
223 coords = _gdk_device_allocate_history (device, tmp_n_events);
224 for (i=0; i<tmp_n_events; i++)
226 coords[i]->time = xcoords[i].time;
227 coords[i]->axes[0] = xcoords[i].x;
228 coords[i]->axes[1] = xcoords[i].y;
239 result = _gdk_device_get_history (device, window, start, stop, &coords, &tmp_n_events);
242 *n_events = tmp_n_events;
246 gdk_device_free_history (coords, tmp_n_events);
252 _gdk_device_allocate_history (GdkDevice *device,
255 GdkTimeCoord **result = g_new (GdkTimeCoord *, n_events);
258 for (i=0; i<n_events; i++)
259 result[i] = g_malloc (sizeof (GdkTimeCoord) -
260 sizeof (double) * (GDK_MAX_TIMECOORD_AXES - device->num_axes));
266 gdk_device_free_history (GdkTimeCoord **events,
271 for (i=0; i<n_events; i++)
278 _gdk_input_window_find(GdkWindow *window)
281 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window));
283 for (tmp_list=display_x11->input_windows; tmp_list; tmp_list=tmp_list->next)
284 if (((GdkInputWindow *)(tmp_list->data))->window == window)
285 return (GdkInputWindow *)(tmp_list->data);
287 return NULL; /* Not found */
290 /* FIXME: this routine currently needs to be called between creation
291 and the corresponding configure event (because it doesn't get the
292 root_relative_geometry). This should work with
293 gtk_window_set_extension_events, but will likely fail in other
297 gdk_input_set_extension_events (GdkWindow *window, gint mask,
298 GdkExtensionMode mode)
300 GdkWindowObject *window_private;
303 GdkDisplayX11 *display_x11;
305 g_return_if_fail (window != NULL);
306 g_return_if_fail (GDK_IS_WINDOW (window));
308 window_private = (GdkWindowObject*) window;
309 display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window));
310 if (GDK_WINDOW_DESTROYED (window))
313 if (mode == GDK_EXTENSION_EVENTS_NONE)
318 iw = g_new(GdkInputWindow,1);
323 iw->obscuring = NULL;
324 iw->num_obscuring = 0;
327 display_x11->input_windows = g_list_append(display_x11->input_windows,iw);
328 window_private->extension_events = mask;
330 /* Add enter window events to the event mask */
331 /* FIXME, this is not needed for XINPUT_NONE */
332 gdk_window_set_events (window,
333 gdk_window_get_events (window) |
334 GDK_ENTER_NOTIFY_MASK);
338 iw = _gdk_input_window_find (window);
341 display_x11->input_windows = g_list_remove(display_x11->input_windows,iw);
345 window_private->extension_events = 0;
348 for (tmp_list = display_x11->input_devices; tmp_list; tmp_list = tmp_list->next)
350 GdkDevicePrivate *gdkdev = tmp_list->data;
352 if (!GDK_IS_CORE (gdkdev))
354 if (mask != 0 && gdkdev->info.mode != GDK_MODE_DISABLED
355 && (gdkdev->info.has_cursor || mode == GDK_EXTENSION_EVENTS_ALL))
356 _gdk_input_enable_window (window,gdkdev);
358 _gdk_input_disable_window (window,gdkdev);
364 _gdk_input_window_destroy (GdkWindow *window)
366 GdkInputWindow *input_window;
367 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window));
369 input_window = _gdk_input_window_find (window);
370 g_return_if_fail (input_window != NULL);
372 display_x11->input_windows = g_list_remove (display_x11->input_windows, input_window);
373 g_free(input_window);
377 _gdk_input_exit (void)
380 GSList *display_list;
381 GdkDevicePrivate *gdkdev;
383 for (display_list = _gdk_displays ; display_list ; display_list = display_list->next)
385 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display_list->data);
387 for (tmp_list = display_x11->input_devices; tmp_list; tmp_list = tmp_list->next)
389 gdkdev = (GdkDevicePrivate *)(tmp_list->data);
390 if (!GDK_IS_CORE (gdkdev))
392 gdk_device_set_mode (&gdkdev->info, GDK_MODE_DISABLED);
394 g_free(gdkdev->info.name);
396 g_free(gdkdev->axes);
398 g_free(gdkdev->info.axes);
399 g_free(gdkdev->info.keys);
404 g_list_free(display_x11->input_devices);
406 for (tmp_list = display_x11->input_windows; tmp_list; tmp_list = tmp_list->next)
407 g_free(tmp_list->data);
409 g_list_free(display_x11->input_windows);
414 * gdk_device_get_axis:
415 * @device: a #GdkDevice
416 * @axes: pointer to an array of axes
417 * @use: the use to look for
418 * @value: location to store the found value.
420 * Interprets an array of double as axis values for a given device,
421 * and locates the value in the array for a given axis use.
423 * Return value: %TRUE if the given axis use was found, otherwise %FALSE
426 gdk_device_get_axis (GdkDevice *device,
433 g_return_val_if_fail (device != NULL, FALSE);
438 for (i=0; i<device->num_axes; i++)
439 if (device->axes[i].use == use)
449 #define __GDK_INPUT_C__
450 #include "gdkaliasdef.c"