2008-12-02 20:15:01 +00: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.
|
|
|
|
*/
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
#include "../config.h"
|
|
|
|
|
2008-11-02 23:51:48 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <math.h>
|
2011-09-27 19:57:31 +00:00
|
|
|
#include <assert.h>
|
2008-11-02 23:51:48 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <cairo.h>
|
2008-11-07 20:54:48 +00:00
|
|
|
#include <glib.h>
|
2010-08-16 21:47:07 +00:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2010-10-25 15:40:03 +00:00
|
|
|
#include <sys/mman.h>
|
2011-09-14 21:33:48 +00:00
|
|
|
#include <sys/epoll.h>
|
2010-06-08 18:08:30 +00:00
|
|
|
|
2011-02-09 15:51:15 +00:00
|
|
|
#include <wayland-egl.h>
|
|
|
|
|
2010-06-08 18:08:30 +00:00
|
|
|
#include <GL/gl.h>
|
|
|
|
#include <EGL/egl.h>
|
|
|
|
#include <EGL/eglext.h>
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2011-01-14 22:41:33 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2010-06-08 18:08:30 +00:00
|
|
|
#include <cairo-gl.h>
|
2010-10-25 15:40:03 +00:00
|
|
|
#endif
|
2008-11-02 23:51:48 +00:00
|
|
|
|
2010-06-25 20:50:05 +00:00
|
|
|
#include <X11/extensions/XKBcommon.h>
|
|
|
|
|
2008-12-12 04:18:45 +00:00
|
|
|
#include <linux/input.h>
|
2011-11-22 12:18:50 +00:00
|
|
|
#include <wayland-client.h>
|
2010-08-16 20:17:42 +00:00
|
|
|
#include "cairo-util.h"
|
2008-11-09 03:46:30 +00:00
|
|
|
|
2008-12-08 00:59:11 +00:00
|
|
|
#include "window.h"
|
2008-11-03 20:31:30 +00:00
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
struct display {
|
2008-11-26 03:40:39 +00:00
|
|
|
struct wl_display *display;
|
2008-12-16 01:35:24 +00:00
|
|
|
struct wl_compositor *compositor;
|
2010-08-05 02:44:55 +00:00
|
|
|
struct wl_shell *shell;
|
2010-10-25 15:40:03 +00:00
|
|
|
struct wl_shm *shm;
|
2011-10-28 16:26:06 +00:00
|
|
|
struct wl_data_device_manager *data_device_manager;
|
2010-06-08 18:08:30 +00:00
|
|
|
EGLDisplay dpy;
|
2011-08-31 20:21:38 +00:00
|
|
|
EGLConfig rgb_config;
|
2011-09-01 08:36:16 +00:00
|
|
|
EGLConfig premultiplied_argb_config;
|
2011-09-27 19:57:31 +00:00
|
|
|
EGLContext rgb_ctx;
|
|
|
|
EGLContext argb_ctx;
|
|
|
|
cairo_device_t *rgb_device;
|
|
|
|
cairo_device_t *argb_device;
|
2011-09-14 21:33:48 +00:00
|
|
|
|
|
|
|
int display_fd;
|
|
|
|
uint32_t mask;
|
|
|
|
struct task display_task;
|
|
|
|
|
|
|
|
int epoll_fd;
|
|
|
|
struct wl_list deferred_list;
|
|
|
|
|
2011-12-15 08:14:07 +00:00
|
|
|
int running;
|
|
|
|
|
2010-06-09 00:34:11 +00:00
|
|
|
struct wl_list window_list;
|
2010-07-20 21:06:19 +00:00
|
|
|
struct wl_list input_list;
|
2011-11-26 22:27:37 +00:00
|
|
|
struct wl_list output_list;
|
2010-06-15 21:16:35 +00:00
|
|
|
cairo_surface_t *active_frame, *inactive_frame, *shadow;
|
2010-07-02 19:12:02 +00:00
|
|
|
struct xkb_desc *xkb;
|
2010-08-18 19:28:04 +00:00
|
|
|
cairo_surface_t **pointer_surfaces;
|
2010-09-03 00:22:42 +00:00
|
|
|
|
2011-02-09 15:57:44 +00:00
|
|
|
PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d;
|
|
|
|
PFNEGLCREATEIMAGEKHRPROC create_image;
|
|
|
|
PFNEGLDESTROYIMAGEKHRPROC destroy_image;
|
2011-11-30 08:52:38 +00:00
|
|
|
|
|
|
|
display_output_handler_t output_configure_handler;
|
|
|
|
|
|
|
|
void *user_data;
|
2009-01-27 04:42:46 +00:00
|
|
|
};
|
|
|
|
|
2011-09-06 22:02:34 +00:00
|
|
|
enum {
|
|
|
|
TYPE_TOPLEVEL,
|
2011-09-08 20:56:38 +00:00
|
|
|
TYPE_FULLSCREEN,
|
2011-09-06 22:02:34 +00:00
|
|
|
TYPE_TRANSIENT,
|
2011-12-19 20:40:10 +00:00
|
|
|
TYPE_MENU,
|
2011-09-06 22:02:34 +00:00
|
|
|
TYPE_CUSTOM
|
|
|
|
};
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
struct window {
|
|
|
|
struct display *display;
|
2011-01-21 23:03:15 +00:00
|
|
|
struct window *parent;
|
2008-11-02 23:51:48 +00:00
|
|
|
struct wl_surface *surface;
|
2011-11-25 10:09:16 +00:00
|
|
|
struct wl_shell_surface *shell_surface;
|
2011-01-25 17:45:37 +00:00
|
|
|
char *title;
|
2010-12-17 14:53:12 +00:00
|
|
|
struct rectangle allocation, saved_allocation, server_allocation;
|
2011-01-21 23:03:15 +00:00
|
|
|
int x, y;
|
2010-08-05 02:44:55 +00:00
|
|
|
int resize_edges;
|
2010-06-15 03:52:50 +00:00
|
|
|
int redraw_scheduled;
|
2011-09-14 21:33:48 +00:00
|
|
|
struct task redraw_task;
|
2008-12-08 00:59:11 +00:00
|
|
|
int minimum_width, minimum_height;
|
2008-11-26 03:40:39 +00:00
|
|
|
int margin;
|
2011-09-06 22:02:34 +00:00
|
|
|
int type;
|
2010-06-08 18:08:30 +00:00
|
|
|
int decoration;
|
2011-05-13 17:45:17 +00:00
|
|
|
int transparent;
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input *keyboard_device;
|
2008-11-02 23:51:48 +00:00
|
|
|
uint32_t name;
|
2010-10-25 15:40:03 +00:00
|
|
|
enum window_buffer_type buffer_type;
|
2008-11-08 20:06:01 +00:00
|
|
|
|
2009-12-16 19:43:37 +00:00
|
|
|
cairo_surface_t *cairo_surface, *pending_surface;
|
2008-12-08 00:59:11 +00:00
|
|
|
|
|
|
|
window_resize_handler_t resize_handler;
|
2010-06-15 03:52:50 +00:00
|
|
|
window_redraw_handler_t redraw_handler;
|
2008-12-08 05:01:36 +00:00
|
|
|
window_key_handler_t key_handler;
|
2010-08-18 19:28:04 +00:00
|
|
|
window_button_handler_t button_handler;
|
2009-02-23 04:01:35 +00:00
|
|
|
window_keyboard_focus_handler_t keyboard_focus_handler;
|
2010-08-18 19:28:04 +00:00
|
|
|
window_motion_handler_t motion_handler;
|
2011-09-06 18:33:52 +00:00
|
|
|
window_enter_handler_t enter_handler;
|
|
|
|
window_leave_handler_t leave_handler;
|
2011-09-21 01:43:54 +00:00
|
|
|
window_item_focus_handler_t item_focus_handler;
|
2011-10-28 16:26:06 +00:00
|
|
|
window_data_handler_t data_handler;
|
|
|
|
window_drop_handler_t drop_handler;
|
2011-09-21 01:43:54 +00:00
|
|
|
|
|
|
|
struct wl_list item_list;
|
|
|
|
struct item *focus_item;
|
|
|
|
uint32_t item_grab_button;
|
2010-06-08 18:08:30 +00:00
|
|
|
|
2008-12-08 00:59:11 +00:00
|
|
|
void *user_data;
|
2010-06-09 00:34:11 +00:00
|
|
|
struct wl_list link;
|
2008-11-02 23:51:48 +00:00
|
|
|
};
|
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
struct item {
|
|
|
|
struct wl_list link;
|
|
|
|
struct rectangle allocation;
|
|
|
|
void *user_data;
|
|
|
|
};
|
|
|
|
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input {
|
|
|
|
struct display *display;
|
|
|
|
struct wl_input_device *input_device;
|
|
|
|
struct window *pointer_focus;
|
|
|
|
struct window *keyboard_focus;
|
2010-09-08 01:50:06 +00:00
|
|
|
uint32_t current_pointer_image;
|
2010-07-20 21:06:19 +00:00
|
|
|
uint32_t modifiers;
|
|
|
|
int32_t x, y, sx, sy;
|
|
|
|
struct wl_list link;
|
2011-10-28 16:26:06 +00:00
|
|
|
|
|
|
|
struct wl_data_device *data_device;
|
|
|
|
struct data_offer *drag_offer;
|
|
|
|
struct data_offer *selection_offer;
|
2010-07-20 21:06:19 +00:00
|
|
|
};
|
|
|
|
|
2011-11-26 22:27:37 +00:00
|
|
|
struct output {
|
|
|
|
struct display *display;
|
|
|
|
struct wl_output *output;
|
|
|
|
struct rectangle allocation;
|
|
|
|
struct wl_list link;
|
2011-11-30 08:52:38 +00:00
|
|
|
|
|
|
|
display_output_handler_t destroy_handler;
|
|
|
|
void *user_data;
|
2011-11-26 22:27:37 +00:00
|
|
|
};
|
|
|
|
|
2010-09-08 01:50:06 +00:00
|
|
|
enum {
|
|
|
|
POINTER_DEFAULT = 100,
|
|
|
|
POINTER_UNSET
|
|
|
|
};
|
|
|
|
|
2010-12-17 14:53:12 +00:00
|
|
|
enum window_location {
|
|
|
|
WINDOW_INTERIOR = 0,
|
|
|
|
WINDOW_RESIZING_TOP = 1,
|
|
|
|
WINDOW_RESIZING_BOTTOM = 2,
|
|
|
|
WINDOW_RESIZING_LEFT = 4,
|
|
|
|
WINDOW_RESIZING_TOP_LEFT = 5,
|
|
|
|
WINDOW_RESIZING_BOTTOM_LEFT = 6,
|
|
|
|
WINDOW_RESIZING_RIGHT = 8,
|
|
|
|
WINDOW_RESIZING_TOP_RIGHT = 9,
|
|
|
|
WINDOW_RESIZING_BOTTOM_RIGHT = 10,
|
|
|
|
WINDOW_RESIZING_MASK = 15,
|
|
|
|
WINDOW_EXTERIOR = 16,
|
|
|
|
WINDOW_TITLEBAR = 17,
|
|
|
|
WINDOW_CLIENT_AREA = 18,
|
|
|
|
};
|
|
|
|
|
2010-08-30 01:33:39 +00:00
|
|
|
const char *option_xkb_layout = "us";
|
|
|
|
const char *option_xkb_variant = "";
|
|
|
|
const char *option_xkb_options = "";
|
|
|
|
|
|
|
|
static const GOptionEntry xkb_option_entries[] = {
|
|
|
|
{ "xkb-layout", 0, 0, G_OPTION_ARG_STRING,
|
|
|
|
&option_xkb_layout, "XKB Layout" },
|
|
|
|
{ "xkb-variant", 0, 0, G_OPTION_ARG_STRING,
|
|
|
|
&option_xkb_variant, "XKB Variant" },
|
|
|
|
{ "xkb-options", 0, 0, G_OPTION_ARG_STRING,
|
|
|
|
&option_xkb_options, "XKB Options" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
static const cairo_user_data_key_t surface_data_key;
|
|
|
|
struct surface_data {
|
|
|
|
struct wl_buffer *buffer;
|
|
|
|
};
|
|
|
|
|
2010-11-29 13:13:35 +00:00
|
|
|
#define MULT(_d,c,a,t) \
|
|
|
|
do { t = c * a + 0x7f; _d = ((t >> 8) + t) >> 8; } while (0)
|
|
|
|
|
2011-01-14 22:41:33 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2011-02-10 11:04:30 +00:00
|
|
|
struct egl_window_surface_data {
|
|
|
|
struct display *display;
|
|
|
|
struct wl_surface *surface;
|
|
|
|
struct wl_egl_window *window;
|
|
|
|
EGLSurface surf;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
egl_window_surface_data_destroy(void *p)
|
|
|
|
{
|
|
|
|
struct egl_window_surface_data *data = p;
|
|
|
|
struct display *d = data->display;
|
|
|
|
|
|
|
|
eglDestroySurface(d->dpy, data->surf);
|
|
|
|
wl_egl_window_destroy(data->window);
|
|
|
|
data->surface = NULL;
|
|
|
|
|
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
|
|
|
display_create_egl_window_surface(struct display *display,
|
|
|
|
struct wl_surface *surface,
|
2011-08-31 20:21:38 +00:00
|
|
|
uint32_t flags,
|
2011-02-10 11:04:30 +00:00
|
|
|
struct rectangle *rectangle)
|
|
|
|
{
|
|
|
|
cairo_surface_t *cairo_surface;
|
|
|
|
struct egl_window_surface_data *data;
|
2011-08-31 20:21:38 +00:00
|
|
|
EGLConfig config;
|
|
|
|
const EGLint *attribs;
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_t *device;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2011-08-31 20:21:38 +00:00
|
|
|
static const EGLint premul_attribs[] = {
|
|
|
|
EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_PRE,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2011-02-10 11:04:30 +00:00
|
|
|
data = malloc(sizeof *data);
|
|
|
|
if (data == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
data->display = display;
|
|
|
|
data->surface = surface;
|
|
|
|
|
2011-08-31 20:21:38 +00:00
|
|
|
if (flags & SURFACE_OPAQUE) {
|
|
|
|
config = display->rgb_config;
|
2011-09-27 19:57:31 +00:00
|
|
|
device = display->rgb_device;
|
2011-09-01 08:36:16 +00:00
|
|
|
attribs = NULL;
|
2011-08-31 20:21:38 +00:00
|
|
|
} else {
|
|
|
|
config = display->premultiplied_argb_config;
|
2011-09-27 19:57:31 +00:00
|
|
|
device = display->argb_device;
|
2011-08-31 20:21:38 +00:00
|
|
|
attribs = premul_attribs;
|
|
|
|
}
|
|
|
|
|
2011-04-14 18:44:58 +00:00
|
|
|
data->window = wl_egl_window_create(surface,
|
2011-02-10 11:04:30 +00:00
|
|
|
rectangle->width,
|
2011-08-31 20:21:38 +00:00
|
|
|
rectangle->height);
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2011-08-31 20:21:38 +00:00
|
|
|
data->surf = eglCreateWindowSurface(display->dpy, config,
|
|
|
|
data->window, attribs);
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_surface = cairo_gl_surface_create_for_egl(device,
|
2011-02-10 11:04:30 +00:00
|
|
|
data->surf,
|
|
|
|
rectangle->width,
|
|
|
|
rectangle->height);
|
|
|
|
|
|
|
|
cairo_surface_set_user_data(cairo_surface, &surface_data_key,
|
|
|
|
data, egl_window_surface_data_destroy);
|
|
|
|
|
|
|
|
return cairo_surface;
|
|
|
|
}
|
|
|
|
|
2011-02-04 19:11:33 +00:00
|
|
|
struct egl_image_surface_data {
|
2010-10-25 15:40:03 +00:00
|
|
|
struct surface_data data;
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_t *device;
|
2010-10-25 15:40:03 +00:00
|
|
|
EGLImageKHR image;
|
|
|
|
GLuint texture;
|
2010-10-29 07:20:17 +00:00
|
|
|
struct display *display;
|
2011-02-04 19:11:33 +00:00
|
|
|
struct wl_egl_pixmap *pixmap;
|
2010-10-25 15:40:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2011-02-04 19:11:33 +00:00
|
|
|
egl_image_surface_data_destroy(void *p)
|
2010-08-16 21:47:07 +00:00
|
|
|
{
|
2011-02-04 19:11:33 +00:00
|
|
|
struct egl_image_surface_data *data = p;
|
2010-10-29 07:20:17 +00:00
|
|
|
struct display *d = data->display;
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_acquire(data->device);
|
2010-10-25 15:40:03 +00:00
|
|
|
glDeleteTextures(1, &data->texture);
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_release(data->device);
|
2010-10-29 07:20:17 +00:00
|
|
|
|
2011-02-09 15:57:44 +00:00
|
|
|
d->destroy_image(d->dpy, data->image);
|
2010-10-25 15:40:03 +00:00
|
|
|
wl_buffer_destroy(data->data.buffer);
|
2011-02-07 15:30:38 +00:00
|
|
|
wl_egl_pixmap_destroy(data->pixmap);
|
2011-02-04 19:11:33 +00:00
|
|
|
free(p);
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
2010-11-08 20:45:55 +00:00
|
|
|
EGLImageKHR
|
2011-02-04 19:11:33 +00:00
|
|
|
display_get_image_for_egl_image_surface(struct display *display,
|
|
|
|
cairo_surface_t *surface)
|
2010-11-08 20:45:55 +00:00
|
|
|
{
|
2011-02-04 19:11:33 +00:00
|
|
|
struct egl_image_surface_data *data;
|
2010-11-08 20:45:55 +00:00
|
|
|
|
|
|
|
data = cairo_surface_get_user_data (surface, &surface_data_key);
|
|
|
|
|
|
|
|
return data->image;
|
|
|
|
}
|
|
|
|
|
2010-12-01 14:50:16 +00:00
|
|
|
static cairo_surface_t *
|
2011-02-04 19:11:33 +00:00
|
|
|
display_create_egl_image_surface(struct display *display,
|
2011-08-31 20:21:38 +00:00
|
|
|
uint32_t flags,
|
2011-02-04 19:11:33 +00:00
|
|
|
struct rectangle *rectangle)
|
2010-10-25 15:40:03 +00:00
|
|
|
{
|
2011-02-04 19:11:33 +00:00
|
|
|
struct egl_image_surface_data *data;
|
2010-10-25 15:40:03 +00:00
|
|
|
EGLDisplay dpy = display->dpy;
|
|
|
|
cairo_surface_t *surface;
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_content_t content;
|
2010-10-25 15:40:03 +00:00
|
|
|
|
|
|
|
data = malloc(sizeof *data);
|
|
|
|
if (data == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2010-10-29 07:20:17 +00:00
|
|
|
data->display = display;
|
|
|
|
|
2011-04-14 18:44:58 +00:00
|
|
|
data->pixmap = wl_egl_pixmap_create(rectangle->width,
|
2011-08-31 20:21:38 +00:00
|
|
|
rectangle->height, 0);
|
2011-02-04 19:11:33 +00:00
|
|
|
if (data->pixmap == NULL) {
|
|
|
|
free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-10-29 07:20:17 +00:00
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
if (flags & SURFACE_OPAQUE) {
|
|
|
|
data->device = display->rgb_device;
|
|
|
|
content = CAIRO_CONTENT_COLOR;
|
|
|
|
} else {
|
|
|
|
data->device = display->argb_device;
|
|
|
|
content = CAIRO_CONTENT_COLOR_ALPHA;
|
|
|
|
}
|
2011-08-31 20:21:38 +00:00
|
|
|
|
2011-02-09 15:57:44 +00:00
|
|
|
data->image = display->create_image(dpy, NULL,
|
|
|
|
EGL_NATIVE_PIXMAP_KHR,
|
|
|
|
(EGLClientBuffer) data->pixmap,
|
|
|
|
NULL);
|
2011-02-01 18:51:47 +00:00
|
|
|
if (data->image == EGL_NO_IMAGE_KHR) {
|
2011-02-07 15:30:38 +00:00
|
|
|
wl_egl_pixmap_destroy(data->pixmap);
|
2011-02-01 18:51:47 +00:00
|
|
|
free(data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-04 19:11:33 +00:00
|
|
|
data->data.buffer =
|
2011-04-14 18:44:58 +00:00
|
|
|
wl_egl_pixmap_create_buffer(data->pixmap);
|
2011-02-04 19:11:33 +00:00
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_acquire(data->device);
|
2010-10-25 15:40:03 +00:00
|
|
|
glGenTextures(1, &data->texture);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, data->texture);
|
2011-02-09 15:57:44 +00:00
|
|
|
display->image_target_texture_2d(GL_TEXTURE_2D, data->image);
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_release(data->device);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
surface = cairo_gl_surface_create_for_texture(data->device,
|
|
|
|
content,
|
2010-10-25 15:40:03 +00:00
|
|
|
data->texture,
|
|
|
|
rectangle->width,
|
|
|
|
rectangle->height);
|
|
|
|
|
|
|
|
cairo_surface_set_user_data (surface, &surface_data_key,
|
2011-02-04 19:11:33 +00:00
|
|
|
data, egl_image_surface_data_destroy);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2010-12-01 14:50:16 +00:00
|
|
|
static cairo_surface_t *
|
2011-02-04 19:11:33 +00:00
|
|
|
display_create_egl_image_surface_from_file(struct display *display,
|
|
|
|
const char *filename,
|
|
|
|
struct rectangle *rect)
|
2010-10-25 15:40:03 +00:00
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
2010-08-16 21:47:07 +00:00
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GError *error = NULL;
|
2010-08-18 19:28:04 +00:00
|
|
|
int stride, i;
|
|
|
|
unsigned char *pixels, *p, *end;
|
2011-02-04 19:11:33 +00:00
|
|
|
struct egl_image_surface_data *data;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
|
2010-10-25 15:40:03 +00:00
|
|
|
rect->width, rect->height,
|
2010-08-16 21:47:07 +00:00
|
|
|
FALSE, &error);
|
|
|
|
if (error != NULL)
|
2010-10-25 15:40:03 +00:00
|
|
|
return NULL;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
if (!gdk_pixbuf_get_has_alpha(pixbuf) ||
|
|
|
|
gdk_pixbuf_get_n_channels(pixbuf) != 4) {
|
2011-01-25 20:00:56 +00:00
|
|
|
g_object_unref(pixbuf);
|
2010-10-25 15:40:03 +00:00
|
|
|
return NULL;
|
2010-08-18 19:28:04 +00:00
|
|
|
}
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
|
|
|
|
stride = gdk_pixbuf_get_rowstride(pixbuf);
|
|
|
|
pixels = gdk_pixbuf_get_pixels(pixbuf);
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
for (i = 0; i < rect->height; i++) {
|
2010-08-18 19:28:04 +00:00
|
|
|
p = pixels + i * stride;
|
2010-10-25 15:40:03 +00:00
|
|
|
end = p + rect->width * 4;
|
2010-08-18 19:28:04 +00:00
|
|
|
while (p < end) {
|
|
|
|
unsigned int t;
|
|
|
|
|
|
|
|
MULT(p[0], p[0], p[3], t);
|
|
|
|
MULT(p[1], p[1], p[3], t);
|
|
|
|
MULT(p[2], p[2], p[3], t);
|
|
|
|
p += 4;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2011-09-01 08:36:16 +00:00
|
|
|
surface = display_create_egl_image_surface(display, 0, rect);
|
2011-02-01 18:51:47 +00:00
|
|
|
if (surface == NULL) {
|
|
|
|
g_object_unref(pixbuf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-29 07:20:17 +00:00
|
|
|
data = cairo_surface_get_user_data(surface, &surface_data_key);
|
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_acquire(display->argb_device);
|
2010-10-29 07:20:17 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, data->texture);
|
2010-10-29 07:20:16 +00:00
|
|
|
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, rect->width, rect->height,
|
|
|
|
GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_release(display->argb_device);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2011-01-25 20:00:56 +00:00
|
|
|
g_object_unref(pixbuf);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct wl_buffer *
|
|
|
|
display_get_buffer_for_surface(struct display *display,
|
|
|
|
cairo_surface_t *surface)
|
|
|
|
{
|
|
|
|
struct surface_data *data;
|
|
|
|
|
|
|
|
data = cairo_surface_get_user_data (surface, &surface_data_key);
|
|
|
|
|
|
|
|
return data->buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct shm_surface_data {
|
|
|
|
struct surface_data data;
|
|
|
|
void *map;
|
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
2010-12-01 14:50:16 +00:00
|
|
|
static void
|
2010-10-25 15:40:03 +00:00
|
|
|
shm_surface_data_destroy(void *p)
|
|
|
|
{
|
|
|
|
struct shm_surface_data *data = p;
|
|
|
|
|
|
|
|
wl_buffer_destroy(data->data.buffer);
|
|
|
|
munmap(data->map, data->length);
|
|
|
|
}
|
|
|
|
|
2010-12-01 14:50:16 +00:00
|
|
|
static cairo_surface_t *
|
2010-10-25 15:40:03 +00:00
|
|
|
display_create_shm_surface(struct display *display,
|
2011-05-13 17:45:17 +00:00
|
|
|
struct rectangle *rectangle, uint32_t flags)
|
2010-10-25 15:40:03 +00:00
|
|
|
{
|
|
|
|
struct shm_surface_data *data;
|
2011-08-31 20:21:38 +00:00
|
|
|
uint32_t format;
|
2011-05-13 17:45:17 +00:00
|
|
|
cairo_surface_t *surface;
|
2010-11-19 20:15:36 +00:00
|
|
|
int stride, fd;
|
2010-10-25 15:40:03 +00:00
|
|
|
char filename[] = "/tmp/wayland-shm-XXXXXX";
|
|
|
|
|
|
|
|
data = malloc(sizeof *data);
|
|
|
|
if (data == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
|
|
|
|
rectangle->width);
|
|
|
|
data->length = stride * rectangle->height;
|
|
|
|
fd = mkstemp(filename);
|
|
|
|
if (fd < 0) {
|
2011-02-01 18:48:46 +00:00
|
|
|
fprintf(stderr, "open %s failed: %m\n", filename);
|
2010-10-25 15:40:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (ftruncate(fd, data->length) < 0) {
|
2011-02-01 18:48:46 +00:00
|
|
|
fprintf(stderr, "ftruncate failed: %m\n");
|
2010-10-25 15:40:03 +00:00
|
|
|
close(fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
data->map = mmap(NULL, data->length,
|
|
|
|
PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
unlink(filename);
|
|
|
|
|
|
|
|
if (data->map == MAP_FAILED) {
|
2011-02-01 18:48:46 +00:00
|
|
|
fprintf(stderr, "mmap failed: %m\n");
|
2010-10-25 15:40:03 +00:00
|
|
|
close(fd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
surface = cairo_image_surface_create_for_data (data->map,
|
|
|
|
CAIRO_FORMAT_ARGB32,
|
|
|
|
rectangle->width,
|
|
|
|
rectangle->height,
|
|
|
|
stride);
|
|
|
|
|
|
|
|
cairo_surface_set_user_data (surface, &surface_data_key,
|
|
|
|
data, shm_surface_data_destroy);
|
|
|
|
|
2011-05-13 17:45:17 +00:00
|
|
|
if (flags & SURFACE_OPAQUE)
|
2011-08-31 20:21:38 +00:00
|
|
|
format = WL_SHM_FORMAT_XRGB32;
|
2011-05-13 17:45:17 +00:00
|
|
|
else
|
2011-08-31 20:21:38 +00:00
|
|
|
format = WL_SHM_FORMAT_PREMULTIPLIED_ARGB32;
|
2011-05-13 17:45:17 +00:00
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
data->data.buffer = wl_shm_create_buffer(display->shm,
|
|
|
|
fd,
|
|
|
|
rectangle->width,
|
|
|
|
rectangle->height,
|
2011-08-31 20:21:38 +00:00
|
|
|
stride, format);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2010-12-01 14:50:16 +00:00
|
|
|
static cairo_surface_t *
|
2010-10-25 15:40:03 +00:00
|
|
|
display_create_shm_surface_from_file(struct display *display,
|
|
|
|
const char *filename,
|
|
|
|
struct rectangle *rect)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
GdkPixbuf *pixbuf;
|
|
|
|
GError *error = NULL;
|
|
|
|
int stride, i;
|
|
|
|
unsigned char *pixels, *p, *end, *dest_data;
|
|
|
|
int dest_stride;
|
|
|
|
uint32_t *d;
|
|
|
|
|
|
|
|
pixbuf = gdk_pixbuf_new_from_file_at_scale(filename,
|
|
|
|
rect->width, rect->height,
|
|
|
|
FALSE, &error);
|
|
|
|
if (error != NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!gdk_pixbuf_get_has_alpha(pixbuf) ||
|
|
|
|
gdk_pixbuf_get_n_channels(pixbuf) != 4) {
|
2011-01-25 20:00:56 +00:00
|
|
|
g_object_unref(pixbuf);
|
2010-10-25 15:40:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
stride = gdk_pixbuf_get_rowstride(pixbuf);
|
|
|
|
pixels = gdk_pixbuf_get_pixels(pixbuf);
|
|
|
|
|
2011-05-13 17:45:17 +00:00
|
|
|
surface = display_create_shm_surface(display, rect, 0);
|
2011-02-01 18:51:47 +00:00
|
|
|
if (surface == NULL) {
|
|
|
|
g_object_unref(pixbuf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
dest_data = cairo_image_surface_get_data (surface);
|
|
|
|
dest_stride = cairo_image_surface_get_stride (surface);
|
|
|
|
|
|
|
|
for (i = 0; i < rect->height; i++) {
|
|
|
|
d = (uint32_t *) (dest_data + i * dest_stride);
|
|
|
|
p = pixels + i * stride;
|
|
|
|
end = p + rect->width * 4;
|
|
|
|
while (p < end) {
|
|
|
|
unsigned int t;
|
|
|
|
unsigned char a, r, g, b;
|
|
|
|
|
|
|
|
a = p[3];
|
|
|
|
MULT(r, p[0], a, t);
|
|
|
|
MULT(g, p[1], a, t);
|
|
|
|
MULT(b, p[2], a, t);
|
|
|
|
p += 4;
|
|
|
|
*d++ = (a << 24) | (r << 16) | (g << 8) | b;
|
|
|
|
}
|
|
|
|
}
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2011-01-25 20:00:56 +00:00
|
|
|
g_object_unref(pixbuf);
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2011-02-01 18:51:47 +00:00
|
|
|
static int
|
|
|
|
check_size(struct rectangle *rect)
|
|
|
|
{
|
|
|
|
if (rect->width && rect->height)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fprintf(stderr, "tried to create surface of "
|
|
|
|
"width: %d, height: %d\n", rect->width, rect->height);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
cairo_surface_t *
|
|
|
|
display_create_surface(struct display *display,
|
2011-02-10 11:04:30 +00:00
|
|
|
struct wl_surface *surface,
|
2011-05-13 17:45:17 +00:00
|
|
|
struct rectangle *rectangle,
|
|
|
|
uint32_t flags)
|
2010-10-25 15:40:03 +00:00
|
|
|
{
|
2011-02-01 18:51:47 +00:00
|
|
|
if (check_size(rectangle) < 0)
|
|
|
|
return NULL;
|
2011-01-14 22:41:33 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-02-04 19:11:33 +00:00
|
|
|
if (display->dpy) {
|
2011-02-10 11:04:30 +00:00
|
|
|
if (surface)
|
|
|
|
return display_create_egl_window_surface(display,
|
|
|
|
surface,
|
2011-08-31 20:21:38 +00:00
|
|
|
flags,
|
2011-02-10 11:04:30 +00:00
|
|
|
rectangle);
|
|
|
|
else
|
|
|
|
return display_create_egl_image_surface(display,
|
2011-08-31 20:21:38 +00:00
|
|
|
flags,
|
2011-02-10 11:04:30 +00:00
|
|
|
rectangle);
|
2010-12-06 14:18:12 +00:00
|
|
|
}
|
2010-10-25 15:40:03 +00:00
|
|
|
#endif
|
2011-05-13 17:45:17 +00:00
|
|
|
return display_create_shm_surface(display, rectangle, flags);
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 14:50:16 +00:00
|
|
|
static cairo_surface_t *
|
2010-10-25 15:40:03 +00:00
|
|
|
display_create_surface_from_file(struct display *display,
|
|
|
|
const char *filename,
|
|
|
|
struct rectangle *rectangle)
|
|
|
|
{
|
2011-02-01 18:51:47 +00:00
|
|
|
if (check_size(rectangle) < 0)
|
|
|
|
return NULL;
|
2011-01-14 22:41:33 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-02-04 19:11:33 +00:00
|
|
|
if (display->dpy) {
|
|
|
|
return display_create_egl_image_surface_from_file(display,
|
|
|
|
filename,
|
|
|
|
rectangle);
|
2010-12-06 14:18:12 +00:00
|
|
|
}
|
2010-10-25 15:40:03 +00:00
|
|
|
#endif
|
2010-12-06 14:18:12 +00:00
|
|
|
return display_create_shm_surface_from_file(display, filename, rectangle);
|
2010-08-16 21:47:07 +00:00
|
|
|
}
|
2010-12-06 14:18:12 +00:00
|
|
|
static const struct {
|
2010-08-16 21:47:07 +00:00
|
|
|
const char *filename;
|
|
|
|
int hotspot_x, hotspot_y;
|
|
|
|
} pointer_images[] = {
|
|
|
|
{ DATADIR "/wayland/bottom_left_corner.png", 6, 30 },
|
|
|
|
{ DATADIR "/wayland/bottom_right_corner.png", 28, 28 },
|
|
|
|
{ DATADIR "/wayland/bottom_side.png", 16, 20 },
|
|
|
|
{ DATADIR "/wayland/grabbing.png", 20, 17 },
|
|
|
|
{ DATADIR "/wayland/left_ptr.png", 10, 5 },
|
|
|
|
{ DATADIR "/wayland/left_side.png", 10, 20 },
|
|
|
|
{ DATADIR "/wayland/right_side.png", 30, 19 },
|
|
|
|
{ DATADIR "/wayland/top_left_corner.png", 8, 8 },
|
|
|
|
{ DATADIR "/wayland/top_right_corner.png", 26, 8 },
|
|
|
|
{ DATADIR "/wayland/top_side.png", 18, 8 },
|
2010-08-18 19:28:04 +00:00
|
|
|
{ DATADIR "/wayland/xterm.png", 15, 15 },
|
|
|
|
{ DATADIR "/wayland/hand1.png", 18, 11 }
|
2010-08-16 21:47:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2010-08-18 19:28:04 +00:00
|
|
|
create_pointer_surfaces(struct display *display)
|
2010-08-16 21:47:07 +00:00
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
const int width = 32, height = 32;
|
2010-08-18 19:28:04 +00:00
|
|
|
struct rectangle rect;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
|
|
|
count = ARRAY_LENGTH(pointer_images);
|
2010-08-18 19:28:04 +00:00
|
|
|
display->pointer_surfaces =
|
|
|
|
malloc(count * sizeof *display->pointer_surfaces);
|
|
|
|
rect.width = width;
|
|
|
|
rect.height = height;
|
2010-08-16 21:47:07 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2010-08-18 19:28:04 +00:00
|
|
|
display->pointer_surfaces[i] =
|
2010-10-25 15:40:03 +00:00
|
|
|
display_create_surface_from_file(display,
|
|
|
|
pointer_images[i].filename,
|
|
|
|
&rect);
|
2011-10-25 11:19:36 +00:00
|
|
|
if (!display->pointer_surfaces[i]) {
|
|
|
|
fprintf(stderr, "Error loading pointer image: %s\n",
|
|
|
|
pointer_images[i].filename);
|
|
|
|
}
|
2010-08-16 21:47:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-12-19 08:31:45 +00:00
|
|
|
static void
|
|
|
|
destroy_pointer_surfaces(struct display *display)
|
|
|
|
{
|
|
|
|
int i, count;
|
|
|
|
|
|
|
|
count = ARRAY_LENGTH(pointer_images);
|
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
if (display->pointer_surfaces[i])
|
|
|
|
cairo_surface_destroy(display->pointer_surfaces[i]);
|
|
|
|
}
|
|
|
|
free(display->pointer_surfaces);
|
|
|
|
}
|
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
cairo_surface_t *
|
|
|
|
display_get_pointer_surface(struct display *display, int pointer,
|
|
|
|
int *width, int *height,
|
|
|
|
int *hotspot_x, int *hotspot_y)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
surface = display->pointer_surfaces[pointer];
|
2011-01-14 22:41:33 +00:00
|
|
|
#if HAVE_CAIRO_EGL
|
2010-08-18 19:28:04 +00:00
|
|
|
*width = cairo_gl_surface_get_width(surface);
|
|
|
|
*height = cairo_gl_surface_get_height(surface);
|
2011-01-05 17:41:55 +00:00
|
|
|
#else
|
|
|
|
*width = cairo_image_surface_get_width(surface);
|
|
|
|
*height = cairo_image_surface_get_height(surface);
|
|
|
|
#endif
|
2010-08-18 19:28:04 +00:00
|
|
|
*hotspot_x = pointer_images[pointer].hotspot_x;
|
|
|
|
*hotspot_y = pointer_images[pointer].hotspot_y;
|
|
|
|
|
|
|
|
return cairo_surface_reference(surface);
|
|
|
|
}
|
|
|
|
|
2010-09-03 18:46:38 +00:00
|
|
|
static void
|
|
|
|
window_attach_surface(struct window *window);
|
|
|
|
|
|
|
|
static void
|
2011-08-23 22:14:06 +00:00
|
|
|
free_surface(void *data, struct wl_callback *callback, uint32_t time)
|
2010-09-03 18:46:38 +00:00
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
|
2011-08-23 22:14:06 +00:00
|
|
|
wl_callback_destroy(callback);
|
2010-09-03 18:46:38 +00:00
|
|
|
cairo_surface_destroy(window->pending_surface);
|
|
|
|
window->pending_surface = NULL;
|
|
|
|
if (window->cairo_surface)
|
|
|
|
window_attach_surface(window);
|
|
|
|
}
|
|
|
|
|
2011-08-23 22:14:06 +00:00
|
|
|
static const struct wl_callback_listener free_surface_listener = {
|
|
|
|
free_surface
|
|
|
|
};
|
|
|
|
|
2009-12-16 19:43:37 +00:00
|
|
|
static void
|
2011-06-23 10:10:51 +00:00
|
|
|
window_get_resize_dx_dy(struct window *window, int *x, int *y)
|
2009-12-16 19:43:37 +00:00
|
|
|
{
|
2010-12-17 14:53:12 +00:00
|
|
|
if (window->resize_edges & WINDOW_RESIZING_LEFT)
|
2011-06-23 10:10:51 +00:00
|
|
|
*x = window->server_allocation.width - window->allocation.width;
|
2010-12-17 14:53:12 +00:00
|
|
|
else
|
2011-06-23 10:10:51 +00:00
|
|
|
*x = 0;
|
2009-12-16 19:43:37 +00:00
|
|
|
|
2010-12-17 14:53:12 +00:00
|
|
|
if (window->resize_edges & WINDOW_RESIZING_TOP)
|
2011-06-23 10:10:51 +00:00
|
|
|
*y = window->server_allocation.height -
|
|
|
|
window->allocation.height;
|
2010-12-17 14:53:12 +00:00
|
|
|
else
|
2011-06-23 10:10:51 +00:00
|
|
|
*y = 0;
|
2010-06-15 03:22:15 +00:00
|
|
|
|
2010-12-17 14:53:12 +00:00
|
|
|
window->resize_edges = 0;
|
2011-06-23 10:10:51 +00:00
|
|
|
}
|
|
|
|
|
2011-09-09 22:20:52 +00:00
|
|
|
static void
|
|
|
|
window_set_type(struct window *window)
|
|
|
|
{
|
2011-11-29 08:25:08 +00:00
|
|
|
if (!window->shell_surface)
|
|
|
|
return;
|
|
|
|
|
2011-09-09 22:20:52 +00:00
|
|
|
switch (window->type) {
|
|
|
|
case TYPE_FULLSCREEN:
|
2011-11-25 10:09:16 +00:00
|
|
|
wl_shell_surface_set_fullscreen(window->shell_surface);
|
2011-09-09 22:20:52 +00:00
|
|
|
break;
|
|
|
|
case TYPE_TOPLEVEL:
|
2011-11-25 10:09:16 +00:00
|
|
|
wl_shell_surface_set_toplevel(window->shell_surface);
|
2011-09-09 22:20:52 +00:00
|
|
|
break;
|
|
|
|
case TYPE_TRANSIENT:
|
2011-11-25 10:09:16 +00:00
|
|
|
wl_shell_surface_set_transient(window->shell_surface,
|
|
|
|
window->parent->shell_surface,
|
|
|
|
window->x, window->y, 0);
|
2011-09-09 22:20:52 +00:00
|
|
|
break;
|
2011-12-19 20:40:10 +00:00
|
|
|
case TYPE_MENU:
|
|
|
|
break;
|
2011-09-09 22:20:52 +00:00
|
|
|
case TYPE_CUSTOM:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-23 10:10:51 +00:00
|
|
|
static void
|
|
|
|
window_attach_surface(struct window *window)
|
|
|
|
{
|
|
|
|
struct display *display = window->display;
|
|
|
|
struct wl_buffer *buffer;
|
2011-08-23 22:14:06 +00:00
|
|
|
struct wl_callback *cb;
|
2011-07-16 19:50:32 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-06-23 10:10:51 +00:00
|
|
|
struct egl_window_surface_data *data;
|
2011-07-16 19:50:32 +00:00
|
|
|
#endif
|
2011-06-23 10:10:51 +00:00
|
|
|
int32_t x, y;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2011-09-09 22:20:52 +00:00
|
|
|
if (display->shell)
|
|
|
|
window_set_type(window);
|
|
|
|
|
2011-02-10 11:04:30 +00:00
|
|
|
switch (window->buffer_type) {
|
2011-07-16 19:50:32 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-02-10 11:04:30 +00:00
|
|
|
case WINDOW_BUFFER_TYPE_EGL_WINDOW:
|
|
|
|
data = cairo_surface_get_user_data(window->cairo_surface,
|
|
|
|
&surface_data_key);
|
|
|
|
|
|
|
|
cairo_gl_surface_swapbuffers(window->cairo_surface);
|
|
|
|
wl_egl_window_get_attached_size(data->window,
|
|
|
|
&window->server_allocation.width,
|
|
|
|
&window->server_allocation.height);
|
|
|
|
break;
|
|
|
|
case WINDOW_BUFFER_TYPE_EGL_IMAGE:
|
2011-07-16 19:50:32 +00:00
|
|
|
#endif
|
2011-02-10 11:04:30 +00:00
|
|
|
case WINDOW_BUFFER_TYPE_SHM:
|
2011-06-23 10:10:51 +00:00
|
|
|
window_get_resize_dx_dy(window, &x, &y);
|
|
|
|
|
2011-02-10 11:04:30 +00:00
|
|
|
if (window->pending_surface != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->pending_surface = window->cairo_surface;
|
|
|
|
window->cairo_surface = NULL;
|
|
|
|
|
|
|
|
buffer =
|
|
|
|
display_get_buffer_for_surface(display,
|
|
|
|
window->pending_surface);
|
|
|
|
|
|
|
|
wl_surface_attach(window->surface, buffer, x, y);
|
|
|
|
window->server_allocation = window->allocation;
|
2011-08-23 22:14:06 +00:00
|
|
|
cb = wl_display_sync(display->display);
|
|
|
|
wl_callback_add_listener(cb, &free_surface_listener, window);
|
2011-02-10 11:04:30 +00:00
|
|
|
break;
|
2011-07-16 19:50:32 +00:00
|
|
|
default:
|
|
|
|
return;
|
2011-02-10 11:04:30 +00:00
|
|
|
}
|
2010-12-17 14:53:12 +00:00
|
|
|
|
|
|
|
wl_surface_damage(window->surface, 0, 0,
|
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height);
|
2009-12-16 19:43:37 +00:00
|
|
|
}
|
|
|
|
|
2010-01-24 23:10:15 +00:00
|
|
|
void
|
2010-09-03 18:46:38 +00:00
|
|
|
window_flush(struct window *window)
|
2010-01-24 23:10:15 +00:00
|
|
|
{
|
2011-03-07 14:08:09 +00:00
|
|
|
if (window->cairo_surface) {
|
|
|
|
switch (window->buffer_type) {
|
|
|
|
case WINDOW_BUFFER_TYPE_EGL_IMAGE:
|
|
|
|
case WINDOW_BUFFER_TYPE_SHM:
|
|
|
|
display_surface_damage(window->display,
|
|
|
|
window->cairo_surface,
|
|
|
|
0, 0,
|
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
window_attach_surface(window);
|
|
|
|
}
|
2010-01-24 23:10:15 +00:00
|
|
|
}
|
|
|
|
|
2010-10-26 04:02:20 +00:00
|
|
|
void
|
|
|
|
window_set_surface(struct window *window, cairo_surface_t *surface)
|
2010-10-25 15:40:03 +00:00
|
|
|
{
|
2010-11-08 20:45:55 +00:00
|
|
|
cairo_surface_reference(surface);
|
|
|
|
|
2010-10-26 04:02:20 +00:00
|
|
|
if (window->cairo_surface != NULL)
|
|
|
|
cairo_surface_destroy(window->cairo_surface);
|
|
|
|
|
2010-11-08 20:45:55 +00:00
|
|
|
window->cairo_surface = surface;
|
2010-10-26 04:02:20 +00:00
|
|
|
}
|
|
|
|
|
2011-07-16 19:50:32 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-02-10 11:04:30 +00:00
|
|
|
static void
|
|
|
|
window_resize_cairo_window_surface(struct window *window)
|
|
|
|
{
|
|
|
|
struct egl_window_surface_data *data;
|
2011-06-23 10:10:51 +00:00
|
|
|
int x, y;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
|
|
|
data = cairo_surface_get_user_data(window->cairo_surface,
|
|
|
|
&surface_data_key);
|
|
|
|
|
2011-06-23 10:10:51 +00:00
|
|
|
window_get_resize_dx_dy(window, &x, &y),
|
2011-02-10 11:04:30 +00:00
|
|
|
wl_egl_window_resize(data->window,
|
|
|
|
window->allocation.width,
|
2011-06-23 10:10:51 +00:00
|
|
|
window->allocation.height,
|
|
|
|
x,y);
|
|
|
|
|
2011-02-10 11:04:30 +00:00
|
|
|
cairo_gl_surface_set_size(window->cairo_surface,
|
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height);
|
|
|
|
}
|
2011-07-16 19:50:32 +00:00
|
|
|
#endif
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2011-10-12 04:36:16 +00:00
|
|
|
struct display *
|
|
|
|
window_get_display(struct window *window)
|
|
|
|
{
|
|
|
|
return window->display;
|
|
|
|
}
|
|
|
|
|
2010-10-26 04:02:20 +00:00
|
|
|
void
|
|
|
|
window_create_surface(struct window *window)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface;
|
2011-05-13 17:45:17 +00:00
|
|
|
uint32_t flags = 0;
|
|
|
|
|
|
|
|
if (!window->transparent)
|
|
|
|
flags = SURFACE_OPAQUE;
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
switch (window->buffer_type) {
|
2011-01-14 22:41:33 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-02-10 11:04:30 +00:00
|
|
|
case WINDOW_BUFFER_TYPE_EGL_WINDOW:
|
|
|
|
if (window->cairo_surface) {
|
|
|
|
window_resize_cairo_window_surface(window);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
surface = display_create_surface(window->display,
|
|
|
|
window->surface,
|
2011-05-13 17:45:17 +00:00
|
|
|
&window->allocation, flags);
|
2011-02-10 11:04:30 +00:00
|
|
|
break;
|
2011-02-04 19:11:33 +00:00
|
|
|
case WINDOW_BUFFER_TYPE_EGL_IMAGE:
|
2010-10-26 04:02:20 +00:00
|
|
|
surface = display_create_surface(window->display,
|
2011-02-10 11:04:30 +00:00
|
|
|
NULL,
|
2011-05-13 17:45:17 +00:00
|
|
|
&window->allocation, flags);
|
2010-10-25 15:40:03 +00:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
case WINDOW_BUFFER_TYPE_SHM:
|
2010-10-26 04:02:20 +00:00
|
|
|
surface = display_create_shm_surface(window->display,
|
2011-05-13 17:45:17 +00:00
|
|
|
&window->allocation, flags);
|
2010-10-25 15:40:03 +00:00
|
|
|
break;
|
2010-11-19 20:14:55 +00:00
|
|
|
default:
|
|
|
|
surface = NULL;
|
|
|
|
break;
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
2010-10-26 04:02:20 +00:00
|
|
|
|
|
|
|
window_set_surface(window, surface);
|
|
|
|
cairo_surface_destroy(surface);
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 17:14:50 +00:00
|
|
|
static void
|
|
|
|
window_draw_decorations(struct window *window)
|
2008-11-02 23:51:48 +00:00
|
|
|
{
|
|
|
|
cairo_t *cr;
|
2008-11-03 11:59:52 +00:00
|
|
|
cairo_text_extents_t extents;
|
2010-08-18 19:28:04 +00:00
|
|
|
cairo_surface_t *frame;
|
|
|
|
int width, height, shadow_dx = 3, shadow_dy = 3;
|
2008-11-02 23:51:48 +00:00
|
|
|
|
2010-10-26 04:02:20 +00:00
|
|
|
window_create_surface(window);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2010-06-15 21:16:35 +00:00
|
|
|
width = window->allocation.width;
|
|
|
|
height = window->allocation.height;
|
2008-11-02 23:51:48 +00:00
|
|
|
|
2009-01-15 16:37:43 +00:00
|
|
|
cr = cairo_create(window->cairo_surface);
|
2008-11-09 03:46:30 +00:00
|
|
|
|
2010-06-15 03:22:15 +00:00
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
2010-06-15 21:16:35 +00:00
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 0);
|
2010-06-15 03:22:15 +00:00
|
|
|
cairo_paint(cr);
|
|
|
|
|
2010-06-15 21:16:35 +00:00
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 0.6);
|
2010-08-18 19:28:04 +00:00
|
|
|
tile_mask(cr, window->display->shadow,
|
|
|
|
shadow_dx, shadow_dy, width, height,
|
|
|
|
window->margin + 10 - shadow_dx,
|
|
|
|
window->margin + 10 - shadow_dy);
|
2008-11-08 23:53:37 +00:00
|
|
|
|
2010-06-15 21:16:35 +00:00
|
|
|
if (window->keyboard_device)
|
2010-08-18 19:28:04 +00:00
|
|
|
frame = window->display->active_frame;
|
2010-06-15 21:16:35 +00:00
|
|
|
else
|
2010-08-18 19:28:04 +00:00
|
|
|
frame = window->display->inactive_frame;
|
|
|
|
|
|
|
|
tile_source(cr, frame, 0, 0, width, height,
|
|
|
|
window->margin + 10, window->margin + 50);
|
2008-11-03 11:59:52 +00:00
|
|
|
|
2008-11-08 23:53:37 +00:00
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_set_font_size(cr, 14);
|
2008-12-08 00:59:11 +00:00
|
|
|
cairo_text_extents(cr, window->title, &extents);
|
2010-06-15 21:16:35 +00:00
|
|
|
cairo_move_to(cr, (width - extents.width) / 2, 32 - extents.y_bearing);
|
|
|
|
if (window->keyboard_device)
|
|
|
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
|
|
|
else
|
2009-09-21 17:43:46 +00:00
|
|
|
cairo_set_source_rgb(cr, 0.8, 0.8, 0.8);
|
2010-06-15 21:16:35 +00:00
|
|
|
cairo_show_text(cr, window->title);
|
|
|
|
|
2008-11-02 23:51:48 +00:00
|
|
|
cairo_destroy(cr);
|
2008-12-22 17:14:50 +00:00
|
|
|
}
|
|
|
|
|
2011-01-21 23:03:15 +00:00
|
|
|
void
|
|
|
|
window_destroy(struct window *window)
|
|
|
|
{
|
2011-11-15 11:34:55 +00:00
|
|
|
struct display *display = window->display;
|
|
|
|
struct input *input;
|
|
|
|
|
|
|
|
if (window->redraw_scheduled)
|
|
|
|
wl_list_remove(&window->redraw_task.link);
|
|
|
|
|
|
|
|
wl_list_for_each(input, &display->input_list, link) {
|
|
|
|
if (input->pointer_focus == window)
|
|
|
|
input->pointer_focus = NULL;
|
|
|
|
if (input->keyboard_focus == window)
|
|
|
|
input->keyboard_focus = NULL;
|
|
|
|
}
|
|
|
|
|
2011-11-29 08:25:08 +00:00
|
|
|
if (window->shell_surface)
|
|
|
|
wl_shell_surface_destroy(window->shell_surface);
|
2011-01-21 23:03:15 +00:00
|
|
|
wl_surface_destroy(window->surface);
|
|
|
|
wl_list_remove(&window->link);
|
2011-12-16 08:09:29 +00:00
|
|
|
|
|
|
|
if (window->cairo_surface != NULL)
|
|
|
|
cairo_surface_destroy(window->cairo_surface);
|
|
|
|
if (window->pending_surface != NULL)
|
|
|
|
cairo_surface_destroy(window->pending_surface);
|
|
|
|
|
|
|
|
free(window->title);
|
2011-01-21 23:03:15 +00:00
|
|
|
free(window);
|
|
|
|
}
|
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
static struct item *
|
|
|
|
window_find_item(struct window *window, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
struct item *item;
|
|
|
|
|
|
|
|
wl_list_for_each(item, &window->item_list, link) {
|
|
|
|
if (item->allocation.x <= x &&
|
|
|
|
x < item->allocation.x + item->allocation.width &&
|
|
|
|
item->allocation.y <= y &&
|
|
|
|
y < item->allocation.y + item->allocation.height) {
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct item *
|
|
|
|
window_add_item(struct window *window, void *data)
|
|
|
|
{
|
|
|
|
struct item *item;
|
|
|
|
|
|
|
|
item = malloc(sizeof *item);
|
|
|
|
memset(item, 0, sizeof *item);
|
|
|
|
item->user_data = data;
|
|
|
|
wl_list_insert(window->item_list.prev, &item->link);
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_for_each_item(struct window *window, item_func_t func, void *data)
|
|
|
|
{
|
|
|
|
struct item *item;
|
|
|
|
|
|
|
|
wl_list_for_each(item, &window->item_list, link)
|
|
|
|
func(item, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct item *
|
|
|
|
window_get_focus_item(struct window *window)
|
|
|
|
{
|
|
|
|
return window->focus_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
item_get_allocation(struct item *item, struct rectangle *allocation)
|
|
|
|
{
|
|
|
|
*allocation = item->allocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
item_set_allocation(struct item *item,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
item->allocation.x = x;
|
|
|
|
item->allocation.y = y;
|
|
|
|
item->allocation.width = width;
|
|
|
|
item->allocation.height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
item_get_user_data(struct item *item)
|
|
|
|
{
|
|
|
|
return item->user_data;
|
|
|
|
}
|
|
|
|
|
2008-12-22 17:14:50 +00:00
|
|
|
void
|
|
|
|
window_draw(struct window *window)
|
|
|
|
{
|
2011-12-19 20:40:10 +00:00
|
|
|
if (!window->decoration)
|
2010-10-26 04:02:20 +00:00
|
|
|
window_create_surface(window);
|
2008-12-22 17:14:50 +00:00
|
|
|
else
|
|
|
|
window_draw_decorations(window);
|
2008-11-26 17:57:31 +00:00
|
|
|
}
|
|
|
|
|
2010-06-08 18:08:30 +00:00
|
|
|
cairo_surface_t *
|
|
|
|
window_get_surface(struct window *window)
|
|
|
|
{
|
2010-10-26 04:02:20 +00:00
|
|
|
return cairo_surface_reference(window->cairo_surface);
|
2010-06-08 18:08:30 +00:00
|
|
|
}
|
|
|
|
|
2011-03-14 11:07:26 +00:00
|
|
|
struct wl_surface *
|
|
|
|
window_get_wl_surface(struct window *window)
|
|
|
|
{
|
|
|
|
return window->surface;
|
|
|
|
}
|
|
|
|
|
2011-11-25 10:09:16 +00:00
|
|
|
struct wl_shell_surface *
|
|
|
|
window_get_wl_shell_surface(struct window *window)
|
|
|
|
{
|
|
|
|
return window->shell_surface;
|
|
|
|
}
|
|
|
|
|
2010-08-16 21:47:07 +00:00
|
|
|
static int
|
|
|
|
get_pointer_location(struct window *window, int32_t x, int32_t y)
|
|
|
|
{
|
2010-08-18 19:28:04 +00:00
|
|
|
int vlocation, hlocation, location;
|
2010-08-16 21:47:07 +00:00
|
|
|
const int grip_size = 8;
|
|
|
|
|
2010-12-17 14:53:12 +00:00
|
|
|
if (!window->decoration)
|
|
|
|
return WINDOW_CLIENT_AREA;
|
|
|
|
|
2010-08-16 21:47:07 +00:00
|
|
|
if (x < window->margin)
|
2010-08-18 19:28:04 +00:00
|
|
|
hlocation = WINDOW_EXTERIOR;
|
2010-08-16 21:47:07 +00:00
|
|
|
else if (window->margin <= x && x < window->margin + grip_size)
|
|
|
|
hlocation = WINDOW_RESIZING_LEFT;
|
|
|
|
else if (x < window->allocation.width - window->margin - grip_size)
|
2010-08-18 19:28:04 +00:00
|
|
|
hlocation = WINDOW_INTERIOR;
|
2010-08-16 21:47:07 +00:00
|
|
|
else if (x < window->allocation.width - window->margin)
|
|
|
|
hlocation = WINDOW_RESIZING_RIGHT;
|
|
|
|
else
|
2010-08-18 19:28:04 +00:00
|
|
|
hlocation = WINDOW_EXTERIOR;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
|
|
|
if (y < window->margin)
|
2010-08-18 19:28:04 +00:00
|
|
|
vlocation = WINDOW_EXTERIOR;
|
2010-08-16 21:47:07 +00:00
|
|
|
else if (window->margin <= y && y < window->margin + grip_size)
|
|
|
|
vlocation = WINDOW_RESIZING_TOP;
|
|
|
|
else if (y < window->allocation.height - window->margin - grip_size)
|
2010-08-18 19:28:04 +00:00
|
|
|
vlocation = WINDOW_INTERIOR;
|
2010-08-16 21:47:07 +00:00
|
|
|
else if (y < window->allocation.height - window->margin)
|
|
|
|
vlocation = WINDOW_RESIZING_BOTTOM;
|
|
|
|
else
|
2010-08-18 19:28:04 +00:00
|
|
|
vlocation = WINDOW_EXTERIOR;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
location = vlocation | hlocation;
|
|
|
|
if (location & WINDOW_EXTERIOR)
|
|
|
|
location = WINDOW_EXTERIOR;
|
|
|
|
if (location == WINDOW_INTERIOR && y < window->margin + 50)
|
|
|
|
location = WINDOW_TITLEBAR;
|
|
|
|
else if (location == WINDOW_INTERIOR)
|
|
|
|
location = WINDOW_CLIENT_AREA;
|
|
|
|
|
|
|
|
return location;
|
2010-08-16 21:47:07 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 14:14:34 +00:00
|
|
|
static int
|
|
|
|
input_get_pointer_image_for_location(struct input *input, int pointer)
|
2010-08-16 21:47:07 +00:00
|
|
|
{
|
2010-08-18 19:28:04 +00:00
|
|
|
int location;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
|
|
|
location = get_pointer_location(input->pointer_focus,
|
|
|
|
input->sx, input->sy);
|
|
|
|
switch (location) {
|
|
|
|
case WINDOW_RESIZING_TOP:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_TOP;
|
2010-08-16 21:47:07 +00:00
|
|
|
case WINDOW_RESIZING_BOTTOM:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_BOTTOM;
|
2010-08-16 21:47:07 +00:00
|
|
|
case WINDOW_RESIZING_LEFT:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_LEFT;
|
2010-08-16 21:47:07 +00:00
|
|
|
case WINDOW_RESIZING_RIGHT:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_RIGHT;
|
2010-08-16 21:47:07 +00:00
|
|
|
case WINDOW_RESIZING_TOP_LEFT:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_TOP_LEFT;
|
2010-08-16 21:47:07 +00:00
|
|
|
case WINDOW_RESIZING_TOP_RIGHT:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_TOP_RIGHT;
|
2010-08-16 21:47:07 +00:00
|
|
|
case WINDOW_RESIZING_BOTTOM_LEFT:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_BOTTOM_LEFT;
|
2010-08-16 21:47:07 +00:00
|
|
|
case WINDOW_RESIZING_BOTTOM_RIGHT:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_BOTTOM_RIGHT;
|
2010-08-18 19:28:04 +00:00
|
|
|
case WINDOW_EXTERIOR:
|
|
|
|
case WINDOW_TITLEBAR:
|
2011-12-15 14:14:34 +00:00
|
|
|
return POINTER_LEFT_PTR;
|
2010-08-16 21:47:07 +00:00
|
|
|
default:
|
2011-12-15 14:14:34 +00:00
|
|
|
return pointer;
|
2010-08-16 21:47:07 +00:00
|
|
|
}
|
2011-12-15 14:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_set_pointer_image(struct input *input, uint32_t time, int pointer)
|
|
|
|
{
|
|
|
|
struct display *display = input->display;
|
|
|
|
struct wl_buffer *buffer;
|
|
|
|
cairo_surface_t *surface;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2010-09-08 01:50:06 +00:00
|
|
|
if (pointer == input->current_pointer_image)
|
|
|
|
return;
|
|
|
|
|
|
|
|
input->current_pointer_image = pointer;
|
2010-08-18 19:28:04 +00:00
|
|
|
surface = display->pointer_surfaces[pointer];
|
2011-10-25 11:20:51 +00:00
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return;
|
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
buffer = display_get_buffer_for_surface(display, surface);
|
2010-09-14 19:39:45 +00:00
|
|
|
wl_input_device_attach(input->input_device, time, buffer,
|
2010-08-16 21:47:07 +00:00
|
|
|
pointer_images[pointer].hotspot_x,
|
|
|
|
pointer_images[pointer].hotspot_y);
|
|
|
|
}
|
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
static void
|
|
|
|
window_set_focus_item(struct window *window, struct item *focus)
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
if (focus == window->focus_item)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->focus_item = focus;
|
|
|
|
data = focus ? focus->user_data : NULL;
|
|
|
|
if (window->item_focus_handler)
|
|
|
|
window->item_focus_handler(window, focus, data);
|
|
|
|
}
|
|
|
|
|
2008-11-08 23:53:37 +00:00
|
|
|
static void
|
2011-12-21 22:11:45 +00:00
|
|
|
input_handle_motion(void *data, struct wl_input_device *input_device,
|
|
|
|
uint32_t time,
|
|
|
|
int32_t x, int32_t y, int32_t sx, int32_t sy)
|
2008-11-02 23:51:48 +00:00
|
|
|
{
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input *input = data;
|
2010-08-18 19:28:04 +00:00
|
|
|
struct window *window = input->pointer_focus;
|
2011-09-21 01:43:54 +00:00
|
|
|
struct item *item;
|
2011-01-25 20:16:01 +00:00
|
|
|
int pointer = POINTER_LEFT_PTR;
|
2010-07-20 21:06:19 +00:00
|
|
|
|
|
|
|
input->x = x;
|
|
|
|
input->y = y;
|
|
|
|
input->sx = sx;
|
|
|
|
input->sy = sy;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
if (!window->focus_item || !window->item_grab_button) {
|
|
|
|
item = window_find_item(window, sx, sy);
|
|
|
|
window_set_focus_item(window, item);
|
|
|
|
}
|
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
if (window->motion_handler)
|
|
|
|
pointer = (*window->motion_handler)(window, input, time,
|
|
|
|
x, y, sx, sy,
|
|
|
|
window->user_data);
|
|
|
|
|
2011-12-15 14:14:34 +00:00
|
|
|
pointer = input_get_pointer_image_for_location(input, pointer);
|
2011-10-28 16:26:06 +00:00
|
|
|
input_set_pointer_image(input, time, pointer);
|
2008-12-30 16:03:33 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 20:34:05 +00:00
|
|
|
static void
|
2011-12-21 22:11:45 +00:00
|
|
|
input_handle_button(void *data,
|
|
|
|
struct wl_input_device *input_device,
|
|
|
|
uint32_t time, uint32_t button, uint32_t state)
|
2008-12-30 16:03:33 +00:00
|
|
|
{
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input *input = data;
|
|
|
|
struct window *window = input->pointer_focus;
|
2011-09-21 01:43:54 +00:00
|
|
|
struct item *item;
|
2010-08-16 21:47:07 +00:00
|
|
|
int location;
|
2010-06-15 00:25:06 +00:00
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
if (window->focus_item && window->item_grab_button == 0 && state)
|
|
|
|
window->item_grab_button = button;
|
|
|
|
|
2010-08-16 21:47:07 +00:00
|
|
|
location = get_pointer_location(window, input->sx, input->sy);
|
2008-11-02 23:51:48 +00:00
|
|
|
|
2011-09-09 22:20:52 +00:00
|
|
|
if (window->display->shell &&
|
|
|
|
button == BTN_LEFT && state == 1) {
|
2010-08-16 21:47:07 +00:00
|
|
|
switch (location) {
|
2010-08-18 19:28:04 +00:00
|
|
|
case WINDOW_TITLEBAR:
|
2011-11-29 08:25:08 +00:00
|
|
|
if (!window->shell_surface)
|
|
|
|
break;
|
2011-12-15 14:14:34 +00:00
|
|
|
input_set_pointer_image(input, time, POINTER_DRAGGING);
|
2011-11-25 10:09:16 +00:00
|
|
|
wl_shell_surface_move(window->shell_surface,
|
|
|
|
input_device, time);
|
2008-12-30 16:03:33 +00:00
|
|
|
break;
|
2010-06-15 00:25:06 +00:00
|
|
|
case WINDOW_RESIZING_TOP:
|
|
|
|
case WINDOW_RESIZING_BOTTOM:
|
|
|
|
case WINDOW_RESIZING_LEFT:
|
|
|
|
case WINDOW_RESIZING_RIGHT:
|
|
|
|
case WINDOW_RESIZING_TOP_LEFT:
|
|
|
|
case WINDOW_RESIZING_TOP_RIGHT:
|
|
|
|
case WINDOW_RESIZING_BOTTOM_LEFT:
|
|
|
|
case WINDOW_RESIZING_BOTTOM_RIGHT:
|
2011-11-29 08:25:08 +00:00
|
|
|
if (!window->shell_surface)
|
|
|
|
break;
|
2011-11-25 10:09:16 +00:00
|
|
|
wl_shell_surface_resize(window->shell_surface,
|
|
|
|
input_device, time,
|
|
|
|
location);
|
2008-12-30 16:03:33 +00:00
|
|
|
break;
|
2010-08-18 19:28:04 +00:00
|
|
|
case WINDOW_CLIENT_AREA:
|
|
|
|
if (window->button_handler)
|
|
|
|
(*window->button_handler)(window,
|
|
|
|
input, time,
|
|
|
|
button, state,
|
|
|
|
window->user_data);
|
|
|
|
break;
|
2008-11-02 23:51:48 +00:00
|
|
|
}
|
2010-08-18 19:28:04 +00:00
|
|
|
} else {
|
|
|
|
if (window->button_handler)
|
|
|
|
(*window->button_handler)(window,
|
|
|
|
input, time,
|
|
|
|
button, state,
|
|
|
|
window->user_data);
|
2008-11-02 23:51:48 +00:00
|
|
|
}
|
2011-09-21 01:43:54 +00:00
|
|
|
|
|
|
|
if (window->focus_item &&
|
|
|
|
window->item_grab_button == button && !state) {
|
|
|
|
window->item_grab_button = 0;
|
|
|
|
item = window_find_item(window, input->sx, input->sy);
|
|
|
|
window_set_focus_item(window, item);
|
|
|
|
}
|
2008-11-02 23:51:48 +00:00
|
|
|
}
|
|
|
|
|
2009-02-24 03:37:14 +00:00
|
|
|
static void
|
2011-12-21 22:11:45 +00:00
|
|
|
input_handle_key(void *data, struct wl_input_device *input_device,
|
|
|
|
uint32_t time, uint32_t key, uint32_t state)
|
2009-02-24 03:37:14 +00:00
|
|
|
{
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input *input = data;
|
|
|
|
struct window *window = input->keyboard_focus;
|
2011-11-28 14:13:57 +00:00
|
|
|
struct display *d = input->display;
|
2010-06-25 20:50:05 +00:00
|
|
|
uint32_t code, sym, level;
|
2009-02-24 03:37:14 +00:00
|
|
|
|
2010-06-25 20:50:05 +00:00
|
|
|
code = key + d->xkb->min_key_code;
|
2011-11-28 14:13:57 +00:00
|
|
|
if (!window || window->keyboard_device != input)
|
2009-02-24 03:37:14 +00:00
|
|
|
return;
|
|
|
|
|
2010-06-25 20:50:05 +00:00
|
|
|
level = 0;
|
2011-01-19 19:41:20 +00:00
|
|
|
if (input->modifiers & XKB_COMMON_SHIFT_MASK &&
|
2010-06-25 20:50:05 +00:00
|
|
|
XkbKeyGroupWidth(d->xkb, code, 0) > 1)
|
|
|
|
level = 1;
|
2009-02-24 03:37:14 +00:00
|
|
|
|
2010-06-25 20:50:05 +00:00
|
|
|
sym = XkbKeySymEntry(d->xkb, code, level, 0);
|
|
|
|
|
|
|
|
if (state)
|
2010-07-20 21:06:19 +00:00
|
|
|
input->modifiers |= d->xkb->map->modmap[code];
|
2010-06-25 20:50:05 +00:00
|
|
|
else
|
2010-07-20 21:06:19 +00:00
|
|
|
input->modifiers &= ~d->xkb->map->modmap[code];
|
2008-12-30 16:03:33 +00:00
|
|
|
|
|
|
|
if (window->key_handler)
|
2011-01-19 19:20:33 +00:00
|
|
|
(*window->key_handler)(window, input, time, key, sym, state,
|
|
|
|
window->user_data);
|
2008-12-30 16:03:33 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 10:02:09 +00:00
|
|
|
static void
|
2011-12-21 22:11:45 +00:00
|
|
|
input_remove_pointer_focus(struct input *input, uint32_t time)
|
2011-12-16 10:02:09 +00:00
|
|
|
{
|
|
|
|
struct window *window = input->pointer_focus;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window_set_focus_item(window, NULL);
|
|
|
|
|
|
|
|
if (window->leave_handler)
|
|
|
|
window->leave_handler(window, input, time, window->user_data);
|
|
|
|
input->pointer_focus = NULL;
|
|
|
|
input->current_pointer_image = POINTER_UNSET;
|
|
|
|
}
|
|
|
|
|
2009-02-23 02:51:24 +00:00
|
|
|
static void
|
2011-12-21 22:11:45 +00:00
|
|
|
input_handle_pointer_focus(void *data,
|
|
|
|
struct wl_input_device *input_device,
|
|
|
|
uint32_t time, struct wl_surface *surface,
|
|
|
|
int32_t x, int32_t y, int32_t sx, int32_t sy)
|
2009-02-23 02:51:24 +00:00
|
|
|
{
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input *input = data;
|
2010-08-18 19:28:04 +00:00
|
|
|
struct window *window;
|
2011-09-21 01:43:54 +00:00
|
|
|
struct item *item;
|
2010-08-18 19:28:04 +00:00
|
|
|
int pointer;
|
2010-07-20 21:06:19 +00:00
|
|
|
|
2011-09-06 18:33:52 +00:00
|
|
|
window = input->pointer_focus;
|
2011-12-16 10:02:09 +00:00
|
|
|
if (window && window->surface != surface)
|
2011-12-21 22:11:45 +00:00
|
|
|
input_remove_pointer_focus(input, time);
|
2011-09-06 18:33:52 +00:00
|
|
|
|
2010-08-16 21:47:07 +00:00
|
|
|
if (surface) {
|
2010-07-20 21:06:19 +00:00
|
|
|
input->pointer_focus = wl_surface_get_user_data(surface);
|
2010-08-18 19:28:04 +00:00
|
|
|
window = input->pointer_focus;
|
|
|
|
|
2011-01-20 16:56:57 +00:00
|
|
|
input->x = x;
|
|
|
|
input->y = y;
|
|
|
|
input->sx = sx;
|
|
|
|
input->sy = sy;
|
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
pointer = POINTER_LEFT_PTR;
|
2011-09-06 18:33:52 +00:00
|
|
|
if (window->enter_handler)
|
|
|
|
pointer = window->enter_handler(window, input,
|
|
|
|
time, sx, sy,
|
|
|
|
window->user_data);
|
2010-08-18 19:28:04 +00:00
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
item = window_find_item(window, x, y);
|
|
|
|
window_set_focus_item(window, item);
|
2011-09-06 18:33:52 +00:00
|
|
|
|
2011-12-15 14:14:34 +00:00
|
|
|
pointer = input_get_pointer_image_for_location(input, pointer);
|
2011-10-28 16:26:06 +00:00
|
|
|
input_set_pointer_image(input, time, pointer);
|
2010-08-16 21:47:07 +00:00
|
|
|
}
|
2009-02-23 02:51:24 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 10:02:09 +00:00
|
|
|
static void
|
2011-12-21 22:11:45 +00:00
|
|
|
input_remove_keyboard_focus(struct input *input)
|
2011-12-16 10:02:09 +00:00
|
|
|
{
|
|
|
|
struct window *window = input->keyboard_focus;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window->keyboard_device = NULL;
|
|
|
|
if (window->keyboard_focus_handler)
|
|
|
|
(*window->keyboard_focus_handler)(window, NULL,
|
|
|
|
window->user_data);
|
|
|
|
|
|
|
|
input->keyboard_focus = NULL;
|
|
|
|
}
|
|
|
|
|
2009-02-23 02:51:24 +00:00
|
|
|
static void
|
2011-12-21 22:11:45 +00:00
|
|
|
input_handle_keyboard_focus(void *data,
|
|
|
|
struct wl_input_device *input_device,
|
|
|
|
uint32_t time,
|
|
|
|
struct wl_surface *surface,
|
|
|
|
struct wl_array *keys)
|
2009-02-23 02:51:24 +00:00
|
|
|
{
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input *input = data;
|
2011-12-16 10:02:09 +00:00
|
|
|
struct window *window;
|
2010-07-20 21:06:19 +00:00
|
|
|
struct display *d = input->display;
|
2009-02-24 03:37:14 +00:00
|
|
|
uint32_t *k, *end;
|
2009-02-23 04:01:35 +00:00
|
|
|
|
2011-12-21 22:11:45 +00:00
|
|
|
input_remove_keyboard_focus(input);
|
2009-02-24 03:37:14 +00:00
|
|
|
|
2010-07-20 21:06:19 +00:00
|
|
|
if (surface)
|
|
|
|
input->keyboard_focus = wl_surface_get_user_data(surface);
|
|
|
|
|
|
|
|
end = keys->data + keys->size;
|
2011-01-27 16:57:19 +00:00
|
|
|
input->modifiers = 0;
|
2010-07-20 21:06:19 +00:00
|
|
|
for (k = keys->data; k < end; k++)
|
|
|
|
input->modifiers |= d->xkb->map->modmap[*k];
|
|
|
|
|
|
|
|
window = input->keyboard_focus;
|
|
|
|
if (window) {
|
|
|
|
window->keyboard_device = input;
|
|
|
|
if (window->keyboard_focus_handler)
|
|
|
|
(*window->keyboard_focus_handler)(window,
|
|
|
|
window->keyboard_device,
|
|
|
|
window->user_data);
|
|
|
|
}
|
2009-02-23 02:51:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 16:03:33 +00:00
|
|
|
static const struct wl_input_device_listener input_device_listener = {
|
2011-12-21 22:11:45 +00:00
|
|
|
input_handle_motion,
|
|
|
|
input_handle_button,
|
|
|
|
input_handle_key,
|
|
|
|
input_handle_pointer_focus,
|
|
|
|
input_handle_keyboard_focus,
|
2008-12-30 16:03:33 +00:00
|
|
|
};
|
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
void
|
|
|
|
input_get_position(struct input *input, int32_t *x, int32_t *y)
|
|
|
|
{
|
|
|
|
*x = input->sx;
|
|
|
|
*y = input->sy;
|
|
|
|
}
|
|
|
|
|
2010-08-25 20:34:05 +00:00
|
|
|
struct wl_input_device *
|
|
|
|
input_get_input_device(struct input *input)
|
|
|
|
{
|
|
|
|
return input->input_device;
|
|
|
|
}
|
|
|
|
|
2011-01-19 19:20:33 +00:00
|
|
|
uint32_t
|
|
|
|
input_get_modifiers(struct input *input)
|
|
|
|
{
|
|
|
|
return input->modifiers;
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
struct data_offer {
|
|
|
|
struct wl_data_offer *offer;
|
|
|
|
struct input *input;
|
|
|
|
struct wl_array types;
|
|
|
|
int refcount;
|
|
|
|
|
|
|
|
struct task io_task;
|
|
|
|
int fd;
|
|
|
|
data_func_t func;
|
|
|
|
int32_t x, y;
|
|
|
|
void *user_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_offer(void *data, struct wl_data_offer *wl_data_offer, const char *type)
|
|
|
|
{
|
|
|
|
struct data_offer *offer = data;
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
p = wl_array_add(&offer->types, sizeof *p);
|
|
|
|
*p = strdup(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_data_offer_listener data_offer_listener = {
|
|
|
|
data_offer_offer,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_destroy(struct data_offer *offer)
|
2010-08-19 21:26:02 +00:00
|
|
|
{
|
2011-10-28 16:26:06 +00:00
|
|
|
char **p;
|
2010-08-18 19:28:04 +00:00
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
offer->refcount--;
|
|
|
|
if (offer->refcount == 0) {
|
|
|
|
wl_data_offer_destroy(offer->offer);
|
|
|
|
for (p = offer->types.data; *p; p++)
|
|
|
|
free(*p);
|
|
|
|
wl_array_release(&offer->types);
|
|
|
|
free(offer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_data_offer(void *data,
|
|
|
|
struct wl_data_device *data_device, uint32_t id)
|
|
|
|
{
|
|
|
|
struct data_offer *offer;
|
|
|
|
|
|
|
|
offer = malloc(sizeof *offer);
|
|
|
|
|
|
|
|
wl_array_init(&offer->types);
|
|
|
|
offer->refcount = 1;
|
|
|
|
offer->input = data;
|
|
|
|
|
|
|
|
/* FIXME: Generate typesafe wrappers for this */
|
|
|
|
offer->offer = (struct wl_data_offer *)
|
|
|
|
wl_proxy_create_for_id((struct wl_proxy *) data_device,
|
|
|
|
id, &wl_data_offer_interface);
|
|
|
|
|
|
|
|
wl_data_offer_add_listener(offer->offer,
|
|
|
|
&data_offer_listener, offer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_enter(void *data, struct wl_data_device *data_device,
|
|
|
|
uint32_t time, struct wl_surface *surface,
|
|
|
|
int32_t x, int32_t y, struct wl_data_offer *offer)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct window *window;
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
input->drag_offer = wl_data_offer_get_user_data(offer);
|
|
|
|
window = wl_surface_get_user_data(surface);
|
|
|
|
input->pointer_focus = window;
|
|
|
|
|
|
|
|
p = wl_array_add(&input->drag_offer->types, sizeof *p);
|
|
|
|
*p = NULL;
|
|
|
|
|
|
|
|
window = input->pointer_focus;
|
|
|
|
if (window->data_handler)
|
|
|
|
window->data_handler(window, input, time, x, y,
|
|
|
|
input->drag_offer->types.data,
|
|
|
|
window->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_leave(void *data, struct wl_data_device *data_device)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
|
|
|
|
data_offer_destroy(input->drag_offer);
|
|
|
|
input->drag_offer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_motion(void *data, struct wl_data_device *data_device,
|
|
|
|
uint32_t time, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct window *window = input->pointer_focus;
|
|
|
|
|
|
|
|
input->sx = x;
|
|
|
|
input->sy = y;
|
|
|
|
|
|
|
|
if (window->data_handler)
|
|
|
|
window->data_handler(window, input, time, x, y,
|
|
|
|
input->drag_offer->types.data,
|
|
|
|
window->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_drop(void *data, struct wl_data_device *data_device)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct window *window = input->pointer_focus;
|
|
|
|
|
|
|
|
if (window->drop_handler)
|
|
|
|
window->drop_handler(window, input,
|
|
|
|
input->sx, input->sy, window->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_selection(void *data,
|
|
|
|
struct wl_data_device *wl_data_device,
|
|
|
|
struct wl_data_offer *offer)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
char **p;
|
|
|
|
|
|
|
|
if (input->selection_offer)
|
|
|
|
data_offer_destroy(input->selection_offer);
|
|
|
|
|
|
|
|
input->selection_offer = wl_data_offer_get_user_data(offer);
|
|
|
|
p = wl_array_add(&input->selection_offer->types, sizeof *p);
|
|
|
|
*p = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_data_device_listener data_device_listener = {
|
|
|
|
data_device_data_offer,
|
|
|
|
data_device_enter,
|
|
|
|
data_device_leave,
|
|
|
|
data_device_motion,
|
|
|
|
data_device_drop,
|
|
|
|
data_device_selection
|
|
|
|
};
|
|
|
|
|
|
|
|
struct wl_data_device *
|
|
|
|
input_get_data_device(struct input *input)
|
|
|
|
{
|
|
|
|
return input->data_device;
|
2010-11-30 19:01:07 +00:00
|
|
|
}
|
2010-09-03 00:22:42 +00:00
|
|
|
|
2010-12-17 14:53:12 +00:00
|
|
|
void
|
2011-10-28 16:26:06 +00:00
|
|
|
input_set_selection(struct input *input,
|
|
|
|
struct wl_data_source *source, uint32_t time)
|
2010-12-17 14:53:12 +00:00
|
|
|
{
|
2011-10-28 16:26:06 +00:00
|
|
|
wl_data_device_set_selection(input->data_device, source, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
input_accept(struct input *input, uint32_t time, const char *type)
|
|
|
|
{
|
|
|
|
wl_data_offer_accept(input->drag_offer->offer, time, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
offer_io_func(struct task *task, uint32_t events)
|
|
|
|
{
|
|
|
|
struct data_offer *offer =
|
|
|
|
container_of(task, struct data_offer, io_task);
|
|
|
|
unsigned int len;
|
|
|
|
char buffer[4096];
|
|
|
|
|
|
|
|
len = read(offer->fd, buffer, sizeof buffer);
|
|
|
|
offer->func(buffer, len,
|
|
|
|
offer->x, offer->y, offer->user_data);
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
close(offer->fd);
|
|
|
|
data_offer_destroy(offer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_offer_receive_data(struct data_offer *offer, const char *mime_type,
|
|
|
|
data_func_t func, void *user_data)
|
|
|
|
{
|
|
|
|
int p[2];
|
|
|
|
|
|
|
|
pipe2(p, O_CLOEXEC);
|
|
|
|
wl_data_offer_receive(offer->offer, mime_type, p[1]);
|
|
|
|
close(p[1]);
|
|
|
|
|
|
|
|
offer->io_task.run = offer_io_func;
|
|
|
|
offer->fd = p[0];
|
|
|
|
offer->func = func;
|
|
|
|
offer->refcount++;
|
|
|
|
offer->user_data = user_data;
|
|
|
|
|
|
|
|
display_watch_fd(offer->input->display,
|
|
|
|
offer->fd, EPOLLIN, &offer->io_task);
|
2010-12-17 14:53:12 +00:00
|
|
|
}
|
|
|
|
|
2010-11-30 19:01:07 +00:00
|
|
|
void
|
2011-10-28 16:26:06 +00:00
|
|
|
input_receive_drag_data(struct input *input, const char *mime_type,
|
|
|
|
data_func_t func, void *data)
|
|
|
|
{
|
|
|
|
data_offer_receive_data(input->drag_offer, mime_type, func, data);
|
|
|
|
input->drag_offer->x = input->sx;
|
|
|
|
input->drag_offer->y = input->sy;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
input_receive_selection_data(struct input *input, const char *mime_type,
|
|
|
|
data_func_t func, void *data)
|
2010-11-30 19:01:07 +00:00
|
|
|
{
|
2011-10-28 16:26:06 +00:00
|
|
|
char **p;
|
|
|
|
|
|
|
|
if (input->selection_offer == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (p = input->selection_offer->types.data; *p; p++)
|
|
|
|
if (strcmp(mime_type, *p) == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (*p == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
data_offer_receive_data(input->selection_offer,
|
|
|
|
mime_type, func, data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_move(struct window *window, struct input *input, uint32_t time)
|
|
|
|
{
|
2011-11-29 08:25:08 +00:00
|
|
|
if (!window->shell_surface)
|
|
|
|
return;
|
|
|
|
|
2011-11-25 10:09:16 +00:00
|
|
|
wl_shell_surface_move(window->shell_surface,
|
|
|
|
input->input_device, time);
|
2010-08-18 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
2010-08-05 02:44:55 +00:00
|
|
|
static void
|
2011-11-25 10:09:16 +00:00
|
|
|
handle_configure(void *data, struct wl_shell_surface *shell_surface,
|
2010-08-05 02:44:55 +00:00
|
|
|
uint32_t time, uint32_t edges,
|
2011-11-25 10:09:16 +00:00
|
|
|
int32_t width, int32_t height)
|
2010-08-05 02:44:55 +00:00
|
|
|
{
|
2011-11-25 10:09:16 +00:00
|
|
|
struct window *window = data;
|
2011-01-11 15:00:52 +00:00
|
|
|
int32_t child_width, child_height;
|
2010-08-05 02:44:55 +00:00
|
|
|
|
2011-01-28 20:18:33 +00:00
|
|
|
/* FIXME: this is probably the wrong place to check for width
|
|
|
|
* or height <= 0, but it prevents the compositor from crashing
|
|
|
|
*/
|
|
|
|
if (width <= 0 || height <= 0)
|
2011-01-17 11:40:01 +00:00
|
|
|
return;
|
|
|
|
|
2011-01-17 16:50:07 +00:00
|
|
|
window->resize_edges = edges;
|
|
|
|
|
2011-01-11 15:00:52 +00:00
|
|
|
if (window->resize_handler) {
|
|
|
|
child_width = width - 20 - window->margin * 2;
|
|
|
|
child_height = height - 60 - window->margin * 2;
|
2010-12-17 14:53:12 +00:00
|
|
|
|
2011-01-11 15:00:52 +00:00
|
|
|
(*window->resize_handler)(window,
|
|
|
|
child_width, child_height,
|
|
|
|
window->user_data);
|
|
|
|
} else {
|
|
|
|
window->allocation.width = width;
|
|
|
|
window->allocation.height = height;
|
|
|
|
|
|
|
|
if (window->redraw_handler)
|
|
|
|
window_schedule_redraw(window);
|
|
|
|
}
|
2010-08-05 02:44:55 +00:00
|
|
|
}
|
|
|
|
|
2011-11-25 10:09:16 +00:00
|
|
|
static const struct wl_shell_surface_listener shell_surface_listener = {
|
2010-08-05 02:44:55 +00:00
|
|
|
handle_configure,
|
|
|
|
};
|
|
|
|
|
2011-02-18 22:00:55 +00:00
|
|
|
void
|
|
|
|
window_get_allocation(struct window *window,
|
|
|
|
struct rectangle *allocation)
|
|
|
|
{
|
|
|
|
*allocation = window->allocation;
|
|
|
|
}
|
|
|
|
|
2008-12-08 00:59:11 +00:00
|
|
|
void
|
2011-01-11 15:00:52 +00:00
|
|
|
window_get_child_allocation(struct window *window,
|
|
|
|
struct rectangle *allocation)
|
2008-12-08 00:59:11 +00:00
|
|
|
{
|
2011-09-06 22:02:34 +00:00
|
|
|
if (!window->decoration) {
|
2011-01-11 15:00:52 +00:00
|
|
|
*allocation = window->allocation;
|
2008-12-22 17:14:50 +00:00
|
|
|
} else {
|
2011-01-11 15:00:52 +00:00
|
|
|
allocation->x = window->margin + 10;
|
|
|
|
allocation->y = window->margin + 50;
|
|
|
|
allocation->width =
|
|
|
|
window->allocation.width - 20 - window->margin * 2;
|
|
|
|
allocation->height =
|
|
|
|
window->allocation.height - 60 - window->margin * 2;
|
2008-12-22 17:14:50 +00:00
|
|
|
}
|
2008-12-08 00:59:11 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 18:50:07 +00:00
|
|
|
void
|
2011-01-11 15:00:52 +00:00
|
|
|
window_set_child_size(struct window *window, int32_t width, int32_t height)
|
2008-12-08 18:50:07 +00:00
|
|
|
{
|
2011-09-06 22:02:34 +00:00
|
|
|
if (window->decoration) {
|
2011-01-28 20:18:33 +00:00
|
|
|
window->allocation.x = 20 + window->margin;
|
|
|
|
window->allocation.y = 60 + window->margin;
|
2011-01-11 15:00:52 +00:00
|
|
|
window->allocation.width = width + 20 + window->margin * 2;
|
|
|
|
window->allocation.height = height + 60 + window->margin * 2;
|
2011-01-28 20:18:33 +00:00
|
|
|
} else {
|
|
|
|
window->allocation.x = 0;
|
|
|
|
window->allocation.y = 0;
|
|
|
|
window->allocation.width = width;
|
|
|
|
window->allocation.height = height;
|
2008-12-22 17:14:50 +00:00
|
|
|
}
|
2008-12-08 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
2011-09-14 21:33:48 +00:00
|
|
|
static void
|
|
|
|
idle_redraw(struct task *task, uint32_t events)
|
2010-06-15 03:52:50 +00:00
|
|
|
{
|
2011-09-14 21:33:48 +00:00
|
|
|
struct window *window =
|
|
|
|
container_of(task, struct window, redraw_task);
|
2010-06-15 03:52:50 +00:00
|
|
|
|
|
|
|
window->redraw_handler(window, window->user_data);
|
|
|
|
window->redraw_scheduled = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_schedule_redraw(struct window *window)
|
|
|
|
{
|
|
|
|
if (!window->redraw_scheduled) {
|
2011-09-14 21:33:48 +00:00
|
|
|
window->redraw_task.run = idle_redraw;
|
|
|
|
display_defer(window->display, &window->redraw_task);
|
2010-06-15 03:52:50 +00:00
|
|
|
window->redraw_scheduled = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-06 22:02:34 +00:00
|
|
|
void
|
|
|
|
window_set_custom(struct window *window)
|
|
|
|
{
|
|
|
|
window->type = TYPE_CUSTOM;
|
|
|
|
}
|
|
|
|
|
2008-12-22 17:14:50 +00:00
|
|
|
void
|
|
|
|
window_set_fullscreen(struct window *window, int fullscreen)
|
|
|
|
{
|
2011-01-28 20:18:33 +00:00
|
|
|
int32_t width, height;
|
2011-11-26 22:27:37 +00:00
|
|
|
struct output *output;
|
2011-01-28 20:18:33 +00:00
|
|
|
|
2011-09-14 00:58:00 +00:00
|
|
|
if ((window->type == TYPE_FULLSCREEN) == fullscreen)
|
2011-01-28 20:18:33 +00:00
|
|
|
return;
|
|
|
|
|
2011-09-06 22:02:34 +00:00
|
|
|
if (fullscreen) {
|
2011-11-26 22:27:37 +00:00
|
|
|
output = display_get_output(window->display);
|
2011-09-06 22:02:34 +00:00
|
|
|
window->type = TYPE_FULLSCREEN;
|
2008-12-22 17:14:50 +00:00
|
|
|
window->saved_allocation = window->allocation;
|
2011-11-26 22:27:37 +00:00
|
|
|
width = output->allocation.width;
|
|
|
|
height = output->allocation.height;
|
2011-09-06 22:02:34 +00:00
|
|
|
window->decoration = 0;
|
2008-12-22 17:14:50 +00:00
|
|
|
} else {
|
2011-09-06 22:02:34 +00:00
|
|
|
window->type = TYPE_TOPLEVEL;
|
2011-01-28 20:18:33 +00:00
|
|
|
width = window->saved_allocation.width - 20 - window->margin * 2;
|
|
|
|
height = window->saved_allocation.height - 60 - window->margin * 2;
|
2011-09-06 22:02:34 +00:00
|
|
|
window->decoration = 1;
|
2008-12-22 17:14:50 +00:00
|
|
|
}
|
2011-01-28 20:18:33 +00:00
|
|
|
|
|
|
|
(*window->resize_handler)(window, width, height, window->user_data);
|
2008-12-08 00:59:11 +00:00
|
|
|
}
|
|
|
|
|
2010-06-08 18:08:30 +00:00
|
|
|
void
|
|
|
|
window_set_decoration(struct window *window, int decoration)
|
|
|
|
{
|
|
|
|
window->decoration = decoration;
|
|
|
|
}
|
|
|
|
|
2010-06-25 15:19:22 +00:00
|
|
|
void
|
|
|
|
window_set_user_data(struct window *window, void *data)
|
|
|
|
{
|
|
|
|
window->user_data = data;
|
|
|
|
}
|
|
|
|
|
2010-09-03 00:22:42 +00:00
|
|
|
void *
|
|
|
|
window_get_user_data(struct window *window)
|
|
|
|
{
|
|
|
|
return window->user_data;
|
|
|
|
}
|
|
|
|
|
2008-12-08 00:59:11 +00:00
|
|
|
void
|
|
|
|
window_set_resize_handler(struct window *window,
|
2010-06-25 15:19:22 +00:00
|
|
|
window_resize_handler_t handler)
|
2008-12-08 00:59:11 +00:00
|
|
|
{
|
|
|
|
window->resize_handler = handler;
|
|
|
|
}
|
|
|
|
|
2010-06-15 03:52:50 +00:00
|
|
|
void
|
|
|
|
window_set_redraw_handler(struct window *window,
|
2010-06-25 15:19:22 +00:00
|
|
|
window_redraw_handler_t handler)
|
2010-06-15 03:52:50 +00:00
|
|
|
{
|
|
|
|
window->redraw_handler = handler;
|
|
|
|
}
|
|
|
|
|
2008-12-08 00:59:11 +00:00
|
|
|
void
|
2008-12-30 16:03:33 +00:00
|
|
|
window_set_key_handler(struct window *window,
|
2010-06-25 15:19:22 +00:00
|
|
|
window_key_handler_t handler)
|
2008-12-08 00:59:11 +00:00
|
|
|
{
|
2008-12-30 16:03:33 +00:00
|
|
|
window->key_handler = handler;
|
2008-12-08 00:59:11 +00:00
|
|
|
}
|
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
void
|
|
|
|
window_set_button_handler(struct window *window,
|
|
|
|
window_button_handler_t handler)
|
|
|
|
{
|
|
|
|
window->button_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_set_motion_handler(struct window *window,
|
|
|
|
window_motion_handler_t handler)
|
|
|
|
{
|
|
|
|
window->motion_handler = handler;
|
|
|
|
}
|
|
|
|
|
2011-09-06 18:33:52 +00:00
|
|
|
void
|
|
|
|
window_set_enter_handler(struct window *window,
|
|
|
|
window_enter_handler_t handler)
|
|
|
|
{
|
|
|
|
window->enter_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_set_leave_handler(struct window *window,
|
|
|
|
window_leave_handler_t handler)
|
|
|
|
{
|
|
|
|
window->leave_handler = handler;
|
|
|
|
}
|
|
|
|
|
2009-02-23 04:01:35 +00:00
|
|
|
void
|
|
|
|
window_set_keyboard_focus_handler(struct window *window,
|
2010-06-25 15:19:22 +00:00
|
|
|
window_keyboard_focus_handler_t handler)
|
2009-02-23 04:01:35 +00:00
|
|
|
{
|
|
|
|
window->keyboard_focus_handler = handler;
|
|
|
|
}
|
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
void
|
|
|
|
window_set_item_focus_handler(struct window *window,
|
|
|
|
window_item_focus_handler_t handler)
|
|
|
|
{
|
|
|
|
window->item_focus_handler = handler;
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
void
|
|
|
|
window_set_data_handler(struct window *window, window_data_handler_t handler)
|
|
|
|
{
|
|
|
|
window->data_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_set_drop_handler(struct window *window, window_drop_handler_t handler)
|
|
|
|
{
|
|
|
|
window->drop_handler = handler;
|
|
|
|
}
|
|
|
|
|
2011-05-13 17:45:17 +00:00
|
|
|
void
|
|
|
|
window_set_transparent(struct window *window, int transparent)
|
|
|
|
{
|
|
|
|
window->transparent = transparent;
|
|
|
|
}
|
|
|
|
|
2011-01-14 07:46:23 +00:00
|
|
|
void
|
|
|
|
window_set_title(struct window *window, const char *title)
|
|
|
|
{
|
2011-01-25 17:45:37 +00:00
|
|
|
free(window->title);
|
2011-01-14 07:46:23 +00:00
|
|
|
window->title = strdup(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
window_get_title(struct window *window)
|
|
|
|
{
|
|
|
|
return window->title;
|
|
|
|
}
|
|
|
|
|
2011-03-07 14:08:09 +00:00
|
|
|
void
|
|
|
|
display_surface_damage(struct display *display, cairo_surface_t *cairo_surface,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
struct wl_buffer *buffer;
|
|
|
|
|
|
|
|
buffer = display_get_buffer_for_surface(display, cairo_surface);
|
|
|
|
|
|
|
|
wl_buffer_damage(buffer, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
void
|
|
|
|
window_damage(struct window *window, int32_t x, int32_t y,
|
|
|
|
int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
wl_surface_damage(window->surface, x, y, width, height);
|
|
|
|
}
|
|
|
|
|
2011-01-21 23:03:15 +00:00
|
|
|
static struct window *
|
|
|
|
window_create_internal(struct display *display, struct window *parent,
|
|
|
|
int32_t width, int32_t height)
|
2009-01-27 04:42:46 +00:00
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
|
|
|
|
window = malloc(sizeof *window);
|
|
|
|
if (window == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(window, 0, sizeof *window);
|
|
|
|
window->display = display;
|
2011-01-21 23:03:15 +00:00
|
|
|
window->parent = parent;
|
2009-01-27 04:42:46 +00:00
|
|
|
window->surface = wl_compositor_create_surface(display->compositor);
|
2011-11-29 08:25:08 +00:00
|
|
|
if (display->shell) {
|
|
|
|
window->shell_surface =
|
|
|
|
wl_shell_get_shell_surface(display->shell,
|
|
|
|
window->surface);
|
|
|
|
}
|
2010-12-17 14:53:12 +00:00
|
|
|
window->allocation.x = 0;
|
|
|
|
window->allocation.y = 0;
|
2009-01-27 04:42:46 +00:00
|
|
|
window->allocation.width = width;
|
|
|
|
window->allocation.height = height;
|
|
|
|
window->saved_allocation = window->allocation;
|
|
|
|
window->margin = 16;
|
2010-06-08 18:59:44 +00:00
|
|
|
window->decoration = 1;
|
2011-05-13 17:45:17 +00:00
|
|
|
window->transparent = 1;
|
2011-09-21 01:43:54 +00:00
|
|
|
wl_list_init(&window->item_list);
|
2009-01-27 04:42:46 +00:00
|
|
|
|
2011-02-04 19:11:33 +00:00
|
|
|
if (display->dpy)
|
2011-07-16 19:50:32 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-02-10 11:04:30 +00:00
|
|
|
/* FIXME: make TYPE_EGL_IMAGE choosable for testing */
|
|
|
|
window->buffer_type = WINDOW_BUFFER_TYPE_EGL_WINDOW;
|
2011-07-16 19:50:32 +00:00
|
|
|
#else
|
|
|
|
window->buffer_type = WINDOW_BUFFER_TYPE_SHM;
|
|
|
|
#endif
|
2010-12-06 14:18:12 +00:00
|
|
|
else
|
|
|
|
window->buffer_type = WINDOW_BUFFER_TYPE_SHM;
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2010-07-20 21:06:19 +00:00
|
|
|
wl_surface_set_user_data(window->surface, window);
|
2010-06-09 00:34:11 +00:00
|
|
|
wl_list_insert(display->window_list.prev, &window->link);
|
2009-01-27 04:42:46 +00:00
|
|
|
|
2011-11-29 08:25:08 +00:00
|
|
|
if (window->shell_surface) {
|
|
|
|
wl_shell_surface_set_user_data(window->shell_surface, window);
|
|
|
|
wl_shell_surface_add_listener(window->shell_surface,
|
|
|
|
&shell_surface_listener, window);
|
|
|
|
}
|
2011-11-25 10:09:16 +00:00
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2011-01-21 23:03:15 +00:00
|
|
|
struct window *
|
|
|
|
window_create(struct display *display, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
|
|
|
|
window = window_create_internal(display, NULL, width, height);
|
|
|
|
if (!window)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct window *
|
|
|
|
window_create_transient(struct display *display, struct window *parent,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
|
|
|
|
window = window_create_internal(parent->display,
|
|
|
|
parent, width, height);
|
|
|
|
if (!window)
|
|
|
|
return NULL;
|
|
|
|
|
2011-09-06 22:02:34 +00:00
|
|
|
window->type = TYPE_TRANSIENT;
|
2011-01-21 23:03:15 +00:00
|
|
|
window->x = x;
|
|
|
|
window->y = y;
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2011-12-19 20:40:10 +00:00
|
|
|
struct menu {
|
|
|
|
struct window *window;
|
|
|
|
const char **entries;
|
|
|
|
int current;
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
menu_set_item(struct window *window, struct menu *menu, int sy)
|
|
|
|
{
|
|
|
|
int next;
|
|
|
|
|
|
|
|
next = (sy - 8) / 20;
|
|
|
|
if (menu->current != next) {
|
|
|
|
menu->current = next;
|
|
|
|
window_schedule_redraw(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
return POINTER_LEFT_PTR;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
menu_motion_handler(struct window *window,
|
|
|
|
struct input *input, uint32_t time,
|
|
|
|
int32_t x, int32_t y,
|
|
|
|
int32_t sx, int32_t sy, void *data)
|
|
|
|
{
|
|
|
|
return menu_set_item(window, data, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
menu_enter_handler(struct window *window,
|
|
|
|
struct input *input, uint32_t time,
|
|
|
|
int32_t x, int32_t y, void *data)
|
|
|
|
{
|
|
|
|
return menu_set_item(window, data, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_leave_handler(struct window *window,
|
|
|
|
struct input *input, uint32_t time, void *data)
|
|
|
|
{
|
|
|
|
menu_set_item(window, data, -200);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_button_handler(struct window *window,
|
|
|
|
struct input *input, uint32_t time,
|
|
|
|
int button, int state, void *data)
|
|
|
|
|
|
|
|
{
|
|
|
|
struct menu *menu = data;
|
|
|
|
|
|
|
|
/* Either relase after press-drag-release or click-motion-click. */
|
|
|
|
if (state == 0 && 0 <= menu->current && menu->current < menu->count)
|
|
|
|
window_destroy(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_redraw_handler(struct window *window, void *data)
|
|
|
|
{
|
|
|
|
cairo_t *cr;
|
|
|
|
const int32_t r = 3, margin = 3;
|
|
|
|
struct menu *menu = data;
|
|
|
|
int32_t width, height, i;
|
|
|
|
|
|
|
|
width = 200;
|
|
|
|
height = menu->count * 20 + margin * 2;
|
|
|
|
window_set_child_size(window, width, height);
|
|
|
|
window_create_surface(window);
|
|
|
|
|
|
|
|
cr = cairo_create(window->cairo_surface);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
|
|
|
|
cairo_paint(cr);
|
|
|
|
|
|
|
|
width = window->allocation.width;
|
|
|
|
height = window->allocation.height;
|
|
|
|
rounded_rect(cr, 0, 0, width, height, r);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.4, 0.8);
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
|
|
|
for (i = 0; i < menu->count; i++) {
|
|
|
|
if (i == menu->current) {
|
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
|
|
|
cairo_rectangle(cr, margin, i * 20 + margin,
|
|
|
|
width - 2 * margin, 20);
|
|
|
|
cairo_fill(cr);
|
|
|
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
|
|
|
|
cairo_move_to(cr, 10, i * 20 + 16);
|
|
|
|
cairo_show_text(cr, menu->entries[i]);
|
|
|
|
} else {
|
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
|
|
|
cairo_move_to(cr, 10, i * 20 + 16);
|
|
|
|
cairo_show_text(cr, menu->entries[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
window_flush(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct window *
|
|
|
|
window_create_menu(struct display *display, struct window *parent,
|
|
|
|
int32_t x, int32_t y, const char **entries, int count)
|
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
struct menu *menu;
|
|
|
|
|
|
|
|
menu = malloc(sizeof *menu);
|
|
|
|
if (!menu)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
window = window_create_internal(parent->display, parent, 0, 0);
|
|
|
|
if (!window)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
menu->window = window;
|
|
|
|
menu->entries = entries;
|
|
|
|
menu->count = count;
|
|
|
|
window->decoration = 0;
|
|
|
|
window->type = TYPE_MENU;
|
|
|
|
window->x = x;
|
|
|
|
window->y = y;
|
|
|
|
|
|
|
|
wl_shell_surface_set_transient(window->shell_surface,
|
|
|
|
window->parent->shell_surface,
|
|
|
|
window->x, window->y, 0);
|
|
|
|
|
|
|
|
window_set_motion_handler(window, menu_motion_handler);
|
|
|
|
window_set_enter_handler(window, menu_enter_handler);
|
|
|
|
window_set_leave_handler(window, menu_leave_handler);
|
|
|
|
window_set_button_handler(window, menu_button_handler);
|
|
|
|
window_set_redraw_handler(window, menu_redraw_handler);
|
|
|
|
window_set_user_data(window, menu);
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
void
|
|
|
|
window_set_buffer_type(struct window *window, enum window_buffer_type type)
|
|
|
|
{
|
|
|
|
window->buffer_type = type;
|
|
|
|
}
|
|
|
|
|
2011-05-13 17:24:56 +00:00
|
|
|
|
2008-12-30 16:03:33 +00:00
|
|
|
static void
|
2009-01-27 04:42:46 +00:00
|
|
|
display_handle_geometry(void *data,
|
2011-06-21 15:16:58 +00:00
|
|
|
struct wl_output *wl_output,
|
|
|
|
int x, int y,
|
|
|
|
int physical_width,
|
|
|
|
int physical_height,
|
|
|
|
int subpixel,
|
|
|
|
const char *make,
|
|
|
|
const char *model)
|
2008-12-08 00:59:11 +00:00
|
|
|
{
|
2011-11-26 22:27:37 +00:00
|
|
|
struct output *output = data;
|
2008-12-30 16:03:33 +00:00
|
|
|
|
2011-11-26 22:27:37 +00:00
|
|
|
output->allocation.x = x;
|
|
|
|
output->allocation.y = y;
|
2011-06-21 15:16:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
display_handle_mode(void *data,
|
|
|
|
struct wl_output *wl_output,
|
|
|
|
uint32_t flags,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
int refresh)
|
|
|
|
{
|
2011-11-26 22:27:37 +00:00
|
|
|
struct output *output = data;
|
2011-11-30 08:52:38 +00:00
|
|
|
struct display *display = output->display;
|
2011-06-21 15:16:58 +00:00
|
|
|
|
2011-11-26 22:27:37 +00:00
|
|
|
if (flags & WL_OUTPUT_MODE_CURRENT) {
|
|
|
|
output->allocation.width = width;
|
|
|
|
output->allocation.height = height;
|
2011-11-30 08:52:38 +00:00
|
|
|
if (display->output_configure_handler)
|
|
|
|
(*display->output_configure_handler)(
|
|
|
|
output, display->user_data);
|
2011-11-26 22:27:37 +00:00
|
|
|
}
|
2008-12-08 00:59:11 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 16:03:33 +00:00
|
|
|
static const struct wl_output_listener output_listener = {
|
2009-01-27 04:42:46 +00:00
|
|
|
display_handle_geometry,
|
2011-06-21 15:16:58 +00:00
|
|
|
display_handle_mode
|
2008-12-30 16:03:33 +00:00
|
|
|
};
|
|
|
|
|
2011-11-26 22:27:37 +00:00
|
|
|
static void
|
|
|
|
display_add_output(struct display *d, uint32_t id)
|
|
|
|
{
|
|
|
|
struct output *output;
|
|
|
|
|
|
|
|
output = malloc(sizeof *output);
|
|
|
|
if (output == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(output, 0, sizeof *output);
|
|
|
|
output->display = d;
|
|
|
|
output->output =
|
|
|
|
wl_display_bind(d->display, id, &wl_output_interface);
|
|
|
|
wl_list_insert(d->output_list.prev, &output->link);
|
|
|
|
|
|
|
|
wl_output_add_listener(output->output, &output_listener, output);
|
|
|
|
}
|
|
|
|
|
2011-12-16 09:35:34 +00:00
|
|
|
static void
|
|
|
|
output_destroy(struct output *output)
|
|
|
|
{
|
|
|
|
if (output->destroy_handler)
|
|
|
|
(*output->destroy_handler)(output, output->user_data);
|
|
|
|
|
|
|
|
wl_output_destroy(output->output);
|
|
|
|
wl_list_remove(&output->link);
|
|
|
|
free(output);
|
|
|
|
}
|
|
|
|
|
2011-11-30 08:52:38 +00:00
|
|
|
void
|
|
|
|
display_set_output_configure_handler(struct display *display,
|
|
|
|
display_output_handler_t handler)
|
|
|
|
{
|
|
|
|
struct output *output;
|
|
|
|
|
|
|
|
display->output_configure_handler = handler;
|
|
|
|
if (!handler)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wl_list_for_each(output, &display->output_list, link)
|
|
|
|
(*display->output_configure_handler)(output,
|
|
|
|
display->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
output_set_user_data(struct output *output, void *data)
|
|
|
|
{
|
|
|
|
output->user_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
output_get_user_data(struct output *output)
|
|
|
|
{
|
|
|
|
return output->user_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
output_set_destroy_handler(struct output *output,
|
|
|
|
display_output_handler_t handler)
|
|
|
|
{
|
|
|
|
output->destroy_handler = handler;
|
|
|
|
/* FIXME: implement this, once we have way to remove outputs */
|
|
|
|
}
|
|
|
|
|
2011-11-26 22:27:37 +00:00
|
|
|
void
|
|
|
|
output_get_allocation(struct output *output, struct rectangle *allocation)
|
|
|
|
{
|
|
|
|
*allocation = output->allocation;
|
|
|
|
}
|
|
|
|
|
2011-11-30 08:52:38 +00:00
|
|
|
struct wl_output *
|
|
|
|
output_get_wl_output(struct output *output)
|
|
|
|
{
|
|
|
|
return output->output;
|
|
|
|
}
|
|
|
|
|
2010-07-20 21:06:19 +00:00
|
|
|
static void
|
2010-08-10 18:02:48 +00:00
|
|
|
display_add_input(struct display *d, uint32_t id)
|
2010-07-20 21:06:19 +00:00
|
|
|
{
|
|
|
|
struct input *input;
|
|
|
|
|
|
|
|
input = malloc(sizeof *input);
|
|
|
|
if (input == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
memset(input, 0, sizeof *input);
|
|
|
|
input->display = d;
|
2011-08-23 22:14:06 +00:00
|
|
|
input->input_device =
|
|
|
|
wl_display_bind(d->display, id, &wl_input_device_interface);
|
2010-07-20 21:06:19 +00:00
|
|
|
input->pointer_focus = NULL;
|
|
|
|
input->keyboard_focus = NULL;
|
|
|
|
wl_list_insert(d->input_list.prev, &input->link);
|
|
|
|
|
|
|
|
wl_input_device_add_listener(input->input_device,
|
|
|
|
&input_device_listener, input);
|
2010-08-18 19:28:04 +00:00
|
|
|
wl_input_device_set_user_data(input->input_device, input);
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
input->data_device =
|
|
|
|
wl_data_device_manager_get_data_device(d->data_device_manager,
|
|
|
|
input->input_device);
|
|
|
|
wl_data_device_add_listener(input->data_device,
|
|
|
|
&data_device_listener, input);
|
2011-01-19 19:27:42 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 10:02:09 +00:00
|
|
|
static void
|
|
|
|
input_destroy(struct input *input)
|
|
|
|
{
|
2011-12-21 22:11:45 +00:00
|
|
|
input_remove_keyboard_focus(input);
|
|
|
|
input_remove_pointer_focus(input, 0);
|
2011-12-16 10:02:09 +00:00
|
|
|
|
|
|
|
if (input->drag_offer)
|
|
|
|
data_offer_destroy(input->drag_offer);
|
|
|
|
|
|
|
|
if (input->selection_offer)
|
|
|
|
data_offer_destroy(input->selection_offer);
|
|
|
|
|
|
|
|
wl_data_device_destroy(input->data_device);
|
|
|
|
wl_list_remove(&input->link);
|
|
|
|
wl_input_device_destroy(input->input_device);
|
|
|
|
free(input);
|
|
|
|
}
|
|
|
|
|
2008-12-30 16:03:33 +00:00
|
|
|
static void
|
2010-08-10 18:02:48 +00:00
|
|
|
display_handle_global(struct wl_display *display, uint32_t id,
|
|
|
|
const char *interface, uint32_t version, void *data)
|
2008-12-08 05:01:36 +00:00
|
|
|
{
|
2009-01-27 04:42:46 +00:00
|
|
|
struct display *d = data;
|
2008-12-30 16:03:33 +00:00
|
|
|
|
2011-04-20 22:53:07 +00:00
|
|
|
if (strcmp(interface, "wl_compositor") == 0) {
|
2011-08-23 22:14:06 +00:00
|
|
|
d->compositor =
|
|
|
|
wl_display_bind(display, id, &wl_compositor_interface);
|
2011-04-20 22:53:07 +00:00
|
|
|
} else if (strcmp(interface, "wl_output") == 0) {
|
2011-11-26 22:27:37 +00:00
|
|
|
display_add_output(d, id);
|
2011-04-20 22:53:07 +00:00
|
|
|
} else if (strcmp(interface, "wl_input_device") == 0) {
|
2010-08-10 18:02:48 +00:00
|
|
|
display_add_input(d, id);
|
2011-04-20 22:53:07 +00:00
|
|
|
} else if (strcmp(interface, "wl_shell") == 0) {
|
2011-08-23 22:14:06 +00:00
|
|
|
d->shell = wl_display_bind(display, id, &wl_shell_interface);
|
2011-04-20 22:53:07 +00:00
|
|
|
} else if (strcmp(interface, "wl_shm") == 0) {
|
2011-08-23 22:14:06 +00:00
|
|
|
d->shm = wl_display_bind(display, id, &wl_shm_interface);
|
2011-10-28 16:26:06 +00:00
|
|
|
} else if (strcmp(interface, "wl_data_device_manager") == 0) {
|
|
|
|
d->data_device_manager =
|
|
|
|
wl_display_bind(display, id,
|
|
|
|
&wl_data_device_manager_interface);
|
2008-12-30 16:03:33 +00:00
|
|
|
}
|
2008-12-08 05:01:36 +00:00
|
|
|
}
|
|
|
|
|
2010-06-15 21:16:35 +00:00
|
|
|
static void
|
|
|
|
display_render_frame(struct display *d)
|
|
|
|
{
|
|
|
|
int radius = 8;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
d->shadow = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
|
|
|
|
cr = cairo_create(d->shadow);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_set_source_rgba(cr, 0, 0, 0, 1);
|
|
|
|
rounded_rect(cr, 16, 16, 112, 112, radius);
|
|
|
|
cairo_fill(cr);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
blur_surface(d->shadow, 64);
|
|
|
|
|
|
|
|
d->active_frame =
|
|
|
|
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
|
|
|
|
cr = cairo_create(d->active_frame);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_set_source_rgba(cr, 0.8, 0.8, 0.4, 1);
|
|
|
|
rounded_rect(cr, 16, 16, 112, 112, radius);
|
|
|
|
cairo_fill(cr);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
|
|
|
|
d->inactive_frame =
|
|
|
|
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 128, 128);
|
|
|
|
cr = cairo_create(d->inactive_frame);
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
|
|
|
cairo_set_source_rgba(cr, 0.6, 0.6, 0.6, 1);
|
|
|
|
rounded_rect(cr, 16, 16, 112, 112, radius);
|
|
|
|
cairo_fill(cr);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
}
|
|
|
|
|
2010-06-25 20:50:05 +00:00
|
|
|
static void
|
|
|
|
init_xkb(struct display *d)
|
|
|
|
{
|
2010-07-02 19:12:02 +00:00
|
|
|
struct xkb_rule_names names;
|
2010-06-25 20:50:05 +00:00
|
|
|
|
2010-07-02 19:12:02 +00:00
|
|
|
names.rules = "evdev";
|
|
|
|
names.model = "pc105";
|
2010-08-30 01:33:39 +00:00
|
|
|
names.layout = option_xkb_layout;
|
|
|
|
names.variant = option_xkb_variant;
|
|
|
|
names.options = option_xkb_options;
|
2010-06-25 20:50:05 +00:00
|
|
|
|
2010-07-02 19:12:02 +00:00
|
|
|
d->xkb = xkb_compile_keymap_from_rules(&names);
|
2010-06-25 20:50:05 +00:00
|
|
|
if (!d->xkb) {
|
|
|
|
fprintf(stderr, "Failed to compile keymap\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-15 13:20:04 +00:00
|
|
|
static void
|
|
|
|
fini_xkb(struct display *display)
|
|
|
|
{
|
|
|
|
xkb_free_keymap(display->xkb);
|
|
|
|
}
|
|
|
|
|
2010-12-06 14:18:12 +00:00
|
|
|
static int
|
2011-02-04 19:11:33 +00:00
|
|
|
init_egl(struct display *d)
|
2010-12-06 14:18:12 +00:00
|
|
|
{
|
|
|
|
EGLint major, minor;
|
2011-02-10 11:04:30 +00:00
|
|
|
EGLint n;
|
2011-08-31 20:21:38 +00:00
|
|
|
|
|
|
|
static const EGLint premul_argb_cfg_attribs[] = {
|
|
|
|
EGL_SURFACE_TYPE,
|
|
|
|
EGL_WINDOW_BIT | EGL_PIXMAP_BIT |
|
|
|
|
EGL_VG_ALPHA_FORMAT_PRE_BIT,
|
2011-02-10 11:04:30 +00:00
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
|
|
|
EGL_ALPHA_SIZE, 1,
|
|
|
|
EGL_DEPTH_SIZE, 1,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
2010-12-06 14:18:12 +00:00
|
|
|
|
2011-08-31 20:21:38 +00:00
|
|
|
static const EGLint rgb_cfg_attribs[] = {
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_BIT,
|
|
|
|
EGL_RED_SIZE, 1,
|
|
|
|
EGL_GREEN_SIZE, 1,
|
|
|
|
EGL_BLUE_SIZE, 1,
|
|
|
|
EGL_ALPHA_SIZE, 0,
|
|
|
|
EGL_DEPTH_SIZE, 1,
|
|
|
|
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
|
2011-04-14 18:44:58 +00:00
|
|
|
d->dpy = eglGetDisplay(d->display);
|
2010-12-06 14:18:12 +00:00
|
|
|
if (!eglInitialize(d->dpy, &major, &minor)) {
|
|
|
|
fprintf(stderr, "failed to initialize display\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglBindAPI(EGL_OPENGL_API)) {
|
|
|
|
fprintf(stderr, "failed to bind api EGL_OPENGL_API\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-08-31 20:21:38 +00:00
|
|
|
if (!eglChooseConfig(d->dpy, premul_argb_cfg_attribs,
|
2011-09-01 08:36:16 +00:00
|
|
|
&d->premultiplied_argb_config, 1, &n) || n != 1) {
|
2011-08-31 20:21:38 +00:00
|
|
|
fprintf(stderr, "failed to choose premul argb config\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!eglChooseConfig(d->dpy, rgb_cfg_attribs,
|
|
|
|
&d->rgb_config, 1, &n) || n != 1) {
|
|
|
|
fprintf(stderr, "failed to choose rgb config\n");
|
2011-02-10 11:04:30 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
d->rgb_ctx = eglCreateContext(d->dpy, d->rgb_config, EGL_NO_CONTEXT, NULL);
|
|
|
|
if (d->rgb_ctx == NULL) {
|
|
|
|
fprintf(stderr, "failed to create context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
d->argb_ctx = eglCreateContext(d->dpy, d->premultiplied_argb_config,
|
|
|
|
EGL_NO_CONTEXT, NULL);
|
|
|
|
if (d->argb_ctx == NULL) {
|
2010-12-06 14:18:12 +00:00
|
|
|
fprintf(stderr, "failed to create context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
if (!eglMakeCurrent(d->dpy, NULL, NULL, d->rgb_ctx)) {
|
2011-02-11 18:37:40 +00:00
|
|
|
fprintf(stderr, "failed to make context current\n");
|
2010-12-06 14:18:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-01-14 22:41:33 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-09-27 19:57:31 +00:00
|
|
|
d->rgb_device = cairo_egl_device_create(d->dpy, d->rgb_ctx);
|
|
|
|
if (cairo_device_status(d->rgb_device) != CAIRO_STATUS_SUCCESS) {
|
2011-02-04 19:11:33 +00:00
|
|
|
fprintf(stderr, "failed to get cairo egl device\n");
|
2010-12-06 14:18:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2011-09-27 19:57:31 +00:00
|
|
|
d->argb_device = cairo_egl_device_create(d->dpy, d->argb_ctx);
|
|
|
|
if (cairo_device_status(d->argb_device) != CAIRO_STATUS_SUCCESS) {
|
|
|
|
fprintf(stderr, "failed to get cairo egl argb device\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2010-12-06 14:18:12 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-15 13:20:04 +00:00
|
|
|
static void
|
|
|
|
fini_egl(struct display *display)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_CAIRO_EGL
|
|
|
|
cairo_device_destroy(display->argb_device);
|
|
|
|
cairo_device_destroy(display->rgb_device);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
eglMakeCurrent(display->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
eglTerminate(display->dpy);
|
|
|
|
eglReleaseThread();
|
|
|
|
}
|
|
|
|
|
2011-09-14 21:33:48 +00:00
|
|
|
static int
|
|
|
|
event_mask_update(uint32_t mask, void *data)
|
|
|
|
{
|
|
|
|
struct display *d = data;
|
|
|
|
|
|
|
|
d->mask = mask;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_display_data(struct task *task, uint32_t events)
|
|
|
|
{
|
|
|
|
struct display *display =
|
|
|
|
container_of(task, struct display, display_task);
|
|
|
|
|
|
|
|
wl_display_iterate(display->display, display->mask);
|
|
|
|
}
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
struct display *
|
2011-08-24 15:09:53 +00:00
|
|
|
display_create(int *argc, char **argv[], const GOptionEntry *option_entries)
|
2008-11-03 20:31:30 +00:00
|
|
|
{
|
2009-01-27 04:42:46 +00:00
|
|
|
struct display *d;
|
2010-06-08 18:59:44 +00:00
|
|
|
GOptionContext *context;
|
2010-08-30 01:33:39 +00:00
|
|
|
GOptionGroup *xkb_option_group;
|
2010-06-08 18:59:44 +00:00
|
|
|
GError *error;
|
2010-06-08 18:08:30 +00:00
|
|
|
|
2010-06-09 00:34:11 +00:00
|
|
|
g_type_init();
|
|
|
|
|
2010-06-08 18:59:44 +00:00
|
|
|
context = g_option_context_new(NULL);
|
2010-08-30 01:33:39 +00:00
|
|
|
if (option_entries)
|
2010-06-08 18:59:44 +00:00
|
|
|
g_option_context_add_main_entries(context, option_entries, "Wayland View");
|
2010-08-30 01:33:39 +00:00
|
|
|
|
|
|
|
xkb_option_group = g_option_group_new("xkb",
|
|
|
|
"Keyboard options",
|
|
|
|
"Show all XKB options",
|
|
|
|
NULL, NULL);
|
|
|
|
g_option_group_add_entries(xkb_option_group, xkb_option_entries);
|
|
|
|
g_option_context_add_group (context, xkb_option_group);
|
|
|
|
|
|
|
|
if (!g_option_context_parse(context, argc, argv, &error)) {
|
|
|
|
fprintf(stderr, "option parsing failed: %s\n", error->message);
|
|
|
|
exit(EXIT_FAILURE);
|
2010-06-08 18:59:44 +00:00
|
|
|
}
|
|
|
|
|
2011-01-23 22:25:25 +00:00
|
|
|
g_option_context_free(context);
|
2010-08-30 01:33:39 +00:00
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
d = malloc(sizeof *d);
|
|
|
|
if (d == NULL)
|
2008-11-07 20:54:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
2011-01-23 22:25:26 +00:00
|
|
|
memset(d, 0, sizeof *d);
|
|
|
|
|
2010-12-01 20:36:20 +00:00
|
|
|
d->display = wl_display_connect(NULL);
|
2010-06-09 00:34:11 +00:00
|
|
|
if (d->display == NULL) {
|
|
|
|
fprintf(stderr, "failed to create display: %m\n");
|
2010-06-08 18:59:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-14 21:33:48 +00:00
|
|
|
d->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
|
|
|
|
d->display_fd = wl_display_get_fd(d->display, event_mask_update, d);
|
|
|
|
d->display_task.run = handle_display_data;
|
|
|
|
display_watch_fd(d, d->display_fd, EPOLLIN, &d->display_task);
|
|
|
|
|
|
|
|
wl_list_init(&d->deferred_list);
|
2010-07-20 21:06:19 +00:00
|
|
|
wl_list_init(&d->input_list);
|
2011-11-26 22:27:37 +00:00
|
|
|
wl_list_init(&d->output_list);
|
2010-07-20 21:06:19 +00:00
|
|
|
|
2010-06-09 00:34:11 +00:00
|
|
|
/* Set up listener so we'll catch all events. */
|
|
|
|
wl_display_add_global_listener(d->display,
|
|
|
|
display_handle_global, d);
|
|
|
|
|
|
|
|
/* Process connection events. */
|
|
|
|
wl_display_iterate(d->display, WL_DISPLAY_READABLE);
|
2011-02-04 19:11:33 +00:00
|
|
|
if (init_egl(d) < 0)
|
2010-06-08 18:59:44 +00:00
|
|
|
return NULL;
|
2008-11-07 20:54:48 +00:00
|
|
|
|
2011-02-09 15:57:44 +00:00
|
|
|
d->image_target_texture_2d =
|
|
|
|
(void *) eglGetProcAddress("glEGLImageTargetTexture2DOES");
|
|
|
|
d->create_image = (void *) eglGetProcAddress("eglCreateImageKHR");
|
|
|
|
d->destroy_image = (void *) eglGetProcAddress("eglDestroyImageKHR");
|
|
|
|
|
2010-08-18 19:28:04 +00:00
|
|
|
create_pointer_surfaces(d);
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2010-06-15 21:16:35 +00:00
|
|
|
display_render_frame(d);
|
|
|
|
|
2010-06-09 00:34:11 +00:00
|
|
|
wl_list_init(&d->window_list);
|
|
|
|
|
2010-06-25 20:50:05 +00:00
|
|
|
init_xkb(d);
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2011-12-16 09:35:34 +00:00
|
|
|
static void
|
|
|
|
display_destroy_outputs(struct display *display)
|
|
|
|
{
|
|
|
|
struct output *tmp;
|
|
|
|
struct output *output;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(output, tmp, &display->output_list, link)
|
|
|
|
output_destroy(output);
|
|
|
|
}
|
|
|
|
|
2011-12-16 10:02:09 +00:00
|
|
|
static void
|
|
|
|
display_destroy_inputs(struct display *display)
|
|
|
|
{
|
|
|
|
struct input *tmp;
|
|
|
|
struct input *input;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(input, tmp, &display->input_list, link)
|
|
|
|
input_destroy(input);
|
|
|
|
}
|
|
|
|
|
2011-12-15 13:20:04 +00:00
|
|
|
void
|
|
|
|
display_destroy(struct display *display)
|
|
|
|
{
|
2011-12-16 09:41:32 +00:00
|
|
|
if (!wl_list_empty(&display->window_list))
|
|
|
|
fprintf(stderr, "toytoolkit warning: windows exist.\n");
|
|
|
|
|
|
|
|
if (!wl_list_empty(&display->deferred_list))
|
|
|
|
fprintf(stderr, "toytoolkit warning: deferred tasks exist.\n");
|
|
|
|
|
2011-12-16 09:35:34 +00:00
|
|
|
display_destroy_outputs(display);
|
2011-12-16 10:02:09 +00:00
|
|
|
display_destroy_inputs(display);
|
2011-12-16 09:35:34 +00:00
|
|
|
|
2011-12-15 13:20:04 +00:00
|
|
|
fini_xkb(display);
|
2011-12-19 08:31:45 +00:00
|
|
|
|
|
|
|
cairo_surface_destroy(display->active_frame);
|
|
|
|
cairo_surface_destroy(display->inactive_frame);
|
|
|
|
cairo_surface_destroy(display->shadow);
|
|
|
|
destroy_pointer_surfaces(display);
|
|
|
|
|
2011-12-15 13:20:04 +00:00
|
|
|
fini_egl(display);
|
|
|
|
|
2011-12-16 09:41:32 +00:00
|
|
|
if (display->shell)
|
|
|
|
wl_shell_destroy(display->shell);
|
|
|
|
|
|
|
|
if (display->shm)
|
|
|
|
wl_shm_destroy(display->shm);
|
|
|
|
|
|
|
|
if (display->data_device_manager)
|
|
|
|
wl_data_device_manager_destroy(display->data_device_manager);
|
|
|
|
|
|
|
|
wl_compositor_destroy(display->compositor);
|
|
|
|
|
|
|
|
close(display->epoll_fd);
|
|
|
|
|
2011-12-15 13:20:04 +00:00
|
|
|
wl_display_flush(display->display);
|
|
|
|
wl_display_destroy(display->display);
|
|
|
|
free(display);
|
|
|
|
}
|
|
|
|
|
2011-11-30 08:52:38 +00:00
|
|
|
void
|
|
|
|
display_set_user_data(struct display *display, void *data)
|
|
|
|
{
|
|
|
|
display->user_data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
display_get_user_data(struct display *display)
|
|
|
|
{
|
|
|
|
return display->user_data;
|
|
|
|
}
|
|
|
|
|
2010-09-03 18:46:38 +00:00
|
|
|
struct wl_display *
|
|
|
|
display_get_display(struct display *display)
|
|
|
|
{
|
|
|
|
return display->display;
|
|
|
|
}
|
|
|
|
|
2011-11-26 22:27:37 +00:00
|
|
|
struct output *
|
|
|
|
display_get_output(struct display *display)
|
|
|
|
{
|
|
|
|
return container_of(display->output_list.next, struct output, link);
|
|
|
|
}
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
struct wl_compositor *
|
|
|
|
display_get_compositor(struct display *display)
|
|
|
|
{
|
|
|
|
return display->compositor;
|
2008-11-02 23:51:48 +00:00
|
|
|
}
|
2010-06-08 18:59:44 +00:00
|
|
|
|
|
|
|
EGLDisplay
|
|
|
|
display_get_egl_display(struct display *d)
|
|
|
|
{
|
|
|
|
return d->dpy;
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
struct wl_data_source *
|
|
|
|
display_create_data_source(struct display *display)
|
|
|
|
{
|
|
|
|
return wl_data_device_manager_create_data_source(display->data_device_manager);
|
|
|
|
}
|
|
|
|
|
2011-02-18 22:00:55 +00:00
|
|
|
EGLConfig
|
2011-09-27 19:57:31 +00:00
|
|
|
display_get_rgb_egl_config(struct display *d)
|
2011-02-18 22:00:55 +00:00
|
|
|
{
|
2011-08-31 20:21:38 +00:00
|
|
|
return d->rgb_config;
|
2011-02-18 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
EGLConfig
|
|
|
|
display_get_argb_egl_config(struct display *d)
|
|
|
|
{
|
|
|
|
return d->premultiplied_argb_config;
|
|
|
|
}
|
|
|
|
|
2011-01-19 19:27:42 +00:00
|
|
|
struct wl_shell *
|
|
|
|
display_get_shell(struct display *display)
|
|
|
|
{
|
|
|
|
return display->shell;
|
|
|
|
}
|
|
|
|
|
2011-10-07 07:33:06 +00:00
|
|
|
int
|
2011-02-18 22:00:55 +00:00
|
|
|
display_acquire_window_surface(struct display *display,
|
|
|
|
struct window *window,
|
|
|
|
EGLContext ctx)
|
|
|
|
{
|
2011-07-16 19:50:32 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-02-18 22:00:55 +00:00
|
|
|
struct egl_window_surface_data *data;
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_t *device;
|
2011-02-18 22:00:55 +00:00
|
|
|
|
|
|
|
if (!window->cairo_surface)
|
2011-10-07 07:33:06 +00:00
|
|
|
return -1;
|
2011-09-27 19:57:31 +00:00
|
|
|
device = cairo_surface_get_device(window->cairo_surface);
|
|
|
|
if (!device)
|
2011-10-07 07:33:06 +00:00
|
|
|
return -1;
|
2011-02-18 22:00:55 +00:00
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
if (!ctx) {
|
|
|
|
if (device == display->rgb_device)
|
|
|
|
ctx = display->rgb_ctx;
|
|
|
|
else if (device == display->argb_device)
|
|
|
|
ctx = display->argb_ctx;
|
|
|
|
else
|
|
|
|
assert(0);
|
|
|
|
}
|
2011-02-18 22:00:55 +00:00
|
|
|
|
|
|
|
data = cairo_surface_get_user_data(window->cairo_surface,
|
|
|
|
&surface_data_key);
|
|
|
|
|
2011-12-19 11:57:59 +00:00
|
|
|
cairo_device_flush(device);
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_acquire(device);
|
2011-02-18 22:00:55 +00:00
|
|
|
if (!eglMakeCurrent(display->dpy, data->surf, data->surf, ctx))
|
|
|
|
fprintf(stderr, "failed to make surface current\n");
|
2011-10-07 07:33:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
return -1;
|
2011-07-16 19:50:32 +00:00
|
|
|
#endif
|
2011-02-18 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-09-27 19:57:31 +00:00
|
|
|
display_release_window_surface(struct display *display,
|
|
|
|
struct window *window)
|
2011-02-18 22:00:55 +00:00
|
|
|
{
|
2011-09-27 19:57:31 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
|
|
|
cairo_device_t *device;
|
|
|
|
|
|
|
|
device = cairo_surface_get_device(window->cairo_surface);
|
|
|
|
if (!device)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!eglMakeCurrent(display->dpy, NULL, NULL, display->rgb_ctx))
|
2011-02-18 22:00:55 +00:00
|
|
|
fprintf(stderr, "failed to make context current\n");
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_release(device);
|
|
|
|
#endif
|
2011-02-18 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
2010-06-08 18:59:44 +00:00
|
|
|
void
|
2011-09-14 21:33:48 +00:00
|
|
|
display_defer(struct display *display, struct task *task)
|
|
|
|
{
|
|
|
|
wl_list_insert(&display->deferred_list, &task->link);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
display_watch_fd(struct display *display,
|
|
|
|
int fd, uint32_t events, struct task *task)
|
2010-06-08 18:59:44 +00:00
|
|
|
{
|
2011-09-14 21:33:48 +00:00
|
|
|
struct epoll_event ep;
|
|
|
|
|
|
|
|
ep.events = events;
|
|
|
|
ep.data.ptr = task;
|
|
|
|
epoll_ctl(display->epoll_fd, EPOLL_CTL_ADD, fd, &ep);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
display_run(struct display *display)
|
|
|
|
{
|
|
|
|
struct task *task;
|
|
|
|
struct epoll_event ep[16];
|
|
|
|
int i, count;
|
|
|
|
|
2011-12-15 08:14:07 +00:00
|
|
|
display->running = 1;
|
2011-09-14 21:33:48 +00:00
|
|
|
while (1) {
|
|
|
|
while (display->mask & WL_DISPLAY_WRITABLE)
|
|
|
|
wl_display_iterate(display->display,
|
|
|
|
WL_DISPLAY_WRITABLE);
|
|
|
|
|
2011-12-15 08:14:07 +00:00
|
|
|
if (!display->running)
|
|
|
|
break;
|
|
|
|
|
2011-09-14 21:33:48 +00:00
|
|
|
count = epoll_wait(display->epoll_fd,
|
|
|
|
ep, ARRAY_LENGTH(ep), -1);
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
task = ep[i].data.ptr;
|
|
|
|
task->run(task, ep[i].events);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!wl_list_empty(&display->deferred_list)) {
|
|
|
|
task = container_of(display->deferred_list.next,
|
|
|
|
struct task, link);
|
|
|
|
wl_list_remove(&task->link);
|
|
|
|
task->run(task, 0);
|
|
|
|
}
|
|
|
|
}
|
2010-06-08 18:59:44 +00:00
|
|
|
}
|
2011-12-15 08:14:07 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
display_exit(struct display *display)
|
|
|
|
{
|
|
|
|
display->running = 0;
|
|
|
|
}
|