Address review comments
This commit is contained in:
parent
1d68f9ecca
commit
61fabede14
|
@ -69,10 +69,8 @@ enum sway_view_prop {
|
|||
struct sway_view_impl {
|
||||
const char *(*get_prop)(struct sway_view *view,
|
||||
enum sway_view_prop prop);
|
||||
void (*set_size)(struct sway_view *view,
|
||||
int width, int height);
|
||||
void (*set_position)(struct sway_view *view,
|
||||
double ox, double oy);
|
||||
void (*configure)(struct sway_view *view, double ox, double oy, int width,
|
||||
int height);
|
||||
void (*set_activated)(struct sway_view *view, bool activated);
|
||||
void (*close)(struct sway_view *view);
|
||||
};
|
||||
|
@ -114,14 +112,19 @@ const char *view_get_class(struct sway_view *view);
|
|||
|
||||
const char *view_get_instance(struct sway_view *view);
|
||||
|
||||
void view_set_size(struct sway_view *view, int width, int height);
|
||||
|
||||
void view_set_position(struct sway_view *view, double ox, double oy);
|
||||
void view_configure(struct sway_view *view, double ox, double oy, int width,
|
||||
int height);
|
||||
|
||||
void view_set_activated(struct sway_view *view, bool activated);
|
||||
|
||||
void view_close(struct sway_view *view);
|
||||
|
||||
void view_damage_whole(struct sway_view *view);
|
||||
|
||||
void view_damage_from(struct sway_view *view);
|
||||
|
||||
// view implementation
|
||||
|
||||
void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);
|
||||
|
||||
void view_map_unmanaged(struct sway_view *view,
|
||||
|
@ -129,8 +132,8 @@ void view_map_unmanaged(struct sway_view *view,
|
|||
|
||||
void view_unmap(struct sway_view *view);
|
||||
|
||||
void view_damage_whole(struct sway_view *view);
|
||||
void view_update_position(struct sway_view *view, double ox, double oy);
|
||||
|
||||
void view_damage_from(struct sway_view *view);
|
||||
void view_update_size(struct sway_view *view, int width, int height);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,24 +30,18 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
|
|||
}
|
||||
}
|
||||
|
||||
static void set_size(struct sway_view *view, int width, int height) {
|
||||
static void configure(struct sway_view *view, double ox, double oy, int width,
|
||||
int height) {
|
||||
if (!assert_wl_shell(view)) {
|
||||
return;
|
||||
}
|
||||
view_update_position(view, ox, oy);
|
||||
view->sway_wl_shell_surface->pending_width = width;
|
||||
view->sway_wl_shell_surface->pending_height = height;
|
||||
wlr_wl_shell_surface_configure(view->wlr_wl_shell_surface, 0, width, height);
|
||||
}
|
||||
|
||||
static void set_position(struct sway_view *view, double ox, double oy) {
|
||||
if (!assert_wl_shell(view)) {
|
||||
return;
|
||||
}
|
||||
view->swayc->x = ox;
|
||||
view->swayc->y = oy;
|
||||
}
|
||||
|
||||
static void close(struct sway_view *view) {
|
||||
static void _close(struct sway_view *view) {
|
||||
if (!assert_wl_shell(view)) {
|
||||
return;
|
||||
}
|
||||
|
@ -57,9 +51,8 @@ static void close(struct sway_view *view) {
|
|||
|
||||
static const struct sway_view_impl view_impl = {
|
||||
.get_prop = get_prop,
|
||||
.set_size = set_size,
|
||||
.set_position = set_position,
|
||||
.close = close,
|
||||
.configure = configure,
|
||||
.close = _close,
|
||||
};
|
||||
|
||||
static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
|
@ -68,8 +61,8 @@ static void handle_commit(struct wl_listener *listener, void *data) {
|
|||
struct sway_view *view = sway_surface->view;
|
||||
// NOTE: We intentionally discard the view's desired width here
|
||||
// TODO: Let floating views do whatever
|
||||
view->width = sway_surface->pending_width;
|
||||
view->height = sway_surface->pending_height;
|
||||
view_update_size(view, sway_surface->pending_width,
|
||||
sway_surface->pending_height);
|
||||
view_damage_from(view);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,23 +30,18 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
|
|||
}
|
||||
}
|
||||
|
||||
static void set_size(struct sway_view *view, int width, int height) {
|
||||
static void configure(struct sway_view *view, double ox, double oy, int width,
|
||||
int height) {
|
||||
if (!assert_xdg(view)) {
|
||||
return;
|
||||
}
|
||||
|
||||
view_update_position(view, ox, oy);
|
||||
view->sway_xdg_surface_v6->pending_width = width;
|
||||
view->sway_xdg_surface_v6->pending_height = height;
|
||||
wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height);
|
||||
}
|
||||
|
||||
static void set_position(struct sway_view *view, double ox, double oy) {
|
||||
if (!assert_xdg(view)) {
|
||||
return;
|
||||
}
|
||||
view->swayc->x = ox;
|
||||
view->swayc->y = oy;
|
||||
}
|
||||
|
||||
static void set_activated(struct sway_view *view, bool activated) {
|
||||
if (!assert_xdg(view)) {
|
||||
return;
|
||||
|
@ -57,7 +52,7 @@ static void set_activated(struct sway_view *view, bool activated) {
|
|||
}
|
||||
}
|
||||
|
||||
static void close(struct sway_view *view) {
|
||||
static void _close(struct sway_view *view) {
|
||||
if (!assert_xdg(view)) {
|
||||
return;
|
||||
}
|
||||
|
@ -69,10 +64,9 @@ static void close(struct sway_view *view) {
|
|||
|
||||
static const struct sway_view_impl view_impl = {
|
||||
.get_prop = get_prop,
|
||||
.set_size = set_size,
|
||||
.set_position = set_position,
|
||||
.configure = configure,
|
||||
.set_activated = set_activated,
|
||||
.close = close,
|
||||
.close = _close,
|
||||
};
|
||||
|
||||
static void handle_commit(struct wl_listener *listener, void *data) {
|
||||
|
@ -82,8 +76,8 @@ static void handle_commit(struct wl_listener *listener, void *data) {
|
|||
// NOTE: We intentionally discard the view's desired width here
|
||||
// TODO: Store this for restoration when moving to floating plane
|
||||
// TODO: Let floating views do whatever
|
||||
view->width = sway_surface->pending_width;
|
||||
view->height = sway_surface->pending_height;
|
||||
view_update_size(view, sway_surface->pending_width,
|
||||
sway_surface->pending_height);
|
||||
view_damage_from(view);
|
||||
}
|
||||
|
||||
|
|
|
@ -33,22 +33,13 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) {
|
|||
}
|
||||
}
|
||||
|
||||
static void set_size(struct sway_view *view, int width, int height) {
|
||||
static void configure(struct sway_view *view, double ox, double oy, int width,
|
||||
int height) {
|
||||
if (!assert_xwayland(view)) {
|
||||
return;
|
||||
}
|
||||
view->sway_xwayland_surface->pending_width = width;
|
||||
view->sway_xwayland_surface->pending_height = height;
|
||||
|
||||
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
|
||||
wlr_xwayland_surface_configure(xsurface, xsurface->x, xsurface->y,
|
||||
width, height);
|
||||
}
|
||||
|
||||
static void set_position(struct sway_view *view, double ox, double oy) {
|
||||
if (!assert_xwayland(view)) {
|
||||
return;
|
||||
}
|
||||
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
|
||||
if (!sway_assert(output, "view must be within tree to set position")) {
|
||||
return;
|
||||
|
@ -64,13 +55,12 @@ static void set_position(struct sway_view *view, double ox, double oy) {
|
|||
return;
|
||||
}
|
||||
|
||||
view->swayc->x = ox;
|
||||
view->swayc->y = oy;
|
||||
view_update_position(view, ox, oy);
|
||||
|
||||
wlr_xwayland_surface_configure(view->wlr_xwayland_surface,
|
||||
ox + loutput->x, oy + loutput->y,
|
||||
view->wlr_xwayland_surface->width,
|
||||
view->wlr_xwayland_surface->height);
|
||||
view->sway_xwayland_surface->pending_width = width;
|
||||
view->sway_xwayland_surface->pending_height = height;
|
||||
wlr_xwayland_surface_configure(xsurface, ox + loutput->x, oy + loutput->y,
|
||||
width, height);
|
||||
}
|
||||
|
||||
static void set_activated(struct sway_view *view, bool activated) {
|
||||
|
@ -90,8 +80,7 @@ static void _close(struct sway_view *view) {
|
|||
|
||||
static const struct sway_view_impl view_impl = {
|
||||
.get_prop = get_prop,
|
||||
.set_size = set_size,
|
||||
.set_position = set_position,
|
||||
.configure = configure,
|
||||
.set_activated = set_activated,
|
||||
.close = _close,
|
||||
};
|
||||
|
@ -102,8 +91,8 @@ static void handle_commit(struct wl_listener *listener, void *data) {
|
|||
struct sway_view *view = sway_surface->view;
|
||||
// NOTE: We intentionally discard the view's desired width here
|
||||
// TODO: Let floating views do whatever
|
||||
view->width = sway_surface->pending_width;
|
||||
view->height = sway_surface->pending_height;
|
||||
view_update_size(view, sway_surface->pending_width,
|
||||
sway_surface->pending_height);
|
||||
view_damage_from(view);
|
||||
}
|
||||
|
||||
|
|
|
@ -261,7 +261,7 @@ void arrange_windows(struct sway_container *container,
|
|||
{
|
||||
container->width = width;
|
||||
container->height = height;
|
||||
view_set_size(container->sway_view,
|
||||
view_configure(container->sway_view, container->x, container->y,
|
||||
container->width, container->height);
|
||||
wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f",
|
||||
container->width, container->height,
|
||||
|
@ -322,7 +322,8 @@ static void apply_horiz_layout(struct sway_container *container,
|
|||
wlr_log(L_DEBUG,
|
||||
"Calculating arrangement for %p:%d (will scale %f by %f)",
|
||||
child, child->type, width, scale);
|
||||
view_set_position(child->sway_view, child_x, y);
|
||||
view_configure(child->sway_view, child_x, y, child->width,
|
||||
child->height);
|
||||
|
||||
if (i == end - 1) {
|
||||
double remaining_width = x + width - child_x;
|
||||
|
@ -373,7 +374,8 @@ void apply_vert_layout(struct sway_container *container,
|
|||
wlr_log(L_DEBUG,
|
||||
"Calculating arrangement for %p:%d (will scale %f by %f)",
|
||||
child, child->type, height, scale);
|
||||
view_set_position(child->sway_view, x, child_y);
|
||||
view_configure(child->sway_view, x, child_y, child->width,
|
||||
child->height);
|
||||
|
||||
if (i == end - 1) {
|
||||
double remaining_height = y + height - child_y;
|
||||
|
|
|
@ -29,6 +29,7 @@ struct sway_container *container_output_destroy(struct sway_container *output) {
|
|||
wl_list_remove(&output->sway_output->destroy.link);
|
||||
wl_list_remove(&output->sway_output->mode.link);
|
||||
wl_list_remove(&output->sway_output->transform.link);
|
||||
wl_list_remove(&output->sway_output->scale.link);
|
||||
|
||||
wl_list_remove(&output->sway_output->damage_destroy.link);
|
||||
wl_list_remove(&output->sway_output->damage_frame.link);
|
||||
|
|
139
sway/tree/view.c
139
sway/tree/view.c
|
@ -62,55 +62,10 @@ const char *view_get_instance(struct sway_view *view) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void view_update_outputs(struct sway_view *view,
|
||||
const struct wlr_box *before) {
|
||||
struct wlr_output_layout *output_layout =
|
||||
root_container.sway_root->output_layout;
|
||||
struct wlr_box box = {
|
||||
.x = view->swayc->x,
|
||||
.y = view->swayc->y,
|
||||
.width = view->width,
|
||||
.height = view->height,
|
||||
};
|
||||
struct wlr_output_layout_output *layout_output;
|
||||
wl_list_for_each(layout_output, &output_layout->outputs, link) {
|
||||
bool intersected = before != NULL && wlr_output_layout_intersects(
|
||||
output_layout, layout_output->output, before);
|
||||
bool intersects = wlr_output_layout_intersects(output_layout,
|
||||
layout_output->output, &box);
|
||||
if (intersected && !intersects) {
|
||||
wlr_surface_send_leave(view->surface, layout_output->output);
|
||||
}
|
||||
if (!intersected && intersects) {
|
||||
wlr_surface_send_enter(view->surface, layout_output->output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void view_set_size(struct sway_view *view, int width, int height) {
|
||||
if (view->impl->set_size) {
|
||||
struct wlr_box box = {
|
||||
.x = view->swayc->x,
|
||||
.y = view->swayc->y,
|
||||
.width = view->width,
|
||||
.height = view->height,
|
||||
};
|
||||
view->impl->set_size(view, width, height);
|
||||
view_update_outputs(view, &box);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO make view coordinates in layout coordinates
|
||||
void view_set_position(struct sway_view *view, double ox, double oy) {
|
||||
if (view->impl->set_position) {
|
||||
struct wlr_box box = {
|
||||
.x = view->swayc->x,
|
||||
.y = view->swayc->y,
|
||||
.width = view->width,
|
||||
.height = view->height,
|
||||
};
|
||||
view->impl->set_position(view, ox, oy);
|
||||
view_update_outputs(view, &box);
|
||||
void view_configure(struct sway_view *view, double ox, double oy, int width,
|
||||
int height) {
|
||||
if (view->impl->configure) {
|
||||
view->impl->configure(view, ox, oy, width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,6 +91,56 @@ struct sway_container *container_view_destroy(struct sway_container *view) {
|
|||
return parent;
|
||||
}
|
||||
|
||||
void view_damage_whole(struct sway_view *view) {
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *cont = root_container.children->items[i];
|
||||
if (cont->type == C_OUTPUT) {
|
||||
output_damage_whole_view(cont->sway_output, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void view_damage_from(struct sway_view *view) {
|
||||
// TODO
|
||||
view_damage_whole(view);
|
||||
}
|
||||
|
||||
static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) {
|
||||
struct sway_container *cont = container_parent(view->swayc, C_OUTPUT);
|
||||
|
||||
struct wlr_output_layout *output_layout =
|
||||
root_container.sway_root->output_layout;
|
||||
struct wlr_box *output_box = wlr_output_layout_get_box(output_layout,
|
||||
cont->sway_output->wlr_output);
|
||||
|
||||
box->x = output_box->x + view->swayc->x;
|
||||
box->y = output_box->y + view->swayc->y;
|
||||
box->width = view->width;
|
||||
box->height = view->height;
|
||||
}
|
||||
|
||||
static void view_update_outputs(struct sway_view *view,
|
||||
const struct wlr_box *before) {
|
||||
struct wlr_box box;
|
||||
view_get_layout_box(view, &box);
|
||||
|
||||
struct wlr_output_layout *output_layout =
|
||||
root_container.sway_root->output_layout;
|
||||
struct wlr_output_layout_output *layout_output;
|
||||
wl_list_for_each(layout_output, &output_layout->outputs, link) {
|
||||
bool intersected = before != NULL && wlr_output_layout_intersects(
|
||||
output_layout, layout_output->output, before);
|
||||
bool intersects = wlr_output_layout_intersects(output_layout,
|
||||
layout_output->output, &box);
|
||||
if (intersected && !intersects) {
|
||||
wlr_surface_send_leave(view->surface, layout_output->output);
|
||||
}
|
||||
if (!intersected && intersects) {
|
||||
wlr_surface_send_enter(view->surface, layout_output->output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
|
||||
if (!sway_assert(view->surface == NULL, "cannot map mapped view")) {
|
||||
return;
|
||||
|
@ -153,6 +158,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
|
|||
sway_input_manager_set_focus(input_manager, cont);
|
||||
|
||||
view_damage_whole(view);
|
||||
view_update_outputs(view, NULL);
|
||||
}
|
||||
|
||||
void view_map_unmanaged(struct sway_view *view,
|
||||
|
@ -168,6 +174,8 @@ void view_map_unmanaged(struct sway_view *view,
|
|||
&view->unmanaged_view_link);
|
||||
|
||||
view_damage_whole(view);
|
||||
// TODO: make this work for unmanaged views
|
||||
//view_update_outputs(view, NULL);
|
||||
}
|
||||
|
||||
void view_unmap(struct sway_view *view) {
|
||||
|
@ -186,17 +194,30 @@ void view_unmap(struct sway_view *view) {
|
|||
view->surface = NULL;
|
||||
}
|
||||
|
||||
void view_damage_whole(struct sway_view *view) {
|
||||
struct sway_container *cont = NULL;
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
cont = root_container.children->items[i];
|
||||
if (cont->type == C_OUTPUT) {
|
||||
output_damage_whole_view(cont->sway_output, view);
|
||||
}
|
||||
void view_update_position(struct sway_view *view, double ox, double oy) {
|
||||
if (view->swayc->x == ox && view->swayc->y == oy) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void view_damage_from(struct sway_view *view) {
|
||||
// TODO
|
||||
struct wlr_box box;
|
||||
view_get_layout_box(view, &box);
|
||||
view_damage_whole(view);
|
||||
view->swayc->x = ox;
|
||||
view->swayc->y = oy;
|
||||
view_update_outputs(view, &box);
|
||||
view_damage_whole(view);
|
||||
}
|
||||
|
||||
void view_update_size(struct sway_view *view, int width, int height) {
|
||||
if (view->width == width && view->height == height) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_box box;
|
||||
view_get_layout_box(view, &box);
|
||||
view_damage_whole(view);
|
||||
view->width = width;
|
||||
view->height = height;
|
||||
view_update_outputs(view, &box);
|
||||
view_damage_whole(view);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue