Merge branch 'master' into wlr_mirror_v1

This commit is contained in:
Alexander Courtis 2022-01-21 10:24:53 +11:00
commit bdc60ac342
50 changed files with 2036 additions and 1961 deletions

View file

@ -7,6 +7,7 @@ charset = utf-8
trim_trailing_whitespace = true
indent_style = tab
indent_size = 4
max_line_length = 80
[*.xml]
indent_style = space

View file

@ -32,9 +32,8 @@ to implement yourself.
Check out our [wiki] to get started with wlroots. Join our IRC channel:
[#sway-devel on Libera Chat].
wlroots is developed under the direction of the [sway] project. A variety of
[wrapper libraries] are available for using it with your favorite programming
language.
A variety of [wrapper libraries] are available for using it with your favorite
programming language.
## Building
@ -77,7 +76,6 @@ See [CONTRIBUTING.md].
[Wayland]: https://wayland.freedesktop.org/
[wiki]: https://gitlab.freedesktop.org/wlroots/wlroots/-/wikis/Getting-started
[#sway-devel on Libera Chat]: https://web.libera.chat/gamja/?channels=#sway-devel
[Sway]: https://github.com/swaywm/sway
[wrapper libraries]: https://gitlab.freedesktop.org/wlroots/wlroots/-/wikis/Projects-which-use-wlroots#wrapper-libraries
[libseat]: https://git.sr.ht/~kennylevinsen/seatd
[CONTRIBUTING.md]: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/CONTRIBUTING.md

View file

@ -14,7 +14,6 @@
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/box.h>
#include <wlr/util/log.h>

View file

@ -13,7 +13,6 @@
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
@ -30,8 +29,7 @@ struct server {
struct wlr_allocator *allocator;
struct wlr_scene *scene;
struct wl_list outputs;
struct wl_list surfaces;
uint32_t surface_offset;
struct wl_listener new_output;
struct wl_listener new_surface;
@ -65,11 +63,7 @@ static void output_handle_frame(struct wl_listener *listener, void *data) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct surface *surface;
wl_list_for_each(surface, &output->server->surfaces, link) {
wlr_surface_send_frame_done(surface->wlr, &now);
}
wlr_scene_output_send_frame_done(output->scene_output, &now);
}
static void server_handle_new_output(struct wl_listener *listener, void *data) {
@ -84,7 +78,6 @@ static void server_handle_new_output(struct wl_listener *listener, void *data) {
output->server = server;
output->frame.notify = output_handle_frame;
wl_signal_add(&wlr_output->events.frame, &output->frame);
wl_list_insert(&server->outputs, &output->link);
output->scene_output = wlr_scene_output_create(server->scene, wlr_output);
@ -118,7 +111,8 @@ static void server_handle_new_surface(struct wl_listener *listener,
struct server *server = wl_container_of(listener, server, new_surface);
struct wlr_surface *wlr_surface = data;
int pos = 50 * wl_list_length(&server->surfaces);
int pos = server->surface_offset;
server->surface_offset += 50;
struct surface *surface = calloc(1, sizeof(struct surface));
surface->wlr = wlr_surface;
@ -134,7 +128,6 @@ static void server_handle_new_surface(struct wl_listener *listener,
surface->scene_surface =
wlr_scene_surface_create(&server->scene->node, wlr_surface);
wl_list_insert(server->surfaces.prev, &surface->link);
wlr_scene_node_set_position(&surface->scene_surface->node,
pos + border_width, pos + border_width);
@ -162,6 +155,7 @@ int main(int argc, char *argv[]) {
}
struct server server = {0};
server.surface_offset = 0;
server.display = wl_display_create();
server.backend = wlr_backend_autocreate(server.display);
server.scene = wlr_scene_create();
@ -177,9 +171,6 @@ int main(int argc, char *argv[]) {
wlr_xdg_shell_create(server.display);
wl_list_init(&server.outputs);
wl_list_init(&server.surfaces);
server.new_output.notify = server_handle_new_output;
wl_signal_add(&server.backend->events.new_output, &server.new_output);

View file

@ -1,20 +0,0 @@
#ifndef TYPES_WLR_SURFACE_H
#define TYPES_WLR_SURFACE_H
#include <wlr/types/wlr_surface.h>
struct wlr_renderer;
/**
* Create a new surface resource with the provided new ID.
*/
struct wlr_surface *surface_create(struct wl_client *client,
uint32_t version, uint32_t id, struct wlr_renderer *renderer);
/**
* Create a new subsurface resource with the provided new ID.
*/
struct wlr_subsurface *subsurface_create(struct wlr_surface *surface,
struct wlr_surface *parent, uint32_t version, uint32_t id);
#endif

View file

@ -20,7 +20,8 @@ void unmap_xdg_surface(struct wlr_xdg_surface *surface);
void reset_xdg_surface(struct wlr_xdg_surface *xdg_surface);
void destroy_xdg_surface(struct wlr_xdg_surface *surface);
void handle_xdg_surface_commit(struct wlr_surface *wlr_surface);
void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface);
void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state);
void create_xdg_positioner(struct wlr_xdg_client *client, uint32_t id);
struct wlr_xdg_positioner_resource *get_xdg_positioner_from_resource(

View file

@ -9,21 +9,167 @@
#ifndef WLR_TYPES_WLR_COMPOSITOR_H
#define WLR_TYPES_WLR_COMPOSITOR_H
#include <pixman.h>
#include <stdbool.h>
#include <stdint.h>
#include <time.h>
#include <wayland-server-core.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_output.h>
#include <wlr/util/addon.h>
#include <wlr/util/box.h>
struct wlr_surface;
struct wlr_subcompositor {
struct wl_global *global;
enum wlr_surface_state_field {
WLR_SURFACE_STATE_BUFFER = 1 << 0,
WLR_SURFACE_STATE_SURFACE_DAMAGE = 1 << 1,
WLR_SURFACE_STATE_BUFFER_DAMAGE = 1 << 2,
WLR_SURFACE_STATE_OPAQUE_REGION = 1 << 3,
WLR_SURFACE_STATE_INPUT_REGION = 1 << 4,
WLR_SURFACE_STATE_TRANSFORM = 1 << 5,
WLR_SURFACE_STATE_SCALE = 1 << 6,
WLR_SURFACE_STATE_FRAME_CALLBACK_LIST = 1 << 7,
WLR_SURFACE_STATE_VIEWPORT = 1 << 8,
};
struct wlr_surface_state {
uint32_t committed; // enum wlr_surface_state_field
// Sequence number of the surface state. Incremented on each commit, may
// overflow.
uint32_t seq;
struct wlr_buffer *buffer;
int32_t dx, dy; // relative to previous position
pixman_region32_t surface_damage, buffer_damage; // clipped to bounds
pixman_region32_t opaque, input;
enum wl_output_transform transform;
int32_t scale;
struct wl_list frame_callback_list; // wl_resource
int width, height; // in surface-local coordinates
int buffer_width, buffer_height;
struct wl_list subsurfaces_below;
struct wl_list subsurfaces_above;
/**
* The viewport is applied after the surface transform and scale.
*
* If has_src is true, the surface content is cropped to the provided
* rectangle. If has_dst is true, the surface content is scaled to the
* provided rectangle.
*/
struct {
bool has_src, has_dst;
// In coordinates after scale/transform are applied, but before the
// destination rectangle is applied
struct wlr_fbox src;
int dst_width, dst_height; // in surface-local coordinates
} viewport;
// Number of locks that prevent this surface state from being committed.
size_t cached_state_locks;
struct wl_list cached_state_link; // wlr_surface.cached
};
struct wlr_surface_role {
const char *name;
void (*commit)(struct wlr_surface *surface);
void (*precommit)(struct wlr_surface *surface,
const struct wlr_surface_state *state);
};
struct wlr_surface_output {
struct wlr_surface *surface;
struct wlr_output *output;
struct wl_list link; // wlr_surface::current_outputs
struct wl_listener bind;
struct wl_listener destroy;
};
struct wlr_surface {
struct wl_resource *resource;
struct wlr_renderer *renderer;
/**
* The surface's buffer, if any. A surface has an attached buffer when it
* commits with a non-null buffer in its pending state. A surface will not
* have a buffer if it has never committed one, has committed a null buffer,
* or something went wrong with uploading the buffer.
*/
struct wlr_client_buffer *buffer;
/**
* The buffer position, in surface-local units.
*/
int sx, sy;
/**
* The last commit's buffer damage, in buffer-local coordinates. This
* contains both the damage accumulated by the client via
* `wlr_surface_state.surface_damage` and `wlr_surface_state.buffer_damage`.
* If the buffer has been resized, the whole buffer is damaged.
*
* This region needs to be scaled and transformed into output coordinates,
* just like the buffer's texture. In addition, if the buffer has shrunk the
* old size needs to be damaged and if the buffer has moved the old and new
* positions need to be damaged.
*/
pixman_region32_t buffer_damage;
/**
* The last commit's damage caused by surface and its subsurfaces'
* movement, in surface-local coordinates.
*/
pixman_region32_t external_damage;
/**
* The current opaque region, in surface-local coordinates. It is clipped to
* the surface bounds. If the surface's buffer is using a fully opaque
* format, this is set to the whole surface.
*/
pixman_region32_t opaque_region;
/**
* The current input region, in surface-local coordinates. It is clipped to
* the surface bounds.
*/
pixman_region32_t input_region;
/**
* `current` contains the current, committed surface state. `pending`
* accumulates state changes from the client between commits and shouldn't
* be accessed by the compositor directly.
*/
struct wlr_surface_state current, pending;
struct wl_list cached; // wlr_surface_state.cached_link
const struct wlr_surface_role *role; // the lifetime-bound role or NULL
void *role_data; // role-specific data
struct {
struct wl_signal client_commit;
struct wl_signal commit;
struct wl_signal new_subsurface;
struct wl_signal destroy;
} events;
struct wl_list current_outputs; // wlr_surface_output::link
struct wlr_addon_set addons;
void *data;
// private state
struct wl_listener renderer_destroy;
struct {
int32_t scale;
enum wl_output_transform transform;
int width, height;
int buffer_width, buffer_height;
} previous;
};
struct wlr_renderer;
struct wlr_compositor {
struct wl_global *global;
struct wlr_renderer *renderer;
struct wlr_subcompositor subcompositor;
struct wl_listener display_destroy;
struct {
@ -32,16 +178,125 @@ struct wlr_compositor {
} events;
};
typedef void (*wlr_surface_iterator_func_t)(struct wlr_surface *surface,
int sx, int sy, void *data);
/**
* Set the lifetime role for this surface. Returns 0 on success or -1 if the
* role cannot be set.
*/
bool wlr_surface_set_role(struct wlr_surface *surface,
const struct wlr_surface_role *role, void *role_data,
struct wl_resource *error_resource, uint32_t error_code);
/**
* Whether or not this surface currently has an attached buffer. A surface has
* an attached buffer when it commits with a non-null buffer in its pending
* state. A surface will not have a buffer if it has never committed one, has
* committed a null buffer, or something went wrong with uploading the buffer.
*/
bool wlr_surface_has_buffer(struct wlr_surface *surface);
/**
* Get the texture of the buffer currently attached to this surface. Returns
* NULL if no buffer is currently attached or if something went wrong with
* uploading the buffer.
*/
struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface);
/**
* Get the root of the subsurface tree for this surface. Can return NULL if
* a surface in the tree has been destroyed.
*/
struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface);
/**
* Check if the surface accepts input events at the given surface-local
* coordinates. Does not check the surface's subsurfaces.
*/
bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
double sx, double sy);
/**
* Find a surface in this surface's tree that accepts input events and has all
* parents mapped (except this surface, which can be unmapped) at the given
* surface-local coordinates. Returns the surface and coordinates in the leaf
* surface coordinate system or NULL if no surface is found at that location.
*/
struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y);
void wlr_surface_send_enter(struct wlr_surface *surface,
struct wlr_output *output);
void wlr_surface_send_leave(struct wlr_surface *surface,
struct wlr_output *output);
void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when);
/**
* Get the bounding box that contains the surface and all subsurfaces in
* surface coordinates.
* X and y may be negative, if there are subsurfaces with negative position.
*/
void wlr_surface_get_extends(struct wlr_surface *surface, struct wlr_box *box);
/**
* Get the wlr_surface corresponding to a wl_surface resource. This asserts
* that the resource is a valid wl_surface resource created by wlroots and
* will never return NULL.
*/
struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource);
/**
* Call `iterator` on each mapped surface in the surface tree (whether or not
* this surface is mapped), with the surface's position relative to the root
* surface. The function is called from root to leaves (in rendering order).
*/
void wlr_surface_for_each_surface(struct wlr_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data);
/**
* Get the effective surface damage in surface-local coordinate space. Besides
* buffer damage, this includes damage induced by resizing and moving the
* surface and its subsurfaces. The resulting damage is not expected to be
* bounded by the surface itself.
*/
void wlr_surface_get_effective_damage(struct wlr_surface *surface,
pixman_region32_t *damage);
/**
* Get the source rectangle describing the region of the buffer that needs to
* be sampled to render this surface's current state. The box is in
* buffer-local coordinates.
*
* If the viewport's source rectangle is unset, the position is zero and the
* size is the buffer's.
*/
void wlr_surface_get_buffer_source_box(struct wlr_surface *surface,
struct wlr_fbox *box);
/**
* Acquire a lock for the pending surface state.
*
* The state won't be committed before the caller releases the lock. Instead,
* the state becomes cached. The caller needs to use wlr_surface_unlock_cached
* to release the lock.
*
* Returns a surface commit sequence number for the cached state.
*/
uint32_t wlr_surface_lock_pending(struct wlr_surface *surface);
/**
* Release a lock for a cached state.
*
* Callers should not assume that the cached state will immediately be
* committed. Another caller may still have an active lock.
*/
void wlr_surface_unlock_cached(struct wlr_surface *surface, uint32_t seq);
struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
struct wlr_renderer *renderer);
bool wlr_surface_is_subsurface(struct wlr_surface *surface);
/**
* Get a subsurface from a surface. Can return NULL if the subsurface has been
* destroyed.
*/
struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
struct wlr_surface *surface);
#endif

View file

@ -36,10 +36,13 @@ enum wlr_foreign_toplevel_handle_v1_state {
struct wlr_foreign_toplevel_handle_v1_output {
struct wl_list link; // wlr_foreign_toplevel_handle_v1::outputs
struct wl_listener output_destroy;
struct wlr_output *output;
struct wlr_foreign_toplevel_handle_v1 *toplevel;
// private state
struct wl_listener output_bind;
struct wl_listener output_destroy;
};
struct wlr_foreign_toplevel_handle_v1 {

View file

@ -12,7 +12,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_compositor.h>
#include "wlr-layer-shell-unstable-v1-protocol.h"
/**

View file

@ -11,7 +11,8 @@
#include <wayland-server-core.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_surface.h>
struct wlr_surface;
struct wlr_pointer_gestures_v1 {
struct wl_global *global;

View file

@ -21,7 +21,7 @@
#include <pixman.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_compositor.h>
struct wlr_output;
struct wlr_output_layout;

View file

@ -14,7 +14,8 @@
#include <wlr/types/wlr_input_device.h>
#include <wlr/types/wlr_keyboard.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_surface.h>
struct wlr_surface;
#define WLR_SERIAL_RINGSET_SIZE 128

View file

@ -0,0 +1,77 @@
/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
#ifndef WLR_USE_UNSTABLE
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif
#ifndef WLR_TYPES_WLR_SUBCOMPOSITOR_H
#define WLR_TYPES_WLR_SUBCOMPOSITOR_H
#include <stdbool.h>
#include <stdint.h>
#include <wayland-server-core.h>
struct wlr_surface;
/**
* The sub-surface state describing the sub-surface's relationship with its
* parent. Contrary to other states, this one is not applied on surface commit.
* Instead, it's applied on parent surface commit.
*/
struct wlr_subsurface_parent_state {
int32_t x, y;
struct wl_list link;
};
struct wlr_subsurface {
struct wl_resource *resource;
struct wlr_surface *surface;
struct wlr_surface *parent;
struct wlr_subsurface_parent_state current, pending;
uint32_t cached_seq;
bool has_cache;
bool synchronized;
bool reordered;
bool mapped;
bool added;
struct wl_listener surface_destroy;
struct wl_listener surface_client_commit;
struct wl_listener parent_destroy;
struct {
struct wl_signal destroy;
struct wl_signal map;
struct wl_signal unmap;
} events;
void *data;
};
struct wlr_subcompositor {
struct wl_global *global;
struct wl_listener display_destroy;
struct {
struct wl_signal destroy;
} events;
};
bool wlr_surface_is_subsurface(struct wlr_surface *surface);
/**
* Get a subsurface from a surface. Can return NULL if the subsurface has been
* destroyed.
*/
struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
struct wlr_surface *surface);
struct wlr_subcompositor *wlr_subcompositor_create(struct wl_display *display);
#endif

View file

@ -1,320 +1,4 @@
/*
* This an unstable interface of wlroots. No guarantees are made regarding the
* future consistency of this API.
*/
#ifndef WLR_USE_UNSTABLE
#error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
#endif
#warning "wlr/types/wlr_surface.h has been deprecated and will be removed in the future. Use wlr/types/wlr_compositor.h and wlr/types/wlr_subcompositor.h."
#ifndef WLR_TYPES_WLR_SURFACE_H
#define WLR_TYPES_WLR_SURFACE_H
#include <pixman.h>
#include <stdbool.h>
#include <stdint.h>
#include <time.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_output.h>
#include <wlr/util/addon.h>
#include <wlr/util/box.h>
enum wlr_surface_state_field {
WLR_SURFACE_STATE_BUFFER = 1 << 0,
WLR_SURFACE_STATE_SURFACE_DAMAGE = 1 << 1,
WLR_SURFACE_STATE_BUFFER_DAMAGE = 1 << 2,
WLR_SURFACE_STATE_OPAQUE_REGION = 1 << 3,
WLR_SURFACE_STATE_INPUT_REGION = 1 << 4,
WLR_SURFACE_STATE_TRANSFORM = 1 << 5,
WLR_SURFACE_STATE_SCALE = 1 << 6,
WLR_SURFACE_STATE_FRAME_CALLBACK_LIST = 1 << 7,
WLR_SURFACE_STATE_VIEWPORT = 1 << 8,
};
struct wlr_surface_state {
uint32_t committed; // enum wlr_surface_state_field
// Sequence number of the surface state. Incremented on each commit, may
// overflow.
uint32_t seq;
struct wlr_buffer *buffer;
int32_t dx, dy; // relative to previous position
pixman_region32_t surface_damage, buffer_damage; // clipped to bounds
pixman_region32_t opaque, input;
enum wl_output_transform transform;
int32_t scale;
struct wl_list frame_callback_list; // wl_resource
int width, height; // in surface-local coordinates
int buffer_width, buffer_height;
struct wl_list subsurfaces_below;
struct wl_list subsurfaces_above;
/**
* The viewport is applied after the surface transform and scale.
*
* If has_src is true, the surface content is cropped to the provided
* rectangle. If has_dst is true, the surface content is scaled to the
* provided rectangle.
*/
struct {
bool has_src, has_dst;
// In coordinates after scale/transform are applied, but before the
// destination rectangle is applied
struct wlr_fbox src;
int dst_width, dst_height; // in surface-local coordinates
} viewport;
// Number of locks that prevent this surface state from being committed.
size_t cached_state_locks;
struct wl_list cached_state_link; // wlr_surface.cached
};
struct wlr_surface_role {
const char *name;
void (*commit)(struct wlr_surface *surface);
void (*precommit)(struct wlr_surface *surface);
};
struct wlr_surface_output {
struct wlr_surface *surface;
struct wlr_output *output;
struct wl_list link; // wlr_surface::current_outputs
struct wl_listener bind;
struct wl_listener destroy;
};
struct wlr_surface {
struct wl_resource *resource;
struct wlr_renderer *renderer;
/**
* The surface's buffer, if any. A surface has an attached buffer when it
* commits with a non-null buffer in its pending state. A surface will not
* have a buffer if it has never committed one, has committed a null buffer,
* or something went wrong with uploading the buffer.
*/
struct wlr_client_buffer *buffer;
/**
* The buffer position, in surface-local units.
*/
int sx, sy;
/**
* The last commit's buffer damage, in buffer-local coordinates. This
* contains both the damage accumulated by the client via
* `wlr_surface_state.surface_damage` and `wlr_surface_state.buffer_damage`.
* If the buffer has been resized, the whole buffer is damaged.
*
* This region needs to be scaled and transformed into output coordinates,
* just like the buffer's texture. In addition, if the buffer has shrunk the
* old size needs to be damaged and if the buffer has moved the old and new
* positions need to be damaged.
*/
pixman_region32_t buffer_damage;
/**
* The last commit's damage caused by surface and its subsurfaces'
* movement, in surface-local coordinates.
*/
pixman_region32_t external_damage;
/**
* The current opaque region, in surface-local coordinates. It is clipped to
* the surface bounds. If the surface's buffer is using a fully opaque
* format, this is set to the whole surface.
*/
pixman_region32_t opaque_region;
/**
* The current input region, in surface-local coordinates. It is clipped to
* the surface bounds.
*/
pixman_region32_t input_region;
/**
* `current` contains the current, committed surface state. `pending`
* accumulates state changes from the client between commits and shouldn't
* be accessed by the compositor directly.
*/
struct wlr_surface_state current, pending;
struct wl_list cached; // wlr_surface_state.cached_link
const struct wlr_surface_role *role; // the lifetime-bound role or NULL
void *role_data; // role-specific data
struct {
struct wl_signal commit;
struct wl_signal new_subsurface;
struct wl_signal destroy;
} events;
struct wl_list current_outputs; // wlr_surface_output::link
struct wlr_addon_set addons;
void *data;
// private state
struct wl_listener renderer_destroy;
struct {
int32_t scale;
enum wl_output_transform transform;
int width, height;
int buffer_width, buffer_height;
} previous;
};
/**
* The sub-surface state describing the sub-surface's relationship with its
* parent. Contrary to other states, this one is not applied on surface commit.
* Instead, it's applied on parent surface commit.
*/
struct wlr_subsurface_parent_state {
int32_t x, y;
struct wl_list link;
};
struct wlr_subsurface {
struct wl_resource *resource;
struct wlr_surface *surface;
struct wlr_surface *parent;
struct wlr_subsurface_parent_state current, pending;
uint32_t cached_seq;
bool has_cache;
bool synchronized;
bool reordered;
bool mapped;
bool added;
struct wl_listener surface_destroy;
struct wl_listener parent_destroy;
struct {
struct wl_signal destroy;
struct wl_signal map;
struct wl_signal unmap;
} events;
void *data;
};
typedef void (*wlr_surface_iterator_func_t)(struct wlr_surface *surface,
int sx, int sy, void *data);
/**
* Set the lifetime role for this surface. Returns 0 on success or -1 if the
* role cannot be set.
*/
bool wlr_surface_set_role(struct wlr_surface *surface,
const struct wlr_surface_role *role, void *role_data,
struct wl_resource *error_resource, uint32_t error_code);
/**
* Whether or not this surface currently has an attached buffer. A surface has
* an attached buffer when it commits with a non-null buffer in its pending
* state. A surface will not have a buffer if it has never committed one, has
* committed a null buffer, or something went wrong with uploading the buffer.
*/
bool wlr_surface_has_buffer(struct wlr_surface *surface);
/**
* Get the texture of the buffer currently attached to this surface. Returns
* NULL if no buffer is currently attached or if something went wrong with
* uploading the buffer.
*/
struct wlr_texture *wlr_surface_get_texture(struct wlr_surface *surface);
/**
* Get the root of the subsurface tree for this surface. Can return NULL if
* a surface in the tree has been destroyed.
*/
struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface);
/**
* Check if the surface accepts input events at the given surface-local
* coordinates. Does not check the surface's subsurfaces.
*/
bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
double sx, double sy);
/**
* Find a surface in this surface's tree that accepts input events and has all
* parents mapped (except this surface, which can be unmapped) at the given
* surface-local coordinates. Returns the surface and coordinates in the leaf
* surface coordinate system or NULL if no surface is found at that location.
*/
struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y);
void wlr_surface_send_enter(struct wlr_surface *surface,
struct wlr_output *output);
void wlr_surface_send_leave(struct wlr_surface *surface,
struct wlr_output *output);
void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when);
/**
* Get the bounding box that contains the surface and all subsurfaces in
* surface coordinates.
* X and y may be negative, if there are subsurfaces with negative position.
*/
void wlr_surface_get_extends(struct wlr_surface *surface, struct wlr_box *box);
/**
* Get the wlr_surface corresponding to a wl_surface resource. This asserts
* that the resource is a valid wl_surface resource created by wlroots and
* will never return NULL.
*/
struct wlr_surface *wlr_surface_from_resource(struct wl_resource *resource);
/**
* Call `iterator` on each mapped surface in the surface tree (whether or not
* this surface is mapped), with the surface's position relative to the root
* surface. The function is called from root to leaves (in rendering order).
*/
void wlr_surface_for_each_surface(struct wlr_surface *surface,
wlr_surface_iterator_func_t iterator, void *user_data);
/**
* Get the effective surface damage in surface-local coordinate space. Besides
* buffer damage, this includes damage induced by resizing and moving the
* surface and its subsurfaces. The resulting damage is not expected to be
* bounded by the surface itself.
*/
void wlr_surface_get_effective_damage(struct wlr_surface *surface,
pixman_region32_t *damage);
/**
* Get the source rectangle describing the region of the buffer that needs to
* be sampled to render this surface's current state. The box is in
* buffer-local coordinates.
*
* If the viewport's source rectangle is unset, the position is zero and the
* size is the buffer's.
*/
void wlr_surface_get_buffer_source_box(struct wlr_surface *surface,
struct wlr_fbox *box);
/**
* Acquire a lock for the pending surface state.
*
* The state won't be committed before the caller releases the lock. Instead,
* the state becomes cached. The caller needs to use wlr_surface_unlock_cached
* to release the lock.
*
* Returns a surface commit sequence number for the cached state.
*/
uint32_t wlr_surface_lock_pending(struct wlr_surface *surface);
/**
* Release a lock for a cached state.
*
* Callers should not assume that the cached state will immediately be
* committed. Another caller may still have an active lock.
*/
void wlr_surface_unlock_cached(struct wlr_surface *surface, uint32_t seq);
#endif
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_subcompositor.h>

View file

@ -11,9 +11,10 @@
#include <wayland-server-core.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/box.h>
struct wlr_surface;
enum wlr_text_input_v3_features {
WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT = 1 << 0,
WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE = 1 << 1,

View file

@ -10,6 +10,7 @@
#define WLR_TYPES_WLR_XDG_SHELL_H
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/box.h>
#include "xdg-shell-protocol.h"

View file

@ -343,22 +343,40 @@ VkPhysicalDevice vulkan_find_drm_phdev(struct wlr_vk_instance *ini, int drm_fd)
}
const char *name = VK_EXT_PHYSICAL_DEVICE_DRM_EXTENSION_NAME;
if (find_extensions(avail_ext_props, avail_extc, &name, 1) != NULL) {
bool has_drm_props = find_extensions(avail_ext_props, avail_extc, &name, 1) == NULL;
name = VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME;
bool has_driver_props = find_extensions(avail_ext_props, avail_extc, &name, 1) == NULL;
VkPhysicalDeviceProperties2 props = {0};
props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
VkPhysicalDeviceDrmPropertiesEXT drm_props = {0};
drm_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT;
if (has_drm_props) {
drm_props.pNext = props.pNext;
props.pNext = &drm_props;
}
VkPhysicalDeviceDriverPropertiesKHR driver_props = {0};
driver_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
if (has_driver_props) {
driver_props.pNext = props.pNext;
props.pNext = &driver_props;
}
vkGetPhysicalDeviceProperties2(phdev, &props);
if (has_driver_props) {
wlr_log(WLR_INFO, " Driver name: %s (%s)", driver_props.driverName, driver_props.driverInfo);
}
if (!has_drm_props) {
wlr_log(WLR_DEBUG, " Ignoring physical device \"%s\": "
"VK_EXT_physical_device_drm not supported",
phdev_props.deviceName);
continue;
}
VkPhysicalDeviceDrmPropertiesEXT drm_props = {0};
drm_props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT;
VkPhysicalDeviceProperties2 props = {0};
props.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
props.pNext = &drm_props;
vkGetPhysicalDeviceProperties2(phdev, &props);
dev_t primary_devid = makedev(drm_props.primaryMajor, drm_props.primaryMinor);
dev_t render_devid = makedev(drm_props.renderMajor, drm_props.renderMinor);
if (primary_devid == drm_stat.st_rdev ||

View file

@ -20,6 +20,7 @@
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/types/wlr_xcursor_manager.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
@ -611,7 +612,8 @@ static void begin_interactive(struct tinywl_view *view,
struct tinywl_server *server = view->server;
struct wlr_surface *focused_surface =
server->seat->pointer_state.focused_surface;
if (view->xdg_surface->surface != focused_surface) {
if (view->xdg_surface->surface !=
wlr_surface_get_root_surface(focused_surface)) {
/* Deny move/resize requests from unfocused clients. */
return;
}
@ -756,12 +758,14 @@ int main(int argc, char *argv[]) {
server.renderer);
/* This creates some hands-off wlroots interfaces. The compositor is
* necessary for clients to allocate surfaces and the data device manager
* necessary for clients to allocate surfaces, the subcompositor allows to
* assign the role of subsurfaces to surfaces and the data device manager
* handles the clipboard. Each of these wlroots interfaces has room for you
* to dig your fingers in and play with their behavior if you want. Note that
* the clients cannot set the selection directly without compositor approval,
* see the handling of the request_set_selection event below.*/
wlr_compositor_create(server.wl_display, server.renderer);
wlr_subcompositor_create(server.wl_display);
wlr_data_device_manager_create(server.wl_display);
/* Creates an output layout, which a wlroots utility for working with an

View file

@ -4,6 +4,7 @@
#include <strings.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>

View file

@ -4,6 +4,7 @@
#include <strings.h>
#include <unistd.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>

View file

@ -59,7 +59,7 @@ wlr_files += files(
'wlr_relative_pointer_v1.c',
'wlr_screencopy_v1.c',
'wlr_server_decoration.c',
'wlr_surface.c',
'wlr_subcompositor.c',
'wlr_switch.c',
'wlr_tablet_pad.c',
'wlr_tablet_tool.c',

View file

@ -3,8 +3,8 @@
#include <stdlib.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include "render/allocator/allocator.h"
#include "render/swapchain.h"

View file

@ -4,8 +4,8 @@
#include <drm_fourcc.h>
#include <stdlib.h>
#include <wlr/interfaces/wlr_output.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include "render/allocator/allocator.h"
#include "render/swapchain.h"

View file

@ -1,6 +1,7 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_subcompositor.h>
#include <wlr/util/addon.h>
/**
@ -13,15 +14,20 @@ struct wlr_scene_subsurface_tree {
struct wlr_surface *surface;
struct wlr_scene_surface *scene_surface;
struct wlr_scene_subsurface_tree *parent; // NULL for the top-level surface
struct wlr_addon surface_addon; // only set if there's a parent
struct wl_listener tree_destroy;
struct wl_listener surface_destroy;
struct wl_listener surface_commit;
struct wl_listener surface_map;
struct wl_listener surface_unmap;
struct wl_listener surface_new_subsurface;
struct wlr_scene_subsurface_tree *parent; // NULL for the top-level surface
// Only valid if the surface is a sub-surface
struct wlr_addon surface_addon;
struct wl_listener subsurface_destroy;
struct wl_listener subsurface_map;
struct wl_listener subsurface_unmap;
};
static void subsurface_tree_handle_tree_destroy(struct wl_listener *listener,
@ -31,23 +37,17 @@ static void subsurface_tree_handle_tree_destroy(struct wl_listener *listener,
// tree and scene_surface will be cleaned up by scene_node_finish
if (subsurface_tree->parent) {
wlr_addon_finish(&subsurface_tree->surface_addon);
wl_list_remove(&subsurface_tree->subsurface_destroy.link);
wl_list_remove(&subsurface_tree->subsurface_map.link);
wl_list_remove(&subsurface_tree->subsurface_unmap.link);
}
wl_list_remove(&subsurface_tree->tree_destroy.link);
wl_list_remove(&subsurface_tree->surface_destroy.link);
wl_list_remove(&subsurface_tree->surface_commit.link);
wl_list_remove(&subsurface_tree->surface_map.link);
wl_list_remove(&subsurface_tree->surface_unmap.link);
wl_list_remove(&subsurface_tree->surface_new_subsurface.link);
free(subsurface_tree);
}
static void subsurface_tree_handle_surface_destroy(struct wl_listener *listener,
void *data) {
struct wlr_scene_subsurface_tree *subsurface_tree =
wl_container_of(listener, subsurface_tree, surface_destroy);
wlr_scene_node_destroy(&subsurface_tree->tree->node);
}
static const struct wlr_addon_interface subsurface_tree_addon_impl;
static struct wlr_scene_subsurface_tree *subsurface_tree_from_subsurface(
@ -97,6 +97,13 @@ static void subsurface_tree_reconfigure(
}
}
static void subsurface_tree_handle_surface_destroy(struct wl_listener *listener,
void *data) {
struct wlr_scene_subsurface_tree *subsurface_tree =
wl_container_of(listener, subsurface_tree, surface_destroy);
wlr_scene_node_destroy(&subsurface_tree->tree->node);
}
static void subsurface_tree_handle_surface_commit(struct wl_listener *listener,
void *data) {
struct wlr_scene_subsurface_tree *subsurface_tree =
@ -106,18 +113,25 @@ static void subsurface_tree_handle_surface_commit(struct wl_listener *listener,
subsurface_tree_reconfigure(subsurface_tree);
}
static void subsurface_tree_handle_surface_map(struct wl_listener *listener,
static void subsurface_tree_handle_subsurface_destroy(struct wl_listener *listener,
void *data) {
struct wlr_scene_subsurface_tree *subsurface_tree =
wl_container_of(listener, subsurface_tree, surface_map);
wl_container_of(listener, subsurface_tree, subsurface_destroy);
wlr_scene_node_destroy(&subsurface_tree->tree->node);
}
static void subsurface_tree_handle_subsurface_map(struct wl_listener *listener,
void *data) {
struct wlr_scene_subsurface_tree *subsurface_tree =
wl_container_of(listener, subsurface_tree, subsurface_map);
wlr_scene_node_set_enabled(&subsurface_tree->tree->node, true);
}
static void subsurface_tree_handle_surface_unmap(struct wl_listener *listener,
static void subsurface_tree_handle_subsurface_unmap(struct wl_listener *listener,
void *data) {
struct wlr_scene_subsurface_tree *subsurface_tree =
wl_container_of(listener, subsurface_tree, surface_unmap);
wl_container_of(listener, subsurface_tree, subsurface_unmap);
wlr_scene_node_set_enabled(&subsurface_tree->tree->node, false);
}
@ -151,8 +165,14 @@ static bool subsurface_tree_create_subsurface(
wlr_addon_init(&child->surface_addon, &subsurface->surface->addons,
parent, &subsurface_tree_addon_impl);
wl_signal_add(&subsurface->events.map, &child->surface_map);
wl_signal_add(&subsurface->events.unmap, &child->surface_unmap);
child->subsurface_destroy.notify = subsurface_tree_handle_subsurface_destroy;
wl_signal_add(&subsurface->events.destroy, &child->subsurface_destroy);
child->subsurface_map.notify = subsurface_tree_handle_subsurface_map;
wl_signal_add(&subsurface->events.map, &child->subsurface_map);
child->subsurface_unmap.notify = subsurface_tree_handle_subsurface_unmap;
wl_signal_add(&subsurface->events.unmap, &child->subsurface_unmap);
return true;
}
@ -214,12 +234,6 @@ static struct wlr_scene_subsurface_tree *scene_surface_tree_create(
subsurface_tree->surface_commit.notify = subsurface_tree_handle_surface_commit;
wl_signal_add(&surface->events.commit, &subsurface_tree->surface_commit);
subsurface_tree->surface_map.notify = subsurface_tree_handle_surface_map;
wl_list_init(&subsurface_tree->surface_map.link);
subsurface_tree->surface_unmap.notify = subsurface_tree_handle_surface_unmap;
wl_list_init(&subsurface_tree->surface_unmap.link);
subsurface_tree->surface_new_subsurface.notify =
subsurface_tree_handle_surface_new_subsurface;
wl_signal_add(&surface->events.new_subsurface,

View file

@ -3,11 +3,11 @@
#include <string.h>
#include <wlr/backend.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_scene.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#include "util/signal.h"

View file

@ -3,6 +3,7 @@
#include <stdlib.h>
#include <time.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/util/log.h>

View file

@ -4,6 +4,7 @@
#include <string.h>
#include <time.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/util/log.h>
#include "types/wlr_seat.h"

View file

@ -4,6 +4,7 @@
#include <string.h>
#include <time.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_input_device.h>
#include <wlr/util/log.h>
#include "types/wlr_seat.h"

View file

@ -7,6 +7,7 @@
#include <stdlib.h>
#include <types/wlr_tablet_v2.h>
#include <wayland-util.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_tablet_tool.h>
#include <wlr/types/wlr_tablet_pad.h>
#include <wlr/types/wlr_tablet_v2.h>

View file

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <types/wlr_tablet_v2.h>
#include <wayland-util.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_tablet_tool.h>
#include <wlr/types/wlr_tablet_v2.h>
#include <wlr/util/log.h>

View file

@ -9,6 +9,7 @@
#include <stdlib.h>
#include <types/wlr_tablet_v2.h>
#include <wayland-util.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_tablet_tool.h>
#include <wlr/types/wlr_tablet_v2.h>
#include <wlr/util/log.h>

File diff suppressed because it is too large Load diff

View file

@ -3,6 +3,7 @@
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_foreign_toplevel_management_v1.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/util/log.h>
@ -256,6 +257,23 @@ static void toplevel_send_output(struct wlr_foreign_toplevel_handle_v1 *toplevel
toplevel_update_idle_source(toplevel);
}
static void toplevel_handle_output_bind(struct wl_listener *listener,
void *data) {
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output =
wl_container_of(listener, toplevel_output, output_bind);
struct wlr_output_event_bind *event = data;
struct wl_client *client = wl_resource_get_client(event->resource);
struct wl_resource *resource;
wl_resource_for_each(resource, &toplevel_output->toplevel->resources) {
if (wl_resource_get_client(resource) == client) {
send_output_to_resource(resource, toplevel_output->output, true);
}
}
toplevel_update_idle_source(toplevel_output->toplevel);
}
static void toplevel_handle_output_destroy(struct wl_listener *listener,
void *data) {
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output =
@ -285,6 +303,9 @@ void wlr_foreign_toplevel_handle_v1_output_enter(
toplevel_output->toplevel = toplevel;
wl_list_insert(&toplevel->outputs, &toplevel_output->link);
toplevel_output->output_bind.notify = toplevel_handle_output_bind;
wl_signal_add(&output->events.bind, &toplevel_output->output_bind);
toplevel_output->output_destroy.notify = toplevel_handle_output_destroy;
wl_signal_add(&output->events.destroy, &toplevel_output->output_destroy);
@ -294,6 +315,7 @@ void wlr_foreign_toplevel_handle_v1_output_enter(
static void toplevel_output_destroy(
struct wlr_foreign_toplevel_handle_v1_output *toplevel_output) {
wl_list_remove(&toplevel_output->link);
wl_list_remove(&toplevel_output->output_bind.link);
wl_list_remove(&toplevel_output->output_destroy.link);
free(toplevel_output);
}

View file

@ -1,8 +1,8 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_fullscreen_shell_v1.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include "util/signal.h"

View file

@ -3,8 +3,8 @@
#include <util/signal.h>
#include <wayland-server-core.h>
#include <wayland-util.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_idle_inhibit_v1.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include "idle-inhibit-unstable-v1-protocol.h"

View file

@ -6,8 +6,8 @@
#include <sys/mman.h>
#include <unistd.h>
#include <wayland-util.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_input_method_v2.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include <xkbcommon/xkbcommon.h>
#include "input-method-unstable-v2-protocol.h"
@ -157,9 +157,22 @@ static void popup_surface_surface_role_commit(struct wlr_surface *surface) {
&& popup_surface->input_method->client_active);
}
static void popup_surface_surface_role_precommit(struct wlr_surface *surface,
const struct wlr_surface_state *state) {
struct wlr_input_popup_surface_v2 *popup_surface = surface->role_data;
if (popup_surface == NULL) {
return;
}
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
popup_surface_set_mapped(popup_surface, false);
}
}
static const struct wlr_surface_role input_popup_surface_v2_role = {
.name = "zwp_input_popup_surface_v2",
.commit = popup_surface_surface_role_commit,
.precommit = popup_surface_surface_role_precommit,
};
bool wlr_surface_is_input_popup_surface_v2(struct wlr_surface *surface) {

View file

@ -1,6 +1,7 @@
#include <assert.h>
#include <stdlib.h>
#include <util/signal.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_keyboard_shortcuts_inhibit_v1.h>
#include "keyboard-shortcuts-inhibit-unstable-v1-protocol.h"

View file

@ -3,9 +3,9 @@
#include <stdlib.h>
#include <string.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_layer_shell_v1.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
#include "util/signal.h"
@ -375,15 +375,15 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
}
}
static void layer_surface_role_precommit(struct wlr_surface *wlr_surface) {
static void layer_surface_role_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state) {
struct wlr_layer_surface_v1 *surface =
wlr_layer_surface_v1_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
wlr_surface->pending.buffer == NULL) {
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
if (surface->configured && surface->mapped) {
layer_surface_unmap(surface);

View file

@ -5,8 +5,8 @@
#include <sys/mman.h>
#include <unistd.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_linux_dmabuf_v1.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include "linux-dmabuf-unstable-v1-protocol.h"
#include "render/drm_format_set.h"

View file

@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_pointer_constraints_v1.h>
#include <wlr/types/wlr_region.h>
#include <wlr/util/box.h>

View file

@ -5,6 +5,7 @@
#include <assert.h>
#include <stdlib.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_pointer.h>
#include <wlr/types/wlr_pointer_gestures_v1.h>
#include <wlr/util/log.h>

View file

@ -3,8 +3,8 @@
#include <stdlib.h>
#include <string.h>
#include <wlr/backend.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_presentation_time.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/addon.h>
#include "presentation-time-protocol.h"
#include "util/signal.h"

View file

@ -1,7 +1,7 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_server_decoration.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/log.h>
#include "server-decoration-protocol.h"
#include "util/signal.h"

483
types/wlr_subcompositor.c Normal file
View file

@ -0,0 +1,483 @@
#include <assert.h>
#include <stdlib.h>
#include <wayland-server-core.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_subcompositor.h>
#include "types/wlr_region.h"
#include "util/signal.h"
#define SUBCOMPOSITOR_VERSION 1
static bool subsurface_is_synchronized(struct wlr_subsurface *subsurface) {
while (subsurface != NULL) {
if (subsurface->synchronized) {
return true;
}
if (!wlr_surface_is_subsurface(subsurface->parent)) {
break;
}
subsurface = wlr_subsurface_from_wlr_surface(subsurface->parent);
}
return false;
}
static void subsurface_unmap(struct wlr_subsurface *subsurface);
static void subsurface_destroy(struct wlr_subsurface *subsurface) {
if (subsurface == NULL) {
return;
}
if (subsurface->has_cache) {
wlr_surface_unlock_cached(subsurface->surface,
subsurface->cached_seq);
}
subsurface_unmap(subsurface);
wlr_signal_emit_safe(&subsurface->events.destroy, subsurface);
wl_list_remove(&subsurface->surface_destroy.link);
wl_list_remove(&subsurface->surface_client_commit.link);
wl_list_remove(&subsurface->current.link);
wl_list_remove(&subsurface->pending.link);
wl_list_remove(&subsurface->parent_destroy.link);
wl_resource_set_user_data(subsurface->resource, NULL);
if (subsurface->surface) {
subsurface->surface->role_data = NULL;
}
free(subsurface);
}
static const struct wl_subsurface_interface subsurface_implementation;
/**
* Get a wlr_subsurface from a wl_subsurface resource.
*
* Returns NULL if the subsurface is inert (e.g. the wl_surface object or the
* parent surface got destroyed).
*/
static struct wlr_subsurface *subsurface_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource, &wl_subsurface_interface,
&subsurface_implementation));
return wl_resource_get_user_data(resource);
}
static void subsurface_resource_destroy(struct wl_resource *resource) {
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
subsurface_destroy(subsurface);
}
static void subsurface_handle_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
static void subsurface_handle_set_position(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y) {
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
if (subsurface == NULL) {
return;
}
subsurface->pending.x = x;
subsurface->pending.y = y;
}
static struct wlr_subsurface *subsurface_find_sibling(
struct wlr_subsurface *subsurface, struct wlr_surface *surface) {
struct wlr_surface *parent = subsurface->parent;
struct wlr_subsurface *sibling;
wl_list_for_each(sibling, &parent->pending.subsurfaces_below, pending.link) {
if (sibling->surface == surface && sibling != subsurface) {
return sibling;
}
}
wl_list_for_each(sibling, &parent->pending.subsurfaces_above, pending.link) {
if (sibling->surface == surface && sibling != subsurface) {
return sibling;
}
}
return NULL;
}
static void subsurface_handle_place_above(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *sibling_resource) {
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
if (subsurface == NULL) {
return;
}
struct wlr_surface *sibling_surface =
wlr_surface_from_resource(sibling_resource);
struct wl_list *node;
if (sibling_surface == subsurface->parent) {
node = &subsurface->parent->pending.subsurfaces_above;
} else {
struct wlr_subsurface *sibling =
subsurface_find_sibling(subsurface, sibling_surface);
if (!sibling) {
wl_resource_post_error(subsurface->resource,
WL_SUBSURFACE_ERROR_BAD_SURFACE,
"%s: wl_surface@%" PRIu32 "is not a parent or sibling",
"place_above", wl_resource_get_id(sibling_resource));
return;
}
node = &sibling->pending.link;
}
wl_list_remove(&subsurface->pending.link);
wl_list_insert(node, &subsurface->pending.link);
subsurface->reordered = true;
}
static void subsurface_handle_place_below(struct wl_client *client,
struct wl_resource *resource, struct wl_resource *sibling_resource) {
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
if (subsurface == NULL) {
return;
}
struct wlr_surface *sibling_surface =
wlr_surface_from_resource(sibling_resource);
struct wl_list *node;
if (sibling_surface == subsurface->parent) {
node = &subsurface->parent->pending.subsurfaces_below;
} else {
struct wlr_subsurface *sibling =
subsurface_find_sibling(subsurface, sibling_surface);
if (!sibling) {
wl_resource_post_error(subsurface->resource,
WL_SUBSURFACE_ERROR_BAD_SURFACE,
"%s: wl_surface@%" PRIu32 " is not a parent or sibling",
"place_below", wl_resource_get_id(sibling_resource));
return;
}
node = &sibling->pending.link;
}
wl_list_remove(&subsurface->pending.link);
wl_list_insert(node->prev, &subsurface->pending.link);
subsurface->reordered = true;
}
static void subsurface_handle_set_sync(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
if (subsurface == NULL) {
return;
}
subsurface->synchronized = true;
}
static void subsurface_handle_set_desync(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_subsurface *subsurface = subsurface_from_resource(resource);
if (subsurface == NULL) {
return;
}
if (subsurface->synchronized) {
subsurface->synchronized = false;
if (!subsurface_is_synchronized(subsurface) &&
subsurface->has_cache) {
wlr_surface_unlock_cached(subsurface->surface,
subsurface->cached_seq);
subsurface->has_cache = false;
}
}
}
static const struct wl_subsurface_interface subsurface_implementation = {
.destroy = subsurface_handle_destroy,
.set_position = subsurface_handle_set_position,
.place_above = subsurface_handle_place_above,
.place_below = subsurface_handle_place_below,
.set_sync = subsurface_handle_set_sync,
.set_desync = subsurface_handle_set_desync,
};
/**
* Checks if this subsurface needs to be marked as mapped. This can happen if:
* - The subsurface has a buffer
* - Its parent is mapped
*/
static void subsurface_consider_map(struct wlr_subsurface *subsurface,
bool check_parent) {
if (subsurface->mapped || !wlr_surface_has_buffer(subsurface->surface)) {
return;
}
if (check_parent && wlr_surface_is_subsurface(subsurface->parent)) {
struct wlr_subsurface *parent =
wlr_subsurface_from_wlr_surface(subsurface->parent);
if (parent == NULL || !parent->mapped) {
return;
}
}
// Now we can map the subsurface
wlr_signal_emit_safe(&subsurface->events.map, subsurface);
subsurface->mapped = true;
// Try mapping all children too
struct wlr_subsurface *child;
wl_list_for_each(child, &subsurface->surface->current.subsurfaces_below,
current.link) {
subsurface_consider_map(child, false);
}
wl_list_for_each(child, &subsurface->surface->current.subsurfaces_above,
current.link) {
subsurface_consider_map(child, false);
}
}
static void subsurface_unmap(struct wlr_subsurface *subsurface) {
if (!subsurface->mapped) {
return;
}
wlr_signal_emit_safe(&subsurface->events.unmap, subsurface);
subsurface->mapped = false;
// Unmap all children
struct wlr_subsurface *child;
wl_list_for_each(child, &subsurface->surface->current.subsurfaces_below,
current.link) {
subsurface_unmap(child);
}
wl_list_for_each(child, &subsurface->surface->current.subsurfaces_above,
current.link) {
subsurface_unmap(child);
}
}
static void subsurface_role_commit(struct wlr_surface *surface) {
struct wlr_subsurface *subsurface =
wlr_subsurface_from_wlr_surface(surface);
if (subsurface == NULL) {
return;
}
subsurface_consider_map(subsurface, true);
}
static void subsurface_role_precommit(struct wlr_surface *surface,
const struct wlr_surface_state *state) {
struct wlr_subsurface *subsurface =
wlr_subsurface_from_wlr_surface(surface);
if (subsurface == NULL) {
return;
}
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
subsurface_unmap(subsurface);
}
}
const struct wlr_surface_role subsurface_role = {
.name = "wl_subsurface",
.commit = subsurface_role_commit,
.precommit = subsurface_role_precommit,
};
static void subsurface_handle_parent_destroy(struct wl_listener *listener,
void *data) {
struct wlr_subsurface *subsurface =
wl_container_of(listener, subsurface, parent_destroy);
// Once the parent is destroyed, the client has no way to use the
// wl_subsurface object anymore, so we can destroy it.
subsurface_destroy(subsurface);
}
static void subsurface_handle_surface_destroy(struct wl_listener *listener,
void *data) {
struct wlr_subsurface *subsurface =
wl_container_of(listener, subsurface, surface_destroy);
subsurface_destroy(subsurface);
}
static void subsurface_handle_surface_client_commit(
struct wl_listener *listener, void *data) {
struct wlr_subsurface *subsurface =
wl_container_of(listener, subsurface, surface_client_commit);
struct wlr_surface *surface = subsurface->surface;
if (subsurface_is_synchronized(subsurface)) {
if (subsurface->has_cache) {
// We already lock a previous commit. The prevents any future
// commit to be applied before we release the previous commit.
return;
}
subsurface->has_cache = true;
subsurface->cached_seq = wlr_surface_lock_pending(surface);
}
}
static struct wlr_subsurface *subsurface_create(struct wlr_surface *surface,
struct wlr_surface *parent, uint32_t version, uint32_t id) {
struct wl_client *client = wl_resource_get_client(surface->resource);
struct wlr_subsurface *subsurface =
calloc(1, sizeof(struct wlr_subsurface));
if (!subsurface) {
wl_client_post_no_memory(client);
return NULL;
}
subsurface->synchronized = true;
subsurface->surface = surface;
subsurface->resource =
wl_resource_create(client, &wl_subsurface_interface, version, id);
if (subsurface->resource == NULL) {
free(subsurface);
wl_client_post_no_memory(client);
return NULL;
}
wl_resource_set_implementation(subsurface->resource,
&subsurface_implementation, subsurface, subsurface_resource_destroy);
wl_signal_init(&subsurface->events.destroy);
wl_signal_init(&subsurface->events.map);
wl_signal_init(&subsurface->events.unmap);
wl_signal_add(&surface->events.destroy, &subsurface->surface_destroy);
subsurface->surface_destroy.notify = subsurface_handle_surface_destroy;
wl_signal_add(&surface->events.client_commit,
&subsurface->surface_client_commit);
subsurface->surface_client_commit.notify =
subsurface_handle_surface_client_commit;
// link parent
subsurface->parent = parent;
wl_signal_add(&parent->events.destroy, &subsurface->parent_destroy);
subsurface->parent_destroy.notify = subsurface_handle_parent_destroy;
wl_list_init(&subsurface->current.link);
wl_list_insert(parent->pending.subsurfaces_above.prev,
&subsurface->pending.link);
surface->role_data = subsurface;
return subsurface;
}
bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
return surface->role == &subsurface_role;
}
struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
struct wlr_surface *surface) {
assert(wlr_surface_is_subsurface(surface));
return (struct wlr_subsurface *)surface->role_data;
}
static void subcompositor_handle_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
static void subcompositor_handle_get_subsurface(struct wl_client *client,
struct wl_resource *resource, uint32_t id,
struct wl_resource *surface_resource,
struct wl_resource *parent_resource) {
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
struct wlr_surface *parent = wlr_surface_from_resource(parent_resource);
static const char msg[] = "get_subsurface: wl_subsurface@";
if (surface == parent) {
wl_resource_post_error(resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
"%s%" PRIu32 ": wl_surface@%" PRIu32 " cannot be its own parent",
msg, id, wl_resource_get_id(surface_resource));
return;
}
if (wlr_surface_is_subsurface(surface) &&
wlr_subsurface_from_wlr_surface(surface) != NULL) {
wl_resource_post_error(resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is already a sub-surface",
msg, id, wl_resource_get_id(surface_resource));
return;
}
if (wlr_surface_get_root_surface(parent) == surface) {
wl_resource_post_error(resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
"%s%" PRIu32 ": wl_surface@%" PRIu32 " is an ancestor of parent",
msg, id, wl_resource_get_id(surface_resource));
return;
}
if (!wlr_surface_set_role(surface, &subsurface_role, NULL,
resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE)) {
return;
}
subsurface_create(surface, parent, wl_resource_get_version(resource), id);
}
static const struct wl_subcompositor_interface subcompositor_impl = {
.destroy = subcompositor_handle_destroy,
.get_subsurface = subcompositor_handle_get_subsurface,
};
static void subcompositor_bind(struct wl_client *client, void *data,
uint32_t version, uint32_t id) {
struct wlr_subcompositor *subcompositor = data;
struct wl_resource *resource =
wl_resource_create(client, &wl_subcompositor_interface, 1, id);
if (resource == NULL) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(resource, &subcompositor_impl,
subcompositor, NULL);
}
static void subcompositor_handle_display_destroy(
struct wl_listener *listener, void *data) {
struct wlr_subcompositor *subcompositor =
wl_container_of(listener, subcompositor, display_destroy);
wlr_signal_emit_safe(&subcompositor->events.destroy, NULL);
wl_list_remove(&subcompositor->display_destroy.link);
wl_global_destroy(subcompositor->global);
free(subcompositor);
}
struct wlr_subcompositor *wlr_subcompositor_create(struct wl_display *display) {
struct wlr_subcompositor *subcompositor =
calloc(1, sizeof(*subcompositor));
if (!subcompositor) {
return NULL;
}
subcompositor->global = wl_global_create(display,
&wl_subcompositor_interface, SUBCOMPOSITOR_VERSION,
subcompositor, subcompositor_bind);
if (!subcompositor->global) {
free(subcompositor);
return NULL;
}
wl_signal_init(&subcompositor->events.destroy);
subcompositor->display_destroy.notify = subcompositor_handle_display_destroy;
wl_display_add_destroy_listener(display, &subcompositor->display_destroy);
return subcompositor;
}

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,7 @@
#include <assert.h>
#include <stdlib.h>
#include <stddef.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_text_input_v3.h>
#include <wlr/util/log.h>
#include "text-input-unstable-v3-protocol.h"

View file

@ -1,6 +1,6 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_viewporter.h>
#include <wlr/util/log.h>
#include "util/signal.h"

View file

@ -2,8 +2,8 @@
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_seat.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_xdg_activation_v1.h>
#include <wlr/util/log.h>
#include "util/signal.h"

View file

@ -338,15 +338,15 @@ void handle_xdg_surface_commit(struct wlr_surface *wlr_surface) {
}
}
void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface) {
void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state) {
struct wlr_xdg_surface *surface =
wlr_xdg_surface_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
wlr_surface->pending.buffer == NULL) {
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
if (surface->configured && surface->mapped) {
unmap_xdg_surface(surface);

View file

@ -5,9 +5,9 @@
#include <stdlib.h>
#include <unistd.h>
#include <wlr/config.h>
#include <wlr/types/wlr_compositor.h>
#include <wlr/types/wlr_data_device.h>
#include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/util/edges.h>
#include <wlr/util/log.h>
#include <wlr/xcursor.h>
@ -852,15 +852,15 @@ static void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) {
}
}
static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface) {
static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state) {
assert(wlr_surface->role == &xwayland_surface_role);
struct wlr_xwayland_surface *surface = wlr_surface->role_data;
if (surface == NULL) {
return;
}
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
wlr_surface->pending.buffer == NULL) {
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
if (surface->mapped) {
wlr_signal_emit_safe(&surface->events.unmap, surface);