2008-12-02 23:15:01 +03:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
* documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
* the above copyright notice appear in all copies and that both that copyright
|
|
|
|
* notice and this permission notice appear in supporting documentation, and
|
|
|
|
* that the name of the copyright holders not be used in advertising or
|
|
|
|
* publicity pertaining to distribution of the software without specific,
|
|
|
|
* written prior permission. The copyright holders make no representations
|
|
|
|
* about the suitability of this software for any purpose. It is provided "as
|
|
|
|
* is" without express or implied warranty.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
|
|
|
|
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
|
|
|
|
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
|
|
|
|
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
|
|
|
|
* OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2008-11-03 02:51:48 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <cairo.h>
|
2008-11-07 23:54:48 +03:00
|
|
|
#include <glib.h>
|
2008-11-03 02:51:48 +03:00
|
|
|
|
2008-12-12 07:18:45 +03:00
|
|
|
#include <linux/input.h>
|
2008-11-03 02:51:48 +03:00
|
|
|
#include "wayland-client.h"
|
2008-11-07 23:54:48 +03:00
|
|
|
#include "wayland-glib.h"
|
2008-11-09 06:46:30 +03:00
|
|
|
|
|
|
|
#include "cairo-util.h"
|
2008-11-03 02:51:48 +03:00
|
|
|
|
2008-12-08 03:59:11 +03:00
|
|
|
#include "window.h"
|
2008-11-03 23:31:30 +03:00
|
|
|
|
2008-11-03 02:51:48 +03:00
|
|
|
struct window {
|
2008-11-26 06:40:39 +03:00
|
|
|
struct wl_display *display;
|
2008-12-16 04:35:24 +03:00
|
|
|
struct wl_compositor *compositor;
|
2008-11-03 02:51:48 +03:00
|
|
|
struct wl_surface *surface;
|
2008-12-08 03:59:11 +03:00
|
|
|
const char *title;
|
2008-12-22 20:14:50 +03:00
|
|
|
struct rectangle allocation, saved_allocation;
|
2008-12-08 03:59:11 +03:00
|
|
|
int minimum_width, minimum_height;
|
2008-11-26 06:40:39 +03:00
|
|
|
int margin;
|
2008-12-12 20:00:02 +03:00
|
|
|
int drag_x, drag_y;
|
2008-11-03 02:51:48 +03:00
|
|
|
int state;
|
2008-12-22 20:14:50 +03:00
|
|
|
int fullscreen;
|
2008-12-12 20:00:02 +03:00
|
|
|
uint32_t grab_device;
|
2008-11-03 02:51:48 +03:00
|
|
|
uint32_t name;
|
|
|
|
int fd;
|
2008-11-08 23:06:01 +03:00
|
|
|
|
|
|
|
struct buffer *buffer;
|
2008-12-08 03:59:11 +03:00
|
|
|
|
|
|
|
window_resize_handler_t resize_handler;
|
|
|
|
window_frame_handler_t frame_handler;
|
|
|
|
window_acknowledge_handler_t acknowledge_handler;
|
2008-12-08 08:01:36 +03:00
|
|
|
window_key_handler_t key_handler;
|
2008-12-08 03:59:11 +03:00
|
|
|
void *user_data;
|
2008-11-03 02:51:48 +03:00
|
|
|
};
|
|
|
|
|
2008-11-09 02:53:37 +03:00
|
|
|
static void
|
|
|
|
rounded_rect(cairo_t *cr, int x0, int y0, int x1, int y1, int radius)
|
|
|
|
{
|
|
|
|
cairo_move_to(cr, x0, y0 + radius);
|
|
|
|
cairo_arc(cr, x0 + radius, y0 + radius, radius, M_PI, 3 * M_PI / 2);
|
|
|
|
cairo_line_to(cr, x1 - radius, y0);
|
|
|
|
cairo_arc(cr, x1 - radius, y0 + radius, radius, 3 * M_PI / 2, 2 * M_PI);
|
|
|
|
cairo_line_to(cr, x1, y1 - radius);
|
|
|
|
cairo_arc(cr, x1 - radius, y1 - radius, radius, 0, M_PI / 2);
|
|
|
|
cairo_line_to(cr, x0 + radius, y1);
|
|
|
|
cairo_arc(cr, x0 + radius, y1 - radius, radius, M_PI / 2, M_PI);
|
|
|
|
cairo_close_path(cr);
|
|
|
|
}
|
|
|
|
|
2008-12-22 20:14:50 +03:00
|
|
|
static void
|
|
|
|
window_draw_decorations(struct window *window)
|
2008-11-03 02:51:48 +03:00
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
cairo_t *cr;
|
2008-11-26 06:40:39 +03:00
|
|
|
int border = 2, radius = 5;
|
2008-11-03 14:59:52 +03:00
|
|
|
cairo_text_extents_t extents;
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_pattern_t *gradient, *outline, *bright, *dim;
|
2008-12-19 01:55:33 +03:00
|
|
|
struct wl_visual *visual;
|
2008-12-22 20:14:50 +03:00
|
|
|
int width, height;
|
2008-11-03 02:51:48 +03:00
|
|
|
|
|
|
|
surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24,
|
2008-12-22 20:14:50 +03:00
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height);
|
2008-11-03 02:51:48 +03:00
|
|
|
|
2008-11-09 02:53:37 +03:00
|
|
|
outline = cairo_pattern_create_rgb(0.1, 0.1, 0.1);
|
2008-11-19 08:49:39 +03:00
|
|
|
bright = cairo_pattern_create_rgb(0.8, 0.8, 0.8);
|
2008-11-09 02:53:37 +03:00
|
|
|
dim = cairo_pattern_create_rgb(0.4, 0.4, 0.4);
|
|
|
|
|
2008-11-03 02:51:48 +03:00
|
|
|
cr = cairo_create(surface);
|
2008-11-09 06:46:30 +03:00
|
|
|
|
2008-12-22 20:14:50 +03:00
|
|
|
width = window->allocation.width - window->margin * 2;
|
|
|
|
height = window->allocation.height - window->margin * 2;
|
|
|
|
|
2008-11-26 06:40:39 +03:00
|
|
|
cairo_translate(cr, window->margin + 7, window->margin + 5);
|
2008-11-09 06:46:30 +03:00
|
|
|
cairo_set_line_width (cr, border);
|
2008-11-19 08:49:39 +03:00
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 0.7);
|
2008-12-22 20:14:50 +03:00
|
|
|
rounded_rect(cr, 0, 0, width, height, radius);
|
2008-11-09 06:46:30 +03:00
|
|
|
cairo_fill(cr);
|
2008-11-18 06:23:55 +03:00
|
|
|
blur_surface(surface, 24 + radius);
|
2008-11-09 06:46:30 +03:00
|
|
|
|
2008-11-19 08:49:39 +03:00
|
|
|
cairo_translate(cr, -7, -5);
|
2008-11-03 02:51:48 +03:00
|
|
|
cairo_set_line_width (cr, border);
|
2008-12-22 20:14:50 +03:00
|
|
|
rounded_rect(cr, 1, 1, width - 1, height - 1, radius);
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_set_source(cr, outline);
|
|
|
|
cairo_stroke(cr);
|
2008-12-22 20:14:50 +03:00
|
|
|
rounded_rect(cr, 2, 2, width - 2, height - 2, radius - 1);
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_set_source(cr, bright);
|
|
|
|
cairo_stroke(cr);
|
2008-12-22 20:14:50 +03:00
|
|
|
rounded_rect(cr, 3, 3, width - 2, height - 2, radius - 1);
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_set_source(cr, dim);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
2008-12-22 20:14:50 +03:00
|
|
|
rounded_rect(cr, 2, 2, width - 2, height - 2, radius - 1);
|
2008-11-09 17:15:46 +03:00
|
|
|
gradient = cairo_pattern_create_linear (0, 0, 0, 100);
|
2008-11-19 08:49:39 +03:00
|
|
|
cairo_pattern_add_color_stop_rgb(gradient, 0, 0.6, 0.6, 0.4);
|
|
|
|
cairo_pattern_add_color_stop_rgb(gradient, 1, 0.8, 0.8, 0.7);
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_set_source(cr, gradient);
|
|
|
|
cairo_fill(cr);
|
|
|
|
cairo_pattern_destroy(gradient);
|
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_move_to(cr, 10, 50);
|
2008-12-22 20:14:50 +03:00
|
|
|
cairo_line_to(cr, width - 10, 50);
|
|
|
|
cairo_line_to(cr, width - 10, height - 10);
|
|
|
|
cairo_line_to(cr, 10, height - 10);
|
2008-11-03 02:51:48 +03:00
|
|
|
cairo_close_path(cr);
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_set_source(cr, dim);
|
|
|
|
cairo_stroke(cr);
|
|
|
|
|
|
|
|
cairo_move_to(cr, 11, 51);
|
2008-12-22 20:14:50 +03:00
|
|
|
cairo_line_to(cr, width - 10, 51);
|
|
|
|
cairo_line_to(cr, width - 10, height - 10);
|
|
|
|
cairo_line_to(cr, 11, height - 10);
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_close_path(cr);
|
|
|
|
cairo_set_source(cr, bright);
|
2008-11-03 02:51:48 +03:00
|
|
|
cairo_stroke(cr);
|
2008-11-03 14:59:52 +03:00
|
|
|
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_set_font_size(cr, 14);
|
2008-12-08 03:59:11 +03:00
|
|
|
cairo_text_extents(cr, window->title, &extents);
|
2008-12-22 20:14:50 +03:00
|
|
|
cairo_move_to(cr, (width - extents.width) / 2, 10 - extents.y_bearing);
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
|
|
|
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
|
|
|
|
cairo_set_line_width (cr, 4);
|
2008-12-08 03:59:11 +03:00
|
|
|
cairo_text_path(cr, window->title);
|
2008-11-09 02:53:37 +03:00
|
|
|
cairo_set_source_rgb(cr, 0.1, 0.1, 0.1);
|
|
|
|
cairo_stroke_preserve(cr);
|
|
|
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
|
|
cairo_fill(cr);
|
2008-11-03 02:51:48 +03:00
|
|
|
cairo_destroy(cr);
|
|
|
|
|
2008-11-26 06:40:39 +03:00
|
|
|
window->buffer = buffer_create_from_cairo_surface(window->fd, surface);
|
2008-11-03 02:51:48 +03:00
|
|
|
cairo_surface_destroy(surface);
|
|
|
|
|
2008-12-19 01:55:33 +03:00
|
|
|
visual = wl_display_get_premultiplied_argb_visual(window->display);
|
2008-11-26 06:40:39 +03:00
|
|
|
wl_surface_attach(window->surface,
|
|
|
|
window->buffer->name,
|
|
|
|
window->buffer->width,
|
|
|
|
window->buffer->height,
|
2008-12-19 01:55:33 +03:00
|
|
|
window->buffer->stride,
|
|
|
|
visual);
|
2008-11-08 23:39:41 +03:00
|
|
|
|
2008-11-29 01:06:06 +03:00
|
|
|
wl_surface_map(window->surface,
|
2008-12-22 20:14:50 +03:00
|
|
|
window->allocation.x - window->margin,
|
|
|
|
window->allocation.y - window->margin,
|
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_draw_fullscreen(struct window *window)
|
|
|
|
{
|
|
|
|
struct wl_visual *visual;
|
|
|
|
int stride = window->allocation.width * 4;
|
|
|
|
|
|
|
|
window->buffer = buffer_create(window->fd,
|
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height,
|
|
|
|
stride);
|
|
|
|
|
|
|
|
visual = wl_display_get_premultiplied_argb_visual(window->display);
|
|
|
|
wl_surface_attach(window->surface,
|
|
|
|
window->buffer->name,
|
|
|
|
window->buffer->width,
|
|
|
|
window->buffer->height,
|
|
|
|
window->buffer->stride,
|
|
|
|
visual);
|
|
|
|
|
|
|
|
wl_surface_map(window->surface,
|
|
|
|
window->allocation.x,
|
|
|
|
window->allocation.y,
|
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_draw(struct window *window)
|
|
|
|
{
|
|
|
|
if (window->fullscreen)
|
|
|
|
window_draw_fullscreen(window);
|
|
|
|
else
|
|
|
|
window_draw_decorations(window);
|
2008-11-26 20:57:31 +03:00
|
|
|
}
|
|
|
|
|
2008-11-03 02:51:48 +03:00
|
|
|
enum window_state {
|
|
|
|
WINDOW_STABLE,
|
|
|
|
WINDOW_MOVING,
|
|
|
|
WINDOW_RESIZING_UPPER_LEFT,
|
|
|
|
WINDOW_RESIZING_UPPER_RIGHT,
|
|
|
|
WINDOW_RESIZING_LOWER_LEFT,
|
|
|
|
WINDOW_RESIZING_LOWER_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum location {
|
|
|
|
LOCATION_INTERIOR,
|
|
|
|
LOCATION_UPPER_LEFT,
|
|
|
|
LOCATION_UPPER_RIGHT,
|
|
|
|
LOCATION_LOWER_LEFT,
|
|
|
|
LOCATION_LOWER_RIGHT,
|
|
|
|
LOCATION_OUTSIDE
|
|
|
|
};
|
|
|
|
|
2008-11-09 02:53:37 +03:00
|
|
|
static void
|
|
|
|
event_handler(struct wl_display *display,
|
2008-11-26 06:40:39 +03:00
|
|
|
uint32_t object, uint32_t opcode,
|
|
|
|
uint32_t size, uint32_t *p, void *data)
|
2008-11-03 02:51:48 +03:00
|
|
|
{
|
|
|
|
struct window *window = data;
|
2008-11-26 06:40:39 +03:00
|
|
|
int location;
|
2008-11-03 02:51:48 +03:00
|
|
|
int grip_size = 16;
|
|
|
|
|
2008-12-16 04:35:24 +03:00
|
|
|
/* FIXME: Object ID 2 is the compositor, for anything else we
|
2008-11-26 06:40:39 +03:00
|
|
|
* assume it's an input device. */
|
2008-12-16 04:35:24 +03:00
|
|
|
if (object == 2 && opcode == 0) {
|
2008-11-29 01:06:06 +03:00
|
|
|
uint32_t key = p[0];
|
|
|
|
|
|
|
|
/* Ignore acknowledge events for window move requests. */
|
|
|
|
if (key != 0)
|
|
|
|
return;
|
|
|
|
|
2008-11-26 06:40:39 +03:00
|
|
|
/* The acknowledge event means that the server
|
2008-11-26 20:57:31 +03:00
|
|
|
* processed our last commit request and we can now
|
2008-11-29 01:06:06 +03:00
|
|
|
* safely free the old window buffer if we resized and
|
|
|
|
* render the next frame into our back buffer.. */
|
|
|
|
|
2008-11-26 20:57:31 +03:00
|
|
|
if (window->buffer != NULL) {
|
2008-11-26 06:40:39 +03:00
|
|
|
buffer_destroy(window->buffer, window->fd);
|
|
|
|
window->buffer = NULL;
|
|
|
|
}
|
2008-12-08 03:59:11 +03:00
|
|
|
if (window->acknowledge_handler)
|
|
|
|
(*window->acknowledge_handler)(window, key,
|
|
|
|
window->user_data);
|
|
|
|
|
2008-12-16 04:35:24 +03:00
|
|
|
} else if (object == 2 && opcode == 1) {
|
2008-11-29 01:06:06 +03:00
|
|
|
/* The frame event means that the previous frame was
|
|
|
|
* composited, and we can now send the request to copy
|
|
|
|
* the frame we've rendered in the mean time into the
|
|
|
|
* servers surface buffer. */
|
2008-12-08 03:59:11 +03:00
|
|
|
if (window->frame_handler)
|
|
|
|
(*window->frame_handler)(window, p[0], p[1],
|
|
|
|
window->user_data);
|
2008-11-26 20:57:31 +03:00
|
|
|
} else if (object == 1) {
|
|
|
|
fprintf(stderr, "unexpected event from display: %d\n",
|
|
|
|
opcode);
|
|
|
|
exit(-1);
|
2008-11-26 06:40:39 +03:00
|
|
|
} else if (opcode == 0) {
|
|
|
|
int x = p[0], y = p[1];
|
|
|
|
|
2008-11-03 02:51:48 +03:00
|
|
|
switch (window->state) {
|
|
|
|
case WINDOW_MOVING:
|
2008-12-22 20:14:50 +03:00
|
|
|
if (window->fullscreen)
|
|
|
|
break;
|
2008-12-12 20:00:02 +03:00
|
|
|
if (window->grab_device != object)
|
|
|
|
break;
|
2008-12-22 20:14:50 +03:00
|
|
|
window->allocation.x = window->drag_x + x;
|
|
|
|
window->allocation.y = window->drag_y + y;
|
2008-11-26 06:40:39 +03:00
|
|
|
wl_surface_map(window->surface,
|
2008-12-22 20:14:50 +03:00
|
|
|
window->allocation.x - window->margin,
|
|
|
|
window->allocation.y - window->margin,
|
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height);
|
2008-12-16 04:35:24 +03:00
|
|
|
wl_compositor_commit(window->compositor, 1);
|
2008-11-03 02:51:48 +03:00
|
|
|
break;
|
|
|
|
case WINDOW_RESIZING_LOWER_RIGHT:
|
2008-12-22 20:14:50 +03:00
|
|
|
if (window->fullscreen)
|
|
|
|
break;
|
2008-12-12 20:00:02 +03:00
|
|
|
if (window->grab_device != object)
|
|
|
|
break;
|
2008-12-22 20:14:50 +03:00
|
|
|
window->allocation.width = window->drag_x + x;
|
|
|
|
window->allocation.height = window->drag_y + y;
|
2008-12-08 03:59:11 +03:00
|
|
|
|
|
|
|
if (window->resize_handler)
|
|
|
|
(*window->resize_handler)(window,
|
|
|
|
window->user_data);
|
2008-12-08 20:59:37 +03:00
|
|
|
|
2008-11-03 02:51:48 +03:00
|
|
|
break;
|
|
|
|
}
|
2008-11-26 06:40:39 +03:00
|
|
|
} else if (opcode == 1) {
|
|
|
|
int button = p[0], state = p[1];
|
2008-12-12 20:00:02 +03:00
|
|
|
int32_t x = p[2], y = p[3];
|
2008-12-22 20:14:50 +03:00
|
|
|
int32_t left = window->allocation.x;
|
|
|
|
int32_t right = window->allocation.x +
|
|
|
|
window->allocation.width - window->margin * 2;
|
|
|
|
int32_t top = window->allocation.y;
|
|
|
|
int32_t bottom = window->allocation.y +
|
|
|
|
window->allocation.height - window->margin * 2;
|
|
|
|
|
|
|
|
if (right - grip_size <= x && x < right &&
|
|
|
|
bottom - grip_size <= y && y < bottom) {
|
2008-11-26 06:40:39 +03:00
|
|
|
location = LOCATION_LOWER_RIGHT;
|
2008-12-22 20:14:50 +03:00
|
|
|
} else if (left <= x && x < right && top <= y && y < bottom) {
|
2008-11-26 06:40:39 +03:00
|
|
|
location = LOCATION_INTERIOR;
|
|
|
|
} else {
|
|
|
|
location = LOCATION_OUTSIDE;
|
|
|
|
}
|
2008-11-03 02:51:48 +03:00
|
|
|
|
2008-12-12 07:18:45 +03:00
|
|
|
if (button == BTN_LEFT && state == 1) {
|
2008-11-26 06:40:39 +03:00
|
|
|
switch (location) {
|
|
|
|
case LOCATION_INTERIOR:
|
2008-12-22 20:14:50 +03:00
|
|
|
window->drag_x = window->allocation.x - x;
|
|
|
|
window->drag_y = window->allocation.y - y;
|
2008-11-26 06:40:39 +03:00
|
|
|
window->state = WINDOW_MOVING;
|
2008-12-12 20:00:02 +03:00
|
|
|
window->grab_device = object;
|
2008-11-26 06:40:39 +03:00
|
|
|
break;
|
|
|
|
case LOCATION_LOWER_RIGHT:
|
2008-12-22 20:14:50 +03:00
|
|
|
window->drag_x = window->allocation.width - x;
|
|
|
|
window->drag_y = window->allocation.height - y;
|
2008-11-26 06:40:39 +03:00
|
|
|
window->state = WINDOW_RESIZING_LOWER_RIGHT;
|
2008-12-12 20:00:02 +03:00
|
|
|
window->grab_device = object;
|
2008-11-26 06:40:39 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
window->state = WINDOW_STABLE;
|
|
|
|
break;
|
|
|
|
}
|
2008-12-12 20:00:02 +03:00
|
|
|
} else if (button == BTN_LEFT &&
|
|
|
|
state == 0 && object == window->grab_device) {
|
2008-11-03 02:51:48 +03:00
|
|
|
window->state = WINDOW_STABLE;
|
|
|
|
}
|
2008-12-08 08:01:36 +03:00
|
|
|
} else if (opcode == 2) {
|
|
|
|
if (window->key_handler)
|
|
|
|
(*window->key_handler)(window, p[0], p[1],
|
|
|
|
window->user_data);
|
2008-11-03 02:51:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-08 03:59:11 +03:00
|
|
|
void
|
|
|
|
window_get_child_rectangle(struct window *window,
|
|
|
|
struct rectangle *rectangle)
|
|
|
|
{
|
2008-12-22 20:14:50 +03:00
|
|
|
if (window->fullscreen) {
|
|
|
|
*rectangle = window->allocation;
|
|
|
|
} else {
|
|
|
|
rectangle->x = window->margin + 10;
|
|
|
|
rectangle->y = window->margin + 50;
|
|
|
|
rectangle->width = window->allocation.width - 20 - window->margin * 2;
|
|
|
|
rectangle->height = window->allocation.height - 60 - window->margin * 2;
|
|
|
|
}
|
2008-12-08 03:59:11 +03:00
|
|
|
}
|
|
|
|
|
2008-12-08 21:50:07 +03:00
|
|
|
void
|
|
|
|
window_set_child_size(struct window *window,
|
|
|
|
struct rectangle *rectangle)
|
|
|
|
{
|
2008-12-22 20:14:50 +03:00
|
|
|
if (!window->fullscreen) {
|
|
|
|
window->allocation.width = rectangle->width + 20 + window->margin * 2;
|
|
|
|
window->allocation.height = rectangle->height + 60 + window->margin * 2;
|
|
|
|
}
|
2008-12-08 21:50:07 +03:00
|
|
|
}
|
|
|
|
|
2008-12-08 03:59:11 +03:00
|
|
|
void
|
|
|
|
window_copy(struct window *window,
|
|
|
|
struct rectangle *rectangle,
|
|
|
|
uint32_t name, uint32_t stride)
|
|
|
|
{
|
|
|
|
wl_surface_copy(window->surface,
|
2008-12-22 20:14:50 +03:00
|
|
|
rectangle->x,
|
|
|
|
rectangle->y,
|
2008-12-08 03:59:11 +03:00
|
|
|
name, stride,
|
2008-12-22 20:14:50 +03:00
|
|
|
0, 0,
|
|
|
|
rectangle->width,
|
|
|
|
rectangle->height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_set_fullscreen(struct window *window, int fullscreen)
|
|
|
|
{
|
|
|
|
window->fullscreen = fullscreen;
|
|
|
|
if (window->fullscreen) {
|
|
|
|
window->saved_allocation = window->allocation;
|
|
|
|
window->allocation.x = 0;
|
|
|
|
window->allocation.y = 0;
|
|
|
|
wl_display_get_geometry(window->display,
|
|
|
|
&window->allocation.width,
|
|
|
|
&window->allocation.height);
|
|
|
|
} else {
|
|
|
|
window->allocation = window->saved_allocation;
|
|
|
|
}
|
2008-12-08 03:59:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_set_resize_handler(struct window *window,
|
|
|
|
window_resize_handler_t handler, void *data)
|
|
|
|
{
|
|
|
|
window->resize_handler = handler;
|
|
|
|
window->user_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_set_frame_handler(struct window *window,
|
|
|
|
window_frame_handler_t handler, void *data)
|
|
|
|
{
|
|
|
|
window->frame_handler = handler;
|
|
|
|
window->user_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_set_acknowledge_handler(struct window *window,
|
|
|
|
window_acknowledge_handler_t handler, void *data)
|
|
|
|
{
|
|
|
|
window->acknowledge_handler = handler;
|
|
|
|
window->user_data = data;
|
|
|
|
}
|
|
|
|
|
2008-12-08 08:01:36 +03:00
|
|
|
void
|
|
|
|
window_set_key_handler(struct window *window,
|
|
|
|
window_key_handler_t handler, void *data)
|
|
|
|
{
|
|
|
|
window->key_handler = handler;
|
|
|
|
window->user_data = data;
|
|
|
|
}
|
|
|
|
|
2008-12-08 03:59:11 +03:00
|
|
|
struct window *
|
|
|
|
window_create(struct wl_display *display, int fd,
|
|
|
|
const char *title,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
2008-11-03 23:31:30 +03:00
|
|
|
{
|
2008-11-07 23:54:48 +03:00
|
|
|
struct window *window;
|
|
|
|
|
|
|
|
window = malloc(sizeof *window);
|
|
|
|
if (window == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2008-11-08 23:06:01 +03:00
|
|
|
memset(window, 0, sizeof *window);
|
2008-11-26 06:40:39 +03:00
|
|
|
window->display = display;
|
2008-12-08 03:59:11 +03:00
|
|
|
window->title = strdup(title);
|
2008-12-16 04:35:24 +03:00
|
|
|
window->compositor = wl_display_get_compositor(display);
|
|
|
|
window->surface = wl_compositor_create_surface(window->compositor);
|
2008-12-22 20:14:50 +03:00
|
|
|
window->allocation.x = x;
|
|
|
|
window->allocation.y = y;
|
|
|
|
window->allocation.width = width;
|
|
|
|
window->allocation.height = height;
|
|
|
|
window->saved_allocation = window->allocation;
|
2008-11-26 06:40:39 +03:00
|
|
|
window->margin = 16;
|
2008-11-07 23:54:48 +03:00
|
|
|
window->state = WINDOW_STABLE;
|
|
|
|
window->fd = fd;
|
|
|
|
|
|
|
|
wl_display_set_event_handler(display, event_handler, window);
|
|
|
|
|
2008-12-08 03:59:11 +03:00
|
|
|
return window;
|
2008-11-03 02:51:48 +03:00
|
|
|
}
|