]> Pileus Git - ~andy/gtk/blob - gdk/broadway/gdkdevice-broadway.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gdk / broadway / gdkdevice-broadway.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
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                                       gint       x,
42                                       gint       y);
43 static void gdk_broadway_device_query_state (GdkDevice        *device,
44                                              GdkWindow        *window,
45                                              GdkWindow       **root_window,
46                                              GdkWindow       **child_window,
47                                              gint             *root_x,
48                                              gint             *root_y,
49                                              gint             *win_x,
50                                              gint             *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                                                            gint            *win_x,
63                                                            gint            *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   gint x_int, y_int;
118
119   gdk_window_get_pointer (window, &x_int, &y_int, mask);
120
121   if (axes)
122     {
123       axes[0] = x_int;
124       axes[1] = y_int;
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                           gint       x,
139                           gint       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                                  gint             *root_x,
149                                  gint             *root_y,
150                                  gint             *win_x,
151                                  gint             *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_y - 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_destroy (GdkWindow *window)
216 {
217   GdkDisplay *display = gdk_window_get_display (window);
218   GdkDeviceManager *device_manager;
219   GdkDeviceGrabInfo *grab;
220   GList *devices, *d;
221
222   device_manager = gdk_display_get_device_manager (display);
223
224   /* Get all devices */
225   devices = gdk_device_manager_list_devices (device_manager, GDK_DEVICE_TYPE_MASTER);
226
227   for (d = devices; d; d = d->next)
228     {
229       /* Make sure there is no lasting grab in this native window */
230       grab = _gdk_display_get_last_device_grab (display, d->data);
231
232       if (grab && grab->native_window == window)
233         {
234           grab->serial_end = grab->serial_start;
235           grab->implicit_ungrab = TRUE;
236         }
237
238     }
239
240   g_list_free (devices);
241 }
242
243
244 static GdkGrabStatus
245 gdk_broadway_device_grab (GdkDevice    *device,
246                           GdkWindow    *window,
247                           gboolean      owner_events,
248                           GdkEventMask  event_mask,
249                           GdkWindow    *confine_to,
250                           GdkCursor    *cursor,
251                           guint32       time_)
252 {
253   GdkDisplay *display;
254   GdkBroadwayDisplay *broadway_display;
255
256   display = gdk_device_get_display (device);
257   broadway_display = GDK_BROADWAY_DISPLAY (display);
258
259   if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
260     {
261       /* Device is a keyboard */
262       return GDK_GRAB_SUCCESS;
263     }
264   else
265     {
266       /* Device is a pointer */
267       return _gdk_broadway_server_grab_pointer (broadway_display->server,
268                                                 GDK_WINDOW_IMPL_BROADWAY (window->impl)->id,
269                                                 owner_events,
270                                                 event_mask,
271                                                 time_);
272     }
273 }
274
275 #define TIME_IS_LATER(time1, time2)                        \
276   ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) ||  \
277     (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 ))     \
278   )
279
280 static void
281 gdk_broadway_device_ungrab (GdkDevice *device,
282                             guint32    time_)
283 {
284   GdkDisplay *display;
285   GdkBroadwayDisplay *broadway_display;
286   GdkDeviceGrabInfo *grab;
287   guint32 serial;
288
289   display = gdk_device_get_display (device);
290   broadway_display = GDK_BROADWAY_DISPLAY (display);
291
292   if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
293     {
294       /* Device is a keyboard */
295     }
296   else
297     {
298       /* Device is a pointer */
299       serial = _gdk_broadway_server_ungrab_pointer (broadway_display->server, time_);
300
301       if (serial != 0)
302         {
303           grab = _gdk_display_get_last_device_grab (display, device);
304           if (grab &&
305               (time_ == GDK_CURRENT_TIME ||
306                grab->time == GDK_CURRENT_TIME ||
307                !TIME_IS_LATER (grab->time, time_)))
308             grab->serial_end = serial;
309         }
310     }
311 }
312
313 static GdkWindow *
314 gdk_broadway_device_window_at_position (GdkDevice       *device,
315                                         gint            *win_x,
316                                         gint            *win_y,
317                                         GdkModifierType *mask,
318                                         gboolean         get_toplevel)
319 {
320   GdkScreen *screen;
321   GdkWindow *root_window;
322   GdkWindow *window;
323
324   screen = gdk_screen_get_default ();
325   root_window = gdk_screen_get_root_window (screen);
326
327   gdk_broadway_device_query_state (device, root_window, NULL, &window, NULL, NULL, win_x, win_y, mask);
328
329   return window;
330 }
331
332 static void
333 gdk_broadway_device_select_window_events (GdkDevice    *device,
334                                           GdkWindow    *window,
335                                           GdkEventMask  event_mask)
336 {
337 }