]> Pileus Git - ~andy/gtk/blob - gdk/x11/gdkinput.c
[docs] Use the correct gtk-doc notation
[~andy/gtk] / gdk / x11 / gdkinput.c
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 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.
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  * Lesser General Public License for more details.
13  *
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.
18  */
19
20 /*
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/.
25  */
26
27 #include "config.h"
28
29 #include <stdlib.h>
30
31 #include "gdkscreen-x11.h"
32 #include "gdkdisplay-x11.h"
33 #include "gdkwindow.h"
34 #include "gdkalias.h"
35
36 /* Addition used for extension_events mask */
37 #define GDK_ALL_DEVICES_MASK (1<<30)
38
39 struct _GdkInputWindow
40 {
41   GList *windows; /* GdkWindow:s with extension_events set */
42
43   /* gdk window */
44   GdkWindow *impl_window; /* an impl window */
45 };
46
47
48 /**
49  * gdk_devices_list:
50  *
51  * Returns the list of available input devices for the default display.
52  * The list is statically allocated and should not be freed.
53  *
54  * Return value: a list of #GdkDevice
55  *
56  * Deprecated: 3.0: Use gdk_device_manager_list_devices() instead.
57  **/
58 GList *
59 gdk_devices_list (void)
60 {
61   return gdk_display_list_devices (gdk_display_get_default ());
62 }
63
64 static void
65 _gdk_input_select_device_events (GdkWindow *impl_window,
66                                  GdkDevice *device)
67 {
68   guint event_mask;
69   GdkWindowObject *w;
70   GdkInputWindow *iw;
71   GdkInputMode mode;
72   gboolean has_cursor;
73   GdkDeviceType type;
74   GList *l;
75
76   event_mask = 0;
77   iw = ((GdkWindowObject *)impl_window)->input_window;
78
79   g_object_get (device,
80                 "type", &type,
81                 "input-mode", &mode,
82                 "has-cursor", &has_cursor,
83                 NULL);
84
85   if (iw == NULL ||
86       mode == GDK_MODE_DISABLED ||
87       type == GDK_DEVICE_TYPE_MASTER)
88     return;
89
90   for (l = iw->windows; l != NULL; l = l->next)
91     {
92       w = l->data;
93
94       if (has_cursor || (w->extension_events & GDK_ALL_DEVICES_MASK))
95         {
96           event_mask = w->extension_events;
97
98           if (event_mask)
99             event_mask |= GDK_PROXIMITY_OUT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK;
100
101           gdk_window_set_device_events ((GdkWindow *) w, device, event_mask);
102         }
103     }
104 }
105
106 static void
107 unset_extension_events (GdkWindow *window)
108 {
109   GdkWindowObject *window_private;
110   GdkWindowObject *impl_window;
111   GdkDisplayX11 *display_x11;
112   GdkInputWindow *iw;
113
114   window_private = (GdkWindowObject*) window;
115   impl_window = (GdkWindowObject *)_gdk_window_get_impl_window (window);
116   iw = impl_window->input_window;
117
118   display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window));
119
120   if (window_private->extension_events != 0)
121     {
122       g_assert (iw != NULL);
123       g_assert (g_list_find (iw->windows, window) != NULL);
124
125       iw->windows = g_list_remove (iw->windows, window);
126       if (iw->windows == NULL)
127         {
128           impl_window->input_window = NULL;
129           display_x11->input_windows = g_list_remove (display_x11->input_windows, iw);
130           g_free (iw);
131         }
132     }
133
134   window_private->extension_events = 0;
135 }
136
137 /**
138  * gdk_input_set_extension_events:
139  * @window: a #GdkWindow.
140  * @mask: the event mask
141  * @mode: the type of extension events that are desired.
142  *
143  * Turns extension events on or off for a particular window,
144  * and specifies the event mask for extension events.
145  *
146  * Deprecated: 3.0: Use gdk_window_set_device_events() instead.
147  **/
148 void
149 gdk_input_set_extension_events (GdkWindow        *window,
150                                 gint              mask,
151                                 GdkExtensionMode  mode)
152 {
153   GdkWindowObject *window_private;
154   GdkWindowObject *impl_window;
155   GdkInputWindow *iw;
156   GdkDisplayX11 *display_x11;
157 #ifndef XINPUT_NONE
158   GList *tmp_list;
159 #endif
160
161   g_return_if_fail (window != NULL);
162   g_return_if_fail (GDK_WINDOW_IS_X11 (window));
163
164   window_private = (GdkWindowObject*) window;
165   display_x11 = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window));
166   if (GDK_WINDOW_DESTROYED (window))
167     return;
168
169   impl_window = (GdkWindowObject *)_gdk_window_get_impl_window (window);
170
171   if (mode == GDK_EXTENSION_EVENTS_ALL && mask != 0)
172     mask |= GDK_ALL_DEVICES_MASK;
173
174   if (mode == GDK_EXTENSION_EVENTS_NONE)
175     mask = 0;
176
177   iw = impl_window->input_window;
178
179   if (mask != 0)
180     {
181       if (!iw)
182         {
183           iw = g_new0 (GdkInputWindow,1);
184
185           iw->impl_window = (GdkWindow *)impl_window;
186
187           iw->windows = NULL;
188
189           display_x11->input_windows = g_list_append (display_x11->input_windows, iw);
190           impl_window->input_window = iw;
191         }
192
193       if (window_private->extension_events == 0)
194         iw->windows = g_list_append (iw->windows, window);
195       window_private->extension_events = mask;
196     }
197   else
198     {
199       unset_extension_events (window);
200     }
201
202 #ifndef XINPUT_NONE
203   for (tmp_list = display_x11->input_devices; tmp_list; tmp_list = tmp_list->next)
204     {
205       GdkDevice *dev = tmp_list->data;
206       _gdk_input_select_device_events (GDK_WINDOW (impl_window), dev);
207     }
208 #endif /* !XINPUT_NONE */
209 }
210
211 void
212 _gdk_input_window_destroy (GdkWindow *window)
213 {
214   unset_extension_events (window);
215 }
216
217 void
218 _gdk_input_check_extension_events (GdkDevice *device)
219 {
220   GdkDisplayX11 *display_impl;
221   GdkInputWindow *input_window;
222   GList *tmp_list;
223
224   display_impl = GDK_DISPLAY_X11 (gdk_device_get_display (device));
225
226   for (tmp_list = display_impl->input_windows; tmp_list; tmp_list = tmp_list->next)
227     {
228       input_window = tmp_list->data;
229       _gdk_input_select_device_events (input_window->impl_window, device);
230     }
231 }
232
233 #define __GDK_INPUT_C__
234 #include "gdkaliasdef.c"