blob: 1ff59c265800e120b1fe03c9985d54f7d2bf4ac7 [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øgsberg61017b12008-11-02 18:51:48 -050033
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -050034#include <linux/input.h>
Kristian Høgsberg61017b12008-11-02 18:51:48 -050035#include "wayland-client.h"
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -050036#include "wayland-glib.h"
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050037
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050038#include "cairo-util.h"
Kristian Høgsberg61017b12008-11-02 18:51:48 -050039
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050040#include "window.h"
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050041
Kristian Høgsberg61017b12008-11-02 18:51:48 -050042struct window {
Kristian Høgsberg40979232008-11-25 22:40:39 -050043 struct wl_display *display;
Kristian Høgsbergd2412e22008-12-15 20:35:24 -050044 struct wl_compositor *compositor;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050045 struct wl_surface *surface;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050046 const char *title;
Kristian Høgsberg78231c82008-11-08 15:06:01 -050047 int x, y, width, height;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050048 int minimum_width, minimum_height;
Kristian Høgsberg40979232008-11-25 22:40:39 -050049 int margin;
Kristian Høgsbergc492b482008-12-12 12:00:02 -050050 int drag_x, drag_y;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050051 int state;
Kristian Høgsbergc492b482008-12-12 12:00:02 -050052 uint32_t grab_device;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050053 uint32_t name;
54 int fd;
Kristian Høgsberg78231c82008-11-08 15:06:01 -050055
56 struct buffer *buffer;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -050057
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050058 window_resize_handler_t resize_handler;
59 window_frame_handler_t frame_handler;
60 window_acknowledge_handler_t acknowledge_handler;
Kristian Høgsberg6e83d582008-12-08 00:01:36 -050061 window_key_handler_t key_handler;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050062 void *user_data;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050063};
64
Kristian Høgsberge4feb562008-11-08 18:53:37 -050065static void
66rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius)
67{
68 cairo_move_to(cr, x0, y0 + radius);
69 cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
70 cairo_line_to(cr, x1 - radius, y0);
71 cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
72 cairo_line_to(cr, x1, y1 - radius);
73 cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
74 cairo_line_to(cr, x0 + radius, y1);
75 cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
76 cairo_close_path(cr);
77}
78
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -050079void
80window_draw(struct window *window)
Kristian Høgsberg61017b12008-11-02 18:51:48 -050081{
82 cairo_surface_t *surface;
83 cairo_t *cr;
Kristian Høgsberg40979232008-11-25 22:40:39 -050084 int border = 2, radius = 5;
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -050085 cairo_text_extents_t extents;
Kristian Høgsberge4feb562008-11-08 18:53:37 -050086 cairo_pattern_t *gradient, *outline, *bright, *dim;
Kristian Høgsbergde31d5c2008-12-18 17:55:33 -050087 struct wl_visual *visual;
Kristian Høgsberg61017b12008-11-02 18:51:48 -050088
89 surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
Kristian Høgsberg40979232008-11-25 22:40:39 -050090 window->width + window->margin * 2,
91 window->height + window->margin * 2);
Kristian Høgsberg61017b12008-11-02 18:51:48 -050092
Kristian Høgsberge4feb562008-11-08 18:53:37 -050093 outline = cairo_pattern_create_rgb(0.1, 0.1, 0.1);
Kristian Høgsberge9d550b2008-11-19 00:49:39 -050094 bright = cairo_pattern_create_rgb(0.8, 0.8, 0.8);
Kristian Høgsberge4feb562008-11-08 18:53:37 -050095 dim = cairo_pattern_create_rgb(0.4, 0.4, 0.4);
96
Kristian Høgsberg61017b12008-11-02 18:51:48 -050097 cr = cairo_create(surface);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -050098
Kristian Høgsberg40979232008-11-25 22:40:39 -050099 cairo_translate(cr, window->margin + 7, window->margin + 5);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500100 cairo_set_line_width (cr, border);
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500101 cairo_set_source_rgba(cr, 0, 0, 0, 0.7);
Kristian Høgsberg8c304f62008-11-10 10:46:53 -0500102 rounded_rect(cr, 0, 0, window->width, window->height, radius);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500103 cairo_fill(cr);
Kristian Høgsberg87330262008-11-17 22:23:55 -0500104 blur_surface(surface, 24 + radius);
Kristian Høgsberg2f2cfae2008-11-08 22:46:30 -0500105
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500106 cairo_translate(cr, -7, -5);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500107 cairo_set_line_width (cr, border);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500108 rounded_rect(cr, 1, 1, window->width - 1, window->height - 1, radius);
109 cairo_set_source(cr, outline);
110 cairo_stroke(cr);
Kristian Høgsberg6e635f32008-11-09 09:15:46 -0500111 rounded_rect(cr, 2, 2, window->width - 2, window->height - 2, radius - 1);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500112 cairo_set_source(cr, bright);
113 cairo_stroke(cr);
Kristian Høgsberg6e635f32008-11-09 09:15:46 -0500114 rounded_rect(cr, 3, 3, window->width - 2, window->height - 2, radius - 1);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500115 cairo_set_source(cr, dim);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500116 cairo_stroke(cr);
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -0500117
Kristian Høgsberg6e635f32008-11-09 09:15:46 -0500118 rounded_rect(cr, 2, 2, window->width - 2, window->height - 2, radius - 1);
119 gradient = cairo_pattern_create_linear (0, 0, 0, 100);
Kristian Høgsberge9d550b2008-11-19 00:49:39 -0500120 cairo_pattern_add_color_stop_rgb(gradient, 0, 0.6, 0.6, 0.4);
121 cairo_pattern_add_color_stop_rgb(gradient, 1, 0.8, 0.8, 0.7);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500122 cairo_set_source(cr, gradient);
123 cairo_fill(cr);
124 cairo_pattern_destroy(gradient);
125
126 cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
127 cairo_move_to(cr, 10, 50);
128 cairo_line_to(cr, window->width - 10, 50);
129 cairo_line_to(cr, window->width - 10, window->height - 10);
130 cairo_line_to(cr, 10, window->height - 10);
131 cairo_close_path(cr);
132 cairo_set_source(cr, dim);
133 cairo_stroke(cr);
134
135 cairo_move_to(cr, 11, 51);
136 cairo_line_to(cr, window->width - 10, 51);
137 cairo_line_to(cr, window->width - 10, window->height - 10);
138 cairo_line_to(cr, 11, window->height - 10);
139 cairo_close_path(cr);
140 cairo_set_source(cr, bright);
141 cairo_stroke(cr);
142
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500143 cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
144 cairo_set_font_size(cr, 14);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500145 cairo_text_extents(cr, window->title, &extents);
Kristian Høgsbergca1d1f62008-11-03 06:59:52 -0500146 cairo_move_to(cr, (window->width - extents.width) / 2, 10 - extents.y_bearing);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500147 cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
148 cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
149 cairo_set_line_width (cr, 4);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500150 cairo_text_path(cr, window->title);
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500151 cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
152 cairo_stroke_preserve(cr);
153 cairo_set_source_rgb(cr, 1, 1, 1);
154 cairo_fill(cr);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500155 cairo_destroy(cr);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500156
Kristian Høgsberg40979232008-11-25 22:40:39 -0500157 window->buffer = buffer_create_from_cairo_surface(window->fd, surface);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500158 cairo_surface_destroy(surface);
159
Kristian Høgsbergde31d5c2008-12-18 17:55:33 -0500160 visual = wl_display_get_premultiplied_argb_visual(window->display);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500161 wl_surface_attach(window->surface,
162 window->buffer->name,
163 window->buffer->width,
164 window->buffer->height,
Kristian Høgsbergde31d5c2008-12-18 17:55:33 -0500165 window->buffer->stride,
166 visual);
Kristian Høgsbergb7a01922008-11-08 15:39:41 -0500167
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -0500168 wl_surface_map(window->surface,
169 window->x - window->margin,
170 window->y - window->margin,
171 window->width + 2 * window->margin,
172 window->height + 2 * window->margin);
Kristian Høgsberg44f36e32008-11-26 12:57:31 -0500173}
174
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500175enum window_state {
176 WINDOW_STABLE,
177 WINDOW_MOVING,
178 WINDOW_RESIZING_UPPER_LEFT,
179 WINDOW_RESIZING_UPPER_RIGHT,
180 WINDOW_RESIZING_LOWER_LEFT,
181 WINDOW_RESIZING_LOWER_RIGHT
182};
183
184enum location {
185 LOCATION_INTERIOR,
186 LOCATION_UPPER_LEFT,
187 LOCATION_UPPER_RIGHT,
188 LOCATION_LOWER_LEFT,
189 LOCATION_LOWER_RIGHT,
190 LOCATION_OUTSIDE
191};
192
Kristian Høgsberge4feb562008-11-08 18:53:37 -0500193static void
194event_handler(struct wl_display *display,
Kristian Høgsberg40979232008-11-25 22:40:39 -0500195 uint32_t object, uint32_t opcode,
196 uint32_t size, uint32_t *p, void *data)
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500197{
198 struct window *window = data;
Kristian Høgsberg1584c572008-12-08 12:59:37 -0500199 struct rectangle rectangle;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500200 int location;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500201 int grip_size = 16;
202
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500203 /* FIXME: Object ID 2 is the compositor, for anything else we
Kristian Høgsberg40979232008-11-25 22:40:39 -0500204 * assume it's an input device. */
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500205 if (object == 2 && opcode == 0) {
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -0500206 uint32_t key = p[0];
207
208 /* Ignore acknowledge events for window move requests. */
209 if (key != 0)
210 return;
211
Kristian Høgsberg40979232008-11-25 22:40:39 -0500212 /* The acknowledge event means that the server
Kristian Høgsberg44f36e32008-11-26 12:57:31 -0500213 * processed our last commit request and we can now
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -0500214 * safely free the old window buffer if we resized and
215 * render the next frame into our back buffer.. */
216
Kristian Høgsberg44f36e32008-11-26 12:57:31 -0500217 if (window->buffer != NULL) {
Kristian Høgsberg40979232008-11-25 22:40:39 -0500218 buffer_destroy(window->buffer, window->fd);
219 window->buffer = NULL;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500220 }
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500221 if (window->acknowledge_handler)
222 (*window->acknowledge_handler)(window, key,
223 window->user_data);
224
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500225 } else if (object == 2 && opcode == 1) {
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -0500226 /* The frame event means that the previous frame was
227 * composited, and we can now send the request to copy
228 * the frame we've rendered in the mean time into the
229 * servers surface buffer. */
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500230 if (window->frame_handler)
231 (*window->frame_handler)(window, p[0], p[1],
232 window->user_data);
Kristian Høgsberg44f36e32008-11-26 12:57:31 -0500233 } else if (object == 1) {
234 fprintf(stderr, "unexpected event from display: %d\n",
235 opcode);
236 exit(-1);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500237 } else if (opcode == 0) {
238 int x = p[0], y = p[1];
239
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500240 switch (window->state) {
241 case WINDOW_MOVING:
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500242 if (window->grab_device != object)
243 break;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500244 window->x = window->drag_x + x;
245 window->y = window->drag_y + y;
246 wl_surface_map(window->surface,
247 window->x - window->margin,
248 window->y - window->margin,
249 window->width + 2 * window->margin,
250 window->height + 2 * window->margin);
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500251 wl_compositor_commit(window->compositor, 1);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500252 break;
253 case WINDOW_RESIZING_LOWER_RIGHT:
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500254 if (window->grab_device != object)
255 break;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500256 window->width = window->drag_x + x;
257 window->height = window->drag_y + y;
Kristian Høgsbergfbdbbdc2008-11-28 17:06:06 -0500258
Kristian Høgsberg1584c572008-12-08 12:59:37 -0500259 window_get_child_rectangle(window, &rectangle);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500260 if (window->resize_handler)
261 (*window->resize_handler)(window,
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500262 window->user_data);
Kristian Høgsberg1584c572008-12-08 12:59:37 -0500263
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500264 break;
265 }
Kristian Høgsberg40979232008-11-25 22:40:39 -0500266 } else if (opcode == 1) {
267 int button = p[0], state = p[1];
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500268 int32_t x = p[2], y = p[3];
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500269
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500270 if (window->x + window->width - grip_size <= x &&
271 x < window->x + window->width &&
272 window->y + window->height - grip_size <= y &&
273 y < window->y + window->height) {
Kristian Høgsberg40979232008-11-25 22:40:39 -0500274 location = LOCATION_LOWER_RIGHT;
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500275 } else if (window->x <= x && x < window->x + window->width &&
276 window->y <= y && y < window->y + window->height) {
Kristian Høgsberg40979232008-11-25 22:40:39 -0500277 location = LOCATION_INTERIOR;
278 } else {
279 location = LOCATION_OUTSIDE;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500280 }
Kristian Høgsberg40979232008-11-25 22:40:39 -0500281
Kristian Høgsberg5ee1a602008-12-11 23:18:45 -0500282 if (button == BTN_LEFT && state == 1) {
Kristian Høgsberg40979232008-11-25 22:40:39 -0500283 switch (location) {
284 case LOCATION_INTERIOR:
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500285 window->drag_x = window->x - x;
286 window->drag_y = window->y - y;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500287 window->state = WINDOW_MOVING;
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500288 window->grab_device = object;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500289 break;
290 case LOCATION_LOWER_RIGHT:
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500291 window->drag_x = window->width - x;
292 window->drag_y = window->height - y;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500293 window->state = WINDOW_RESIZING_LOWER_RIGHT;
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500294 window->grab_device = object;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500295 break;
296 default:
297 window->state = WINDOW_STABLE;
298 break;
299 }
Kristian Høgsbergc492b482008-12-12 12:00:02 -0500300 } else if (button == BTN_LEFT &&
301 state == 0 && object == window->grab_device) {
Kristian Høgsberg40979232008-11-25 22:40:39 -0500302 window->state = WINDOW_STABLE;
303 }
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500304 } else if (opcode == 2) {
305 if (window->key_handler)
306 (*window->key_handler)(window, p[0], p[1],
307 window->user_data);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500308 }
309}
310
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500311void
312window_get_child_rectangle(struct window *window,
313 struct rectangle *rectangle)
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500314{
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500315 rectangle->x = 10;
316 rectangle->y = 50;
317 rectangle->width = window->width - 20;
318 rectangle->height = window->height - 60;
319}
320
321void
Kristian Høgsberg22106762008-12-08 13:50:07 -0500322window_set_child_size(struct window *window,
323 struct rectangle *rectangle)
324{
325 window->width = rectangle->width + 20;
326 window->height = rectangle->height + 60;
327}
328
329void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500330window_copy(struct window *window,
331 struct rectangle *rectangle,
332 uint32_t name, uint32_t stride)
333{
334 wl_surface_copy(window->surface,
335 window->margin + rectangle->x,
336 window->margin + rectangle->y,
337 name, stride,
338 0, 0, rectangle->width, rectangle->height);
339}
340
341void
342window_set_resize_handler(struct window *window,
343 window_resize_handler_t handler, void *data)
344{
345 window->resize_handler = handler;
346 window->user_data = data;
347}
348
349void
350window_set_frame_handler(struct window *window,
351 window_frame_handler_t handler, void *data)
352{
353 window->frame_handler = handler;
354 window->user_data = data;
355}
356
357void
358window_set_acknowledge_handler(struct window *window,
359 window_acknowledge_handler_t handler, void *data)
360{
361 window->acknowledge_handler = handler;
362 window->user_data = data;
363}
364
365void
Kristian Høgsberg6e83d582008-12-08 00:01:36 -0500366window_set_key_handler(struct window *window,
367 window_key_handler_t handler, void *data)
368{
369 window->key_handler = handler;
370 window->user_data = data;
371}
372
373void
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500374window_set_minimum_size(struct window *window, uint32_t width, int32_t height)
375{
376 window->minimum_width = width;
377 window->minimum_height = height;
378}
379
380struct window *
381window_create(struct wl_display *display, int fd,
382 const char *title,
383 int32_t x, int32_t y, int32_t width, int32_t height)
384{
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500385 struct window *window;
386
387 window = malloc(sizeof *window);
388 if (window == NULL)
389 return NULL;
390
Kristian Høgsberg78231c82008-11-08 15:06:01 -0500391 memset(window, 0, sizeof *window);
Kristian Høgsberg40979232008-11-25 22:40:39 -0500392 window->display = display;
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500393 window->title = strdup(title);
Kristian Høgsbergd2412e22008-12-15 20:35:24 -0500394 window->compositor = wl_display_get_compositor(display);
395 window->surface = wl_compositor_create_surface(window->compositor);
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500396 window->x = x;
397 window->y = y;
398 window->minimum_width = 100;
399 window->minimum_height = 100;
400 window->width = width;
401 window->height = height;
Kristian Høgsberg40979232008-11-25 22:40:39 -0500402 window->margin = 16;
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500403 window->state = WINDOW_STABLE;
404 window->fd = fd;
Kristian Høgsberg8a9cda82008-11-03 15:31:30 -0500405
Kristian Høgsberg1cbaa6a2008-11-07 15:54:48 -0500406 wl_display_set_event_handler(display, event_handler, window);
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500407
Kristian Høgsberg0c4457f2008-12-07 19:59:11 -0500408 return window;
Kristian Høgsberg61017b12008-11-02 18:51:48 -0500409}