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/.
27 /* This file should really be one level up, in the backend-independent
28 * GDK, and the x11/gdkinput.c could also be removed.
30 * That stuff in x11/gdkinput.c which really *is* X11-dependent should
31 * be in x11/gdkinput-x11.c.
36 #include "gdkdisplay.h"
38 #include "gdkprivate.h"
40 /* When ther necessary stuff is in
41 * gdkinput.h, gdkinternals.h and
42 * gdkprivate.h, these includes shouldn't be here.
50 #include "gdkinput-win32.h"
52 static GdkDeviceAxis gdk_input_core_axes[] = {
57 /* Global variables */
59 gint _gdk_input_ignore_core;
61 GList *_gdk_input_devices;
62 GList *_gdk_input_windows;
65 _gdk_init_input_core (GdkDisplay *display)
67 display->core_pointer = g_object_new (GDK_TYPE_DEVICE, NULL);
69 display->core_pointer->name = "Core Pointer";
70 display->core_pointer->source = GDK_SOURCE_MOUSE;
71 display->core_pointer->mode = GDK_MODE_SCREEN;
72 display->core_pointer->has_cursor = TRUE;
73 display->core_pointer->num_axes = 2;
74 display->core_pointer->axes = gdk_input_core_axes;
75 display->core_pointer->num_keys = 0;
76 display->core_pointer->keys = NULL;
80 gdk_device_finalize (GObject *object)
82 g_error ("A GdkDevice object was finalized. This should not happen");
86 gdk_device_class_init (GObjectClass *class)
88 class->finalize = gdk_device_finalize;
92 gdk_device_get_type (void)
94 static GType object_type = 0;
98 static const GTypeInfo object_info =
100 sizeof (GdkDeviceClass),
101 (GBaseInitFunc) NULL,
102 (GBaseFinalizeFunc) NULL,
103 (GClassInitFunc) gdk_device_class_init,
104 NULL, /* class_finalize */
105 NULL, /* class_data */
106 sizeof (GdkDevicePrivate),
108 (GInstanceInitFunc) NULL,
111 object_type = g_type_register_static (G_TYPE_OBJECT,
120 gdk_devices_list (void)
122 return _gdk_input_devices;
126 gdk_device_set_source (GdkDevice *device,
127 GdkInputSource source)
129 g_return_if_fail (device != NULL);
131 device->source = source;
135 gdk_device_set_key (GdkDevice *device,
138 GdkModifierType modifiers)
140 g_return_if_fail (device != NULL);
141 g_return_if_fail (index < device->num_keys);
143 device->keys[index].keyval = keyval;
144 device->keys[index].modifiers = modifiers;
148 gdk_device_set_axis_use (GdkDevice *device,
152 g_return_if_fail (device != NULL);
153 g_return_if_fail (index < device->num_axes);
155 device->axes[index].use = use;
161 device->axes[index].min = 0.;
162 device->axes[index].max = 0.;
166 device->axes[index].min = -1.;
167 device->axes[index].max = 1;
170 device->axes[index].min = 0.;
171 device->axes[index].max = 1;
177 gdk_device_get_history (GdkDevice *device,
181 GdkTimeCoord ***events,
184 g_return_val_if_fail (window != NULL, FALSE);
185 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
186 g_return_val_if_fail (events != NULL, FALSE);
187 g_return_val_if_fail (n_events != NULL, FALSE);
194 if (GDK_WINDOW_DESTROYED (window))
197 if (GDK_IS_CORE (device))
200 return _gdk_device_get_history (device, window, start, stop, events, n_events);
204 _gdk_device_allocate_history (GdkDevice *device,
207 GdkTimeCoord **result = g_new (GdkTimeCoord *, n_events);
210 for (i=0; i<n_events; i++)
211 result[i] = g_malloc (sizeof (GdkTimeCoord) -
212 sizeof (double) * (GDK_MAX_TIMECOORD_AXES - device->num_axes));
218 gdk_device_free_history (GdkTimeCoord **events,
223 for (i=0; i<n_events; i++)
230 _gdk_input_window_find(GdkWindow *window)
234 for (tmp_list=_gdk_input_windows; tmp_list; tmp_list=tmp_list->next)
235 if (((GdkInputWindow *)(tmp_list->data))->window == window)
236 return (GdkInputWindow *)(tmp_list->data);
238 return NULL; /* Not found */
241 /* FIXME: this routine currently needs to be called between creation
242 and the corresponding configure event (because it doesn't get the
243 root_relative_geometry). This should work with
244 gtk_window_set_extension_events, but will likely fail in other
248 gdk_input_set_extension_events (GdkWindow *window, gint mask,
249 GdkExtensionMode mode)
251 GdkWindowObject *window_private;
255 g_return_if_fail (window != NULL);
256 g_return_if_fail (GDK_IS_WINDOW (window));
258 window_private = (GdkWindowObject*) window;
259 if (GDK_WINDOW_DESTROYED (window))
262 if (mode == GDK_EXTENSION_EVENTS_NONE)
267 iw = g_new(GdkInputWindow,1);
272 iw->obscuring = NULL;
273 iw->num_obscuring = 0;
276 _gdk_input_windows = g_list_append(_gdk_input_windows,iw);
277 window_private->extension_events = mask;
279 /* Add enter window events to the event mask */
280 if (g_list_length (_gdk_input_devices) > 1)
281 gdk_window_set_events (window,
282 gdk_window_get_events (window) |
283 GDK_ENTER_NOTIFY_MASK);
287 iw = _gdk_input_window_find (window);
290 _gdk_input_windows = g_list_remove(_gdk_input_windows,iw);
294 window_private->extension_events = 0;
297 for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
299 GdkDevicePrivate *gdkdev = tmp_list->data;
301 if (!GDK_IS_CORE (gdkdev))
303 if (mask != 0 && gdkdev->info.mode != GDK_MODE_DISABLED
304 && (gdkdev->info.has_cursor || mode == GDK_EXTENSION_EVENTS_ALL))
305 _gdk_input_enable_window (window,gdkdev);
307 _gdk_input_disable_window (window,gdkdev);
313 _gdk_input_window_destroy (GdkWindow *window)
315 GdkInputWindow *input_window;
317 input_window = _gdk_input_window_find (window);
318 g_return_if_fail (input_window != NULL);
320 _gdk_input_windows = g_list_remove (_gdk_input_windows,input_window);
321 g_free(input_window);
325 _gdk_input_exit (void)
328 GdkDevicePrivate *gdkdev;
330 for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
332 gdkdev = (GdkDevicePrivate *)(tmp_list->data);
333 if (!GDK_IS_CORE (gdkdev))
335 gdk_device_set_mode (&gdkdev->info, GDK_MODE_DISABLED);
337 g_free(gdkdev->info.name);
338 g_free(gdkdev->axes);
339 g_free(gdkdev->info.axes);
340 g_free(gdkdev->info.keys);
345 g_list_free(_gdk_input_devices);
347 for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
348 g_free(tmp_list->data);
350 g_list_free(_gdk_input_windows);
354 gdk_device_get_axis (GdkDevice *device,
361 g_return_val_if_fail (device != NULL, FALSE);
366 for (i=0; i<device->num_axes; i++)
367 if (device->axes[i].use == use)
378 gdk_device_set_mode (GdkDevice *device,
382 GdkDevicePrivate *gdkdev;
383 GdkInputMode old_mode;
384 GdkInputWindow *input_window;
386 if (GDK_IS_CORE (device))
389 gdkdev = (GdkDevicePrivate *)device;
391 if (device->mode == mode)
394 old_mode = device->mode;
397 if (mode == GDK_MODE_WINDOW)
399 device->has_cursor = FALSE;
400 for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
402 input_window = (GdkInputWindow *)tmp_list->data;
403 if (input_window->mode != GDK_EXTENSION_EVENTS_CURSOR)
404 _gdk_input_enable_window (input_window->window, gdkdev);
406 if (old_mode != GDK_MODE_DISABLED)
407 _gdk_input_disable_window (input_window->window, gdkdev);
410 else if (mode == GDK_MODE_SCREEN)
412 device->has_cursor = TRUE;
413 for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
414 _gdk_input_enable_window (((GdkInputWindow *)tmp_list->data)->window,
417 else /* mode == GDK_MODE_DISABLED */
419 for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
421 input_window = (GdkInputWindow *)tmp_list->data;
422 if (old_mode != GDK_MODE_WINDOW ||
423 input_window->mode != GDK_EXTENSION_EVENTS_CURSOR)
424 _gdk_input_disable_window (input_window->window, gdkdev);