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/.
30 #include "gdkprivate-fb.h"
32 #include "gdkprivate.h"
33 #include "gdkinputprivate.h"
35 static const GdkDeviceAxis gdk_input_core_axes[] = {
40 static GdkDevice gdk_input_core_info =
47 (GdkDeviceAxis *)gdk_input_core_axes,
52 GdkDevice *gdk_core_pointer = (GdkDevice *)&gdk_input_core_info;
54 /* Global variables */
56 gchar *gdk_input_gxid_host;
57 gint gdk_input_gxid_port;
58 gint gdk_input_ignore_core;
59 GList *gdk_input_windows;
60 GList *gdk_input_devices;
63 gdk_devices_list (void)
65 return gdk_input_devices;
69 gdk_device_set_source (GdkDevice *device, GdkInputSource source)
71 device->source = source;
76 gdk_device_set_key (GdkDevice *device,
79 GdkModifierType modifiers)
81 g_return_if_fail (device != NULL);
82 g_return_if_fail (index < device->num_keys);
84 device->keys[index].keyval = keyval;
85 device->keys[index].modifiers = modifiers;
89 gdk_device_set_axis_use (GdkDevice *device,
93 g_return_if_fail (device != NULL);
94 g_return_if_fail (index < device->num_axes);
96 device->axes[index].use = use;
102 device->axes[index].min = 0.;
103 device->axes[index].max = 0.;
107 device->axes[index].min = -1.;
108 device->axes[index].max = 1;
111 device->axes[index].min = 0.;
112 device->axes[index].max = 1;
118 gdk_device_get_state (GdkDevice *device,
121 GdkModifierType *mask)
125 g_assert(device == gdk_core_pointer);
127 gdk_window_get_pointer (window, &x_int, &y_int, mask);
137 gdk_device_free_history (GdkTimeCoord **events,
142 for (i=0; i<n_events; i++)
149 gdk_device_get_history (GdkDevice *device,
153 GdkTimeCoord ***events,
156 g_return_val_if_fail (window != NULL, FALSE);
157 g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
158 g_return_val_if_fail (events != NULL, FALSE);
159 g_return_val_if_fail (n_events != NULL, FALSE);
167 gdk_device_set_mode (GdkDevice *device,
174 gdk_input_enable_window (GdkWindow *window, GdkDevicePrivate *gdkdev)
180 gdk_input_disable_window (GdkWindow *window, GdkDevicePrivate *gdkdev)
187 gdk_input_window_find(GdkWindow *window)
191 for (tmp_list=gdk_input_windows; tmp_list; tmp_list=tmp_list->next)
192 if (((GdkInputWindow *)(tmp_list->data))->window == window)
193 return (GdkInputWindow *)(tmp_list->data);
195 return NULL; /* Not found */
198 /* FIXME: this routine currently needs to be called between creation
199 and the corresponding configure event (because it doesn't get the
200 root_relative_geometry). This should work with
201 gtk_window_set_extension_events, but will likely fail in other
205 gdk_input_set_extension_events (GdkWindow *window, gint mask,
206 GdkExtensionMode mode)
208 GdkWindowPrivate *window_private;
212 g_return_if_fail (window != NULL);
213 g_return_if_fail (GDK_IS_WINDOW (window));
215 window_private = (GdkWindowPrivate*) window;
217 if (mode == GDK_EXTENSION_EVENTS_NONE)
222 iw = g_new(GdkInputWindow,1);
227 iw->obscuring = NULL;
228 iw->num_obscuring = 0;
231 gdk_input_windows = g_list_append(gdk_input_windows,iw);
232 window_private->extension_events = mask;
234 /* Add enter window events to the event mask */
235 /* FIXME, this is not needed for XINPUT_NONE */
236 gdk_window_set_events (window,
237 gdk_window_get_events (window) |
238 GDK_ENTER_NOTIFY_MASK);
242 iw = gdk_input_window_find (window);
245 gdk_input_windows = g_list_remove(gdk_input_windows,iw);
249 window_private->extension_events = 0;
252 for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
254 GdkDevicePrivate *gdkdev = (GdkDevicePrivate *)(tmp_list->data);
256 if (gdkdev != (GdkDevicePrivate *)gdk_core_pointer)
258 if (mask != 0 && gdkdev->info.mode != GDK_MODE_DISABLED
259 && (gdkdev->info.has_cursor || mode == GDK_EXTENSION_EVENTS_ALL))
260 gdk_input_enable_window(window,gdkdev);
262 gdk_input_disable_window(window,gdkdev);
268 gdk_input_window_destroy (GdkWindow *window)
270 GdkInputWindow *input_window;
272 input_window = gdk_input_window_find (window);
273 g_return_if_fail (input_window != NULL);
275 gdk_input_windows = g_list_remove (gdk_input_windows,input_window);
276 g_free(input_window);
280 gdk_input_exit (void)
283 GdkDevicePrivate *gdkdev;
285 for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
287 gdkdev = (GdkDevicePrivate *)(tmp_list->data);
288 if (gdkdev != (GdkDevicePrivate *)gdk_core_pointer)
290 gdk_device_set_mode((GdkDevice *)gdkdev, GDK_MODE_DISABLED);
292 g_free(gdkdev->info.name);
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_device_get_axis:
310 * @axis: a #GdkDevice
311 * @axes: pointer to an array of axes
312 * @use: the use to look for
313 * @value: location to store the found value.
315 * Interprets an array of double as axis values for a given device,
316 * and locates the value in the array for a given axis use.
318 * Return value: %TRUE if the given axis use was found, otherwies %FALSE
321 gdk_device_get_axis (GdkDevice *device, gdouble *axes, GdkAxisUse use, gdouble *value)
325 g_return_val_if_fail (device != NULL, FALSE);
330 for (i=0; i<device->num_axes; i++)
331 if (device->axes[i].use == use)