blob: 9354f180688aa44a0ec8eec0dfd9a0e661051ced [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øgsberg9a686242010-08-18 15:28:04 -0400528set_pointer_image(struct input *input, 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øgsberg9a686242010-08-18 15:28:04 -0400567 wl_input_device_attach(input->input_device, 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);
580 wl_input_device_attach(input->input_device, 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
606 set_pointer_image(input, 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
706 set_pointer_image(input, 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øgsberg9d69f8e2010-09-03 14:46:38 -0400876
877 wl_surface_damage(window->surface,
878 rectangle->x, rectangle->y,
879 rectangle->width, rectangle->height);
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500880}
881
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400882static gboolean
883idle_redraw(void *data)
884{
885 struct window *window = data;
886
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400887 if (window->resize_edges)
888 window->allocation = window->pending_allocation;
889
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400890 window->redraw_handler(window, window->user_data);
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400891
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400892 window->redraw_scheduled = 0;
Kristian Høgsberg83fc0612010-08-04 22:44:55 -0400893 window->resize_edges = 0;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400894
895 return FALSE;
896}
897
898void
899window_schedule_redraw(struct window *window)
900{
901 if (!window->redraw_scheduled) {
902 g_idle_add(idle_redraw, window);
903 window->redraw_scheduled = 1;
904 }
905}
906
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -0500907void
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500908window_set_fullscreen(struct window *window, int fullscreen)
909{
910 window->fullscreen = fullscreen;
911 if (window->fullscreen) {
912 window->saved_allocation = window->allocation;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500913 window->allocation = window->display->screen_allocation;
Kristian Høgsberg0395f302008-12-22 12:14:50 -0500914 } else {
915 window->allocation = window->saved_allocation;
916 }
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500917}
918
919void
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400920window_set_decoration(struct window *window, int decoration)
921{
922 window->decoration = decoration;
923}
924
925void
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400926window_set_user_data(struct window *window, void *data)
927{
928 window->user_data = data;
929}
930
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -0400931void *
932window_get_user_data(struct window *window)
933{
934 return window->user_data;
935}
936
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400937void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500938window_set_resize_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400939 window_resize_handler_t handler)
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500940{
941 window->resize_handler = handler;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500942}
943
944void
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400945window_set_redraw_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400946 window_redraw_handler_t handler)
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400947{
948 window->redraw_handler = handler;
Kristian Høgsberg80d746f2010-06-14 23:52:50 -0400949}
950
951void
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500952window_set_key_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400953 window_key_handler_t handler)
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500954{
955 window->key_handler = handler;
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500956}
957
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500958void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400959window_set_button_handler(struct window *window,
960 window_button_handler_t handler)
961{
962 window->button_handler = handler;
963}
964
965void
Kristian Høgsberg9a686242010-08-18 15:28:04 -0400966window_set_motion_handler(struct window *window,
967 window_motion_handler_t handler)
968{
969 window->motion_handler = handler;
970}
971
972void
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500973window_set_keyboard_focus_handler(struct window *window,
Kristian Høgsbergc8c37342010-06-25 11:19:22 -0400974 window_keyboard_focus_handler_t handler)
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500975{
976 window->keyboard_focus_handler = handler;
Kristian Høgsberg3c248cc2009-02-22 23:01:35 -0500977}
978
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -0400979void
980window_move(struct window *window, int32_t x, int32_t y)
981{
982 window->allocation.x = x;
983 window->allocation.y = y;
984
985 wl_surface_map(window->surface,
986 window->allocation.x - window->margin,
987 window->allocation.y - window->margin,
988 window->allocation.width,
989 window->allocation.height);
990}
991
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500992struct window *
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -0500993window_create(struct display *display, const char *title,
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500994 int32_t x, int32_t y, int32_t width, int32_t height)
995{
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500996 struct window *window;
997
998 window = malloc(sizeof *window);
999 if (window == NULL)
1000 return NULL;
1001
Kristian Høgsberg78231c82008-11-08 15:06:01 -05001002 memset(window, 0, sizeof *window);
Kristian Høgsberg40979232008-11-25 22:40:39 -05001003 window->display = display;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -05001004 window->title = strdup(title);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001005 window->surface = wl_compositor_create_surface(display->compositor);
Kristian Høgsberg0395f302008-12-22 12:14:50 -05001006 window->allocation.x = x;
1007 window->allocation.y = y;
1008 window->allocation.width = width;
1009 window->allocation.height = height;
1010 window->saved_allocation = window->allocation;
Kristian Høgsberg40979232008-11-25 22:40:39 -05001011 window->margin = 16;
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001012 window->decoration = 1;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001013
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001014 wl_surface_set_user_data(window->surface, window);
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001015 wl_list_insert(display->window_list.prev, &window->link);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001016
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001017 return window;
1018}
1019
1020static void
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001021drm_handle_device(void *data, struct wl_drm *drm, const char *device)
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001022{
1023 struct display *d = data;
1024
1025 d->device_name = strdup(device);
1026}
1027
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001028static void drm_handle_authenticated(void *data, struct wl_drm *drm)
1029{
Kristian Høgsberg640609a2010-08-09 22:11:47 -04001030 struct display *d = data;
1031
1032 d->authenticated = 1;
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001033}
1034
1035static const struct wl_drm_listener drm_listener = {
1036 drm_handle_device,
1037 drm_handle_authenticated
1038};
1039
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001040static void
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001041display_handle_geometry(void *data,
1042 struct wl_output *output,
1043 int32_t width, int32_t height)
1044{
1045 struct display *display = data;
1046
1047 display->screen_allocation.x = 0;
1048 display->screen_allocation.y = 0;
1049 display->screen_allocation.width = width;
1050 display->screen_allocation.height = height;
1051}
1052
1053static const struct wl_output_listener output_listener = {
1054 display_handle_geometry,
1055};
1056
1057static void
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001058display_add_input(struct display *d, uint32_t id)
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001059{
1060 struct input *input;
1061
1062 input = malloc(sizeof *input);
1063 if (input == NULL)
1064 return;
1065
1066 memset(input, 0, sizeof *input);
1067 input->display = d;
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001068 input->input_device = wl_input_device_create(d->display, id);
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001069 input->pointer_focus = NULL;
1070 input->keyboard_focus = NULL;
1071 wl_list_insert(d->input_list.prev, &input->link);
1072
1073 wl_input_device_add_listener(input->input_device,
1074 &input_device_listener, input);
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001075 wl_input_device_set_user_data(input->input_device, input);
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001076}
1077
1078static void
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001079display_handle_global(struct wl_display *display, uint32_t id,
1080 const char *interface, uint32_t version, void *data)
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001081{
1082 struct display *d = data;
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -04001083 struct wl_drag_offer *offer;
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001084
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001085 if (strcmp(interface, "compositor") == 0) {
1086 d->compositor = wl_compositor_create(display, id);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001087 } else if (strcmp(interface, "output") == 0) {
1088 d->output = wl_output_create(display, id);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001089 wl_output_add_listener(d->output, &output_listener, d);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001090 } else if (strcmp(interface, "input_device") == 0) {
1091 display_add_input(d, id);
1092 } else if (strcmp(interface, "shell") == 0) {
1093 d->shell = wl_shell_create(display, id);
Kristian Høgsberg83fc0612010-08-04 22:44:55 -04001094 wl_shell_add_listener(d->shell, &shell_listener, d);
Kristian Høgsberg4fe1a3e2010-08-10 14:02:48 -04001095 } else if (strcmp(interface, "drm") == 0) {
1096 d->drm = wl_drm_create(display, id);
Kristian Høgsberg5fcd0aa2010-08-09 14:43:33 -04001097 wl_drm_add_listener(d->drm, &drm_listener, d);
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -04001098 } else if (strcmp(interface, "drag_offer") == 0) {
1099 offer = wl_drag_offer_create(display, id);
1100 d->drag_offer_handler(offer, d);
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001101 }
1102}
1103
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001104static const char socket_name[] = "\0wayland";
1105
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001106static void
1107display_render_frame(struct display *d)
1108{
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001109 int radius = 8;
1110 cairo_t *cr;
1111
1112 d->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1113 cr = cairo_create(d->shadow);
1114 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1115 cairo_set_source_rgba(cr, 0, 0, 0, 1);
1116 rounded_rect(cr, 16, 16, 112, 112, radius);
1117 cairo_fill(cr);
1118 cairo_destroy(cr);
1119 blur_surface(d->shadow, 64);
1120
1121 d->active_frame =
1122 cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1123 cr = cairo_create(d->active_frame);
1124 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1125 cairo_set_source_rgba(cr, 0.8, 0.8, 0.4, 1);
1126 rounded_rect(cr, 16, 16, 112, 112, radius);
1127 cairo_fill(cr);
1128 cairo_destroy(cr);
1129
1130 d->inactive_frame =
1131 cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
1132 cr = cairo_create(d->inactive_frame);
1133 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
1134 cairo_set_source_rgba(cr, 0.6, 0.6, 0.6, 1);
1135 rounded_rect(cr, 16, 16, 112, 112, radius);
1136 cairo_fill(cr);
1137 cairo_destroy(cr);
1138}
1139
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001140static void
1141init_xkb(struct display *d)
1142{
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001143 struct xkb_rule_names names;
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001144
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001145 names.rules = "evdev";
1146 names.model = "pc105";
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001147 names.layout = option_xkb_layout;
1148 names.variant = option_xkb_variant;
1149 names.options = option_xkb_options;
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001150
Kristian Høgsberg3e6e7e62010-07-02 15:12:02 -04001151 d->xkb = xkb_compile_keymap_from_rules(&names);
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001152 if (!d->xkb) {
1153 fprintf(stderr, "Failed to compile keymap\n");
1154 exit(1);
1155 }
1156}
1157
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001158struct display *
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001159display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001160{
1161 struct display *d;
Kristian Høgsberg379b6782010-07-28 22:52:28 -04001162 EGLint major, minor;
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001163 int fd;
1164 GOptionContext *context;
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001165 GOptionGroup *xkb_option_group;
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001166 GError *error;
Kristian Høgsberg640609a2010-08-09 22:11:47 -04001167 drm_magic_t magic;
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001168
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001169 g_type_init();
1170
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001171 context = g_option_context_new(NULL);
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001172 if (option_entries)
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001173 g_option_context_add_main_entries(context, option_entries, "Wayland View");
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001174
1175 xkb_option_group = g_option_group_new("xkb",
1176 "Keyboard options",
1177 "Show all XKB options",
1178 NULL, NULL);
1179 g_option_group_add_entries(xkb_option_group, xkb_option_entries);
1180 g_option_context_add_group (context, xkb_option_group);
1181
1182 if (!g_option_context_parse(context, argc, argv, &error)) {
1183 fprintf(stderr, "option parsing failed: %s\n", error->message);
1184 exit(EXIT_FAILURE);
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001185 }
1186
Kristian Høgsbergc7c60642010-08-29 21:33:39 -04001187
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001188 d = malloc(sizeof *d);
1189 if (d == NULL)
1190 return NULL;
1191
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001192 d->display = wl_display_create(socket_name, sizeof socket_name);
1193 if (d->display == NULL) {
1194 fprintf(stderr, "failed to create display: %m\n");
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001195 return NULL;
1196 }
1197
Kristian Høgsberg808fd412010-07-20 17:06:19 -04001198 wl_list_init(&d->input_list);
1199
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001200 /* Set up listener so we'll catch all events. */
1201 wl_display_add_global_listener(d->display,
1202 display_handle_global, d);
1203
1204 /* Process connection events. */
1205 wl_display_iterate(d->display, WL_DISPLAY_READABLE);
1206
1207 fd = open(d->device_name, O_RDWR);
1208 if (fd < 0) {
1209 fprintf(stderr, "drm open failed: %m\n");
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001210 return NULL;
1211 }
1212
Kristian Høgsberg640609a2010-08-09 22:11:47 -04001213 if (drmGetMagic(fd, &magic)) {
1214 fprintf(stderr, "DRI2: failed to get drm magic");
1215 return NULL;
1216 }
1217
1218 /* Wait for authenticated event */
1219 wl_drm_authenticate(d->drm, magic);
1220 wl_display_iterate(d->display, WL_DISPLAY_WRITABLE);
1221 while (!d->authenticated)
1222 wl_display_iterate(d->display, WL_DISPLAY_READABLE);
1223
Kristian Høgsbergf252d6a2010-07-08 20:15:10 -04001224 d->dpy = eglGetDRMDisplayMESA(fd);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001225 if (!eglInitialize(d->dpy, &major, &minor)) {
1226 fprintf(stderr, "failed to initialize display\n");
1227 return NULL;
1228 }
1229
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001230 eglBindAPI(EGL_OPENGL_API);
1231
Kristian Høgsberg379b6782010-07-28 22:52:28 -04001232 d->ctx = eglCreateContext(d->dpy, NULL, EGL_NO_CONTEXT, NULL);
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001233 if (d->ctx == NULL) {
1234 fprintf(stderr, "failed to create context\n");
1235 return NULL;
1236 }
1237
1238 if (!eglMakeCurrent(d->dpy, NULL, NULL, d->ctx)) {
1239 fprintf(stderr, "faile to make context current\n");
1240 return NULL;
1241 }
1242
Kristian Høgsberga85fe3c2010-06-08 14:08:30 -04001243 d->device = cairo_egl_device_create(d->dpy, d->ctx);
Kristian Høgsberg26449102009-05-28 20:23:31 -04001244 if (d->device == NULL) {
1245 fprintf(stderr, "failed to get cairo drm device\n");
Kristian Høgsberg0ac16f02009-01-15 11:37:43 -05001246 return NULL;
1247 }
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -05001248
Kristian Høgsberg9a686242010-08-18 15:28:04 -04001249 create_pointer_surfaces(d);
Kristian Høgsbergda275dd2010-08-16 17:47:07 -04001250
Kristian Høgsbergdcb71b62010-06-15 17:16:35 -04001251 display_render_frame(d);
1252
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001253 d->loop = g_main_loop_new(NULL, FALSE);
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001254 d->source = wl_glib_source_new(d->display);
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001255 g_source_attach(d->source, NULL);
1256
Kristian Høgsberg478d9262010-06-08 20:34:11 -04001257 wl_list_init(&d->window_list);
1258
Kristian Høgsberg94adf6c2010-06-25 16:50:05 -04001259 init_xkb(d);
1260
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001261 return d;
1262}
1263
Kristian Høgsberg9d69f8e2010-09-03 14:46:38 -04001264struct wl_display *
1265display_get_display(struct display *display)
1266{
1267 return display->display;
1268}
1269
Kristian Høgsberg43c28ee2009-01-26 23:42:46 -05001270struct wl_compositor *
1271display_get_compositor(struct display *display)
1272{
1273 return display->compositor;
Kristian Høgsberg61017b12008-11-02 18:51:48 -05001274}
Kristian Høgsberg7824d812010-06-08 14:59:44 -04001275
1276EGLDisplay
1277display_get_egl_display(struct display *d)
1278{
1279 return d->dpy;
1280}
1281
1282void
1283display_run(struct display *d)
1284{
1285 g_main_loop_run(d->loop);
1286}
Kristian Høgsberge9d37bd2010-09-02 20:22:42 -04001287
1288void
1289display_set_drag_offer_handler(struct display *display,
1290 display_drag_offer_handler_t handler)
1291{
1292 display->drag_offer_handler = handler;
1293}