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 GdkWindowImplBroadway *impl;
159 GdkBroadwayDisplay *broadway_display;
161 gint device_root_x, device_root_y;
163 if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE)
166 display = gdk_device_get_display (device);
167 broadway_display = GDK_BROADWAY_DISPLAY (display);
169 impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
170 toplevel = impl->wrapper;
174 screen = gdk_window_get_screen (window);
175 *root_window = gdk_screen_get_root_window (screen);
178 if (broadway_display->output)
180 _gdk_broadway_display_consume_all_input (display);
182 *root_x = broadway_display->future_root_x;
184 *root_y = broadway_display->future_root_y;
185 /* TODO: Should really use future_x/y when we get configure events */
187 *win_x = broadway_display->future_root_x - toplevel->x;
189 *win_y = broadway_display->future_root_y - toplevel->y;
191 *mask = broadway_display->future_state;
194 if (gdk_window_get_window_type (toplevel) == GDK_WINDOW_ROOT)
196 g_hash_table_lookup (broadway_display->id_ht,
197 GINT_TO_POINTER (broadway_display->future_mouse_in_toplevel));
199 *child_window = toplevel; /* No native children */
204 /* Fallback when unconnected */
206 device_root_x = broadway_display->last_x;
207 device_root_y = broadway_display->last_y;
210 *root_x = device_root_x;
212 *root_y = device_root_y;
214 *win_x = device_root_y - toplevel->x;
216 *win_y = device_root_y - toplevel->y;
218 *mask = broadway_display->last_state;
221 if (gdk_window_get_window_type (toplevel) == GDK_WINDOW_ROOT)
223 *child_window = broadway_display->mouse_in_toplevel;
224 if (*child_window == NULL)
225 *child_window = toplevel;
229 /* No native children */
230 *child_window = toplevel;
238 gdk_broadway_device_grab (GdkDevice *device,
240 gboolean owner_events,
241 GdkEventMask event_mask,
242 GdkWindow *confine_to,
247 GdkBroadwayDisplay *broadway_display;
249 display = gdk_device_get_display (device);
250 broadway_display = GDK_BROADWAY_DISPLAY (display);
252 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
254 /* Device is a keyboard */
255 return GDK_GRAB_SUCCESS;
259 /* Device is a pointer */
261 if (broadway_display->pointer_grab_window != NULL &&
262 time_ != 0 && broadway_display->pointer_grab_time > time_)
263 return GDK_GRAB_ALREADY_GRABBED;
266 time_ = broadway_display->last_seen_time;
268 broadway_display->pointer_grab_window = window;
269 broadway_display->pointer_grab_owner_events = owner_events;
270 broadway_display->pointer_grab_time = time_;
272 if (broadway_display->output)
274 broadway_output_grab_pointer (broadway_display->output,
275 GDK_WINDOW_IMPL_BROADWAY (window->impl)->id,
277 gdk_display_flush (display);
280 /* TODO: What about toplevel grab events if we're not connected? */
282 return GDK_GRAB_SUCCESS;
286 #define TIME_IS_LATER(time1, time2) \
287 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
288 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
292 gdk_broadway_device_ungrab (GdkDevice *device,
296 GdkBroadwayDisplay *broadway_display;
297 GdkDeviceGrabInfo *grab;
300 display = gdk_device_get_display (device);
301 broadway_display = GDK_BROADWAY_DISPLAY (display);
303 if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
305 /* Device is a keyboard */
309 /* Device is a pointer */
311 if (broadway_display->pointer_grab_window != NULL &&
312 time_ != 0 && broadway_display->pointer_grab_time > time_)
315 /* TODO: What about toplevel grab events if we're not connected? */
317 if (broadway_display->output)
319 serial = broadway_output_ungrab_pointer (broadway_display->output);
320 gdk_display_flush (display);
324 serial = broadway_display->saved_serial;
327 grab = _gdk_display_get_last_device_grab (display, device);
329 (time_ == GDK_CURRENT_TIME ||
330 grab->time == GDK_CURRENT_TIME ||
331 !TIME_IS_LATER (grab->time, time_)))
332 grab->serial_end = serial;
334 broadway_display->pointer_grab_window = NULL;
339 gdk_broadway_device_window_at_position (GdkDevice *device,
342 GdkModifierType *mask,
343 gboolean get_toplevel)
347 GdkWindow *root_window;
350 screen = gdk_screen_get_default ();
351 root_window = gdk_screen_get_root_window (screen);
353 res = gdk_broadway_device_query_state (device, root_window, NULL, &window, NULL, NULL, win_x, win_y, mask);
361 gdk_broadway_device_select_window_events (GdkDevice *device,
363 GdkEventMask event_mask)