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"
39 #include "gdkprivate-win32.h"
40 #include "gdkinput-win32.h"
42 static GdkDeviceAxis gdk_input_core_axes[] = {
47 /* Global variables */
49 gint _gdk_input_ignore_core;
51 GList *_gdk_input_devices;
52 GList *_gdk_input_windows;
55 _gdk_init_input_core (GdkDisplay *display)
57 display->core_pointer = g_object_new (GDK_TYPE_DEVICE, NULL);
59 display->core_pointer->name = "Core Pointer";
60 display->core_pointer->source = GDK_SOURCE_MOUSE;
61 display->core_pointer->mode = GDK_MODE_SCREEN;
62 display->core_pointer->has_cursor = TRUE;
63 display->core_pointer->num_axes = 2;
64 display->core_pointer->axes = gdk_input_core_axes;
65 display->core_pointer->num_keys = 0;
66 display->core_pointer->keys = NULL;
70 gdk_device_get_type (void)
72 static GType object_type = 0;
76 const GTypeInfo object_info =
78 sizeof (GdkDeviceClass),
80 (GBaseFinalizeFunc) NULL,
81 (GClassInitFunc) NULL,
82 NULL, /* class_finalize */
83 NULL, /* class_data */
84 sizeof (GdkDevicePrivate),
86 (GInstanceInitFunc) NULL,
89 object_type = g_type_register_static (G_TYPE_OBJECT,
90 g_intern_static_string ("GdkDevice"),
98 gdk_devices_list (void)
100 return gdk_display_list_devices (_gdk_display);
104 gdk_display_list_devices (GdkDisplay *dpy)
106 g_return_val_if_fail (dpy == _gdk_display, NULL);
108 _gdk_input_wintab_init_check ();
109 return _gdk_input_devices;
113 gdk_device_set_source (GdkDevice *device,
114 GdkInputSource source)
116 g_return_if_fail (device != NULL);
118 device->source = source;
122 gdk_device_set_key (GdkDevice *device,
125 GdkModifierType modifiers)
127 g_return_if_fail (device != NULL);
128 g_return_if_fail (index < device->num_keys);
130 device->keys[index].keyval = keyval;
131 device->keys[index].modifiers = modifiers;
135 gdk_device_set_axis_use (GdkDevice *device,
139 g_return_if_fail (device != NULL);
140 g_return_if_fail (index < device->num_axes);
142 device->axes[index].use = use;
148 device->axes[index].min = 0.;
149 device->axes[index].max = 0.;
153 device->axes[index].min = -1.;
154 device->axes[index].max = 1;
157 device->axes[index].min = 0.;
158 device->axes[index].max = 1;
164 gdk_device_get_history (GdkDevice *device,
168 GdkTimeCoord ***events,
171 g_return_val_if_fail (window != NULL, FALSE);
172 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
173 g_return_val_if_fail (events != NULL, FALSE);
174 g_return_val_if_fail (n_events != NULL, FALSE);
181 if (GDK_WINDOW_DESTROYED (window))
184 if (GDK_IS_CORE (device))
187 return _gdk_device_get_history (device, window, start, stop, events, n_events);
191 _gdk_device_allocate_history (GdkDevice *device,
194 GdkTimeCoord **result = g_new (GdkTimeCoord *, n_events);
197 for (i=0; i<n_events; i++)
198 result[i] = g_malloc (sizeof (GdkTimeCoord) -
199 sizeof (double) * (GDK_MAX_TIMECOORD_AXES - device->num_axes));
205 gdk_device_free_history (GdkTimeCoord **events,
210 for (i=0; i<n_events; i++)
217 _gdk_input_window_find(GdkWindow *window)
221 for (tmp_list=_gdk_input_windows; tmp_list; tmp_list=tmp_list->next)
222 if (((GdkInputWindow *)(tmp_list->data))->window == window)
223 return (GdkInputWindow *)(tmp_list->data);
225 return NULL; /* Not found */
228 /* FIXME: this routine currently needs to be called between creation
229 and the corresponding configure event (because it doesn't get the
230 root_relative_geometry). This should work with
231 gtk_window_set_extension_events, but will likely fail in other
235 gdk_input_set_extension_events (GdkWindow *window, gint mask,
236 GdkExtensionMode mode)
238 GdkWindowObject *window_private;
242 g_return_if_fail (window != NULL);
243 g_return_if_fail (GDK_IS_WINDOW (window));
245 window_private = (GdkWindowObject*) window;
246 if (GDK_WINDOW_DESTROYED (window))
249 if (mode == GDK_EXTENSION_EVENTS_NONE)
254 _gdk_input_wintab_init_check ();
256 iw = g_new(GdkInputWindow,1);
261 iw->obscuring = NULL;
262 iw->num_obscuring = 0;
265 _gdk_input_windows = g_list_append(_gdk_input_windows,iw);
266 window_private->extension_events = mask;
268 /* Add enter window events to the event mask */
269 if (g_list_length (_gdk_input_devices) > 1)
270 gdk_window_set_events (window,
271 gdk_window_get_events (window) |
272 GDK_ENTER_NOTIFY_MASK);
276 iw = _gdk_input_window_find (window);
279 _gdk_input_windows = g_list_remove(_gdk_input_windows,iw);
283 window_private->extension_events = 0;
286 for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
288 GdkDevicePrivate *gdkdev = tmp_list->data;
290 if (!GDK_IS_CORE (gdkdev))
292 if (mask != 0 && gdkdev->info.mode != GDK_MODE_DISABLED
293 && (gdkdev->info.has_cursor || mode == GDK_EXTENSION_EVENTS_ALL))
294 _gdk_input_enable_window (window,gdkdev);
296 _gdk_input_disable_window (window,gdkdev);
302 _gdk_input_window_destroy (GdkWindow *window)
304 GdkInputWindow *input_window;
306 input_window = _gdk_input_window_find (window);
307 g_return_if_fail (input_window != NULL);
309 _gdk_input_windows = g_list_remove (_gdk_input_windows,input_window);
310 g_free(input_window);
314 _gdk_input_crossing_event (GdkWindow *window,
317 GdkWindowObject *priv = (GdkWindowObject *)window;
318 GdkInputWindow *input_window;
324 /* No idea what to do... */
326 gdk_input_check_proximity(display);
328 input_window = priv->input_window;
329 if (input_window != NULL)
331 _gdk_input_get_root_relative_geometry (window, &root_x, &root_y);
332 input_window->root_x = root_x;
333 input_window->root_y = root_y;
338 _gdk_input_ignore_core = FALSE;
342 _gdk_input_exit (void)
345 GdkDevicePrivate *gdkdev;
347 for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
349 gdkdev = (GdkDevicePrivate *)(tmp_list->data);
350 if (!GDK_IS_CORE (gdkdev))
352 gdk_device_set_mode (&gdkdev->info, GDK_MODE_DISABLED);
354 g_free(gdkdev->info.name);
355 g_free(gdkdev->axes);
356 g_free(gdkdev->info.axes);
357 g_free(gdkdev->info.keys);
362 g_list_free(_gdk_input_devices);
364 for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
365 g_free(tmp_list->data);
367 g_list_free(_gdk_input_windows);
371 gdk_device_get_axis (GdkDevice *device,
378 g_return_val_if_fail (device != NULL, FALSE);
383 for (i=0; i<device->num_axes; i++)
384 if (device->axes[i].use == use)
395 gdk_device_set_mode (GdkDevice *device,
399 GdkDevicePrivate *gdkdev;
400 GdkInputMode old_mode;
401 GdkInputWindow *input_window;
403 if (GDK_IS_CORE (device))
406 gdkdev = (GdkDevicePrivate *)device;
408 if (device->mode == mode)
411 old_mode = device->mode;
414 if (mode == GDK_MODE_WINDOW)
416 device->has_cursor = FALSE;
417 for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
419 input_window = (GdkInputWindow *)tmp_list->data;
420 if (input_window->mode != GDK_EXTENSION_EVENTS_CURSOR)
421 _gdk_input_enable_window (input_window->window, gdkdev);
423 if (old_mode != GDK_MODE_DISABLED)
424 _gdk_input_disable_window (input_window->window, gdkdev);
427 else if (mode == GDK_MODE_SCREEN)
429 device->has_cursor = TRUE;
430 for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
431 _gdk_input_enable_window (((GdkInputWindow *)tmp_list->data)->window,
434 else /* mode == GDK_MODE_DISABLED */
436 for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
438 input_window = (GdkInputWindow *)tmp_list->data;
439 if (old_mode != GDK_MODE_WINDOW ||
440 input_window->mode != GDK_EXTENSION_EVENTS_CURSOR)
441 _gdk_input_disable_window (input_window->window, gdkdev);