]> Pileus Git - ~andy/gtk/blob - gdk/wayland/gdkdevice-wayland.c
wayland: Support setting cursors
[~andy/gtk] / gdk / wayland / gdkdevice-wayland.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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <gdk/gdkwindow.h>
23 #include "gdkdevice-wayland.h"
24 #include "gdkprivate-wayland.h"
25 #include "gdkwayland.h"
26
27 static gboolean gdk_device_core_get_history (GdkDevice      *device,
28                                              GdkWindow      *window,
29                                              guint32         start,
30                                              guint32         stop,
31                                              GdkTimeCoord ***events,
32                                              gint           *n_events);
33 static void gdk_device_core_get_state (GdkDevice       *device,
34                                        GdkWindow       *window,
35                                        gdouble         *axes,
36                                        GdkModifierType *mask);
37 static void gdk_device_core_set_window_cursor (GdkDevice *device,
38                                                GdkWindow *window,
39                                                GdkCursor *cursor);
40 static void gdk_device_core_warp (GdkDevice *device,
41                                   GdkScreen *screen,
42                                   gint       x,
43                                   gint       y);
44 static gboolean gdk_device_core_query_state (GdkDevice        *device,
45                                              GdkWindow        *window,
46                                              GdkWindow       **root_window,
47                                              GdkWindow       **child_window,
48                                              gint             *root_x,
49                                              gint             *root_y,
50                                              gint             *win_x,
51                                              gint             *win_y,
52                                              GdkModifierType  *mask);
53 static GdkGrabStatus gdk_device_core_grab   (GdkDevice     *device,
54                                              GdkWindow     *window,
55                                              gboolean       owner_events,
56                                              GdkEventMask   event_mask,
57                                              GdkWindow     *confine_to,
58                                              GdkCursor     *cursor,
59                                              guint32        time_);
60 static void          gdk_device_core_ungrab (GdkDevice     *device,
61                                              guint32        time_);
62 static GdkWindow * gdk_device_core_window_at_position (GdkDevice       *device,
63                                                        gint            *win_x,
64                                                        gint            *win_y,
65                                                        GdkModifierType *mask,
66                                                        gboolean         get_toplevel);
67 static void      gdk_device_core_select_window_events (GdkDevice       *device,
68                                                        GdkWindow       *window,
69                                                        GdkEventMask     event_mask);
70
71
72 G_DEFINE_TYPE (GdkDeviceCore, gdk_device_core, GDK_TYPE_DEVICE)
73
74 static void
75 gdk_device_core_class_init (GdkDeviceCoreClass *klass)
76 {
77   GdkDeviceClass *device_class = GDK_DEVICE_CLASS (klass);
78
79   device_class->get_history = gdk_device_core_get_history;
80   device_class->get_state = gdk_device_core_get_state;
81   device_class->set_window_cursor = gdk_device_core_set_window_cursor;
82   device_class->warp = gdk_device_core_warp;
83   device_class->query_state = gdk_device_core_query_state;
84   device_class->grab = gdk_device_core_grab;
85   device_class->ungrab = gdk_device_core_ungrab;
86   device_class->window_at_position = gdk_device_core_window_at_position;
87   device_class->select_window_events = gdk_device_core_select_window_events;
88 }
89
90 static void
91 gdk_device_core_init (GdkDeviceCore *device_core)
92 {
93   GdkDevice *device;
94
95   device = GDK_DEVICE (device_core);
96
97   _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_X, 0, 0, 1);
98   _gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_Y, 0, 0, 1);
99 }
100
101 static gboolean
102 gdk_device_core_get_history (GdkDevice      *device,
103                              GdkWindow      *window,
104                              guint32         start,
105                              guint32         stop,
106                              GdkTimeCoord ***events,
107                              gint           *n_events)
108 {
109   return FALSE;
110 }
111
112 static void
113 gdk_device_core_get_state (GdkDevice       *device,
114                            GdkWindow       *window,
115                            gdouble         *axes,
116                            GdkModifierType *mask)
117 {
118   gint x_int, y_int;
119
120   gdk_window_get_pointer (window, &x_int, &y_int, mask);
121
122   if (axes)
123     {
124       axes[0] = x_int;
125       axes[1] = y_int;
126     }
127 }
128
129 static void
130 gdk_device_core_set_window_cursor (GdkDevice *device,
131                                    GdkWindow *window,
132                                    GdkCursor *cursor)
133 {
134   GdkWaylandDevice *wd = GDK_DEVICE_CORE(device)->device;
135   struct wl_buffer *buffer;
136   int x, y;
137
138   if (cursor)
139     {
140       buffer = _gdk_wayland_cursor_get_buffer(cursor, &x, &y);
141       wl_input_device_attach(wd->device, wd->time, buffer, x, y);
142     }
143   else
144     {
145       wl_input_device_attach(wd->device, wd->time, NULL, 0, 0);
146     }
147 }
148
149 static void
150 gdk_device_core_warp (GdkDevice *device,
151                       GdkScreen *screen,
152                       gint       x,
153                       gint       y)
154 {
155 }
156
157 static gboolean
158 gdk_device_core_query_state (GdkDevice        *device,
159                              GdkWindow        *window,
160                              GdkWindow       **root_window,
161                              GdkWindow       **child_window,
162                              gint             *root_x,
163                              gint             *root_y,
164                              gint             *win_x,
165                              gint             *win_y,
166                              GdkModifierType  *mask)
167 {
168   GdkWaylandDevice *wd;
169   GdkScreen *default_screen;
170
171   wd = GDK_DEVICE_CORE(device)->device;
172   default_screen = gdk_display_get_default_screen (wd->display);
173
174   if (root_window)
175     *root_window = gdk_screen_get_root_window (default_screen);
176   if (child_window)
177     *child_window = wd->pointer_focus;
178   if (root_x)
179     *root_x = wd->x;
180   if (root_y)
181     *root_y = wd->y;
182   if (win_x)
183     *win_x = wd->surface_x;
184   if (win_y)
185     *win_y = wd->surface_y;
186   if (mask)
187     *mask = wd->modifiers;
188
189   return TRUE;
190 }
191
192 static GdkGrabStatus
193 gdk_device_core_grab (GdkDevice    *device,
194                       GdkWindow    *window,
195                       gboolean      owner_events,
196                       GdkEventMask  event_mask,
197                       GdkWindow    *confine_to,
198                       GdkCursor    *cursor,
199                       guint32       time_)
200 {
201   return GDK_GRAB_SUCCESS;
202 }
203
204 static void
205 gdk_device_core_ungrab (GdkDevice *device,
206                         guint32    time_)
207 {
208 }
209
210 static GdkWindow *
211 gdk_device_core_window_at_position (GdkDevice       *device,
212                                     gint            *win_x,
213                                     gint            *win_y,
214                                     GdkModifierType *mask,
215                                     gboolean         get_toplevel)
216 {
217   GdkWaylandDevice *wd;
218
219   wd = GDK_DEVICE_CORE(device)->device;
220
221   return wd->pointer_focus;
222 }
223
224 static void
225 gdk_device_core_select_window_events (GdkDevice    *device,
226                                       GdkWindow    *window,
227                                       GdkEventMask  event_mask)
228 {
229 }