Merge pull request #160 from acrisci/feature/subcompositor

Subcompositor
This commit is contained in:
Drew DeVault 2017-09-30 14:31:57 -04:00 committed by GitHub
commit bfb6914cdf
8 changed files with 706 additions and 164 deletions

View file

@ -48,15 +48,14 @@ void view_begin_resize(struct roots_input *input, struct wlr_cursor *cursor,
void cursor_update_position(struct roots_input *input, uint32_t time) {
struct roots_desktop *desktop = input->server->desktop;
struct roots_view *view;
struct wlr_surface *surface;
double sx, sy;
switch (input->mode) {
case ROOTS_CURSOR_PASSTHROUGH:
view = view_at(desktop, input->cursor->x, input->cursor->y);
view = view_at(desktop, input->cursor->x, input->cursor->y, &surface,
&sx, &sy);
if (view) {
struct wlr_box box;
view_get_input_bounds(view, &box);
double sx = input->cursor->x - view->x;
double sy = input->cursor->y - view->y;
wlr_seat_pointer_enter(input->wl_seat, view->wlr_surface, sx, sy);
wlr_seat_pointer_enter(input->wl_seat, surface, sx, sy);
wlr_seat_pointer_send_motion(input->wl_seat, time, sx, sy);
} else {
wlr_seat_pointer_clear_focus(input->wl_seat);
@ -146,8 +145,10 @@ static void do_cursor_button_press(struct roots_input *input,
struct wlr_cursor *cursor, struct wlr_input_device *device,
uint32_t time, uint32_t button, uint32_t state) {
struct roots_desktop *desktop = input->server->desktop;
struct wlr_surface *surface;
double sx, sy;
struct roots_view *view = view_at(desktop,
input->cursor->x, input->cursor->y);
input->cursor->x, input->cursor->y, &surface, &sx, &sy);
uint32_t serial = wlr_seat_pointer_send_button(
input->wl_seat, time, button, state);
int i;
@ -165,7 +166,7 @@ static void do_cursor_button_press(struct roots_input *input,
% (sizeof(input->input_events) / sizeof(input->input_events[0]));
set_view_focus(input, desktop, view);
if (view) {
wlr_seat_keyboard_enter(input->wl_seat, view->wlr_surface);
wlr_seat_keyboard_enter(input->wl_seat, surface);
}
break;
}

View file

@ -31,8 +31,8 @@ void view_get_size(struct roots_view *view, struct wlr_box *box) {
return;
}
box->x = box->y = 0;
box->width = view->wlr_surface->current.width;
box->height = view->wlr_surface->current.height;
box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height;
}
void view_get_input_bounds(struct roots_view *view, struct wlr_box *box) {
@ -41,8 +41,8 @@ void view_get_input_bounds(struct roots_view *view, struct wlr_box *box) {
return;
}
box->x = box->y = 0;
box->width = view->wlr_surface->current.width;
box->height = view->wlr_surface->current.height;
box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height;
}
void view_activate(struct roots_view *view, bool activate) {
@ -57,14 +57,60 @@ void view_resize(struct roots_view *view, uint32_t width, uint32_t height) {
}
}
struct roots_view *view_at(struct roots_desktop *desktop, int x, int y) {
static struct wlr_subsurface *subsurface_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 =
subsurface_at(subsurface->surface, _sub_x + sx, _sub_y + sy,
sub_x, sub_y);
if (sub) {
// TODO: convert sub_x and sub_y to the parent coordinate system
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 && sub_y < sub_y + sub_height)) {
*sub_x = _sub_x;
*sub_y = _sub_y;
return subsurface;
}
}
return NULL;
}
struct roots_view *view_at(struct roots_desktop *desktop, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) {
for (size_t i = 0; i < desktop->views->length; ++i) {
struct roots_view *view = desktop->views->items[i];
double view_sx = lx - view->x;
double view_sy = ly - view->y;
double sub_x, sub_y;
struct wlr_subsurface *subsurface =
subsurface_at(view->wlr_surface, view_sx, view_sy, &sub_x, &sub_y);
if (subsurface) {
*sx = view_sx - sub_x;
*sy = view_sy - sub_y;
*surface = subsurface->surface;
return view;
}
struct wlr_box box;
view_get_input_bounds(view, &box);
box.x += view->x;
box.y += view->y;
if (wlr_box_contains_point(&box, x, y)) {
if (wlr_box_contains_point(&box, lx, ly)) {
*sx = view_sx;
*sy = view_sy;
*surface = view->wlr_surface;
return view;
}
}

View file

@ -16,28 +16,49 @@ static inline int64_t timespec_to_msec(const struct timespec *a) {
return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000;
}
static void render_view(struct roots_desktop *desktop,
struct wlr_output *wlr_output, struct timespec *when,
struct roots_view *view, double ox, double oy) {
struct wlr_surface *surface = view->wlr_surface;
float matrix[16];
float transform[16];
static void render_surface(struct wlr_surface *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double lx, double ly) {
wlr_surface_flush_damage(surface);
if (surface->texture->valid) {
wlr_matrix_translate(&transform, ox, oy, 0);
wlr_surface_get_matrix(surface, &matrix,
&wlr_output->transform_matrix, &transform);
wlr_render_with_matrix(desktop->server->renderer,
surface->texture, &matrix);
int width = surface->current->buffer_width;
int height = surface->current->buffer_height;
double ox = lx, oy = ly;
wlr_output_layout_output_coords(desktop->layout, wlr_output, &ox, &oy);
struct wlr_frame_callback *cb, *cnext;
wl_list_for_each_safe(cb, cnext, &surface->frame_callback_list, link) {
wl_callback_send_done(cb->resource, timespec_to_msec(when));
wl_resource_destroy(cb->resource);
if (wlr_output_layout_intersects(desktop->layout, wlr_output,
lx, ly, lx + width, ly + height)) {
float matrix[16];
float transform[16];
wlr_matrix_translate(&transform, ox, oy, 0);
wlr_surface_get_matrix(surface, &matrix,
&wlr_output->transform_matrix, &transform);
wlr_render_with_matrix(desktop->server->renderer,
surface->texture, &matrix);
struct wlr_frame_callback *cb, *cnext;
wl_list_for_each_safe(cb, cnext,
&surface->current->frame_callback_list, link) {
wl_callback_send_done(cb->resource, timespec_to_msec(when));
wl_resource_destroy(cb->resource);
}
}
struct wlr_subsurface *subsurface;
wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) {
render_surface(subsurface->surface, desktop, wlr_output, when,
lx + subsurface->surface->current->subsurface_position.x,
ly + subsurface->surface->current->subsurface_position.y);
}
}
}
static void render_view(struct roots_view *view, struct roots_desktop *desktop,
struct wlr_output *wlr_output, struct timespec *when) {
render_surface(view->wlr_surface, desktop, wlr_output, when,
view->x, view->y);
}
static void output_frame_notify(struct wl_listener *listener, void *data) {
struct wlr_output *wlr_output = data;
struct roots_output *output = wl_container_of(listener, output, frame);
@ -52,16 +73,7 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
for (size_t i = 0; i < desktop->views->length; ++i) {
struct roots_view *view = desktop->views->items[i];
int width = view->wlr_surface->current.buffer_width;
int height = view->wlr_surface->current.buffer_height;
if (wlr_output_layout_intersects(desktop->layout, wlr_output,
view->x, view->y, view->x + width, view->y + height)) {
double ox = view->x, oy = view->y;
wlr_output_layout_output_coords(
desktop->layout, wlr_output, &ox, &oy);
render_view(desktop, wlr_output, &now, view, ox, oy);
}
render_view(view, desktop, wlr_output, &now);
}
wlr_renderer_end(server->renderer);