| 1 |
/* GDK - The GIMP Drawing Kit |
| 2 |
* Copyright (C) 2009 Carlos Garnacho <[email protected]> |
| 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, see <http://www.gnu.org/licenses/>. |
| 16 |
*/ |
| 17 |
|
| 18 |
#include "config.h" |
| 19 |
#include <stdlib.h> |
| 20 |
|
| 21 |
#include "gdkdevice-broadway.h" |
| 22 |
|
| 23 |
#include "gdkwindow.h" |
| 24 |
#include "gdkprivate-broadway.h" |
| 25 |
|
| 26 |
static gboolean gdk_broadway_device_get_history (GdkDevice *device, |
| 27 |
GdkWindow *window, |
| 28 |
guint32 start, |
| 29 |
guint32 stop, |
| 30 |
GdkTimeCoord ***events, |
| 31 |
gint *n_events); |
| 32 |
static void gdk_broadway_device_get_state (GdkDevice *device, |
| 33 |
GdkWindow *window, |
| 34 |
gdouble *axes, |
| 35 |
GdkModifierType *mask); |
| 36 |
static void gdk_broadway_device_set_window_cursor (GdkDevice *device, |
| 37 |
GdkWindow *window, |
| 38 |
GdkCursor *cursor); |
| 39 |
static void gdk_broadway_device_warp (GdkDevice *device, |
| 40 |
GdkScreen *screen, |
| 41 |
gdouble x, |
| 42 |
gdouble y); |
| 43 |
static void gdk_broadway_device_query_state (GdkDevice *device, |
| 44 |
GdkWindow *window, |
| 45 |
GdkWindow **root_window, |
| 46 |
GdkWindow **child_window, |
| 47 |
gdouble *root_x, |
| 48 |
gdouble *root_y, |
| 49 |
gdouble *win_x, |
| 50 |
gdouble *win_y, |
| 51 |
GdkModifierType *mask); |
| 52 |
static GdkGrabStatus gdk_broadway_device_grab (GdkDevice *device, |
| 53 |
GdkWindow *window, |
| 54 |
gboolean owner_events, |
| 55 |
GdkEventMask event_mask, |
| 56 |
GdkWindow *confine_to, |
| 57 |
GdkCursor *cursor, |
| 58 |
guint32 time_); |
| 59 |
static void gdk_broadway_device_ungrab (GdkDevice *device, |
| 60 |
guint32 time_); |
| 61 |
static GdkWindow * gdk_broadway_device_window_at_position (GdkDevice *device, |
| 62 |
gdouble *win_x, |
| 63 |
gdouble *win_y, |
| 64 |
GdkModifierType *mask, |
| 65 |
gboolean get_toplevel); |
| 66 |
static void gdk_broadway_device_select_window_events (GdkDevice *device, |
| 67 |
GdkWindow *window, |
| 68 |
GdkEventMask event_mask); |
| 69 |
|
| 70 |
|
| 71 |
G_DEFINE_TYPE (GdkBroadwayDevice, gdk_broadway_device, GDK_TYPE_DEVICE) |
| 72 |
|
| 73 |
static void |
| 74 |
gdk_broadway_device_class_init (GdkBroadwayDeviceClass *klass) |
| 75 |
{ |
| 76 |
GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass); |
| 77 |
|
| 78 |
device_class->get_history = gdk_broadway_device_get_history; |
| 79 |
device_class->get_state = gdk_broadway_device_get_state; |
| 80 |
device_class->set_window_cursor = gdk_broadway_device_set_window_cursor; |
| 81 |
device_class->warp = gdk_broadway_device_warp; |
| 82 |
device_class->query_state = gdk_broadway_device_query_state; |
| 83 |
device_class->grab = gdk_broadway_device_grab; |
| 84 |
device_class->ungrab = gdk_broadway_device_ungrab; |
| 85 |
device_class->window_at_position = gdk_broadway_device_window_at_position; |
| 86 |
device_class->select_window_events = gdk_broadway_device_select_window_events; |
| 87 |
} |
| 88 |
|
| 89 |
static void |
| 90 |
gdk_broadway_device_init (GdkBroadwayDevice *device_core) |
| 91 |
{ |
| 92 |
GdkDevice *device; |
| 93 |
|
| 94 |
device = GDK_DEVICE (device_core); |
| 95 |
|
| 96 |
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1); |
| 97 |
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1); |
| 98 |
} |
| 99 |
|
| 100 |
static gboolean |
| 101 |
gdk_broadway_device_get_history (GdkDevice *device, |
| 102 |
GdkWindow *window, |
| 103 |
guint32 start, |
| 104 |
guint32 stop, |
| 105 |
GdkTimeCoord ***events, |
| 106 |
gint *n_events) |
| 107 |
{ |
| 108 |
return FALSE; |
| 109 |
} |
| 110 |
|
| 111 |
static void |
| 112 |
gdk_broadway_device_get_state (GdkDevice *device, |
| 113 |
GdkWindow *window, |
| 114 |
gdouble *axes, |
| 115 |
GdkModifierType *mask) |
| 116 |
{ |
| 117 |
gdouble x, y; |
| 118 |
|
| 119 |
gdk_window_get_device_position_double (window, device, &x, &y, mask); |
| 120 |
|
| 121 |
if (axes) |
| 122 |
{ |
| 123 |
axes[0] = x; |
| 124 |
axes[1] = y; |
| 125 |
} |
| 126 |
} |
| 127 |
|
| 128 |
static void |
| 129 |
gdk_broadway_device_set_window_cursor (GdkDevice *device, |
| 130 |
GdkWindow *window, |
| 131 |
GdkCursor *cursor) |
| 132 |
{ |
| 133 |
} |
| 134 |
|
| 135 |
static void |
| 136 |
gdk_broadway_device_warp (GdkDevice *device, |
| 137 |
GdkScreen *screen, |
| 138 |
gdouble x, |
| 139 |
gdouble y) |
| 140 |
{ |
| 141 |
} |
| 142 |
|
| 143 |
static void |
| 144 |
gdk_broadway_device_query_state (GdkDevice *device, |
| 145 |
GdkWindow *window, |
| 146 |
GdkWindow **root_window, |
| 147 |
GdkWindow **child_window, |
| 148 |
gdouble *root_x, |
| 149 |
gdouble *root_y, |
| 150 |
gdouble *win_x, |
| 151 |
gdouble *win_y, |
| 152 |
GdkModifierType *mask) |
| 153 |
{ |
| 154 |
GdkWindow *toplevel; |
| 155 |
GdkWindowImplBroadway *impl; |
| 156 |
GdkDisplay *display; |
| 157 |
GdkBroadwayDisplay *broadway_display; |
| 158 |
GdkScreen *screen; |
| 159 |
gint32 device_root_x, device_root_y; |
| 160 |
guint32 mouse_toplevel_id; |
| 161 |
GdkWindow *mouse_toplevel; |
| 162 |
guint32 mask32; |
| 163 |
|
| 164 |
if (gdk_device_get_source (device) != GDK_SOURCE_MOUSE) |
| 165 |
return; |
| 166 |
|
| 167 |
display = gdk_device_get_display (device); |
| 168 |
broadway_display = GDK_BROADWAY_DISPLAY (display); |
| 169 |
|
| 170 |
impl = GDK_WINDOW_IMPL_BROADWAY (window->impl); |
| 171 |
toplevel = impl->wrapper; |
| 172 |
|
| 173 |
if (root_window) |
| 174 |
{ |
| 175 |
screen = gdk_window_get_screen (window); |
| 176 |
*root_window = gdk_screen_get_root_window (screen); |
| 177 |
} |
| 178 |
|
| 179 |
_gdk_broadway_server_query_mouse (broadway_display->server, |
| 180 |
&mouse_toplevel_id, |
| 181 |
&device_root_x, |
| 182 |
&device_root_y, |
| 183 |
&mask32); |
| 184 |
mouse_toplevel = g_hash_table_lookup (broadway_display->id_ht, GUINT_TO_POINTER (mouse_toplevel_id)); |
| 185 |
|
| 186 |
if (root_x) |
| 187 |
*root_x = device_root_x; |
| 188 |
if (root_y) |
| 189 |
*root_y = device_root_y; |
| 190 |
if (win_x) |
| 191 |
*win_x = device_root_x - toplevel->x; |
| 192 |
if (win_y) |
| 193 |
*win_y = device_root_y - toplevel->y; |
| 194 |
if (mask) |
| 195 |
*mask = mask32; |
| 196 |
if (child_window) |
| 197 |
{ |
| 198 |
if (gdk_window_get_window_type (toplevel) == GDK_WINDOW_ROOT) |
| 199 |
{ |
| 200 |
*child_window = mouse_toplevel; |
| 201 |
if (*child_window == NULL) |
| 202 |
*child_window = toplevel; |
| 203 |
} |
| 204 |
else |
| 205 |
{ |
| 206 |
/* No native children */ |
| 207 |
*child_window = toplevel; |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
return; |
| 212 |
} |
| 213 |
|
| 214 |
void |
| 215 |
_gdk_broadway_window_grab_check_unmap (GdkWindow *window, |
| 216 |
gulong serial) |
| 217 |
{ |
| 218 |
GdkDisplay *display = gdk_window_get_display (window); |
| 219 |
GdkDeviceManager *device_manager; |
| 220 |
GList *devices, *d; |
| 221 |
|
| 222 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 223 |
device_manager = gdk_display_get_device_manager (display); |
| 224 |
|
| 225 |
/* Get all devices */ |
| 226 |
devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER); |
| 227 |
devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_SLAVE)); |
| 228 |
devices = g_list_concat (devices, gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_FLOATING)); |
| 229 |
G_GNUC_END_IGNORE_DEPRECATIONS; |
| 230 |
|
| 231 |
/* End all grabs on the newly hidden window */ |
| 232 |
for (d = devices; d; d = d->next) |
| 233 |
_gdk_display_end_device_grab (display, d->data, serial, window, TRUE); |
| 234 |
|
| 235 |
g_list_free (devices); |
| 236 |
} |
| 237 |
|
| 238 |
|
| 239 |
void |
| 240 |
_gdk_broadway_window_grab_check_destroy (GdkWindow *window) |
| 241 |
{ |
| 242 |
GdkDisplay *display = gdk_window_get_display (window); |
| 243 |
GdkDeviceManager *device_manager; |
| 244 |
GdkDeviceGrabInfo *grab; |
| 245 |
GList *devices, *d; |
| 246 |
|
| 247 |
G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 248 |
device_manager = gdk_display_get_device_manager (display); |
| 249 |
|
| 250 |
/* Get all devices */ |
| 251 |
devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER); |
| 252 |
G_GNUC_END_IGNORE_DEPRECATIONS; |
| 253 |
|
| 254 |
for (d = devices; d; d = d->next) |
| 255 |
{ |
| 256 |
/* Make sure there is no lasting grab in this native window */ |
| 257 |
grab = _gdk_display_get_last_device_grab (display, d->data); |
| 258 |
|
| 259 |
if (grab && grab->native_window == window) |
| 260 |
{ |
| 261 |
grab->serial_end = grab->serial_start; |
| 262 |
grab->implicit_ungrab = TRUE; |
| 263 |
} |
| 264 |
|
| 265 |
} |
| 266 |
|
| 267 |
g_list_free (devices); |
| 268 |
} |
| 269 |
|
| 270 |
|
| 271 |
static GdkGrabStatus |
| 272 |
gdk_broadway_device_grab (GdkDevice *device, |
| 273 |
GdkWindow *window, |
| 274 |
gboolean owner_events, |
| 275 |
GdkEventMask event_mask, |
| 276 |
GdkWindow *confine_to, |
| 277 |
GdkCursor *cursor, |
| 278 |
guint32 time_) |
| 279 |
{ |
| 280 |
GdkDisplay *display; |
| 281 |
GdkBroadwayDisplay *broadway_display; |
| 282 |
|
| 283 |
display = gdk_device_get_display (device); |
| 284 |
broadway_display = GDK_BROADWAY_DISPLAY (display); |
| 285 |
|
| 286 |
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) |
| 287 |
{ |
| 288 |
/* Device is a keyboard */ |
| 289 |
return GDK_GRAB_SUCCESS; |
| 290 |
} |
| 291 |
else |
| 292 |
{ |
| 293 |
/* Device is a pointer */ |
| 294 |
return _gdk_broadway_server_grab_pointer (broadway_display->server, |
| 295 |
GDK_WINDOW_IMPL_BROADWAY (window->impl)->id, |
| 296 |
owner_events, |
| 297 |
event_mask, |
| 298 |
time_); |
| 299 |
} |
| 300 |
} |
| 301 |
|
| 302 |
#define TIME_IS_LATER(time1, time2) \ |
| 303 |
( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \ |
| 304 |
(( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \ |
| 305 |
) |
| 306 |
|
| 307 |
static void |
| 308 |
gdk_broadway_device_ungrab (GdkDevice *device, |
| 309 |
guint32 time_) |
| 310 |
{ |
| 311 |
GdkDisplay *display; |
| 312 |
GdkBroadwayDisplay *broadway_display; |
| 313 |
GdkDeviceGrabInfo *grab; |
| 314 |
guint32 serial; |
| 315 |
|
| 316 |
display = gdk_device_get_display (device); |
| 317 |
broadway_display = GDK_BROADWAY_DISPLAY (display); |
| 318 |
|
| 319 |
if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) |
| 320 |
{ |
| 321 |
/* Device is a keyboard */ |
| 322 |
} |
| 323 |
else |
| 324 |
{ |
| 325 |
/* Device is a pointer */ |
| 326 |
serial = _gdk_broadway_server_ungrab_pointer (broadway_display->server, time_); |
| 327 |
|
| 328 |
if (serial != 0) |
| 329 |
{ |
| 330 |
grab = _gdk_display_get_last_device_grab (display, device); |
| 331 |
if (grab && |
| 332 |
(time_ == GDK_CURRENT_TIME || |
| 333 |
grab->time == GDK_CURRENT_TIME || |
| 334 |
!TIME_IS_LATER (grab->time, time_))) |
| 335 |
grab->serial_end = serial; |
| 336 |
} |
| 337 |
} |
| 338 |
} |
| 339 |
|
| 340 |
static GdkWindow * |
| 341 |
gdk_broadway_device_window_at_position (GdkDevice *device, |
| 342 |
gdouble *win_x, |
| 343 |
gdouble *win_y, |
| 344 |
GdkModifierType *mask, |
| 345 |
gboolean get_toplevel) |
| 346 |
{ |
| 347 |
GdkScreen *screen; |
| 348 |
GdkWindow *root_window; |
| 349 |
GdkWindow *window; |
| 350 |
|
| 351 |
screen = gdk_display_get_default_screen (gdk_device_get_display (device)); |
| 352 |
root_window = gdk_screen_get_root_window (screen); |
| 353 |
|
| 354 |
gdk_broadway_device_query_state (device, root_window, NULL, &window, NULL, NULL, win_x, win_y, mask); |
| 355 |
|
| 356 |
return window; |
| 357 |
} |
| 358 |
|
| 359 |
static void |
| 360 |
gdk_broadway_device_select_window_events (GdkDevice *device, |
| 361 |
GdkWindow *window, |
| 362 |
GdkEventMask event_mask) |
| 363 |
{ |
| 364 |
} |