Merge pull request #544 from emersion/fix-views-outside-output-layout

Fix views outside output layout
This commit is contained in:
Drew DeVault 2018-01-01 11:45:08 -05:00 committed by GitHub
commit b23bd8ea28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 151 additions and 106 deletions

View File

@ -105,11 +105,11 @@ static void handle_output_frame(struct output_state *output,
animate_cat(sample, output->output); animate_cat(sample, output->output);
bool intersects = wlr_output_layout_intersects(sample->layout, struct wlr_box box = {
output->output, sample->x_offs, sample->y_offs, .x = sample->x_offs, .y = sample->y_offs,
sample->x_offs + 128, sample->y_offs + 128); .width = 128, .height = 128,
};
if (intersects) { if (wlr_output_layout_intersects(sample->layout, output->output, &box)) {
float matrix[16]; float matrix[16];
// transform global coordinates to local coordinates // transform global coordinates to local coordinates
@ -122,7 +122,6 @@ static void handle_output_frame(struct output_state *output,
&wlr_output->transform_matrix, local_x, local_y); &wlr_output->transform_matrix, local_x, local_y);
wlr_render_with_matrix(sample->renderer, wlr_render_with_matrix(sample->renderer,
sample->cat_texture, &matrix); sample->cat_texture, &matrix);
} }
wlr_renderer_end(sample->renderer); wlr_renderer_end(sample->renderer);

View File

@ -47,6 +47,7 @@ struct roots_desktop {
struct wl_listener output_add; struct wl_listener output_add;
struct wl_listener output_remove; struct wl_listener output_remove;
struct wl_listener layout_change;
struct wl_listener xdg_shell_v6_surface; struct wl_listener xdg_shell_v6_surface;
struct wl_listener wl_shell_surface; struct wl_listener wl_shell_surface;
struct wl_listener decoration_new; struct wl_listener decoration_new;

View File

@ -8,18 +8,18 @@ struct wlr_box {
int width, height; int width, height;
}; };
void wlr_box_closest_point(struct wlr_box *box, double x, double y, void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
double *dest_x, double *dest_y); double *dest_x, double *dest_y);
bool wlr_box_intersection(struct wlr_box *box_a, bool wlr_box_intersection(const struct wlr_box *box_a,
struct wlr_box *box_b, struct wlr_box **dest); const struct wlr_box *box_b, struct wlr_box *dest);
bool wlr_box_contains_point(struct wlr_box *box, double x, double y); bool wlr_box_contains_point(const struct wlr_box *box, double x, double y);
bool wlr_box_empty(struct wlr_box *box); bool wlr_box_empty(const struct wlr_box *box);
enum wl_output_transform; enum wl_output_transform;
void wlr_box_transform(struct wlr_box *box, enum wl_output_transform transform, void wlr_box_transform(const struct wlr_box *box,
struct wlr_box *dest); enum wl_output_transform transform, struct wlr_box *dest);
#endif #endif

View File

@ -1,6 +1,7 @@
#ifndef WLR_TYPES_WLR_OUTPUT_LAYOUT_H #ifndef WLR_TYPES_WLR_OUTPUT_LAYOUT_H
#define WLR_TYPES_WLR_OUTPUT_LAYOUT_H #define WLR_TYPES_WLR_OUTPUT_LAYOUT_H
#include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wayland-util.h> #include <wayland-util.h>
#include <stdbool.h> #include <stdbool.h>
@ -61,7 +62,7 @@ bool wlr_output_layout_contains_point(struct wlr_output_layout *layout,
struct wlr_output *reference, int x, int y); struct wlr_output *reference, int x, int y);
bool wlr_output_layout_intersects(struct wlr_output_layout *layout, bool wlr_output_layout_intersects(struct wlr_output_layout *layout,
struct wlr_output *reference, int x1, int y1, int x2, int y2); struct wlr_output *reference, const struct wlr_box *target_box);
/** /**
* Get the closest point on this layout from the given point from the reference * Get the closest point on this layout from the given point from the reference

View File

@ -38,12 +38,9 @@ static void view_update_output(const struct roots_view *view,
view_get_box(view, &box); view_get_box(view, &box);
wl_list_for_each(output, &desktop->outputs, link) { wl_list_for_each(output, &desktop->outputs, link) {
bool intersected = before != NULL && wlr_output_layout_intersects( bool intersected = before != NULL && wlr_output_layout_intersects(
desktop->layout, output->wlr_output, desktop->layout, output->wlr_output, before);
before->x, before->y, before->x + before->width, bool intersects = wlr_output_layout_intersects(desktop->layout,
before->y + before->height); output->wlr_output, &box);
bool intersects = wlr_output_layout_intersects(
desktop->layout, output->wlr_output,
view->x, view->y, view->x + box.width, view->y + box.height);
if (intersected && !intersects) { if (intersected && !intersects) {
wlr_surface_send_leave(view->wlr_surface, output->wlr_output); wlr_surface_send_leave(view->wlr_surface, output->wlr_output);
} }
@ -386,6 +383,34 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
return NULL; return NULL;
} }
static void handle_layout_change(struct wl_listener *listener, void *data) {
struct roots_desktop *desktop =
wl_container_of(listener, desktop, layout_change);
struct wlr_output *center_output =
wlr_output_layout_get_center_output(desktop->layout);
if (center_output == NULL) {
return;
}
struct wlr_box *center_output_box =
wlr_output_layout_get_box(desktop->layout, center_output);
double center_x = center_output_box->x + center_output_box->width/2;
double center_y = center_output_box->y + center_output_box->height/2;
struct roots_view *view;
wl_list_for_each(view, &desktop->views, link) {
struct wlr_box box;
view_get_box(view, &box);
if (wlr_output_layout_intersects(desktop->layout, NULL, &box)) {
continue;
}
view_move(view, center_x - box.width/2, center_y - box.height/2);
}
}
struct roots_desktop *desktop_create(struct roots_server *server, struct roots_desktop *desktop_create(struct roots_server *server,
struct roots_config *config) { struct roots_config *config) {
wlr_log(L_DEBUG, "Initializing roots desktop"); wlr_log(L_DEBUG, "Initializing roots desktop");
@ -428,6 +453,9 @@ struct roots_desktop *desktop_create(struct roots_server *server,
} }
desktop->layout = wlr_output_layout_create(); desktop->layout = wlr_output_layout_create();
desktop->layout_change.notify = handle_layout_change;
wl_signal_add(&desktop->layout->events.change, &desktop->layout_change);
desktop->compositor = wlr_compositor_create(server->wl_display, desktop->compositor = wlr_compositor_create(server->wl_display,
server->renderer); server->renderer);

View File

@ -34,7 +34,10 @@ static void rotate_child_position(double *sx, double *sy, double sw, double sh,
static void render_surface(struct wlr_surface *surface, static void render_surface(struct wlr_surface *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output, struct roots_desktop *desktop, struct wlr_output *wlr_output,
struct timespec *when, double lx, double ly, float rotation) { struct timespec *when, double lx, double ly, float rotation) {
if (wlr_surface_has_buffer(surface)) { if (!wlr_surface_has_buffer(surface)) {
return;
}
int width = surface->current->width; int width = surface->current->width;
int height = surface->current->height; int height = surface->current->height;
int render_width = width * wlr_output->scale; int render_width = width * wlr_output->scale;
@ -44,8 +47,11 @@ static void render_surface(struct wlr_surface *surface,
ox *= wlr_output->scale; ox *= wlr_output->scale;
oy *= wlr_output->scale; oy *= wlr_output->scale;
if (wlr_output_layout_intersects(desktop->layout, wlr_output, struct wlr_box render_box = {
lx, ly, lx + render_width, ly + render_height)) { .x = lx, .y = ly,
.width = render_width, .height = render_height,
};
if (wlr_output_layout_intersects(desktop->layout, wlr_output, &render_box)) {
float matrix[16]; float matrix[16];
float translate_center[16]; float translate_center[16];
@ -108,7 +114,6 @@ static void render_surface(struct wlr_surface *surface,
rotation); rotation);
} }
} }
}
static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface, static void render_xdg_v6_popups(struct wlr_xdg_surface_v6 *surface,
struct roots_desktop *desktop, struct wlr_output *wlr_output, struct roots_desktop *desktop, struct wlr_output *wlr_output,
@ -356,7 +361,9 @@ void output_add_notify(struct wl_listener *listener, void *data) {
void output_remove_notify(struct wl_listener *listener, void *data) { void output_remove_notify(struct wl_listener *listener, void *data) {
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
struct roots_desktop *desktop = wl_container_of(listener, desktop, output_remove); struct roots_desktop *desktop =
wl_container_of(listener, desktop, output_remove);
struct roots_output *output = NULL, *_output; struct roots_output *output = NULL, *_output;
wl_list_for_each(_output, &desktop->outputs, link) { wl_list_for_each(_output, &desktop->outputs, link) {
if (_output->wlr_output == wlr_output) { if (_output->wlr_output == wlr_output) {
@ -367,10 +374,13 @@ void output_remove_notify(struct wl_listener *listener, void *data) {
if (!output) { if (!output) {
return; // We are unfamiliar with this output return; // We are unfamiliar with this output
} }
wlr_output_layout_remove(desktop->layout, output->wlr_output); wlr_output_layout_remove(desktop->layout, output->wlr_output);
// TODO: cursor // TODO: cursor
//example_config_configure_cursor(sample->config, sample->cursor, //example_config_configure_cursor(sample->config, sample->cursor,
// sample->compositor); // sample->compositor);
wl_list_remove(&output->link); wl_list_remove(&output->link);
wl_list_remove(&output->frame.link); wl_list_remove(&output->frame.link);
free(output); free(output);

View File

@ -6,7 +6,7 @@
#include <wlr/types/wlr_box.h> #include <wlr/types/wlr_box.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
void wlr_box_closest_point(struct wlr_box *box, double x, double y, void wlr_box_closest_point(const struct wlr_box *box, double x, double y,
double *dest_x, double *dest_y) { double *dest_x, double *dest_y) {
// find the closest x point // find the closest x point
if (x < box->x) { if (x < box->x) {
@ -27,13 +27,12 @@ void wlr_box_closest_point(struct wlr_box *box, double x, double y,
} }
} }
bool wlr_box_empty(struct wlr_box *box) { bool wlr_box_empty(const struct wlr_box *box) {
return box == NULL || box->width <= 0 || box->height <= 0; return box == NULL || box->width <= 0 || box->height <= 0;
} }
bool wlr_box_intersection(struct wlr_box *box_a, bool wlr_box_intersection(const struct wlr_box *box_a,
struct wlr_box *box_b, struct wlr_box **box_dest) { const struct wlr_box *box_b, struct wlr_box *dest) {
struct wlr_box *dest = *box_dest;
bool a_empty = wlr_box_empty(box_a); bool a_empty = wlr_box_empty(box_a);
bool b_empty = wlr_box_empty(box_b); bool b_empty = wlr_box_empty(box_b);
@ -58,7 +57,7 @@ bool wlr_box_intersection(struct wlr_box *box_a,
return !wlr_box_empty(dest); return !wlr_box_empty(dest);
} }
bool wlr_box_contains_point(struct wlr_box *box, double x, double y) { bool wlr_box_contains_point(const struct wlr_box *box, double x, double y) {
if (wlr_box_empty(box)) { if (wlr_box_empty(box)) {
return false; return false;
} else { } else {
@ -67,7 +66,7 @@ bool wlr_box_contains_point(struct wlr_box *box, double x, double y) {
} }
} }
void wlr_box_transform(struct wlr_box *box, void wlr_box_transform(const struct wlr_box *box,
enum wl_output_transform transform, struct wlr_box *dest) { enum wl_output_transform transform, struct wlr_box *dest) {
if (transform % 2 == 0) { if (transform % 2 == 0) {
dest->width = box->width; dest->width = box->width;

View File

@ -561,9 +561,8 @@ static void output_cursor_update_visible(struct wlr_output_cursor *cursor) {
output_cursor_get_box(cursor, &cursor_box); output_cursor_get_box(cursor, &cursor_box);
struct wlr_box intersection; struct wlr_box intersection;
struct wlr_box *intersection_ptr = &intersection;
bool visible = bool visible =
wlr_box_intersection(&output_box, &cursor_box, &intersection_ptr); wlr_box_intersection(&output_box, &cursor_box, &intersection);
if (cursor->surface != NULL) { if (cursor->surface != NULL) {
if (cursor->visible && !visible) { if (cursor->visible && !visible) {

View File

@ -230,32 +230,40 @@ bool wlr_output_layout_contains_point(struct wlr_output_layout *layout,
} }
bool wlr_output_layout_intersects(struct wlr_output_layout *layout, bool wlr_output_layout_intersects(struct wlr_output_layout *layout,
struct wlr_output *reference, int x1, int y1, int x2, int y2) { struct wlr_output *reference, const struct wlr_box *target_box) {
struct wlr_output_layout_output *layout_output = struct wlr_box out_box;
if (reference == NULL) {
struct wlr_output_layout_output *l_output;
wl_list_for_each(l_output, &layout->outputs, link) {
struct wlr_box *output_box =
wlr_output_layout_output_get_box(l_output);
if (wlr_box_intersection(output_box, target_box, &out_box)) {
return true;
}
}
return false;
} else {
struct wlr_output_layout_output *l_output =
wlr_output_layout_get(layout, reference); wlr_output_layout_get(layout, reference);
if (!layout_output) { if (!l_output) {
return false; return false;
} }
struct wlr_box *output_box = wlr_output_layout_output_get_box(layout_output); struct wlr_box *output_box = wlr_output_layout_output_get_box(l_output);
struct wlr_box target_box = {x1, y1, x2 - x1, y2 - y1}; return wlr_box_intersection(output_box, target_box, &out_box);
}
struct wlr_box out;
struct wlr_box *out_ptr = &out;
return wlr_box_intersection(output_box, &target_box, &out_ptr);
} }
struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout, struct wlr_output *wlr_output_layout_output_at(struct wlr_output_layout *layout,
double x, double y) { double x, double y) {
struct wlr_output_layout_output *l_output; struct wlr_output_layout_output *l_output;
wl_list_for_each(l_output, &layout->outputs, link) { wl_list_for_each(l_output, &layout->outputs, link) {
if (l_output->output) {
struct wlr_box *box = wlr_output_layout_output_get_box(l_output); struct wlr_box *box = wlr_output_layout_output_get_box(l_output);
if (wlr_box_contains_point(box, x, y)) { if (wlr_box_contains_point(box, x, y)) {
return l_output->output; return l_output->output;
} }
} }
}
return NULL; return NULL;
} }