source: trunk/third/gtk/gdk/gdkinput.c @ 14482

Revision 14482, 8.5 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r14481, which included commits to RCS files with non-trunk default branches.
Line 
1/* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
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.
8 *
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.
13 *
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.
18 */
19
20/*
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/.
25 */
26
27#include <stdlib.h>
28#include <X11/Xlib.h>
29#include <X11/Xutil.h>
30#include "config.h"
31#include "gdk.h"
32#include "gdkx.h"
33#include "gdkprivate.h"
34#include "gdkinput.h"
35
36
37/* Forward declarations */
38
39static gint gdk_input_enable_window (GdkWindow *window,
40                                     GdkDevicePrivate *gdkdev);
41static gint gdk_input_disable_window (GdkWindow *window,
42                                      GdkDevicePrivate *gdkdev);
43static GdkInputWindow *gdk_input_window_find (GdkWindow *window);
44static GdkDevicePrivate *gdk_input_find_device (guint32 id);
45
46
47/* Incorporate the specific routines depending on compilation options */
48
49static const GdkAxisUse gdk_input_core_axes[] = { GDK_AXIS_X, GDK_AXIS_Y };
50
51static const GdkDeviceInfo gdk_input_core_info =
52{
53  GDK_CORE_POINTER,
54  "Core Pointer",
55  GDK_SOURCE_MOUSE,
56  GDK_MODE_SCREEN,
57  TRUE,
58  2,
59  gdk_input_core_axes
60};
61
62/* Global variables  */
63
64GdkInputVTable    gdk_input_vtable;
65/* information about network port and host for gxid daemon */
66gchar            *gdk_input_gxid_host;
67gint              gdk_input_gxid_port;
68gint              gdk_input_ignore_core;
69
70/* Local variables */
71
72static GList            *gdk_input_devices;
73static GList            *gdk_input_windows;
74
75#include "gdkinputnone.h"
76#include "gdkinputcommon.h"
77#include "gdkinputxfree.h"
78#include "gdkinputgxi.h"
79
80GList *
81gdk_input_list_devices (void)
82{
83  return gdk_input_devices;
84}
85
86void
87gdk_input_set_source (guint32 deviceid, GdkInputSource source)
88{
89  GdkDevicePrivate *gdkdev = gdk_input_find_device(deviceid);
90  g_return_if_fail (gdkdev != NULL);
91
92  gdkdev->info.source = source;
93}
94
95gboolean
96gdk_input_set_mode (guint32 deviceid, GdkInputMode mode)
97{
98  if (deviceid == GDK_CORE_POINTER)
99    return FALSE;
100
101  if (gdk_input_vtable.set_mode)
102    return gdk_input_vtable.set_mode(deviceid,mode);
103  else
104    return FALSE;
105}
106
107void
108gdk_input_set_axes (guint32 deviceid, GdkAxisUse *axes)
109{
110  if (deviceid != GDK_CORE_POINTER && gdk_input_vtable.set_axes)
111    gdk_input_vtable.set_axes (deviceid, axes);
112}
113
114void gdk_input_set_key (guint32 deviceid,
115                        guint   index,
116                        guint   keyval,
117                        GdkModifierType modifiers)
118{
119  if (deviceid != GDK_CORE_POINTER && gdk_input_vtable.set_key)
120    gdk_input_vtable.set_key (deviceid, index, keyval, modifiers);
121}
122
123GdkTimeCoord *
124gdk_input_motion_events (GdkWindow *window,
125                         guint32 deviceid,
126                         guint32 start,
127                         guint32 stop,
128                         gint *nevents_return)
129{
130  GdkWindowPrivate *window_private;
131  XTimeCoord *xcoords;
132  GdkTimeCoord *coords;
133  int i;
134
135  g_return_val_if_fail (window != NULL, NULL);
136  window_private = (GdkWindowPrivate *) window;
137  if (window_private->destroyed)
138    return NULL;
139
140  if (deviceid == GDK_CORE_POINTER)
141    {
142      xcoords = XGetMotionEvents (gdk_display,
143                                  window_private->xwindow,
144                                  start, stop, nevents_return);
145      if (xcoords)
146        {
147          coords = g_new (GdkTimeCoord, *nevents_return);
148          for (i=0; i<*nevents_return; i++)
149            {
150              coords[i].time = xcoords[i].time;
151              coords[i].x = xcoords[i].x;
152              coords[i].y = xcoords[i].y;
153              coords[i].pressure = 0.5;
154              coords[i].xtilt = 0.0;
155              coords[i].ytilt = 0.0;
156            }
157
158          XFree (xcoords);
159
160          return coords;
161        }
162      else
163        return NULL;
164    }
165  else
166    {
167      if (gdk_input_vtable.motion_events)
168        {
169          return gdk_input_vtable.motion_events(window,
170                                                deviceid, start, stop,
171                                                nevents_return);
172        }
173      else
174        {
175          *nevents_return = 0;
176          return NULL;
177        }
178    }
179}
180
181static gint
182gdk_input_enable_window (GdkWindow *window, GdkDevicePrivate *gdkdev)
183{
184  if (gdk_input_vtable.enable_window)
185    return gdk_input_vtable.enable_window (window, gdkdev);
186  else
187    return TRUE;
188}
189
190static gint
191gdk_input_disable_window (GdkWindow *window, GdkDevicePrivate *gdkdev)
192{
193  if (gdk_input_vtable.disable_window)
194    return gdk_input_vtable.disable_window(window,gdkdev);
195  else
196    return TRUE;
197}
198
199
200static GdkInputWindow *
201gdk_input_window_find(GdkWindow *window)
202{
203  GList *tmp_list;
204
205  for (tmp_list=gdk_input_windows; tmp_list; tmp_list=tmp_list->next)
206    if (((GdkInputWindow *)(tmp_list->data))->window == window)
207      return (GdkInputWindow *)(tmp_list->data);
208
209  return NULL;      /* Not found */
210}
211
212/* FIXME: this routine currently needs to be called between creation
213   and the corresponding configure event (because it doesn't get the
214   root_relative_geometry).  This should work with
215   gtk_window_set_extension_events, but will likely fail in other
216   cases */
217
218void
219gdk_input_set_extension_events (GdkWindow *window, gint mask,
220                                GdkExtensionMode mode)
221{
222  GdkWindowPrivate *window_private;
223  GList *tmp_list;
224  GdkInputWindow *iw;
225
226  g_return_if_fail (window != NULL);
227  window_private = (GdkWindowPrivate*) window;
228  if (window_private->destroyed)
229    return;
230
231  if (mode == GDK_EXTENSION_EVENTS_NONE)
232    mask = 0;
233
234  if (mask != 0)
235    {
236      iw = g_new(GdkInputWindow,1);
237
238      iw->window = window;
239      iw->mode = mode;
240
241      iw->obscuring = NULL;
242      iw->num_obscuring = 0;
243      iw->grabbed = FALSE;
244
245      gdk_input_windows = g_list_append(gdk_input_windows,iw);
246      window_private->extension_events = mask;
247
248      /* Add enter window events to the event mask */
249      /* FIXME, this is not needed for XINPUT_NONE */
250      gdk_window_set_events (window,
251                             gdk_window_get_events (window) |
252                             GDK_ENTER_NOTIFY_MASK);
253    }
254  else
255    {
256      iw = gdk_input_window_find (window);
257      if (iw)
258        {
259          gdk_input_windows = g_list_remove(gdk_input_windows,iw);
260          g_free(iw);
261        }
262
263      window_private->extension_events = 0;
264    }
265
266  for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
267    {
268      GdkDevicePrivate *gdkdev = (GdkDevicePrivate *)(tmp_list->data);
269
270      if (gdkdev->info.deviceid != GDK_CORE_POINTER)
271        {
272          if (mask != 0 && gdkdev->info.mode != GDK_MODE_DISABLED
273              && (gdkdev->info.has_cursor || mode == GDK_EXTENSION_EVENTS_ALL))
274            gdk_input_enable_window(window,gdkdev);
275          else
276            gdk_input_disable_window(window,gdkdev);
277        }
278    }
279}
280
281void
282gdk_input_window_destroy (GdkWindow *window)
283{
284  GdkInputWindow *input_window;
285
286  input_window = gdk_input_window_find (window);
287  g_return_if_fail (input_window != NULL);
288
289  gdk_input_windows = g_list_remove (gdk_input_windows,input_window);
290  g_free(input_window);
291}
292
293void
294gdk_input_exit (void)
295{
296  GList *tmp_list;
297  GdkDevicePrivate *gdkdev;
298
299  for (tmp_list = gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
300    {
301      gdkdev = (GdkDevicePrivate *)(tmp_list->data);
302      if (gdkdev->info.deviceid != GDK_CORE_POINTER)
303        {
304          gdk_input_set_mode(gdkdev->info.deviceid,GDK_MODE_DISABLED);
305
306          g_free(gdkdev->info.name);
307#ifndef XINPUT_NONE       
308          g_free(gdkdev->axes);
309#endif   
310          g_free(gdkdev->info.axes);
311          g_free(gdkdev->info.keys);
312          g_free(gdkdev);
313        }
314    }
315
316  g_list_free(gdk_input_devices);
317
318  for (tmp_list = gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
319    {
320      g_free(tmp_list->data);
321    }
322  g_list_free(gdk_input_windows);
323}
324
325static GdkDevicePrivate *
326gdk_input_find_device(guint32 id)
327{
328  GList *tmp_list = gdk_input_devices;
329  GdkDevicePrivate *gdkdev;
330  while (tmp_list)
331    {
332      gdkdev = (GdkDevicePrivate *)(tmp_list->data);
333      if (gdkdev->info.deviceid == id)
334        return gdkdev;
335      tmp_list = tmp_list->next;
336    }
337  return NULL;
338}
339
340void
341gdk_input_window_get_pointer (GdkWindow       *window,
342                              guint32     deviceid,
343                              gdouble         *x,
344                              gdouble         *y,
345                              gdouble         *pressure,
346                              gdouble         *xtilt,
347                              gdouble         *ytilt,
348                              GdkModifierType *mask)
349{
350  if (gdk_input_vtable.get_pointer)
351    gdk_input_vtable.get_pointer (window, deviceid, x, y, pressure,
352                                  xtilt, ytilt, mask);
353}
Note: See TracBrowser for help on using the repository browser.