1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * Copyright (C) 1999 Tor Lillqvist
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 /*
22  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.
24  */
25 
26 /*
27  * GTK+ DirectFB backend
28  * Copyright (C) 2001-2002  convergence integrated media GmbH
29  * Copyright (C) 2002-2004  convergence GmbH
30  * Written by Denis Oliver Kropp <dok@convergence.de> and
31  *            Sven Neumann <sven@convergence.de>
32  */
33 
34 #include "config.h"
35 #include "gdk.h"
36 
37 #include "gdkdirectfb.h"
38 #include "gdkprivate-directfb.h"
39 #include "gdkinput-directfb.h"
40 
41 #include "gdkinput.h"
42 #include "gdkkeysyms.h"
43 #include "gdkalias.h"
44 
45 
46 static GdkDeviceAxis gdk_input_core_axes[] =
47   {
48     { GDK_AXIS_X, 0, 0 },
49     { GDK_AXIS_Y, 0, 0 }
50   };
51 
52 
53 GdkDevice *_gdk_core_pointer      = NULL;
54 GList     *_gdk_input_devices     = NULL;
55 gboolean   _gdk_input_ignore_core = FALSE;
56 
57 int _gdk_directfb_mouse_x = 0;
58 int _gdk_directfb_mouse_y = 0;
59 
60 
61 void
_gdk_init_input_core(void)62 _gdk_init_input_core (void)
63 {
64   GdkDisplay *display = GDK_DISPLAY_OBJECT (_gdk_display);
65 
66   _gdk_core_pointer = g_object_new (GDK_TYPE_DEVICE, NULL);
67 
68   _gdk_core_pointer->name       = "Core Pointer";
69   _gdk_core_pointer->source     = GDK_SOURCE_MOUSE;
70   _gdk_core_pointer->mode       = GDK_MODE_SCREEN;
71   _gdk_core_pointer->has_cursor = TRUE;
72   _gdk_core_pointer->num_axes   = 2;
73   _gdk_core_pointer->axes       = gdk_input_core_axes;
74   _gdk_core_pointer->num_keys   = 0;
75   _gdk_core_pointer->keys       = NULL;
76   display->core_pointer         = _gdk_core_pointer;
77 }
78 
79 static void
gdk_device_finalize(GObject * object)80 gdk_device_finalize (GObject *object)
81 {
82   g_error ("A GdkDevice object was finalized. This should not happen");
83 }
84 
85 static void
gdk_device_class_init(GObjectClass * class)86 gdk_device_class_init (GObjectClass *class)
87 {
88   class->finalize = gdk_device_finalize;
89 }
90 
91 GType
gdk_device_get_type(void)92 gdk_device_get_type (void)
93 {
94   static GType object_type = 0;
95 
96   if (!object_type)
97     {
98       const GTypeInfo object_info =
99         {
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 (GdkDevice),
107           0,              /* n_preallocs */
108           (GInstanceInitFunc) NULL,
109         };
110 
111       object_type = g_type_register_static (G_TYPE_OBJECT,
112                                             "GdkDevice",
113                                             &object_info, 0);
114     }
115 
116   return object_type;
117 }
118 
119 /**
120  * gdk_devices_list:
121  *
122  * Returns the list of available input devices for the default display.
123  * The list is statically allocated and should not be freed.
124  *
125  * Return value: a list of #GdkDevice
126  **/
127 GList *
gdk_devices_list(void)128 gdk_devices_list (void)
129 {
130   return _gdk_input_devices;
131 }
132 
133 
134 /**
135  * gdk_display_list_devices:
136  * @display: a #GdkDisplay
137  *
138  * Returns the list of available input devices attached to @display.
139  * The list is statically allocated and should not be freed.
140  *
141  * Return value: a list of #GdkDevice
142  *
143  * Since: 2.2
144  **/
145 GList *
gdk_display_list_devices(GdkDisplay * dpy)146 gdk_display_list_devices (GdkDisplay *dpy)
147 {
148   return _gdk_input_devices;
149 }
150 
151 /**
152  * gdk_device_get_name:
153  * @device: a #GdkDevice
154  *
155  * Determines the name of the device.
156  *
157  * Return value: a name
158  *
159  * Since: 2.22
160  **/
161 const gchar *
gdk_device_get_name(GdkDevice * device)162 gdk_device_get_name (GdkDevice *device)
163 {
164   g_return_val_if_fail (GDK_IS_DEVICE (device), NULL);
165 
166   return device->name;
167 }
168 
169 /**
170  * gdk_device_get_source:
171  * @device: a #GdkDevice
172  *
173  * Determines the type of the device.
174  *
175  * Return value: a #GdkInputSource
176  *
177  * Since: 2.22
178  **/
179 GdkInputSource
gdk_device_get_source(GdkDevice * device)180 gdk_device_get_source (GdkDevice *device)
181 {
182   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
183 
184   return device->source;
185 }
186 
187 /**
188  * gdk_device_get_mode:
189  * @device: a #GdkDevice
190  *
191  * Determines the mode of the device.
192  *
193  * Return value: a #GdkInputSource
194  *
195  * Since: 2.22
196  **/
197 GdkInputMode
gdk_device_get_mode(GdkDevice * device)198 gdk_device_get_mode (GdkDevice *device)
199 {
200   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
201 
202   return device->mode;
203 }
204 
205 /**
206  * gdk_device_get_has_cursor:
207  * @device: a #GdkDevice
208  *
209  * Determines whether the pointer follows device motion.
210  *
211  * Return value: %TRUE if the pointer follows device motion
212  *
213  * Since: 2.22
214  **/
215 gboolean
gdk_device_get_has_cursor(GdkDevice * device)216 gdk_device_get_has_cursor (GdkDevice *device)
217 {
218   g_return_val_if_fail (GDK_IS_DEVICE (device), FALSE);
219 
220   return device->has_cursor;
221 }
222 
223 void
gdk_device_set_source(GdkDevice * device,GdkInputSource source)224 gdk_device_set_source (GdkDevice      *device,
225                        GdkInputSource  source)
226 {
227   g_return_if_fail (device != NULL);
228   device->source = source;
229 }
230 
231 /**
232  * gdk_device_get_key:
233  * @device: a #GdkDevice.
234  * @index: the index of the macro button to get.
235  * @keyval: return value for the keyval.
236  * @modifiers: return value for modifiers.
237  *
238  * If @index has a valid keyval, this function will
239  * fill in @keyval and @modifiers with the keyval settings.
240  *
241  * Since: 2.22
242  **/
243 void
gdk_device_get_key(GdkDevice * device,guint index,guint * keyval,GdkModifierType * modifiers)244 gdk_device_get_key (GdkDevice       *device,
245                     guint            index,
246                     guint           *keyval,
247                     GdkModifierType *modifiers)
248 {
249   g_return_if_fail (GDK_IS_DEVICE (device));
250   g_return_if_fail (index < device->num_keys);
251 
252   if (!device->keys[index].keyval &&
253       !device->keys[index].modifiers)
254     return;
255 
256   if (keyval)
257     *keyval = device->keys[index].keyval;
258 
259   if (modifiers)
260     *modifiers = device->keys[index].modifiers;
261 }
262 
263 /**
264  * gdk_device_get_axis_use:
265  * @device: a #GdkDevice.
266  * @index: the index of the axis.
267  *
268  * Returns the axis use for @index.
269  *
270  * Returns: a #GdkAxisUse specifying how the axis is used.
271  *
272  * Since: 2.22
273  **/
274 GdkAxisUse
gdk_device_get_axis_use(GdkDevice * device,guint index)275 gdk_device_get_axis_use (GdkDevice *device,
276                          guint      index)
277 {
278   g_return_val_if_fail (GDK_IS_DEVICE (device), GDK_AXIS_IGNORE);
279   g_return_val_if_fail (index < device->num_axes, GDK_AXIS_IGNORE);
280 
281   return device->axes[index].use;
282 }
283 
284 gint
gdk_device_get_n_keys(GdkDevice * device)285 gdk_device_get_n_keys (GdkDevice *device)
286 {
287   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
288 
289   return device->num_keys;
290 }
291 
292 /**
293  * gdk_device_get_n_axes:
294  * @device: a #GdkDevice.
295  *
296  * Gets the number of axes of a device.
297  *
298  * Returns: the number of axes of @device
299  *
300  * Since: 2.22
301  **/
302 gint
gdk_device_get_n_axes(GdkDevice * device)303 gdk_device_get_n_axes (GdkDevice *device)
304 {
305   g_return_val_if_fail (GDK_IS_DEVICE (device), 0);
306 
307   return device->num_axes;
308 }
309 
310 void
gdk_device_set_axis_use(GdkDevice * device,guint index,GdkAxisUse use)311 gdk_device_set_axis_use (GdkDevice   *device,
312                          guint        index,
313                          GdkAxisUse   use)
314 {
315   g_return_if_fail (device != NULL);
316   g_return_if_fail (index < device->num_axes);
317 
318   device->axes[index].use = use;
319 
320   switch (use)
321     {
322     case GDK_AXIS_X:
323     case GDK_AXIS_Y:
324       device->axes[index].min =  0.0;
325       device->axes[index].max =  0.0;
326       break;
327     case GDK_AXIS_XTILT:
328     case GDK_AXIS_YTILT:
329       device->axes[index].min = -1.0;
330       device->axes[index].max =  1.0;
331       break;
332     default:
333       device->axes[index].min =  0.0;
334       device->axes[index].max =  1.0;
335       break;
336     }
337 }
338 
339 gboolean
gdk_device_set_mode(GdkDevice * device,GdkInputMode mode)340 gdk_device_set_mode (GdkDevice    *device,
341                      GdkInputMode  mode)
342 {
343   g_message ("unimplemented %s", G_STRFUNC);
344 
345   return FALSE;
346 }
347 
348 gboolean
gdk_device_get_history(GdkDevice * device,GdkWindow * window,guint32 start,guint32 stop,GdkTimeCoord *** events,gint * n_events)349 gdk_device_get_history  (GdkDevice      *device,
350                          GdkWindow      *window,
351                          guint32         start,
352                          guint32         stop,
353                          GdkTimeCoord ***events,
354                          gint           *n_events)
355 {
356   g_return_val_if_fail (GDK_IS_WINDOW (window), FALSE);
357   g_return_val_if_fail (events != NULL, FALSE);
358   g_return_val_if_fail (n_events != NULL, FALSE);
359 
360   *n_events = 0;
361   *events = NULL;
362 
363   if (GDK_WINDOW_DESTROYED (window))
364     return FALSE;
365 
366   if (GDK_IS_CORE (device))
367     return FALSE;
368   else
369     return FALSE;
370   //TODODO_gdk_device_get_history (device, window, start, stop, events, n_events);
371 }
372 
373 void
gdk_device_free_history(GdkTimeCoord ** events,gint n_events)374 gdk_device_free_history (GdkTimeCoord **events,
375                          gint           n_events)
376 {
377   gint i;
378 
379   for (i = 0; i < n_events; i++)
380     g_free (events[i]);
381 
382   g_free (events);
383 }
384 
385 void
gdk_device_get_state(GdkDevice * device,GdkWindow * window,gdouble * axes,GdkModifierType * mask)386 gdk_device_get_state (GdkDevice       *device,
387                       GdkWindow       *window,
388                       gdouble         *axes,
389                       GdkModifierType *mask)
390 {
391   g_return_if_fail (device != NULL);
392   g_return_if_fail (GDK_IS_WINDOW (window));
393 
394   if (mask)
395     *mask = _gdk_directfb_modifiers;
396 }
397 
398 void
gdk_directfb_mouse_get_info(gint * x,gint * y,GdkModifierType * mask)399 gdk_directfb_mouse_get_info (gint            *x,
400                              gint            *y,
401                              GdkModifierType *mask)
402 {
403   if (x)
404     *x = _gdk_directfb_mouse_x;
405 
406   if (y)
407     *y = _gdk_directfb_mouse_y;
408 
409   if (mask)
410     *mask = _gdk_directfb_modifiers;
411 }
412 
413 void
gdk_input_set_extension_events(GdkWindow * window,gint mask,GdkExtensionMode mode)414 gdk_input_set_extension_events (GdkWindow        *window,
415                                 gint              mask,
416                                 GdkExtensionMode  mode)
417 {
418   g_message ("unimplemented %s", G_STRFUNC);
419 }
420 
421 void
gdk_device_set_key(GdkDevice * device,guint index,guint keyval,GdkModifierType modifiers)422 gdk_device_set_key (GdkDevice       *device,
423                     guint            index,
424                     guint            keyval,
425                     GdkModifierType  modifiers)
426 {
427   g_return_if_fail (device != NULL);
428   g_return_if_fail (index < device->num_keys);
429 
430   device->keys[index].keyval    = keyval;
431   device->keys[index].modifiers = modifiers;
432 }
433 
434 /**
435  * gdk_device_get_axis:
436  * @device: a #GdkDevice
437  * @axes: pointer to an array of axes
438  * @use: the use to look for
439  * @value: location to store the found value.
440  *
441  * Interprets an array of double as axis values for a given device,
442  * and locates the value in the array for a given axis use.
443  *
444  * Return value: %TRUE if the given axis use was found, otherwise %FALSE
445  **/
446 gboolean
gdk_device_get_axis(GdkDevice * device,gdouble * axes,GdkAxisUse use,gdouble * value)447 gdk_device_get_axis (GdkDevice  *device,
448                      gdouble    *axes,
449                      GdkAxisUse  use,
450                      gdouble    *value)
451 {
452   gint i;
453   g_return_val_if_fail (device != NULL, FALSE);
454 
455   if (axes == NULL)
456     return FALSE;
457 
458   for (i = 0; i < device->num_axes; i++)
459     if (device->axes[i].use == use)
460       {
461 	if (value)
462 	  *value = axes[i];
463 	return TRUE;
464       }
465 
466   return FALSE;
467 }
468 
469 void
_gdk_input_init(void)470 _gdk_input_init (void)
471 {
472   _gdk_init_input_core ();
473   _gdk_input_devices = g_list_append (NULL, _gdk_core_pointer);
474   _gdk_input_ignore_core = FALSE;
475 }
476 
477 void
_gdk_input_exit(void)478 _gdk_input_exit (void)
479 {
480   GList     *tmp_list;
481   GdkDevice *gdkdev;
482 
483   for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
484     {
485       gdkdev = (GdkDevice *)(tmp_list->data);
486       if (!GDK_IS_CORE (gdkdev))
487 	{
488 	  gdk_device_set_mode ((GdkDevice *)gdkdev, GDK_MODE_DISABLED);
489 
490 	  g_free (gdkdev->name);
491 	  g_free (gdkdev->axes);
492 	  g_free (gdkdev->keys);
493 	  g_free (gdkdev);
494 	}
495     }
496 
497   g_list_free (_gdk_input_devices);
498 }
499 
500 #define __GDK_INPUT_NONE_C__
501 #define __GDK_INPUT_C__
502 #include "gdkaliasdef.c"
503