Merge branch 'master' into xwayland-dnd

This commit is contained in:
Drew DeVault 2018-04-05 15:04:49 -04:00
commit 6710de9878
40 changed files with 991 additions and 258 deletions

View file

@ -10,6 +10,7 @@ lib_wlr_types = static_library(
'wlr_idle.c',
'wlr_idle_inhibit_v1.c',
'wlr_input_device.c',
'wlr_input_inhibitor.c',
'wlr_keyboard.c',
'wlr_layer_shell.c',
'wlr_linux_dmabuf.c',
@ -32,6 +33,7 @@ lib_wlr_types = static_library(
'wlr_xcursor_manager.c',
'wlr_xdg_shell_v6.c',
'wlr_xdg_shell.c',
'wlr_xdg_output.c',
),
include_directories: wlr_inc,
dependencies: [pixman, xkbcommon, wayland_server, wlr_protos],

View file

@ -7,6 +7,18 @@
#include <wlr/util/log.h>
#include "util/signal.h"
static const char *subsurface_role = "wl_subsurface";
bool wlr_surface_is_subsurface(struct wlr_surface *surface) {
return strcmp(surface->role, subsurface_role) == 0;
}
struct wlr_subsurface *wlr_subsurface_from_surface(
struct wlr_surface *surface) {
assert(wlr_surface_is_subsurface(surface));
return (struct wlr_subsurface *)surface->role_data;
}
static const struct wl_compositor_interface wl_compositor_impl;
static struct wlr_compositor *compositor_from_resource(struct wl_resource *resource) {
@ -126,7 +138,7 @@ static void subcompositor_get_subsurface(struct wl_client *client,
return;
}
if (wlr_surface_get_main_surface(parent) == surface) {
if (wlr_surface_get_root_surface(parent) == surface) {
wl_resource_post_error(resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE,
"%s%d: wl_surface@%d is an ancestor of parent",
@ -134,7 +146,7 @@ static void subcompositor_get_subsurface(struct wl_client *client,
return;
}
if (wlr_surface_set_role(surface, "wl_subsurface", resource,
if (wlr_surface_set_role(surface, subsurface_role, resource,
WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) {
return;
}
@ -144,6 +156,8 @@ static void subcompositor_get_subsurface(struct wl_client *client,
wl_resource_post_no_memory(resource);
return;
}
surface->role_data = surface->subsurface;
}

150
types/wlr_input_inhibitor.c Normal file
View file

@ -0,0 +1,150 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <wayland-server.h>
#include "wlr/types/wlr_input_inhibitor.h"
#include "wlr-input-inhibitor-unstable-v1-protocol.h"
static const struct zwlr_input_inhibit_manager_v1_interface inhibit_manager_implementation;
static struct zwlr_input_inhibitor_v1_interface input_inhibitor_implementation;
static struct wlr_input_inhibit_manager *input_inhibit_manager_from_resource(
struct wl_resource *resource) {
assert(wl_resource_instance_of(resource,
&zwlr_input_inhibit_manager_v1_interface,
&inhibit_manager_implementation)
|| wl_resource_instance_of(resource,
&zwlr_input_inhibitor_v1_interface,
&input_inhibitor_implementation));
return wl_resource_get_user_data(resource);
}
static void input_inhibit_manager_deactivate(
struct wlr_input_inhibit_manager *manager) {
if (manager->active_client == NULL && manager->active_inhibitor == NULL) {
return;
}
manager->active_client = NULL;
manager->active_inhibitor = NULL;
wl_signal_emit(&manager->events.deactivate, manager);
}
static void input_inhibitor_destroy(struct wl_client *client,
struct wl_resource *resource) {
struct wlr_input_inhibit_manager *manager =
input_inhibit_manager_from_resource(resource);
input_inhibit_manager_deactivate(manager);
wl_resource_destroy(resource);
}
static void input_inhibitor_resource_destroy(struct wl_resource *resource) {
struct wlr_input_inhibit_manager *manager =
input_inhibit_manager_from_resource(resource);
input_inhibit_manager_deactivate(manager);
}
static struct zwlr_input_inhibitor_v1_interface input_inhibitor_implementation = {
.destroy = input_inhibitor_destroy,
};
static void inhibit_manager_get_inhibitor(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
struct wlr_input_inhibit_manager *manager =
input_inhibit_manager_from_resource(resource);
if (manager->active_client || manager->active_inhibitor) {
wl_resource_post_error(resource,
ZWLR_INPUT_INHIBIT_MANAGER_V1_ERROR_ALREADY_INHIBITED,
"this compositor already has input inhibited");
return;
}
struct wl_resource *wl_resource = wl_resource_create(client,
&zwlr_input_inhibitor_v1_interface,
wl_resource_get_version(resource), id);
if (!wl_resource) {
wl_client_post_no_memory(client);
}
wl_resource_set_implementation(wl_resource, &input_inhibitor_implementation,
manager, input_inhibitor_resource_destroy);
manager->active_client = client;
manager->active_inhibitor = wl_resource;
wl_signal_emit(&manager->events.activate, manager);
}
static const struct zwlr_input_inhibit_manager_v1_interface inhibit_manager_implementation = {
.get_inhibitor = inhibit_manager_get_inhibitor
};
static void input_manager_resource_destroy(struct wl_resource *resource) {
struct wlr_input_inhibit_manager *manager =
input_inhibit_manager_from_resource(resource);
struct wl_client *client = wl_resource_get_client(resource);
if (manager->active_client == client) {
input_inhibit_manager_deactivate(manager);
}
}
static void inhibit_manager_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) {
struct wlr_input_inhibit_manager *manager = data;
assert(wl_client && manager);
struct wl_resource *wl_resource = wl_resource_create(wl_client,
&zwlr_input_inhibit_manager_v1_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource,
&inhibit_manager_implementation, manager,
input_manager_resource_destroy);
}
void wlr_input_inhibit_manager_destroy(
struct wlr_input_inhibit_manager *manager) {
if (!manager) {
return;
}
if (manager->active_client) {
input_inhibitor_destroy(manager->active_client,
manager->active_inhibitor);
}
wl_list_remove(&manager->display_destroy.link);
wl_global_destroy(manager->wl_global);
free(manager);
}
static void handle_display_destroy(struct wl_listener *listener, void *data) {
struct wlr_input_inhibit_manager *manager =
wl_container_of(listener, manager, display_destroy);
wlr_input_inhibit_manager_destroy(manager);
}
struct wlr_input_inhibit_manager *wlr_input_inhibit_manager_create(
struct wl_display *display) {
// TODO: Client destroy
struct wlr_input_inhibit_manager *manager =
calloc(1, sizeof(struct wlr_input_inhibit_manager));
if (!manager) {
return NULL;
}
manager->wl_global = wl_global_create(display,
&zwlr_input_inhibit_manager_v1_interface,
1, manager, inhibit_manager_bind);
if (manager->wl_global == NULL){
wl_list_remove(&manager->display_destroy.link);
free(manager);
return NULL;
}
wl_signal_init(&manager->events.activate);
wl_signal_init(&manager->events.deactivate);
manager->display_destroy.notify = handle_display_destroy;
wl_display_add_destroy_listener(display, &manager->display_destroy);
return manager;
}

View file

@ -137,6 +137,7 @@ static void surface_set_input_region(struct wl_client *client,
pixman_region32_t *region = wlr_region_from_resource(region_resource);
pixman_region32_copy(&surface->pending->input, region);
} else {
pixman_region32_fini(&surface->pending->input);
pixman_region32_init_rect(&surface->pending->input,
INT32_MIN, INT32_MIN, UINT32_MAX, UINT32_MAX);
}
@ -868,43 +869,41 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface,
}
struct wlr_surface *wlr_surface_get_main_surface(struct wlr_surface *surface) {
struct wlr_subsurface *sub;
while (surface && (sub = surface->subsurface)) {
struct wlr_surface *wlr_surface_get_root_surface(struct wlr_surface *surface) {
while (surface != NULL) {
struct wlr_subsurface *sub = surface->subsurface;
if (sub == NULL) {
return surface;
}
surface = sub->parent;
}
return surface;
return NULL;
}
struct wlr_subsurface *wlr_surface_subsurface_at(struct wlr_surface *surface,
bool wlr_surface_point_accepts_input(struct wlr_surface *surface,
double sx, double sy) {
return sx >= 0 && sx <= surface->current->width &&
sy >= 0 && sy <= surface->current->height &&
pixman_region32_contains_point(&surface->current->input, sx, sy, NULL);
}
struct wlr_surface *wlr_surface_surface_at(struct wlr_surface *surface,
double sx, double sy, double *sub_x, double *sub_y) {
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
double _sub_x = subsurface->surface->current->subsurface_position.x;
double _sub_y = subsurface->surface->current->subsurface_position.y;
struct wlr_subsurface *sub =
wlr_surface_subsurface_at(subsurface->surface, _sub_x + sx,
_sub_y + sy, sub_x, sub_y);
if (sub) {
// TODO: This won't work for nested subsurfaces. Convert sub_x and
// sub_y to the parent coordinate system
struct wlr_surface *sub = wlr_surface_surface_at(subsurface->surface,
sx - _sub_x, sy - _sub_y, sub_x, sub_y);
if (sub != NULL) {
return sub;
}
}
int sub_width = subsurface->surface->current->buffer_width;
int sub_height = subsurface->surface->current->buffer_height;
if ((sx > _sub_x && sx < _sub_x + sub_width) &&
(sy > _sub_y && sy < _sub_y + sub_height)) {
if (pixman_region32_contains_point(
&subsurface->surface->current->input,
sx - _sub_x, sy - _sub_y, NULL)) {
*sub_x = _sub_x;
*sub_y = _sub_y;
return subsurface;
}
}
if (wlr_surface_point_accepts_input(surface, sx, sy)) {
*sub_x = sx;
*sub_y = sy;
return surface;
}
return NULL;
@ -952,10 +951,3 @@ void wlr_surface_set_role_committed(struct wlr_surface *surface,
surface->role_committed = role_committed;
surface->role_data = role_data;
}
bool wlr_surface_point_accepts_input(
struct wlr_surface *surface, double sx, double sy) {
return sx >= 0 && sx <= surface->current->width &&
sy >= 0 && sy <= surface->current->height &&
pixman_region32_contains_point(&surface->current->input, sx, sy, NULL);
}

View file

@ -658,42 +658,23 @@ void wlr_wl_shell_surface_configure(struct wlr_wl_shell_surface *surface,
wl_shell_surface_send_configure(surface->resource, edges, width, height);
}
struct wlr_wl_shell_surface *wlr_wl_shell_surface_popup_at(
struct wlr_surface *wlr_wl_shell_surface_surface_at(
struct wlr_wl_shell_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy) {
double *sub_sx, double *sub_sy) {
struct wlr_wl_shell_surface *popup;
wl_list_for_each(popup, &surface->popups, popup_link) {
if (!popup->popup_mapped) {
continue;
}
double _popup_sx = popup->transient_state->x;
double _popup_sy = popup->transient_state->y;
int popup_width =
popup->surface->current->buffer_width;
int popup_height =
popup->surface->current->buffer_height;
struct wlr_wl_shell_surface *_popup =
wlr_wl_shell_surface_popup_at(popup,
popup->transient_state->x,
popup->transient_state->y,
popup_sx, popup_sy);
if (_popup) {
*popup_sx = sx + _popup_sx;
*popup_sy = sy + _popup_sy;
return _popup;
}
if ((sx > _popup_sx && sx < _popup_sx + popup_width) &&
(sy > _popup_sy && sy < _popup_sy + popup_height)) {
if (pixman_region32_contains_point(&popup->surface->current->input,
sx - _popup_sx, sy - _popup_sy, NULL)) {
*popup_sx = _popup_sx;
*popup_sy = _popup_sy;
return popup;
}
double popup_sx = popup->transient_state->x;
double popup_sy = popup->transient_state->y;
struct wlr_surface *sub = wlr_wl_shell_surface_surface_at(popup,
sx - popup_sx, sy - popup_sy, sub_sx, sub_sy);
if (sub != NULL) {
return sub;
}
}
return NULL;
return wlr_surface_surface_at(surface->surface, sx, sy, sub_sx, sub_sy);
}

178
types/wlr_xdg_output.c Normal file
View file

@ -0,0 +1,178 @@
#include <assert.h>
#include <stdlib.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_xdg_output.h>
#include <wlr/util/log.h>
#include "xdg-output-unstable-v1-protocol.h"
static void xdg_output_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
static const struct zxdg_output_v1_interface xdg_output_implementation = {
.destroy = xdg_output_destroy,
};
static void xdg_output_manager_destroy(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
static const struct zxdg_output_manager_v1_interface xdg_output_manager_implementation;
static void xdg_output_send_details(struct wl_resource *resource,
struct wlr_output_layout_output *layout_output) {
zxdg_output_v1_send_logical_position(resource,
layout_output->x, layout_output->y);
zxdg_output_v1_send_logical_size(resource,
(float)layout_output->output->width / layout_output->output->scale,
(float)layout_output->output->height / layout_output->output->scale);
zxdg_output_v1_send_done(resource);
}
static void xdg_output_manager_get_xdg_output(struct wl_client *client,
struct wl_resource *resource, uint32_t id, struct wl_resource *output) {
assert(wl_resource_instance_of(resource, &zxdg_output_manager_v1_interface,
&xdg_output_manager_implementation));
struct wlr_xdg_output_manager *manager =
wl_resource_get_user_data(resource);
struct wlr_output_layout *layout = manager->layout;
struct wlr_output *wlr_output = wlr_output_from_resource(output);
struct wlr_output_layout_output *layout_output =
wlr_output_layout_get(layout, wlr_output);
assert(layout_output);
struct wl_resource *output_resource = wl_resource_create(client,
&zxdg_output_v1_interface, wl_resource_get_version(resource), id);
if (!output_resource) {
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(output_resource,
&xdg_output_implementation, NULL, NULL);
xdg_output_send_details(output_resource, layout_output);
}
static const struct zxdg_output_manager_v1_interface xdg_output_manager_implementation = {
.destroy = xdg_output_manager_destroy,
.get_xdg_output = xdg_output_manager_get_xdg_output,
};
static void output_manager_bind(struct wl_client *wl_client, void *data,
uint32_t version, uint32_t id) {
struct wlr_xdg_output_manager *manager = data;
assert(wl_client && manager);
struct wl_resource *wl_resource = wl_resource_create(wl_client,
&zxdg_output_manager_v1_interface, version, id);
if (wl_resource == NULL) {
wl_client_post_no_memory(wl_client);
return;
}
wl_resource_set_implementation(wl_resource,
&xdg_output_manager_implementation, manager, NULL);
}
static void destroy_output(struct wlr_xdg_output *output) {
struct wl_resource *resource, *tmp;
wl_resource_for_each_safe(resource, tmp, &output->resources) {
wl_list_remove(wl_resource_get_link(resource));
wl_list_init(wl_resource_get_link(resource));
}
wl_list_remove(&output->destroy.link);
wl_list_remove(&output->link);
free(output);
}
static void handle_output_destroy(struct wl_listener *listener, void *data) {
struct wlr_xdg_output *output = wl_container_of(listener, output, destroy);
destroy_output(output);
}
static void add_output(struct wlr_xdg_output_manager *manager,
struct wlr_output_layout_output *layout_output) {
struct wlr_xdg_output *output = calloc(1, sizeof(struct wlr_xdg_output));
wl_list_init(&output->resources);
output->manager = manager;
output->layout_output = layout_output;
output->destroy.notify = handle_output_destroy;
wl_signal_add(&layout_output->events.destroy, &output->destroy);
wl_list_insert(&manager->outputs, &output->link);
}
static void xdg_output_manager_send_details(
struct wlr_xdg_output_manager *manager) {
struct wlr_xdg_output *output;
wl_list_for_each(output, &manager->outputs, link) {
struct wl_resource *resource;
wl_resource_for_each(resource, &output->resources) {
xdg_output_send_details(resource, output->layout_output);
}
}
}
static void handle_layout_add(struct wl_listener *listener, void *data) {
struct wlr_xdg_output_manager *manager =
wl_container_of(listener, manager, layout_add);
struct wlr_output_layout_output *layout_output = data;
add_output(manager, layout_output);
}
static void handle_layout_change(struct wl_listener *listener, void *data) {
struct wlr_xdg_output_manager *manager =
wl_container_of(listener, manager, layout_change);
xdg_output_manager_send_details(manager);
}
static void handle_layout_destroy(struct wl_listener *listener, void *data) {
struct wlr_xdg_output_manager *manager =
wl_container_of(listener, manager, layout_change);
wlr_xdg_output_manager_destroy(manager);
}
struct wlr_xdg_output_manager *wlr_xdg_output_manager_create(
struct wl_display *display, struct wlr_output_layout *layout) {
assert(display && layout);
struct wlr_xdg_output_manager *manager =
calloc(1, sizeof(struct wlr_xdg_output_manager));
if (manager == NULL) {
return NULL;
}
manager->layout = layout;
manager->global = wl_global_create(display,
&zxdg_output_manager_v1_interface,
1, manager, output_manager_bind);
if (!manager->global) {
free(manager);
return NULL;
}
wl_list_init(&manager->outputs);
struct wlr_output_layout_output *layout_output;
wl_list_for_each(layout_output, &layout->outputs, link) {
add_output(manager, layout_output);
}
manager->layout_add.notify = handle_layout_add;
wl_signal_add(&layout->events.add, &manager->layout_add);
manager->layout_change.notify = handle_layout_change;
wl_signal_add(&layout->events.change, &manager->layout_change);
manager->layout_destroy.notify = handle_layout_destroy;
wl_signal_add(&layout->events.destroy, &manager->layout_destroy);
return manager;
}
void wlr_xdg_output_manager_destroy(struct wlr_xdg_output_manager *manager) {
struct wlr_xdg_output *output, *tmp;
wl_list_for_each_safe(output, tmp, &manager->outputs, link) {
destroy_output(output);
}
wl_list_remove(&manager->layout_add.link);
wl_list_remove(&manager->layout_change.link);
wl_list_remove(&manager->layout_destroy.link);
free(manager);
}

View file

@ -1638,45 +1638,24 @@ void wlr_xdg_surface_popup_get_position(struct wlr_xdg_surface *surface,
surface->geometry.y;
}
struct wlr_xdg_surface *wlr_xdg_surface_popup_at(
struct wlr_surface *wlr_xdg_surface_surface_at(
struct wlr_xdg_surface *surface, double sx, double sy,
double *popup_sx, double *popup_sy) {
// XXX: I think this is so complicated because we're mixing geometry
// coordinates with surface coordinates. Input handling should only deal
// with surface coordinates.
double *sub_x, double *sub_y) {
struct wlr_xdg_popup *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface *popup = popup_state->base;
double _popup_sx =
surface->geometry.x + popup_state->geometry.x;
double _popup_sy =
surface->geometry.y + popup_state->geometry.y;
int popup_width = popup_state->geometry.width;
int popup_height = popup_state->geometry.height;
double popup_sx, popup_sy;
wlr_xdg_surface_popup_get_position(popup, &popup_sx, &popup_sy);
struct wlr_xdg_surface *_popup =
wlr_xdg_surface_popup_at(popup,
sx - _popup_sx + popup->geometry.x,
sy - _popup_sy + popup->geometry.y,
popup_sx, popup_sy);
if (_popup) {
*popup_sx = *popup_sx + _popup_sx - popup->geometry.x;
*popup_sy = *popup_sy + _popup_sy - popup->geometry.y;
return _popup;
}
if ((sx > _popup_sx && sx < _popup_sx + popup_width) &&
(sy > _popup_sy && sy < _popup_sy + popup_height)) {
if (pixman_region32_contains_point(&popup->surface->current->input,
sx - _popup_sx + popup->geometry.x,
sy - _popup_sy + popup->geometry.y, NULL)) {
*popup_sx = _popup_sx - popup->geometry.x;
*popup_sy = _popup_sy - popup->geometry.y;
return popup;
}
struct wlr_surface *sub = wlr_xdg_surface_surface_at(popup,
sx - popup_sx + popup->geometry.x,
sy - popup_sy + popup->geometry.y,
sub_x, sub_y);
if (sub != NULL) {
return sub;
}
}
return NULL;
return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y);
}

View file

@ -1602,47 +1602,26 @@ void wlr_xdg_surface_v6_popup_get_position(struct wlr_xdg_surface_v6 *surface,
surface->geometry.y;
}
struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6_popup_at(
struct wlr_surface *wlr_xdg_surface_v6_surface_at(
struct wlr_xdg_surface_v6 *surface, double sx, double sy,
double *popup_sx, double *popup_sy) {
// XXX: I think this is so complicated because we're mixing geometry
// coordinates with surface coordinates. Input handling should only deal
// with surface coordinates.
double *sub_x, double *sub_y) {
struct wlr_xdg_popup_v6 *popup_state;
wl_list_for_each(popup_state, &surface->popups, link) {
struct wlr_xdg_surface_v6 *popup = popup_state->base;
double _popup_sx =
surface->geometry.x + popup_state->geometry.x;
double _popup_sy =
surface->geometry.y + popup_state->geometry.y;
int popup_width = popup_state->geometry.width;
int popup_height = popup_state->geometry.height;
double popup_sx, popup_sy;
wlr_xdg_surface_v6_popup_get_position(popup, &popup_sx, &popup_sy);
struct wlr_xdg_surface_v6 *_popup =
wlr_xdg_surface_v6_popup_at(popup,
sx - _popup_sx + popup->geometry.x,
sy - _popup_sy + popup->geometry.y,
popup_sx, popup_sy);
if (_popup) {
*popup_sx = *popup_sx + _popup_sx - popup->geometry.x;
*popup_sy = *popup_sy + _popup_sy - popup->geometry.y;
return _popup;
}
if ((sx > _popup_sx && sx < _popup_sx + popup_width) &&
(sy > _popup_sy && sy < _popup_sy + popup_height)) {
if (pixman_region32_contains_point(&popup->surface->current->input,
sx - _popup_sx + popup->geometry.x,
sy - _popup_sy + popup->geometry.y, NULL)) {
*popup_sx = _popup_sx - popup->geometry.x;
*popup_sy = _popup_sy - popup->geometry.y;
return popup;
}
struct wlr_surface *sub = wlr_xdg_surface_v6_surface_at(popup,
sx - popup_sx + popup->geometry.x,
sy - popup_sy + popup->geometry.y,
sub_x, sub_y);
if (sub != NULL) {
return sub;
}
}
return NULL;
return wlr_surface_surface_at(surface->surface, sx, sy, sub_x, sub_y);
}
void wlr_xdg_popup_v6_get_anchor_point(struct wlr_xdg_popup_v6 *popup,