blob: 31c294f814e4a8ee7483a276a064d99954292c1c [file] [log] [blame]
Kristian Høgsbergffd710e2008-12-02 15:15:01 -05001/*
2 * Copyright © 2008 Kristian Høgsberg
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
13 *
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20 * OF THIS SOFTWARE.
21 */
22
Kristian Høgsberg61017b12008-11-02 18:51:48 -050023#include <stdint.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
Kristian Høgsberg61017b12008-11-02 18:51:48 -050027#include <fcntl.h>
28#include <unistd.h>
29#include <math.h>
30#include <time.h>
31#include <cairo.h>
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050032#include <glib.h>
Kristian Høgsberg478d9262010-06-08 20:34:11 -040033#include <glib-object.h>
Kristian Høgsbergda275dd2010-08-16 17:47:07 -040034#include <gdk-pixbuf/gdk-pixbuf.h>
Kristian Høgsberg640609a2010-08-09 22:11:47 -040035#include <xf86drm.h>
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -040036
37#define EGL_EGLEXT_PROTOTYPES 1
38#define GL_GLEXT_PROTOTYPES 1
39#include <GL/gl.h>
40#include <EGL/egl.h>
41#include <EGL/eglext.h>
42#include <cairo-gl.h>
Kristian Høgsberg61017b12008-11-02 18:51:48 -050043
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -040044#include <X11/extensions/XKBcommon.h>
45
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -050046#include <linux/input.h>
Kristian Høgsberg3c38fa02009-02-23 22:30:29 -050047#include "wayland-util.h"
Kristian Høgsberg61017b12008-11-02 18:51:48 -050048#include "wayland-client.h"
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050049#include "wayland-glib.h"
Kristian Høgsbergb91cd102010-08-16 16:17:42 -040050#include "cairo-util.h"
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050051
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050052#include "window.h"
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050053
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050054struct display {
Kristian Høgsberg40979232008-11-25 22:40:39 -050055 struct wl_display *display;
Kristian Høgsbergd2412e22008-12-15 20:35:24 -050056 struct wl_compositor *compositor;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -040057 struct wl_shell *shell;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -040058 struct wl_drm *drm;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050059 struct wl_output *output;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050060 struct rectangle screen_allocation;
Kristian Høgsberg640609a2010-08-09 22:11:47 -040061 int authenticated;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -040062 EGLDisplay dpy;
63 EGLContext ctx;
Janusz Lewandowskid923e9d2010-01-31 03:01:26 +010064 cairo_device_t *device;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050065 int fd;
Kristian Høgsberg7824d812010-06-08 14:59:44 -040066 GMainLoop *loop;
67 GSource *source;
Kristian Høgsberg478d9262010-06-08 20:34:11 -040068 struct wl_list window_list;
Kristian Høgsberg808fd412010-07-20 17:06:19 -040069 struct wl_list input_list;
Kristian Høgsberg478d9262010-06-08 20:34:11 -040070 char *device_name;
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -040071 cairo_surface_t *active_frame, *inactive_frame, *shadow;
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -040072 struct xkb_desc *xkb;
Kristian Høgsberg9a686242010-08-18 15:28:04 -040073 cairo_surface_t **pointer_surfaces;
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -040074
75 display_drag_offer_handler_t drag_offer_handler;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -050076};
77
78struct window {
79 struct display *display;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050080 struct wl_surface *surface;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050081 const char *title;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -040082 struct rectangle allocation, saved_allocation, pending_allocation;
83 int resize_edges;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -040084 int redraw_scheduled;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050085 int minimum_width, minimum_height;
Kristian Høgsberg40979232008-11-25 22:40:39 -050086 int margin;
Kristian Høgsberg0395f302008-12-22 12:14:50 -050087 int fullscreen;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -040088 int decoration;
Kristian Høgsberg808fd412010-07-20 17:06:19 -040089 struct input *grab_device;
90 struct input *keyboard_device;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050091 uint32_t name;
Kristian Høgsberg78231c82008-11-08 15:06:01 -050092
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -040093 EGLImageKHR *image;
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -050094 cairo_surface_t *cairo_surface, *pending_surface;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050095
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050096 window_resize_handler_t resize_handler;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -040097 window_redraw_handler_t redraw_handler;
Kristian Høgsberg6e83d582008-12-08 00:01:36 -050098 window_key_handler_t key_handler;
Kristian Høgsberg9a686242010-08-18 15:28:04 -040099 window_button_handler_t button_handler;
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500100 window_keyboard_focus_handler_t keyboard_focus_handler;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400101 window_motion_handler_t motion_handler;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400102
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500103 void *user_data;
Kristian Høgsberg478d9262010-06-08 20:34:11 -0400104 struct wl_list link;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500105};
106
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400107struct input {
108 struct display *display;
109 struct wl_input_device *input_device;
110 struct window *pointer_focus;
111 struct window *keyboard_focus;
Kristian Høgsberg7d804062010-09-07 21:50:06 -0400112 uint32_t current_pointer_image;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400113 uint32_t modifiers;
114 int32_t x, y, sx, sy;
115 struct wl_list link;
116};
117
Kristian Høgsberg7d804062010-09-07 21:50:06 -0400118enum {
119 POINTER_DEFAULT = 100,
120 POINTER_UNSET
121};
122
Kristian Høgsbergc7c60642010-08-29 21:33:39 -0400123const char *option_xkb_layout = "us";
124const char *option_xkb_variant = "";
125const char *option_xkb_options = "";
126
127static const GOptionEntry xkb_option_entries[] = {
128 { "xkb-layout", 0, 0, G_OPTION_ARG_STRING,
129 &option_xkb_layout, "XKB Layout" },
130 { "xkb-variant", 0, 0, G_OPTION_ARG_STRING,
131 &option_xkb_variant, "XKB Variant" },
132 { "xkb-options", 0, 0, G_OPTION_ARG_STRING,
133 &option_xkb_options, "XKB Options" },
134 { NULL }
135};
136
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500137static void
138rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius)
139{
140 cairo_move_to(cr, x0, y0 + radius);
141 cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
142 cairo_line_to(cr, x1 - radius, y0);
143 cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
144 cairo_line_to(cr, x1, y1 - radius);
145 cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
146 cairo_line_to(cr, x0 + radius, y1);
147 cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
148 cairo_close_path(cr);
149}
150
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400151static int
152texture_from_png(const char *filename, int width, int height)
153{
154 GdkPixbuf *pixbuf;
155 GError *error = NULL;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400156 int stride, i;
157 unsigned char *pixels, *p, *end;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400158
159 pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
160 width, height,
161 FALSE, &error);
162 if (error != NULL)
163 return -1;
164
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400165 if (!gdk_pixbuf_get_has_alpha(pixbuf) ||
166 gdk_pixbuf_get_n_channels(pixbuf) != 4) {
167 gdk_pixbuf_unref(pixbuf);
168 return -1;
169 }
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400170
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400171
172 stride = gdk_pixbuf_get_rowstride(pixbuf);
173 pixels = gdk_pixbuf_get_pixels(pixbuf);
174
175 for (i = 0; i < height; i++) {
176 p = pixels + i * stride;
177 end = p + width * 4;
178 while (p < end) {
179 unsigned int t;
180
181#define MULT(d,c,a,t) \
182 do { t = c * a + 0x7f; d = ((t >> 8) + t) >> 8; } while (0)
183
184 MULT(p[0], p[0], p[3], t);
185 MULT(p[1], p[1], p[3], t);
186 MULT(p[2], p[2], p[3], t);
187 p += 4;
188
189 }
190 }
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400191
192 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400193 width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400194
195 gdk_pixbuf_unref(pixbuf);
196
197 return 0;
198}
199
200static const struct {
201 const char *filename;
202 int hotspot_x, hotspot_y;
203} pointer_images[] = {
204 { DATADIR "/wayland/bottom_left_corner.png", 6, 30 },
205 { DATADIR "/wayland/bottom_right_corner.png", 28, 28 },
206 { DATADIR "/wayland/bottom_side.png", 16, 20 },
207 { DATADIR "/wayland/grabbing.png", 20, 17 },
208 { DATADIR "/wayland/left_ptr.png", 10, 5 },
209 { DATADIR "/wayland/left_side.png", 10, 20 },
210 { DATADIR "/wayland/right_side.png", 30, 19 },
211 { DATADIR "/wayland/top_left_corner.png", 8, 8 },
212 { DATADIR "/wayland/top_right_corner.png", 26, 8 },
213 { DATADIR "/wayland/top_side.png", 18, 8 },
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400214 { DATADIR "/wayland/xterm.png", 15, 15 },
215 { DATADIR "/wayland/hand1.png", 18, 11 }
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400216};
217
218static void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400219create_pointer_surfaces(struct display *display)
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400220{
221 int i, count;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400222 const int width = 32, height = 32;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400223 struct rectangle rect;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400224
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400225 count = ARRAY_LENGTH(pointer_images);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400226 display->pointer_surfaces =
227 malloc(count * sizeof *display->pointer_surfaces);
228 rect.width = width;
229 rect.height = height;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400230 for (i = 0; i < count; i++) {
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400231 display->pointer_surfaces[i] =
232 display_create_surface(display, &rect);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400233 texture_from_png(pointer_images[i].filename, width, height);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400234 }
235
236}
237
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400238static const cairo_user_data_key_t surface_data_key;
239struct surface_data {
240 EGLImageKHR image;
241 GLuint texture;
242 EGLDisplay dpy;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400243 struct wl_buffer *buffer;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400244};
245
246static void
247surface_data_destroy(void *p)
248{
249 struct surface_data *data = p;
250
251 glDeleteTextures(1, &data->texture);
252 eglDestroyImageKHR(data->dpy, data->image);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400253 if (data->buffer)
254 wl_buffer_destroy(data->buffer);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400255}
256
257cairo_surface_t *
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400258display_create_surface(struct display *display,
259 struct rectangle *rectangle)
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400260{
261 struct surface_data *data;
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400262 EGLDisplay dpy = display->dpy;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400263 cairo_surface_t *surface;
264
265 EGLint image_attribs[] = {
266 EGL_WIDTH, 0,
267 EGL_HEIGHT, 0,
Kristian Høgsbergb12fcce2010-08-24 17:34:23 -0400268 EGL_DRM_BUFFER_FORMAT_MESA, EGL_DRM_BUFFER_FORMAT_ARGB32_MESA,
269 EGL_DRM_BUFFER_USE_MESA, EGL_DRM_BUFFER_USE_SCANOUT_MESA,
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400270 EGL_NONE
271 };
272
273 data = malloc(sizeof *data);
274 image_attribs[1] = rectangle->width;
275 image_attribs[3] = rectangle->height;
276 data->image = eglCreateDRMImageMESA(dpy, image_attribs);
277 glGenTextures(1, &data->texture);
278 data->dpy = dpy;
279 glBindTexture(GL_TEXTURE_2D, data->texture);
280 glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, data->image);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400281 data->buffer = NULL;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400282
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400283 surface = cairo_gl_surface_create_for_texture(display->device,
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400284 CAIRO_CONTENT_COLOR_ALPHA,
285 data->texture,
286 rectangle->width,
287 rectangle->height);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400288
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400289 cairo_surface_set_user_data (surface, &surface_data_key,
290 data, surface_data_destroy);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400291
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400292 return surface;
293}
294
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400295struct wl_buffer *
296display_get_buffer_for_surface(struct display *display,
297 cairo_surface_t *surface)
298{
299 struct surface_data *data;
300 struct wl_visual *visual;
301 struct wl_buffer *buffer;
302 EGLint name, stride;
303 int width, height;
304
305 data = cairo_surface_get_user_data (surface, &surface_data_key);
306 if (data->buffer)
307 return data->buffer;
308
309 width = cairo_gl_surface_get_width (surface);
310 height = cairo_gl_surface_get_height (surface);
311
312 eglExportDRMImageMESA(display->dpy, data->image, &name, NULL, &stride);
313
314 visual = wl_display_get_premultiplied_argb_visual(display->display);
315 buffer = wl_drm_create_buffer(display->drm,
316 name, width, height, stride, visual);
317 data->buffer = buffer;
318
319 return buffer;
320}
321
322cairo_surface_t *
323display_get_pointer_surface(struct display *display, int pointer,
324 int *width, int *height,
325 int *hotspot_x, int *hotspot_y)
326{
327 cairo_surface_t *surface;
328
329 surface = display->pointer_surfaces[pointer];
330 *width = cairo_gl_surface_get_width(surface);
331 *height = cairo_gl_surface_get_height(surface);
332 *hotspot_x = pointer_images[pointer].hotspot_x;
333 *hotspot_y = pointer_images[pointer].hotspot_y;
334
335 return cairo_surface_reference(surface);
336}
337
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400338
339static void
340window_attach_surface(struct window *window);
341
342static void
343free_surface(void *data)
344{
345 struct window *window = data;
346
347 cairo_surface_destroy(window->pending_surface);
348 window->pending_surface = NULL;
349 if (window->cairo_surface)
350 window_attach_surface(window);
351}
352
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500353static void
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500354window_attach_surface(struct window *window)
355{
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400356 struct display *display = window->display;
357 struct wl_buffer *buffer;
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500358
Kristian Høgsberg2aac3022009-12-21 10:04:53 -0500359 if (window->pending_surface != NULL)
360 return;
361
Kristian Høgsberg09531622010-06-14 23:22:15 -0400362 window->pending_surface = window->cairo_surface;
363 window->cairo_surface = NULL;
Kristian Høgsberg2aac3022009-12-21 10:04:53 -0500364
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400365 buffer = display_get_buffer_for_surface(display,
366 window->pending_surface);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -0400367 wl_surface_attach(window->surface, buffer);
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500368
369 wl_surface_map(window->surface,
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400370 window->allocation.x,
371 window->allocation.y,
372 window->allocation.width,
373 window->allocation.height);
Kristian Høgsberg09531622010-06-14 23:22:15 -0400374
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400375 wl_display_sync_callback(display->display, free_surface, window);
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500376}
377
Kristian Høgsberga341fa02010-01-24 18:10:15 -0500378void
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400379window_flush(struct window *window)
Kristian Høgsberga341fa02010-01-24 18:10:15 -0500380{
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -0400381 if (window->cairo_surface)
382 window_attach_surface(window);
Kristian Høgsberga341fa02010-01-24 18:10:15 -0500383}
384
Kristian Høgsberg6a1b2012009-12-16 14:43:37 -0500385static void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500386window_draw_decorations(struct window *window)
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500387{
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500388 cairo_t *cr;
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -0500389 cairo_text_extents_t extents;
Kristian Høgsberg2d6b7c12010-06-25 16:51:57 -0400390 cairo_pattern_t *outline, *bright, *dim;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400391 cairo_surface_t *frame;
392 int width, height, shadow_dx = 3, shadow_dy = 3;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500393
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500394 window->cairo_surface =
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400395 display_create_surface(window->display, &window->allocation);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400396 width = window->allocation.width;
397 height = window->allocation.height;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500398
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500399 outline = cairo_pattern_create_rgb(0.1, 0.1, 0.1);
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500400 bright = cairo_pattern_create_rgb(0.8, 0.8, 0.8);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500401 dim = cairo_pattern_create_rgb(0.4, 0.4, 0.4);
402
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500403 cr = cairo_create(window->cairo_surface);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500404
Kristian Høgsberg09531622010-06-14 23:22:15 -0400405 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400406 cairo_set_source_rgba(cr, 0, 0, 0, 0);
Kristian Høgsberg09531622010-06-14 23:22:15 -0400407 cairo_paint(cr);
408
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400409 cairo_set_source_rgba(cr, 0, 0, 0, 0.6);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400410 tile_mask(cr, window->display->shadow,
411 shadow_dx, shadow_dy, width, height,
412 window->margin + 10 - shadow_dx,
413 window->margin + 10 - shadow_dy);
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500414
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400415 if (window->keyboard_device)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400416 frame = window->display->active_frame;
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400417 else
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400418 frame = window->display->inactive_frame;
419
420 tile_source(cr, frame, 0, 0, width, height,
421 window->margin + 10, window->margin + 50);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500422
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500423 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
424 cairo_set_font_size(cr, 14);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500425 cairo_text_extents(cr, window->title, &extents);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400426 cairo_move_to(cr, (width - extents.width) / 2, 32 - extents.y_bearing);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500427 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
428 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
429 cairo_set_line_width (cr, 4);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400430 if (window->keyboard_device)
431 cairo_set_source_rgb(cr, 0, 0, 0);
432 else
Kristian Høgsberg7d7b5db2009-09-21 13:43:46 -0400433 cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400434 cairo_show_text(cr, window->title);
435
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500436 cairo_destroy(cr);
Kristian Høgsberg10ddbd22010-08-16 21:08:52 -0400437
438 cairo_device_flush (window->display->device);
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500439}
440
Kristian Høgsberge968f9c2010-08-27 22:18:00 -0400441void
442display_flush_cairo_device(struct display *display)
443{
444 cairo_device_flush (display->device);
445}
446
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500447static void
448window_draw_fullscreen(struct window *window)
449{
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500450 window->cairo_surface =
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -0400451 display_create_surface(window->display, &window->allocation);
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500452}
453
454void
455window_draw(struct window *window)
456{
Kristian Høgsberg2aac3022009-12-21 10:04:53 -0500457 if (window->cairo_surface != NULL)
458 cairo_surface_destroy(window->cairo_surface);
459
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400460 if (window->fullscreen || !window->decoration)
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500461 window_draw_fullscreen(window);
462 else
463 window_draw_decorations(window);
Kristian Høgsberg44f36e32008-11-26 12:57:31 -0500464}
465
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400466cairo_surface_t *
467window_get_surface(struct window *window)
468{
469 return window->cairo_surface;
470}
471
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400472enum window_location {
473 WINDOW_INTERIOR = 0,
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400474 WINDOW_RESIZING_TOP = 1,
475 WINDOW_RESIZING_BOTTOM = 2,
476 WINDOW_RESIZING_LEFT = 4,
477 WINDOW_RESIZING_TOP_LEFT = 5,
478 WINDOW_RESIZING_BOTTOM_LEFT = 6,
479 WINDOW_RESIZING_RIGHT = 8,
480 WINDOW_RESIZING_TOP_RIGHT = 9,
481 WINDOW_RESIZING_BOTTOM_RIGHT = 10,
482 WINDOW_RESIZING_MASK = 15,
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400483 WINDOW_EXTERIOR = 16,
484 WINDOW_TITLEBAR = 17,
485 WINDOW_CLIENT_AREA = 18,
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400486};
487
488static int
489get_pointer_location(struct window *window, int32_t x, int32_t y)
490{
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400491 int vlocation, hlocation, location;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400492 const int grip_size = 8;
493
494 if (x < window->margin)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400495 hlocation = WINDOW_EXTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400496 else if (window->margin <= x && x < window->margin + grip_size)
497 hlocation = WINDOW_RESIZING_LEFT;
498 else if (x < window->allocation.width - window->margin - grip_size)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400499 hlocation = WINDOW_INTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400500 else if (x < window->allocation.width - window->margin)
501 hlocation = WINDOW_RESIZING_RIGHT;
502 else
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400503 hlocation = WINDOW_EXTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400504
505 if (y < window->margin)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400506 vlocation = WINDOW_EXTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400507 else if (window->margin <= y && y < window->margin + grip_size)
508 vlocation = WINDOW_RESIZING_TOP;
509 else if (y < window->allocation.height - window->margin - grip_size)
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400510 vlocation = WINDOW_INTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400511 else if (y < window->allocation.height - window->margin)
512 vlocation = WINDOW_RESIZING_BOTTOM;
513 else
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400514 vlocation = WINDOW_EXTERIOR;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400515
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400516 location = vlocation | hlocation;
517 if (location & WINDOW_EXTERIOR)
518 location = WINDOW_EXTERIOR;
519 if (location == WINDOW_INTERIOR && y < window->margin + 50)
520 location = WINDOW_TITLEBAR;
521 else if (location == WINDOW_INTERIOR)
522 location = WINDOW_CLIENT_AREA;
523
524 return location;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400525}
526
527static void
Kristian Høgsbergce457ba2010-09-14 15:39:45 -0400528set_pointer_image(struct input *input, uint32_t time, int pointer)
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400529{
530 struct display *display = input->display;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400531 struct wl_buffer *buffer;
532 cairo_surface_t *surface;
533 int location;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400534
535 location = get_pointer_location(input->pointer_focus,
536 input->sx, input->sy);
537 switch (location) {
538 case WINDOW_RESIZING_TOP:
539 pointer = POINTER_TOP;
540 break;
541 case WINDOW_RESIZING_BOTTOM:
542 pointer = POINTER_BOTTOM;
543 break;
544 case WINDOW_RESIZING_LEFT:
545 pointer = POINTER_LEFT;
546 break;
547 case WINDOW_RESIZING_RIGHT:
548 pointer = POINTER_RIGHT;
549 break;
550 case WINDOW_RESIZING_TOP_LEFT:
551 pointer = POINTER_TOP_LEFT;
552 break;
553 case WINDOW_RESIZING_TOP_RIGHT:
554 pointer = POINTER_TOP_RIGHT;
555 break;
556 case WINDOW_RESIZING_BOTTOM_LEFT:
557 pointer = POINTER_BOTTOM_LEFT;
558 break;
559 case WINDOW_RESIZING_BOTTOM_RIGHT:
560 pointer = POINTER_BOTTOM_RIGHT;
561 break;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400562 case WINDOW_EXTERIOR:
563 case WINDOW_TITLEBAR:
Kristian Høgsberg7d804062010-09-07 21:50:06 -0400564 if (input->current_pointer_image == POINTER_DEFAULT)
565 return;
566
Kristian Høgsbergce457ba2010-09-14 15:39:45 -0400567 wl_input_device_attach(input->input_device, time, NULL, 0, 0);
Kristian Høgsberg7d804062010-09-07 21:50:06 -0400568 input->current_pointer_image = POINTER_DEFAULT;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400569 return;
570 default:
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400571 break;
572 }
573
Kristian Høgsberg7d804062010-09-07 21:50:06 -0400574 if (pointer == input->current_pointer_image)
575 return;
576
577 input->current_pointer_image = pointer;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400578 surface = display->pointer_surfaces[pointer];
579 buffer = display_get_buffer_for_surface(display, surface);
Kristian Høgsbergce457ba2010-09-14 15:39:45 -0400580 wl_input_device_attach(input->input_device, time, buffer,
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400581 pointer_images[pointer].hotspot_x,
582 pointer_images[pointer].hotspot_y);
583}
584
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500585static void
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500586window_handle_motion(void *data, struct wl_input_device *input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400587 uint32_t time,
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500588 int32_t x, int32_t y, int32_t sx, int32_t sy)
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500589{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400590 struct input *input = data;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400591 struct window *window = input->pointer_focus;
592 int location, pointer = POINTER_LEFT_PTR;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400593
594 input->x = x;
595 input->y = y;
596 input->sx = sx;
597 input->sy = sy;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400598
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400599 location = get_pointer_location(window, input->sx, input->sy);
600
601 if (window->motion_handler)
602 pointer = (*window->motion_handler)(window, input, time,
603 x, y, sx, sy,
604 window->user_data);
605
Kristian Høgsbergce457ba2010-09-14 15:39:45 -0400606 set_pointer_image(input, time, pointer);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500607}
608
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400609static void
610window_handle_button(void *data,
611 struct wl_input_device *input_device,
612 uint32_t time, uint32_t button, uint32_t state)
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500613{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400614 struct input *input = data;
615 struct window *window = input->pointer_focus;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400616 int location;
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400617
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400618 location = get_pointer_location(window, input->sx, input->sy);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500619
620 if (button == BTN_LEFT && state == 1) {
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400621 switch (location) {
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400622 case WINDOW_TITLEBAR:
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400623 wl_shell_move(window->display->shell,
624 window->surface, input_device, time);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500625 break;
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400626 case WINDOW_RESIZING_TOP:
627 case WINDOW_RESIZING_BOTTOM:
628 case WINDOW_RESIZING_LEFT:
629 case WINDOW_RESIZING_RIGHT:
630 case WINDOW_RESIZING_TOP_LEFT:
631 case WINDOW_RESIZING_TOP_RIGHT:
632 case WINDOW_RESIZING_BOTTOM_LEFT:
633 case WINDOW_RESIZING_BOTTOM_RIGHT:
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400634 wl_shell_resize(window->display->shell,
635 window->surface, input_device, time,
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400636 location);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500637 break;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400638 case WINDOW_CLIENT_AREA:
639 if (window->button_handler)
640 (*window->button_handler)(window,
641 input, time,
642 button, state,
643 window->user_data);
644 break;
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500645 }
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400646 } else {
647 if (window->button_handler)
648 (*window->button_handler)(window,
649 input, time,
650 button, state,
651 window->user_data);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500652 }
653}
654
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500655static void
656window_handle_key(void *data, struct wl_input_device *input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400657 uint32_t time, uint32_t key, uint32_t state)
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500658{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400659 struct input *input = data;
660 struct window *window = input->keyboard_focus;
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400661 struct display *d = window->display;
662 uint32_t code, sym, level;
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500663
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400664 code = key + d->xkb->min_key_code;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400665 if (window->keyboard_device != input)
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500666 return;
667
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400668 level = 0;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400669 if (input->modifiers & WINDOW_MODIFIER_SHIFT &&
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400670 XkbKeyGroupWidth(d->xkb, code, 0) > 1)
671 level = 1;
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500672
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400673 sym = XkbKeySymEntry(d->xkb, code, level, 0);
674
675 if (state)
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400676 input->modifiers |= d->xkb->map->modmap[code];
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400677 else
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400678 input->modifiers &= ~d->xkb->map->modmap[code];
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500679
680 if (window->key_handler)
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -0400681 (*window->key_handler)(window, key, sym, state,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400682 input->modifiers, window->user_data);
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500683}
684
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500685static void
686window_handle_pointer_focus(void *data,
687 struct wl_input_device *input_device,
Kristian Høgsberg6d702022010-08-06 15:12:22 -0400688 uint32_t time, struct wl_surface *surface,
689 int32_t x, int32_t y, int32_t sx, int32_t sy)
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500690{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400691 struct input *input = data;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400692 struct window *window;
693 int pointer;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400694
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400695 if (surface) {
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400696 input->pointer_focus = wl_surface_get_user_data(surface);
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400697 window = input->pointer_focus;
698
699 pointer = POINTER_LEFT_PTR;
700 if (window->motion_handler)
701 pointer = (*window->motion_handler)(window,
702 input, time,
703 x, y, sx, sy,
704 window->user_data);
705
Kristian Høgsbergce457ba2010-09-14 15:39:45 -0400706 set_pointer_image(input, time, pointer);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400707 } else {
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400708 input->pointer_focus = NULL;
Kristian Høgsberg7d804062010-09-07 21:50:06 -0400709 input->current_pointer_image = POINTER_UNSET;
Kristian Høgsbergda275dd2010-08-16 17:47:07 -0400710 }
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500711}
712
713static void
714window_handle_keyboard_focus(void *data,
715 struct wl_input_device *input_device,
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400716 uint32_t time,
Kristian Høgsberg3c38fa02009-02-23 22:30:29 -0500717 struct wl_surface *surface,
718 struct wl_array *keys)
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500719{
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400720 struct input *input = data;
721 struct window *window = input->keyboard_focus;
722 struct display *d = input->display;
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500723 uint32_t *k, *end;
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500724
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400725 window = input->keyboard_focus;
726 if (window) {
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500727 window->keyboard_device = NULL;
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400728 if (window->keyboard_focus_handler)
729 (*window->keyboard_focus_handler)(window, NULL,
730 window->user_data);
Kristian Høgsberg99f090d2009-02-23 22:37:14 -0500731 }
732
Kristian Høgsberg808fd412010-07-20 17:06:19 -0400733 if (surface)
734 input->keyboard_focus = wl_surface_get_user_data(surface);
735 else
736 input->keyboard_focus = NULL;
737
738 end = keys->data + keys->size;
739 for (k = keys->data; k < end; k++)
740 input->modifiers |= d->xkb->map->modmap[*k];
741
742 window = input->keyboard_focus;
743 if (window) {
744 window->keyboard_device = input;
745 if (window->keyboard_focus_handler)
746 (*window->keyboard_focus_handler)(window,
747 window->keyboard_device,
748 window->user_data);
749 }
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500750}
751
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500752static const struct wl_input_device_listener input_device_listener = {
753 window_handle_motion,
754 window_handle_button,
755 window_handle_key,
Kristian Høgsbergdb6c2f32009-02-22 21:51:24 -0500756 window_handle_pointer_focus,
757 window_handle_keyboard_focus,
Kristian Høgsberg94448c02008-12-30 11:03:33 -0500758};
759
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400760void
761input_get_position(struct input *input, int32_t *x, int32_t *y)
762{
763 *x = input->sx;
764 *y = input->sy;
765}
766
Kristian Høgsberg1d7ffd32010-08-25 16:34:05 -0400767struct wl_input_device *
768input_get_input_device(struct input *input)
769{
770 return input->input_device;
771}
772
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400773struct wl_drag *
774window_start_drag(struct window *window, struct input *input, uint32_t time,
775 const struct wl_drag_listener *listener, void *data)
Kristian Høgsberg506e20e2010-08-19 17:26:02 -0400776{
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400777 struct wl_drag *drag;
Kristian Høgsberg506e20e2010-08-19 17:26:02 -0400778
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400779 cairo_device_flush (window->display->device);
780
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400781 drag = wl_shell_create_drag(window->display->shell);
782 wl_drag_offer(drag, "text/plain");
783 wl_drag_offer(drag, "text/html");
784 wl_drag_activate(drag, window->surface, input->input_device, time);
785 wl_drag_add_listener(drag, listener, data);
786
787 return drag;
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400788}
789
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400790static void
791handle_configure(void *data, struct wl_shell *shell,
792 uint32_t time, uint32_t edges,
793 struct wl_surface *surface,
794 int32_t x, int32_t y, int32_t width, int32_t height)
795{
796 struct window *window = wl_surface_get_user_data(surface);
797
798 window->resize_edges = edges;
799 window->pending_allocation.x = x;
800 window->pending_allocation.y = y;
801 window->pending_allocation.width = width;
802 window->pending_allocation.height = height;
803
804 if (!(edges & 15))
805 return;
806
807 if (window->resize_handler)
808 (*window->resize_handler)(window,
809 window->user_data);
810 else if (window->redraw_handler)
811 window_schedule_redraw(window);
812}
813
814static const struct wl_shell_listener shell_listener = {
815 handle_configure,
816};
817
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500818void
819window_get_child_rectangle(struct window *window,
820 struct rectangle *rectangle)
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500821{
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400822 if (window->fullscreen && !window->decoration) {
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500823 *rectangle = window->allocation;
824 } else {
825 rectangle->x = window->margin + 10;
826 rectangle->y = window->margin + 50;
827 rectangle->width = window->allocation.width - 20 - window->margin * 2;
828 rectangle->height = window->allocation.height - 60 - window->margin * 2;
829 }
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500830}
831
832void
Kristian Høgsberg22106762008-12-08 13:50:07 -0500833window_set_child_size(struct window *window,
834 struct rectangle *rectangle)
835{
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400836 int32_t width, height;
837
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500838 if (!window->fullscreen) {
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400839 width = rectangle->width + 20 + window->margin * 2;
840 height = rectangle->height + 60 + window->margin * 2;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400841
842 if (window->resize_edges & WINDOW_RESIZING_LEFT)
843 window->allocation.x +=
844 window->allocation.width - width;
845 if (window->resize_edges & WINDOW_RESIZING_TOP)
846 window->allocation.y +=
847 window->allocation.height - height;
848
Kristian Høgsbergbf6ceda2010-06-14 20:25:06 -0400849 window->allocation.width = width;
850 window->allocation.height = height;
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500851 }
Kristian Høgsberg22106762008-12-08 13:50:07 -0500852}
853
854void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400855window_copy_image(struct window *window,
856 struct rectangle *rectangle, EGLImageKHR image)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500857{
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400858 /* set image as read buffer, copy pixels or something... */
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500859}
860
861void
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500862window_copy_surface(struct window *window,
863 struct rectangle *rectangle,
864 cairo_surface_t *surface)
865{
Kristian Høgsberg2aac3022009-12-21 10:04:53 -0500866 cairo_t *cr;
867
868 cr = cairo_create (window->cairo_surface);
869
870 cairo_set_source_surface (cr,
871 surface,
872 rectangle->x, rectangle->y);
873
874 cairo_paint (cr);
875 cairo_destroy (cr);
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500876}
877
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400878static gboolean
879idle_redraw(void *data)
880{
881 struct window *window = data;
882
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400883 if (window->resize_edges)
884 window->allocation = window->pending_allocation;
885
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400886 window->redraw_handler(window, window->user_data);
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400887
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400888 window->redraw_scheduled = 0;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400889 window->resize_edges = 0;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400890
891 return FALSE;
892}
893
894void
895window_schedule_redraw(struct window *window)
896{
897 if (!window->redraw_scheduled) {
898 g_idle_add(idle_redraw, window);
899 window->redraw_scheduled = 1;
900 }
901}
902
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500903void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500904window_set_fullscreen(struct window *window, int fullscreen)
905{
906 window->fullscreen = fullscreen;
907 if (window->fullscreen) {
908 window->saved_allocation = window->allocation;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500909 window->allocation = window->display->screen_allocation;
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500910 } else {
911 window->allocation = window->saved_allocation;
912 }
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500913}
914
915void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400916window_set_decoration(struct window *window, int decoration)
917{
918 window->decoration = decoration;
919}
920
921void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400922window_set_user_data(struct window *window, void *data)
923{
924 window->user_data = data;
925}
926
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400927void *
928window_get_user_data(struct window *window)
929{
930 return window->user_data;
931}
932
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400933void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500934window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400935 window_resize_handler_t handler)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500936{
937 window->resize_handler = handler;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500938}
939
940void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400941window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400942 window_redraw_handler_t handler)
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400943{
944 window->redraw_handler = handler;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400945}
946
947void
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500948window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400949 window_key_handler_t handler)
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500950{
951 window->key_handler = handler;
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500952}
953
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500954void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400955window_set_button_handler(struct window *window,
956 window_button_handler_t handler)
957{
958 window->button_handler = handler;
959}
960
961void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400962window_set_motion_handler(struct window *window,
963 window_motion_handler_t handler)
964{
965 window->motion_handler = handler;
966}
967
968void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500969window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400970 window_keyboard_focus_handler_t handler)
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500971{
972 window->keyboard_focus_handler = handler;
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500973}
974
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400975void
976window_move(struct window *window, int32_t x, int32_t y)
977{
978 window->allocation.x = x;
979 window->allocation.y = y;
980
981 wl_surface_map(window->surface,
982 window->allocation.x - window->margin,
983 window->allocation.y - window->margin,
984 window->allocation.width,
985 window->allocation.height);
986}
987
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500988struct window *
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500989window_create(struct display *display, const char *title,
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500990 int32_t x, int32_t y, int32_t width, int32_t height)
991{
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500992 struct window *window;
993
994 window = malloc(sizeof *window);
995 if (window == NULL)
996 return NULL;
997
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500998 memset(window, 0, sizeof *window);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500999 window->display = display;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -05001000 window->title = strdup(title);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001001 window->surface = wl_compositor_create_surface(display->compositor);
Kristian Høgsberg0395f302008-12-22 12:14:50 -05001002 window->allocation.x = x;
1003 window->allocation.y = y;
1004 window->allocation.width = width;
1005 window->allocation.height = height;
1006 window->saved_allocation = window->allocation;
Kristian Høgsberg40979232008-11-25 22:40:39 -05001007 window->margin = 16;
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001008 window->decoration = 1;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001009
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001010 wl_surface_set_user_data(window->surface, window);
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001011 wl_list_insert(display->window_list.prev, &window->link);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001012
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001013 return window;
1014}
1015
1016static void
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001017drm_handle_device(void *data, struct wl_drm *drm, const char *device)
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001018{
1019 struct display *d = data;
1020
1021 d->device_name = strdup(device);
1022}
1023
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001024static void drm_handle_authenticated(void *data, struct wl_drm *drm)
1025{
Kristian Høgsberg640609a2010-08-09 22:11:47 -04001026 struct display *d = data;
1027
1028 d->authenticated = 1;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001029}
1030
1031static const struct wl_drm_listener drm_listener = {
1032 drm_handle_device,
1033 drm_handle_authenticated
1034};
1035
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001036static void
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001037display_handle_geometry(void *data,
1038 struct wl_output *output,
1039 int32_t width, int32_t height)
1040{
1041 struct display *display = data;
1042
1043 display->screen_allocation.x = 0;
1044 display->screen_allocation.y = 0;
1045 display->screen_allocation.width = width;
1046 display->screen_allocation.height = height;
1047}
1048
1049static const struct wl_output_listener output_listener = {
1050 display_handle_geometry,
1051};
1052
1053static void
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001054display_add_input(struct display *d, uint32_t id)
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001055{
1056 struct input *input;
1057
1058 input = malloc(sizeof *input);
1059 if (input == NULL)
1060 return;
1061
1062 memset(input, 0, sizeof *input);
1063 input->display = d;
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001064 input->input_device = wl_input_device_create(d->display, id);
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001065 input->pointer_focus = NULL;
1066 input->keyboard_focus = NULL;
1067 wl_list_insert(d->input_list.prev, &input->link);
1068
1069 wl_input_device_add_listener(input->input_device,
1070 &input_device_listener, input);
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001071 wl_input_device_set_user_data(input->input_device, input);
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001072}
1073
1074static void
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001075display_handle_global(struct wl_display *display, uint32_t id,
1076 const char *interface, uint32_t version, void *data)
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001077{
1078 struct display *d = data;
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -04001079 struct wl_drag_offer *offer;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001080
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001081 if (strcmp(interface, "compositor") == 0) {
1082 d->compositor = wl_compositor_create(display, id);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001083 } else if (strcmp(interface, "output") == 0) {
1084 d->output = wl_output_create(display, id);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001085 wl_output_add_listener(d->output, &output_listener, d);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001086 } else if (strcmp(interface, "input_device") == 0) {
1087 display_add_input(d, id);
1088 } else if (strcmp(interface, "shell") == 0) {
1089 d->shell = wl_shell_create(display, id);
Kristian Høgsberg83fc0612010-08-04 22:44:55 -04001090 wl_shell_add_listener(d->shell, &shell_listener, d);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001091 } else if (strcmp(interface, "drm") == 0) {
1092 d->drm = wl_drm_create(display, id);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001093 wl_drm_add_listener(d->drm, &drm_listener, d);
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -04001094 } else if (strcmp(interface, "drag_offer") == 0) {
1095 offer = wl_drag_offer_create(display, id);
1096 d->drag_offer_handler(offer, d);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001097 }
1098}
1099
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001100static const char socket_name[] = "\0wayland";
1101
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001102static void
1103display_render_frame(struct display *d)
1104{
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001105 int radius = 8;
1106 cairo_t *cr;
1107
1108 d->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1109 cr = cairo_create(d->shadow);
1110 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1111 cairo_set_source_rgba(cr, 0, 0, 0, 1);
1112 rounded_rect(cr, 16, 16, 112, 112, radius);
1113 cairo_fill(cr);
1114 cairo_destroy(cr);
1115 blur_surface(d->shadow, 64);
1116
1117 d->active_frame =
1118 cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1119 cr = cairo_create(d->active_frame);
1120 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1121 cairo_set_source_rgba(cr, 0.8, 0.8, 0.4, 1);
1122 rounded_rect(cr, 16, 16, 112, 112, radius);
1123 cairo_fill(cr);
1124 cairo_destroy(cr);
1125
1126 d->inactive_frame =
1127 cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1128 cr = cairo_create(d->inactive_frame);
1129 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1130 cairo_set_source_rgba(cr, 0.6, 0.6, 0.6, 1);
1131 rounded_rect(cr, 16, 16, 112, 112, radius);
1132 cairo_fill(cr);
1133 cairo_destroy(cr);
1134}
1135
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001136static void
1137init_xkb(struct display *d)
1138{
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001139 struct xkb_rule_names names;
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001140
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001141 names.rules = "evdev";
1142 names.model = "pc105";
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001143 names.layout = option_xkb_layout;
1144 names.variant = option_xkb_variant;
1145 names.options = option_xkb_options;
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001146
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001147 d->xkb = xkb_compile_keymap_from_rules(&names);
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001148 if (!d->xkb) {
1149 fprintf(stderr, "Failed to compile keymap\n");
1150 exit(1);
1151 }
1152}
1153
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001154struct display *
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001155display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001156{
1157 struct display *d;
Kristian Høgsberg379b6782010-07-28 22:52:28 -04001158 EGLint major, minor;
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001159 int fd;
1160 GOptionContext *context;
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001161 GOptionGroup *xkb_option_group;
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001162 GError *error;
Kristian Høgsberg640609a2010-08-09 22:11:47 -04001163 drm_magic_t magic;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001164
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001165 g_type_init();
1166
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001167 context = g_option_context_new(NULL);
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001168 if (option_entries)
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001169 g_option_context_add_main_entries(context, option_entries, "Wayland View");
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001170
1171 xkb_option_group = g_option_group_new("xkb",
1172 "Keyboard options",
1173 "Show all XKB options",
1174 NULL, NULL);
1175 g_option_group_add_entries(xkb_option_group, xkb_option_entries);
1176 g_option_context_add_group (context, xkb_option_group);
1177
1178 if (!g_option_context_parse(context, argc, argv, &error)) {
1179 fprintf(stderr, "option parsing failed: %s\n", error->message);
1180 exit(EXIT_FAILURE);
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001181 }
1182
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001183
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001184 d = malloc(sizeof *d);
1185 if (d == NULL)
1186 return NULL;
1187
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001188 d->display = wl_display_create(socket_name, sizeof socket_name);
1189 if (d->display == NULL) {
1190 fprintf(stderr, "failed to create display: %m\n");
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001191 return NULL;
1192 }
1193
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001194 wl_list_init(&d->input_list);
1195
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001196 /* Set up listener so we'll catch all events. */
1197 wl_display_add_global_listener(d->display,
1198 display_handle_global, d);
1199
1200 /* Process connection events. */
1201 wl_display_iterate(d->display, WL_DISPLAY_READABLE);
1202
1203 fd = open(d->device_name, O_RDWR);
1204 if (fd < 0) {
1205 fprintf(stderr, "drm open failed: %m\n");
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001206 return NULL;
1207 }
1208
Kristian Høgsberg640609a2010-08-09 22:11:47 -04001209 if (drmGetMagic(fd, &magic)) {
1210 fprintf(stderr, "DRI2: failed to get drm magic");
1211 return NULL;
1212 }
1213
1214 /* Wait for authenticated event */
1215 wl_drm_authenticate(d->drm, magic);
1216 wl_display_iterate(d->display, WL_DISPLAY_WRITABLE);
1217 while (!d->authenticated)
1218 wl_display_iterate(d->display, WL_DISPLAY_READABLE);
1219
Kristian Høgsbergf252d6a2010-07-08 20:15:10 -04001220 d->dpy = eglGetDRMDisplayMESA(fd);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001221 if (!eglInitialize(d->dpy, &major, &minor)) {
1222 fprintf(stderr, "failed to initialize display\n");
1223 return NULL;
1224 }
1225
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001226 eglBindAPI(EGL_OPENGL_API);
1227
Kristian Høgsberg379b6782010-07-28 22:52:28 -04001228 d->ctx = eglCreateContext(d->dpy, NULL, EGL_NO_CONTEXT, NULL);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001229 if (d->ctx == NULL) {
1230 fprintf(stderr, "failed to create context\n");
1231 return NULL;
1232 }
1233
1234 if (!eglMakeCurrent(d->dpy, NULL, NULL, d->ctx)) {
1235 fprintf(stderr, "faile to make context current\n");
1236 return NULL;
1237 }
1238
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001239 d->device = cairo_egl_device_create(d->dpy, d->ctx);
Kristian Høgsberg26449102009-05-28 20:23:31 -04001240 if (d->device == NULL) {
1241 fprintf(stderr, "failed to get cairo drm device\n");
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -05001242 return NULL;
1243 }
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -05001244
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001245 create_pointer_surfaces(d);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -04001246
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001247 display_render_frame(d);
1248
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001249 d->loop = g_main_loop_new(NULL, FALSE);
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001250 d->source = wl_glib_source_new(d->display);
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001251 g_source_attach(d->source, NULL);
1252
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001253 wl_list_init(&d->window_list);
1254
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001255 init_xkb(d);
1256
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001257 return d;
1258}
1259
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -04001260struct wl_display *
1261display_get_display(struct display *display)
1262{
1263 return display->display;
1264}
1265
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001266struct wl_compositor *
1267display_get_compositor(struct display *display)
1268{
1269 return display->compositor;
Kristian Høgsberg61017b12008-11-02 18:51:48 -05001270}
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001271
1272EGLDisplay
1273display_get_egl_display(struct display *d)
1274{
1275 return d->dpy;
1276}
1277
1278void
1279display_run(struct display *d)
1280{
1281 g_main_loop_run(d->loop);
1282}
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -04001283
1284void
1285display_set_drag_offer_handler(struct display *display,
1286 display_drag_offer_handler_t handler)
1287{
1288 display->drag_offer_handler = handler;
1289}