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>
|
2010-10-25 15:40:03 +00:00
|
|
|
#include <sys/mman.h>
|
2011-09-14 21:33:48 +00:00
|
|
|
#include <sys/epoll.h>
|
2012-05-23 19:06:27 +00:00
|
|
|
#include <sys/timerfd.h>
|
2010-06-08 18:08:30 +00:00
|
|
|
|
2012-03-12 05:05:25 +00:00
|
|
|
#include <pixman.h>
|
|
|
|
|
2011-02-09 15:51:15 +00:00
|
|
|
#include <wayland-egl.h>
|
|
|
|
|
2012-03-12 00:48:41 +00:00
|
|
|
#ifdef USE_CAIRO_GLESV2
|
|
|
|
#include <GLES2/gl2.h>
|
|
|
|
#include <GLES2/gl2ext.h>
|
|
|
|
#else
|
2010-06-08 18:08:30 +00:00
|
|
|
#include <GL/gl.h>
|
2012-03-12 00:48:41 +00:00
|
|
|
#endif
|
2010-06-08 18:08:30 +00:00
|
|
|
#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
|
|
|
|
2012-02-15 16:33:21 +00:00
|
|
|
#include <xkbcommon/xkbcommon.h>
|
2012-05-22 12:39:42 +00:00
|
|
|
#include <wayland-cursor.h>
|
2010-06-25 20:50:05 +00:00
|
|
|
|
2008-12-12 04:18:45 +00:00
|
|
|
#include <linux/input.h>
|
2011-11-22 12:18:50 +00:00
|
|
|
#include <wayland-client.h>
|
2012-05-16 02:33:43 +00:00
|
|
|
#include "../shared/cairo-util.h"
|
2012-05-27 20:25:02 +00:00
|
|
|
#include "text-cursor-position-client-protocol.h"
|
2012-05-30 12:53:43 +00:00
|
|
|
#include "../shared/os-compatibility.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
|
|
|
|
2012-05-07 18:34:26 +00:00
|
|
|
struct shm_pool;
|
2012-05-03 09:29:46 +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;
|
2012-05-27 20:25:02 +00:00
|
|
|
struct text_cursor_position *text_cursor_position;
|
2010-06-08 18:08:30 +00:00
|
|
|
EGLDisplay dpy;
|
2012-01-11 19:24:46 +00:00
|
|
|
EGLConfig argb_config;
|
2011-09-27 19:57:31 +00:00
|
|
|
EGLContext argb_ctx;
|
|
|
|
cairo_device_t *argb_device;
|
2012-04-12 02:42:15 +00:00
|
|
|
uint32_t serial;
|
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;
|
2012-05-16 02:12:54 +00:00
|
|
|
|
2012-05-16 02:25:28 +00:00
|
|
|
struct theme *theme;
|
2012-05-08 19:55:39 +00:00
|
|
|
|
2012-05-22 12:39:42 +00:00
|
|
|
struct wl_cursor_theme *cursor_theme;
|
2012-05-25 06:30:02 +00:00
|
|
|
struct wl_cursor **cursors;
|
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;
|
2012-05-30 15:32:01 +00:00
|
|
|
|
|
|
|
struct xkb_context *xkb_context;
|
2009-01-27 04:42:46 +00:00
|
|
|
};
|
|
|
|
|
2011-09-06 22:02:34 +00:00
|
|
|
enum {
|
2012-04-27 21:17:12 +00:00
|
|
|
TYPE_NONE,
|
2011-09-06 22:02:34 +00:00
|
|
|
TYPE_TOPLEVEL,
|
2011-09-08 20:56:38 +00:00
|
|
|
TYPE_FULLSCREEN,
|
2012-02-16 20:53:46 +00:00
|
|
|
TYPE_MAXIMIZED,
|
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
|
|
|
|
};
|
2012-05-15 16:55:34 +00:00
|
|
|
|
|
|
|
struct window_output {
|
|
|
|
struct output *output;
|
|
|
|
struct wl_list link;
|
|
|
|
};
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
struct window {
|
|
|
|
struct display *display;
|
2011-01-21 23:03:15 +00:00
|
|
|
struct window *parent;
|
2012-05-15 16:55:34 +00:00
|
|
|
struct wl_list window_output_list;
|
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;
|
2012-02-23 22:30:45 +00:00
|
|
|
struct wl_region *input_region;
|
|
|
|
struct wl_region *opaque_region;
|
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;
|
2012-01-31 20:30:47 +00:00
|
|
|
struct rectangle pending_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;
|
2012-03-24 18:42:09 +00:00
|
|
|
int redraw_needed;
|
2011-09-14 21:33:48 +00:00
|
|
|
struct task redraw_task;
|
2012-03-26 17:49:29 +00:00
|
|
|
int resize_needed;
|
2011-09-06 22:02:34 +00:00
|
|
|
int type;
|
2011-05-13 17:45:17 +00:00
|
|
|
int transparent;
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input *keyboard_device;
|
2010-10-25 15:40:03 +00:00
|
|
|
enum window_buffer_type buffer_type;
|
2008-11-08 20:06:01 +00:00
|
|
|
|
2012-04-10 15:23:13 +00:00
|
|
|
cairo_surface_t *cairo_surface;
|
2008-12-08 00:59:11 +00:00
|
|
|
|
2012-05-07 18:34:26 +00:00
|
|
|
struct shm_pool *pool;
|
2012-04-03 16:00:48 +00:00
|
|
|
|
2008-12-08 05:01:36 +00:00
|
|
|
window_key_handler_t key_handler;
|
2009-02-23 04:01:35 +00:00
|
|
|
window_keyboard_focus_handler_t keyboard_focus_handler;
|
2011-10-28 16:26:06 +00:00
|
|
|
window_data_handler_t data_handler;
|
|
|
|
window_drop_handler_t drop_handler;
|
2012-01-07 02:59:05 +00:00
|
|
|
window_close_handler_t close_handler;
|
2011-09-21 01:43:54 +00:00
|
|
|
|
2012-01-19 11:33:50 +00:00
|
|
|
struct frame *frame;
|
2012-01-10 18:52:34 +00:00
|
|
|
struct widget *widget;
|
2012-01-07 02:59:05 +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
|
|
|
};
|
|
|
|
|
2012-01-08 20:09:53 +00:00
|
|
|
struct widget {
|
2012-01-08 20:18:19 +00:00
|
|
|
struct window *window;
|
2012-05-23 19:06:27 +00:00
|
|
|
struct tooltip *tooltip;
|
2012-01-10 18:52:34 +00:00
|
|
|
struct wl_list child_list;
|
2011-09-21 01:43:54 +00:00
|
|
|
struct wl_list link;
|
|
|
|
struct rectangle allocation;
|
2012-01-10 17:23:19 +00:00
|
|
|
widget_resize_handler_t resize_handler;
|
|
|
|
widget_redraw_handler_t redraw_handler;
|
2012-01-09 13:42:24 +00:00
|
|
|
widget_enter_handler_t enter_handler;
|
|
|
|
widget_leave_handler_t leave_handler;
|
2012-01-09 14:36:16 +00:00
|
|
|
widget_motion_handler_t motion_handler;
|
2012-01-09 16:12:05 +00:00
|
|
|
widget_button_handler_t button_handler;
|
2011-09-21 01:43:54 +00:00
|
|
|
void *user_data;
|
2012-02-23 22:30:45 +00:00
|
|
|
int opaque;
|
2012-05-23 19:06:27 +00:00
|
|
|
int tooltip_count;
|
2011-09-21 01:43:54 +00:00
|
|
|
};
|
|
|
|
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input {
|
|
|
|
struct display *display;
|
2012-05-16 17:45:18 +00:00
|
|
|
struct wl_seat *seat;
|
|
|
|
struct wl_pointer *pointer;
|
|
|
|
struct wl_keyboard *keyboard;
|
2010-07-20 21:06:19 +00:00
|
|
|
struct window *pointer_focus;
|
|
|
|
struct window *keyboard_focus;
|
2012-05-03 09:29:46 +00:00
|
|
|
int current_cursor;
|
2012-06-15 14:27:35 +00:00
|
|
|
struct wl_surface *pointer_surface;
|
2010-07-20 21:06:19 +00:00
|
|
|
uint32_t modifiers;
|
2012-04-12 02:42:15 +00:00
|
|
|
uint32_t pointer_enter_serial;
|
2012-05-10 16:21:37 +00:00
|
|
|
float sx, sy;
|
2010-07-20 21:06:19 +00:00
|
|
|
struct wl_list link;
|
2011-10-28 16:26:06 +00:00
|
|
|
|
2012-01-11 05:04:42 +00:00
|
|
|
struct widget *focus_widget;
|
2012-01-11 04:46:33 +00:00
|
|
|
struct widget *grab;
|
|
|
|
uint32_t grab_button;
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
struct wl_data_device *data_device;
|
|
|
|
struct data_offer *drag_offer;
|
|
|
|
struct data_offer *selection_offer;
|
2012-05-30 15:32:01 +00:00
|
|
|
|
|
|
|
struct {
|
|
|
|
struct xkb_keymap *keymap;
|
|
|
|
struct xkb_state *state;
|
|
|
|
xkb_mod_mask_t control_mask;
|
|
|
|
xkb_mod_mask_t alt_mask;
|
|
|
|
xkb_mod_mask_t shift_mask;
|
|
|
|
} xkb;
|
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
|
|
|
};
|
|
|
|
|
2012-05-10 00:04:35 +00:00
|
|
|
enum frame_button_action {
|
|
|
|
FRAME_BUTTON_NULL = 0,
|
|
|
|
FRAME_BUTTON_ICON = 1,
|
|
|
|
FRAME_BUTTON_CLOSE = 2,
|
|
|
|
FRAME_BUTTON_MINIMIZE = 3,
|
|
|
|
FRAME_BUTTON_MAXIMIZE = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum frame_button_pointer {
|
|
|
|
FRAME_BUTTON_DEFAULT = 0,
|
|
|
|
FRAME_BUTTON_OVER = 1,
|
|
|
|
FRAME_BUTTON_ACTIVE = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum frame_button_align {
|
|
|
|
FRAME_BUTTON_RIGHT = 0,
|
|
|
|
FRAME_BUTTON_LEFT = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum frame_button_decoration {
|
|
|
|
FRAME_BUTTON_NONE = 0,
|
|
|
|
FRAME_BUTTON_FANCY = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct frame_button {
|
|
|
|
struct widget *widget;
|
|
|
|
struct frame *frame;
|
|
|
|
cairo_surface_t *icon;
|
|
|
|
enum frame_button_action type;
|
|
|
|
enum frame_button_pointer state;
|
|
|
|
struct wl_list link; /* buttons_list */
|
|
|
|
enum frame_button_align align;
|
|
|
|
enum frame_button_decoration decoration;
|
|
|
|
};
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
struct frame {
|
|
|
|
struct widget *widget;
|
|
|
|
struct widget *child;
|
2012-05-10 00:04:35 +00:00
|
|
|
struct wl_list buttons_list;
|
2012-01-11 03:41:05 +00:00
|
|
|
};
|
|
|
|
|
2012-01-07 02:59:05 +00:00
|
|
|
struct menu {
|
|
|
|
struct window *window;
|
2012-01-10 14:43:58 +00:00
|
|
|
struct widget *widget;
|
2012-01-11 04:46:33 +00:00
|
|
|
struct input *input;
|
2012-01-07 02:59:05 +00:00
|
|
|
const char **entries;
|
|
|
|
uint32_t time;
|
|
|
|
int current;
|
|
|
|
int count;
|
|
|
|
menu_func_t func;
|
|
|
|
};
|
|
|
|
|
2012-05-23 19:06:27 +00:00
|
|
|
struct tooltip {
|
|
|
|
struct widget *parent;
|
|
|
|
struct window *window;
|
|
|
|
struct widget *widget;
|
|
|
|
char *entry;
|
|
|
|
struct task tooltip_task;
|
|
|
|
int tooltip_fd;
|
|
|
|
float x, y;
|
|
|
|
};
|
|
|
|
|
2012-05-07 18:34:26 +00:00
|
|
|
struct shm_pool {
|
|
|
|
struct wl_shm_pool *pool;
|
|
|
|
size_t size;
|
|
|
|
size_t used;
|
|
|
|
void *data;
|
|
|
|
};
|
|
|
|
|
2010-09-08 01:50:06 +00:00
|
|
|
enum {
|
2012-05-25 13:01:41 +00:00
|
|
|
CURSOR_DEFAULT = 100,
|
|
|
|
CURSOR_UNSET
|
2010-09-08 01:50:06 +00:00
|
|
|
};
|
|
|
|
|
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 = "";
|
|
|
|
|
2012-03-12 01:05:57 +00:00
|
|
|
static const struct weston_option xkb_options[] = {
|
|
|
|
{ WESTON_OPTION_STRING, "xkb-layout", 0, &option_xkb_layout },
|
|
|
|
{ WESTON_OPTION_STRING, "xkb-variant", 0, &option_xkb_variant },
|
|
|
|
{ WESTON_OPTION_STRING, "xkb-options", 0, &option_xkb_options },
|
2010-08-30 01:33:39 +00:00
|
|
|
};
|
|
|
|
|
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;
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_t *device;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
|
|
|
data = malloc(sizeof *data);
|
|
|
|
if (data == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
data->display = display;
|
|
|
|
data->surface = surface;
|
|
|
|
|
2012-02-29 21:15:53 +00:00
|
|
|
config = display->argb_config;
|
|
|
|
device = display->argb_device;
|
2011-08-31 20:21:38 +00:00
|
|
|
|
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,
|
2012-01-11 19:24:46 +00:00
|
|
|
data->window, NULL);
|
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;
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
#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;
|
2012-05-07 18:34:26 +00:00
|
|
|
struct shm_pool *pool;
|
2010-10-25 15:40:03 +00:00
|
|
|
};
|
|
|
|
|
2012-05-07 18:34:26 +00:00
|
|
|
static void
|
|
|
|
shm_pool_destroy(struct shm_pool *pool);
|
|
|
|
|
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);
|
2012-05-07 18:34:26 +00:00
|
|
|
if (data->pool)
|
|
|
|
shm_pool_destroy(data->pool);
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
2012-04-03 15:21:27 +00:00
|
|
|
static struct wl_shm_pool *
|
|
|
|
make_shm_pool(struct display *display, int size, void **data)
|
2010-10-25 15:40:03 +00:00
|
|
|
{
|
2012-04-03 15:21:27 +00:00
|
|
|
struct wl_shm_pool *pool;
|
|
|
|
int fd;
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2012-06-06 13:59:43 +00:00
|
|
|
fd = os_create_anonymous_file(size);
|
2010-10-25 15:40:03 +00:00
|
|
|
if (fd < 0) {
|
2012-06-06 13:59:43 +00:00
|
|
|
fprintf(stderr, "creating a buffer file for %d B failed: %m\n",
|
|
|
|
size);
|
2010-10-25 15:40:03 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-03 15:21:27 +00:00
|
|
|
*data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
if (*data == 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;
|
|
|
|
}
|
|
|
|
|
2012-04-03 15:21:27 +00:00
|
|
|
pool = wl_shm_create_pool(display->shm, fd, size);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
2012-05-07 18:34:26 +00:00
|
|
|
static struct shm_pool *
|
|
|
|
shm_pool_create(struct display *display, size_t size)
|
|
|
|
{
|
|
|
|
struct shm_pool *pool = malloc(sizeof *pool);
|
|
|
|
|
|
|
|
if (!pool)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
pool->pool = make_shm_pool(display, size, &pool->data);
|
|
|
|
if (!pool->pool) {
|
|
|
|
free(pool);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pool->size = size;
|
|
|
|
pool->used = 0;
|
|
|
|
|
|
|
|
return pool;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
|
|
|
shm_pool_allocate(struct shm_pool *pool, size_t size, int *offset)
|
|
|
|
{
|
|
|
|
if (pool->used + size > pool->size)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*offset = pool->used;
|
|
|
|
pool->used += size;
|
|
|
|
|
|
|
|
return (char *) pool->data + *offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* destroy the pool. this does not unmap the memory though */
|
|
|
|
static void
|
|
|
|
shm_pool_destroy(struct shm_pool *pool)
|
|
|
|
{
|
|
|
|
munmap(pool->data, pool->size);
|
|
|
|
wl_shm_pool_destroy(pool->pool);
|
|
|
|
free(pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start allocating from the beginning of the pool again */
|
|
|
|
static void
|
|
|
|
shm_pool_reset(struct shm_pool *pool)
|
|
|
|
{
|
|
|
|
pool->used = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
data_length_for_shm_surface(struct rectangle *rect)
|
|
|
|
{
|
|
|
|
int stride;
|
|
|
|
|
|
|
|
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
|
|
|
|
rect->width);
|
|
|
|
return stride * rect->height;
|
|
|
|
}
|
|
|
|
|
2012-04-03 15:21:27 +00:00
|
|
|
static cairo_surface_t *
|
2012-05-07 18:34:26 +00:00
|
|
|
display_create_shm_surface_from_pool(struct display *display,
|
|
|
|
struct rectangle *rectangle,
|
|
|
|
uint32_t flags, struct shm_pool *pool)
|
2012-04-03 15:21:27 +00:00
|
|
|
{
|
|
|
|
struct shm_surface_data *data;
|
|
|
|
uint32_t format;
|
|
|
|
cairo_surface_t *surface;
|
2012-05-07 18:34:26 +00:00
|
|
|
int stride, length, offset;
|
2012-04-03 16:00:48 +00:00
|
|
|
void *map;
|
2012-04-03 15:21:27 +00:00
|
|
|
|
|
|
|
data = malloc(sizeof *data);
|
|
|
|
if (data == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
stride = cairo_format_stride_for_width (CAIRO_FORMAT_ARGB32,
|
|
|
|
rectangle->width);
|
2012-05-07 18:34:26 +00:00
|
|
|
length = stride * rectangle->height;
|
|
|
|
data->pool = NULL;
|
|
|
|
map = shm_pool_allocate(pool, length, &offset);
|
|
|
|
|
|
|
|
if (!map) {
|
|
|
|
free(data);
|
|
|
|
return NULL;
|
2012-04-03 16:00:48 +00:00
|
|
|
}
|
2012-04-03 15:21:27 +00:00
|
|
|
|
2012-04-03 16:00:48 +00:00
|
|
|
surface = cairo_image_surface_create_for_data (map,
|
2010-10-25 15:40:03 +00:00
|
|
|
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)
|
2012-01-11 19:24:46 +00:00
|
|
|
format = WL_SHM_FORMAT_XRGB8888;
|
2011-05-13 17:45:17 +00:00
|
|
|
else
|
2012-01-11 19:24:46 +00:00
|
|
|
format = WL_SHM_FORMAT_ARGB8888;
|
2011-05-13 17:45:17 +00:00
|
|
|
|
2012-05-07 18:34:26 +00:00
|
|
|
data->data.buffer = wl_shm_pool_create_buffer(pool->pool, offset,
|
2012-04-03 15:21:27 +00:00
|
|
|
rectangle->width,
|
|
|
|
rectangle->height,
|
|
|
|
stride, format);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2012-05-07 18:34:26 +00:00
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
|
|
|
display_create_shm_surface(struct display *display,
|
|
|
|
struct rectangle *rectangle, uint32_t flags,
|
|
|
|
struct window *window)
|
|
|
|
{
|
|
|
|
struct shm_surface_data *data;
|
|
|
|
struct shm_pool *pool;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
|
|
|
if (window && window->pool) {
|
|
|
|
shm_pool_reset(window->pool);
|
|
|
|
surface = display_create_shm_surface_from_pool(display,
|
|
|
|
rectangle,
|
|
|
|
flags,
|
|
|
|
window->pool);
|
|
|
|
if (surface)
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
pool = shm_pool_create(display,
|
|
|
|
data_length_for_shm_surface(rectangle));
|
|
|
|
if (!pool)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
surface =
|
|
|
|
display_create_shm_surface_from_pool(display, rectangle,
|
|
|
|
flags, pool);
|
|
|
|
|
|
|
|
if (!surface) {
|
|
|
|
shm_pool_destroy(pool);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure we destroy the pool when the surface is destroyed */
|
|
|
|
data = cairo_surface_get_user_data(surface, &surface_data_key);
|
|
|
|
data->pool = pool;
|
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
|
2012-05-25 13:03:06 +00:00
|
|
|
if (display->dpy && !(flags & SURFACE_SHM))
|
2012-04-10 20:55:11 +00:00
|
|
|
return display_create_egl_window_surface(display,
|
|
|
|
surface,
|
|
|
|
flags,
|
|
|
|
rectangle);
|
2010-10-25 15:40:03 +00:00
|
|
|
#endif
|
2012-04-03 16:00:48 +00:00
|
|
|
return display_create_shm_surface(display, rectangle, flags, NULL);
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
2012-05-25 06:30:02 +00:00
|
|
|
static const char *cursors[] = {
|
|
|
|
"bottom_left_corner",
|
|
|
|
"bottom_right_corner",
|
|
|
|
"bottom_side",
|
|
|
|
"grabbing",
|
|
|
|
"left_ptr",
|
|
|
|
"left_side",
|
|
|
|
"right_side",
|
|
|
|
"top_left_corner",
|
|
|
|
"top_right_corner",
|
|
|
|
"top_side",
|
|
|
|
"xterm",
|
|
|
|
"hand1",
|
2012-06-04 20:10:40 +00:00
|
|
|
"watch",
|
2012-05-25 06:30:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_cursors(struct display *display)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
display->cursor_theme = wl_cursor_theme_load(NULL, 32, display->shm);
|
|
|
|
display->cursors =
|
|
|
|
malloc(ARRAY_LENGTH(cursors) * sizeof display->cursors[0]);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_LENGTH(cursors); i++)
|
|
|
|
display->cursors[i] =
|
|
|
|
wl_cursor_theme_get_cursor(display->cursor_theme,
|
|
|
|
cursors[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
destroy_cursors(struct display *display)
|
|
|
|
{
|
|
|
|
wl_cursor_theme_destroy(display->cursor_theme);
|
2012-05-28 06:07:25 +00:00
|
|
|
free(display->cursors);
|
2012-05-25 06:30:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 12:39:42 +00:00
|
|
|
struct wl_cursor_image *
|
|
|
|
display_get_pointer_image(struct display *display, int pointer)
|
2010-08-18 19:28:04 +00:00
|
|
|
{
|
2012-05-22 12:39:42 +00:00
|
|
|
struct wl_cursor *cursor =
|
2012-05-25 06:30:02 +00:00
|
|
|
wl_cursor_theme_get_cursor(display->cursor_theme,
|
|
|
|
cursors[pointer]);
|
2012-05-03 09:29:46 +00:00
|
|
|
|
2012-05-22 12:39:42 +00:00
|
|
|
return cursor ? cursor->images[0] : NULL;
|
2010-08-18 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
window_attach_surface(struct window *window)
|
|
|
|
{
|
|
|
|
struct display *display = window->display;
|
|
|
|
struct wl_buffer *buffer;
|
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
|
|
|
|
2012-04-27 21:17:12 +00:00
|
|
|
if (window->type == TYPE_NONE) {
|
|
|
|
window->type = TYPE_TOPLEVEL;
|
|
|
|
if (display->shell)
|
|
|
|
wl_shell_surface_set_toplevel(window->shell_surface);
|
|
|
|
}
|
|
|
|
|
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;
|
2011-07-16 19:50:32 +00:00
|
|
|
#endif
|
2011-02-10 11:04:30 +00:00
|
|
|
case WINDOW_BUFFER_TYPE_SHM:
|
|
|
|
buffer =
|
|
|
|
display_get_buffer_for_surface(display,
|
2012-04-10 15:23:13 +00:00
|
|
|
window->cairo_surface);
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-01-27 15:17:39 +00:00
|
|
|
window_get_resize_dx_dy(window, &x, &y);
|
2011-02-10 11:04:30 +00:00
|
|
|
wl_surface_attach(window->surface, buffer, x, y);
|
2012-04-10 15:23:13 +00:00
|
|
|
wl_surface_damage(window->surface, 0, 0,
|
|
|
|
window->allocation.width,
|
|
|
|
window->allocation.height);
|
2011-02-10 11:04:30 +00:00
|
|
|
window->server_allocation = window->allocation;
|
2012-04-10 15:23:13 +00:00
|
|
|
cairo_surface_destroy(window->cairo_surface);
|
|
|
|
window->cairo_surface = NULL;
|
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
|
|
|
|
2012-03-05 04:47:56 +00:00
|
|
|
if (window->input_region) {
|
|
|
|
wl_surface_set_input_region(window->surface,
|
|
|
|
window->input_region);
|
|
|
|
wl_region_destroy(window->input_region);
|
|
|
|
window->input_region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->opaque_region) {
|
|
|
|
wl_surface_set_opaque_region(window->surface,
|
|
|
|
window->opaque_region);
|
|
|
|
wl_region_destroy(window->opaque_region);
|
|
|
|
window->opaque_region = NULL;
|
|
|
|
}
|
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
|
|
|
{
|
2012-03-26 19:56:39 +00:00
|
|
|
if (window->cairo_surface)
|
2011-03-07 14:08:09 +00:00
|
|
|
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;
|
2010-10-25 15:40:03 +00:00
|
|
|
#endif
|
|
|
|
case WINDOW_BUFFER_TYPE_SHM:
|
2010-10-26 04:02:20 +00:00
|
|
|
surface = display_create_shm_surface(window->display,
|
2012-04-03 16:00:48 +00:00
|
|
|
&window->allocation,
|
|
|
|
flags, window);
|
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
|
|
|
}
|
|
|
|
|
2012-01-19 11:33:50 +00:00
|
|
|
static void frame_destroy(struct frame *frame);
|
|
|
|
|
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;
|
2012-05-15 16:55:34 +00:00
|
|
|
struct window_output *window_output;
|
|
|
|
struct window_output *window_output_tmp;
|
2011-11-15 11:34:55 +00:00
|
|
|
|
|
|
|
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;
|
2012-01-26 16:09:20 +00:00
|
|
|
if (input->focus_widget &&
|
|
|
|
input->focus_widget->window == window)
|
|
|
|
input->focus_widget = NULL;
|
2011-11-15 11:34:55 +00:00
|
|
|
}
|
|
|
|
|
2012-05-15 16:55:34 +00:00
|
|
|
wl_list_for_each_safe(window_output, window_output_tmp,
|
|
|
|
&window->window_output_list, link) {
|
|
|
|
free (window_output);
|
|
|
|
}
|
|
|
|
|
2012-02-23 22:30:45 +00:00
|
|
|
if (window->input_region)
|
|
|
|
wl_region_destroy(window->input_region);
|
|
|
|
if (window->opaque_region)
|
|
|
|
wl_region_destroy(window->opaque_region);
|
|
|
|
|
2012-01-19 11:33:50 +00:00
|
|
|
if (window->frame)
|
|
|
|
frame_destroy(window->frame);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
free(window->title);
|
2011-01-21 23:03:15 +00:00
|
|
|
free(window);
|
|
|
|
}
|
|
|
|
|
2012-01-08 20:09:53 +00:00
|
|
|
static struct widget *
|
2012-01-10 18:52:34 +00:00
|
|
|
widget_find_widget(struct widget *widget, int32_t x, int32_t y)
|
2011-09-21 01:43:54 +00:00
|
|
|
{
|
2012-01-10 18:52:34 +00:00
|
|
|
struct widget *child, *target;
|
2011-09-21 01:43:54 +00:00
|
|
|
|
2012-01-10 18:52:34 +00:00
|
|
|
wl_list_for_each(child, &widget->child_list, link) {
|
|
|
|
target = widget_find_widget(child, x, y);
|
|
|
|
if (target)
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widget->allocation.x <= x &&
|
|
|
|
x < widget->allocation.x + widget->allocation.width &&
|
|
|
|
widget->allocation.y <= y &&
|
|
|
|
y < widget->allocation.y + widget->allocation.height) {
|
|
|
|
return widget;
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:52:34 +00:00
|
|
|
static struct widget *
|
|
|
|
widget_create(struct window *window, void *data)
|
2011-09-21 01:43:54 +00:00
|
|
|
{
|
2012-01-08 20:09:53 +00:00
|
|
|
struct widget *widget;
|
2011-09-21 01:43:54 +00:00
|
|
|
|
2012-01-08 20:09:53 +00:00
|
|
|
widget = malloc(sizeof *widget);
|
|
|
|
memset(widget, 0, sizeof *widget);
|
2012-01-08 20:18:19 +00:00
|
|
|
widget->window = window;
|
2012-01-08 20:09:53 +00:00
|
|
|
widget->user_data = data;
|
2012-01-10 14:43:58 +00:00
|
|
|
widget->allocation = window->allocation;
|
2012-01-10 18:52:34 +00:00
|
|
|
wl_list_init(&widget->child_list);
|
2012-02-23 22:30:45 +00:00
|
|
|
widget->opaque = 0;
|
2012-05-23 19:06:27 +00:00
|
|
|
widget->tooltip = NULL;
|
|
|
|
widget->tooltip_count = 0;
|
2011-09-21 01:43:54 +00:00
|
|
|
|
2012-01-08 20:09:53 +00:00
|
|
|
return widget;
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 18:52:34 +00:00
|
|
|
struct widget *
|
|
|
|
window_add_widget(struct window *window, void *data)
|
|
|
|
{
|
|
|
|
window->widget = widget_create(window, data);
|
|
|
|
wl_list_init(&window->widget->link);
|
|
|
|
|
|
|
|
return window->widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct widget *
|
|
|
|
widget_add_widget(struct widget *parent, void *data)
|
2011-09-21 01:43:54 +00:00
|
|
|
{
|
2012-01-08 20:09:53 +00:00
|
|
|
struct widget *widget;
|
2011-09-21 01:43:54 +00:00
|
|
|
|
2012-01-10 18:52:34 +00:00
|
|
|
widget = widget_create(parent->window, data);
|
|
|
|
wl_list_insert(parent->child_list.prev, &widget->link);
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_destroy(struct widget *widget)
|
|
|
|
{
|
2012-01-19 11:51:38 +00:00
|
|
|
struct display *display = widget->window->display;
|
|
|
|
struct input *input;
|
|
|
|
|
2012-05-23 19:06:27 +00:00
|
|
|
if (widget->tooltip) {
|
|
|
|
free(widget->tooltip);
|
|
|
|
widget->tooltip = NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-19 11:51:38 +00:00
|
|
|
wl_list_for_each(input, &display->input_list, link) {
|
|
|
|
if (input->focus_widget == widget)
|
|
|
|
input->focus_widget = NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:52:34 +00:00
|
|
|
wl_list_remove(&widget->link);
|
|
|
|
free(widget);
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-01-08 20:09:53 +00:00
|
|
|
widget_get_allocation(struct widget *widget, struct rectangle *allocation)
|
2011-09-21 01:43:54 +00:00
|
|
|
{
|
2012-01-08 20:09:53 +00:00
|
|
|
*allocation = widget->allocation;
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 00:11:42 +00:00
|
|
|
void
|
|
|
|
widget_set_size(struct widget *widget, int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
widget->allocation.width = width;
|
|
|
|
widget->allocation.height = height;
|
|
|
|
}
|
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
void
|
2012-01-08 20:09:53 +00:00
|
|
|
widget_set_allocation(struct widget *widget,
|
|
|
|
int32_t x, int32_t y, int32_t width, int32_t height)
|
2011-09-21 01:43:54 +00:00
|
|
|
{
|
2012-01-08 20:09:53 +00:00
|
|
|
widget->allocation.x = x;
|
|
|
|
widget->allocation.y = y;
|
2012-02-09 17:06:55 +00:00
|
|
|
widget_set_size(widget, width, height);
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
2012-02-23 22:30:45 +00:00
|
|
|
void
|
|
|
|
widget_set_transparent(struct widget *widget, int transparent)
|
|
|
|
{
|
|
|
|
widget->opaque = !transparent;
|
|
|
|
}
|
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
void *
|
2012-01-08 20:09:53 +00:00
|
|
|
widget_get_user_data(struct widget *widget)
|
2011-09-21 01:43:54 +00:00
|
|
|
{
|
2012-01-08 20:09:53 +00:00
|
|
|
return widget->user_data;
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 17:23:19 +00:00
|
|
|
void
|
|
|
|
widget_set_resize_handler(struct widget *widget,
|
|
|
|
widget_resize_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->resize_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_set_redraw_handler(struct widget *widget,
|
|
|
|
widget_redraw_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->redraw_handler = handler;
|
|
|
|
}
|
|
|
|
|
2012-01-08 20:18:19 +00:00
|
|
|
void
|
2012-01-09 13:42:24 +00:00
|
|
|
widget_set_enter_handler(struct widget *widget, widget_enter_handler_t handler)
|
2012-01-08 20:18:19 +00:00
|
|
|
{
|
2012-01-09 13:42:24 +00:00
|
|
|
widget->enter_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_set_leave_handler(struct widget *widget, widget_leave_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->leave_handler = handler;
|
2012-01-08 20:18:19 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 14:36:16 +00:00
|
|
|
void
|
|
|
|
widget_set_motion_handler(struct widget *widget,
|
|
|
|
widget_motion_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->motion_handler = handler;
|
|
|
|
}
|
|
|
|
|
2012-01-09 16:12:05 +00:00
|
|
|
void
|
|
|
|
widget_set_button_handler(struct widget *widget,
|
|
|
|
widget_button_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->button_handler = handler;
|
|
|
|
}
|
|
|
|
|
2012-01-08 20:18:19 +00:00
|
|
|
void
|
|
|
|
widget_schedule_redraw(struct widget *widget)
|
|
|
|
{
|
|
|
|
window_schedule_redraw(widget->window);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-23 19:06:27 +00:00
|
|
|
static void
|
|
|
|
tooltip_redraw_handler(struct widget *widget, void *data)
|
|
|
|
{
|
|
|
|
cairo_t *cr;
|
|
|
|
const int32_t r = 3;
|
|
|
|
struct tooltip *tooltip = data;
|
|
|
|
int32_t width, height;
|
|
|
|
struct window *window = widget->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_OVER);
|
|
|
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.4, 0.8);
|
|
|
|
cairo_fill(cr);
|
|
|
|
|
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
|
|
|
cairo_move_to(cr, 10, 16);
|
|
|
|
cairo_show_text(cr, tooltip->entry);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static cairo_text_extents_t
|
|
|
|
get_text_extents(struct tooltip *tooltip)
|
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
cairo_t *cr;
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
|
|
|
|
/* we borrow cairo_surface from the parent cause tooltip's wasn't
|
|
|
|
* created yet */
|
|
|
|
window = tooltip->widget->window->parent;
|
|
|
|
cr = cairo_create(window->cairo_surface);
|
|
|
|
cairo_text_extents(cr, tooltip->entry, &extents);
|
|
|
|
cairo_destroy(cr);
|
|
|
|
|
|
|
|
return extents;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
window_create_tooltip(struct tooltip *tooltip)
|
|
|
|
{
|
|
|
|
struct widget *parent = tooltip->parent;
|
|
|
|
struct display *display = parent->window->display;
|
|
|
|
struct window *window;
|
|
|
|
const int offset_y = 27;
|
|
|
|
const int margin = 3;
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
|
|
|
|
if (tooltip->widget)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
window = window_create_transient(display, parent->window, tooltip->x,
|
|
|
|
tooltip->y + offset_y,
|
|
|
|
WL_SHELL_SURFACE_TRANSIENT_INACTIVE);
|
|
|
|
if (!window)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
tooltip->window = window;
|
|
|
|
tooltip->widget = window_add_widget(tooltip->window, tooltip);
|
|
|
|
|
|
|
|
extents = get_text_extents(tooltip);
|
|
|
|
widget_set_redraw_handler(tooltip->widget, tooltip_redraw_handler);
|
|
|
|
window_schedule_resize(window, extents.width + 20, 20 + margin * 2);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_destroy_tooltip(struct widget *parent)
|
|
|
|
{
|
|
|
|
struct tooltip *tooltip = parent->tooltip;
|
|
|
|
|
|
|
|
parent->tooltip_count = 0;
|
|
|
|
if (!tooltip)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tooltip->widget) {
|
|
|
|
widget_destroy(tooltip->widget);
|
|
|
|
window_destroy(tooltip->window);
|
|
|
|
tooltip->widget = NULL;
|
|
|
|
tooltip->window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(tooltip->tooltip_fd);
|
|
|
|
free(tooltip->entry);
|
|
|
|
free(tooltip);
|
|
|
|
parent->tooltip = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tooltip_func(struct task *task, uint32_t events)
|
|
|
|
{
|
|
|
|
struct tooltip *tooltip =
|
|
|
|
container_of(task, struct tooltip, tooltip_task);
|
|
|
|
uint64_t exp;
|
|
|
|
|
|
|
|
read(tooltip->tooltip_fd, &exp, sizeof (uint64_t));
|
|
|
|
window_create_tooltip(tooltip);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TOOLTIP_TIMEOUT 500
|
|
|
|
static int
|
|
|
|
tooltip_timer_reset(struct tooltip *tooltip)
|
|
|
|
{
|
|
|
|
struct itimerspec its;
|
|
|
|
|
|
|
|
its.it_interval.tv_sec = 0;
|
|
|
|
its.it_interval.tv_nsec = 0;
|
|
|
|
its.it_value.tv_sec = TOOLTIP_TIMEOUT / 1000;
|
|
|
|
its.it_value.tv_nsec = (TOOLTIP_TIMEOUT % 1000) * 1000 * 1000;
|
|
|
|
if (timerfd_settime(tooltip->tooltip_fd, 0, &its, NULL) < 0) {
|
|
|
|
fprintf(stderr, "could not set timerfd\n: %m");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
widget_set_tooltip(struct widget *parent, char *entry, float x, float y)
|
|
|
|
{
|
|
|
|
struct tooltip *tooltip = parent->tooltip;
|
|
|
|
|
|
|
|
parent->tooltip_count++;
|
|
|
|
if (tooltip) {
|
|
|
|
tooltip->x = x;
|
|
|
|
tooltip->y = y;
|
|
|
|
tooltip_timer_reset(tooltip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the handler might be triggered too fast via input device motion, so
|
|
|
|
* we need this check here to make sure tooltip is fully initialized */
|
|
|
|
if (parent->tooltip_count > 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
tooltip = malloc(sizeof *tooltip);
|
|
|
|
if (!tooltip)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
parent->tooltip = tooltip;
|
|
|
|
tooltip->parent = parent;
|
|
|
|
tooltip->widget = NULL;
|
|
|
|
tooltip->window = NULL;
|
|
|
|
tooltip->x = x;
|
|
|
|
tooltip->y = y;
|
|
|
|
tooltip->entry = strdup(entry);
|
|
|
|
tooltip->tooltip_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
|
|
|
|
if (tooltip->tooltip_fd < 0) {
|
|
|
|
fprintf(stderr, "could not create timerfd\n: %m");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
tooltip->tooltip_task.run = tooltip_func;
|
|
|
|
display_watch_fd(parent->window->display, tooltip->tooltip_fd,
|
|
|
|
EPOLLIN, &tooltip->tooltip_task);
|
|
|
|
tooltip_timer_reset(tooltip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
static void
|
|
|
|
frame_resize_handler(struct widget *widget,
|
|
|
|
int32_t width, int32_t height, void *data)
|
|
|
|
{
|
|
|
|
struct frame *frame = data;
|
|
|
|
struct widget *child = frame->child;
|
|
|
|
struct rectangle allocation;
|
2012-02-23 22:30:45 +00:00
|
|
|
struct display *display = widget->window->display;
|
2012-05-10 00:04:35 +00:00
|
|
|
struct frame_button * button;
|
2012-05-16 02:25:28 +00:00
|
|
|
struct theme *t = display->theme;
|
2012-05-10 00:04:35 +00:00
|
|
|
int x_l, x_r, y, w, h;
|
2012-01-11 03:41:05 +00:00
|
|
|
int decoration_width, decoration_height;
|
2012-02-23 22:30:45 +00:00
|
|
|
int opaque_margin;
|
2012-01-11 03:41:05 +00:00
|
|
|
|
2012-03-06 01:38:08 +00:00
|
|
|
if (widget->window->type != TYPE_FULLSCREEN) {
|
2012-05-16 02:12:54 +00:00
|
|
|
decoration_width = (t->width + t->margin) * 2;
|
|
|
|
decoration_height = t->width +
|
|
|
|
t->titlebar_height + t->margin * 2;
|
2012-02-17 03:57:21 +00:00
|
|
|
|
2012-05-16 02:12:54 +00:00
|
|
|
allocation.x = t->width + t->margin;
|
|
|
|
allocation.y = t->titlebar_height + t->margin;
|
2012-02-17 03:57:21 +00:00
|
|
|
allocation.width = width - decoration_width;
|
|
|
|
allocation.height = height - decoration_height;
|
2012-02-23 22:30:45 +00:00
|
|
|
|
2012-05-16 02:12:54 +00:00
|
|
|
opaque_margin = t->margin + t->frame_radius;
|
2012-05-10 00:04:35 +00:00
|
|
|
|
|
|
|
wl_list_for_each(button, &frame->buttons_list, link)
|
|
|
|
button->widget->opaque = 0;
|
2012-02-17 03:57:21 +00:00
|
|
|
} else {
|
|
|
|
decoration_width = 0;
|
|
|
|
decoration_height = 0;
|
2012-01-11 03:41:05 +00:00
|
|
|
|
2012-02-17 03:57:21 +00:00
|
|
|
allocation.x = 0;
|
|
|
|
allocation.y = 0;
|
|
|
|
allocation.width = width;
|
|
|
|
allocation.height = height;
|
2012-02-23 22:30:45 +00:00
|
|
|
opaque_margin = 0;
|
2012-05-10 00:04:35 +00:00
|
|
|
|
|
|
|
wl_list_for_each(button, &frame->buttons_list, link)
|
|
|
|
button->widget->opaque = 1;
|
2012-02-23 22:30:45 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
widget_set_allocation(child, allocation.x, allocation.y,
|
|
|
|
allocation.width, allocation.height);
|
|
|
|
|
|
|
|
if (child->resize_handler)
|
|
|
|
child->resize_handler(child,
|
|
|
|
allocation.width,
|
|
|
|
allocation.height,
|
|
|
|
child->user_data);
|
|
|
|
|
2012-05-14 17:39:29 +00:00
|
|
|
width = child->allocation.width + decoration_width;
|
|
|
|
height = child->allocation.height + decoration_height;
|
|
|
|
|
|
|
|
widget->window->input_region =
|
|
|
|
wl_compositor_create_region(display->compositor);
|
|
|
|
wl_region_add(widget->window->input_region,
|
2012-05-16 02:12:54 +00:00
|
|
|
t->margin, t->margin,
|
|
|
|
width - 2 * t->margin,
|
|
|
|
height - 2 * t->margin);
|
2012-05-14 17:39:29 +00:00
|
|
|
|
|
|
|
widget_set_allocation(widget, 0, 0, width, height);
|
2012-02-29 02:52:12 +00:00
|
|
|
|
|
|
|
if (child->opaque) {
|
|
|
|
widget->window->opaque_region =
|
|
|
|
wl_compositor_create_region(display->compositor);
|
|
|
|
wl_region_add(widget->window->opaque_region,
|
|
|
|
opaque_margin, opaque_margin,
|
|
|
|
widget->allocation.width - 2 * opaque_margin,
|
|
|
|
widget->allocation.height - 2 * opaque_margin);
|
|
|
|
}
|
2012-05-10 00:04:35 +00:00
|
|
|
|
|
|
|
/* frame internal buttons */
|
2012-05-16 02:12:54 +00:00
|
|
|
x_r = frame->widget->allocation.width - t->width - t->margin;
|
|
|
|
x_l = t->width + t->margin;
|
|
|
|
y = t->width + t->margin;
|
2012-05-10 00:04:35 +00:00
|
|
|
wl_list_for_each(button, &frame->buttons_list, link) {
|
|
|
|
const int button_padding = 4;
|
|
|
|
w = cairo_image_surface_get_width(button->icon);
|
|
|
|
h = cairo_image_surface_get_height(button->icon);
|
|
|
|
|
|
|
|
if (button->decoration == FRAME_BUTTON_FANCY)
|
|
|
|
w += 10;
|
|
|
|
|
|
|
|
if (button->align == FRAME_BUTTON_LEFT) {
|
|
|
|
widget_set_allocation(button->widget,
|
|
|
|
x_l, y , w + 1, h + 1);
|
|
|
|
x_l += w;
|
|
|
|
x_l += button_padding;
|
|
|
|
} else {
|
|
|
|
x_r -= w;
|
|
|
|
widget_set_allocation(button->widget,
|
|
|
|
x_r, y , w + 1, h + 1);
|
|
|
|
x_r -= button_padding;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
frame_button_enter_handler(struct widget *widget,
|
|
|
|
struct input *input, float x, float y, void *data)
|
|
|
|
{
|
|
|
|
struct frame_button *frame_button = data;
|
|
|
|
|
|
|
|
widget_schedule_redraw(frame_button->widget);
|
|
|
|
frame_button->state = FRAME_BUTTON_OVER;
|
|
|
|
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_LEFT_PTR;
|
2012-05-10 00:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_button_leave_handler(struct widget *widget, struct input *input, void *data)
|
|
|
|
{
|
|
|
|
struct frame_button *frame_button = data;
|
|
|
|
|
|
|
|
widget_schedule_redraw(frame_button->widget);
|
|
|
|
frame_button->state = FRAME_BUTTON_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_button_button_handler(struct widget *widget,
|
|
|
|
struct input *input, uint32_t time,
|
2012-05-30 15:31:51 +00:00
|
|
|
uint32_t button,
|
|
|
|
enum wl_pointer_button_state state, void *data)
|
2012-05-10 00:04:35 +00:00
|
|
|
{
|
|
|
|
struct frame_button *frame_button = data;
|
|
|
|
struct window *window = widget->window;
|
|
|
|
|
|
|
|
if (button != BTN_LEFT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (state) {
|
2012-05-30 15:31:51 +00:00
|
|
|
case WL_POINTER_BUTTON_STATE_PRESSED:
|
2012-05-10 00:04:35 +00:00
|
|
|
frame_button->state = FRAME_BUTTON_ACTIVE;
|
|
|
|
widget_schedule_redraw(frame_button->widget);
|
|
|
|
|
|
|
|
if (frame_button->type == FRAME_BUTTON_ICON)
|
|
|
|
window_show_frame_menu(window, input, time);
|
|
|
|
return;
|
2012-05-30 15:31:51 +00:00
|
|
|
case WL_POINTER_BUTTON_STATE_RELEASED:
|
2012-05-10 00:04:35 +00:00
|
|
|
frame_button->state = FRAME_BUTTON_DEFAULT;
|
|
|
|
widget_schedule_redraw(frame_button->widget);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (frame_button->type) {
|
|
|
|
case FRAME_BUTTON_CLOSE:
|
|
|
|
if (window->close_handler)
|
|
|
|
window->close_handler(window->parent,
|
|
|
|
window->user_data);
|
|
|
|
else
|
|
|
|
display_exit(window->display);
|
|
|
|
break;
|
|
|
|
case FRAME_BUTTON_MINIMIZE:
|
|
|
|
fprintf(stderr,"Minimize stub\n");
|
|
|
|
break;
|
|
|
|
case FRAME_BUTTON_MAXIMIZE:
|
|
|
|
window_set_maximized(window, window->type != TYPE_MAXIMIZED);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* Unknown operation */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_button_redraw_handler(struct widget *widget, void *data)
|
|
|
|
{
|
|
|
|
struct frame_button *frame_button = data;
|
|
|
|
cairo_t *cr;
|
|
|
|
int width, height, x, y;
|
|
|
|
struct window *window = widget->window;
|
|
|
|
|
|
|
|
x = widget->allocation.x;
|
|
|
|
y = widget->allocation.y;
|
|
|
|
width = widget->allocation.width;
|
|
|
|
height = widget->allocation.height;
|
|
|
|
|
|
|
|
if (!width)
|
|
|
|
return;
|
|
|
|
if (!height)
|
|
|
|
return;
|
|
|
|
if (widget->opaque)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cr = cairo_create(window->cairo_surface);
|
|
|
|
|
|
|
|
if (frame_button->decoration == FRAME_BUTTON_FANCY) {
|
|
|
|
cairo_set_line_width(cr, 1);
|
|
|
|
|
|
|
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
|
|
|
|
cairo_rectangle (cr, x, y, 25, 16);
|
|
|
|
|
|
|
|
cairo_stroke_preserve(cr);
|
|
|
|
|
|
|
|
switch (frame_button->state) {
|
|
|
|
case FRAME_BUTTON_DEFAULT:
|
|
|
|
cairo_set_source_rgb(cr, 0.88, 0.88, 0.88);
|
|
|
|
break;
|
|
|
|
case FRAME_BUTTON_OVER:
|
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
|
|
|
break;
|
|
|
|
case FRAME_BUTTON_ACTIVE:
|
|
|
|
cairo_set_source_rgb(cr, 0.7, 0.7, 0.7);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
x += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_set_source_surface(cr, frame_button->icon, x, y);
|
|
|
|
cairo_paint(cr);
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct widget *
|
|
|
|
frame_button_create(struct frame *frame, void *data, enum frame_button_action type,
|
|
|
|
enum frame_button_align align, enum frame_button_decoration style)
|
|
|
|
{
|
|
|
|
struct frame_button *frame_button;
|
|
|
|
const char *icon = data;
|
|
|
|
|
|
|
|
frame_button = malloc (sizeof *frame_button);
|
|
|
|
memset(frame_button, 0, sizeof *frame_button);
|
|
|
|
|
|
|
|
frame_button->icon = cairo_image_surface_create_from_png(icon);
|
|
|
|
frame_button->widget = widget_add_widget(frame->widget, frame_button);
|
|
|
|
frame_button->frame = frame;
|
|
|
|
frame_button->type = type;
|
|
|
|
frame_button->align = align;
|
|
|
|
frame_button->decoration = style;
|
|
|
|
|
|
|
|
wl_list_insert(frame->buttons_list.prev, &frame_button->link);
|
|
|
|
|
|
|
|
widget_set_redraw_handler(frame_button->widget, frame_button_redraw_handler);
|
|
|
|
widget_set_enter_handler(frame_button->widget, frame_button_enter_handler);
|
|
|
|
widget_set_leave_handler(frame_button->widget, frame_button_leave_handler);
|
|
|
|
widget_set_button_handler(frame_button->widget, frame_button_button_handler);
|
|
|
|
return frame_button->widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_button_destroy(struct frame_button *frame_button)
|
|
|
|
{
|
|
|
|
widget_destroy(frame_button->widget);
|
|
|
|
wl_list_remove(&frame_button->link);
|
|
|
|
cairo_surface_destroy(frame_button->icon);
|
|
|
|
free(frame_button);
|
|
|
|
|
|
|
|
return;
|
2012-01-11 03:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_redraw_handler(struct widget *widget, void *data)
|
|
|
|
{
|
|
|
|
cairo_t *cr;
|
|
|
|
struct window *window = widget->window;
|
2012-05-16 02:25:28 +00:00
|
|
|
struct theme *t = window->display->theme;
|
|
|
|
uint32_t flags = 0;
|
2012-01-11 03:41:05 +00:00
|
|
|
|
2012-02-17 03:57:21 +00:00
|
|
|
if (window->type == TYPE_FULLSCREEN)
|
|
|
|
return;
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
cr = cairo_create(window->cairo_surface);
|
|
|
|
|
|
|
|
if (window->keyboard_device)
|
2012-05-16 02:25:28 +00:00
|
|
|
flags |= THEME_FRAME_ACTIVE;
|
|
|
|
theme_render_frame(t, cr, widget->allocation.width,
|
|
|
|
widget->allocation.height, window->title, flags);
|
2012-01-11 03:41:05 +00:00
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
}
|
|
|
|
|
2011-12-15 14:14:34 +00:00
|
|
|
static int
|
2012-01-11 03:41:05 +00:00
|
|
|
frame_get_pointer_image_for_location(struct frame *frame, struct input *input)
|
2010-08-16 21:47:07 +00:00
|
|
|
{
|
2012-05-22 20:38:53 +00:00
|
|
|
struct theme *t = frame->widget->window->display->theme;
|
2010-08-18 19:28:04 +00:00
|
|
|
int location;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2012-05-22 20:38:53 +00:00
|
|
|
location = theme_get_location(t, input->sx, input->sy,
|
|
|
|
frame->widget->allocation.width,
|
|
|
|
frame->widget->allocation.height);
|
|
|
|
|
2010-08-16 21:47:07 +00:00
|
|
|
switch (location) {
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_TOP:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_TOP;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_BOTTOM:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_BOTTOM;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_LEFT:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_LEFT;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_RIGHT:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_RIGHT;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_TOP_LEFT:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_TOP_LEFT;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_TOP_RIGHT:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_TOP_RIGHT;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_BOTTOM_LEFT:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_BOTTOM_LEFT;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_BOTTOM_RIGHT;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_EXTERIOR:
|
|
|
|
case THEME_LOCATION_TITLEBAR:
|
2010-08-16 21:47:07 +00:00
|
|
|
default:
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_LEFT_PTR;
|
2010-08-16 21:47:07 +00:00
|
|
|
}
|
2011-12-15 14:14:34 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
static void
|
|
|
|
frame_menu_func(struct window *window, int index, void *data)
|
2011-12-15 14:14:34 +00:00
|
|
|
{
|
2012-01-11 03:41:05 +00:00
|
|
|
switch (index) {
|
|
|
|
case 0: /* close */
|
|
|
|
if (window->close_handler)
|
|
|
|
window->close_handler(window->parent,
|
|
|
|
window->user_data);
|
|
|
|
else
|
|
|
|
display_exit(window->display);
|
|
|
|
break;
|
|
|
|
case 1: /* fullscreen */
|
|
|
|
/* we don't have a way to get out of fullscreen for now */
|
|
|
|
window_set_fullscreen(window, 1);
|
|
|
|
break;
|
|
|
|
case 2: /* rotate */
|
|
|
|
case 3: /* scale */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2012-01-31 14:53:44 +00:00
|
|
|
void
|
|
|
|
window_show_frame_menu(struct window *window,
|
|
|
|
struct input *input, uint32_t time)
|
|
|
|
{
|
|
|
|
int32_t x, y;
|
|
|
|
|
|
|
|
static const char *entries[] = {
|
|
|
|
"Close", "Fullscreen", "Rotate", "Scale"
|
|
|
|
};
|
|
|
|
|
|
|
|
input_get_position(input, &x, &y);
|
|
|
|
window_show_menu(window->display, input, time, window,
|
|
|
|
x - 10, y - 10, frame_menu_func, entries, 4);
|
|
|
|
}
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
static int
|
|
|
|
frame_enter_handler(struct widget *widget,
|
2012-05-10 16:21:37 +00:00
|
|
|
struct input *input, float x, float y, void *data)
|
2012-01-11 03:41:05 +00:00
|
|
|
{
|
|
|
|
return frame_get_pointer_image_for_location(data, input);
|
|
|
|
}
|
2010-09-08 01:50:06 +00:00
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
static int
|
|
|
|
frame_motion_handler(struct widget *widget,
|
|
|
|
struct input *input, uint32_t time,
|
2012-05-10 16:21:37 +00:00
|
|
|
float x, float y, void *data)
|
2012-01-11 03:41:05 +00:00
|
|
|
{
|
|
|
|
return frame_get_pointer_image_for_location(data, input);
|
|
|
|
}
|
2011-10-25 11:20:51 +00:00
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
static void
|
|
|
|
frame_button_handler(struct widget *widget,
|
|
|
|
struct input *input, uint32_t time,
|
2012-05-30 15:31:51 +00:00
|
|
|
uint32_t button, enum wl_pointer_button_state state,
|
|
|
|
void *data)
|
2012-01-11 03:41:05 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
struct frame *frame = data;
|
|
|
|
struct window *window = widget->window;
|
2012-04-03 16:00:48 +00:00
|
|
|
struct display *display = window->display;
|
2012-01-11 03:41:05 +00:00
|
|
|
int location;
|
2012-04-03 16:00:48 +00:00
|
|
|
|
2012-05-22 20:38:53 +00:00
|
|
|
location = theme_get_location(display->theme, input->sx, input->sy,
|
|
|
|
frame->widget->allocation.width,
|
|
|
|
frame->widget->allocation.height);
|
2012-01-11 03:41:05 +00:00
|
|
|
|
2012-05-30 15:31:51 +00:00
|
|
|
if (window->display->shell && button == BTN_LEFT &&
|
|
|
|
state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
2012-01-11 03:41:05 +00:00
|
|
|
switch (location) {
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_TITLEBAR:
|
2012-01-11 03:41:05 +00:00
|
|
|
if (!window->shell_surface)
|
|
|
|
break;
|
2012-06-04 20:04:07 +00:00
|
|
|
input_set_pointer_image(input, CURSOR_DRAGGING);
|
2012-04-12 02:42:15 +00:00
|
|
|
input_ungrab(input);
|
2012-01-11 03:41:05 +00:00
|
|
|
wl_shell_surface_move(window->shell_surface,
|
2012-05-16 17:45:18 +00:00
|
|
|
input_get_seat(input),
|
2012-04-12 02:42:15 +00:00
|
|
|
display->serial);
|
2012-01-11 03:41:05 +00:00
|
|
|
break;
|
2012-05-22 20:38:53 +00:00
|
|
|
case THEME_LOCATION_RESIZING_TOP:
|
|
|
|
case THEME_LOCATION_RESIZING_BOTTOM:
|
|
|
|
case THEME_LOCATION_RESIZING_LEFT:
|
|
|
|
case THEME_LOCATION_RESIZING_RIGHT:
|
|
|
|
case THEME_LOCATION_RESIZING_TOP_LEFT:
|
|
|
|
case THEME_LOCATION_RESIZING_TOP_RIGHT:
|
|
|
|
case THEME_LOCATION_RESIZING_BOTTOM_LEFT:
|
|
|
|
case THEME_LOCATION_RESIZING_BOTTOM_RIGHT:
|
2012-01-11 03:41:05 +00:00
|
|
|
if (!window->shell_surface)
|
|
|
|
break;
|
2012-04-12 02:42:15 +00:00
|
|
|
input_ungrab(input);
|
2012-04-03 16:00:48 +00:00
|
|
|
|
|
|
|
if (!display->dpy) {
|
|
|
|
/* If we're using shm, allocate a big
|
|
|
|
pool to create buffers out of while
|
|
|
|
we resize. We should probably base
|
|
|
|
this number on the size of the output. */
|
2012-05-07 18:34:26 +00:00
|
|
|
window->pool =
|
|
|
|
shm_pool_create(display, 6 * 1024 * 1024);
|
2012-04-03 16:00:48 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
wl_shell_surface_resize(window->shell_surface,
|
2012-05-16 17:45:18 +00:00
|
|
|
input_get_seat(input),
|
2012-04-12 02:42:15 +00:00
|
|
|
display->serial, location);
|
2012-01-11 03:41:05 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-05-30 15:31:51 +00:00
|
|
|
} else if (button == BTN_RIGHT &&
|
|
|
|
state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
2012-01-31 14:53:44 +00:00
|
|
|
window_show_frame_menu(window, input, time);
|
2012-01-11 03:41:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct widget *
|
|
|
|
frame_create(struct window *window, void *data)
|
|
|
|
{
|
|
|
|
struct frame *frame;
|
|
|
|
|
|
|
|
frame = malloc(sizeof *frame);
|
|
|
|
memset(frame, 0, sizeof *frame);
|
|
|
|
|
|
|
|
frame->widget = window_add_widget(window, frame);
|
|
|
|
frame->child = widget_add_widget(frame->widget, data);
|
2012-05-10 00:04:35 +00:00
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
widget_set_redraw_handler(frame->widget, frame_redraw_handler);
|
|
|
|
widget_set_resize_handler(frame->widget, frame_resize_handler);
|
|
|
|
widget_set_enter_handler(frame->widget, frame_enter_handler);
|
|
|
|
widget_set_motion_handler(frame->widget, frame_motion_handler);
|
|
|
|
widget_set_button_handler(frame->widget, frame_button_handler);
|
|
|
|
|
2012-05-10 00:04:35 +00:00
|
|
|
/* Create empty list for frame buttons */
|
|
|
|
wl_list_init(&frame->buttons_list);
|
|
|
|
|
|
|
|
frame_button_create(frame, DATADIR "/weston/icon_window.png",
|
|
|
|
FRAME_BUTTON_ICON, FRAME_BUTTON_LEFT, FRAME_BUTTON_NONE);
|
|
|
|
|
|
|
|
frame_button_create(frame, DATADIR "/weston/sign_close.png",
|
|
|
|
FRAME_BUTTON_CLOSE, FRAME_BUTTON_RIGHT, FRAME_BUTTON_FANCY);
|
|
|
|
|
|
|
|
frame_button_create(frame, DATADIR "/weston/sign_maximize.png",
|
|
|
|
FRAME_BUTTON_MAXIMIZE, FRAME_BUTTON_RIGHT, FRAME_BUTTON_FANCY);
|
|
|
|
|
|
|
|
frame_button_create(frame, DATADIR "/weston/sign_minimize.png",
|
|
|
|
FRAME_BUTTON_MINIMIZE, FRAME_BUTTON_RIGHT, FRAME_BUTTON_FANCY);
|
|
|
|
|
2012-01-19 11:33:50 +00:00
|
|
|
window->frame = frame;
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
return frame->child;
|
2010-08-16 21:47:07 +00:00
|
|
|
}
|
|
|
|
|
2012-01-19 11:33:50 +00:00
|
|
|
static void
|
|
|
|
frame_destroy(struct frame *frame)
|
|
|
|
{
|
2012-05-10 00:04:35 +00:00
|
|
|
struct frame_button *button, *tmp;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(button, tmp, &frame->buttons_list, link)
|
|
|
|
frame_button_destroy(button);
|
|
|
|
|
2012-01-19 11:33:50 +00:00
|
|
|
/* frame->child must be destroyed by the application */
|
|
|
|
widget_destroy(frame->widget);
|
|
|
|
free(frame);
|
|
|
|
}
|
|
|
|
|
2011-09-21 01:43:54 +00:00
|
|
|
static void
|
2012-01-11 05:04:42 +00:00
|
|
|
input_set_focus_widget(struct input *input, struct widget *focus,
|
2012-05-10 16:21:37 +00:00
|
|
|
float x, float y)
|
2011-09-21 01:43:54 +00:00
|
|
|
{
|
2012-01-11 04:46:33 +00:00
|
|
|
struct widget *old, *widget;
|
2012-05-25 13:01:41 +00:00
|
|
|
int pointer = CURSOR_LEFT_PTR;
|
2011-09-21 01:43:54 +00:00
|
|
|
|
2012-01-11 05:04:42 +00:00
|
|
|
if (focus == input->focus_widget)
|
2011-09-21 01:43:54 +00:00
|
|
|
return;
|
|
|
|
|
2012-01-11 05:04:42 +00:00
|
|
|
old = input->focus_widget;
|
2012-01-09 13:42:24 +00:00
|
|
|
if (old) {
|
2012-01-11 04:46:33 +00:00
|
|
|
widget = old;
|
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
if (widget->leave_handler)
|
|
|
|
widget->leave_handler(old, input, widget->user_data);
|
2012-01-11 05:04:42 +00:00
|
|
|
input->focus_widget = NULL;
|
2012-01-09 13:42:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (focus) {
|
2012-01-11 04:46:33 +00:00
|
|
|
widget = focus;
|
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
2012-06-05 03:36:32 +00:00
|
|
|
input->focus_widget = focus;
|
2012-01-11 04:46:33 +00:00
|
|
|
if (widget->enter_handler)
|
2012-04-12 02:42:15 +00:00
|
|
|
pointer = widget->enter_handler(focus, input, x, y,
|
2012-01-11 04:46:33 +00:00
|
|
|
widget->user_data);
|
2012-01-09 16:22:32 +00:00
|
|
|
|
2012-06-04 20:04:07 +00:00
|
|
|
input_set_pointer_image(input, pointer);
|
2012-01-09 13:42:24 +00:00
|
|
|
}
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
2008-11-08 23:53:37 +00:00
|
|
|
static void
|
2012-05-16 17:45:18 +00:00
|
|
|
pointer_handle_motion(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
|
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;
|
2012-01-08 20:09:53 +00:00
|
|
|
struct widget *widget;
|
2012-05-25 13:01:41 +00:00
|
|
|
int cursor = CURSOR_LEFT_PTR;
|
2012-05-10 16:21:37 +00:00
|
|
|
float sx = wl_fixed_to_double(sx_w);
|
|
|
|
float sy = wl_fixed_to_double(sy_w);
|
2010-07-20 21:06:19 +00:00
|
|
|
|
|
|
|
input->sx = sx;
|
|
|
|
input->sy = sy;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2012-01-11 04:46:33 +00:00
|
|
|
if (!(input->grab && input->grab_button)) {
|
2012-01-10 18:52:34 +00:00
|
|
|
widget = widget_find_widget(window->widget, sx, sy);
|
2012-04-12 02:42:15 +00:00
|
|
|
input_set_focus_widget(input, widget, sx, sy);
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 04:46:33 +00:00
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
else
|
2012-01-11 05:04:42 +00:00
|
|
|
widget = input->focus_widget;
|
2012-01-09 14:36:16 +00:00
|
|
|
if (widget && widget->motion_handler)
|
2012-05-16 17:45:18 +00:00
|
|
|
cursor = widget->motion_handler(input->focus_widget,
|
|
|
|
input, time, sx, sy,
|
|
|
|
widget->user_data);
|
2010-08-18 19:28:04 +00:00
|
|
|
|
2012-06-04 20:04:07 +00:00
|
|
|
input_set_pointer_image(input, cursor);
|
2008-12-30 16:03:33 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 04:46:33 +00:00
|
|
|
void
|
|
|
|
input_grab(struct input *input, struct widget *widget, uint32_t button)
|
|
|
|
{
|
|
|
|
input->grab = widget;
|
|
|
|
input->grab_button = button;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-04-12 02:42:15 +00:00
|
|
|
input_ungrab(struct input *input)
|
2012-01-11 04:46:33 +00:00
|
|
|
{
|
|
|
|
struct widget *widget;
|
|
|
|
|
|
|
|
input->grab = NULL;
|
|
|
|
if (input->pointer_focus) {
|
|
|
|
widget = widget_find_widget(input->pointer_focus->widget,
|
|
|
|
input->sx, input->sy);
|
2012-04-12 02:42:15 +00:00
|
|
|
input_set_focus_widget(input, widget, input->sx, input->sy);
|
2012-01-11 04:46:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-25 20:34:05 +00:00
|
|
|
static void
|
2012-05-16 17:45:18 +00:00
|
|
|
pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
|
2012-05-30 15:31:51 +00:00
|
|
|
uint32_t time, uint32_t button, uint32_t state_w)
|
2008-12-30 16:03:33 +00:00
|
|
|
{
|
2010-07-20 21:06:19 +00:00
|
|
|
struct input *input = data;
|
2012-01-08 20:09:53 +00:00
|
|
|
struct widget *widget;
|
2012-05-30 15:31:51 +00:00
|
|
|
enum wl_pointer_button_state state = state_w;
|
2010-06-15 00:25:06 +00:00
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input->display->serial = serial;
|
2012-05-30 15:31:51 +00:00
|
|
|
if (input->focus_widget && input->grab == NULL &&
|
|
|
|
state == WL_POINTER_BUTTON_STATE_PRESSED)
|
2012-01-11 05:04:42 +00:00
|
|
|
input_grab(input, input->focus_widget, button);
|
2011-09-21 01:43:54 +00:00
|
|
|
|
2012-01-23 19:11:18 +00:00
|
|
|
widget = input->grab;
|
2012-01-11 03:41:05 +00:00
|
|
|
if (widget && widget->button_handler)
|
2012-01-23 19:11:18 +00:00
|
|
|
(*widget->button_handler)(widget,
|
|
|
|
input, time,
|
|
|
|
button, state,
|
|
|
|
input->grab->user_data);
|
2012-01-11 04:46:33 +00:00
|
|
|
|
2012-05-30 15:31:51 +00:00
|
|
|
if (input->grab && input->grab_button == button &&
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED)
|
2012-04-12 02:42:15 +00:00
|
|
|
input_ungrab(input);
|
2008-11-02 23:51:48 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 16:47:01 +00:00
|
|
|
static void
|
2012-05-16 17:45:18 +00:00
|
|
|
pointer_handle_axis(void *data, struct wl_pointer *pointer,
|
2012-05-30 15:32:00 +00:00
|
|
|
uint32_t time, uint32_t axis, wl_fixed_t value)
|
2012-03-22 16:47:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-02-24 03:37:14 +00:00
|
|
|
static void
|
2012-05-16 17:45:18 +00:00
|
|
|
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
|
2012-05-30 15:31:52 +00:00
|
|
|
uint32_t serial, uint32_t time, uint32_t key,
|
|
|
|
uint32_t state_w)
|
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;
|
2012-05-08 19:55:39 +00:00
|
|
|
uint32_t code, num_syms;
|
2012-05-30 15:31:52 +00:00
|
|
|
enum wl_keyboard_key_state state = state_w;
|
2012-05-08 19:55:39 +00:00
|
|
|
const xkb_keysym_t *syms;
|
|
|
|
xkb_keysym_t sym;
|
|
|
|
xkb_mod_mask_t mask;
|
2009-02-24 03:37:14 +00:00
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input->display->serial = serial;
|
2012-02-16 12:48:00 +00:00
|
|
|
code = key + 8;
|
2012-06-01 11:14:06 +00:00
|
|
|
if (!window || window->keyboard_device != input || !input->xkb.state)
|
2009-02-24 03:37:14 +00:00
|
|
|
return;
|
|
|
|
|
2012-05-30 15:32:01 +00:00
|
|
|
num_syms = xkb_key_get_syms(input->xkb.state, code, &syms);
|
2008-12-30 16:03:33 +00:00
|
|
|
|
2012-05-30 15:32:01 +00:00
|
|
|
mask = xkb_state_serialize_mods(input->xkb.state,
|
2012-05-31 19:27:47 +00:00
|
|
|
XKB_STATE_DEPRESSED |
|
2012-05-08 19:55:39 +00:00
|
|
|
XKB_STATE_LATCHED);
|
|
|
|
input->modifiers = 0;
|
2012-05-30 15:32:01 +00:00
|
|
|
if (mask & input->xkb.control_mask)
|
2012-05-08 19:55:39 +00:00
|
|
|
input->modifiers |= MOD_CONTROL_MASK;
|
2012-05-30 15:32:01 +00:00
|
|
|
if (mask & input->xkb.alt_mask)
|
2012-05-08 19:55:39 +00:00
|
|
|
input->modifiers |= MOD_ALT_MASK;
|
2012-05-30 15:32:01 +00:00
|
|
|
if (mask & input->xkb.shift_mask)
|
2012-05-08 19:55:39 +00:00
|
|
|
input->modifiers |= MOD_SHIFT_MASK;
|
|
|
|
|
2012-05-11 15:24:29 +00:00
|
|
|
if (num_syms == 1 && syms[0] == XKB_KEY_F5 &&
|
2012-05-08 19:55:39 +00:00
|
|
|
input->modifiers == MOD_ALT_MASK) {
|
2012-05-30 15:31:52 +00:00
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
|
2012-02-16 20:53:46 +00:00
|
|
|
window_set_maximized(window,
|
|
|
|
window->type != TYPE_MAXIMIZED);
|
|
|
|
} else if (window->key_handler) {
|
2012-05-08 19:55:39 +00:00
|
|
|
if (num_syms == 1)
|
|
|
|
sym = syms[0];
|
|
|
|
else
|
2012-05-14 13:21:06 +00:00
|
|
|
sym = XKB_KEY_NoSymbol;
|
2012-05-08 19:55:39 +00:00
|
|
|
|
2012-02-16 20:53:46 +00:00
|
|
|
(*window->key_handler)(window, input, time, key,
|
|
|
|
sym, state, window->user_data);
|
|
|
|
}
|
2008-12-30 16:03:33 +00:00
|
|
|
}
|
|
|
|
|
2012-05-31 19:27:47 +00:00
|
|
|
static void
|
|
|
|
keyboard_handle_modifiers(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, uint32_t mods_depressed,
|
|
|
|
uint32_t mods_latched, uint32_t mods_locked,
|
|
|
|
uint32_t group)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
|
2012-06-01 11:14:06 +00:00
|
|
|
xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
|
|
|
|
mods_locked, 0, 0, group);
|
2012-05-31 19:27:47 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 10:02:09 +00:00
|
|
|
static void
|
2012-04-12 02:42:15 +00:00
|
|
|
input_remove_pointer_focus(struct input *input)
|
2011-12-16 10:02:09 +00:00
|
|
|
{
|
|
|
|
struct window *window = input->pointer_focus;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input_set_focus_widget(input, NULL, 0, 0);
|
2011-12-16 10:02:09 +00:00
|
|
|
|
|
|
|
input->pointer_focus = NULL;
|
2012-05-25 13:01:41 +00:00
|
|
|
input->current_cursor = CURSOR_UNSET;
|
2011-12-16 10:02:09 +00:00
|
|
|
}
|
|
|
|
|
2009-02-23 02:51:24 +00:00
|
|
|
static void
|
2012-05-16 17:45:18 +00:00
|
|
|
pointer_handle_enter(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t serial, struct wl_surface *surface,
|
|
|
|
wl_fixed_t sx_w, wl_fixed_t sy_w)
|
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;
|
2012-01-08 20:09:53 +00:00
|
|
|
struct widget *widget;
|
2012-05-10 16:21:37 +00:00
|
|
|
float sx = wl_fixed_to_double(sx_w);
|
|
|
|
float sy = wl_fixed_to_double(sy_w);
|
2010-07-20 21:06:19 +00:00
|
|
|
|
2012-05-10 00:04:35 +00:00
|
|
|
if (!surface) {
|
|
|
|
/* enter event for a window we've just destroyed */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input->display->serial = serial;
|
|
|
|
input->pointer_enter_serial = serial;
|
2012-02-23 14:59:05 +00:00
|
|
|
input->pointer_focus = wl_surface_get_user_data(surface);
|
2011-09-06 18:33:52 +00:00
|
|
|
window = input->pointer_focus;
|
|
|
|
|
2012-04-03 16:00:48 +00:00
|
|
|
if (window->pool) {
|
2012-05-07 18:34:26 +00:00
|
|
|
shm_pool_destroy(window->pool);
|
2012-04-03 16:00:48 +00:00
|
|
|
window->pool = NULL;
|
|
|
|
/* Schedule a redraw to free the pool */
|
|
|
|
window_schedule_redraw(window);
|
|
|
|
}
|
|
|
|
|
2012-02-23 14:59:05 +00:00
|
|
|
input->sx = sx;
|
|
|
|
input->sy = sy;
|
2010-08-18 19:28:04 +00:00
|
|
|
|
2012-02-23 14:59:05 +00:00
|
|
|
widget = widget_find_widget(window->widget, sx, sy);
|
2012-04-12 02:42:15 +00:00
|
|
|
input_set_focus_widget(input, widget, sx, sy);
|
2012-02-23 14:59:05 +00:00
|
|
|
}
|
2011-01-20 16:56:57 +00:00
|
|
|
|
2012-02-23 14:59:05 +00:00
|
|
|
static void
|
2012-05-16 17:45:18 +00:00
|
|
|
pointer_handle_leave(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t serial, struct wl_surface *surface)
|
2012-02-23 14:59:05 +00:00
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input->display->serial = serial;
|
|
|
|
input_remove_pointer_focus(input);
|
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
|
2012-05-16 17:45:18 +00:00
|
|
|
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, 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;
|
2009-02-23 04:01:35 +00:00
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input->display->serial = serial;
|
2012-02-23 14:59:05 +00:00
|
|
|
input->keyboard_focus = wl_surface_get_user_data(surface);
|
2010-07-20 21:06:19 +00:00
|
|
|
|
|
|
|
window = input->keyboard_focus;
|
2012-02-23 14:59:05 +00:00
|
|
|
window->keyboard_device = input;
|
|
|
|
if (window->keyboard_focus_handler)
|
|
|
|
(*window->keyboard_focus_handler)(window,
|
|
|
|
window->keyboard_device,
|
|
|
|
window->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-16 17:45:18 +00:00
|
|
|
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, struct wl_surface *surface)
|
2012-02-23 14:59:05 +00:00
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input->display->serial = serial;
|
2012-02-23 14:59:05 +00:00
|
|
|
input_remove_keyboard_focus(input);
|
2009-02-23 02:51:24 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 11:14:06 +00:00
|
|
|
static void
|
|
|
|
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t format, int fd, uint32_t size)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
char *map_str;
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
|
|
|
|
if (map_str == MAP_FAILED) {
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input->xkb.keymap = xkb_map_new_from_string(input->display->xkb_context,
|
|
|
|
map_str,
|
|
|
|
XKB_KEYMAP_FORMAT_TEXT_V1,
|
|
|
|
0);
|
|
|
|
munmap(map_str, size);
|
|
|
|
close(fd);
|
|
|
|
|
|
|
|
if (!input->xkb.keymap) {
|
|
|
|
fprintf(stderr, "failed to compile keymap\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input->xkb.state = xkb_state_new(input->xkb.keymap);
|
|
|
|
if (!input->xkb.state) {
|
|
|
|
fprintf(stderr, "failed to create XKB state\n");
|
|
|
|
xkb_map_unref(input->xkb.keymap);
|
|
|
|
input->xkb.keymap = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
input->xkb.control_mask =
|
|
|
|
1 << xkb_map_mod_get_index(input->xkb.keymap, "Control");
|
|
|
|
input->xkb.alt_mask =
|
|
|
|
1 << xkb_map_mod_get_index(input->xkb.keymap, "Mod1");
|
|
|
|
input->xkb.shift_mask =
|
|
|
|
1 << xkb_map_mod_get_index(input->xkb.keymap, "Shift");
|
|
|
|
}
|
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
static const struct wl_pointer_listener pointer_listener = {
|
|
|
|
pointer_handle_enter,
|
|
|
|
pointer_handle_leave,
|
|
|
|
pointer_handle_motion,
|
|
|
|
pointer_handle_button,
|
|
|
|
pointer_handle_axis,
|
|
|
|
};
|
2011-12-21 22:14:54 +00:00
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
static const struct wl_keyboard_listener keyboard_listener = {
|
2012-06-01 11:14:06 +00:00
|
|
|
keyboard_handle_keymap,
|
2012-05-16 17:45:18 +00:00
|
|
|
keyboard_handle_enter,
|
|
|
|
keyboard_handle_leave,
|
|
|
|
keyboard_handle_key,
|
2012-05-31 19:27:47 +00:00
|
|
|
keyboard_handle_modifiers,
|
2012-05-16 17:45:18 +00:00
|
|
|
};
|
2011-12-21 22:14:54 +00:00
|
|
|
|
|
|
|
static void
|
2012-05-16 17:45:18 +00:00
|
|
|
seat_handle_capabilities(void *data, struct wl_seat *seat,
|
|
|
|
enum wl_seat_capability caps)
|
2011-12-21 22:14:54 +00:00
|
|
|
{
|
2012-05-16 17:45:18 +00:00
|
|
|
struct input *input = data;
|
2011-12-21 22:14:54 +00:00
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
if ((caps & WL_SEAT_CAPABILITY_POINTER) && !input->pointer) {
|
|
|
|
input->pointer = wl_seat_get_pointer(seat);
|
|
|
|
wl_pointer_set_user_data(input->pointer, input);
|
|
|
|
wl_pointer_add_listener(input->pointer, &pointer_listener,
|
|
|
|
input);
|
|
|
|
} else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && input->pointer) {
|
|
|
|
wl_pointer_destroy(input->pointer);
|
|
|
|
input->pointer = NULL;
|
|
|
|
}
|
2011-12-21 22:14:54 +00:00
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
if ((caps & WL_SEAT_CAPABILITY_KEYBOARD) && !input->keyboard) {
|
|
|
|
input->keyboard = wl_seat_get_keyboard(seat);
|
|
|
|
wl_keyboard_set_user_data(input->keyboard, input);
|
|
|
|
wl_keyboard_add_listener(input->keyboard, &keyboard_listener,
|
|
|
|
input);
|
|
|
|
} else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && input->keyboard) {
|
|
|
|
wl_keyboard_destroy(input->keyboard);
|
|
|
|
input->keyboard = NULL;
|
|
|
|
}
|
2011-12-21 22:14:54 +00:00
|
|
|
}
|
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
static const struct wl_seat_listener seat_listener = {
|
|
|
|
seat_handle_capabilities,
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-05 13:58:51 +00:00
|
|
|
struct display *
|
|
|
|
input_get_display(struct input *input)
|
|
|
|
{
|
|
|
|
return input->display;
|
|
|
|
}
|
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
struct wl_seat *
|
|
|
|
input_get_seat(struct input *input)
|
2010-08-25 20:34:05 +00:00
|
|
|
{
|
2012-05-16 17:45:18 +00:00
|
|
|
return input->seat;
|
2010-08-25 20:34:05 +00:00
|
|
|
}
|
|
|
|
|
2011-01-19 19:20:33 +00:00
|
|
|
uint32_t
|
|
|
|
input_get_modifiers(struct input *input)
|
|
|
|
{
|
|
|
|
return input->modifiers;
|
|
|
|
}
|
|
|
|
|
2012-01-11 05:04:42 +00:00
|
|
|
struct widget *
|
|
|
|
input_get_focus_widget(struct input *input)
|
|
|
|
{
|
|
|
|
return input->focus_widget;
|
|
|
|
}
|
|
|
|
|
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,
|
2012-04-12 02:42:15 +00:00
|
|
|
uint32_t serial, struct wl_surface *surface,
|
2012-05-08 16:17:55 +00:00
|
|
|
wl_fixed_t x_w, wl_fixed_t y_w,
|
|
|
|
struct wl_data_offer *offer)
|
2011-10-28 16:26:06 +00:00
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct window *window;
|
2012-05-29 07:58:27 +00:00
|
|
|
void *types_data;
|
2012-05-10 16:21:37 +00:00
|
|
|
float x = wl_fixed_to_double(x_w);
|
|
|
|
float y = wl_fixed_to_double(y_w);
|
2011-10-28 16:26:06 +00:00
|
|
|
char **p;
|
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input->pointer_enter_serial = serial;
|
2011-10-28 16:26:06 +00:00
|
|
|
window = wl_surface_get_user_data(surface);
|
|
|
|
input->pointer_focus = window;
|
|
|
|
|
2012-05-29 07:58:27 +00:00
|
|
|
if (offer) {
|
|
|
|
input->drag_offer = wl_data_offer_get_user_data(offer);
|
|
|
|
|
|
|
|
p = wl_array_add(&input->drag_offer->types, sizeof *p);
|
|
|
|
*p = NULL;
|
|
|
|
|
|
|
|
types_data = input->drag_offer->types.data;
|
|
|
|
} else {
|
|
|
|
input->drag_offer = NULL;
|
|
|
|
types_data = NULL;
|
|
|
|
}
|
2011-10-28 16:26:06 +00:00
|
|
|
|
|
|
|
window = input->pointer_focus;
|
|
|
|
if (window->data_handler)
|
2012-05-29 07:58:27 +00:00
|
|
|
window->data_handler(window, input, x, y, types_data,
|
2011-10-28 16:26:06 +00:00
|
|
|
window->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_leave(void *data, struct wl_data_device *data_device)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
|
2012-05-29 07:58:27 +00:00
|
|
|
if (input->drag_offer) {
|
|
|
|
data_offer_destroy(input->drag_offer);
|
|
|
|
input->drag_offer = NULL;
|
|
|
|
}
|
2011-10-28 16:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
data_device_motion(void *data, struct wl_data_device *data_device,
|
2012-05-08 16:17:55 +00:00
|
|
|
uint32_t time, wl_fixed_t x_w, wl_fixed_t y_w)
|
2011-10-28 16:26:06 +00:00
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct window *window = input->pointer_focus;
|
2012-05-10 16:21:37 +00:00
|
|
|
float x = wl_fixed_to_double(x_w);
|
|
|
|
float y = wl_fixed_to_double(y_w);
|
2012-05-29 07:58:27 +00:00
|
|
|
void *types_data;
|
2011-10-28 16:26:06 +00:00
|
|
|
|
|
|
|
input->sx = x;
|
|
|
|
input->sy = y;
|
|
|
|
|
2012-05-29 07:58:27 +00:00
|
|
|
if (input->drag_offer)
|
|
|
|
types_data = input->drag_offer->types.data;
|
|
|
|
else
|
|
|
|
types_data = NULL;
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
if (window->data_handler)
|
2012-05-29 07:58:27 +00:00
|
|
|
window->data_handler(window, input, x, y, types_data,
|
2011-10-28 16:26:06 +00:00
|
|
|
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);
|
|
|
|
|
2012-01-27 16:04:18 +00:00
|
|
|
if (offer) {
|
|
|
|
input->selection_offer = wl_data_offer_get_user_data(offer);
|
|
|
|
p = wl_array_add(&input->selection_offer->types, sizeof *p);
|
|
|
|
*p = NULL;
|
2012-06-01 03:30:32 +00:00
|
|
|
} else {
|
|
|
|
input->selection_offer = NULL;
|
2012-01-27 16:04:18 +00:00
|
|
|
}
|
2011-10-28 16:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
void
|
2012-06-05 03:37:42 +00:00
|
|
|
input_set_pointer_image_index(struct input *input, int pointer, int index)
|
2012-01-11 03:41:05 +00:00
|
|
|
{
|
|
|
|
struct wl_buffer *buffer;
|
2012-05-22 12:39:42 +00:00
|
|
|
struct wl_cursor *cursor;
|
|
|
|
struct wl_cursor_image *image;
|
2012-01-11 03:41:05 +00:00
|
|
|
|
2012-05-25 06:30:02 +00:00
|
|
|
cursor = input->display->cursors[pointer];
|
2012-05-22 12:39:42 +00:00
|
|
|
if (!cursor)
|
2012-05-09 04:02:33 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-05 03:37:42 +00:00
|
|
|
if (index >= (int) cursor->image_count) {
|
|
|
|
fprintf(stderr, "cursor index out of range\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = cursor->images[index];
|
2012-05-22 12:39:42 +00:00
|
|
|
buffer = wl_cursor_image_get_buffer(image);
|
|
|
|
if (!buffer)
|
2012-01-11 03:41:05 +00:00
|
|
|
return;
|
|
|
|
|
2012-05-03 09:29:46 +00:00
|
|
|
input->current_cursor = pointer;
|
2012-06-15 14:27:35 +00:00
|
|
|
wl_pointer_set_cursor(input->pointer, input->display->serial,
|
|
|
|
input->pointer_surface,
|
|
|
|
image->hotspot_x, image->hotspot_y);
|
|
|
|
wl_surface_attach(input->pointer_surface, buffer, 0, 0);
|
|
|
|
wl_surface_damage(input->pointer_surface, 0, 0,
|
|
|
|
image->width, image->height);
|
2012-01-11 03:41:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 03:37:42 +00:00
|
|
|
void
|
|
|
|
input_set_pointer_image(struct input *input, int pointer)
|
|
|
|
{
|
|
|
|
if (pointer == input->current_cursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
input_set_pointer_image_index(input, pointer, 0);
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
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
|
2012-04-12 02:42:15 +00:00
|
|
|
input_accept(struct input *input, const char *type)
|
2011-10-28 16:26:06 +00:00
|
|
|
{
|
2012-04-12 02:42:15 +00:00
|
|
|
wl_data_offer_accept(input->drag_offer->offer,
|
|
|
|
input->pointer_enter_serial, type);
|
2011-10-28 16:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
2012-03-30 21:10:27 +00:00
|
|
|
if (pipe2(p, O_CLOEXEC) == -1)
|
|
|
|
return;
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-27 18:50:04 +00:00
|
|
|
int
|
|
|
|
input_receive_selection_data_to_fd(struct input *input,
|
|
|
|
const char *mime_type, int fd)
|
|
|
|
{
|
2012-06-01 03:30:32 +00:00
|
|
|
if (input->selection_offer)
|
|
|
|
wl_data_offer_receive(input->selection_offer->offer,
|
|
|
|
mime_type, fd);
|
2011-12-27 18:50:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
void
|
2012-04-12 02:42:15 +00:00
|
|
|
window_move(struct window *window, struct input *input, uint32_t serial)
|
2011-10-28 16:26:06 +00:00
|
|
|
{
|
2011-11-29 08:25:08 +00:00
|
|
|
if (!window->shell_surface)
|
|
|
|
return;
|
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
wl_shell_surface_move(window->shell_surface, input->seat, serial);
|
2010-08-18 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 17:23:19 +00:00
|
|
|
static void
|
2012-03-26 17:49:29 +00:00
|
|
|
idle_resize(struct window *window)
|
2012-01-10 17:23:19 +00:00
|
|
|
{
|
2012-01-11 00:11:42 +00:00
|
|
|
struct widget *widget;
|
|
|
|
|
2012-03-26 17:49:29 +00:00
|
|
|
window->resize_needed = 0;
|
2012-01-11 00:11:42 +00:00
|
|
|
widget = window->widget;
|
2012-01-31 20:30:47 +00:00
|
|
|
widget_set_allocation(widget,
|
|
|
|
window->pending_allocation.x,
|
|
|
|
window->pending_allocation.y,
|
|
|
|
window->pending_allocation.width,
|
|
|
|
window->pending_allocation.height);
|
2012-01-10 18:52:34 +00:00
|
|
|
|
2012-02-23 22:30:45 +00:00
|
|
|
if (window->input_region) {
|
|
|
|
wl_region_destroy(window->input_region);
|
|
|
|
window->input_region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->opaque_region) {
|
|
|
|
wl_region_destroy(window->opaque_region);
|
|
|
|
window->opaque_region = NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-11 00:11:42 +00:00
|
|
|
if (widget->resize_handler)
|
|
|
|
widget->resize_handler(widget,
|
2012-01-31 20:30:47 +00:00
|
|
|
widget->allocation.width,
|
|
|
|
widget->allocation.height,
|
2012-01-11 00:11:42 +00:00
|
|
|
widget->user_data);
|
|
|
|
|
2012-01-31 16:53:20 +00:00
|
|
|
if (window->allocation.width != widget->allocation.width ||
|
|
|
|
window->allocation.height != widget->allocation.height) {
|
|
|
|
window->allocation = widget->allocation;
|
|
|
|
window_schedule_redraw(window);
|
|
|
|
}
|
2012-01-10 17:23:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_schedule_resize(struct window *window, int width, int height)
|
|
|
|
{
|
2012-01-31 20:30:47 +00:00
|
|
|
window->pending_allocation.x = 0;
|
|
|
|
window->pending_allocation.y = 0;
|
|
|
|
window->pending_allocation.width = width;
|
|
|
|
window->pending_allocation.height = height;
|
|
|
|
|
2012-03-26 17:49:29 +00:00
|
|
|
window->resize_needed = 1;
|
|
|
|
window_schedule_redraw(window);
|
2012-01-10 17:23:19 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 00:11:42 +00:00
|
|
|
void
|
|
|
|
widget_schedule_resize(struct widget *widget, int32_t width, int32_t height)
|
|
|
|
{
|
2012-01-11 03:41:05 +00:00
|
|
|
window_schedule_resize(widget->window, width, height);
|
2012-01-11 00:11:42 +00:00
|
|
|
}
|
|
|
|
|
2012-04-18 01:06:18 +00:00
|
|
|
static void
|
|
|
|
handle_ping(void *data, struct wl_shell_surface *shell_surface,
|
|
|
|
uint32_t serial)
|
|
|
|
{
|
|
|
|
wl_shell_surface_pong(shell_surface, serial);
|
|
|
|
}
|
|
|
|
|
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,
|
2012-04-12 02:42:15 +00:00
|
|
|
uint32_t edges, 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;
|
2010-08-05 02:44:55 +00:00
|
|
|
|
2011-01-28 20:18:33 +00:00
|
|
|
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;
|
2012-01-31 20:30:47 +00:00
|
|
|
window_schedule_resize(window, width, height);
|
2010-08-05 02:44:55 +00:00
|
|
|
}
|
|
|
|
|
2012-01-19 13:17:59 +00:00
|
|
|
static void
|
|
|
|
menu_destroy(struct menu *menu)
|
|
|
|
{
|
|
|
|
widget_destroy(menu->widget);
|
|
|
|
window_destroy(menu->window);
|
|
|
|
free(menu);
|
|
|
|
}
|
|
|
|
|
2012-01-05 03:19:14 +00:00
|
|
|
static void
|
|
|
|
handle_popup_done(void *data, struct wl_shell_surface *shell_surface)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
2012-01-11 04:46:33 +00:00
|
|
|
struct menu *menu = window->widget->user_data;
|
|
|
|
|
2012-01-05 03:19:14 +00:00
|
|
|
/* FIXME: Need more context in this event, at least the input
|
2012-01-11 04:46:33 +00:00
|
|
|
* device. Or just use wl_callback. And this really needs to
|
|
|
|
* be a window vfunc that the menu can set. And we need the
|
|
|
|
* time. */
|
2012-01-05 03:19:14 +00:00
|
|
|
|
2012-01-07 02:59:05 +00:00
|
|
|
menu->func(window->parent, menu->current, window->parent->user_data);
|
2012-04-12 02:42:15 +00:00
|
|
|
input_ungrab(menu->input);
|
2012-01-19 13:17:59 +00:00
|
|
|
menu_destroy(menu);
|
2012-01-05 03:19:14 +00:00
|
|
|
}
|
|
|
|
|
2011-11-25 10:09:16 +00:00
|
|
|
static const struct wl_shell_surface_listener shell_surface_listener = {
|
2012-04-18 01:06:18 +00:00
|
|
|
handle_ping,
|
2010-08-05 02:44:55 +00:00
|
|
|
handle_configure,
|
2012-01-05 03:19:14 +00:00
|
|
|
handle_popup_done
|
2010-08-05 02:44:55 +00:00
|
|
|
};
|
|
|
|
|
2011-02-18 22:00:55 +00:00
|
|
|
void
|
|
|
|
window_get_allocation(struct window *window,
|
|
|
|
struct rectangle *allocation)
|
|
|
|
{
|
|
|
|
*allocation = window->allocation;
|
|
|
|
}
|
|
|
|
|
2012-01-10 18:52:34 +00:00
|
|
|
static void
|
|
|
|
widget_redraw(struct widget *widget)
|
|
|
|
{
|
|
|
|
struct widget *child;
|
|
|
|
|
|
|
|
if (widget->redraw_handler)
|
|
|
|
widget->redraw_handler(widget, widget->user_data);
|
|
|
|
wl_list_for_each(child, &widget->child_list, link)
|
|
|
|
widget_redraw(child);
|
|
|
|
}
|
|
|
|
|
2012-03-24 18:42:09 +00:00
|
|
|
static void
|
|
|
|
frame_callback(void *data, struct wl_callback *callback, uint32_t time)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
|
|
|
|
wl_callback_destroy(callback);
|
|
|
|
window->redraw_scheduled = 0;
|
|
|
|
if (window->redraw_needed)
|
|
|
|
window_schedule_redraw(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener listener = {
|
|
|
|
frame_callback
|
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2012-03-26 17:49:29 +00:00
|
|
|
struct window *window = container_of(task, struct window, redraw_task);
|
2012-03-24 18:42:09 +00:00
|
|
|
struct wl_callback *callback;
|
2010-06-15 03:52:50 +00:00
|
|
|
|
2012-03-26 17:49:29 +00:00
|
|
|
if (window->resize_needed)
|
|
|
|
idle_resize(window);
|
|
|
|
|
2012-01-10 15:49:41 +00:00
|
|
|
window_create_surface(window);
|
2012-01-10 18:52:34 +00:00
|
|
|
widget_redraw(window->widget);
|
2012-01-10 15:49:41 +00:00
|
|
|
window_flush(window);
|
2012-03-24 18:42:09 +00:00
|
|
|
window->redraw_needed = 0;
|
2012-04-13 16:01:18 +00:00
|
|
|
wl_list_init(&window->redraw_task.link);
|
2012-03-24 18:42:09 +00:00
|
|
|
|
|
|
|
callback = wl_surface_frame(window->surface);
|
|
|
|
wl_callback_add_listener(callback, &listener, window);
|
2010-06-15 03:52:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_schedule_redraw(struct window *window)
|
|
|
|
{
|
2012-03-24 18:42:09 +00:00
|
|
|
window->redraw_needed = 1;
|
2010-06-15 03:52:50 +00:00
|
|
|
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)
|
|
|
|
{
|
2012-02-17 03:56:12 +00:00
|
|
|
if (!window->display->shell)
|
|
|
|
return;
|
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) {
|
|
|
|
window->type = TYPE_FULLSCREEN;
|
2008-12-22 17:14:50 +00:00
|
|
|
window->saved_allocation = window->allocation;
|
2012-02-17 03:56:12 +00:00
|
|
|
wl_shell_surface_set_fullscreen(window->shell_surface,
|
|
|
|
WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
|
|
|
|
0, NULL);
|
2008-12-22 17:14:50 +00:00
|
|
|
} else {
|
2011-09-06 22:02:34 +00:00
|
|
|
window->type = TYPE_TOPLEVEL;
|
2012-02-17 03:56:12 +00:00
|
|
|
wl_shell_surface_set_toplevel(window->shell_surface);
|
|
|
|
window_schedule_resize(window,
|
|
|
|
window->saved_allocation.width,
|
|
|
|
window->saved_allocation.height);
|
2008-12-22 17:14:50 +00:00
|
|
|
}
|
2010-06-08 18:08:30 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 20:53:46 +00:00
|
|
|
void
|
|
|
|
window_set_maximized(struct window *window, int maximized)
|
|
|
|
{
|
|
|
|
if (!window->display->shell)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((window->type == TYPE_MAXIMIZED) == maximized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (window->type == TYPE_TOPLEVEL) {
|
|
|
|
window->saved_allocation = window->allocation;
|
|
|
|
wl_shell_surface_set_maximized(window->shell_surface, NULL);
|
|
|
|
window->type = TYPE_MAXIMIZED;
|
|
|
|
} else {
|
|
|
|
wl_shell_surface_set_toplevel(window->shell_surface);
|
|
|
|
window->type = TYPE_TOPLEVEL;
|
|
|
|
window_schedule_resize(window,
|
|
|
|
window->saved_allocation.width,
|
|
|
|
window->saved_allocation.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
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
|
|
|
}
|
|
|
|
|
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-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;
|
|
|
|
}
|
|
|
|
|
2012-01-07 02:59:05 +00:00
|
|
|
void
|
|
|
|
window_set_close_handler(struct window *window,
|
|
|
|
window_close_handler_t handler)
|
|
|
|
{
|
|
|
|
window->close_handler = handler;
|
|
|
|
}
|
|
|
|
|
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);
|
2012-05-02 13:47:55 +00:00
|
|
|
if (window->shell_surface)
|
|
|
|
wl_shell_surface_set_title(window->shell_surface, title);
|
2011-01-14 07:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
window_get_title(struct window *window)
|
|
|
|
{
|
|
|
|
return window->title;
|
|
|
|
}
|
|
|
|
|
2012-05-27 20:25:02 +00:00
|
|
|
void
|
|
|
|
window_set_text_cursor_position(struct window *window, int32_t x, int32_t y)
|
|
|
|
{
|
|
|
|
struct text_cursor_position *text_cursor_position =
|
|
|
|
window->display->text_cursor_position;
|
|
|
|
|
2012-06-01 18:46:10 +00:00
|
|
|
if (!text_cursor_position)
|
2012-05-27 20:25:02 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
text_cursor_position_notify(text_cursor_position,
|
2012-06-01 18:46:09 +00:00
|
|
|
window->surface,
|
|
|
|
wl_fixed_from_int(x),
|
|
|
|
wl_fixed_from_int(y));
|
2012-05-27 20:25:02 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-04-20 02:50:09 +00:00
|
|
|
static void
|
|
|
|
surface_enter(void *data,
|
2012-05-15 16:55:34 +00:00
|
|
|
struct wl_surface *wl_surface, struct wl_output *wl_output)
|
2012-04-20 02:50:09 +00:00
|
|
|
{
|
2012-05-15 16:55:34 +00:00
|
|
|
struct window *window = data;
|
|
|
|
struct output *output;
|
|
|
|
struct output *output_found = NULL;
|
|
|
|
struct window_output *window_output;
|
|
|
|
|
|
|
|
wl_list_for_each(output, &window->display->output_list, link) {
|
|
|
|
if (output->output == wl_output) {
|
|
|
|
output_found = output;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!output_found)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window_output = malloc (sizeof *window_output);
|
|
|
|
window_output->output = output_found;
|
|
|
|
|
|
|
|
wl_list_insert (&window->window_output_list, &window_output->link);
|
2012-04-20 02:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
surface_leave(void *data,
|
|
|
|
struct wl_surface *wl_surface, struct wl_output *output)
|
|
|
|
{
|
2012-05-15 16:55:34 +00:00
|
|
|
struct window *window = data;
|
|
|
|
struct window_output *window_output;
|
|
|
|
struct window_output *window_output_found = NULL;
|
|
|
|
|
|
|
|
wl_list_for_each(window_output, &window->window_output_list, link) {
|
|
|
|
if (window_output->output->output == output) {
|
|
|
|
window_output_found = window_output;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window_output_found) {
|
|
|
|
wl_list_remove(&window_output_found->link);
|
|
|
|
free(window_output_found);
|
|
|
|
}
|
2012-04-20 02:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_surface_listener surface_listener = {
|
|
|
|
surface_enter,
|
|
|
|
surface_leave
|
|
|
|
};
|
|
|
|
|
2011-01-21 23:03:15 +00:00
|
|
|
static struct window *
|
2012-01-31 20:24:48 +00:00
|
|
|
window_create_internal(struct display *display, struct window *parent)
|
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);
|
2012-04-20 02:50:09 +00:00
|
|
|
wl_surface_add_listener(window->surface, &surface_listener, window);
|
2011-11-29 08:25:08 +00:00
|
|
|
if (display->shell) {
|
|
|
|
window->shell_surface =
|
|
|
|
wl_shell_get_shell_surface(display->shell,
|
|
|
|
window->surface);
|
2012-05-02 13:47:55 +00:00
|
|
|
if (window->title)
|
|
|
|
wl_shell_surface_set_title(window->shell_surface,
|
|
|
|
window->title);
|
2011-11-29 08:25:08 +00:00
|
|
|
}
|
2010-12-17 14:53:12 +00:00
|
|
|
window->allocation.x = 0;
|
|
|
|
window->allocation.y = 0;
|
2012-01-31 20:24:48 +00:00
|
|
|
window->allocation.width = 0;
|
|
|
|
window->allocation.height = 0;
|
2009-01-27 04:42:46 +00:00
|
|
|
window->saved_allocation = window->allocation;
|
2011-05-13 17:45:17 +00:00
|
|
|
window->transparent = 1;
|
2012-04-27 21:17:12 +00:00
|
|
|
window->type = TYPE_NONE;
|
2012-02-23 22:30:45 +00:00
|
|
|
window->input_region = NULL;
|
|
|
|
window->opaque_region = NULL;
|
2012-01-09 15:34:35 +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
|
|
|
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);
|
2012-04-13 16:01:18 +00:00
|
|
|
wl_list_init(&window->redraw_task.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
|
|
|
|
2012-05-15 16:55:34 +00:00
|
|
|
wl_list_init (&window->window_output_list);
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2011-01-21 23:03:15 +00:00
|
|
|
struct window *
|
2012-01-31 20:24:48 +00:00
|
|
|
window_create(struct display *display)
|
2011-01-21 23:03:15 +00:00
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
|
2012-01-31 20:24:48 +00:00
|
|
|
window = window_create_internal(display, NULL);
|
2011-01-21 23:03:15 +00:00
|
|
|
if (!window)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct window *
|
|
|
|
window_create_transient(struct display *display, struct window *parent,
|
2012-05-21 13:47:46 +00:00
|
|
|
int32_t x, int32_t y, uint32_t flags)
|
2011-01-21 23:03:15 +00:00
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
|
2012-01-31 20:24:48 +00:00
|
|
|
window = window_create_internal(parent->display, parent);
|
2011-01-21 23:03:15 +00:00
|
|
|
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;
|
|
|
|
|
2012-02-17 03:56:12 +00:00
|
|
|
if (display->shell)
|
|
|
|
wl_shell_surface_set_transient(window->shell_surface,
|
|
|
|
window->parent->shell_surface,
|
2012-05-21 13:47:46 +00:00
|
|
|
window->x, window->y, flags);
|
2012-02-17 03:56:12 +00:00
|
|
|
|
2011-01-21 23:03:15 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2012-01-11 04:46:33 +00:00
|
|
|
static void
|
2012-01-09 15:42:41 +00:00
|
|
|
menu_set_item(struct menu *menu, int sy)
|
2011-12-19 20:40:10 +00:00
|
|
|
{
|
|
|
|
int next;
|
|
|
|
|
|
|
|
next = (sy - 8) / 20;
|
|
|
|
if (menu->current != next) {
|
|
|
|
menu->current = next;
|
2012-01-10 14:43:58 +00:00
|
|
|
widget_schedule_redraw(menu->widget);
|
2011-12-19 20:40:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-01-09 14:44:45 +00:00
|
|
|
menu_motion_handler(struct widget *widget,
|
2011-12-19 20:40:10 +00:00
|
|
|
struct input *input, uint32_t time,
|
2012-05-10 16:21:37 +00:00
|
|
|
float x, float y, void *data)
|
2011-12-19 20:40:10 +00:00
|
|
|
{
|
2012-01-11 04:46:33 +00:00
|
|
|
struct menu *menu = data;
|
|
|
|
|
|
|
|
if (widget == menu->widget)
|
|
|
|
menu_set_item(data, y);
|
|
|
|
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_LEFT_PTR;
|
2011-12-19 20:40:10 +00:00
|
|
|
}
|
|
|
|
|
2012-01-09 16:22:32 +00:00
|
|
|
static int
|
2012-01-09 14:22:30 +00:00
|
|
|
menu_enter_handler(struct widget *widget,
|
2012-05-10 16:21:37 +00:00
|
|
|
struct input *input, float x, float y, void *data)
|
2011-12-19 20:40:10 +00:00
|
|
|
{
|
2012-01-11 04:46:33 +00:00
|
|
|
struct menu *menu = data;
|
|
|
|
|
|
|
|
if (widget == menu->widget)
|
|
|
|
menu_set_item(data, y);
|
|
|
|
|
2012-05-25 13:01:41 +00:00
|
|
|
return CURSOR_LEFT_PTR;
|
2011-12-19 20:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-09 14:22:30 +00:00
|
|
|
menu_leave_handler(struct widget *widget, struct input *input, void *data)
|
2011-12-19 20:40:10 +00:00
|
|
|
{
|
2012-01-11 04:46:33 +00:00
|
|
|
struct menu *menu = data;
|
|
|
|
|
|
|
|
if (widget == menu->widget)
|
|
|
|
menu_set_item(data, -200);
|
2011-12-19 20:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-09 16:12:05 +00:00
|
|
|
menu_button_handler(struct widget *widget,
|
2011-12-19 20:40:10 +00:00
|
|
|
struct input *input, uint32_t time,
|
2012-05-30 15:31:51 +00:00
|
|
|
uint32_t button, enum wl_pointer_button_state state,
|
|
|
|
void *data)
|
2011-12-19 20:40:10 +00:00
|
|
|
|
|
|
|
{
|
2012-01-10 14:43:58 +00:00
|
|
|
struct menu *menu = data;
|
2011-12-19 20:40:10 +00:00
|
|
|
|
2012-05-30 15:31:51 +00:00
|
|
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED &&
|
|
|
|
time - menu->time > 500) {
|
2012-01-11 04:46:33 +00:00
|
|
|
/* Either relase after press-drag-release or
|
|
|
|
* click-motion-click. */
|
2012-01-10 14:43:58 +00:00
|
|
|
menu->func(menu->window->parent,
|
|
|
|
menu->current, menu->window->parent->user_data);
|
2012-04-12 02:42:15 +00:00
|
|
|
input_ungrab(input);
|
2012-01-19 13:17:59 +00:00
|
|
|
menu_destroy(menu);
|
2012-01-07 02:59:05 +00:00
|
|
|
}
|
2011-12-19 20:40:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-01-10 17:23:19 +00:00
|
|
|
menu_redraw_handler(struct widget *widget, void *data)
|
2011-12-19 20:40:10 +00:00
|
|
|
{
|
|
|
|
cairo_t *cr;
|
|
|
|
const int32_t r = 3, margin = 3;
|
|
|
|
struct menu *menu = data;
|
|
|
|
int32_t width, height, i;
|
2012-01-10 17:23:19 +00:00
|
|
|
struct window *window = widget->window;
|
2011-12-19 20:40:10 +00:00
|
|
|
|
|
|
|
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);
|
2012-01-19 18:54:09 +00:00
|
|
|
|
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_OVER);
|
2011-12-19 20:40:10 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-01-19 13:17:59 +00:00
|
|
|
void
|
|
|
|
window_show_menu(struct display *display,
|
|
|
|
struct input *input, uint32_t time, struct window *parent,
|
|
|
|
int32_t x, int32_t y,
|
|
|
|
menu_func_t func, const char **entries, int count)
|
2011-12-19 20:40:10 +00:00
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
struct menu *menu;
|
2012-01-10 14:43:58 +00:00
|
|
|
const int32_t margin = 3;
|
2011-12-19 20:40:10 +00:00
|
|
|
|
|
|
|
menu = malloc(sizeof *menu);
|
|
|
|
if (!menu)
|
2012-01-19 13:17:59 +00:00
|
|
|
return;
|
2011-12-19 20:40:10 +00:00
|
|
|
|
2012-01-31 20:24:48 +00:00
|
|
|
window = window_create_internal(parent->display, parent);
|
2011-12-19 20:40:10 +00:00
|
|
|
if (!window)
|
2012-01-19 13:17:59 +00:00
|
|
|
return;
|
2011-12-19 20:40:10 +00:00
|
|
|
|
|
|
|
menu->window = window;
|
2012-01-10 14:43:58 +00:00
|
|
|
menu->widget = window_add_widget(menu->window, menu);
|
2011-12-19 20:40:10 +00:00
|
|
|
menu->entries = entries;
|
|
|
|
menu->count = count;
|
2012-01-11 04:46:33 +00:00
|
|
|
menu->current = -1;
|
2012-01-05 03:19:14 +00:00
|
|
|
menu->time = time;
|
2012-01-07 02:59:05 +00:00
|
|
|
menu->func = func;
|
2012-01-11 04:46:33 +00:00
|
|
|
menu->input = input;
|
2011-12-19 20:40:10 +00:00
|
|
|
window->type = TYPE_MENU;
|
|
|
|
window->x = x;
|
|
|
|
window->y = y;
|
|
|
|
|
2012-04-13 16:55:45 +00:00
|
|
|
input_ungrab(input);
|
2012-05-16 17:45:18 +00:00
|
|
|
wl_shell_surface_set_popup(window->shell_surface, input->seat,
|
2012-04-13 16:37:19 +00:00
|
|
|
display_get_serial(window->display),
|
2012-01-05 03:19:14 +00:00
|
|
|
window->parent->shell_surface,
|
|
|
|
window->x, window->y, 0);
|
2011-12-19 20:40:10 +00:00
|
|
|
|
2012-01-10 17:23:19 +00:00
|
|
|
widget_set_redraw_handler(menu->widget, menu_redraw_handler);
|
2012-01-10 14:43:58 +00:00
|
|
|
widget_set_enter_handler(menu->widget, menu_enter_handler);
|
|
|
|
widget_set_leave_handler(menu->widget, menu_leave_handler);
|
|
|
|
widget_set_motion_handler(menu->widget, menu_motion_handler);
|
|
|
|
widget_set_button_handler(menu->widget, menu_button_handler);
|
2012-01-09 14:22:30 +00:00
|
|
|
|
2012-01-11 04:46:33 +00:00
|
|
|
input_grab(input, menu->widget, 0);
|
2012-01-31 20:24:48 +00:00
|
|
|
window_schedule_resize(window, 200, count * 20 + margin * 2);
|
2011-12-19 20:40:10 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-30 15:32:01 +00:00
|
|
|
static void
|
|
|
|
fini_xkb(struct input *input)
|
|
|
|
{
|
|
|
|
xkb_state_unref(input->xkb.state);
|
|
|
|
xkb_map_unref(input->xkb.keymap);
|
|
|
|
}
|
|
|
|
|
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;
|
2012-05-16 17:45:18 +00:00
|
|
|
input->seat = wl_display_bind(d->display, id, &wl_seat_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);
|
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
wl_seat_add_listener(input->seat, &seat_listener, input);
|
|
|
|
wl_seat_set_user_data(input->seat, input);
|
2010-08-18 19:28:04 +00:00
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
input->data_device =
|
|
|
|
wl_data_device_manager_get_data_device(d->data_device_manager,
|
2012-05-16 17:45:18 +00:00
|
|
|
input->seat);
|
|
|
|
wl_data_device_add_listener(input->data_device, &data_device_listener,
|
|
|
|
input);
|
2012-06-15 14:27:35 +00:00
|
|
|
|
|
|
|
input->pointer_surface = wl_compositor_create_surface(d->compositor);
|
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);
|
2012-04-12 02:42:15 +00:00
|
|
|
input_remove_pointer_focus(input);
|
2011-12-16 10:02:09 +00:00
|
|
|
|
2012-06-01 11:14:06 +00:00
|
|
|
if (input->xkb.state)
|
|
|
|
xkb_state_unref(input->xkb.state);
|
|
|
|
if (input->xkb.keymap)
|
|
|
|
xkb_map_unref(input->xkb.keymap);
|
|
|
|
|
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);
|
2012-05-30 15:32:01 +00:00
|
|
|
fini_xkb(input);
|
|
|
|
|
2012-06-15 14:27:35 +00:00
|
|
|
wl_surface_destroy(input->pointer_surface);
|
|
|
|
|
2011-12-16 10:02:09 +00:00
|
|
|
wl_list_remove(&input->link);
|
2012-05-16 17:45:18 +00:00
|
|
|
wl_seat_destroy(input->seat);
|
2011-12-16 10:02:09 +00:00
|
|
|
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);
|
2012-05-16 17:45:18 +00:00
|
|
|
} else if (strcmp(interface, "wl_seat") == 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);
|
2012-05-27 20:25:02 +00:00
|
|
|
} else if (strcmp(interface, "text_cursor_position") == 0) {
|
|
|
|
d->text_cursor_position =
|
|
|
|
wl_display_bind(display, id,
|
|
|
|
&text_cursor_position_interface);
|
2008-12-30 16:03:33 +00:00
|
|
|
}
|
2008-12-08 05:01:36 +00:00
|
|
|
}
|
|
|
|
|
2012-04-03 15:57:44 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
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
|
|
|
|
2012-03-12 00:48:41 +00:00
|
|
|
#ifdef USE_CAIRO_GLESV2
|
|
|
|
# define GL_BIT EGL_OPENGL_ES2_BIT
|
|
|
|
#else
|
|
|
|
# define GL_BIT EGL_OPENGL_BIT
|
|
|
|
#endif
|
|
|
|
|
2012-01-11 19:24:46 +00:00
|
|
|
static const EGLint argb_cfg_attribs[] = {
|
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PIXMAP_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,
|
2012-03-12 00:48:41 +00:00
|
|
|
EGL_RENDERABLE_TYPE, GL_BIT,
|
2011-02-10 11:04:30 +00:00
|
|
|
EGL_NONE
|
|
|
|
};
|
2010-12-06 14:18:12 +00:00
|
|
|
|
2012-01-18 19:50:58 +00:00
|
|
|
#ifdef USE_CAIRO_GLESV2
|
|
|
|
static const EGLint context_attribs[] = {
|
|
|
|
EGL_CONTEXT_CLIENT_VERSION, 2,
|
|
|
|
EGL_NONE
|
|
|
|
};
|
|
|
|
EGLint api = EGL_OPENGL_ES_API;
|
|
|
|
#else
|
|
|
|
EGLint *context_attribs = NULL;
|
|
|
|
EGLint api = EGL_OPENGL_API;
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-01-18 19:50:58 +00:00
|
|
|
if (!eglBindAPI(api)) {
|
2010-12-06 14:18:12 +00:00
|
|
|
fprintf(stderr, "failed to bind api EGL_OPENGL_API\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-11 19:24:46 +00:00
|
|
|
if (!eglChooseConfig(d->dpy, argb_cfg_attribs,
|
|
|
|
&d->argb_config, 1, &n) || n != 1) {
|
|
|
|
fprintf(stderr, "failed to choose argb config\n");
|
2011-08-31 20:21:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-11 19:24:46 +00:00
|
|
|
d->argb_ctx = eglCreateContext(d->dpy, d->argb_config,
|
2012-01-18 19:50:58 +00:00
|
|
|
EGL_NO_CONTEXT, context_attribs);
|
2011-09-27 19:57:31 +00:00
|
|
|
if (d->argb_ctx == NULL) {
|
2010-12-06 14:18:12 +00:00
|
|
|
fprintf(stderr, "failed to create context\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-02-29 21:15:53 +00:00
|
|
|
if (!eglMakeCurrent(d->dpy, NULL, NULL, d->argb_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->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);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
eglMakeCurrent(display->dpy, EGL_NO_SURFACE, EGL_NO_SURFACE,
|
|
|
|
EGL_NO_CONTEXT);
|
|
|
|
|
|
|
|
eglTerminate(display->dpy);
|
|
|
|
eglReleaseThread();
|
|
|
|
}
|
2012-04-03 15:57:44 +00:00
|
|
|
#endif
|
2011-12-15 13:20:04 +00:00
|
|
|
|
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 *
|
2012-03-12 01:05:57 +00:00
|
|
|
display_create(int argc, char *argv[])
|
2008-11-03 20:31:30 +00:00
|
|
|
{
|
2009-01-27 04:42:46 +00:00
|
|
|
struct display *d;
|
2010-06-08 18:08:30 +00:00
|
|
|
|
2012-03-12 01:05:57 +00:00
|
|
|
argc = parse_options(xkb_options,
|
|
|
|
ARRAY_LENGTH(xkb_options), argc, argv);
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:53:43 +00:00
|
|
|
d->epoll_fd = os_epoll_create_cloexec();
|
2011-09-14 21:33:48 +00:00
|
|
|
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
|
|
|
|
2012-05-30 15:32:01 +00:00
|
|
|
d->xkb_context = xkb_context_new(0);
|
2012-06-01 11:14:06 +00:00
|
|
|
if (d->xkb_context == NULL) {
|
|
|
|
fprintf(stderr, "Failed to create XKB context\n");
|
2012-05-30 15:32:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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);
|
2012-04-03 15:57:44 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-02-04 19:11:33 +00:00
|
|
|
if (init_egl(d) < 0)
|
2010-06-08 18:59:44 +00:00
|
|
|
return NULL;
|
2012-04-03 15:57:44 +00:00
|
|
|
#endif
|
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");
|
|
|
|
|
2012-05-25 06:30:02 +00:00
|
|
|
create_cursors(d);
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2012-05-16 02:25:28 +00:00
|
|
|
d->theme = theme_create();
|
2010-06-15 21:16:35 +00:00
|
|
|
|
2010-06-09 00:34:11 +00:00
|
|
|
wl_list_init(&d->window_list);
|
|
|
|
|
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
|
|
|
|
2012-05-30 15:32:01 +00:00
|
|
|
xkb_context_unref(display->xkb_context);
|
2011-12-19 08:31:45 +00:00
|
|
|
|
2012-05-16 02:25:28 +00:00
|
|
|
theme_destroy(display->theme);
|
2012-05-25 06:30:02 +00:00
|
|
|
destroy_cursors(display);
|
2011-12-19 08:31:45 +00:00
|
|
|
|
2012-04-03 15:57:44 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2011-12-15 13:20:04 +00:00
|
|
|
fini_egl(display);
|
2012-04-03 15:57:44 +00:00
|
|
|
#endif
|
2011-12-15 13:20:04 +00:00
|
|
|
|
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);
|
2012-02-28 19:29:19 +00:00
|
|
|
wl_display_disconnect(display->display);
|
2011-12-15 13:20:04 +00:00
|
|
|
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
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
uint32_t
|
|
|
|
display_get_serial(struct display *display)
|
|
|
|
{
|
|
|
|
return display->serial;
|
|
|
|
}
|
|
|
|
|
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-09-27 19:57:31 +00:00
|
|
|
EGLConfig
|
|
|
|
display_get_argb_egl_config(struct display *d)
|
|
|
|
{
|
2012-01-11 19:24:46 +00:00
|
|
|
return d->argb_config;
|
2011-09-27 19:57:31 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2012-02-29 21:15:53 +00:00
|
|
|
if (device == display->argb_device)
|
2011-09-27 19:57:31 +00:00
|
|
|
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;
|
|
|
|
|
2012-02-29 21:15:53 +00:00
|
|
|
if (!eglMakeCurrent(display->dpy, NULL, NULL, display->argb_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) {
|
2012-01-09 23:48:14 +00:00
|
|
|
wl_display_flush(display->display);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2011-09-14 21:33:48 +00:00
|
|
|
|
2011-12-15 08:14:07 +00:00
|
|
|
if (!display->running)
|
|
|
|
break;
|
|
|
|
|
2012-01-09 23:48:14 +00:00
|
|
|
wl_display_flush(display->display);
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
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;
|
|
|
|
}
|