1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
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.
23 #include "gdkdevice-broadway.h"
25 #include "gdkwindow.h"
26 #include "gdkprivate-broadway.h"
28 static gboolean gdk_broadway_device_get_history (GdkDevice *device,
32 GdkTimeCoord ***events,
34 static void gdk_broadway_device_get_state (GdkDevice *device,
37 GdkModifierType *mask);
38 static void gdk_broadway_device_set_window_cursor (GdkDevice *device,
41 static void gdk_broadway_device_warp (GdkDevice *device,
45 static gboolean gdk_broadway_device_query_state (GdkDevice *device,
47 GdkWindow **root_window,
48 GdkWindow **child_window,
53 GdkModifierType *mask);
54 static GdkGrabStatus gdk_broadway_device_grab (GdkDevice *device,
56 gboolean owner_events,
57 GdkEventMask event_mask,
58 GdkWindow *confine_to,
61 static void gdk_broadway_device_ungrab (GdkDevice *device,
63 static GdkWindow * gdk_broadway_device_window_at_position (GdkDevice *device,
66 GdkModifierType *mask,
67 gboolean get_toplevel);
68 static void gdk_broadway_device_select_window_events (GdkDevice *device,
70 GdkEventMask event_mask);
73 G_DEFINE_TYPE (GdkBroadwayDevice, gdk_broadway_device, GDK_TYPE_DEVICE)
76 gdk_broadway_device_class_init (GdkBroadwayDeviceClass *klass)
78 GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
80 device_class->get_history = gdk_broadway_device_get_history;
81 device_class->get_state = gdk_broadway_device_get_state;
82 device_class->set_window_cursor = gdk_broadway_device_set_window_cursor;
83 device_class->warp = gdk_broadway_device_warp;
84 device_class->query_state = gdk_broadway_device_query_state;
85 device_class->grab = gdk_broadway_device_grab;
86 device_class->ungrab = gdk_broadway_device_ungrab;
87 device_class->window_at_position = gdk_broadway_device_window_at_position;
88 device_class->select_window_events = gdk_broadway_device_select_window_events;
92 gdk_broadway_device_init (GdkBroadwayDevice *device_core)
96 device = GDK_DEVICE (device_core);
98 _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
99 _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
103 gdk_broadway_device_get_history (GdkDevice *device,
107 GdkTimeCoord ***events,
114 gdk_broadway_device_get_state (GdkDevice *device,
117 GdkModifierType *mask)
121 gdk_window_get_pointer (window, &x_int, &y_int, mask);
131 gdk_broadway_device_set_window_cursor (GdkDevice *device,
138 gdk_broadway_device_warp (GdkDevice *device,
146 gdk_broadway_device_query_state (GdkDevice *device,
148 GdkWindow **root_window,
149 GdkWindow **child_window,
154 GdkModifierType *mask)
157 GdkBroadwayDisplay *broadway_display;
158 GdkWindowImplBroadway *impl;
162 gint device_root_x, device_root_y, device_win_x, device_win_y, id;
164 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
167 display = gdk_device_get_display (device);
168 broadway_display = GDK_BROADWAY_DISPLAY (display);
172 screen = gdk_window_get_screen (window);
173 *root_window = gdk_screen_get_root_window (screen);
177 *mask = 0; /* TODO */
179 if (broadway_display->output)
181 impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
183 serial = broadway_output_query_pointer (broadway_display->output, impl->id);
185 reply = _gdk_broadway_display_block_for_input (display, 'q', serial, TRUE);
191 guint32 reply_serial;
196 reply_serial = (guint32)strtol(p, &p, 10);
199 device_root_x = strtol(p, &p, 10);
201 device_root_y = strtol(p, &p, 10);
203 device_win_x = strtol(p, &p, 10);
205 device_win_y = strtol(p, &p, 10);
207 id = strtol(p, &p, 10);
210 *root_x = device_root_x;
212 *root_y = device_root_y;
214 *win_x = device_win_x;
216 *win_y = device_win_y;
219 if (gdk_window_get_window_type (window) == GDK_WINDOW_ROOT)
220 *child_window = g_hash_table_lookup (broadway_display->id_ht, GINT_TO_POINTER (id));
222 *child_window = window; /* No native children */
229 /* Fallback when unconnected */
231 device_root_x = broadway_display->last_x;
232 device_root_y = broadway_display->last_y;
235 *root_x = device_root_x;
237 *root_y = device_root_y;
239 *win_x = device_root_y - window->x;
241 *win_y = device_root_y - window->y;
244 if (gdk_window_get_window_type (window) == GDK_WINDOW_ROOT)
246 *child_window = broadway_display->mouse_in_toplevel;
247 if (*child_window == NULL)
248 *child_window = window;
252 /* No native children */
253 *child_window = window;
261 gdk_broadway_device_grab (GdkDevice *device,
263 gboolean owner_events,
264 GdkEventMask event_mask,
265 GdkWindow *confine_to,
270 GdkBroadwayDisplay *broadway_display;
271 GdkWindowImplBroadway *impl;
275 display = gdk_device_get_display (device);
276 broadway_display = GDK_BROADWAY_DISPLAY (display);
278 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
280 /* Device is a keyboard */
281 return GDK_GRAB_SUCCESS;
285 /* Device is a pointer */
287 if (broadway_display->output)
289 impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
291 serial = broadway_output_grab_pointer (broadway_display->output,
292 impl->id, owner_events, time_);
293 reply = _gdk_broadway_display_block_for_input (display, 'g', serial, FALSE);
298 guint32 reply_serial;
304 reply_serial = (guint32)strtol(p, &p, 10);
307 res = strtol(p, &p, 10);
313 return GDK_GRAB_NOT_VIEWABLE;
317 #define TIME_IS_LATER(time1, time2) \
318 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
319 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
323 gdk_broadway_device_ungrab (GdkDevice *device,
327 GdkBroadwayDisplay *broadway_display;
328 GdkDeviceGrabInfo *grab;
331 display = gdk_device_get_display (device);
332 broadway_display = GDK_BROADWAY_DISPLAY (display);
334 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
336 /* Device is a keyboard */
340 /* Device is a pointer */
342 if (broadway_display->output)
344 serial = broadway_output_ungrab_pointer (broadway_display->output, time_);
346 gdk_display_flush (display);
348 grab = _gdk_display_get_last_device_grab (display, device);
350 (time_ == GDK_CURRENT_TIME ||
351 grab->time == GDK_CURRENT_TIME ||
352 !TIME_IS_LATER (grab->time, time_)))
353 grab->serial_end = serial;
359 gdk_broadway_device_window_at_position (GdkDevice *device,
362 GdkModifierType *mask,
363 gboolean get_toplevel)
367 GdkWindow *root_window;
370 screen = gdk_screen_get_default ();
371 root_window = gdk_screen_get_root_window (screen);
373 res = gdk_broadway_device_query_state (device, root_window, NULL, &window, NULL, NULL, win_x, win_y, mask);
381 gdk_broadway_device_select_window_events (GdkDevice *device,
383 GdkEventMask event_mask)