2008-12-02 20:15:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Kristian Høgsberg
|
2013-02-13 14:17:13 +00:00
|
|
|
* Copyright © 2012-2013 Collabora, Ltd.
|
2008-12-02 20:15:01 +00:00
|
|
|
*
|
2015-06-11 05:48:59 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2008-12-02 20:15:01 +00:00
|
|
|
*
|
2015-06-11 05:48:59 +00:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2008-12-02 20:15:01 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-22 15:03:19 +00:00
|
|
|
#include "config.h"
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2008-11-02 23:51:48 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2013-04-25 10:57:53 +00:00
|
|
|
#include <stdarg.h>
|
2008-11-02 23:51:48 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2012-10-11 01:34:26 +00:00
|
|
|
#include <errno.h>
|
2008-11-02 23:51:48 +00:00
|
|
|
#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>
|
2015-03-04 22:26:25 +00:00
|
|
|
#include <stdbool.h>
|
2010-06-08 18:08:30 +00:00
|
|
|
|
2012-10-16 14:27:19 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
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
|
|
|
|
2010-06-08 18:08:30 +00:00
|
|
|
#include <cairo-gl.h>
|
2012-10-16 14:27:19 +00:00
|
|
|
#else /* HAVE_CAIRO_EGL */
|
|
|
|
typedef void *EGLDisplay;
|
|
|
|
typedef void *EGLConfig;
|
|
|
|
typedef void *EGLContext;
|
|
|
|
#define EGL_NO_DISPLAY ((EGLDisplay)0)
|
|
|
|
#endif /* no HAVE_CAIRO_EGL */
|
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>
|
2015-06-15 22:37:07 +00:00
|
|
|
#include "shared/cairo-util.h"
|
2015-06-15 22:37:08 +00:00
|
|
|
#include "shared/helpers.h"
|
2015-11-17 08:00:32 +00:00
|
|
|
#include "xdg-shell-unstable-v5-client-protocol.h"
|
2012-05-27 20:25:02 +00:00
|
|
|
#include "text-cursor-position-client-protocol.h"
|
2015-06-15 22:37:07 +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
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include "ivi-application-client-protocol.h"
|
|
|
|
#define IVI_SURFACE_ID 9000
|
|
|
|
|
2012-05-07 18:34:26 +00:00
|
|
|
struct shm_pool;
|
2012-05-03 09:29:46 +00:00
|
|
|
|
2012-10-11 01:34:26 +00:00
|
|
|
struct global {
|
|
|
|
uint32_t name;
|
|
|
|
char *interface;
|
|
|
|
uint32_t version;
|
|
|
|
struct wl_list link;
|
|
|
|
};
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
struct display {
|
2008-11-26 03:40:39 +00:00
|
|
|
struct wl_display *display;
|
2012-10-11 01:34:26 +00:00
|
|
|
struct wl_registry *registry;
|
2008-12-16 01:35:24 +00:00
|
|
|
struct wl_compositor *compositor;
|
2013-04-25 10:57:48 +00:00
|
|
|
struct wl_subcompositor *subcompositor;
|
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;
|
2013-12-09 19:58:00 +00:00
|
|
|
struct xdg_shell *xdg_shell;
|
2014-11-27 04:24:52 +00:00
|
|
|
struct ivi_application *ivi_application; /* ivi style shell */
|
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;
|
2012-10-03 04:12:35 +00:00
|
|
|
uint32_t display_fd_events;
|
2011-09-14 21:33:48 +00:00
|
|
|
struct task display_task;
|
|
|
|
|
|
|
|
int epoll_fd;
|
|
|
|
struct wl_list deferred_list;
|
|
|
|
|
2011-12-15 08:14:07 +00:00
|
|
|
int running;
|
|
|
|
|
2012-10-11 01:34:26 +00:00
|
|
|
struct wl_list global_list;
|
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-11-30 08:52:38 +00:00
|
|
|
display_output_handler_t output_configure_handler;
|
2012-10-11 01:34:26 +00:00
|
|
|
display_global_handler_t global_handler;
|
2013-10-23 05:58:35 +00:00
|
|
|
display_global_handler_t global_handler_remove;
|
2011-11-30 08:52:38 +00:00
|
|
|
|
|
|
|
void *user_data;
|
2012-05-30 15:32:01 +00:00
|
|
|
|
|
|
|
struct xkb_context *xkb_context;
|
2012-08-29 20:13:02 +00:00
|
|
|
|
2012-11-19 15:16:01 +00:00
|
|
|
/* A hack to get text extents for tooltips */
|
|
|
|
cairo_surface_t *dummy_surface;
|
|
|
|
void *dummy_surface_data;
|
2013-08-06 18:05:54 +00:00
|
|
|
|
|
|
|
int has_rgb565;
|
2014-10-20 06:25:29 +00:00
|
|
|
int data_device_manager_version;
|
2009-01-27 04:42:46 +00:00
|
|
|
};
|
|
|
|
|
2012-05-15 16:55:34 +00:00
|
|
|
struct window_output {
|
|
|
|
struct output *output;
|
|
|
|
struct wl_list link;
|
|
|
|
};
|
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
struct toysurface {
|
|
|
|
/*
|
2015-11-23 20:13:57 +00:00
|
|
|
* Prepare the surface for drawing. Ensure there is a surface
|
2015-11-20 19:57:43 +00:00
|
|
|
* of the right size available for rendering, and return it.
|
2012-11-19 15:15:58 +00:00
|
|
|
* dx,dy are the x,y of wl_surface.attach.
|
2013-05-22 12:41:28 +00:00
|
|
|
* width,height are the new buffer size.
|
2012-11-30 11:37:27 +00:00
|
|
|
* If flags has SURFACE_HINT_RESIZE set, the user is
|
|
|
|
* doing continuous resizing.
|
2012-11-19 15:15:58 +00:00
|
|
|
* Returns the Cairo surface to draw to.
|
|
|
|
*/
|
|
|
|
cairo_surface_t *(*prepare)(struct toysurface *base, int dx, int dy,
|
2013-05-22 12:41:31 +00:00
|
|
|
int32_t width, int32_t height, uint32_t flags,
|
2013-05-24 11:09:43 +00:00
|
|
|
enum wl_output_transform buffer_transform, int32_t buffer_scale);
|
2012-11-19 15:15:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Post the surface to the server, returning the server allocation
|
|
|
|
* rectangle. The Cairo surface from prepare() must be destroyed
|
|
|
|
* after calling this.
|
|
|
|
*/
|
|
|
|
void (*swap)(struct toysurface *base,
|
2013-05-24 11:09:43 +00:00
|
|
|
enum wl_output_transform buffer_transform, int32_t buffer_scale,
|
2012-11-19 15:15:58 +00:00
|
|
|
struct rectangle *server_allocation);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make the toysurface current with the given EGL context.
|
2015-11-20 19:57:43 +00:00
|
|
|
* Returns 0 on success, and negative on failure.
|
2012-11-19 15:15:58 +00:00
|
|
|
*/
|
|
|
|
int (*acquire)(struct toysurface *base, EGLContext ctx);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Release the toysurface from the EGL context, returning control
|
|
|
|
* to Cairo.
|
|
|
|
*/
|
|
|
|
void (*release)(struct toysurface *base);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Destroy the toysurface, including the Cairo surface, any
|
|
|
|
* backing storage, and the Wayland protocol objects.
|
|
|
|
*/
|
|
|
|
void (*destroy)(struct toysurface *base);
|
|
|
|
};
|
|
|
|
|
2013-02-13 14:17:13 +00:00
|
|
|
struct surface {
|
|
|
|
struct window *window;
|
|
|
|
|
|
|
|
struct wl_surface *surface;
|
2013-04-25 10:57:48 +00:00
|
|
|
struct wl_subsurface *subsurface;
|
|
|
|
int synchronized;
|
|
|
|
int synchronized_default;
|
2013-02-13 14:17:14 +00:00
|
|
|
struct toysurface *toysurface;
|
2013-02-13 14:17:17 +00:00
|
|
|
struct widget *widget;
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
int redraw_needed;
|
|
|
|
struct wl_callback *frame_cb;
|
clients: add subsurfaces demo
Add a demo program with:
- a main surface (green)
- a Cairo-image sub-surface (red)
- a raw GLESv2 widget (triangle)
Sub-surface input region is set empty to avoid problems in toytoolkit.
If Cairo links to libGL, then we will end up with also libGLESv2 linked
to subsurfaces program, and both libs getting really used, which leads
to disaster.
Do not build subsurfaces demo, if Cairo links to libGL and cairo-egl is
usable.
The GL rendering loop is not tied to the toytoolkit or the widget, but
runs directly from its own frame callback. Therefore it runs
independent of the rest of the application. This also relies on one of
two things:
- eglSwapInterval(0) is implemented, and therefore eglSwapBuffers never
blocks indefinitely, or
- toytoolkit has a workaround, that guarantees that eglSwapBuffers will
return soon, when we force a repaint on resize.
Otherwise the demo will deadlock.
The code is separated into three sections:
1. The library component, using only EGL, GLESv2, and libwayland-client
APIs, and not aware of any toolkit details of the parent application.
This runs independently until the parent application tells otherwise.
2. The glue code: a toytoolkit application widget, who has its own
rendering machinery.
3. The application written in toytoolkit.
This patch also adds new toytoolkit interfaces:
- widget_get_wl_surface()
- widget_get_last_time()
- widget_input_region_add()
Toytoolkit applications have not had a possibility to change the input
region. The frame widget (decorations) set the input region on its own
when used, otherwise the default input region of everything has been
used. If a window does not have a frame widget, it can now use
widget_input_region_add() to set a custom input region.
These are not window methods, because a widget may lie on a different
wl_surface (sub-surface) than the window.
Changes in v3:
- replace set_commit_mode with set_sync and set_desync
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:50 +00:00
|
|
|
uint32_t last_time;
|
2013-02-13 14:17:14 +00:00
|
|
|
|
|
|
|
struct rectangle allocation;
|
|
|
|
struct rectangle server_allocation;
|
2013-02-13 14:17:15 +00:00
|
|
|
|
2013-02-13 14:17:18 +00:00
|
|
|
struct wl_region *input_region;
|
|
|
|
struct wl_region *opaque_region;
|
|
|
|
|
2013-02-13 14:17:15 +00:00
|
|
|
enum window_buffer_type buffer_type;
|
|
|
|
enum wl_output_transform buffer_transform;
|
2013-05-24 11:09:43 +00:00
|
|
|
int32_t buffer_scale;
|
2013-02-13 14:17:20 +00:00
|
|
|
|
|
|
|
cairo_surface_t *cairo_surface;
|
2013-04-25 10:57:48 +00:00
|
|
|
|
|
|
|
struct wl_list link;
|
2013-02-13 14:17:13 +00:00
|
|
|
};
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
struct window {
|
|
|
|
struct display *display;
|
2012-05-15 16:55:34 +00:00
|
|
|
struct wl_list window_output_list;
|
2011-01-25 17:45:37 +00:00
|
|
|
char *title;
|
2013-02-13 14:17:14 +00:00
|
|
|
struct rectangle saved_allocation;
|
2012-07-20 15:32:51 +00:00
|
|
|
struct rectangle min_allocation;
|
2012-01-31 20:30:47 +00:00
|
|
|
struct rectangle pending_allocation;
|
2014-09-13 14:35:45 +00:00
|
|
|
struct rectangle last_geometry;
|
2011-01-21 23:03:15 +00:00
|
|
|
int x, y;
|
2012-03-24 18:42:09 +00:00
|
|
|
int redraw_needed;
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
int redraw_task_scheduled;
|
2011-09-14 21:33:48 +00:00
|
|
|
struct task redraw_task;
|
2012-03-26 17:49:29 +00:00
|
|
|
int resize_needed;
|
2013-12-09 19:58:00 +00:00
|
|
|
int custom;
|
|
|
|
int focused;
|
2012-08-14 02:25:53 +00:00
|
|
|
|
2012-11-19 15:15:59 +00:00
|
|
|
int resizing;
|
2012-04-03 16:00:48 +00:00
|
|
|
|
2013-11-12 00:16:11 +00:00
|
|
|
int fullscreen;
|
|
|
|
int maximized;
|
|
|
|
|
2013-08-06 18:05:54 +00:00
|
|
|
enum preferred_format preferred_format;
|
|
|
|
|
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;
|
2012-07-24 01:56:31 +00:00
|
|
|
window_fullscreen_handler_t fullscreen_handler;
|
2012-11-30 15:34:25 +00:00
|
|
|
window_output_handler_t output_handler;
|
2014-04-11 00:23:49 +00:00
|
|
|
window_state_changed_handler_t state_changed_handler;
|
2011-09-21 01:43:54 +00:00
|
|
|
|
2013-02-13 14:17:13 +00:00
|
|
|
struct surface *main_surface;
|
2013-12-09 19:58:00 +00:00
|
|
|
struct xdg_surface *xdg_surface;
|
|
|
|
struct xdg_popup *xdg_popup;
|
2012-09-17 19:15:57 +00:00
|
|
|
|
2014-04-11 01:37:54 +00:00
|
|
|
struct window *parent;
|
2015-02-13 06:01:55 +00:00
|
|
|
struct window *last_parent;
|
2013-12-09 20:26:25 +00:00
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
struct ivi_surface *ivi_surface;
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame *frame;
|
2012-01-07 02:59:05 +00:00
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
/* struct surface::link, contains also main_surface */
|
|
|
|
struct wl_list subsurface_list;
|
|
|
|
|
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;
|
2013-02-13 14:17:19 +00:00
|
|
|
struct surface *surface;
|
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;
|
2013-08-09 04:20:38 +00:00
|
|
|
widget_touch_down_handler_t touch_down_handler;
|
|
|
|
widget_touch_up_handler_t touch_up_handler;
|
|
|
|
widget_touch_motion_handler_t touch_motion_handler;
|
|
|
|
widget_touch_frame_handler_t touch_frame_handler;
|
|
|
|
widget_touch_cancel_handler_t touch_cancel_handler;
|
2012-08-14 09:02:41 +00:00
|
|
|
widget_axis_handler_t axis_handler;
|
2016-01-18 06:38:22 +00:00
|
|
|
widget_pointer_frame_handler_t pointer_frame_handler;
|
|
|
|
widget_axis_source_handler_t axis_source_handler;
|
|
|
|
widget_axis_stop_handler_t axis_stop_handler;
|
|
|
|
widget_axis_discrete_handler_t axis_discrete_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;
|
2012-11-30 19:54:35 +00:00
|
|
|
int default_cursor;
|
2013-12-19 16:17:12 +00:00
|
|
|
/* If this is set to false then no cairo surface will be
|
|
|
|
* created before redrawing the surface. This is useful if the
|
|
|
|
* redraw handler is going to do completely custom rendering
|
|
|
|
* such as using EGL directly */
|
|
|
|
int use_cairo;
|
2011-09-21 01:43:54 +00:00
|
|
|
};
|
|
|
|
|
2013-08-09 04:20:38 +00:00
|
|
|
struct touch_point {
|
|
|
|
int32_t id;
|
2014-01-07 20:57:59 +00:00
|
|
|
float x, y;
|
2013-08-09 04:20:38 +00:00
|
|
|
struct widget *widget;
|
|
|
|
struct wl_list link;
|
|
|
|
};
|
|
|
|
|
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;
|
2013-08-09 04:20:38 +00:00
|
|
|
struct wl_touch *touch;
|
|
|
|
struct wl_list touch_point_list;
|
2010-07-20 21:06:19 +00:00
|
|
|
struct window *pointer_focus;
|
|
|
|
struct window *keyboard_focus;
|
2013-08-09 04:20:38 +00:00
|
|
|
struct window *touch_focus;
|
2012-05-03 09:29:46 +00:00
|
|
|
int current_cursor;
|
2012-06-15 14:27:36 +00:00
|
|
|
uint32_t cursor_anim_start;
|
|
|
|
struct wl_callback *cursor_frame_cb;
|
2015-04-22 22:23:35 +00:00
|
|
|
uint32_t cursor_timer_start;
|
|
|
|
uint32_t cursor_anim_current;
|
|
|
|
int cursor_delay_fd;
|
|
|
|
bool cursor_timer_running;
|
|
|
|
struct task cursor_task;
|
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-06-22 14:52:58 +00:00
|
|
|
uint32_t cursor_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;
|
2013-11-25 10:42:51 +00:00
|
|
|
uint32_t touch_grab;
|
|
|
|
int32_t touch_grab_id;
|
|
|
|
float drag_x, drag_y;
|
|
|
|
struct window *drag_focus;
|
|
|
|
uint32_t drag_enter_serial;
|
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;
|
2012-06-20 18:52:12 +00:00
|
|
|
|
2014-08-12 12:58:27 +00:00
|
|
|
int32_t repeat_rate_sec;
|
|
|
|
int32_t repeat_rate_nsec;
|
|
|
|
int32_t repeat_delay_sec;
|
|
|
|
int32_t repeat_delay_nsec;
|
|
|
|
|
2012-06-20 18:52:12 +00:00
|
|
|
struct task repeat_task;
|
|
|
|
int repeat_timer_fd;
|
|
|
|
uint32_t repeat_sym;
|
|
|
|
uint32_t repeat_key;
|
|
|
|
uint32_t repeat_time;
|
2015-10-14 14:39:59 +00:00
|
|
|
int seat_version;
|
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;
|
2013-10-23 05:58:35 +00:00
|
|
|
uint32_t server_output_id;
|
2011-11-26 22:27:37 +00:00
|
|
|
struct rectangle allocation;
|
|
|
|
struct wl_list link;
|
2012-09-29 08:03:11 +00:00
|
|
|
int transform;
|
2013-05-22 12:41:27 +00:00
|
|
|
int scale;
|
2014-04-03 00:53:50 +00:00
|
|
|
char *make;
|
|
|
|
char *model;
|
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
|
|
|
};
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame {
|
2012-01-11 03:41:05 +00:00
|
|
|
struct widget *widget;
|
|
|
|
struct widget *child;
|
2013-10-14 00:08:40 +00:00
|
|
|
struct frame *frame;
|
2014-06-12 03:06:25 +00:00
|
|
|
|
|
|
|
uint32_t last_time;
|
|
|
|
uint32_t did_double, double_click;
|
2014-06-12 03:06:26 +00:00
|
|
|
int32_t last_id, double_id;
|
2012-01-11 03:41:05 +00:00
|
|
|
};
|
|
|
|
|
2012-01-07 02:59:05 +00:00
|
|
|
struct menu {
|
2014-03-13 16:06:00 +00:00
|
|
|
void *user_data;
|
2012-01-07 02:59:05 +00:00
|
|
|
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;
|
2013-10-24 04:49:30 +00:00
|
|
|
struct frame *frame;
|
2012-01-07 02:59:05 +00:00
|
|
|
const char **entries;
|
|
|
|
uint32_t time;
|
|
|
|
int current;
|
|
|
|
int count;
|
2012-10-30 17:45:22 +00:00
|
|
|
int release_count;
|
2012-01-07 02:59:05 +00:00
|
|
|
menu_func_t func;
|
|
|
|
};
|
|
|
|
|
2012-05-23 19:06:27 +00:00
|
|
|
struct tooltip {
|
|
|
|
struct widget *parent;
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2012-11-19 13:32:51 +00:00
|
|
|
static const cairo_user_data_key_t shm_surface_data_key;
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2013-05-22 07:20:05 +00:00
|
|
|
/* #define DEBUG */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-04-25 10:57:53 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
debug_print(void *proxy, int line, const char *func, const char *fmt, ...)
|
|
|
|
__attribute__ ((format (printf, 4, 5)));
|
|
|
|
|
|
|
|
static void
|
|
|
|
debug_print(void *proxy, int line, const char *func, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
fprintf(stderr, "%8ld.%03ld ",
|
|
|
|
(long)tv.tv_sec & 0xffff, (long)tv.tv_usec / 1000);
|
|
|
|
|
|
|
|
if (proxy)
|
|
|
|
fprintf(stderr, "%s@%d ",
|
|
|
|
wl_proxy_get_class(proxy), wl_proxy_get_id(proxy));
|
|
|
|
|
|
|
|
/*fprintf(stderr, __FILE__ ":%d:%s ", line, func);*/
|
|
|
|
fprintf(stderr, "%s ", func);
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
vfprintf(stderr, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DBG(fmt, ...) \
|
|
|
|
debug_print(NULL, __LINE__, __func__, fmt, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define DBG_OBJ(obj, fmt, ...) \
|
|
|
|
debug_print(obj, __LINE__, __func__, fmt, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define DBG(...) do {} while (0)
|
|
|
|
#define DBG_OBJ(...) do {} while (0)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-05-22 12:41:31 +00:00
|
|
|
static void
|
2013-05-24 11:09:43 +00:00
|
|
|
surface_to_buffer_size (enum wl_output_transform buffer_transform, int32_t buffer_scale, int32_t *width, int32_t *height)
|
2013-05-22 12:41:31 +00:00
|
|
|
{
|
|
|
|
int32_t tmp;
|
|
|
|
|
|
|
|
switch (buffer_transform) {
|
|
|
|
case WL_OUTPUT_TRANSFORM_90:
|
|
|
|
case WL_OUTPUT_TRANSFORM_270:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
|
|
|
tmp = *width;
|
|
|
|
*width = *height;
|
|
|
|
*height = tmp;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*width *= buffer_scale;
|
|
|
|
*height *= buffer_scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-05-24 11:09:43 +00:00
|
|
|
buffer_to_surface_size (enum wl_output_transform buffer_transform, int32_t buffer_scale, int32_t *width, int32_t *height)
|
2013-05-22 12:41:31 +00:00
|
|
|
{
|
|
|
|
int32_t tmp;
|
|
|
|
|
|
|
|
switch (buffer_transform) {
|
|
|
|
case WL_OUTPUT_TRANSFORM_90:
|
|
|
|
case WL_OUTPUT_TRANSFORM_270:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
|
|
|
tmp = *width;
|
|
|
|
*width = *height;
|
|
|
|
*height = tmp;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*width /= buffer_scale;
|
|
|
|
*height /= buffer_scale;
|
|
|
|
}
|
|
|
|
|
2011-01-14 22:41:33 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
struct egl_window_surface {
|
|
|
|
struct toysurface base;
|
|
|
|
cairo_surface_t *cairo_surface;
|
2011-02-10 11:04:30 +00:00
|
|
|
struct display *display;
|
|
|
|
struct wl_surface *surface;
|
2012-11-19 15:15:58 +00:00
|
|
|
struct wl_egl_window *egl_window;
|
|
|
|
EGLSurface egl_surface;
|
2011-02-10 11:04:30 +00:00
|
|
|
};
|
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
static struct egl_window_surface *
|
|
|
|
to_egl_window_surface(struct toysurface *base)
|
|
|
|
{
|
|
|
|
return container_of(base, struct egl_window_surface, base);
|
|
|
|
}
|
|
|
|
|
|
|
|
static cairo_surface_t *
|
|
|
|
egl_window_surface_prepare(struct toysurface *base, int dx, int dy,
|
2013-05-22 12:41:31 +00:00
|
|
|
int32_t width, int32_t height, uint32_t flags,
|
2013-05-24 11:09:43 +00:00
|
|
|
enum wl_output_transform buffer_transform, int32_t buffer_scale)
|
2012-11-19 15:15:58 +00:00
|
|
|
{
|
|
|
|
struct egl_window_surface *surface = to_egl_window_surface(base);
|
|
|
|
|
2013-05-22 12:41:31 +00:00
|
|
|
surface_to_buffer_size (buffer_transform, buffer_scale, &width, &height);
|
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
wl_egl_window_resize(surface->egl_window, width, height, dx, dy);
|
|
|
|
cairo_gl_surface_set_size(surface->cairo_surface, width, height);
|
|
|
|
|
|
|
|
return cairo_surface_reference(surface->cairo_surface);
|
|
|
|
}
|
|
|
|
|
2011-02-10 11:04:30 +00:00
|
|
|
static void
|
2012-11-19 15:15:58 +00:00
|
|
|
egl_window_surface_swap(struct toysurface *base,
|
2013-05-24 11:09:43 +00:00
|
|
|
enum wl_output_transform buffer_transform, int32_t buffer_scale,
|
2012-11-19 15:15:58 +00:00
|
|
|
struct rectangle *server_allocation)
|
|
|
|
{
|
|
|
|
struct egl_window_surface *surface = to_egl_window_surface(base);
|
|
|
|
|
|
|
|
cairo_gl_surface_swapbuffers(surface->cairo_surface);
|
|
|
|
wl_egl_window_get_attached_size(surface->egl_window,
|
|
|
|
&server_allocation->width,
|
|
|
|
&server_allocation->height);
|
2013-05-22 12:41:31 +00:00
|
|
|
|
|
|
|
buffer_to_surface_size (buffer_transform, buffer_scale,
|
|
|
|
&server_allocation->width,
|
|
|
|
&server_allocation->height);
|
2012-11-19 15:15:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
egl_window_surface_acquire(struct toysurface *base, EGLContext ctx)
|
2011-02-10 11:04:30 +00:00
|
|
|
{
|
2012-11-19 15:15:58 +00:00
|
|
|
struct egl_window_surface *surface = to_egl_window_surface(base);
|
|
|
|
cairo_device_t *device;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
device = cairo_surface_get_device(surface->cairo_surface);
|
|
|
|
if (!device)
|
|
|
|
return -1;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
if (!ctx) {
|
|
|
|
if (device == surface->display->argb_device)
|
|
|
|
ctx = surface->display->argb_ctx;
|
|
|
|
else
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_device_flush(device);
|
|
|
|
cairo_device_acquire(device);
|
|
|
|
if (!eglMakeCurrent(surface->display->dpy, surface->egl_surface,
|
|
|
|
surface->egl_surface, ctx))
|
|
|
|
fprintf(stderr, "failed to make surface current\n");
|
|
|
|
|
|
|
|
return 0;
|
2011-02-10 11:04:30 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
static void
|
|
|
|
egl_window_surface_release(struct toysurface *base)
|
2011-02-10 11:04:30 +00:00
|
|
|
{
|
2012-11-19 15:15:58 +00:00
|
|
|
struct egl_window_surface *surface = to_egl_window_surface(base);
|
2011-09-27 19:57:31 +00:00
|
|
|
cairo_device_t *device;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
device = cairo_surface_get_device(surface->cairo_surface);
|
|
|
|
if (!device)
|
|
|
|
return;
|
|
|
|
|
2014-08-25 18:56:43 +00:00
|
|
|
if (!eglMakeCurrent(surface->display->dpy,
|
|
|
|
EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT))
|
2012-11-19 15:15:58 +00:00
|
|
|
fprintf(stderr, "failed to make context current\n");
|
|
|
|
|
|
|
|
cairo_device_release(device);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
egl_window_surface_destroy(struct toysurface *base)
|
|
|
|
{
|
|
|
|
struct egl_window_surface *surface = to_egl_window_surface(base);
|
|
|
|
struct display *d = surface->display;
|
|
|
|
|
|
|
|
cairo_surface_destroy(surface->cairo_surface);
|
|
|
|
eglDestroySurface(d->dpy, surface->egl_surface);
|
|
|
|
wl_egl_window_destroy(surface->egl_window);
|
|
|
|
surface->surface = NULL;
|
|
|
|
|
|
|
|
free(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct toysurface *
|
|
|
|
egl_window_surface_create(struct display *display,
|
|
|
|
struct wl_surface *wl_surface,
|
|
|
|
uint32_t flags,
|
|
|
|
struct rectangle *rectangle)
|
|
|
|
{
|
|
|
|
struct egl_window_surface *surface;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-11-19 15:16:00 +00:00
|
|
|
if (display->dpy == EGL_NO_DISPLAY)
|
|
|
|
return NULL;
|
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
surface = calloc(1, sizeof *surface);
|
|
|
|
if (!surface)
|
|
|
|
return NULL;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
surface->base.prepare = egl_window_surface_prepare;
|
|
|
|
surface->base.swap = egl_window_surface_swap;
|
|
|
|
surface->base.acquire = egl_window_surface_acquire;
|
|
|
|
surface->base.release = egl_window_surface_release;
|
|
|
|
surface->base.destroy = egl_window_surface_destroy;
|
2011-08-31 20:21:38 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
surface->display = display;
|
|
|
|
surface->surface = wl_surface;
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
surface->egl_window = wl_egl_window_create(surface->surface,
|
|
|
|
rectangle->width,
|
|
|
|
rectangle->height);
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2015-03-20 14:26:53 +00:00
|
|
|
surface->egl_surface =
|
2015-03-24 12:12:09 +00:00
|
|
|
weston_platform_create_egl_surface(display->dpy,
|
|
|
|
display->argb_config,
|
|
|
|
surface->egl_window, NULL);
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
surface->cairo_surface =
|
|
|
|
cairo_gl_surface_create_for_egl(display->argb_device,
|
|
|
|
surface->egl_surface,
|
|
|
|
rectangle->width,
|
|
|
|
rectangle->height);
|
2011-02-10 11:04:30 +00:00
|
|
|
|
2012-11-19 15:15:58 +00:00
|
|
|
return &surface->base;
|
2011-02-10 11:04:30 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 15:16:00 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
static struct toysurface *
|
|
|
|
egl_window_surface_create(struct display *display,
|
|
|
|
struct wl_surface *wl_surface,
|
|
|
|
uint32_t flags,
|
|
|
|
struct rectangle *rectangle)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-19 13:32:50 +00:00
|
|
|
struct shm_surface_data {
|
|
|
|
struct wl_buffer *buffer;
|
|
|
|
struct shm_pool *pool;
|
|
|
|
};
|
|
|
|
|
2010-10-25 15:40:03 +00:00
|
|
|
struct wl_buffer *
|
|
|
|
display_get_buffer_for_surface(struct display *display,
|
|
|
|
cairo_surface_t *surface)
|
|
|
|
{
|
2012-11-19 13:32:50 +00:00
|
|
|
struct shm_surface_data *data;
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2012-11-19 13:32:51 +00:00
|
|
|
data = cairo_surface_get_user_data(surface, &shm_surface_data_key);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
|
|
|
return data->buffer;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2012-11-19 13:32:50 +00:00
|
|
|
wl_buffer_destroy(data->buffer);
|
2012-05-07 18:34:26 +00:00
|
|
|
if (data->pool)
|
|
|
|
shm_pool_destroy(data->pool);
|
2012-06-19 10:45:55 +00:00
|
|
|
|
|
|
|
free(data);
|
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;
|
2013-08-06 18:05:54 +00:00
|
|
|
cairo_format_t cairo_format;
|
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;
|
|
|
|
|
2013-08-06 18:05:54 +00:00
|
|
|
if (flags & SURFACE_HINT_RGB565 && display->has_rgb565)
|
|
|
|
cairo_format = CAIRO_FORMAT_RGB16_565;
|
|
|
|
else
|
|
|
|
cairo_format = CAIRO_FORMAT_ARGB32;
|
|
|
|
|
|
|
|
stride = cairo_format_stride_for_width (cairo_format, 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,
|
2013-08-06 18:05:54 +00:00
|
|
|
cairo_format,
|
2010-10-25 15:40:03 +00:00
|
|
|
rectangle->width,
|
|
|
|
rectangle->height,
|
|
|
|
stride);
|
|
|
|
|
2012-11-19 13:32:51 +00:00
|
|
|
cairo_surface_set_user_data(surface, &shm_surface_data_key,
|
|
|
|
data, shm_surface_data_destroy);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2013-08-06 18:05:54 +00:00
|
|
|
if (flags & SURFACE_HINT_RGB565 && display->has_rgb565)
|
|
|
|
format = WL_SHM_FORMAT_RGB565;
|
|
|
|
else {
|
|
|
|
if (flags & SURFACE_OPAQUE)
|
|
|
|
format = WL_SHM_FORMAT_XRGB8888;
|
|
|
|
else
|
|
|
|
format = WL_SHM_FORMAT_ARGB8888;
|
|
|
|
}
|
2011-05-13 17:45:17 +00:00
|
|
|
|
2012-11-19 13:32:50 +00:00
|
|
|
data->buffer = wl_shm_pool_create_buffer(pool->pool, offset,
|
|
|
|
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,
|
2012-11-19 15:15:59 +00:00
|
|
|
struct shm_pool *alternate_pool,
|
|
|
|
struct shm_surface_data **data_ret)
|
2012-05-07 18:34:26 +00:00
|
|
|
{
|
|
|
|
struct shm_surface_data *data;
|
|
|
|
struct shm_pool *pool;
|
|
|
|
cairo_surface_t *surface;
|
|
|
|
|
2012-11-19 15:15:59 +00:00
|
|
|
if (alternate_pool) {
|
|
|
|
shm_pool_reset(alternate_pool);
|
2012-05-07 18:34:26 +00:00
|
|
|
surface = display_create_shm_surface_from_pool(display,
|
|
|
|
rectangle,
|
|
|
|
flags,
|
2012-11-19 15:15:59 +00:00
|
|
|
alternate_pool);
|
|
|
|
if (surface) {
|
|
|
|
data = cairo_surface_get_user_data(surface,
|
|
|
|
&shm_surface_data_key);
|
|
|
|
goto out;
|
|
|
|
}
|
2012-05-07 18:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
2012-11-19 13:32:51 +00:00
|
|
|
data = cairo_surface_get_user_data(surface, &shm_surface_data_key);
|
2012-05-07 18:34:26 +00:00
|
|
|
data->pool = pool;
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2012-11-19 15:15:59 +00:00
|
|
|
out:
|
|
|
|
if (data_ret)
|
|
|
|
*data_ret = data;
|
|
|
|
|
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;
|
2012-11-19 15:15:57 +00:00
|
|
|
|
|
|
|
assert(flags & SURFACE_SHM);
|
2012-11-19 15:15:59 +00:00
|
|
|
return display_create_shm_surface(display, rectangle, flags,
|
|
|
|
NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2012-11-19 15:16:02 +00:00
|
|
|
struct shm_surface_leaf {
|
|
|
|
cairo_surface_t *cairo_surface;
|
|
|
|
/* 'data' is automatically destroyed, when 'cairo_surface' is */
|
|
|
|
struct shm_surface_data *data;
|
|
|
|
|
|
|
|
struct shm_pool *resize_pool;
|
|
|
|
int busy;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
shm_surface_leaf_release(struct shm_surface_leaf *leaf)
|
|
|
|
{
|
|
|
|
if (leaf->cairo_surface)
|
|
|
|
cairo_surface_destroy(leaf->cairo_surface);
|
|
|
|
/* leaf->data already destroyed via cairo private */
|
|
|
|
|
|
|
|
if (leaf->resize_pool)
|
|
|
|
shm_pool_destroy(leaf->resize_pool);
|
2013-02-13 14:17:12 +00:00
|
|
|
|
|
|
|
memset(leaf, 0, sizeof *leaf);
|
2012-11-19 15:16:02 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 10:57:47 +00:00
|
|
|
#define MAX_LEAVES 3
|
|
|
|
|
2012-11-19 15:15:59 +00:00
|
|
|
struct shm_surface {
|
|
|
|
struct toysurface base;
|
|
|
|
struct display *display;
|
|
|
|
struct wl_surface *surface;
|
|
|
|
uint32_t flags;
|
|
|
|
int dx, dy;
|
|
|
|
|
2013-04-25 10:57:47 +00:00
|
|
|
struct shm_surface_leaf leaf[MAX_LEAVES];
|
2012-11-19 15:16:02 +00:00
|
|
|
struct shm_surface_leaf *current;
|
2012-11-19 15:15:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct shm_surface *
|
|
|
|
to_shm_surface(struct toysurface *base)
|
|
|
|
{
|
|
|
|
return container_of(base, struct shm_surface, base);
|
|
|
|
}
|
|
|
|
|
2013-05-22 07:20:05 +00:00
|
|
|
static void
|
|
|
|
shm_surface_buffer_state_debug(struct shm_surface *surface, const char *msg)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
struct shm_surface_leaf *leaf;
|
|
|
|
char bufs[MAX_LEAVES + 1];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_LEAVES; i++) {
|
|
|
|
leaf = &surface->leaf[i];
|
|
|
|
|
|
|
|
if (leaf->busy)
|
|
|
|
bufs[i] = 'b';
|
|
|
|
else if (leaf->cairo_surface)
|
|
|
|
bufs[i] = 'a';
|
|
|
|
else
|
|
|
|
bufs[i] = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
bufs[MAX_LEAVES] = '\0';
|
|
|
|
DBG_OBJ(surface->surface, "%s, leaves [%s]\n", msg, bufs);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-19 15:16:02 +00:00
|
|
|
static void
|
|
|
|
shm_surface_buffer_release(void *data, struct wl_buffer *buffer)
|
|
|
|
{
|
2013-02-13 14:17:12 +00:00
|
|
|
struct shm_surface *surface = data;
|
2013-04-25 10:57:47 +00:00
|
|
|
struct shm_surface_leaf *leaf;
|
|
|
|
int i;
|
|
|
|
int free_found;
|
2013-05-22 07:20:05 +00:00
|
|
|
|
|
|
|
shm_surface_buffer_state_debug(surface, "buffer_release before");
|
2013-04-25 10:57:47 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MAX_LEAVES; i++) {
|
|
|
|
leaf = &surface->leaf[i];
|
|
|
|
if (leaf->data && leaf->data->buffer == buffer) {
|
|
|
|
leaf->busy = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(i < MAX_LEAVES && "unknown buffer released");
|
2012-11-19 15:16:02 +00:00
|
|
|
|
2013-04-25 10:57:47 +00:00
|
|
|
/* Leave one free leaf with storage, release others */
|
|
|
|
free_found = 0;
|
|
|
|
for (i = 0; i < MAX_LEAVES; i++) {
|
|
|
|
leaf = &surface->leaf[i];
|
|
|
|
|
|
|
|
if (!leaf->cairo_surface || leaf->busy)
|
|
|
|
continue;
|
2012-12-04 14:01:16 +00:00
|
|
|
|
2013-04-25 10:57:47 +00:00
|
|
|
if (!free_found)
|
|
|
|
free_found = 1;
|
2013-05-22 07:20:05 +00:00
|
|
|
else
|
2013-04-25 10:57:47 +00:00
|
|
|
shm_surface_leaf_release(leaf);
|
|
|
|
}
|
2013-04-25 10:57:53 +00:00
|
|
|
|
2013-05-22 07:20:05 +00:00
|
|
|
shm_surface_buffer_state_debug(surface, "buffer_release after");
|
2012-11-19 15:16:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_buffer_listener shm_surface_buffer_listener = {
|
|
|
|
shm_surface_buffer_release
|
|
|
|
};
|
|
|
|
|
2012-11-19 15:15:59 +00:00
|
|
|
static cairo_surface_t *
|
|
|
|
shm_surface_prepare(struct toysurface *base, int dx, int dy,
|
2013-05-22 12:41:31 +00:00
|
|
|
int32_t width, int32_t height, uint32_t flags,
|
2013-05-24 11:09:43 +00:00
|
|
|
enum wl_output_transform buffer_transform, int32_t buffer_scale)
|
2012-11-19 15:15:59 +00:00
|
|
|
{
|
2012-11-30 11:37:27 +00:00
|
|
|
int resize_hint = !!(flags & SURFACE_HINT_RESIZE);
|
2012-11-19 15:15:59 +00:00
|
|
|
struct shm_surface *surface = to_shm_surface(base);
|
2013-05-22 12:41:31 +00:00
|
|
|
struct rectangle rect = { 0};
|
2013-04-25 10:57:47 +00:00
|
|
|
struct shm_surface_leaf *leaf = NULL;
|
|
|
|
int i;
|
2012-11-19 15:15:59 +00:00
|
|
|
|
|
|
|
surface->dx = dx;
|
|
|
|
surface->dy = dy;
|
|
|
|
|
2015-03-19 01:42:00 +00:00
|
|
|
/* pick a free buffer, preferably one that already has storage */
|
2013-04-25 10:57:47 +00:00
|
|
|
for (i = 0; i < MAX_LEAVES; i++) {
|
|
|
|
if (surface->leaf[i].busy)
|
|
|
|
continue;
|
2012-12-04 14:01:16 +00:00
|
|
|
|
2013-04-25 10:57:47 +00:00
|
|
|
if (!leaf || surface->leaf[i].cairo_surface)
|
|
|
|
leaf = &surface->leaf[i];
|
|
|
|
}
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(surface->surface, "pick leaf %d\n",
|
|
|
|
(int)(leaf - &surface->leaf[0]));
|
|
|
|
|
2013-04-25 10:57:47 +00:00
|
|
|
if (!leaf) {
|
|
|
|
fprintf(stderr, "%s: all buffers are held by the server.\n",
|
2012-11-19 15:16:02 +00:00
|
|
|
__func__);
|
2013-04-25 10:57:53 +00:00
|
|
|
exit(1);
|
2012-11-19 15:16:02 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!resize_hint && leaf->resize_pool) {
|
|
|
|
cairo_surface_destroy(leaf->cairo_surface);
|
|
|
|
leaf->cairo_surface = NULL;
|
|
|
|
shm_pool_destroy(leaf->resize_pool);
|
|
|
|
leaf->resize_pool = NULL;
|
2012-11-19 15:15:59 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:41:31 +00:00
|
|
|
surface_to_buffer_size (buffer_transform, buffer_scale, &width, &height);
|
|
|
|
|
2012-11-19 15:16:02 +00:00
|
|
|
if (leaf->cairo_surface &&
|
|
|
|
cairo_image_surface_get_width(leaf->cairo_surface) == width &&
|
|
|
|
cairo_image_surface_get_height(leaf->cairo_surface) == height)
|
2012-11-19 15:15:59 +00:00
|
|
|
goto out;
|
|
|
|
|
2012-11-19 15:16:02 +00:00
|
|
|
if (leaf->cairo_surface)
|
|
|
|
cairo_surface_destroy(leaf->cairo_surface);
|
2012-11-19 15:15:59 +00:00
|
|
|
|
2013-05-22 15:03:11 +00:00
|
|
|
#ifdef USE_RESIZE_POOL
|
2012-11-19 15:16:02 +00:00
|
|
|
if (resize_hint && !leaf->resize_pool) {
|
2012-11-19 15:15:59 +00:00
|
|
|
/* Create a big pool to allocate from, while continuously
|
|
|
|
* resizing. Mmapping a new pool in the server
|
|
|
|
* is relatively expensive, so reusing a pool performs
|
|
|
|
* better, but may temporarily reserve unneeded memory.
|
|
|
|
*/
|
|
|
|
/* We should probably base this number on the output size. */
|
2012-11-19 15:16:02 +00:00
|
|
|
leaf->resize_pool = shm_pool_create(surface->display,
|
|
|
|
6 * 1024 * 1024);
|
2012-11-19 15:15:59 +00:00
|
|
|
}
|
2013-05-22 15:03:11 +00:00
|
|
|
#endif
|
2012-11-19 15:15:59 +00:00
|
|
|
|
2013-05-22 12:41:31 +00:00
|
|
|
rect.width = width;
|
|
|
|
rect.height = height;
|
|
|
|
|
2012-11-19 15:16:02 +00:00
|
|
|
leaf->cairo_surface =
|
2012-11-19 15:15:59 +00:00
|
|
|
display_create_shm_surface(surface->display, &rect,
|
|
|
|
surface->flags,
|
2012-11-19 15:16:02 +00:00
|
|
|
leaf->resize_pool,
|
|
|
|
&leaf->data);
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
if (!leaf->cairo_surface)
|
|
|
|
return NULL;
|
|
|
|
|
2012-11-19 15:16:02 +00:00
|
|
|
wl_buffer_add_listener(leaf->data->buffer,
|
2013-02-13 14:17:12 +00:00
|
|
|
&shm_surface_buffer_listener, surface);
|
2012-11-19 15:15:59 +00:00
|
|
|
|
|
|
|
out:
|
2012-11-19 15:16:02 +00:00
|
|
|
surface->current = leaf;
|
|
|
|
|
|
|
|
return cairo_surface_reference(leaf->cairo_surface);
|
2012-11-19 15:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shm_surface_swap(struct toysurface *base,
|
2013-05-24 11:09:43 +00:00
|
|
|
enum wl_output_transform buffer_transform, int32_t buffer_scale,
|
2012-11-19 15:15:59 +00:00
|
|
|
struct rectangle *server_allocation)
|
|
|
|
{
|
|
|
|
struct shm_surface *surface = to_shm_surface(base);
|
2012-11-19 15:16:02 +00:00
|
|
|
struct shm_surface_leaf *leaf = surface->current;
|
2012-11-19 15:15:59 +00:00
|
|
|
|
|
|
|
server_allocation->width =
|
2012-11-19 15:16:02 +00:00
|
|
|
cairo_image_surface_get_width(leaf->cairo_surface);
|
2012-11-19 15:15:59 +00:00
|
|
|
server_allocation->height =
|
2012-11-19 15:16:02 +00:00
|
|
|
cairo_image_surface_get_height(leaf->cairo_surface);
|
2012-11-19 15:15:59 +00:00
|
|
|
|
2013-05-22 12:41:31 +00:00
|
|
|
buffer_to_surface_size (buffer_transform, buffer_scale,
|
|
|
|
&server_allocation->width,
|
|
|
|
&server_allocation->height);
|
|
|
|
|
2012-11-19 15:16:02 +00:00
|
|
|
wl_surface_attach(surface->surface, leaf->data->buffer,
|
2012-11-19 15:15:59 +00:00
|
|
|
surface->dx, surface->dy);
|
|
|
|
wl_surface_damage(surface->surface, 0, 0,
|
|
|
|
server_allocation->width, server_allocation->height);
|
|
|
|
wl_surface_commit(surface->surface);
|
2012-11-19 15:16:02 +00:00
|
|
|
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(surface->surface, "leaf %d busy\n",
|
|
|
|
(int)(leaf - &surface->leaf[0]));
|
|
|
|
|
2012-11-19 15:16:02 +00:00
|
|
|
leaf->busy = 1;
|
|
|
|
surface->current = NULL;
|
2012-11-19 15:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
shm_surface_acquire(struct toysurface *base, EGLContext ctx)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shm_surface_release(struct toysurface *base)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
shm_surface_destroy(struct toysurface *base)
|
|
|
|
{
|
|
|
|
struct shm_surface *surface = to_shm_surface(base);
|
2013-04-25 10:57:47 +00:00
|
|
|
int i;
|
2012-11-19 15:15:59 +00:00
|
|
|
|
2013-04-25 10:57:47 +00:00
|
|
|
for (i = 0; i < MAX_LEAVES; i++)
|
|
|
|
shm_surface_leaf_release(&surface->leaf[i]);
|
2012-11-19 15:15:59 +00:00
|
|
|
|
|
|
|
free(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct toysurface *
|
|
|
|
shm_surface_create(struct display *display, struct wl_surface *wl_surface,
|
|
|
|
uint32_t flags, struct rectangle *rectangle)
|
|
|
|
{
|
|
|
|
struct shm_surface *surface;
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(wl_surface, "\n");
|
2012-11-19 15:15:59 +00:00
|
|
|
|
2015-06-19 23:12:22 +00:00
|
|
|
surface = xzalloc(sizeof *surface);
|
2012-11-19 15:15:59 +00:00
|
|
|
surface->base.prepare = shm_surface_prepare;
|
|
|
|
surface->base.swap = shm_surface_swap;
|
|
|
|
surface->base.acquire = shm_surface_acquire;
|
|
|
|
surface->base.release = shm_surface_release;
|
|
|
|
surface->base.destroy = shm_surface_destroy;
|
|
|
|
|
|
|
|
surface->display = display;
|
|
|
|
surface->surface = wl_surface;
|
|
|
|
surface->flags = flags;
|
|
|
|
|
|
|
|
return &surface->base;
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-21 18:36:16 +00:00
|
|
|
/*
|
|
|
|
* The following correspondences between file names and cursors was copied
|
|
|
|
* from: https://bugs.kde.org/attachment.cgi?id=67313
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char *bottom_left_corners[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"bottom_left_corner",
|
2013-05-14 06:51:11 +00:00
|
|
|
"sw-resize",
|
|
|
|
"size_bdiag"
|
2012-08-21 18:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *bottom_right_corners[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"bottom_right_corner",
|
2013-05-14 06:51:11 +00:00
|
|
|
"se-resize",
|
|
|
|
"size_fdiag"
|
2012-08-21 18:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *bottom_sides[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"bottom_side",
|
2013-05-14 06:51:11 +00:00
|
|
|
"s-resize",
|
|
|
|
"size_ver"
|
2012-08-21 18:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *grabbings[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"grabbing",
|
2012-08-21 18:36:16 +00:00
|
|
|
"closedhand",
|
|
|
|
"208530c400c041818281048008011002"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *left_ptrs[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"left_ptr",
|
2012-08-21 18:36:16 +00:00
|
|
|
"default",
|
|
|
|
"top_left_arrow",
|
|
|
|
"left-arrow"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *left_sides[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"left_side",
|
2013-05-14 06:51:11 +00:00
|
|
|
"w-resize",
|
|
|
|
"size_hor"
|
2012-08-21 18:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *right_sides[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"right_side",
|
2013-05-14 06:51:11 +00:00
|
|
|
"e-resize",
|
|
|
|
"size_hor"
|
2012-08-21 18:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *top_left_corners[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"top_left_corner",
|
2013-05-14 06:51:11 +00:00
|
|
|
"nw-resize",
|
|
|
|
"size_fdiag"
|
2012-08-21 18:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *top_right_corners[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"top_right_corner",
|
2013-05-14 06:51:11 +00:00
|
|
|
"ne-resize",
|
|
|
|
"size_bdiag"
|
2012-08-21 18:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *top_sides[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"top_side",
|
2013-05-14 06:51:11 +00:00
|
|
|
"n-resize",
|
|
|
|
"size_ver"
|
2012-08-21 18:36:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *xterms[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"xterm",
|
2012-08-21 18:36:16 +00:00
|
|
|
"ibeam",
|
|
|
|
"text"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *hand1s[] = {
|
2012-05-25 06:30:02 +00:00
|
|
|
"hand1",
|
2012-08-21 18:36:16 +00:00
|
|
|
"pointer",
|
|
|
|
"pointing_hand",
|
|
|
|
"e29285e634086352946a0e7090d73106"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *watches[] = {
|
2012-06-04 20:10:40 +00:00
|
|
|
"watch",
|
2012-08-21 18:36:16 +00:00
|
|
|
"wait",
|
|
|
|
"0426c94ea35c87780ff01dc239897213"
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cursor_alternatives {
|
|
|
|
const char **names;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct cursor_alternatives cursors[] = {
|
|
|
|
{bottom_left_corners, ARRAY_LENGTH(bottom_left_corners)},
|
|
|
|
{bottom_right_corners, ARRAY_LENGTH(bottom_right_corners)},
|
|
|
|
{bottom_sides, ARRAY_LENGTH(bottom_sides)},
|
|
|
|
{grabbings, ARRAY_LENGTH(grabbings)},
|
|
|
|
{left_ptrs, ARRAY_LENGTH(left_ptrs)},
|
|
|
|
{left_sides, ARRAY_LENGTH(left_sides)},
|
|
|
|
{right_sides, ARRAY_LENGTH(right_sides)},
|
|
|
|
{top_left_corners, ARRAY_LENGTH(top_left_corners)},
|
|
|
|
{top_right_corners, ARRAY_LENGTH(top_right_corners)},
|
|
|
|
{top_sides, ARRAY_LENGTH(top_sides)},
|
|
|
|
{xterms, ARRAY_LENGTH(xterms)},
|
|
|
|
{hand1s, ARRAY_LENGTH(hand1s)},
|
|
|
|
{watches, ARRAY_LENGTH(watches)},
|
2012-05-25 06:30:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
create_cursors(struct display *display)
|
|
|
|
{
|
2015-03-24 13:56:19 +00:00
|
|
|
const char *config_file;
|
2013-09-22 05:26:10 +00:00
|
|
|
struct weston_config *config;
|
|
|
|
struct weston_config_section *s;
|
2013-09-22 06:02:31 +00:00
|
|
|
int size;
|
2012-08-11 14:12:09 +00:00
|
|
|
char *theme = NULL;
|
2012-08-21 18:36:16 +00:00
|
|
|
unsigned int i, j;
|
|
|
|
struct wl_cursor *cursor;
|
2012-08-11 14:12:09 +00:00
|
|
|
|
2015-03-24 13:56:19 +00:00
|
|
|
config_file = weston_config_get_name_from_env();
|
|
|
|
config = weston_config_parse(config_file);
|
2013-09-22 05:26:10 +00:00
|
|
|
s = weston_config_get_section(config, "shell", NULL, NULL);
|
|
|
|
weston_config_section_get_string(s, "cursor-theme", &theme, NULL);
|
|
|
|
weston_config_section_get_int(s, "cursor-size", &size, 32);
|
|
|
|
weston_config_destroy(config);
|
|
|
|
|
2013-03-14 16:23:37 +00:00
|
|
|
display->cursor_theme = wl_cursor_theme_load(theme, size, display->shm);
|
2014-03-18 13:12:50 +00:00
|
|
|
if (!display->cursor_theme) {
|
|
|
|
fprintf(stderr, "could not load theme '%s'\n", theme);
|
|
|
|
return;
|
|
|
|
}
|
2013-10-09 20:02:04 +00:00
|
|
|
free(theme);
|
2012-05-25 06:30:02 +00:00
|
|
|
display->cursors =
|
2013-08-07 22:34:59 +00:00
|
|
|
xmalloc(ARRAY_LENGTH(cursors) * sizeof display->cursors[0]);
|
2012-05-25 06:30:02 +00:00
|
|
|
|
2012-07-31 10:21:09 +00:00
|
|
|
for (i = 0; i < ARRAY_LENGTH(cursors); i++) {
|
2012-08-21 18:36:16 +00:00
|
|
|
cursor = NULL;
|
|
|
|
for (j = 0; !cursor && j < cursors[i].count; ++j)
|
|
|
|
cursor = wl_cursor_theme_get_cursor(
|
|
|
|
display->cursor_theme, cursors[i].names[j]);
|
|
|
|
|
|
|
|
if (!cursor)
|
2012-07-31 10:21:09 +00:00
|
|
|
fprintf(stderr, "could not load cursor '%s'\n",
|
2012-08-21 18:36:16 +00:00
|
|
|
cursors[i].names[0]);
|
|
|
|
|
|
|
|
display->cursors[i] = cursor;
|
2012-07-31 10:21:09 +00:00
|
|
|
}
|
2012-05-25 06:30:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-08-21 18:36:16 +00:00
|
|
|
struct wl_cursor *cursor = display->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
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:14 +00:00
|
|
|
static void
|
2013-02-13 14:17:20 +00:00
|
|
|
surface_flush(struct surface *surface)
|
2013-02-13 14:17:14 +00:00
|
|
|
{
|
2013-02-13 14:17:20 +00:00
|
|
|
if (!surface->cairo_surface)
|
|
|
|
return;
|
|
|
|
|
2013-02-13 14:17:18 +00:00
|
|
|
if (surface->opaque_region) {
|
|
|
|
wl_surface_set_opaque_region(surface->surface,
|
|
|
|
surface->opaque_region);
|
|
|
|
wl_region_destroy(surface->opaque_region);
|
|
|
|
surface->opaque_region = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface->input_region) {
|
|
|
|
wl_surface_set_input_region(surface->surface,
|
|
|
|
surface->input_region);
|
|
|
|
wl_region_destroy(surface->input_region);
|
|
|
|
surface->input_region = NULL;
|
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:14 +00:00
|
|
|
surface->toysurface->swap(surface->toysurface,
|
2013-05-22 12:41:31 +00:00
|
|
|
surface->buffer_transform, surface->buffer_scale,
|
2013-02-13 14:17:14 +00:00
|
|
|
&surface->server_allocation);
|
|
|
|
|
2013-02-13 14:17:20 +00:00
|
|
|
cairo_surface_destroy(surface->cairo_surface);
|
|
|
|
surface->cairo_surface = NULL;
|
2009-12-16 19:43:37 +00:00
|
|
|
}
|
|
|
|
|
2012-08-14 02:25:53 +00:00
|
|
|
int
|
|
|
|
window_has_focus(struct window *window)
|
|
|
|
{
|
2013-12-09 19:58:00 +00:00
|
|
|
return window->focused;
|
2010-01-24 23:10:15 +00:00
|
|
|
}
|
|
|
|
|
2014-02-01 23:17:34 +00:00
|
|
|
static void
|
|
|
|
window_close(struct window *window)
|
|
|
|
{
|
|
|
|
if (window->close_handler)
|
|
|
|
window->close_handler(window->user_data);
|
|
|
|
else
|
|
|
|
display_exit(window->display);
|
|
|
|
}
|
|
|
|
|
2011-10-12 04:36:16 +00:00
|
|
|
struct display *
|
|
|
|
window_get_display(struct window *window)
|
|
|
|
{
|
|
|
|
return window->display;
|
|
|
|
}
|
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
static void
|
|
|
|
handle_ivi_surface_configure(void *data, struct ivi_surface *ivi_surface,
|
|
|
|
int32_t width, int32_t height)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
|
|
|
|
window_schedule_resize(window, width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ivi_surface_listener ivi_surface_listener = {
|
|
|
|
handle_ivi_surface_configure,
|
|
|
|
};
|
|
|
|
|
2013-02-13 14:17:20 +00:00
|
|
|
static void
|
2014-03-10 15:35:48 +00:00
|
|
|
surface_create_surface(struct surface *surface, uint32_t flags)
|
2010-10-26 04:02:20 +00:00
|
|
|
{
|
2013-02-13 14:17:15 +00:00
|
|
|
struct display *display = surface->window->display;
|
2013-02-13 14:17:14 +00:00
|
|
|
struct rectangle allocation = surface->allocation;
|
2012-11-19 15:15:58 +00:00
|
|
|
|
2013-02-13 14:17:15 +00:00
|
|
|
if (!surface->toysurface && display->dpy &&
|
|
|
|
surface->buffer_type == WINDOW_BUFFER_TYPE_EGL_WINDOW) {
|
2013-02-13 14:17:14 +00:00
|
|
|
surface->toysurface =
|
2013-02-13 14:17:15 +00:00
|
|
|
egl_window_surface_create(display,
|
2013-02-13 14:17:14 +00:00
|
|
|
surface->surface,
|
2013-02-13 14:17:13 +00:00
|
|
|
flags,
|
2012-11-30 15:34:24 +00:00
|
|
|
&allocation);
|
2012-11-19 15:16:00 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:14 +00:00
|
|
|
if (!surface->toysurface)
|
2013-02-13 14:17:15 +00:00
|
|
|
surface->toysurface = shm_surface_create(display,
|
2013-02-13 14:17:14 +00:00
|
|
|
surface->surface,
|
|
|
|
flags, &allocation);
|
2010-10-26 04:02:20 +00:00
|
|
|
|
2013-02-13 14:17:20 +00:00
|
|
|
surface->cairo_surface = surface->toysurface->prepare(
|
2014-03-10 15:35:48 +00:00
|
|
|
surface->toysurface, 0, 0,
|
2013-05-22 12:41:31 +00:00
|
|
|
allocation.width, allocation.height, flags,
|
|
|
|
surface->buffer_transform, surface->buffer_scale);
|
2013-02-13 14:17:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-02-13 14:17:23 +00:00
|
|
|
window_create_main_surface(struct window *window)
|
2013-02-13 14:17:15 +00:00
|
|
|
{
|
2013-02-13 14:17:16 +00:00
|
|
|
struct surface *surface = window->main_surface;
|
2013-02-13 14:17:15 +00:00
|
|
|
uint32_t flags = 0;
|
|
|
|
|
2012-11-30 11:37:27 +00:00
|
|
|
if (window->resizing)
|
2013-02-13 14:17:15 +00:00
|
|
|
flags |= SURFACE_HINT_RESIZE;
|
2012-11-30 11:37:27 +00:00
|
|
|
|
2013-08-06 18:05:54 +00:00
|
|
|
if (window->preferred_format == WINDOW_PREFERRED_FORMAT_RGB565)
|
|
|
|
flags |= SURFACE_HINT_RGB565;
|
|
|
|
|
2014-03-10 15:35:48 +00:00
|
|
|
surface_create_surface(surface, flags);
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
2012-11-30 15:34:24 +00:00
|
|
|
int
|
|
|
|
window_get_buffer_transform(struct window *window)
|
|
|
|
{
|
2013-02-13 14:17:15 +00:00
|
|
|
return window->main_surface->buffer_transform;
|
2012-11-30 15:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
window_set_buffer_transform(struct window *window,
|
|
|
|
enum wl_output_transform transform)
|
|
|
|
{
|
2013-02-13 14:17:15 +00:00
|
|
|
window->main_surface->buffer_transform = transform;
|
2013-02-13 14:17:13 +00:00
|
|
|
wl_surface_set_buffer_transform(window->main_surface->surface,
|
|
|
|
transform);
|
2012-11-30 15:34:24 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:41:28 +00:00
|
|
|
void
|
|
|
|
window_set_buffer_scale(struct window *window,
|
2013-05-24 11:09:43 +00:00
|
|
|
int32_t scale)
|
2013-05-22 12:41:28 +00:00
|
|
|
{
|
|
|
|
window->main_surface->buffer_scale = scale;
|
|
|
|
wl_surface_set_buffer_scale(window->main_surface->surface,
|
|
|
|
scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
|
|
|
window_get_buffer_scale(struct window *window)
|
|
|
|
{
|
|
|
|
return window->main_surface->buffer_scale;
|
|
|
|
}
|
|
|
|
|
2013-05-22 12:41:33 +00:00
|
|
|
uint32_t
|
|
|
|
window_get_output_scale(struct window *window)
|
|
|
|
{
|
|
|
|
struct window_output *window_output;
|
|
|
|
struct window_output *window_output_tmp;
|
|
|
|
int scale = 1;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(window_output, window_output_tmp,
|
|
|
|
&window->window_output_list, link) {
|
|
|
|
if (window_output->output->scale > scale)
|
|
|
|
scale = window_output->output->scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
return scale;
|
|
|
|
}
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
static void window_frame_destroy(struct window_frame *frame);
|
2012-01-19 11:33:50 +00:00
|
|
|
|
2013-02-13 14:17:13 +00:00
|
|
|
static void
|
|
|
|
surface_destroy(struct surface *surface)
|
|
|
|
{
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
if (surface->frame_cb)
|
|
|
|
wl_callback_destroy(surface->frame_cb);
|
|
|
|
|
2013-02-13 14:17:18 +00:00
|
|
|
if (surface->input_region)
|
|
|
|
wl_region_destroy(surface->input_region);
|
|
|
|
|
|
|
|
if (surface->opaque_region)
|
|
|
|
wl_region_destroy(surface->opaque_region);
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
if (surface->subsurface)
|
|
|
|
wl_subsurface_destroy(surface->subsurface);
|
|
|
|
|
2013-02-13 14:17:13 +00:00
|
|
|
wl_surface_destroy(surface->surface);
|
2013-02-13 14:17:14 +00:00
|
|
|
|
|
|
|
if (surface->toysurface)
|
|
|
|
surface->toysurface->destroy(surface->toysurface);
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
wl_list_remove(&surface->link);
|
2013-02-13 14:17:13 +00:00
|
|
|
free(surface);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
wl_list_remove(&window->redraw_task.link);
|
2011-11-15 11:34:55 +00:00
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
wl_list_for_each(input, &display->input_list, link) {
|
2013-08-15 16:10:08 +00:00
|
|
|
if (input->touch_focus == window)
|
|
|
|
input->touch_focus = NULL;
|
2011-11-15 11:34:55 +00:00
|
|
|
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-01-19 11:33:50 +00:00
|
|
|
if (window->frame)
|
2013-10-14 00:08:38 +00:00
|
|
|
window_frame_destroy(window->frame);
|
2012-01-19 11:33:50 +00:00
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
if (window->xdg_surface)
|
|
|
|
xdg_surface_destroy(window->xdg_surface);
|
|
|
|
if (window->xdg_popup)
|
|
|
|
xdg_popup_destroy(window->xdg_popup);
|
2013-02-13 14:17:13 +00:00
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
if (window->ivi_surface)
|
|
|
|
ivi_surface_destroy(window->ivi_surface);
|
|
|
|
|
2013-02-13 14:17:13 +00:00
|
|
|
surface_destroy(window->main_surface);
|
|
|
|
|
2011-01-21 23:03:15 +00:00
|
|
|
wl_list_remove(&window->link);
|
2011-12-16 08:09:29 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:17 +00:00
|
|
|
static struct widget *
|
|
|
|
window_find_widget(struct window *window, int32_t x, int32_t y)
|
|
|
|
{
|
2013-04-25 10:57:48 +00:00
|
|
|
struct surface *surface;
|
|
|
|
struct widget *widget;
|
|
|
|
|
|
|
|
wl_list_for_each(surface, &window->subsurface_list, link) {
|
|
|
|
widget = widget_find_widget(surface->widget, x, y);
|
|
|
|
if (widget)
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2013-02-13 14:17:17 +00:00
|
|
|
}
|
|
|
|
|
2012-01-10 18:52:34 +00:00
|
|
|
static struct widget *
|
2013-02-13 14:17:19 +00:00
|
|
|
widget_create(struct window *window, struct surface *surface, 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
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
widget = xzalloc(sizeof *widget);
|
2012-01-08 20:18:19 +00:00
|
|
|
widget->window = window;
|
2013-02-13 14:17:19 +00:00
|
|
|
widget->surface = surface;
|
2012-01-08 20:09:53 +00:00
|
|
|
widget->user_data = data;
|
2013-02-13 14:17:19 +00:00
|
|
|
widget->allocation = surface->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;
|
2012-11-30 19:54:35 +00:00
|
|
|
widget->default_cursor = CURSOR_LEFT_PTR;
|
2013-12-19 16:17:12 +00:00
|
|
|
widget->use_cairo = 1;
|
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)
|
|
|
|
{
|
2013-02-13 14:17:17 +00:00
|
|
|
struct widget *widget;
|
2012-01-10 18:52:34 +00:00
|
|
|
|
2013-02-13 14:17:19 +00:00
|
|
|
widget = widget_create(window, window->main_surface, data);
|
2013-02-13 14:17:17 +00:00
|
|
|
wl_list_init(&widget->link);
|
|
|
|
window->main_surface->widget = widget;
|
|
|
|
|
|
|
|
return widget;
|
2012-01-10 18:52:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-02-13 14:17:19 +00:00
|
|
|
widget = widget_create(parent->window, parent->surface, data);
|
2012-01-10 18:52:34 +00:00
|
|
|
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;
|
2013-04-25 10:57:48 +00:00
|
|
|
struct surface *surface = widget->surface;
|
2012-01-19 11:51:38 +00:00
|
|
|
struct input *input;
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
/* Destroy the sub-surface along with the root widget */
|
|
|
|
if (surface->widget == widget && surface->subsurface)
|
|
|
|
surface_destroy(widget->surface);
|
|
|
|
|
2014-01-10 08:27:35 +00:00
|
|
|
if (widget->tooltip)
|
|
|
|
widget_destroy_tooltip(widget);
|
2012-05-23 19:06:27 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-11-30 19:54:35 +00:00
|
|
|
void
|
|
|
|
widget_set_default_cursor(struct widget *widget, int cursor)
|
|
|
|
{
|
|
|
|
widget->default_cursor = cursor;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:23 +00:00
|
|
|
static cairo_surface_t *
|
|
|
|
widget_get_cairo_surface(struct widget *widget)
|
|
|
|
{
|
|
|
|
struct surface *surface = widget->surface;
|
|
|
|
struct window *window = widget->window;
|
|
|
|
|
2013-12-19 16:17:12 +00:00
|
|
|
assert(widget->use_cairo);
|
|
|
|
|
2013-02-13 14:17:23 +00:00
|
|
|
if (!surface->cairo_surface) {
|
|
|
|
if (surface == window->main_surface)
|
|
|
|
window_create_main_surface(window);
|
|
|
|
else
|
2014-03-10 15:35:48 +00:00
|
|
|
surface_create_surface(surface, 0);
|
2013-02-13 14:17:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return surface->cairo_surface;
|
|
|
|
}
|
|
|
|
|
2013-05-22 12:41:25 +00:00
|
|
|
static void
|
|
|
|
widget_cairo_update_transform(struct widget *widget, cairo_t *cr)
|
|
|
|
{
|
|
|
|
struct surface *surface = widget->surface;
|
|
|
|
double angle;
|
|
|
|
cairo_matrix_t m;
|
|
|
|
enum wl_output_transform transform;
|
|
|
|
int surface_width, surface_height;
|
|
|
|
int translate_x, translate_y;
|
2013-05-24 11:09:43 +00:00
|
|
|
int32_t scale;
|
2013-05-22 12:41:25 +00:00
|
|
|
|
|
|
|
surface_width = surface->allocation.width;
|
|
|
|
surface_height = surface->allocation.height;
|
|
|
|
|
2013-05-22 12:41:28 +00:00
|
|
|
transform = surface->buffer_transform;
|
2013-05-22 12:41:29 +00:00
|
|
|
scale = surface->buffer_scale;
|
2013-05-22 12:41:28 +00:00
|
|
|
|
2013-05-22 12:41:25 +00:00
|
|
|
switch (transform) {
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
|
|
|
cairo_matrix_init(&m, -1, 0, 0, 1, 0, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cairo_matrix_init_identity(&m);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (transform) {
|
|
|
|
case WL_OUTPUT_TRANSFORM_NORMAL:
|
|
|
|
default:
|
|
|
|
angle = 0;
|
|
|
|
translate_x = 0;
|
|
|
|
translate_y = 0;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED:
|
|
|
|
angle = 0;
|
|
|
|
translate_x = surface_width;
|
|
|
|
translate_y = 0;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_90:
|
|
|
|
angle = M_PI_2;
|
|
|
|
translate_x = surface_height;
|
|
|
|
translate_y = 0;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
|
|
|
angle = M_PI_2;
|
|
|
|
translate_x = surface_height;
|
|
|
|
translate_y = surface_width;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_180:
|
|
|
|
angle = M_PI;
|
|
|
|
translate_x = surface_width;
|
|
|
|
translate_y = surface_height;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
|
|
|
|
angle = M_PI;
|
|
|
|
translate_x = 0;
|
|
|
|
translate_y = surface_height;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_270:
|
|
|
|
angle = M_PI + M_PI_2;
|
|
|
|
translate_x = 0;
|
|
|
|
translate_y = surface_width;
|
|
|
|
break;
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
|
|
|
angle = M_PI + M_PI_2;
|
|
|
|
translate_x = 0;
|
|
|
|
translate_y = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-05-22 12:41:29 +00:00
|
|
|
cairo_scale(cr, scale, scale);
|
2013-05-22 12:41:25 +00:00
|
|
|
cairo_translate(cr, translate_x, translate_y);
|
|
|
|
cairo_rotate(cr, angle);
|
|
|
|
cairo_transform(cr, &m);
|
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:23 +00:00
|
|
|
cairo_t *
|
|
|
|
widget_cairo_create(struct widget *widget)
|
|
|
|
{
|
2013-04-25 10:57:48 +00:00
|
|
|
struct surface *surface = widget->surface;
|
2013-02-13 14:17:23 +00:00
|
|
|
cairo_surface_t *cairo_surface;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
cairo_surface = widget_get_cairo_surface(widget);
|
|
|
|
cr = cairo_create(cairo_surface);
|
|
|
|
|
2013-05-22 12:41:25 +00:00
|
|
|
widget_cairo_update_transform(widget, cr);
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
cairo_translate(cr, -surface->allocation.x, -surface->allocation.y);
|
|
|
|
|
2013-02-13 14:17:23 +00:00
|
|
|
return cr;
|
|
|
|
}
|
|
|
|
|
clients: add subsurfaces demo
Add a demo program with:
- a main surface (green)
- a Cairo-image sub-surface (red)
- a raw GLESv2 widget (triangle)
Sub-surface input region is set empty to avoid problems in toytoolkit.
If Cairo links to libGL, then we will end up with also libGLESv2 linked
to subsurfaces program, and both libs getting really used, which leads
to disaster.
Do not build subsurfaces demo, if Cairo links to libGL and cairo-egl is
usable.
The GL rendering loop is not tied to the toytoolkit or the widget, but
runs directly from its own frame callback. Therefore it runs
independent of the rest of the application. This also relies on one of
two things:
- eglSwapInterval(0) is implemented, and therefore eglSwapBuffers never
blocks indefinitely, or
- toytoolkit has a workaround, that guarantees that eglSwapBuffers will
return soon, when we force a repaint on resize.
Otherwise the demo will deadlock.
The code is separated into three sections:
1. The library component, using only EGL, GLESv2, and libwayland-client
APIs, and not aware of any toolkit details of the parent application.
This runs independently until the parent application tells otherwise.
2. The glue code: a toytoolkit application widget, who has its own
rendering machinery.
3. The application written in toytoolkit.
This patch also adds new toytoolkit interfaces:
- widget_get_wl_surface()
- widget_get_last_time()
- widget_input_region_add()
Toytoolkit applications have not had a possibility to change the input
region. The frame widget (decorations) set the input region on its own
when used, otherwise the default input region of everything has been
used. If a window does not have a frame widget, it can now use
widget_input_region_add() to set a custom input region.
These are not window methods, because a widget may lie on a different
wl_surface (sub-surface) than the window.
Changes in v3:
- replace set_commit_mode with set_sync and set_desync
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:50 +00:00
|
|
|
struct wl_surface *
|
|
|
|
widget_get_wl_surface(struct widget *widget)
|
|
|
|
{
|
|
|
|
return widget->surface->surface;
|
|
|
|
}
|
|
|
|
|
2013-09-08 23:40:17 +00:00
|
|
|
struct wl_subsurface *
|
|
|
|
widget_get_wl_subsurface(struct widget *widget)
|
|
|
|
{
|
|
|
|
return widget->surface->subsurface;
|
|
|
|
}
|
|
|
|
|
clients: add subsurfaces demo
Add a demo program with:
- a main surface (green)
- a Cairo-image sub-surface (red)
- a raw GLESv2 widget (triangle)
Sub-surface input region is set empty to avoid problems in toytoolkit.
If Cairo links to libGL, then we will end up with also libGLESv2 linked
to subsurfaces program, and both libs getting really used, which leads
to disaster.
Do not build subsurfaces demo, if Cairo links to libGL and cairo-egl is
usable.
The GL rendering loop is not tied to the toytoolkit or the widget, but
runs directly from its own frame callback. Therefore it runs
independent of the rest of the application. This also relies on one of
two things:
- eglSwapInterval(0) is implemented, and therefore eglSwapBuffers never
blocks indefinitely, or
- toytoolkit has a workaround, that guarantees that eglSwapBuffers will
return soon, when we force a repaint on resize.
Otherwise the demo will deadlock.
The code is separated into three sections:
1. The library component, using only EGL, GLESv2, and libwayland-client
APIs, and not aware of any toolkit details of the parent application.
This runs independently until the parent application tells otherwise.
2. The glue code: a toytoolkit application widget, who has its own
rendering machinery.
3. The application written in toytoolkit.
This patch also adds new toytoolkit interfaces:
- widget_get_wl_surface()
- widget_get_last_time()
- widget_input_region_add()
Toytoolkit applications have not had a possibility to change the input
region. The frame widget (decorations) set the input region on its own
when used, otherwise the default input region of everything has been
used. If a window does not have a frame widget, it can now use
widget_input_region_add() to set a custom input region.
These are not window methods, because a widget may lie on a different
wl_surface (sub-surface) than the window.
Changes in v3:
- replace set_commit_mode with set_sync and set_desync
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:50 +00:00
|
|
|
uint32_t
|
|
|
|
widget_get_last_time(struct widget *widget)
|
|
|
|
{
|
|
|
|
return widget->surface->last_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_input_region_add(struct widget *widget, const struct rectangle *rect)
|
|
|
|
{
|
|
|
|
struct wl_compositor *comp = widget->window->display->compositor;
|
|
|
|
struct surface *surface = widget->surface;
|
|
|
|
|
|
|
|
if (!surface->input_region)
|
|
|
|
surface->input_region = wl_compositor_create_region(comp);
|
|
|
|
|
|
|
|
if (rect) {
|
|
|
|
wl_region_add(surface->input_region,
|
|
|
|
rect->x, rect->y, rect->width, rect->height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-08-09 04:20:38 +00:00
|
|
|
void
|
|
|
|
widget_set_touch_up_handler(struct widget *widget,
|
|
|
|
widget_touch_up_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->touch_up_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_set_touch_down_handler(struct widget *widget,
|
|
|
|
widget_touch_down_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->touch_down_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_set_touch_motion_handler(struct widget *widget,
|
|
|
|
widget_touch_motion_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->touch_motion_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_set_touch_frame_handler(struct widget *widget,
|
|
|
|
widget_touch_frame_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->touch_frame_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_set_touch_cancel_handler(struct widget *widget,
|
|
|
|
widget_touch_cancel_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->touch_cancel_handler = handler;
|
|
|
|
}
|
|
|
|
|
2012-08-14 09:02:41 +00:00
|
|
|
void
|
|
|
|
widget_set_axis_handler(struct widget *widget,
|
|
|
|
widget_axis_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->axis_handler = handler;
|
|
|
|
}
|
|
|
|
|
2016-01-18 06:38:22 +00:00
|
|
|
void
|
|
|
|
widget_set_pointer_frame_handler(struct widget *widget,
|
|
|
|
widget_pointer_frame_handler_t handler)
|
|
|
|
{
|
|
|
|
widget->pointer_frame_handler = handler;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
widget_set_axis_handlers(struct widget *widget,
|
|
|
|
widget_axis_handler_t axis_handler,
|
|
|
|
widget_axis_source_handler_t axis_source_handler,
|
|
|
|
widget_axis_stop_handler_t axis_stop_handler,
|
|
|
|
widget_axis_discrete_handler_t axis_discrete_handler)
|
|
|
|
{
|
|
|
|
widget->axis_handler = axis_handler;
|
|
|
|
widget->axis_source_handler = axis_source_handler;
|
|
|
|
widget->axis_stop_handler = axis_stop_handler;
|
|
|
|
widget->axis_discrete_handler = axis_discrete_handler;
|
|
|
|
}
|
|
|
|
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
static void
|
|
|
|
window_schedule_redraw_task(struct window *window);
|
|
|
|
|
2012-01-08 20:18:19 +00:00
|
|
|
void
|
|
|
|
widget_schedule_redraw(struct widget *widget)
|
|
|
|
{
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(widget->surface->surface, "widget %p\n", widget);
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
widget->surface->redraw_needed = 1;
|
|
|
|
window_schedule_redraw_task(widget->window);
|
2012-01-08 20:18:19 +00:00
|
|
|
}
|
|
|
|
|
2013-12-19 16:17:12 +00:00
|
|
|
void
|
|
|
|
widget_set_use_cairo(struct widget *widget,
|
|
|
|
int use_cairo)
|
|
|
|
{
|
|
|
|
widget->use_cairo = use_cairo;
|
|
|
|
}
|
|
|
|
|
2010-06-08 18:08:30 +00:00
|
|
|
cairo_surface_t *
|
|
|
|
window_get_surface(struct window *window)
|
|
|
|
{
|
2013-02-13 14:17:23 +00:00
|
|
|
cairo_surface_t *cairo_surface;
|
|
|
|
|
|
|
|
cairo_surface = widget_get_cairo_surface(window->main_surface->widget);
|
|
|
|
|
|
|
|
return cairo_surface_reference(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)
|
|
|
|
{
|
2013-02-13 14:17:13 +00:00
|
|
|
return window->main_surface->surface;
|
2011-03-14 11:07:26 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-02-13 14:17:23 +00:00
|
|
|
cr = widget_cairo_create(widget);
|
2013-11-12 00:42:23 +00:00
|
|
|
cairo_translate(cr, widget->allocation.x, widget->allocation.y);
|
2012-05-23 19:06:27 +00:00
|
|
|
cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0);
|
|
|
|
cairo_paint(cr);
|
|
|
|
|
2013-02-13 14:17:22 +00:00
|
|
|
width = widget->allocation.width;
|
|
|
|
height = widget->allocation.height;
|
2012-05-23 19:06:27 +00:00
|
|
|
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
|
2013-11-12 00:42:23 +00:00
|
|
|
get_text_extents(struct display *display, struct tooltip *tooltip)
|
2012-05-23 19:06:27 +00:00
|
|
|
{
|
|
|
|
cairo_t *cr;
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
|
2015-11-20 19:57:43 +00:00
|
|
|
/* Use the dummy_surface because the tooltip's surface was not
|
2012-11-19 15:16:01 +00:00
|
|
|
* created yet, and parent does not have a valid surface
|
|
|
|
* outside repaint, either.
|
|
|
|
*/
|
2013-11-12 00:42:23 +00:00
|
|
|
cr = cairo_create(display->dummy_surface);
|
2012-05-23 19:06:27 +00:00
|
|
|
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;
|
|
|
|
const int offset_y = 27;
|
|
|
|
const int margin = 3;
|
|
|
|
cairo_text_extents_t extents;
|
|
|
|
|
|
|
|
if (tooltip->widget)
|
|
|
|
return 0;
|
|
|
|
|
2013-11-12 00:42:23 +00:00
|
|
|
tooltip->widget = window_add_subsurface(parent->window, tooltip, SUBSURFACE_DESYNCHRONIZED);
|
2012-05-23 19:06:27 +00:00
|
|
|
|
2013-11-12 00:42:23 +00:00
|
|
|
extents = get_text_extents(display, tooltip);
|
2012-05-23 19:06:27 +00:00
|
|
|
widget_set_redraw_handler(tooltip->widget, tooltip_redraw_handler);
|
2013-11-12 00:42:23 +00:00
|
|
|
widget_set_allocation(tooltip->widget,
|
|
|
|
tooltip->x, tooltip->y + offset_y,
|
|
|
|
extents.width + 20, 20 + margin * 2);
|
2012-05-23 19:06:27 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
tooltip->widget = 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;
|
|
|
|
|
2012-07-08 01:03:47 +00:00
|
|
|
if (read(tooltip->tooltip_fd, &exp, sizeof (uint64_t)) != sizeof (uint64_t))
|
|
|
|
abort();
|
2012-05-23 19:06:27 +00:00
|
|
|
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->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)
|
|
|
|
{
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame *frame = data;
|
2012-01-11 03:41:05 +00:00
|
|
|
struct widget *child = frame->child;
|
2013-10-14 00:08:40 +00:00
|
|
|
struct rectangle interior;
|
|
|
|
struct rectangle input;
|
|
|
|
struct rectangle opaque;
|
|
|
|
|
2013-11-12 00:16:11 +00:00
|
|
|
if (widget->window->fullscreen) {
|
2013-10-14 00:08:40 +00:00
|
|
|
interior.x = 0;
|
|
|
|
interior.y = 0;
|
|
|
|
interior.width = width;
|
|
|
|
interior.height = height;
|
2012-10-15 19:01:24 +00:00
|
|
|
} else {
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_resize(frame->frame, width, height);
|
|
|
|
frame_interior(frame->frame, &interior.x, &interior.y,
|
|
|
|
&interior.width, &interior.height);
|
2012-05-10 00:04:35 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
widget_set_allocation(child, interior.x, interior.y,
|
|
|
|
interior.width, interior.height);
|
2012-05-10 00:04:35 +00:00
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
if (child->resize_handler) {
|
|
|
|
child->resize_handler(child, interior.width, interior.height,
|
|
|
|
child->user_data);
|
2013-08-09 04:20:38 +00:00
|
|
|
|
2013-11-12 00:16:11 +00:00
|
|
|
if (widget->window->fullscreen) {
|
2013-10-14 00:08:40 +00:00
|
|
|
width = child->allocation.width;
|
|
|
|
height = child->allocation.height;
|
|
|
|
} else {
|
|
|
|
frame_resize_inside(frame->frame,
|
|
|
|
child->allocation.width,
|
|
|
|
child->allocation.height);
|
|
|
|
width = frame_width(frame->frame);
|
|
|
|
height = frame_height(frame->frame);
|
|
|
|
}
|
2013-08-09 04:20:38 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
widget_set_allocation(widget, 0, 0, width, height);
|
2012-09-26 12:05:45 +00:00
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
widget->surface->input_region =
|
|
|
|
wl_compositor_create_region(widget->window->display->compositor);
|
2013-11-12 00:16:11 +00:00
|
|
|
if (!widget->window->fullscreen) {
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_input_rect(frame->frame, &input.x, &input.y,
|
|
|
|
&input.width, &input.height);
|
|
|
|
wl_region_add(widget->surface->input_region,
|
|
|
|
input.x, input.y, input.width, input.height);
|
2012-09-26 12:05:45 +00:00
|
|
|
} else {
|
2013-10-14 00:08:40 +00:00
|
|
|
wl_region_add(widget->surface->input_region, 0, 0, width, height);
|
2012-09-26 12:05:45 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
widget_set_allocation(widget, 0, 0, width, height);
|
2012-05-10 00:04:35 +00:00
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
if (child->opaque) {
|
2013-11-12 00:16:11 +00:00
|
|
|
if (!widget->window->fullscreen) {
|
2013-10-16 23:06:18 +00:00
|
|
|
frame_opaque_rect(frame->frame, &opaque.x, &opaque.y,
|
|
|
|
&opaque.width, &opaque.height);
|
|
|
|
|
|
|
|
wl_region_add(widget->surface->opaque_region,
|
|
|
|
opaque.x, opaque.y,
|
|
|
|
opaque.width, opaque.height);
|
|
|
|
} else {
|
|
|
|
wl_region_add(widget->surface->opaque_region,
|
|
|
|
0, 0, width, height);
|
|
|
|
}
|
2012-05-10 00:04:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
widget_schedule_redraw(widget);
|
2012-01-11 03:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_redraw_handler(struct widget *widget, void *data)
|
|
|
|
{
|
|
|
|
cairo_t *cr;
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame *frame = data;
|
2012-01-11 03:41:05 +00:00
|
|
|
struct window *window = widget->window;
|
|
|
|
|
2013-11-12 00:16:11 +00:00
|
|
|
if (window->fullscreen)
|
2012-02-17 03:57:21 +00:00
|
|
|
return;
|
|
|
|
|
2013-02-13 14:17:23 +00:00
|
|
|
cr = widget_cairo_create(widget);
|
2012-01-11 03:41:05 +00:00
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_repaint(frame->frame, cr);
|
2012-01-11 03:41:05 +00:00
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
}
|
|
|
|
|
2011-12-15 14:14:34 +00:00
|
|
|
static int
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_get_pointer_image_for_location(struct window_frame *frame,
|
|
|
|
enum theme_location location)
|
2010-08-16 21:47:07 +00:00
|
|
|
{
|
2012-09-28 08:45:06 +00:00
|
|
|
struct window *window = frame->widget->window;
|
2010-08-16 21:47:07 +00:00
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
if (window->custom)
|
2013-02-14 21:31:42 +00:00
|
|
|
return CURSOR_LEFT_PTR;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-10 12:10:30 +00:00
|
|
|
static void
|
|
|
|
frame_menu_func(void *data, struct input *input, int index)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
|
|
|
|
switch (index) {
|
|
|
|
case 0: /* close */
|
|
|
|
window_close(window);
|
|
|
|
break;
|
2015-11-17 08:00:35 +00:00
|
|
|
case 1: /* fullscreen */
|
2014-09-10 12:10:30 +00:00
|
|
|
/* we don't have a way to get out of fullscreen for now */
|
|
|
|
if (window->fullscreen_handler)
|
|
|
|
window->fullscreen_handler(window, window->user_data);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2014-09-10 12:10:30 +00:00
|
|
|
int count;
|
2012-01-31 14:53:44 +00:00
|
|
|
|
2014-09-10 12:10:30 +00:00
|
|
|
static const char *entries[] = {
|
|
|
|
"Close",
|
|
|
|
"Fullscreen"
|
|
|
|
};
|
|
|
|
|
|
|
|
if (window->fullscreen_handler)
|
|
|
|
count = ARRAY_LENGTH(entries);
|
|
|
|
else
|
|
|
|
count = ARRAY_LENGTH(entries) - 1;
|
|
|
|
|
|
|
|
input_get_position(input, &x, &y);
|
|
|
|
window_show_menu(window->display, input, time, window,
|
|
|
|
x - 10, y - 10, frame_menu_func, entries, count);
|
2012-01-31 14:53:44 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame *frame = data;
|
|
|
|
enum theme_location location;
|
|
|
|
|
|
|
|
location = frame_pointer_enter(frame->frame, input, x, y);
|
|
|
|
if (frame_status(frame->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
widget_schedule_redraw(frame->widget);
|
|
|
|
|
|
|
|
return frame_get_pointer_image_for_location(data, location);
|
2012-01-11 03:41:05 +00:00
|
|
|
}
|
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
|
|
|
{
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame *frame = data;
|
|
|
|
enum theme_location location;
|
|
|
|
|
|
|
|
location = frame_pointer_motion(frame->frame, input, x, y);
|
|
|
|
if (frame_status(frame->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
widget_schedule_redraw(frame->widget);
|
|
|
|
|
|
|
|
return frame_get_pointer_image_for_location(data, location);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_leave_handler(struct widget *widget,
|
|
|
|
struct input *input, void *data)
|
|
|
|
{
|
|
|
|
struct window_frame *frame = data;
|
|
|
|
|
|
|
|
frame_pointer_leave(frame->frame, input);
|
|
|
|
if (frame_status(frame->frame) & FRAME_STATUS_REPAINT)
|
|
|
|
widget_schedule_redraw(frame->widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_handle_status(struct window_frame *frame, struct input *input,
|
|
|
|
uint32_t time, enum theme_location location)
|
|
|
|
{
|
|
|
|
struct window *window = frame->widget->window;
|
|
|
|
uint32_t status;
|
|
|
|
|
|
|
|
status = frame_status(frame->frame);
|
|
|
|
if (status & FRAME_STATUS_REPAINT)
|
|
|
|
widget_schedule_redraw(frame->widget);
|
|
|
|
|
2014-02-19 00:18:42 +00:00
|
|
|
if (status & FRAME_STATUS_MINIMIZE) {
|
|
|
|
window_set_minimized(window);
|
|
|
|
frame_status_clear(frame->frame, FRAME_STATUS_MINIMIZE);
|
|
|
|
}
|
2013-10-14 00:08:40 +00:00
|
|
|
|
|
|
|
if (status & FRAME_STATUS_MENU) {
|
|
|
|
window_show_frame_menu(window, input, time);
|
|
|
|
frame_status_clear(frame->frame, FRAME_STATUS_MENU);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & FRAME_STATUS_MAXIMIZE) {
|
2013-11-12 00:16:11 +00:00
|
|
|
window_set_maximized(window, !window->maximized);
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_status_clear(frame->frame, FRAME_STATUS_MAXIMIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status & FRAME_STATUS_CLOSE) {
|
2014-02-01 23:17:34 +00:00
|
|
|
window_close(window);
|
2013-10-28 02:32:54 +00:00
|
|
|
return;
|
2013-10-14 00:08:40 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
if ((status & FRAME_STATUS_MOVE) && window->xdg_surface) {
|
2013-10-14 00:08:40 +00:00
|
|
|
input_ungrab(input);
|
2013-12-09 19:58:00 +00:00
|
|
|
xdg_surface_move(window->xdg_surface,
|
|
|
|
input_get_seat(input),
|
|
|
|
window->display->serial);
|
2013-10-14 00:08:40 +00:00
|
|
|
|
|
|
|
frame_status_clear(frame->frame, FRAME_STATUS_MOVE);
|
|
|
|
}
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
if ((status & FRAME_STATUS_RESIZE) && window->xdg_surface) {
|
2013-10-14 00:08:40 +00:00
|
|
|
input_ungrab(input);
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
xdg_surface_resize(window->xdg_surface,
|
|
|
|
input_get_seat(input),
|
|
|
|
window->display->serial,
|
|
|
|
location);
|
2013-10-14 00:08:40 +00:00
|
|
|
|
|
|
|
frame_status_clear(frame->frame, FRAME_STATUS_RESIZE);
|
|
|
|
}
|
2012-01-11 03:41:05 +00:00
|
|
|
}
|
2011-10-25 11:20:51 +00:00
|
|
|
|
2014-06-12 03:06:25 +00:00
|
|
|
#define DOUBLE_CLICK_PERIOD 250
|
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
|
|
|
|
|
|
|
{
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame *frame = data;
|
|
|
|
enum theme_location location;
|
2013-02-14 21:31:42 +00:00
|
|
|
|
2014-06-12 03:06:25 +00:00
|
|
|
frame->double_click = 0;
|
|
|
|
if (state == WL_POINTER_BUTTON_STATE_PRESSED) {
|
|
|
|
if (time - frame->last_time <= DOUBLE_CLICK_PERIOD) {
|
|
|
|
frame->double_click = 1;
|
|
|
|
frame->did_double = 1;
|
|
|
|
} else
|
|
|
|
frame->did_double = 0;
|
|
|
|
|
|
|
|
frame->last_time = time;
|
|
|
|
} else if (frame->did_double == 1) {
|
|
|
|
frame->double_click = 1;
|
|
|
|
frame->did_double = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame->double_click)
|
|
|
|
location = frame_double_click(frame->frame, input,
|
|
|
|
button, state);
|
|
|
|
else
|
|
|
|
location = frame_pointer_button(frame->frame, input,
|
|
|
|
button, state);
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_handle_status(frame, input, time, location);
|
2012-01-11 03:41:05 +00:00
|
|
|
}
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
static void
|
2013-08-15 16:10:08 +00:00
|
|
|
frame_touch_down_handler(struct widget *widget, struct input *input,
|
|
|
|
uint32_t serial, uint32_t time, int32_t id,
|
|
|
|
float x, float y, void *data)
|
|
|
|
{
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame *frame = data;
|
|
|
|
|
2014-06-12 03:06:26 +00:00
|
|
|
frame->double_click = 0;
|
|
|
|
if (time - frame->last_time <= DOUBLE_CLICK_PERIOD &&
|
|
|
|
frame->last_id == id) {
|
|
|
|
frame->double_click = 1;
|
|
|
|
frame->did_double = 1;
|
|
|
|
frame->double_id = id;
|
|
|
|
} else
|
|
|
|
frame->did_double = 0;
|
|
|
|
|
|
|
|
frame->last_time = time;
|
|
|
|
frame->last_id = id;
|
|
|
|
|
|
|
|
if (frame->double_click)
|
|
|
|
frame_double_touch_down(frame->frame, input, id, x, y);
|
|
|
|
else
|
|
|
|
frame_touch_down(frame->frame, input, id, x, y);
|
|
|
|
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_handle_status(frame, input, time, THEME_LOCATION_CLIENT_AREA);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
frame_touch_up_handler(struct widget *widget,
|
|
|
|
struct input *input, uint32_t serial, uint32_t time,
|
|
|
|
int32_t id, void *data)
|
|
|
|
{
|
|
|
|
struct window_frame *frame = data;
|
|
|
|
|
2014-06-12 03:06:26 +00:00
|
|
|
if (frame->double_id == id && frame->did_double) {
|
|
|
|
frame->did_double = 0;
|
|
|
|
frame->double_id = 0;
|
|
|
|
frame_double_touch_up(frame->frame, input, id);
|
|
|
|
} else
|
|
|
|
frame_touch_up(frame->frame, input, id);
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_handle_status(frame, input, time, THEME_LOCATION_CLIENT_AREA);
|
2013-08-15 16:10:08 +00:00
|
|
|
}
|
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
struct widget *
|
2013-10-14 00:08:38 +00:00
|
|
|
window_frame_create(struct window *window, void *data)
|
2012-01-11 03:41:05 +00:00
|
|
|
{
|
2013-10-14 00:08:40 +00:00
|
|
|
struct window_frame *frame;
|
2013-12-31 23:35:39 +00:00
|
|
|
uint32_t buttons;
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
if (window->custom) {
|
2013-12-31 23:35:39 +00:00
|
|
|
buttons = FRAME_BUTTON_NONE;
|
|
|
|
} else {
|
|
|
|
buttons = FRAME_BUTTON_ALL;
|
|
|
|
}
|
2012-01-11 03:41:05 +00:00
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
frame = xzalloc(sizeof *frame);
|
2013-10-14 00:08:40 +00:00
|
|
|
frame->frame = frame_create(window->display->theme, 0, 0,
|
2013-12-31 23:35:39 +00:00
|
|
|
buttons, window->title);
|
2013-10-14 00:08:40 +00:00
|
|
|
|
2012-01-11 03:41:05 +00:00
|
|
|
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);
|
2013-10-14 00:08:40 +00:00
|
|
|
widget_set_leave_handler(frame->widget, frame_leave_handler);
|
2012-01-11 03:41:05 +00:00
|
|
|
widget_set_motion_handler(frame->widget, frame_motion_handler);
|
|
|
|
widget_set_button_handler(frame->widget, frame_button_handler);
|
2013-08-15 16:10:08 +00:00
|
|
|
widget_set_touch_down_handler(frame->widget, frame_touch_down_handler);
|
2013-10-14 00:08:40 +00:00
|
|
|
widget_set_touch_up_handler(frame->widget, frame_touch_up_handler);
|
2012-05-10 00:04:35 +00:00
|
|
|
|
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-06-20 21:30:03 +00:00
|
|
|
void
|
2013-10-14 00:08:38 +00:00
|
|
|
window_frame_set_child_size(struct widget *widget, int child_width,
|
|
|
|
int child_height)
|
2012-06-20 21:30:03 +00:00
|
|
|
{
|
|
|
|
struct display *display = widget->window->display;
|
|
|
|
struct theme *t = display->theme;
|
|
|
|
int decoration_width, decoration_height;
|
|
|
|
int width, height;
|
2013-11-12 00:16:11 +00:00
|
|
|
int margin = widget->window->maximized ? 0 : t->margin;
|
2012-06-20 21:30:03 +00:00
|
|
|
|
2013-11-12 00:16:11 +00:00
|
|
|
if (!widget->window->fullscreen) {
|
2012-09-28 08:45:06 +00:00
|
|
|
decoration_width = (t->width + margin) * 2;
|
2012-06-20 21:30:03 +00:00
|
|
|
decoration_height = t->width +
|
2012-09-28 08:45:06 +00:00
|
|
|
t->titlebar_height + margin * 2;
|
2012-06-20 21:30:03 +00:00
|
|
|
|
|
|
|
width = child_width + decoration_width;
|
|
|
|
height = child_height + decoration_height;
|
|
|
|
} else {
|
|
|
|
width = child_width;
|
|
|
|
height = child_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_schedule_resize(widget->window, width, height);
|
|
|
|
}
|
|
|
|
|
2012-01-19 11:33:50 +00:00
|
|
|
static void
|
2013-10-14 00:08:40 +00:00
|
|
|
window_frame_destroy(struct window_frame *frame)
|
2012-01-19 11:33:50 +00:00
|
|
|
{
|
2013-10-14 00:08:40 +00:00
|
|
|
frame_destroy(frame->frame);
|
2012-05-10 00:04:35 +00:00
|
|
|
|
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-11-30 19:54:35 +00:00
|
|
|
int cursor;
|
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-11-30 19:54:35 +00:00
|
|
|
cursor = widget->enter_handler(focus, input, x, y,
|
|
|
|
widget->user_data);
|
|
|
|
else
|
|
|
|
cursor = widget->default_cursor;
|
2012-01-09 16:22:32 +00:00
|
|
|
|
2012-11-30 19:54:35 +00:00
|
|
|
input_set_pointer_image(input, cursor);
|
2012-01-09 13:42:24 +00:00
|
|
|
}
|
2011-09-21 01:43:54 +00:00
|
|
|
}
|
|
|
|
|
2013-11-25 10:42:51 +00:00
|
|
|
void
|
|
|
|
touch_grab(struct input *input, int32_t touch_id)
|
|
|
|
{
|
|
|
|
input->touch_grab = 1;
|
|
|
|
input->touch_grab_id = touch_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
touch_ungrab(struct input *input)
|
|
|
|
{
|
|
|
|
struct touch_point *tp, *tmp;
|
|
|
|
|
|
|
|
input->touch_grab = 0;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(tp, tmp,
|
|
|
|
&input->touch_point_list, link) {
|
|
|
|
if (tp->id != input->touch_grab_id)
|
|
|
|
continue;
|
|
|
|
wl_list_remove(&tp->link);
|
|
|
|
free(tp);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
2014-04-29 21:11:26 +00:00
|
|
|
|
|
|
|
input_set_focus_widget(input, widget, input->sx, input->sy);
|
2012-01-11 04:46:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2013-02-13 14:17:17 +00:00
|
|
|
widget = window_find_widget(input->pointer_focus,
|
2012-01-11 04:46:33 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:23:35 +00:00
|
|
|
static void
|
|
|
|
cursor_delay_timer_reset(struct input *input, uint32_t duration)
|
|
|
|
{
|
|
|
|
struct itimerspec its;
|
|
|
|
|
|
|
|
if (!duration)
|
|
|
|
input->cursor_timer_running = false;
|
|
|
|
else
|
|
|
|
input->cursor_timer_running = true;
|
|
|
|
|
|
|
|
its.it_interval.tv_sec = 0;
|
|
|
|
its.it_interval.tv_nsec = 0;
|
|
|
|
its.it_value.tv_sec = duration / 1000;
|
|
|
|
its.it_value.tv_nsec = (duration % 1000) * 1000 * 1000;
|
|
|
|
if (timerfd_settime(input->cursor_delay_fd, 0, &its, NULL) < 0)
|
|
|
|
fprintf(stderr, "could not set cursor timerfd\n: %m");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cancel_pointer_image_update(struct input *input)
|
|
|
|
{
|
|
|
|
if (input->cursor_timer_running)
|
|
|
|
cursor_delay_timer_reset(input, 0);
|
|
|
|
}
|
|
|
|
|
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;
|
2015-04-22 22:23:35 +00:00
|
|
|
cancel_pointer_image_update(input);
|
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;
|
|
|
|
}
|
|
|
|
|
2014-05-06 12:25:40 +00:00
|
|
|
window = wl_surface_get_user_data(surface);
|
|
|
|
if (surface != window->main_surface->surface) {
|
|
|
|
DBG("Ignoring input event from subsurface %p\n", surface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-12 02:42:15 +00:00
|
|
|
input->display->serial = serial;
|
|
|
|
input->pointer_enter_serial = serial;
|
2014-05-06 12:25:40 +00:00
|
|
|
input->pointer_focus = window;
|
2011-09-06 18:33:52 +00:00
|
|
|
|
2012-02-23 14:59:05 +00:00
|
|
|
input->sx = sx;
|
|
|
|
input->sy = sy;
|
2010-08-18 19:28:04 +00:00
|
|
|
|
2013-02-13 14:17:17 +00:00
|
|
|
widget = window_find_widget(window, 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
|
|
|
}
|
|
|
|
|
2012-08-11 18:56:08 +00:00
|
|
|
static void
|
|
|
|
pointer_handle_motion(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t time, wl_fixed_t sx_w, wl_fixed_t sy_w)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct window *window = input->pointer_focus;
|
|
|
|
struct widget *widget;
|
2012-11-30 19:54:35 +00:00
|
|
|
int cursor;
|
2012-08-11 18:56:08 +00:00
|
|
|
float sx = wl_fixed_to_double(sx_w);
|
|
|
|
float sy = wl_fixed_to_double(sy_w);
|
|
|
|
|
2013-08-29 09:52:54 +00:00
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
2014-05-06 12:25:40 +00:00
|
|
|
input->sx = sx;
|
|
|
|
input->sy = sy;
|
|
|
|
|
2013-07-11 18:41:27 +00:00
|
|
|
/* when making the window smaller - e.g. after a unmaximise we might
|
|
|
|
* still have a pending motion event that the compositor has picked
|
2015-08-26 22:13:27 +00:00
|
|
|
* based on the old surface dimensions. However, if we have an active
|
|
|
|
* grab, we expect to see input from outside the window anyway.
|
2013-07-11 18:41:27 +00:00
|
|
|
*/
|
2015-08-26 22:13:27 +00:00
|
|
|
if (!input->grab && (sx < window->main_surface->allocation.x ||
|
2015-08-26 22:13:26 +00:00
|
|
|
sy < window->main_surface->allocation.y ||
|
|
|
|
sx > window->main_surface->allocation.width ||
|
2015-08-26 22:13:27 +00:00
|
|
|
sy > window->main_surface->allocation.height))
|
2013-07-11 18:41:27 +00:00
|
|
|
return;
|
|
|
|
|
2012-08-11 18:56:08 +00:00
|
|
|
if (!(input->grab && input->grab_button)) {
|
2013-02-13 14:17:17 +00:00
|
|
|
widget = window_find_widget(window, sx, sy);
|
2012-08-11 18:56:08 +00:00
|
|
|
input_set_focus_widget(input, widget, sx, sy);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
else
|
|
|
|
widget = input->focus_widget;
|
2013-08-15 21:15:18 +00:00
|
|
|
if (widget) {
|
|
|
|
if (widget->motion_handler)
|
|
|
|
cursor = widget->motion_handler(input->focus_widget,
|
|
|
|
input, time, sx, sy,
|
|
|
|
widget->user_data);
|
|
|
|
else
|
|
|
|
cursor = widget->default_cursor;
|
|
|
|
} else
|
|
|
|
cursor = CURSOR_LEFT_PTR;
|
2012-08-11 18:56:08 +00:00
|
|
|
|
|
|
|
input_set_pointer_image(input, cursor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial,
|
|
|
|
uint32_t time, uint32_t button, uint32_t state_w)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct widget *widget;
|
|
|
|
enum wl_pointer_button_state state = state_w;
|
|
|
|
|
|
|
|
input->display->serial = serial;
|
|
|
|
if (input->focus_widget && input->grab == NULL &&
|
|
|
|
state == WL_POINTER_BUTTON_STATE_PRESSED)
|
|
|
|
input_grab(input, input->focus_widget, button);
|
|
|
|
|
|
|
|
widget = input->grab;
|
|
|
|
if (widget && widget->button_handler)
|
|
|
|
(*widget->button_handler)(widget,
|
|
|
|
input, time,
|
|
|
|
button, state,
|
|
|
|
input->grab->user_data);
|
|
|
|
|
|
|
|
if (input->grab && input->grab_button == button &&
|
|
|
|
state == WL_POINTER_BUTTON_STATE_RELEASED)
|
|
|
|
input_ungrab(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_handle_axis(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t time, uint32_t axis, wl_fixed_t value)
|
|
|
|
{
|
2012-08-14 09:02:41 +00:00
|
|
|
struct input *input = data;
|
|
|
|
struct widget *widget;
|
|
|
|
|
|
|
|
widget = input->focus_widget;
|
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
if (widget && widget->axis_handler)
|
|
|
|
(*widget->axis_handler)(widget,
|
|
|
|
input, time,
|
|
|
|
axis, value,
|
|
|
|
widget->user_data);
|
2012-08-11 18:56:08 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 06:38:22 +00:00
|
|
|
static void
|
|
|
|
pointer_handle_frame(void *data, struct wl_pointer *pointer)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct widget *widget;
|
|
|
|
|
|
|
|
widget = input->focus_widget;
|
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
if (widget && widget->pointer_frame_handler)
|
|
|
|
(*widget->pointer_frame_handler)(widget,
|
|
|
|
input,
|
|
|
|
widget->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_handle_axis_source(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t source)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct widget *widget;
|
|
|
|
|
|
|
|
widget = input->focus_widget;
|
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
if (widget && widget->axis_source_handler)
|
|
|
|
(*widget->axis_source_handler)(widget,
|
|
|
|
input,
|
|
|
|
source,
|
|
|
|
widget->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_handle_axis_stop(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t time, uint32_t axis)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct widget *widget;
|
|
|
|
|
|
|
|
widget = input->focus_widget;
|
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
if (widget && widget->axis_stop_handler)
|
|
|
|
(*widget->axis_stop_handler)(widget,
|
|
|
|
input, time,
|
|
|
|
axis,
|
|
|
|
widget->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pointer_handle_axis_discrete(void *data, struct wl_pointer *pointer,
|
|
|
|
uint32_t axis, int32_t discrete)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct widget *widget;
|
|
|
|
|
|
|
|
widget = input->focus_widget;
|
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
if (widget && widget->axis_discrete_handler)
|
|
|
|
(*widget->axis_discrete_handler)(widget,
|
|
|
|
input,
|
|
|
|
axis,
|
|
|
|
discrete,
|
|
|
|
widget->user_data);
|
|
|
|
}
|
|
|
|
|
2012-08-11 18:56:08 +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,
|
2016-01-18 06:38:22 +00:00
|
|
|
pointer_handle_frame,
|
|
|
|
pointer_handle_axis_source,
|
|
|
|
pointer_handle_axis_stop,
|
|
|
|
pointer_handle_axis_discrete,
|
2012-08-11 18:56:08 +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;
|
2012-06-21 02:41:59 +00:00
|
|
|
struct itimerspec its;
|
|
|
|
|
|
|
|
its.it_interval.tv_sec = 0;
|
|
|
|
its.it_interval.tv_nsec = 0;
|
|
|
|
its.it_value.tv_sec = 0;
|
|
|
|
its.it_value.tv_nsec = 0;
|
|
|
|
timerfd_settime(input->repeat_timer_fd, 0, &its, NULL);
|
2011-12-16 10:02:09 +00:00
|
|
|
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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-08-11 18:56:08 +00:00
|
|
|
keyboard_repeat_func(struct task *task, uint32_t events)
|
2009-02-23 02:51:24 +00:00
|
|
|
{
|
2012-08-11 18:56:08 +00:00
|
|
|
struct input *input =
|
|
|
|
container_of(task, struct input, repeat_task);
|
|
|
|
struct window *window = input->keyboard_focus;
|
|
|
|
uint64_t exp;
|
2012-02-23 14:59:05 +00:00
|
|
|
|
2012-08-11 18:56:08 +00:00
|
|
|
if (read(input->repeat_timer_fd, &exp, sizeof exp) != sizeof exp)
|
|
|
|
/* If we change the timer between the fd becoming
|
|
|
|
* readable and getting here, there'll be nothing to
|
|
|
|
* read and we get EAGAIN. */
|
|
|
|
return;
|
2012-02-23 14:59:05 +00:00
|
|
|
|
2012-08-11 18:56:08 +00:00
|
|
|
if (window && window->key_handler) {
|
|
|
|
(*window->key_handler)(window, input, input->repeat_time,
|
|
|
|
input->repeat_key, input->repeat_sym,
|
|
|
|
WL_KEYBOARD_KEY_STATE_PRESSED,
|
|
|
|
window->user_data);
|
|
|
|
}
|
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;
|
2013-10-10 17:44:22 +00:00
|
|
|
struct xkb_keymap *keymap;
|
|
|
|
struct xkb_state *state;
|
2012-06-01 11:14:06 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-08-19 20:59:51 +00:00
|
|
|
keymap = xkb_keymap_new_from_string(input->display->xkb_context,
|
|
|
|
map_str,
|
|
|
|
XKB_KEYMAP_FORMAT_TEXT_V1,
|
|
|
|
0);
|
2012-06-01 11:14:06 +00:00
|
|
|
munmap(map_str, size);
|
|
|
|
close(fd);
|
|
|
|
|
2013-10-10 17:44:22 +00:00
|
|
|
if (!keymap) {
|
2012-06-01 11:14:06 +00:00
|
|
|
fprintf(stderr, "failed to compile keymap\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-10 17:44:22 +00:00
|
|
|
state = xkb_state_new(keymap);
|
|
|
|
if (!state) {
|
2012-06-01 11:14:06 +00:00
|
|
|
fprintf(stderr, "failed to create XKB state\n");
|
2014-08-19 20:59:51 +00:00
|
|
|
xkb_keymap_unref(keymap);
|
2012-06-01 11:14:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-10 17:44:22 +00:00
|
|
|
xkb_keymap_unref(input->xkb.keymap);
|
|
|
|
xkb_state_unref(input->xkb.state);
|
|
|
|
input->xkb.keymap = keymap;
|
|
|
|
input->xkb.state = state;
|
|
|
|
|
2012-06-01 11:14:06 +00:00
|
|
|
input->xkb.control_mask =
|
2014-08-19 20:59:51 +00:00
|
|
|
1 << xkb_keymap_mod_get_index(input->xkb.keymap, "Control");
|
2012-06-01 11:14:06 +00:00
|
|
|
input->xkb.alt_mask =
|
2014-08-19 20:59:51 +00:00
|
|
|
1 << xkb_keymap_mod_get_index(input->xkb.keymap, "Mod1");
|
2012-06-01 11:14:06 +00:00
|
|
|
input->xkb.shift_mask =
|
2014-08-19 20:59:51 +00:00
|
|
|
1 << xkb_keymap_mod_get_index(input->xkb.keymap, "Shift");
|
2012-06-01 11:14:06 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 18:56:08 +00:00
|
|
|
static void
|
|
|
|
keyboard_handle_enter(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, struct wl_surface *surface,
|
|
|
|
struct wl_array *keys)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct window *window;
|
|
|
|
|
|
|
|
input->display->serial = serial;
|
|
|
|
input->keyboard_focus = wl_surface_get_user_data(surface);
|
|
|
|
|
|
|
|
window = input->keyboard_focus;
|
|
|
|
if (window->keyboard_focus_handler)
|
|
|
|
(*window->keyboard_focus_handler)(window,
|
2012-08-14 02:25:53 +00:00
|
|
|
input, window->user_data);
|
2012-08-11 18:56:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
keyboard_handle_leave(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, struct wl_surface *surface)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
|
|
|
|
input->display->serial = serial;
|
|
|
|
input_remove_keyboard_focus(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
keyboard_handle_key(void *data, struct wl_keyboard *keyboard,
|
|
|
|
uint32_t serial, uint32_t time, uint32_t key,
|
|
|
|
uint32_t state_w)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct window *window = input->keyboard_focus;
|
|
|
|
uint32_t code, num_syms;
|
|
|
|
enum wl_keyboard_key_state state = state_w;
|
|
|
|
const xkb_keysym_t *syms;
|
|
|
|
xkb_keysym_t sym;
|
|
|
|
struct itimerspec its;
|
|
|
|
|
|
|
|
input->display->serial = serial;
|
|
|
|
code = key + 8;
|
2012-08-14 02:25:53 +00:00
|
|
|
if (!window || !input->xkb.state)
|
2012-08-11 18:56:08 +00:00
|
|
|
return;
|
|
|
|
|
2014-04-29 21:19:20 +00:00
|
|
|
/* We only use input grabs for pointer events for now, so just
|
|
|
|
* ignore key presses if a grab is active. We expand the key
|
|
|
|
* event delivery mechanism to route events to widgets to
|
|
|
|
* properly handle key grabs. In the meantime, this prevents
|
|
|
|
* key event devlivery while a grab is active. */
|
|
|
|
if (input->grab && input->grab_button == 0)
|
|
|
|
return;
|
|
|
|
|
2014-08-19 20:59:51 +00:00
|
|
|
num_syms = xkb_state_key_get_syms(input->xkb.state, code, &syms);
|
2012-08-11 18:56:08 +00:00
|
|
|
|
|
|
|
sym = XKB_KEY_NoSymbol;
|
|
|
|
if (num_syms == 1)
|
|
|
|
sym = syms[0];
|
|
|
|
|
2014-01-11 21:10:21 +00:00
|
|
|
|
2012-08-11 18:56:08 +00:00
|
|
|
if (sym == XKB_KEY_F5 && input->modifiers == MOD_ALT_MASK) {
|
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_PRESSED)
|
2013-11-12 00:16:11 +00:00
|
|
|
window_set_maximized(window, !window->maximized);
|
2012-08-11 18:56:08 +00:00
|
|
|
} else if (sym == XKB_KEY_F11 &&
|
|
|
|
window->fullscreen_handler &&
|
|
|
|
state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
|
|
|
window->fullscreen_handler(window, window->user_data);
|
|
|
|
} else if (sym == XKB_KEY_F4 &&
|
|
|
|
input->modifiers == MOD_ALT_MASK &&
|
|
|
|
state == WL_KEYBOARD_KEY_STATE_PRESSED) {
|
2014-02-01 23:17:34 +00:00
|
|
|
window_close(window);
|
2012-08-11 18:56:08 +00:00
|
|
|
} else if (window->key_handler) {
|
|
|
|
(*window->key_handler)(window, input, time, key,
|
|
|
|
sym, state, window->user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == WL_KEYBOARD_KEY_STATE_RELEASED &&
|
|
|
|
key == input->repeat_key) {
|
|
|
|
its.it_interval.tv_sec = 0;
|
|
|
|
its.it_interval.tv_nsec = 0;
|
|
|
|
its.it_value.tv_sec = 0;
|
|
|
|
its.it_value.tv_nsec = 0;
|
|
|
|
timerfd_settime(input->repeat_timer_fd, 0, &its, NULL);
|
2014-02-05 21:43:44 +00:00
|
|
|
} else if (state == WL_KEYBOARD_KEY_STATE_PRESSED &&
|
|
|
|
xkb_keymap_key_repeats(input->xkb.keymap, code)) {
|
2012-08-11 18:56:08 +00:00
|
|
|
input->repeat_sym = sym;
|
|
|
|
input->repeat_key = key;
|
|
|
|
input->repeat_time = time;
|
2014-08-12 12:58:27 +00:00
|
|
|
its.it_interval.tv_sec = input->repeat_rate_sec;
|
|
|
|
its.it_interval.tv_nsec = input->repeat_rate_nsec;
|
|
|
|
its.it_value.tv_sec = input->repeat_delay_sec;
|
|
|
|
its.it_value.tv_nsec = input->repeat_delay_nsec;
|
2012-08-11 18:56:08 +00:00
|
|
|
timerfd_settime(input->repeat_timer_fd, 0, &its, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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-09-27 16:40:45 +00:00
|
|
|
xkb_mod_mask_t mask;
|
2012-08-11 18:56:08 +00:00
|
|
|
|
2013-06-24 15:52:43 +00:00
|
|
|
/* If we're not using a keymap, then we don't handle PC-style modifiers */
|
|
|
|
if (!input->xkb.keymap)
|
|
|
|
return;
|
|
|
|
|
2012-08-11 18:56:08 +00:00
|
|
|
xkb_state_update_mask(input->xkb.state, mods_depressed, mods_latched,
|
|
|
|
mods_locked, 0, 0, group);
|
2012-09-27 16:40:45 +00:00
|
|
|
mask = xkb_state_serialize_mods(input->xkb.state,
|
2014-08-19 20:59:51 +00:00
|
|
|
XKB_STATE_MODS_DEPRESSED |
|
|
|
|
XKB_STATE_MODS_LATCHED);
|
2012-09-27 16:40:45 +00:00
|
|
|
input->modifiers = 0;
|
|
|
|
if (mask & input->xkb.control_mask)
|
|
|
|
input->modifiers |= MOD_CONTROL_MASK;
|
|
|
|
if (mask & input->xkb.alt_mask)
|
|
|
|
input->modifiers |= MOD_ALT_MASK;
|
|
|
|
if (mask & input->xkb.shift_mask)
|
|
|
|
input->modifiers |= MOD_SHIFT_MASK;
|
2012-08-11 18:56:08 +00:00
|
|
|
}
|
2011-12-21 22:14:54 +00:00
|
|
|
|
2014-08-12 12:58:27 +00:00
|
|
|
static void
|
|
|
|
set_repeat_info(struct input *input, int32_t rate, int32_t delay)
|
|
|
|
{
|
|
|
|
input->repeat_rate_sec = input->repeat_rate_nsec = 0;
|
|
|
|
input->repeat_delay_sec = input->repeat_delay_nsec = 0;
|
|
|
|
|
|
|
|
/* a rate of zero disables any repeating, regardless of the delay's
|
|
|
|
* value */
|
|
|
|
if (rate == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (rate == 1)
|
|
|
|
input->repeat_rate_sec = 1;
|
|
|
|
else
|
|
|
|
input->repeat_rate_nsec = 1000000000 / rate;
|
|
|
|
|
|
|
|
input->repeat_delay_sec = delay / 1000;
|
|
|
|
delay -= (input->repeat_delay_sec * 1000);
|
|
|
|
input->repeat_delay_nsec = delay * 1000 * 1000;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
keyboard_handle_repeat_info(void *data, struct wl_keyboard *keyboard,
|
|
|
|
int32_t rate, int32_t delay)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
|
|
|
|
set_repeat_info(input, rate, delay);
|
|
|
|
}
|
|
|
|
|
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,
|
2014-08-12 12:58:27 +00:00
|
|
|
keyboard_handle_repeat_info
|
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
};
|
2011-12-21 22:14:54 +00:00
|
|
|
|
2013-08-09 04:20:38 +00:00
|
|
|
static void
|
|
|
|
touch_handle_down(void *data, struct wl_touch *wl_touch,
|
|
|
|
uint32_t serial, uint32_t time, struct wl_surface *surface,
|
|
|
|
int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct widget *widget;
|
|
|
|
float sx = wl_fixed_to_double(x_w);
|
|
|
|
float sy = wl_fixed_to_double(y_w);
|
|
|
|
|
2013-08-15 16:10:08 +00:00
|
|
|
input->display->serial = serial;
|
2013-08-09 04:20:38 +00:00
|
|
|
input->touch_focus = wl_surface_get_user_data(surface);
|
|
|
|
if (!input->touch_focus) {
|
|
|
|
DBG("Failed to find to touch focus for surface %p\n", surface);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-05-06 12:25:40 +00:00
|
|
|
if (surface != input->touch_focus->main_surface->surface) {
|
|
|
|
DBG("Ignoring input event from subsurface %p\n", surface);
|
|
|
|
input->touch_focus = NULL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-29 21:30:44 +00:00
|
|
|
if (input->grab)
|
|
|
|
widget = input->grab;
|
|
|
|
else
|
|
|
|
widget = window_find_widget(input->touch_focus,
|
|
|
|
wl_fixed_to_double(x_w),
|
|
|
|
wl_fixed_to_double(y_w));
|
2013-08-09 04:20:38 +00:00
|
|
|
if (widget) {
|
|
|
|
struct touch_point *tp = xmalloc(sizeof *tp);
|
|
|
|
if (tp) {
|
|
|
|
tp->id = id;
|
|
|
|
tp->widget = widget;
|
2014-01-07 20:57:59 +00:00
|
|
|
tp->x = sx;
|
|
|
|
tp->y = sy;
|
2013-08-09 04:20:38 +00:00
|
|
|
wl_list_insert(&input->touch_point_list, &tp->link);
|
|
|
|
|
|
|
|
if (widget->touch_down_handler)
|
2014-11-27 04:24:52 +00:00
|
|
|
(*widget->touch_down_handler)(widget, input,
|
2013-08-15 16:10:08 +00:00
|
|
|
serial, time, id,
|
2013-08-09 04:20:38 +00:00
|
|
|
sx, sy,
|
|
|
|
widget->user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_handle_up(void *data, struct wl_touch *wl_touch,
|
|
|
|
uint32_t serial, uint32_t time, int32_t id)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct touch_point *tp, *tmp;
|
|
|
|
|
|
|
|
if (!input->touch_focus) {
|
|
|
|
DBG("No touch focus found for touch up event!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each_safe(tp, tmp, &input->touch_point_list, link) {
|
|
|
|
if (tp->id != id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (tp->widget->touch_up_handler)
|
2013-08-15 16:10:08 +00:00
|
|
|
(*tp->widget->touch_up_handler)(tp->widget, input, serial,
|
2013-08-09 04:20:38 +00:00
|
|
|
time, id,
|
|
|
|
tp->widget->user_data);
|
|
|
|
|
|
|
|
wl_list_remove(&tp->link);
|
|
|
|
free(tp);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_handle_motion(void *data, struct wl_touch *wl_touch,
|
|
|
|
uint32_t time, int32_t id, wl_fixed_t x_w, wl_fixed_t y_w)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct touch_point *tp;
|
|
|
|
float sx = wl_fixed_to_double(x_w);
|
|
|
|
float sy = wl_fixed_to_double(y_w);
|
|
|
|
|
|
|
|
DBG("touch_handle_motion: %i %i\n", id, wl_list_length(&input->touch_point_list));
|
|
|
|
|
|
|
|
if (!input->touch_focus) {
|
|
|
|
DBG("No touch focus found for touch motion event!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each(tp, &input->touch_point_list, link) {
|
|
|
|
if (tp->id != id)
|
|
|
|
continue;
|
|
|
|
|
2014-01-07 20:57:59 +00:00
|
|
|
tp->x = sx;
|
|
|
|
tp->y = sy;
|
2013-08-09 04:20:38 +00:00
|
|
|
if (tp->widget->touch_motion_handler)
|
2013-08-15 16:10:08 +00:00
|
|
|
(*tp->widget->touch_motion_handler)(tp->widget, input, time,
|
2013-08-09 04:20:38 +00:00
|
|
|
id, sx, sy,
|
|
|
|
tp->widget->user_data);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_handle_frame(void *data, struct wl_touch *wl_touch)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct touch_point *tp, *tmp;
|
|
|
|
|
|
|
|
DBG("touch_handle_frame\n");
|
|
|
|
|
|
|
|
if (!input->touch_focus) {
|
|
|
|
DBG("No touch focus found for touch frame event!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each_safe(tp, tmp, &input->touch_point_list, link) {
|
|
|
|
if (tp->widget->touch_frame_handler)
|
2015-05-15 15:17:47 +00:00
|
|
|
(*tp->widget->touch_frame_handler)(tp->widget, input,
|
2013-08-15 16:10:08 +00:00
|
|
|
tp->widget->user_data);
|
2013-08-09 04:20:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
touch_handle_cancel(void *data, struct wl_touch *wl_touch)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
|
|
|
struct touch_point *tp, *tmp;
|
|
|
|
|
|
|
|
DBG("touch_handle_cancel\n");
|
|
|
|
|
|
|
|
if (!input->touch_focus) {
|
|
|
|
DBG("No touch focus found for touch cancel event!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each_safe(tp, tmp, &input->touch_point_list, link) {
|
|
|
|
if (tp->widget->touch_cancel_handler)
|
2013-08-15 16:10:08 +00:00
|
|
|
(*tp->widget->touch_cancel_handler)(tp->widget, input,
|
|
|
|
tp->widget->user_data);
|
2013-08-09 04:20:38 +00:00
|
|
|
|
|
|
|
wl_list_remove(&tp->link);
|
|
|
|
free(tp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_touch_listener touch_listener = {
|
|
|
|
touch_handle_down,
|
|
|
|
touch_handle_up,
|
|
|
|
touch_handle_motion,
|
|
|
|
touch_handle_frame,
|
|
|
|
touch_handle_cancel,
|
|
|
|
};
|
|
|
|
|
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) {
|
2015-10-14 14:39:59 +00:00
|
|
|
if (input->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION)
|
2015-10-09 16:17:43 +00:00
|
|
|
wl_pointer_release(input->pointer);
|
|
|
|
else
|
|
|
|
wl_pointer_destroy(input->pointer);
|
2012-05-16 17:45:18 +00:00
|
|
|
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) {
|
2015-10-14 14:39:59 +00:00
|
|
|
if (input->seat_version >= WL_KEYBOARD_RELEASE_SINCE_VERSION)
|
2015-10-09 16:17:43 +00:00
|
|
|
wl_keyboard_release(input->keyboard);
|
|
|
|
else
|
|
|
|
wl_keyboard_destroy(input->keyboard);
|
2012-05-16 17:45:18 +00:00
|
|
|
input->keyboard = NULL;
|
|
|
|
}
|
2013-08-09 04:20:38 +00:00
|
|
|
|
|
|
|
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !input->touch) {
|
|
|
|
input->touch = wl_seat_get_touch(seat);
|
|
|
|
wl_touch_set_user_data(input->touch, input);
|
|
|
|
wl_touch_add_listener(input->touch, &touch_listener, input);
|
|
|
|
} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && input->touch) {
|
2015-10-14 14:39:59 +00:00
|
|
|
if (input->seat_version >= WL_TOUCH_RELEASE_SINCE_VERSION)
|
2015-10-09 16:17:43 +00:00
|
|
|
wl_touch_release(input->touch);
|
|
|
|
else
|
|
|
|
wl_touch_destroy(input->touch);
|
2013-08-09 04:20:38 +00:00
|
|
|
input->touch = NULL;
|
|
|
|
}
|
2011-12-21 22:14:54 +00:00
|
|
|
}
|
|
|
|
|
2013-08-13 19:11:03 +00:00
|
|
|
static void
|
|
|
|
seat_handle_name(void *data, struct wl_seat *seat,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-05-16 17:45:18 +00:00
|
|
|
static const struct wl_seat_listener seat_listener = {
|
|
|
|
seat_handle_capabilities,
|
2013-08-13 19:11:03 +00:00
|
|
|
seat_handle_name
|
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;
|
|
|
|
}
|
|
|
|
|
2014-01-07 20:57:59 +00:00
|
|
|
int
|
|
|
|
input_get_touch(struct input *input, int32_t id, float *x, float *y)
|
|
|
|
{
|
|
|
|
struct touch_point *tp;
|
|
|
|
|
|
|
|
wl_list_for_each(tp, &input->touch_point_list, link) {
|
|
|
|
if (tp->id != id)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*x = tp->x;
|
|
|
|
*y = tp->y;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
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,
|
2012-06-29 02:04:06 +00:00
|
|
|
struct wl_data_device *data_device,
|
|
|
|
struct wl_data_offer *_offer)
|
2011-10-28 16:26:06 +00:00
|
|
|
{
|
|
|
|
struct data_offer *offer;
|
|
|
|
|
2013-08-07 22:34:59 +00:00
|
|
|
offer = xmalloc(sizeof *offer);
|
2011-10-28 16:26:06 +00:00
|
|
|
|
|
|
|
wl_array_init(&offer->types);
|
|
|
|
offer->refcount = 1;
|
|
|
|
offer->input = data;
|
2012-06-29 02:04:06 +00:00
|
|
|
offer->offer = _offer;
|
2011-10-28 16:26:06 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
window = wl_surface_get_user_data(surface);
|
2013-11-25 10:42:51 +00:00
|
|
|
input->drag_enter_serial = serial;
|
|
|
|
input->drag_focus = window,
|
|
|
|
input->drag_x = x;
|
|
|
|
input->drag_y = y;
|
|
|
|
|
|
|
|
if (!input->touch_grab)
|
|
|
|
input->pointer_enter_serial = serial;
|
2011-10-28 16:26:06 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
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;
|
2013-11-25 10:42:51 +00:00
|
|
|
struct window *window = input->drag_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
|
|
|
|
2013-11-25 10:42:51 +00:00
|
|
|
input->drag_x = x;
|
|
|
|
input->drag_y = y;
|
2011-10-28 16:26:06 +00:00
|
|
|
|
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;
|
2013-11-25 10:42:51 +00:00
|
|
|
struct window *window = input->drag_focus;
|
|
|
|
float x, y;
|
|
|
|
|
|
|
|
x = input->drag_x;
|
|
|
|
y = input->drag_y;
|
2011-10-28 16:26:06 +00:00
|
|
|
|
|
|
|
if (window->drop_handler)
|
|
|
|
window->drop_handler(window, input,
|
2013-11-25 10:42:51 +00:00
|
|
|
x, y, window->user_data);
|
|
|
|
|
|
|
|
if (input->touch_grab)
|
|
|
|
touch_ungrab(input);
|
2011-10-28 16:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-06-15 14:27:36 +00:00
|
|
|
static void
|
|
|
|
input_set_pointer_image_index(struct input *input, 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-11-07 06:51:39 +00:00
|
|
|
if (!input->pointer)
|
|
|
|
return;
|
|
|
|
|
2012-06-15 14:27:36 +00:00
|
|
|
cursor = input->display->cursors[input->current_cursor];
|
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-06-15 14:27:35 +00:00
|
|
|
wl_surface_attach(input->pointer_surface, buffer, 0, 0);
|
|
|
|
wl_surface_damage(input->pointer_surface, 0, 0,
|
|
|
|
image->width, image->height);
|
2012-10-10 09:49:24 +00:00
|
|
|
wl_surface_commit(input->pointer_surface);
|
2014-01-31 14:07:51 +00:00
|
|
|
wl_pointer_set_cursor(input->pointer, input->pointer_enter_serial,
|
|
|
|
input->pointer_surface,
|
|
|
|
image->hotspot_x, image->hotspot_y);
|
2012-01-11 03:41:05 +00:00
|
|
|
}
|
|
|
|
|
2012-06-15 14:27:36 +00:00
|
|
|
static const struct wl_callback_listener pointer_surface_listener;
|
|
|
|
|
2015-03-04 22:26:25 +00:00
|
|
|
static bool
|
|
|
|
input_set_pointer_special(struct input *input)
|
|
|
|
{
|
|
|
|
if (input->current_cursor == CURSOR_BLANK) {
|
|
|
|
wl_pointer_set_cursor(input->pointer,
|
|
|
|
input->pointer_enter_serial,
|
|
|
|
NULL, 0, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input->current_cursor == CURSOR_UNSET)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-22 22:23:35 +00:00
|
|
|
static void
|
|
|
|
schedule_pointer_image_update(struct input *input,
|
|
|
|
struct wl_cursor *cursor,
|
|
|
|
uint32_t duration,
|
|
|
|
bool force_frame)
|
|
|
|
{
|
|
|
|
/* Some silly cursor sets have enormous pauses in them. In these
|
|
|
|
* cases it's better to use a timer even if it results in less
|
|
|
|
* accurate presentation, since it will save us having to set the
|
|
|
|
* same cursor image over and over again.
|
|
|
|
*
|
|
|
|
* This is really not the way we're supposed to time any kind of
|
|
|
|
* animation, but we're pretending it's OK here because we don't
|
|
|
|
* want animated cursors with long delays to needlessly hog CPU.
|
|
|
|
*
|
|
|
|
* We use force_frame to ensure we don't accumulate large timing
|
|
|
|
* errors by running off the wrong clock.
|
|
|
|
*/
|
|
|
|
if (!force_frame && duration > 100) {
|
|
|
|
struct timespec tp;
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &tp);
|
|
|
|
input->cursor_timer_start = tp.tv_sec * 1000
|
|
|
|
+ tp.tv_nsec / 1000000;
|
|
|
|
cursor_delay_timer_reset(input, duration);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* for short durations we'll just spin on frame callbacks for
|
|
|
|
* accurate timing - the way any kind of timing sensitive animation
|
|
|
|
* should really be done. */
|
|
|
|
input->cursor_frame_cb = wl_surface_frame(input->pointer_surface);
|
|
|
|
wl_callback_add_listener(input->cursor_frame_cb,
|
|
|
|
&pointer_surface_listener, input);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-15 14:27:36 +00:00
|
|
|
static void
|
|
|
|
pointer_surface_frame_callback(void *data, struct wl_callback *callback,
|
|
|
|
uint32_t time)
|
|
|
|
{
|
|
|
|
struct input *input = data;
|
2012-06-18 18:31:12 +00:00
|
|
|
struct wl_cursor *cursor;
|
2012-06-15 14:27:36 +00:00
|
|
|
int i;
|
2015-04-22 22:23:35 +00:00
|
|
|
uint32_t duration;
|
|
|
|
bool force_frame = true;
|
|
|
|
|
|
|
|
cancel_pointer_image_update(input);
|
2012-06-15 14:27:36 +00:00
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
assert(callback == input->cursor_frame_cb);
|
|
|
|
wl_callback_destroy(callback);
|
|
|
|
input->cursor_frame_cb = NULL;
|
2015-04-22 22:23:35 +00:00
|
|
|
force_frame = false;
|
2012-06-15 14:27:36 +00:00
|
|
|
}
|
|
|
|
|
2012-11-07 06:51:39 +00:00
|
|
|
if (!input->pointer)
|
|
|
|
return;
|
|
|
|
|
2015-03-04 22:26:25 +00:00
|
|
|
if (input_set_pointer_special(input))
|
2012-06-21 03:04:41 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-18 18:31:12 +00:00
|
|
|
cursor = input->display->cursors[input->current_cursor];
|
|
|
|
if (!cursor)
|
|
|
|
return;
|
2012-06-15 14:27:36 +00:00
|
|
|
|
|
|
|
/* FIXME We don't have the current time on the first call so we set
|
|
|
|
* the animation start to the time of the first frame callback. */
|
|
|
|
if (time == 0)
|
|
|
|
input->cursor_anim_start = 0;
|
|
|
|
else if (input->cursor_anim_start == 0)
|
|
|
|
input->cursor_anim_start = time;
|
|
|
|
|
2015-04-22 22:23:35 +00:00
|
|
|
input->cursor_anim_current = time;
|
|
|
|
|
|
|
|
if (time == 0 || input->cursor_anim_start == 0) {
|
|
|
|
duration = 0;
|
2012-06-15 14:27:36 +00:00
|
|
|
i = 0;
|
2015-04-22 22:23:35 +00:00
|
|
|
} else
|
|
|
|
i = wl_cursor_frame_and_duration(
|
|
|
|
cursor,
|
|
|
|
time - input->cursor_anim_start,
|
|
|
|
&duration);
|
2012-06-15 14:27:36 +00:00
|
|
|
|
2015-04-22 22:23:35 +00:00
|
|
|
if (cursor->image_count > 1)
|
|
|
|
schedule_pointer_image_update(input, cursor, duration,
|
|
|
|
force_frame);
|
2012-06-15 14:27:36 +00:00
|
|
|
|
2012-10-10 09:49:31 +00:00
|
|
|
input_set_pointer_image_index(input, i);
|
2012-06-15 14:27:36 +00:00
|
|
|
}
|
|
|
|
|
2015-04-22 22:23:35 +00:00
|
|
|
static void
|
|
|
|
cursor_timer_func(struct task *task, uint32_t events)
|
|
|
|
{
|
|
|
|
struct input *input = container_of(task, struct input, cursor_task);
|
|
|
|
struct timespec tp;
|
|
|
|
struct wl_cursor *cursor;
|
|
|
|
uint32_t time;
|
|
|
|
uint64_t exp;
|
|
|
|
|
|
|
|
if (!input->cursor_timer_running)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (read(input->cursor_delay_fd, &exp, sizeof (uint64_t)) != sizeof (uint64_t))
|
|
|
|
return;
|
|
|
|
|
|
|
|
cursor = input->display->cursors[input->current_cursor];
|
|
|
|
if (!cursor)
|
|
|
|
return;
|
|
|
|
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &tp);
|
|
|
|
time = tp.tv_sec * 1000 + tp.tv_nsec / 1000000 - input->cursor_timer_start;
|
|
|
|
pointer_surface_frame_callback(input, NULL, input->cursor_anim_current + time);
|
|
|
|
}
|
|
|
|
|
2012-06-15 14:27:36 +00:00
|
|
|
static const struct wl_callback_listener pointer_surface_listener = {
|
|
|
|
pointer_surface_frame_callback
|
|
|
|
};
|
|
|
|
|
2012-06-05 03:37:42 +00:00
|
|
|
void
|
|
|
|
input_set_pointer_image(struct input *input, int pointer)
|
|
|
|
{
|
2012-07-16 11:15:49 +00:00
|
|
|
int force = 0;
|
|
|
|
|
2012-10-29 20:42:26 +00:00
|
|
|
if (!input->pointer)
|
|
|
|
return;
|
|
|
|
|
2012-07-16 11:15:49 +00:00
|
|
|
if (input->pointer_enter_serial > input->cursor_serial)
|
|
|
|
force = 1;
|
|
|
|
|
|
|
|
if (!force && pointer == input->current_cursor)
|
2012-06-05 03:37:42 +00:00
|
|
|
return;
|
|
|
|
|
2012-06-15 14:27:36 +00:00
|
|
|
input->current_cursor = pointer;
|
2012-06-22 14:52:58 +00:00
|
|
|
input->cursor_serial = input->pointer_enter_serial;
|
2012-06-15 14:27:36 +00:00
|
|
|
if (!input->cursor_frame_cb)
|
|
|
|
pointer_surface_frame_callback(input, NULL, 0);
|
2015-03-04 22:26:25 +00:00
|
|
|
else if (force && !input_set_pointer_special(input)) {
|
2012-07-16 11:15:49 +00:00
|
|
|
/* The current frame callback may be stuck if, for instance,
|
|
|
|
* the set cursor request was processed by the server after
|
|
|
|
* this client lost the focus. In this case the cursor surface
|
|
|
|
* might not be mapped and the frame callback wouldn't ever
|
|
|
|
* complete. Send a set_cursor and attach to try to map the
|
|
|
|
* cursor surface again so that the callback will finish */
|
|
|
|
input_set_pointer_image_index(input, 0);
|
|
|
|
}
|
2012-06-05 03:37:42 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2014-04-03 00:53:51 +00:00
|
|
|
if (input->data_device)
|
|
|
|
wl_data_device_set_selection(input->data_device, source, time);
|
2011-10-28 16:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2013-11-25 10:42:51 +00:00
|
|
|
input->drag_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);
|
2013-11-25 10:42:51 +00:00
|
|
|
input->drag_offer->x = input->drag_x;
|
|
|
|
input->drag_offer->y = input->drag_y;
|
2011-10-28 16:26:06 +00:00
|
|
|
}
|
|
|
|
|
2013-09-05 03:41:06 +00:00
|
|
|
int
|
|
|
|
input_receive_drag_data_to_fd(struct input *input,
|
|
|
|
const char *mime_type, int fd)
|
|
|
|
{
|
|
|
|
if (input->drag_offer)
|
|
|
|
wl_data_offer_receive(input->drag_offer->offer, mime_type, fd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:26:06 +00:00
|
|
|
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
|
|
|
{
|
2013-12-09 19:58:00 +00:00
|
|
|
if (!window->xdg_surface)
|
2011-11-29 08:25:08 +00:00
|
|
|
return;
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
xdg_surface_move(window->xdg_surface, input->seat, serial);
|
2010-08-18 19:28:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
static void
|
|
|
|
surface_set_synchronized(struct surface *surface)
|
|
|
|
{
|
|
|
|
if (!surface->subsurface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (surface->synchronized)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wl_subsurface_set_sync(surface->subsurface);
|
|
|
|
surface->synchronized = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
surface_set_synchronized_default(struct surface *surface)
|
|
|
|
{
|
|
|
|
if (!surface->subsurface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (surface->synchronized == surface->synchronized_default)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (surface->synchronized_default)
|
|
|
|
wl_subsurface_set_sync(surface->subsurface);
|
|
|
|
else
|
|
|
|
wl_subsurface_set_desync(surface->subsurface);
|
|
|
|
|
|
|
|
surface->synchronized = surface->synchronized_default;
|
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:14 +00:00
|
|
|
static void
|
2013-02-13 14:17:18 +00:00
|
|
|
surface_resize(struct surface *surface)
|
2012-01-10 17:23:19 +00:00
|
|
|
{
|
2013-02-13 14:17:18 +00:00
|
|
|
struct widget *widget = surface->widget;
|
|
|
|
struct wl_compositor *compositor = widget->window->display->compositor;
|
2012-01-10 18:52:34 +00:00
|
|
|
|
2013-02-13 14:17:18 +00:00
|
|
|
if (surface->input_region) {
|
|
|
|
wl_region_destroy(surface->input_region);
|
|
|
|
surface->input_region = NULL;
|
2012-02-23 22:30:45 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:18 +00:00
|
|
|
if (surface->opaque_region)
|
|
|
|
wl_region_destroy(surface->opaque_region);
|
2012-11-30 15:34:23 +00:00
|
|
|
|
2013-02-13 14:17:18 +00:00
|
|
|
surface->opaque_region = wl_compositor_create_region(compositor);
|
2012-02-23 22:30:45 +00:00
|
|
|
|
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);
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
if (surface->subsurface &&
|
|
|
|
(surface->allocation.x != widget->allocation.x ||
|
|
|
|
surface->allocation.y != widget->allocation.y)) {
|
|
|
|
wl_subsurface_set_position(surface->subsurface,
|
|
|
|
widget->allocation.x,
|
|
|
|
widget->allocation.y);
|
|
|
|
}
|
2013-02-13 14:17:18 +00:00
|
|
|
if (surface->allocation.width != widget->allocation.width ||
|
|
|
|
surface->allocation.height != widget->allocation.height) {
|
|
|
|
window_schedule_redraw(widget->window);
|
|
|
|
}
|
2013-04-25 10:57:48 +00:00
|
|
|
surface->allocation = widget->allocation;
|
2012-11-30 15:34:23 +00:00
|
|
|
|
|
|
|
if (widget->opaque)
|
2013-02-13 14:17:18 +00:00
|
|
|
wl_region_add(surface->opaque_region, 0, 0,
|
2012-11-30 15:34:23 +00:00
|
|
|
widget->allocation.width,
|
|
|
|
widget->allocation.height);
|
2012-01-10 17:23:19 +00:00
|
|
|
}
|
|
|
|
|
2013-02-13 14:17:18 +00:00
|
|
|
static void
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
window_do_resize(struct window *window)
|
2013-02-13 14:17:18 +00:00
|
|
|
{
|
2013-04-25 10:57:48 +00:00
|
|
|
struct surface *surface;
|
|
|
|
|
2013-02-13 14:17:18 +00:00
|
|
|
widget_set_allocation(window->main_surface->widget,
|
|
|
|
window->pending_allocation.x,
|
|
|
|
window->pending_allocation.y,
|
|
|
|
window->pending_allocation.width,
|
|
|
|
window->pending_allocation.height);
|
|
|
|
|
|
|
|
surface_resize(window->main_surface);
|
2013-04-25 10:57:48 +00:00
|
|
|
|
|
|
|
/* The main surface is in the list, too. Main surface's
|
|
|
|
* resize_handler is responsible for calling widget_set_allocation()
|
|
|
|
* on all sub-surface root widgets, so they will be resized
|
|
|
|
* properly.
|
|
|
|
*/
|
|
|
|
wl_list_for_each(surface, &window->subsurface_list, link) {
|
|
|
|
if (surface == window->main_surface)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
surface_set_synchronized(surface);
|
|
|
|
surface_resize(surface);
|
|
|
|
}
|
2014-02-08 23:29:49 +00:00
|
|
|
|
|
|
|
if (!window->fullscreen && !window->maximized)
|
|
|
|
window->saved_allocation = window->pending_allocation;
|
2013-02-13 14:17:18 +00:00
|
|
|
}
|
|
|
|
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
static void
|
|
|
|
idle_resize(struct window *window)
|
|
|
|
{
|
|
|
|
window->resize_needed = 0;
|
|
|
|
window->redraw_needed = 1;
|
|
|
|
|
|
|
|
DBG("from %dx%d to %dx%d\n",
|
|
|
|
window->main_surface->server_allocation.width,
|
|
|
|
window->main_surface->server_allocation.height,
|
|
|
|
window->pending_allocation.width,
|
|
|
|
window->pending_allocation.height);
|
|
|
|
|
|
|
|
window_do_resize(window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
undo_resize(struct window *window)
|
|
|
|
{
|
|
|
|
window->pending_allocation.width =
|
|
|
|
window->main_surface->server_allocation.width;
|
|
|
|
window->pending_allocation.height =
|
|
|
|
window->main_surface->server_allocation.height;
|
|
|
|
|
|
|
|
DBG("back to %dx%d\n",
|
|
|
|
window->main_surface->server_allocation.width,
|
|
|
|
window->main_surface->server_allocation.height);
|
|
|
|
|
|
|
|
window_do_resize(window);
|
|
|
|
|
|
|
|
if (window->pending_allocation.width == 0 &&
|
|
|
|
window->pending_allocation.height == 0) {
|
|
|
|
fprintf(stderr, "Error: Could not draw a surface, "
|
|
|
|
"most likely due to insufficient disk space in "
|
|
|
|
"%s (XDG_RUNTIME_DIR).\n", getenv("XDG_RUNTIME_DIR"));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-10 17:23:19 +00:00
|
|
|
void
|
|
|
|
window_schedule_resize(struct window *window, int width, int height)
|
|
|
|
{
|
2013-10-21 22:05:49 +00:00
|
|
|
/* We should probably get these numbers from the theme. */
|
|
|
|
const int min_width = 200, min_height = 200;
|
|
|
|
|
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;
|
|
|
|
|
2013-10-21 22:05:49 +00:00
|
|
|
if (window->min_allocation.width == 0) {
|
2013-10-21 22:23:17 +00:00
|
|
|
if (width < min_width && window->frame)
|
2013-10-21 22:05:49 +00:00
|
|
|
window->min_allocation.width = min_width;
|
|
|
|
else
|
|
|
|
window->min_allocation.width = width;
|
2013-10-21 22:23:17 +00:00
|
|
|
if (height < min_height && window->frame)
|
2013-10-21 22:05:49 +00:00
|
|
|
window->min_allocation.height = min_height;
|
|
|
|
else
|
2013-10-21 22:23:17 +00:00
|
|
|
window->min_allocation.height = height;
|
2013-10-21 22:05:49 +00:00
|
|
|
}
|
|
|
|
|
2012-07-20 15:32:51 +00:00
|
|
|
if (window->pending_allocation.width < window->min_allocation.width)
|
|
|
|
window->pending_allocation.width = window->min_allocation.width;
|
|
|
|
if (window->pending_allocation.height < window->min_allocation.height)
|
|
|
|
window->pending_allocation.height = window->min_allocation.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
|
|
|
}
|
|
|
|
|
2014-07-14 20:28:48 +00:00
|
|
|
static int
|
|
|
|
window_get_shadow_margin(struct window *window)
|
|
|
|
{
|
2014-08-04 17:43:25 +00:00
|
|
|
if (window->frame && !window->fullscreen)
|
2014-07-14 20:28:48 +00:00
|
|
|
return frame_get_shadow_margin(window->frame->frame);
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-05 02:44:55 +00:00
|
|
|
static void
|
2013-12-09 19:58:00 +00:00
|
|
|
handle_surface_configure(void *data, struct xdg_surface *xdg_surface,
|
2014-04-10 17:41:46 +00:00
|
|
|
int32_t width, int32_t height,
|
|
|
|
struct wl_array *states, uint32_t serial)
|
2012-01-19 13:17:59 +00:00
|
|
|
{
|
2013-12-09 19:58:00 +00:00
|
|
|
struct window *window = data;
|
2014-04-10 17:41:46 +00:00
|
|
|
uint32_t *p;
|
2012-01-19 13:17:59 +00:00
|
|
|
|
2014-04-10 17:41:46 +00:00
|
|
|
window->maximized = 0;
|
|
|
|
window->fullscreen = 0;
|
2014-05-06 12:50:47 +00:00
|
|
|
window->resizing = 0;
|
2014-05-06 12:44:29 +00:00
|
|
|
window->focused = 0;
|
2014-04-10 17:41:46 +00:00
|
|
|
|
|
|
|
wl_array_for_each(p, states) {
|
|
|
|
uint32_t state = *p;
|
|
|
|
switch (state) {
|
|
|
|
case XDG_SURFACE_STATE_MAXIMIZED:
|
|
|
|
window->maximized = 1;
|
|
|
|
break;
|
|
|
|
case XDG_SURFACE_STATE_FULLSCREEN:
|
|
|
|
window->fullscreen = 1;
|
|
|
|
break;
|
2014-05-06 12:50:47 +00:00
|
|
|
case XDG_SURFACE_STATE_RESIZING:
|
|
|
|
window->resizing = 1;
|
|
|
|
break;
|
2014-05-06 12:44:29 +00:00
|
|
|
case XDG_SURFACE_STATE_ACTIVATED:
|
|
|
|
window->focused = 1;
|
|
|
|
break;
|
2014-04-10 17:41:46 +00:00
|
|
|
default:
|
|
|
|
/* Unknown state */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 12:20:22 +00:00
|
|
|
if (window->frame) {
|
|
|
|
if (window->maximized) {
|
|
|
|
frame_set_flag(window->frame->frame, FRAME_FLAG_MAXIMIZED);
|
|
|
|
} else {
|
|
|
|
frame_unset_flag(window->frame->frame, FRAME_FLAG_MAXIMIZED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->focused) {
|
|
|
|
frame_set_flag(window->frame->frame, FRAME_FLAG_ACTIVE);
|
|
|
|
} else {
|
|
|
|
frame_unset_flag(window->frame->frame, FRAME_FLAG_ACTIVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-06 12:33:27 +00:00
|
|
|
if (width > 0 && height > 0) {
|
2014-07-14 20:28:48 +00:00
|
|
|
/* The width / height params are for window geometry,
|
|
|
|
* but window_schedule_resize takes allocation. Add
|
|
|
|
* on the shadow margin to get the difference. */
|
|
|
|
int margin = window_get_shadow_margin(window);
|
|
|
|
|
|
|
|
window_schedule_resize(window,
|
|
|
|
width + margin * 2,
|
|
|
|
height + margin * 2);
|
2014-05-06 12:33:27 +00:00
|
|
|
} else {
|
|
|
|
window_schedule_resize(window,
|
|
|
|
window->saved_allocation.width,
|
|
|
|
window->saved_allocation.height);
|
|
|
|
}
|
|
|
|
|
2014-05-13 06:30:28 +00:00
|
|
|
xdg_surface_ack_configure(window->xdg_surface, serial);
|
2014-04-11 00:23:49 +00:00
|
|
|
|
|
|
|
if (window->state_changed_handler)
|
|
|
|
window->state_changed_handler(window, window->user_data);
|
2013-12-09 19:58:00 +00:00
|
|
|
}
|
|
|
|
|
2014-02-01 23:17:34 +00:00
|
|
|
static void
|
|
|
|
handle_surface_delete(void *data, struct xdg_surface *xdg_surface)
|
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
window_close(window);
|
|
|
|
}
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
static const struct xdg_surface_listener xdg_surface_listener = {
|
|
|
|
handle_surface_configure,
|
2014-02-01 23:17:34 +00:00
|
|
|
handle_surface_delete,
|
2010-08-05 02:44:55 +00:00
|
|
|
};
|
|
|
|
|
2013-12-09 20:26:25 +00:00
|
|
|
static void
|
2014-04-11 01:37:54 +00:00
|
|
|
window_sync_parent(struct window *window)
|
2013-12-09 20:26:25 +00:00
|
|
|
{
|
2015-02-13 06:01:55 +00:00
|
|
|
struct xdg_surface *parent_surface;
|
2013-12-09 20:26:25 +00:00
|
|
|
|
|
|
|
if (!window->xdg_surface)
|
|
|
|
return;
|
|
|
|
|
2015-02-13 06:01:55 +00:00
|
|
|
if (window->parent == window->last_parent)
|
|
|
|
return;
|
|
|
|
|
2014-04-11 01:37:54 +00:00
|
|
|
if (window->parent)
|
2015-02-13 06:01:55 +00:00
|
|
|
parent_surface = window->parent->xdg_surface;
|
2013-12-09 20:26:25 +00:00
|
|
|
else
|
|
|
|
parent_surface = NULL;
|
|
|
|
|
2014-04-11 01:37:54 +00:00
|
|
|
xdg_surface_set_parent(window->xdg_surface, parent_surface);
|
2015-02-13 06:01:55 +00:00
|
|
|
window->last_parent = window->parent;
|
2013-12-09 20:26:25 +00:00
|
|
|
}
|
|
|
|
|
2014-02-01 23:36:41 +00:00
|
|
|
static void
|
shell: Replace set_margin with set_window_geometry
Currently, there is a fun flicker when toggling maximization or
fullscreen on a window in mutter or more sophisicated compositors
and WMs.
What happens is that the client want so go maximized, so we
calculate the size that we want the window to resize to (640x480),
and then add on its margins to find the buffer size (+10 = 660x500),
and then send out a configure event for that size. The client
renders to that size, realizes that it's maximized, and then
says "oh hey, my margins are actually 0 now!", and so the compositor
has to send out another configure event.
In order to fix this, make the the configure request correspond to
the window geometry we'd like the window to be at. At the same time,
replace set_margin with set_window_geometry, where we specify a rect
rather than a border around the window.
2014-05-02 14:21:38 +00:00
|
|
|
window_get_geometry(struct window *window, struct rectangle *geometry)
|
2014-02-01 23:36:41 +00:00
|
|
|
{
|
2014-08-04 17:43:25 +00:00
|
|
|
if (window->frame && !window->fullscreen)
|
shell: Replace set_margin with set_window_geometry
Currently, there is a fun flicker when toggling maximization or
fullscreen on a window in mutter or more sophisicated compositors
and WMs.
What happens is that the client want so go maximized, so we
calculate the size that we want the window to resize to (640x480),
and then add on its margins to find the buffer size (+10 = 660x500),
and then send out a configure event for that size. The client
renders to that size, realizes that it's maximized, and then
says "oh hey, my margins are actually 0 now!", and so the compositor
has to send out another configure event.
In order to fix this, make the the configure request correspond to
the window geometry we'd like the window to be at. At the same time,
replace set_margin with set_window_geometry, where we specify a rect
rather than a border around the window.
2014-05-02 14:21:38 +00:00
|
|
|
frame_input_rect(window->frame->frame,
|
|
|
|
&geometry->x,
|
|
|
|
&geometry->y,
|
|
|
|
&geometry->width,
|
|
|
|
&geometry->height);
|
|
|
|
else
|
|
|
|
window_get_allocation(window, geometry);
|
|
|
|
}
|
2014-02-01 23:36:41 +00:00
|
|
|
|
shell: Replace set_margin with set_window_geometry
Currently, there is a fun flicker when toggling maximization or
fullscreen on a window in mutter or more sophisicated compositors
and WMs.
What happens is that the client want so go maximized, so we
calculate the size that we want the window to resize to (640x480),
and then add on its margins to find the buffer size (+10 = 660x500),
and then send out a configure event for that size. The client
renders to that size, realizes that it's maximized, and then
says "oh hey, my margins are actually 0 now!", and so the compositor
has to send out another configure event.
In order to fix this, make the the configure request correspond to
the window geometry we'd like the window to be at. At the same time,
replace set_margin with set_window_geometry, where we specify a rect
rather than a border around the window.
2014-05-02 14:21:38 +00:00
|
|
|
static void
|
|
|
|
window_sync_geometry(struct window *window)
|
|
|
|
{
|
|
|
|
struct rectangle geometry;
|
2014-02-01 23:36:41 +00:00
|
|
|
|
shell: Replace set_margin with set_window_geometry
Currently, there is a fun flicker when toggling maximization or
fullscreen on a window in mutter or more sophisicated compositors
and WMs.
What happens is that the client want so go maximized, so we
calculate the size that we want the window to resize to (640x480),
and then add on its margins to find the buffer size (+10 = 660x500),
and then send out a configure event for that size. The client
renders to that size, realizes that it's maximized, and then
says "oh hey, my margins are actually 0 now!", and so the compositor
has to send out another configure event.
In order to fix this, make the the configure request correspond to
the window geometry we'd like the window to be at. At the same time,
replace set_margin with set_window_geometry, where we specify a rect
rather than a border around the window.
2014-05-02 14:21:38 +00:00
|
|
|
if (!window->xdg_surface)
|
2014-02-01 23:36:41 +00:00
|
|
|
return;
|
|
|
|
|
shell: Replace set_margin with set_window_geometry
Currently, there is a fun flicker when toggling maximization or
fullscreen on a window in mutter or more sophisicated compositors
and WMs.
What happens is that the client want so go maximized, so we
calculate the size that we want the window to resize to (640x480),
and then add on its margins to find the buffer size (+10 = 660x500),
and then send out a configure event for that size. The client
renders to that size, realizes that it's maximized, and then
says "oh hey, my margins are actually 0 now!", and so the compositor
has to send out another configure event.
In order to fix this, make the the configure request correspond to
the window geometry we'd like the window to be at. At the same time,
replace set_margin with set_window_geometry, where we specify a rect
rather than a border around the window.
2014-05-02 14:21:38 +00:00
|
|
|
window_get_geometry(window, &geometry);
|
2014-09-13 14:35:45 +00:00
|
|
|
if (geometry.x == window->last_geometry.x &&
|
|
|
|
geometry.y == window->last_geometry.y &&
|
|
|
|
geometry.width == window->last_geometry.width &&
|
|
|
|
geometry.height == window->last_geometry.height)
|
|
|
|
return;
|
2014-02-01 23:36:41 +00:00
|
|
|
|
shell: Replace set_margin with set_window_geometry
Currently, there is a fun flicker when toggling maximization or
fullscreen on a window in mutter or more sophisicated compositors
and WMs.
What happens is that the client want so go maximized, so we
calculate the size that we want the window to resize to (640x480),
and then add on its margins to find the buffer size (+10 = 660x500),
and then send out a configure event for that size. The client
renders to that size, realizes that it's maximized, and then
says "oh hey, my margins are actually 0 now!", and so the compositor
has to send out another configure event.
In order to fix this, make the the configure request correspond to
the window geometry we'd like the window to be at. At the same time,
replace set_margin with set_window_geometry, where we specify a rect
rather than a border around the window.
2014-05-02 14:21:38 +00:00
|
|
|
xdg_surface_set_window_geometry(window->xdg_surface,
|
|
|
|
geometry.x,
|
|
|
|
geometry.y,
|
|
|
|
geometry.width,
|
|
|
|
geometry.height);
|
2014-09-13 14:35:45 +00:00
|
|
|
window->last_geometry = geometry;
|
2014-02-01 23:36:41 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
static void
|
|
|
|
window_flush(struct window *window)
|
|
|
|
{
|
|
|
|
struct surface *surface;
|
|
|
|
|
|
|
|
if (!window->custom) {
|
2014-04-07 18:28:05 +00:00
|
|
|
if (window->xdg_surface) {
|
2014-04-11 01:37:54 +00:00
|
|
|
window_sync_parent(window);
|
shell: Replace set_margin with set_window_geometry
Currently, there is a fun flicker when toggling maximization or
fullscreen on a window in mutter or more sophisicated compositors
and WMs.
What happens is that the client want so go maximized, so we
calculate the size that we want the window to resize to (640x480),
and then add on its margins to find the buffer size (+10 = 660x500),
and then send out a configure event for that size. The client
renders to that size, realizes that it's maximized, and then
says "oh hey, my margins are actually 0 now!", and so the compositor
has to send out another configure event.
In order to fix this, make the the configure request correspond to
the window geometry we'd like the window to be at. At the same time,
replace set_margin with set_window_geometry, where we specify a rect
rather than a border around the window.
2014-05-02 14:21:38 +00:00
|
|
|
window_sync_geometry(window);
|
2013-12-09 19:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wl_list_for_each(surface, &window->subsurface_list, link) {
|
|
|
|
if (surface == window->main_surface)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
surface_flush(surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_flush(window->main_surface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
menu_destroy(struct menu *menu)
|
|
|
|
{
|
|
|
|
widget_destroy(menu->widget);
|
|
|
|
window_destroy(menu->window);
|
|
|
|
frame_destroy(menu->frame);
|
|
|
|
free(menu);
|
|
|
|
}
|
|
|
|
|
2011-02-18 22:00:55 +00:00
|
|
|
void
|
|
|
|
window_get_allocation(struct window *window,
|
|
|
|
struct rectangle *allocation)
|
|
|
|
{
|
2013-02-13 14:17:14 +00:00
|
|
|
*allocation = window->main_surface->allocation;
|
2011-02-18 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
struct surface *surface = data;
|
2012-03-24 18:42:09 +00:00
|
|
|
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
assert(callback == surface->frame_cb);
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(callback, "done\n");
|
2012-03-24 18:42:09 +00:00
|
|
|
wl_callback_destroy(callback);
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
surface->frame_cb = NULL;
|
|
|
|
|
clients: add subsurfaces demo
Add a demo program with:
- a main surface (green)
- a Cairo-image sub-surface (red)
- a raw GLESv2 widget (triangle)
Sub-surface input region is set empty to avoid problems in toytoolkit.
If Cairo links to libGL, then we will end up with also libGLESv2 linked
to subsurfaces program, and both libs getting really used, which leads
to disaster.
Do not build subsurfaces demo, if Cairo links to libGL and cairo-egl is
usable.
The GL rendering loop is not tied to the toytoolkit or the widget, but
runs directly from its own frame callback. Therefore it runs
independent of the rest of the application. This also relies on one of
two things:
- eglSwapInterval(0) is implemented, and therefore eglSwapBuffers never
blocks indefinitely, or
- toytoolkit has a workaround, that guarantees that eglSwapBuffers will
return soon, when we force a repaint on resize.
Otherwise the demo will deadlock.
The code is separated into three sections:
1. The library component, using only EGL, GLESv2, and libwayland-client
APIs, and not aware of any toolkit details of the parent application.
This runs independently until the parent application tells otherwise.
2. The glue code: a toytoolkit application widget, who has its own
rendering machinery.
3. The application written in toytoolkit.
This patch also adds new toytoolkit interfaces:
- widget_get_wl_surface()
- widget_get_last_time()
- widget_input_region_add()
Toytoolkit applications have not had a possibility to change the input
region. The frame widget (decorations) set the input region on its own
when used, otherwise the default input region of everything has been
used. If a window does not have a frame widget, it can now use
widget_input_region_add() to set a custom input region.
These are not window methods, because a widget may lie on a different
wl_surface (sub-surface) than the window.
Changes in v3:
- replace set_commit_mode with set_sync and set_desync
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:50 +00:00
|
|
|
surface->last_time = time;
|
|
|
|
|
2013-04-25 10:57:53 +00:00
|
|
|
if (surface->redraw_needed || surface->window->redraw_needed) {
|
|
|
|
DBG_OBJ(surface->surface, "window_schedule_redraw_task\n");
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
window_schedule_redraw_task(surface->window);
|
2013-04-25 10:57:53 +00:00
|
|
|
}
|
2012-03-24 18:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_callback_listener listener = {
|
|
|
|
frame_callback
|
|
|
|
};
|
|
|
|
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
static int
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
surface_redraw(struct surface *surface)
|
|
|
|
{
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(surface->surface, "begin\n");
|
|
|
|
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
if (!surface->window->redraw_needed && !surface->redraw_needed)
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
return 0;
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
|
|
|
|
/* Whole-window redraw forces a redraw even if the previous has
|
|
|
|
* not yet hit the screen.
|
|
|
|
*/
|
|
|
|
if (surface->frame_cb) {
|
|
|
|
if (!surface->window->redraw_needed)
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
return 0;
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(surface->frame_cb, "cancelled\n");
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
wl_callback_destroy(surface->frame_cb);
|
|
|
|
}
|
|
|
|
|
2013-12-19 16:17:12 +00:00
|
|
|
if (surface->widget->use_cairo &&
|
|
|
|
!widget_get_cairo_surface(surface->widget)) {
|
2015-11-20 19:57:43 +00:00
|
|
|
DBG_OBJ(surface->surface, "cancelled due to buffer failure\n");
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
surface->frame_cb = wl_surface_frame(surface->surface);
|
|
|
|
wl_callback_add_listener(surface->frame_cb, &listener, surface);
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(surface->frame_cb, "new\n");
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
|
|
|
|
surface->redraw_needed = 0;
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(surface->surface, "-> widget_redraw\n");
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
widget_redraw(surface->widget);
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(surface->surface, "done\n");
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
return 0;
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
}
|
|
|
|
|
2011-09-14 21:33:48 +00:00
|
|
|
static void
|
|
|
|
idle_redraw(struct task *task, uint32_t events)
|
2010-06-15 03:52:50 +00:00
|
|
|
{
|
2012-03-26 17:49:29 +00:00
|
|
|
struct window *window = container_of(task, struct window, redraw_task);
|
2013-04-25 10:57:48 +00:00
|
|
|
struct surface *surface;
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
int failed = 0;
|
|
|
|
int resized = 0;
|
2010-06-15 03:52:50 +00:00
|
|
|
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG(" --------- \n");
|
|
|
|
|
2013-04-25 10:57:52 +00:00
|
|
|
wl_list_init(&window->redraw_task.link);
|
|
|
|
window->redraw_task_scheduled = 0;
|
|
|
|
|
|
|
|
if (window->resize_needed) {
|
|
|
|
/* throttle resizing to the main surface display */
|
2013-04-25 10:57:53 +00:00
|
|
|
if (window->main_surface->frame_cb) {
|
|
|
|
DBG_OBJ(window->main_surface->frame_cb, "pending\n");
|
2013-04-25 10:57:52 +00:00
|
|
|
return;
|
2013-04-25 10:57:53 +00:00
|
|
|
}
|
2013-04-25 10:57:52 +00:00
|
|
|
|
2012-03-26 17:49:29 +00:00
|
|
|
idle_resize(window);
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
resized = 1;
|
2013-04-25 10:57:52 +00:00
|
|
|
}
|
2012-03-26 17:49:29 +00:00
|
|
|
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
if (surface_redraw(window->main_surface) < 0) {
|
|
|
|
/*
|
|
|
|
* Only main_surface failure will cause us to undo the resize.
|
|
|
|
* If sub-surfaces fail, they will just be broken with old
|
|
|
|
* content.
|
|
|
|
*/
|
|
|
|
failed = 1;
|
|
|
|
} else {
|
|
|
|
wl_list_for_each(surface, &window->subsurface_list, link) {
|
|
|
|
if (surface == window->main_surface)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
surface_redraw(surface);
|
|
|
|
}
|
|
|
|
}
|
2013-04-25 10:57:48 +00:00
|
|
|
|
2012-03-24 18:42:09 +00:00
|
|
|
window->redraw_needed = 0;
|
2012-10-10 09:49:31 +00:00
|
|
|
window_flush(window);
|
2013-04-25 10:57:48 +00:00
|
|
|
|
|
|
|
wl_list_for_each(surface, &window->subsurface_list, link)
|
|
|
|
surface_set_synchronized_default(surface);
|
window: handle insufficient buffer space
It is quite possible for os_create_anonymous_file() to fail when trying
to allocate a new wl_shm buffer. Propagate this failure out from
shm_surface_prepare. Most parts of toytoolkit are already avoiding NULL
cairo surfaces.
If cairo surface allocation fails, do not try to call the widget redraw
functions, those are not prepared to deal with NULL. Also do not
schedule a frame callback, this allows us to retry drawing the next
time.
If redraw fails for the main_surface of a window, restore the widget
geometry to what the compositor currently is showing. This keeps the
window visual appearance in sync with application state, so interacting
with the application does not break too badly.
If the very first draw of any window fails, then forcefully exit the
program. E.g. if weston-desktop-shell fails to allocate buffers for the
unlock dialog, w-d-s exits, and weston unlocks the screen automatically.
This patch allows e.g. weston-terminal to stop from enlarging while
resizing, if new sized buffers can no longer the allocated. Even then,
the application stays usable, as it can often repaint in the last
successful size. It does not crash, and the user is able to resize it
smaller, too.
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2013-11-29 15:48:52 +00:00
|
|
|
|
|
|
|
if (resized && failed) {
|
|
|
|
/* Restore widget tree to correspond to what is on screen. */
|
|
|
|
undo_resize(window);
|
|
|
|
}
|
2010-06-15 03:52:50 +00:00
|
|
|
}
|
|
|
|
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
static void
|
|
|
|
window_schedule_redraw_task(struct window *window)
|
2010-06-15 03:52:50 +00:00
|
|
|
{
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
if (!window->redraw_task_scheduled) {
|
2011-09-14 21:33:48 +00:00
|
|
|
window->redraw_task.run = idle_redraw;
|
|
|
|
display_defer(window->display, &window->redraw_task);
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
window->redraw_task_scheduled = 1;
|
2010-06-15 03:52:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
void
|
|
|
|
window_schedule_redraw(struct window *window)
|
|
|
|
{
|
|
|
|
struct surface *surface;
|
|
|
|
|
2013-04-25 10:57:53 +00:00
|
|
|
DBG_OBJ(window->main_surface->surface, "window %p\n", window);
|
|
|
|
|
window: implement per-surface redraws
Add redraw_needed flag to all surfaces, in addition to having one in
window. The window redraw_needed flag is changed to force a redraw of
the whole window, regardless of frame events.
widget_schedule_redraw() now schedules the redraw only for the surface,
where the widget is on. window_schedule_redraw() is equivalent to
scheduling a redraw for all (sub-)surfaces of the window.
We still use only one deferred task for all redraws.
surface_redraw() will skip the redraw, if the window does not force a
redraw and the surface does not need a redraw. It will also skip the
redraw, if the frame callback from the previous redraw has not triggered
yet. When the frame callback later arrives, the redraw task will be
scheduled, if the surface still needs a redraw.
If the window forces a redraw, the redraw is executed even if there is a
pending frame callback. This is for resizing: resizing should trigger a
window repaint, as it really wants to update all surfaces in one go, to
apply possible sub-surface size and position changes. Resizing is the
only thing that makes a window force a redraw.
With this change, subsurfaces demo can avoid repainting the cairo
sub-surface while still animating the GL sub-surface.
Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
2013-04-25 10:57:49 +00:00
|
|
|
wl_list_for_each(surface, &window->subsurface_list, link)
|
|
|
|
surface->redraw_needed = 1;
|
|
|
|
|
|
|
|
window_schedule_redraw_task(window);
|
|
|
|
}
|
|
|
|
|
2012-10-10 15:36:24 +00:00
|
|
|
int
|
|
|
|
window_is_fullscreen(struct window *window)
|
|
|
|
{
|
2013-11-12 00:16:11 +00:00
|
|
|
return window->fullscreen;
|
2012-10-10 15:36:24 +00:00
|
|
|
}
|
|
|
|
|
2008-12-22 17:14:50 +00:00
|
|
|
void
|
|
|
|
window_set_fullscreen(struct window *window, int fullscreen)
|
|
|
|
{
|
2013-12-09 19:58:00 +00:00
|
|
|
if (!window->xdg_surface)
|
2012-02-17 03:56:12 +00:00
|
|
|
return;
|
2011-01-28 20:18:33 +00:00
|
|
|
|
2013-11-12 00:16:11 +00:00
|
|
|
if (window->fullscreen == fullscreen)
|
2011-01-28 20:18:33 +00:00
|
|
|
return;
|
|
|
|
|
2014-04-10 17:41:46 +00:00
|
|
|
if (fullscreen)
|
|
|
|
xdg_surface_set_fullscreen(window->xdg_surface, NULL);
|
|
|
|
else
|
|
|
|
xdg_surface_unset_fullscreen(window->xdg_surface);
|
2010-06-08 18:08:30 +00:00
|
|
|
}
|
|
|
|
|
2012-10-10 15:36:24 +00:00
|
|
|
int
|
|
|
|
window_is_maximized(struct window *window)
|
|
|
|
{
|
2013-11-12 00:16:11 +00:00
|
|
|
return window->maximized;
|
2012-10-10 15:36:24 +00:00
|
|
|
}
|
|
|
|
|
2012-02-16 20:53:46 +00:00
|
|
|
void
|
|
|
|
window_set_maximized(struct window *window, int maximized)
|
|
|
|
{
|
2013-12-09 19:58:00 +00:00
|
|
|
if (!window->xdg_surface)
|
2012-02-16 20:53:46 +00:00
|
|
|
return;
|
|
|
|
|
2013-11-12 00:16:11 +00:00
|
|
|
if (window->maximized == maximized)
|
2012-02-16 20:53:46 +00:00
|
|
|
return;
|
|
|
|
|
2014-04-10 17:41:46 +00:00
|
|
|
if (maximized)
|
|
|
|
xdg_surface_set_maximized(window->xdg_surface);
|
|
|
|
else
|
|
|
|
xdg_surface_unset_maximized(window->xdg_surface);
|
2012-02-16 20:53:46 +00:00
|
|
|
}
|
|
|
|
|
2014-04-11 00:23:49 +00:00
|
|
|
int
|
|
|
|
window_is_resizing(struct window *window)
|
|
|
|
{
|
|
|
|
return window->resizing;
|
|
|
|
}
|
|
|
|
|
2014-02-19 00:18:42 +00:00
|
|
|
void
|
|
|
|
window_set_minimized(struct window *window)
|
|
|
|
{
|
|
|
|
if (!window->xdg_surface)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xdg_surface_set_minimized(window->xdg_surface);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-24 01:56:31 +00:00
|
|
|
void
|
|
|
|
window_set_fullscreen_handler(struct window *window,
|
|
|
|
window_fullscreen_handler_t handler)
|
|
|
|
{
|
|
|
|
window->fullscreen_handler = handler;
|
|
|
|
}
|
|
|
|
|
2012-11-30 15:34:25 +00:00
|
|
|
void
|
|
|
|
window_set_output_handler(struct window *window,
|
|
|
|
window_output_handler_t handler)
|
|
|
|
{
|
|
|
|
window->output_handler = handler;
|
|
|
|
}
|
|
|
|
|
2014-04-11 00:23:49 +00:00
|
|
|
void
|
|
|
|
window_set_state_changed_handler(struct window *window,
|
|
|
|
window_state_changed_handler_t handler)
|
|
|
|
{
|
|
|
|
window->state_changed_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);
|
2013-10-14 00:08:40 +00:00
|
|
|
if (window->frame) {
|
|
|
|
frame_set_title(window->frame->frame, title);
|
|
|
|
widget_schedule_redraw(window->frame->widget);
|
|
|
|
}
|
2013-12-09 19:58:00 +00:00
|
|
|
if (window->xdg_surface)
|
|
|
|
xdg_surface_set_title(window->xdg_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,
|
2013-02-13 14:17:13 +00:00
|
|
|
window->main_surface->surface,
|
|
|
|
wl_fixed_from_int(x),
|
|
|
|
wl_fixed_from_int(y));
|
2012-05-27 20:25:02 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2013-08-07 22:34:59 +00:00
|
|
|
window_output = xmalloc(sizeof *window_output);
|
2012-05-15 16:55:34 +00:00
|
|
|
window_output->output = output_found;
|
|
|
|
|
|
|
|
wl_list_insert (&window->window_output_list, &window_output->link);
|
2012-11-30 15:34:25 +00:00
|
|
|
|
|
|
|
if (window->output_handler)
|
|
|
|
window->output_handler(window, output_found, 1,
|
|
|
|
window->user_data);
|
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);
|
2012-11-30 15:34:25 +00:00
|
|
|
|
|
|
|
if (window->output_handler)
|
|
|
|
window->output_handler(window, window_output->output,
|
|
|
|
0, window->user_data);
|
|
|
|
|
2012-05-15 16:55:34 +00:00
|
|
|
free(window_output_found);
|
|
|
|
}
|
2012-04-20 02:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_surface_listener surface_listener = {
|
|
|
|
surface_enter,
|
|
|
|
surface_leave
|
|
|
|
};
|
|
|
|
|
2013-02-13 14:17:13 +00:00
|
|
|
static struct surface *
|
|
|
|
surface_create(struct window *window)
|
|
|
|
{
|
|
|
|
struct display *display = window->display;
|
|
|
|
struct surface *surface;
|
|
|
|
|
2015-06-19 23:12:22 +00:00
|
|
|
surface = xzalloc(sizeof *surface);
|
2013-02-13 14:17:13 +00:00
|
|
|
surface->window = window;
|
|
|
|
surface->surface = wl_compositor_create_surface(display->compositor);
|
2013-05-22 12:41:28 +00:00
|
|
|
surface->buffer_scale = 1;
|
2013-02-13 14:17:13 +00:00
|
|
|
wl_surface_add_listener(surface->surface, &surface_listener, window);
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
wl_list_insert(&window->subsurface_list, &surface->link);
|
|
|
|
|
2013-02-13 14:17:13 +00:00
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
2014-04-28 15:19:32 +00:00
|
|
|
static enum window_buffer_type
|
2014-04-28 15:19:31 +00:00
|
|
|
get_preferred_buffer_type(struct display *display)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2014-04-28 15:19:32 +00:00
|
|
|
if (display->argb_device && !getenv("TOYTOOLKIT_NO_EGL"))
|
2014-04-28 15:19:31 +00:00
|
|
|
return WINDOW_BUFFER_TYPE_EGL_WINDOW;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return WINDOW_BUFFER_TYPE_SHM;
|
|
|
|
}
|
|
|
|
|
2011-01-21 23:03:15 +00:00
|
|
|
static struct window *
|
2013-12-09 19:58:00 +00:00
|
|
|
window_create_internal(struct display *display, int custom)
|
2009-01-27 04:42:46 +00:00
|
|
|
{
|
|
|
|
struct window *window;
|
2013-02-13 14:17:15 +00:00
|
|
|
struct surface *surface;
|
2009-01-27 04:42:46 +00:00
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
window = xzalloc(sizeof *window);
|
2013-04-25 10:57:48 +00:00
|
|
|
wl_list_init(&window->subsurface_list);
|
2009-01-27 04:42:46 +00:00
|
|
|
window->display = display;
|
2013-02-13 14:17:15 +00:00
|
|
|
|
|
|
|
surface = surface_create(window);
|
|
|
|
window->main_surface = surface;
|
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
assert(custom || display->xdg_shell || display->ivi_application);
|
2013-02-13 14:17:14 +00:00
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
window->custom = custom;
|
2013-08-06 18:05:54 +00:00
|
|
|
window->preferred_format = WINDOW_PREFERRED_FORMAT_NONE;
|
2012-01-09 15:34:35 +00:00
|
|
|
|
2014-04-28 15:19:31 +00:00
|
|
|
surface->buffer_type = get_preferred_buffer_type(display);
|
2010-10-25 15:40:03 +00:00
|
|
|
|
2013-02-13 14:17:15 +00:00
|
|
|
wl_surface_set_user_data(surface->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
|
|
|
|
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
|
|
|
{
|
2014-04-07 18:28:05 +00:00
|
|
|
struct window *window;
|
2014-11-27 04:24:52 +00:00
|
|
|
uint32_t id_ivisurf;
|
2014-04-07 18:28:05 +00:00
|
|
|
|
|
|
|
window = window_create_internal(display, 0);
|
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
if (window->display->xdg_shell) {
|
|
|
|
window->xdg_surface =
|
|
|
|
xdg_shell_get_xdg_surface(window->display->xdg_shell,
|
|
|
|
window->main_surface->surface);
|
|
|
|
fail_on_null(window->xdg_surface);
|
2014-04-07 18:28:05 +00:00
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
xdg_surface_set_user_data(window->xdg_surface, window);
|
|
|
|
xdg_surface_add_listener(window->xdg_surface,
|
|
|
|
&xdg_surface_listener, window);
|
|
|
|
} else if (display->ivi_application) {
|
|
|
|
/* auto generation of ivi_id based on process id + basement of id */
|
|
|
|
id_ivisurf = IVI_SURFACE_ID + (uint32_t)getpid();
|
|
|
|
window->ivi_surface =
|
|
|
|
ivi_application_surface_create(display->ivi_application,
|
|
|
|
id_ivisurf, window->main_surface->surface);
|
|
|
|
fail_on_null(window->ivi_surface);
|
|
|
|
|
|
|
|
ivi_surface_add_listener(window->ivi_surface,
|
|
|
|
&ivi_surface_listener, window);
|
|
|
|
}
|
2014-04-07 18:28:05 +00:00
|
|
|
|
|
|
|
return window;
|
2012-06-26 20:29:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct window *
|
|
|
|
window_create_custom(struct display *display)
|
|
|
|
{
|
2013-12-09 19:58:00 +00:00
|
|
|
return window_create_internal(display, 1);
|
2011-01-21 23:03:15 +00:00
|
|
|
}
|
|
|
|
|
2013-12-09 20:26:25 +00:00
|
|
|
void
|
2014-04-11 01:37:54 +00:00
|
|
|
window_set_parent(struct window *window,
|
|
|
|
struct window *parent_window)
|
2013-12-09 20:26:25 +00:00
|
|
|
{
|
2014-04-11 01:37:54 +00:00
|
|
|
window->parent = parent_window;
|
|
|
|
window_sync_parent(window);
|
2013-12-09 20:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct window *
|
2014-04-11 01:37:54 +00:00
|
|
|
window_get_parent(struct window *window)
|
2013-12-09 20:26:25 +00:00
|
|
|
{
|
2014-04-11 01:37:54 +00:00
|
|
|
return window->parent;
|
2013-12-09 20:26:25 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2013-10-24 04:49:30 +00:00
|
|
|
int32_t x, y, width, height;
|
2011-12-19 20:40:10 +00:00
|
|
|
int next;
|
|
|
|
|
2013-10-24 04:49:30 +00:00
|
|
|
frame_interior(menu->frame, &x, &y, &width, &height);
|
|
|
|
next = (sy - y) / 20;
|
2011-12-19 20:40:10 +00:00
|
|
|
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-10-30 17:45:22 +00:00
|
|
|
if (state == WL_POINTER_BUTTON_STATE_RELEASED &&
|
|
|
|
(menu->release_count > 0 || time - menu->time > 500)) {
|
2012-01-11 04:46:33 +00:00
|
|
|
/* Either relase after press-drag-release or
|
|
|
|
* click-motion-click. */
|
2014-03-13 16:06:00 +00:00
|
|
|
menu->func(menu->user_data, input, menu->current);
|
2015-09-11 19:28:15 +00:00
|
|
|
input_ungrab(menu->input);
|
2012-01-19 13:17:59 +00:00
|
|
|
menu_destroy(menu);
|
2012-10-30 22:10:30 +00:00
|
|
|
} else if (state == WL_POINTER_BUTTON_STATE_RELEASED) {
|
2012-10-30 17:45:22 +00:00
|
|
|
menu->release_count++;
|
2012-10-30 22:10:30 +00:00
|
|
|
}
|
2011-12-19 20:40:10 +00:00
|
|
|
}
|
|
|
|
|
2014-04-29 21:47:19 +00:00
|
|
|
static void
|
|
|
|
menu_touch_up_handler(struct widget *widget,
|
|
|
|
struct input *input,
|
|
|
|
uint32_t serial,
|
|
|
|
uint32_t time,
|
|
|
|
int32_t id,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
struct menu *menu = data;
|
|
|
|
|
|
|
|
input_ungrab(input);
|
|
|
|
menu_destroy(menu);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
struct menu *menu = data;
|
2013-10-24 04:49:30 +00:00
|
|
|
int32_t x, y, width, height, i;
|
2011-12-19 20:40:10 +00:00
|
|
|
|
2013-02-13 14:17:23 +00:00
|
|
|
cr = widget_cairo_create(widget);
|
2011-12-19 20:40:10 +00:00
|
|
|
|
2013-10-24 04:49:30 +00:00
|
|
|
frame_repaint(menu->frame, cr);
|
|
|
|
frame_interior(menu->frame, &x, &y, &width, &height);
|
2012-01-19 18:54:09 +00:00
|
|
|
|
2013-10-24 04:49:30 +00:00
|
|
|
theme_set_background_source(menu->window->display->theme,
|
|
|
|
cr, THEME_FRAME_ACTIVE);
|
|
|
|
cairo_rectangle(cr, x, y, width, height);
|
2011-12-19 20:40:10 +00:00
|
|
|
cairo_fill(cr);
|
|
|
|
|
2013-10-24 04:49:30 +00:00
|
|
|
cairo_select_font_face(cr, "sans",
|
|
|
|
CAIRO_FONT_SLANT_NORMAL,
|
|
|
|
CAIRO_FONT_WEIGHT_NORMAL);
|
|
|
|
cairo_set_font_size(cr, 12);
|
|
|
|
|
2011-12-19 20:40:10 +00:00
|
|
|
for (i = 0; i < menu->count; i++) {
|
|
|
|
if (i == menu->current) {
|
|
|
|
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
|
2013-10-24 04:49:30 +00:00
|
|
|
cairo_rectangle(cr, x, y + i * 20, width, 20);
|
2011-12-19 20:40:10 +00:00
|
|
|
cairo_fill(cr);
|
|
|
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
|
2013-10-24 04:49:30 +00:00
|
|
|
cairo_move_to(cr, x + 10, y + i * 20 + 16);
|
2011-12-19 20:40:10 +00:00
|
|
|
cairo_show_text(cr, menu->entries[i]);
|
|
|
|
} else {
|
2013-10-24 04:49:30 +00:00
|
|
|
cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
|
|
|
|
cairo_move_to(cr, x + 10, y + i * 20 + 16);
|
2011-12-19 20:40:10 +00:00
|
|
|
cairo_show_text(cr, menu->entries[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_destroy(cr);
|
|
|
|
}
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
static void
|
2015-02-13 06:01:56 +00:00
|
|
|
handle_popup_popup_done(void *data, struct xdg_popup *xdg_popup)
|
2013-12-09 19:58:00 +00:00
|
|
|
{
|
|
|
|
struct window *window = data;
|
|
|
|
struct menu *menu = window->main_surface->widget->user_data;
|
|
|
|
|
|
|
|
input_ungrab(menu->input);
|
|
|
|
menu_destroy(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct xdg_popup_listener xdg_popup_listener = {
|
|
|
|
handle_popup_popup_done,
|
|
|
|
};
|
|
|
|
|
2014-03-13 15:57:31 +00:00
|
|
|
static struct menu *
|
|
|
|
create_menu(struct display *display,
|
|
|
|
struct input *input, uint32_t time,
|
|
|
|
menu_func_t func, const char **entries, int count,
|
|
|
|
void *user_data)
|
2011-12-19 20:40:10 +00:00
|
|
|
{
|
|
|
|
struct window *window;
|
|
|
|
struct menu *menu;
|
|
|
|
|
|
|
|
menu = malloc(sizeof *menu);
|
|
|
|
if (!menu)
|
2014-03-13 15:57:31 +00:00
|
|
|
return NULL;
|
2011-12-19 20:40:10 +00:00
|
|
|
|
2014-03-13 15:57:31 +00:00
|
|
|
window = window_create_internal(display, 0);
|
2012-07-08 01:03:40 +00:00
|
|
|
if (!window) {
|
|
|
|
free(menu);
|
2014-03-13 15:57:31 +00:00
|
|
|
return NULL;
|
2012-07-08 01:03:40 +00:00
|
|
|
}
|
2011-12-19 20:40:10 +00:00
|
|
|
|
|
|
|
menu->window = window;
|
2014-03-13 15:57:31 +00:00
|
|
|
menu->user_data = user_data;
|
2012-01-10 14:43:58 +00:00
|
|
|
menu->widget = window_add_widget(menu->window, menu);
|
2013-10-24 04:49:30 +00:00
|
|
|
menu->frame = frame_create(window->display->theme, 0, 0,
|
2013-10-24 05:12:13 +00:00
|
|
|
FRAME_BUTTON_NONE, NULL);
|
2014-01-15 21:38:51 +00:00
|
|
|
fail_on_null(menu->frame);
|
2011-12-19 20:40:10 +00:00
|
|
|
menu->entries = entries;
|
|
|
|
menu->count = count;
|
2012-10-30 17:45:22 +00:00
|
|
|
menu->release_count = 0;
|
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
|
|
|
|
2013-10-29 05:06:11 +00:00
|
|
|
input_ungrab(input);
|
|
|
|
|
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);
|
2014-04-29 21:47:19 +00:00
|
|
|
widget_set_touch_up_handler(menu->widget, menu_touch_up_handler);
|
2012-01-09 14:22:30 +00:00
|
|
|
|
2012-01-11 04:46:33 +00:00
|
|
|
input_grab(input, menu->widget, 0);
|
2013-10-24 04:49:30 +00:00
|
|
|
frame_resize_inside(menu->frame, 200, count * 20);
|
|
|
|
frame_set_flag(menu->frame, FRAME_FLAG_ACTIVE);
|
|
|
|
window_schedule_resize(window, frame_width(menu->frame),
|
|
|
|
frame_height(menu->frame));
|
|
|
|
|
2014-03-13 15:57:31 +00:00
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct window *
|
|
|
|
window_create_menu(struct display *display,
|
|
|
|
struct input *input, uint32_t time,
|
|
|
|
menu_func_t func, const char **entries, int count,
|
|
|
|
void *user_data)
|
|
|
|
{
|
|
|
|
struct menu *menu;
|
|
|
|
menu = create_menu(display, input, time, func, entries, count, user_data);
|
|
|
|
|
|
|
|
if (menu == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return menu->window;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
struct menu *menu;
|
|
|
|
struct window *window;
|
|
|
|
int32_t ix, iy;
|
|
|
|
|
|
|
|
menu = create_menu(display, input, time, func, entries, count, parent);
|
|
|
|
|
|
|
|
if (menu == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window = menu->window;
|
|
|
|
|
|
|
|
window_set_buffer_scale (menu->window, window_get_buffer_scale (parent));
|
|
|
|
window_set_buffer_transform (menu->window, window_get_buffer_transform (parent));
|
|
|
|
|
|
|
|
window->x = x;
|
|
|
|
window->y = y;
|
|
|
|
|
2013-10-24 04:49:30 +00:00
|
|
|
frame_interior(menu->frame, &ix, &iy, NULL, NULL);
|
2013-12-09 19:58:00 +00:00
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
if (!display->xdg_shell)
|
|
|
|
return;
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
window->xdg_popup = xdg_shell_get_xdg_popup(display->xdg_shell,
|
|
|
|
window->main_surface->surface,
|
|
|
|
parent->main_surface->surface,
|
|
|
|
input->seat,
|
|
|
|
display_get_serial(window->display),
|
|
|
|
window->x - ix,
|
2015-02-13 06:01:57 +00:00
|
|
|
window->y - iy);
|
2013-12-09 19:58:00 +00:00
|
|
|
fail_on_null(window->xdg_popup);
|
|
|
|
|
|
|
|
xdg_popup_set_user_data(window->xdg_popup, window);
|
|
|
|
xdg_popup_add_listener(window->xdg_popup,
|
|
|
|
&xdg_popup_listener, window);
|
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)
|
|
|
|
{
|
2013-02-13 14:17:15 +00:00
|
|
|
window->main_surface->buffer_type = type;
|
2010-10-25 15:40:03 +00:00
|
|
|
}
|
|
|
|
|
2014-04-04 08:04:18 +00:00
|
|
|
enum window_buffer_type
|
|
|
|
window_get_buffer_type(struct window *window)
|
|
|
|
{
|
|
|
|
return window->main_surface->buffer_type;
|
|
|
|
}
|
|
|
|
|
2013-08-06 18:05:54 +00:00
|
|
|
void
|
|
|
|
window_set_preferred_format(struct window *window,
|
|
|
|
enum preferred_format format)
|
|
|
|
{
|
|
|
|
window->preferred_format = format;
|
|
|
|
}
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
struct widget *
|
|
|
|
window_add_subsurface(struct window *window, void *data,
|
|
|
|
enum subsurface_mode default_mode)
|
|
|
|
{
|
|
|
|
struct widget *widget;
|
|
|
|
struct surface *surface;
|
|
|
|
struct wl_surface *parent;
|
|
|
|
struct wl_subcompositor *subcompo = window->display->subcompositor;
|
|
|
|
|
|
|
|
surface = surface_create(window);
|
2014-04-04 08:04:18 +00:00
|
|
|
surface->buffer_type = window_get_buffer_type(window);
|
2013-04-25 10:57:48 +00:00
|
|
|
widget = widget_create(window, surface, data);
|
|
|
|
wl_list_init(&widget->link);
|
|
|
|
surface->widget = widget;
|
|
|
|
|
|
|
|
parent = window->main_surface->surface;
|
|
|
|
surface->subsurface = wl_subcompositor_get_subsurface(subcompo,
|
|
|
|
surface->surface,
|
|
|
|
parent);
|
|
|
|
surface->synchronized = 1;
|
|
|
|
|
|
|
|
switch (default_mode) {
|
|
|
|
case SUBSURFACE_SYNCHRONIZED:
|
|
|
|
surface->synchronized_default = 1;
|
|
|
|
break;
|
|
|
|
case SUBSURFACE_DESYNCHRONIZED:
|
|
|
|
surface->synchronized_default = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(!"bad enum subsurface_mode");
|
|
|
|
}
|
|
|
|
|
2013-11-12 01:07:33 +00:00
|
|
|
window->resize_needed = 1;
|
|
|
|
window_schedule_redraw(window);
|
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
return widget;
|
|
|
|
}
|
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,
|
2012-07-22 19:49:57 +00:00
|
|
|
const char *model,
|
|
|
|
int transform)
|
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;
|
2012-09-29 08:03:11 +00:00
|
|
|
output->transform = transform;
|
2014-04-03 00:53:50 +00:00
|
|
|
|
|
|
|
if (output->make)
|
|
|
|
free(output->make);
|
|
|
|
output->make = strdup(make);
|
|
|
|
|
|
|
|
if (output->model)
|
|
|
|
free(output->model);
|
|
|
|
output->model = strdup(model);
|
2011-06-21 15:16:58 +00:00
|
|
|
}
|
|
|
|
|
2013-05-22 12:41:27 +00:00
|
|
|
static void
|
|
|
|
display_handle_done(void *data,
|
|
|
|
struct wl_output *wl_output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
display_handle_scale(void *data,
|
|
|
|
struct wl_output *wl_output,
|
2013-05-24 11:09:43 +00:00
|
|
|
int32_t scale)
|
2013-05-22 12:41:27 +00:00
|
|
|
{
|
|
|
|
struct output *output = data;
|
|
|
|
|
|
|
|
output->scale = scale;
|
|
|
|
}
|
|
|
|
|
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,
|
2013-05-22 12:41:27 +00:00
|
|
|
display_handle_mode,
|
|
|
|
display_handle_done,
|
|
|
|
display_handle_scale
|
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;
|
|
|
|
|
2013-08-15 21:28:25 +00:00
|
|
|
output = xzalloc(sizeof *output);
|
2011-11-26 22:27:37 +00:00
|
|
|
output->display = d;
|
2013-05-22 12:41:27 +00:00
|
|
|
output->scale = 1;
|
2011-11-26 22:27:37 +00:00
|
|
|
output->output =
|
2013-05-22 12:41:27 +00:00
|
|
|
wl_registry_bind(d->registry, id, &wl_output_interface, 2);
|
2013-10-23 05:58:35 +00:00
|
|
|
output->server_output_id = id;
|
2011-11-26 22:27:37 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-10-23 05:58:35 +00:00
|
|
|
static void
|
|
|
|
display_destroy_output(struct display *d, uint32_t id)
|
|
|
|
{
|
|
|
|
struct output *output;
|
|
|
|
|
|
|
|
wl_list_for_each(output, &d->output_list, link) {
|
|
|
|
if (output->server_output_id == id) {
|
|
|
|
output_destroy(output);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-11 01:34:26 +00:00
|
|
|
void
|
|
|
|
display_set_global_handler(struct display *display,
|
|
|
|
display_global_handler_t handler)
|
|
|
|
{
|
|
|
|
struct global *global;
|
|
|
|
|
|
|
|
display->global_handler = handler;
|
|
|
|
if (!handler)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wl_list_for_each(global, &display->global_list, link)
|
|
|
|
display->global_handler(display,
|
|
|
|
global->name, global->interface,
|
|
|
|
global->version, display->user_data);
|
|
|
|
}
|
|
|
|
|
2013-10-23 05:58:35 +00:00
|
|
|
void
|
|
|
|
display_set_global_handler_remove(struct display *display,
|
|
|
|
display_global_handler_t remove_handler)
|
|
|
|
{
|
|
|
|
display->global_handler_remove = remove_handler;
|
|
|
|
if (!remove_handler)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2012-10-15 09:06:53 +00:00
|
|
|
wl_list_for_each(output, &display->output_list, link) {
|
|
|
|
if (output->allocation.width == 0 &&
|
|
|
|
output->allocation.height == 0)
|
|
|
|
continue;
|
|
|
|
|
2011-11-30 08:52:38 +00:00
|
|
|
(*display->output_configure_handler)(output,
|
|
|
|
display->user_data);
|
2012-10-15 09:06:53 +00:00
|
|
|
}
|
2011-11-30 08:52:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2012-09-29 08:03:11 +00:00
|
|
|
output_get_allocation(struct output *output, struct rectangle *base)
|
2011-11-26 22:27:37 +00:00
|
|
|
{
|
2012-09-29 08:03:11 +00:00
|
|
|
struct rectangle allocation = output->allocation;
|
|
|
|
|
|
|
|
switch (output->transform) {
|
|
|
|
case WL_OUTPUT_TRANSFORM_90:
|
|
|
|
case WL_OUTPUT_TRANSFORM_270:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
|
|
|
|
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
|
|
|
|
/* Swap width and height */
|
|
|
|
allocation.width = output->allocation.height;
|
|
|
|
allocation.height = output->allocation.width;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
*base = allocation;
|
2011-11-26 22:27:37 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 08:52:38 +00:00
|
|
|
struct wl_output *
|
|
|
|
output_get_wl_output(struct output *output)
|
|
|
|
{
|
|
|
|
return output->output;
|
|
|
|
}
|
|
|
|
|
2012-11-30 15:34:25 +00:00
|
|
|
enum wl_output_transform
|
|
|
|
output_get_transform(struct output *output)
|
|
|
|
{
|
|
|
|
return output->transform;
|
|
|
|
}
|
|
|
|
|
2013-05-22 12:41:27 +00:00
|
|
|
uint32_t
|
|
|
|
output_get_scale(struct output *output)
|
|
|
|
{
|
|
|
|
return output->scale;
|
|
|
|
}
|
|
|
|
|
2014-04-03 00:53:50 +00:00
|
|
|
const char *
|
|
|
|
output_get_make(struct output *output)
|
|
|
|
{
|
|
|
|
return output->make;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
output_get_model(struct output *output)
|
|
|
|
{
|
|
|
|
return output->model;
|
|
|
|
}
|
|
|
|
|
2012-05-30 15:32:01 +00:00
|
|
|
static void
|
|
|
|
fini_xkb(struct input *input)
|
|
|
|
{
|
|
|
|
xkb_state_unref(input->xkb.state);
|
2014-08-19 20:59:51 +00:00
|
|
|
xkb_keymap_unref(input->xkb.keymap);
|
2012-05-30 15:32:01 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 21:06:19 +00:00
|
|
|
static void
|
2015-10-14 14:39:59 +00:00
|
|
|
display_add_input(struct display *d, uint32_t id, int display_seat_version)
|
2010-07-20 21:06:19 +00:00
|
|
|
{
|
|
|
|
struct input *input;
|
2016-01-18 06:38:22 +00:00
|
|
|
int seat_version = MIN(display_seat_version, 5);
|
2010-07-20 21:06:19 +00:00
|
|
|
|
2013-08-15 21:17:13 +00:00
|
|
|
input = xzalloc(sizeof *input);
|
2010-07-20 21:06:19 +00:00
|
|
|
input->display = d;
|
2013-08-13 19:11:03 +00:00
|
|
|
input->seat = wl_registry_bind(d->registry, id, &wl_seat_interface,
|
2015-10-14 14:39:59 +00:00
|
|
|
seat_version);
|
2013-08-15 16:10:08 +00:00
|
|
|
input->touch_focus = NULL;
|
2010-07-20 21:06:19 +00:00
|
|
|
input->pointer_focus = NULL;
|
|
|
|
input->keyboard_focus = NULL;
|
2015-10-14 14:39:59 +00:00
|
|
|
input->seat_version = seat_version;
|
|
|
|
|
2013-08-09 04:20:38 +00:00
|
|
|
wl_list_init(&input->touch_point_list);
|
2010-07-20 21:06:19 +00:00
|
|
|
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
|
|
|
|
2014-04-03 00:53:51 +00:00
|
|
|
if (d->data_device_manager) {
|
|
|
|
input->data_device =
|
|
|
|
wl_data_device_manager_get_data_device(d->data_device_manager,
|
|
|
|
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);
|
2015-04-22 22:23:35 +00:00
|
|
|
input->cursor_task.run = cursor_timer_func;
|
2012-06-20 18:52:12 +00:00
|
|
|
|
2015-04-22 22:23:35 +00:00
|
|
|
input->cursor_delay_fd = timerfd_create(CLOCK_MONOTONIC,
|
|
|
|
TFD_CLOEXEC | TFD_NONBLOCK);
|
|
|
|
display_watch_fd(d, input->cursor_delay_fd, EPOLLIN,
|
|
|
|
&input->cursor_task);
|
2014-08-12 12:58:27 +00:00
|
|
|
set_repeat_info(input, 40, 400);
|
|
|
|
|
2012-06-20 22:00:13 +00:00
|
|
|
input->repeat_timer_fd = timerfd_create(CLOCK_MONOTONIC,
|
|
|
|
TFD_CLOEXEC | TFD_NONBLOCK);
|
2012-06-20 18:52:12 +00:00
|
|
|
input->repeat_task.run = keyboard_repeat_func;
|
|
|
|
display_watch_fd(d, input->repeat_timer_fd,
|
|
|
|
EPOLLIN, &input->repeat_task);
|
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
|
|
|
|
|
|
|
if (input->drag_offer)
|
|
|
|
data_offer_destroy(input->drag_offer);
|
|
|
|
|
|
|
|
if (input->selection_offer)
|
|
|
|
data_offer_destroy(input->selection_offer);
|
|
|
|
|
2014-10-20 06:25:29 +00:00
|
|
|
if (input->data_device) {
|
2015-08-06 20:12:19 +00:00
|
|
|
if (input->display->data_device_manager_version >= 2)
|
2014-10-20 06:25:29 +00:00
|
|
|
wl_data_device_release(input->data_device);
|
|
|
|
else
|
|
|
|
wl_data_device_destroy(input->data_device);
|
|
|
|
}
|
2015-10-14 14:39:59 +00:00
|
|
|
if (input->seat_version >= WL_POINTER_RELEASE_SINCE_VERSION) {
|
2015-10-09 16:17:43 +00:00
|
|
|
if (input->touch)
|
|
|
|
wl_touch_release(input->touch);
|
2013-08-13 19:11:03 +00:00
|
|
|
if (input->pointer)
|
|
|
|
wl_pointer_release(input->pointer);
|
|
|
|
if (input->keyboard)
|
|
|
|
wl_keyboard_release(input->keyboard);
|
2015-10-09 16:17:43 +00:00
|
|
|
} else {
|
|
|
|
if (input->touch)
|
|
|
|
wl_touch_destroy(input->touch);
|
|
|
|
if (input->pointer)
|
|
|
|
wl_pointer_destroy(input->pointer);
|
|
|
|
if (input->keyboard)
|
|
|
|
wl_keyboard_destroy(input->keyboard);
|
2013-08-13 19:11:03 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2012-06-20 18:52:12 +00:00
|
|
|
close(input->repeat_timer_fd);
|
2015-04-22 22:23:35 +00:00
|
|
|
close(input->cursor_delay_fd);
|
2011-12-16 10:02:09 +00:00
|
|
|
free(input);
|
|
|
|
}
|
|
|
|
|
2013-08-06 18:05:54 +00:00
|
|
|
static void
|
|
|
|
shm_format(void *data, struct wl_shm *wl_shm, uint32_t format)
|
|
|
|
{
|
|
|
|
struct display *d = data;
|
|
|
|
|
|
|
|
if (format == WL_SHM_FORMAT_RGB565)
|
|
|
|
d->has_rgb565 = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct wl_shm_listener shm_listener = {
|
|
|
|
shm_format
|
|
|
|
};
|
|
|
|
|
2014-02-11 20:22:51 +00:00
|
|
|
static void
|
|
|
|
xdg_shell_ping(void *data, struct xdg_shell *shell, uint32_t serial)
|
|
|
|
{
|
|
|
|
xdg_shell_pong(shell, serial);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct xdg_shell_listener xdg_shell_listener = {
|
|
|
|
xdg_shell_ping,
|
|
|
|
};
|
|
|
|
|
2015-02-13 06:02:02 +00:00
|
|
|
#define XDG_VERSION 5 /* The version of xdg-shell that we implement */
|
2014-02-11 21:50:08 +00:00
|
|
|
#ifdef static_assert
|
|
|
|
static_assert(XDG_VERSION == XDG_SHELL_VERSION_CURRENT,
|
|
|
|
"Interface version doesn't match implementation version");
|
|
|
|
#endif
|
|
|
|
|
2008-12-30 16:03:33 +00:00
|
|
|
static void
|
2012-10-11 01:34:26 +00:00
|
|
|
registry_handle_global(void *data, struct wl_registry *registry, uint32_t id,
|
|
|
|
const char *interface, uint32_t version)
|
2008-12-08 05:01:36 +00:00
|
|
|
{
|
2009-01-27 04:42:46 +00:00
|
|
|
struct display *d = data;
|
2012-10-11 01:34:26 +00:00
|
|
|
struct global *global;
|
|
|
|
|
2013-08-07 22:34:59 +00:00
|
|
|
global = xmalloc(sizeof *global);
|
2012-10-11 01:34:26 +00:00
|
|
|
global->name = id;
|
|
|
|
global->interface = strdup(interface);
|
|
|
|
global->version = version;
|
|
|
|
wl_list_insert(d->global_list.prev, &global->link);
|
2008-12-30 16:03:33 +00:00
|
|
|
|
2011-04-20 22:53:07 +00:00
|
|
|
if (strcmp(interface, "wl_compositor") == 0) {
|
2012-10-11 01:34:26 +00:00
|
|
|
d->compositor = wl_registry_bind(registry, id,
|
2013-06-27 03:20:31 +00:00
|
|
|
&wl_compositor_interface, 3);
|
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) {
|
2015-10-14 14:39:59 +00:00
|
|
|
display_add_input(d, id, version);
|
2011-04-20 22:53:07 +00:00
|
|
|
} else if (strcmp(interface, "wl_shm") == 0) {
|
2012-10-11 01:34:26 +00:00
|
|
|
d->shm = wl_registry_bind(registry, id, &wl_shm_interface, 1);
|
2013-08-06 18:05:54 +00:00
|
|
|
wl_shm_add_listener(d->shm, &shm_listener, d);
|
2011-10-28 16:26:06 +00:00
|
|
|
} else if (strcmp(interface, "wl_data_device_manager") == 0) {
|
2014-10-20 06:25:29 +00:00
|
|
|
d->data_device_manager_version = MIN(version, 2);
|
2011-10-28 16:26:06 +00:00
|
|
|
d->data_device_manager =
|
2012-10-11 01:34:26 +00:00
|
|
|
wl_registry_bind(registry, id,
|
2014-10-20 06:25:29 +00:00
|
|
|
&wl_data_device_manager_interface,
|
|
|
|
d->data_device_manager_version);
|
2013-12-09 19:58:00 +00:00
|
|
|
} else if (strcmp(interface, "xdg_shell") == 0) {
|
|
|
|
d->xdg_shell = wl_registry_bind(registry, id,
|
|
|
|
&xdg_shell_interface, 1);
|
2014-02-11 21:50:08 +00:00
|
|
|
xdg_shell_use_unstable_version(d->xdg_shell, XDG_VERSION);
|
2014-02-11 20:22:51 +00:00
|
|
|
xdg_shell_add_listener(d->xdg_shell, &xdg_shell_listener, d);
|
2012-05-27 20:25:02 +00:00
|
|
|
} else if (strcmp(interface, "text_cursor_position") == 0) {
|
|
|
|
d->text_cursor_position =
|
2012-10-11 01:34:26 +00:00
|
|
|
wl_registry_bind(registry, id,
|
|
|
|
&text_cursor_position_interface, 1);
|
2013-04-25 10:57:48 +00:00
|
|
|
} else if (strcmp(interface, "wl_subcompositor") == 0) {
|
|
|
|
d->subcompositor =
|
|
|
|
wl_registry_bind(registry, id,
|
|
|
|
&wl_subcompositor_interface, 1);
|
2008-12-30 16:03:33 +00:00
|
|
|
}
|
2014-11-27 04:24:52 +00:00
|
|
|
else if (strcmp(interface, "ivi_application") == 0) {
|
|
|
|
d->ivi_application =
|
|
|
|
wl_registry_bind(registry, id,
|
|
|
|
&ivi_application_interface, 1);
|
|
|
|
}
|
2012-10-11 01:34:26 +00:00
|
|
|
|
|
|
|
if (d->global_handler)
|
|
|
|
d->global_handler(d, id, interface, version, d->user_data);
|
2008-12-08 05:01:36 +00:00
|
|
|
}
|
|
|
|
|
2013-01-22 12:53:55 +00:00
|
|
|
static void
|
|
|
|
registry_handle_global_remove(void *data, struct wl_registry *registry,
|
|
|
|
uint32_t name)
|
|
|
|
{
|
|
|
|
struct display *d = data;
|
|
|
|
struct global *global;
|
|
|
|
struct global *tmp;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(global, tmp, &d->global_list, link) {
|
|
|
|
if (global->name != name)
|
|
|
|
continue;
|
|
|
|
|
2013-10-23 05:58:35 +00:00
|
|
|
if (strcmp(global->interface, "wl_output") == 0)
|
|
|
|
display_destroy_output(d, name);
|
|
|
|
|
|
|
|
/* XXX: Should destroy remaining bound globals */
|
|
|
|
|
|
|
|
if (d->global_handler_remove)
|
|
|
|
d->global_handler_remove(d, name, global->interface,
|
|
|
|
global->version, d->user_data);
|
|
|
|
|
2013-01-22 12:53:55 +00:00
|
|
|
wl_list_remove(&global->link);
|
|
|
|
free(global->interface);
|
|
|
|
free(global);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-11 01:34:26 +00:00
|
|
|
void *
|
|
|
|
display_bind(struct display *display, uint32_t name,
|
|
|
|
const struct wl_interface *interface, uint32_t version)
|
|
|
|
{
|
|
|
|
return wl_registry_bind(display->registry, name, interface, version);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wl_registry_listener registry_listener = {
|
2013-01-22 12:53:55 +00:00
|
|
|
registry_handle_global,
|
|
|
|
registry_handle_global_remove
|
2012-10-11 01:34:26 +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[] = {
|
2012-10-16 19:31:31 +00:00
|
|
|
EGL_SURFACE_TYPE, EGL_WINDOW_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
|
|
|
|
|
2015-03-20 14:26:51 +00:00
|
|
|
d->dpy =
|
|
|
|
weston_platform_get_egl_display(EGL_PLATFORM_WAYLAND_KHR,
|
|
|
|
d->display, NULL);
|
|
|
|
|
2010-12-06 14:18:12 +00:00
|
|
|
if (!eglInitialize(d->dpy, &major, &minor)) {
|
2013-02-14 09:49:12 +00:00
|
|
|
fprintf(stderr, "failed to initialize EGL\n");
|
2010-12-06 14:18:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-18 19:50:58 +00:00
|
|
|
if (!eglBindAPI(api)) {
|
2013-02-14 09:49:12 +00:00
|
|
|
fprintf(stderr, "failed to bind EGL client API\n");
|
2010-12-06 14:18:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-01-11 19:24:46 +00:00
|
|
|
if (!eglChooseConfig(d->dpy, argb_cfg_attribs,
|
|
|
|
&d->argb_config, 1, &n) || n != 1) {
|
2013-02-14 09:49:12 +00:00
|
|
|
fprintf(stderr, "failed to choose argb EGL 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) {
|
2013-02-14 09:49:12 +00:00
|
|
|
fprintf(stderr, "failed to create EGL context\n");
|
2010-12-06 14:18:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-09-27 19:57:31 +00:00
|
|
|
d->argb_device = cairo_egl_device_create(d->dpy, d->argb_ctx);
|
|
|
|
if (cairo_device_status(d->argb_device) != CAIRO_STATUS_SUCCESS) {
|
2013-02-14 09:49:12 +00:00
|
|
|
fprintf(stderr, "failed to get cairo EGL argb device\n");
|
2011-09-27 19:57:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-12-06 14:18:12 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-15 13:20:04 +00:00
|
|
|
static void
|
|
|
|
fini_egl(struct display *display)
|
|
|
|
{
|
|
|
|
cairo_device_destroy(display->argb_device);
|
|
|
|
|
|
|
|
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
|
|
|
|
2012-11-19 15:16:01 +00:00
|
|
|
static void
|
|
|
|
init_dummy_surface(struct display *display)
|
|
|
|
{
|
|
|
|
int len;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
len = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, 1);
|
2014-11-20 21:42:35 +00:00
|
|
|
data = xmalloc(len);
|
2012-11-19 15:16:01 +00:00
|
|
|
display->dummy_surface =
|
|
|
|
cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32,
|
|
|
|
1, 1, len);
|
|
|
|
display->dummy_surface_data = data;
|
|
|
|
}
|
|
|
|
|
2011-09-14 21:33:48 +00:00
|
|
|
static void
|
|
|
|
handle_display_data(struct task *task, uint32_t events)
|
|
|
|
{
|
|
|
|
struct display *display =
|
|
|
|
container_of(task, struct display, display_task);
|
2012-10-11 01:34:26 +00:00
|
|
|
struct epoll_event ep;
|
|
|
|
int ret;
|
2012-10-03 04:12:35 +00:00
|
|
|
|
|
|
|
display->display_fd_events = events;
|
|
|
|
|
|
|
|
if (events & EPOLLERR || events & EPOLLHUP) {
|
|
|
|
display_exit(display);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-16 17:16:10 +00:00
|
|
|
if (events & EPOLLIN) {
|
|
|
|
ret = wl_display_dispatch(display->display);
|
|
|
|
if (ret == -1) {
|
|
|
|
display_exit(display);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-10-11 01:34:26 +00:00
|
|
|
|
|
|
|
if (events & EPOLLOUT) {
|
|
|
|
ret = wl_display_flush(display->display);
|
|
|
|
if (ret == 0) {
|
|
|
|
ep.events = EPOLLIN | EPOLLERR | EPOLLHUP;
|
|
|
|
ep.data.ptr = &display->display_task;
|
|
|
|
epoll_ctl(display->epoll_fd, EPOLL_CTL_MOD,
|
|
|
|
display->display_fd, &ep);
|
|
|
|
} else if (ret == -1 && errno != EAGAIN) {
|
|
|
|
display_exit(display);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-09-14 21:33:48 +00:00
|
|
|
}
|
|
|
|
|
2013-04-16 15:21:48 +00:00
|
|
|
static void
|
|
|
|
log_handler(const char *format, va_list args)
|
|
|
|
{
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
}
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
struct display *
|
2013-02-20 20:27:49 +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
|
|
|
|
2013-04-16 15:21:48 +00:00
|
|
|
wl_log_set_handler_client(log_handler);
|
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
d = zalloc(sizeof *d);
|
2009-01-27 04:42:46 +00:00
|
|
|
if (d == NULL)
|
2008-11-07 20:54:48 +00:00
|
|
|
return NULL;
|
|
|
|
|
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) {
|
2013-02-14 09:49:12 +00:00
|
|
|
fprintf(stderr, "failed to connect to Wayland display: %m\n");
|
2013-01-10 19:48:54 +00:00
|
|
|
free(d);
|
2010-06-08 18:59:44 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-26 15:29:43 +00:00
|
|
|
d->xkb_context = xkb_context_new(0);
|
|
|
|
if (d->xkb_context == NULL) {
|
|
|
|
fprintf(stderr, "Failed to create XKB context\n");
|
|
|
|
free(d);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-05-30 12:53:43 +00:00
|
|
|
d->epoll_fd = os_epoll_create_cloexec();
|
2012-10-11 01:34:26 +00:00
|
|
|
d->display_fd = wl_display_get_fd(d->display);
|
2011-09-14 21:33:48 +00:00
|
|
|
d->display_task.run = handle_display_data;
|
2012-10-03 04:12:35 +00:00
|
|
|
display_watch_fd(d, d->display_fd, EPOLLIN | EPOLLERR | EPOLLHUP,
|
|
|
|
&d->display_task);
|
2011-09-14 21:33:48 +00:00
|
|
|
|
|
|
|
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);
|
2012-10-11 01:34:26 +00:00
|
|
|
wl_list_init(&d->global_list);
|
2010-07-20 21:06:19 +00:00
|
|
|
|
2012-10-11 01:34:26 +00:00
|
|
|
d->registry = wl_display_get_registry(d->display);
|
|
|
|
wl_registry_add_listener(d->registry, ®istry_listener, d);
|
2013-02-14 10:18:00 +00:00
|
|
|
|
2014-12-05 12:49:40 +00:00
|
|
|
if (wl_display_roundtrip(d->display) < 0) {
|
2013-02-14 10:18:00 +00:00
|
|
|
fprintf(stderr, "Failed to process Wayland connection: %m\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-04-03 15:57:44 +00:00
|
|
|
#ifdef HAVE_CAIRO_EGL
|
2013-02-14 09:49:12 +00:00
|
|
|
if (init_egl(d) < 0)
|
|
|
|
fprintf(stderr, "EGL does not seem to work, "
|
|
|
|
"falling back to software rendering and wl_shm.\n");
|
2012-04-03 15:57:44 +00:00
|
|
|
#endif
|
2008-11-07 20:54:48 +00:00
|
|
|
|
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);
|
|
|
|
|
2012-11-19 15:16:01 +00:00
|
|
|
init_dummy_surface(d);
|
|
|
|
|
2009-01-27 04:42:46 +00:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2011-12-16 09:35:34 +00:00
|
|
|
static void
|
|
|
|
display_destroy_outputs(struct display *display)
|
|
|
|
{
|
|
|
|
struct output *tmp;
|
|
|
|
struct output *output;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(output, tmp, &display->output_list, link)
|
|
|
|
output_destroy(output);
|
|
|
|
}
|
|
|
|
|
2011-12-16 10:02:09 +00:00
|
|
|
static void
|
|
|
|
display_destroy_inputs(struct display *display)
|
|
|
|
{
|
|
|
|
struct input *tmp;
|
|
|
|
struct input *input;
|
|
|
|
|
|
|
|
wl_list_for_each_safe(input, tmp, &display->input_list, link)
|
|
|
|
input_destroy(input);
|
|
|
|
}
|
|
|
|
|
2011-12-15 13:20:04 +00:00
|
|
|
void
|
|
|
|
display_destroy(struct display *display)
|
|
|
|
{
|
2011-12-16 09:41:32 +00:00
|
|
|
if (!wl_list_empty(&display->window_list))
|
2012-10-03 04:12:35 +00:00
|
|
|
fprintf(stderr, "toytoolkit warning: %d windows exist.\n",
|
|
|
|
wl_list_length(&display->window_list));
|
2011-12-16 09:41:32 +00:00
|
|
|
|
|
|
|
if (!wl_list_empty(&display->deferred_list))
|
|
|
|
fprintf(stderr, "toytoolkit warning: deferred tasks exist.\n");
|
|
|
|
|
2012-11-19 15:16:01 +00:00
|
|
|
cairo_surface_destroy(display->dummy_surface);
|
|
|
|
free(display->dummy_surface_data);
|
|
|
|
|
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
|
2013-01-07 20:47:14 +00:00
|
|
|
if (display->argb_device)
|
|
|
|
fini_egl(display);
|
2012-04-03 15:57:44 +00:00
|
|
|
#endif
|
2011-12-15 13:20:04 +00:00
|
|
|
|
2013-04-25 10:57:48 +00:00
|
|
|
if (display->subcompositor)
|
|
|
|
wl_subcompositor_destroy(display->subcompositor);
|
|
|
|
|
2013-12-09 19:58:00 +00:00
|
|
|
if (display->xdg_shell)
|
|
|
|
xdg_shell_destroy(display->xdg_shell);
|
2011-12-16 09:41:32 +00:00
|
|
|
|
2014-11-27 04:24:52 +00:00
|
|
|
if (display->ivi_application)
|
|
|
|
ivi_application_destroy(display->ivi_application);
|
|
|
|
|
2011-12-16 09:41:32 +00:00
|
|
|
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);
|
2012-12-04 14:01:15 +00:00
|
|
|
wl_registry_destroy(display->registry);
|
2011-12-16 09:41:32 +00:00
|
|
|
|
|
|
|
close(display->epoll_fd);
|
|
|
|
|
2012-10-03 04:12:35 +00:00
|
|
|
if (!(display->display_fd_events & EPOLLERR) &&
|
|
|
|
!(display->display_fd_events & EPOLLHUP))
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-08-15 18:54:03 +00:00
|
|
|
int
|
|
|
|
display_has_subcompositor(struct display *display)
|
|
|
|
{
|
|
|
|
if (display->subcompositor)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
wl_display_roundtrip(display->display);
|
|
|
|
|
|
|
|
return display->subcompositor != NULL;
|
|
|
|
}
|
|
|
|
|
2013-04-12 01:47:41 +00:00
|
|
|
cairo_device_t *
|
|
|
|
display_get_cairo_device(struct display *display)
|
|
|
|
{
|
|
|
|
return display->argb_device;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-04-03 00:53:51 +00:00
|
|
|
if (display->data_device_manager)
|
|
|
|
return wl_data_device_manager_create_data_source(display->data_device_manager);
|
|
|
|
else
|
|
|
|
return NULL;
|
2011-10-28 16:26:06 +00:00
|
|
|
}
|
|
|
|
|
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-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)
|
|
|
|
{
|
2013-02-13 14:17:14 +00:00
|
|
|
struct surface *surface = window->main_surface;
|
|
|
|
|
2013-02-13 14:17:15 +00:00
|
|
|
if (surface->buffer_type != WINDOW_BUFFER_TYPE_EGL_WINDOW)
|
2011-10-07 07:33:06 +00:00
|
|
|
return -1;
|
2011-02-18 22:00:55 +00:00
|
|
|
|
2013-02-20 11:39:17 +00:00
|
|
|
widget_get_cairo_surface(window->main_surface->widget);
|
2013-02-13 14:17:14 +00:00
|
|
|
return surface->toysurface->acquire(surface->toysurface, ctx);
|
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
|
|
|
{
|
2013-02-13 14:17:14 +00:00
|
|
|
struct surface *surface = window->main_surface;
|
|
|
|
|
2013-02-13 14:17:15 +00:00
|
|
|
if (surface->buffer_type != WINDOW_BUFFER_TYPE_EGL_WINDOW)
|
2011-09-27 19:57:31 +00:00
|
|
|
return;
|
|
|
|
|
2013-02-13 14:17:14 +00:00
|
|
|
surface->toysurface->release(surface->toysurface);
|
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);
|
|
|
|
}
|
|
|
|
|
2012-11-29 08:27:09 +00:00
|
|
|
void
|
|
|
|
display_unwatch_fd(struct display *display, int fd)
|
|
|
|
{
|
|
|
|
epoll_ctl(display->epoll_fd, EPOLL_CTL_DEL, fd, NULL);
|
|
|
|
}
|
|
|
|
|
2011-09-14 21:33:48 +00:00
|
|
|
void
|
|
|
|
display_run(struct display *display)
|
|
|
|
{
|
|
|
|
struct task *task;
|
|
|
|
struct epoll_event ep[16];
|
2012-10-11 01:34:26 +00:00
|
|
|
int i, count, ret;
|
2011-09-14 21:33:48 +00:00
|
|
|
|
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
|
|
|
while (!wl_list_empty(&display->deferred_list)) {
|
2012-09-27 11:46:23 +00:00
|
|
|
task = container_of(display->deferred_list.prev,
|
2012-01-09 23:48:14 +00:00
|
|
|
struct task, link);
|
|
|
|
wl_list_remove(&task->link);
|
|
|
|
task->run(task, 0);
|
|
|
|
}
|
2011-09-14 21:33:48 +00:00
|
|
|
|
2012-10-15 16:56:11 +00:00
|
|
|
wl_display_dispatch_pending(display->display);
|
|
|
|
|
2011-12-15 08:14:07 +00:00
|
|
|
if (!display->running)
|
|
|
|
break;
|
|
|
|
|
2012-10-11 01:34:26 +00:00
|
|
|
ret = wl_display_flush(display->display);
|
|
|
|
if (ret < 0 && errno == EAGAIN) {
|
|
|
|
ep[0].events =
|
|
|
|
EPOLLIN | EPOLLOUT | EPOLLERR | EPOLLHUP;
|
|
|
|
ep[0].data.ptr = &display->display_task;
|
|
|
|
|
|
|
|
epoll_ctl(display->epoll_fd, EPOLL_CTL_MOD,
|
|
|
|
display->display_fd, &ep[0]);
|
|
|
|
} else if (ret < 0) {
|
|
|
|
break;
|
|
|
|
}
|
2012-01-09 23:48:14 +00:00
|
|
|
|
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;
|
|
|
|
}
|
2012-11-18 18:06:44 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
keysym_modifiers_add(struct wl_array *modifiers_map,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
size_t len = strlen(name) + 1;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
p = wl_array_add(modifiers_map, len);
|
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
strncpy(p, name, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static xkb_mod_index_t
|
|
|
|
keysym_modifiers_get_index(struct wl_array *modifiers_map,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
xkb_mod_index_t index = 0;
|
|
|
|
char *p = modifiers_map->data;
|
|
|
|
|
|
|
|
while ((const char *)p < (const char *)(modifiers_map->data + modifiers_map->size)) {
|
|
|
|
if (strcmp(p, name) == 0)
|
|
|
|
return index;
|
|
|
|
|
|
|
|
index++;
|
|
|
|
p += strlen(p) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return XKB_MOD_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
xkb_mod_mask_t
|
|
|
|
keysym_modifiers_get_mask(struct wl_array *modifiers_map,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
xkb_mod_index_t index = keysym_modifiers_get_index(modifiers_map, name);
|
|
|
|
|
|
|
|
if (index == XKB_MOD_INVALID)
|
|
|
|
return XKB_MOD_INVALID;
|
|
|
|
|
|
|
|
return 1 << index;
|
|
|
|
}
|
2013-07-25 22:20:20 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
fail_on_null(void *p)
|
|
|
|
{
|
|
|
|
if (p == NULL) {
|
2013-08-08 07:13:47 +00:00
|
|
|
fprintf(stderr, "%s: out of memory\n", program_invocation_short_name);
|
2013-07-25 22:20:20 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
xmalloc(size_t s)
|
|
|
|
{
|
|
|
|
return fail_on_null(malloc(s));
|
|
|
|
}
|
|
|
|
|
2013-08-08 01:57:05 +00:00
|
|
|
void *
|
|
|
|
xzalloc(size_t s)
|
|
|
|
{
|
|
|
|
return fail_on_null(zalloc(s));
|
|
|
|
}
|
|
|
|
|
2013-07-25 22:20:20 +00:00
|
|
|
char *
|
|
|
|
xstrdup(const char *s)
|
|
|
|
{
|
|
|
|
return fail_on_null(strdup(s));
|
|
|
|
}
|
2014-01-10 07:45:18 +00:00
|
|
|
|
|
|
|
void *
|
|
|
|
xrealloc(char *p, size_t s)
|
|
|
|
{
|
|
|
|
return fail_on_null(realloc(p, s));
|
|
|
|
}
|