Store geometry in the view and handle any floating view resizing

master
Ryan Dwyer 6 years ago
parent 4e755c4b12
commit b0a5f3a25f

@ -1,8 +1,13 @@
#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_surface.h>
struct sway_container; struct sway_container;
struct sway_view;
void desktop_damage_surface(struct wlr_surface *surface, double lx, double ly, void desktop_damage_surface(struct wlr_surface *surface, double lx, double ly,
bool whole); bool whole);
void desktop_damage_whole_container(struct sway_container *con); void desktop_damage_whole_container(struct sway_container *con);
void desktop_damage_box(struct wlr_box *box);
void desktop_damage_view(struct sway_view *view);

@ -38,7 +38,6 @@ struct sway_view_impl {
const char *(*get_string_prop)(struct sway_view *view, const char *(*get_string_prop)(struct sway_view *view,
enum sway_view_prop prop); enum sway_view_prop prop);
uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop); uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop);
void (*get_geometry)(struct sway_view *view, struct wlr_box *box);
uint32_t (*configure)(struct sway_view *view, double lx, double ly, uint32_t (*configure)(struct sway_view *view, double lx, double ly,
int width, int height); int width, int height);
void (*set_activated)(struct sway_view *view, bool activated); void (*set_activated)(struct sway_view *view, bool activated);
@ -88,7 +87,14 @@ struct sway_view {
struct wlr_buffer *saved_buffer; struct wlr_buffer *saved_buffer;
int saved_buffer_width, saved_buffer_height; int saved_buffer_width, saved_buffer_height;
struct wlr_box saved_geometry; // The "old" geometry during a transaction
// The geometry for whatever the client is committing, regardless of
// transaction state. Updated on every commit.
struct wlr_box geometry;
// The "old" geometry during a transaction. Used to damage the old location
// when a transaction is applied.
struct wlr_box saved_geometry;
bool destroying; bool destroying;
@ -243,8 +249,6 @@ const char *view_get_shell(struct sway_view *view);
void view_get_constraints(struct sway_view *view, double *min_width, void view_get_constraints(struct sway_view *view, double *min_width,
double *max_width, double *min_height, double *max_height); double *max_width, double *min_height, double *max_height);
void view_get_geometry(struct sway_view *view, struct wlr_box *box);
uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
int height); int height);
@ -289,6 +293,8 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);
void view_unmap(struct sway_view *view); void view_unmap(struct sway_view *view);
void view_update_size(struct sway_view *view, int width, int height);
void view_child_init(struct sway_view_child *child, void view_child_init(struct sway_view_child *child,
const struct sway_view_child_impl *impl, struct sway_view *view, const struct sway_view_child_impl *impl, struct sway_view *view,
struct wlr_surface *surface); struct wlr_surface *surface);

@ -22,3 +22,21 @@ void desktop_damage_whole_container(struct sway_container *con) {
} }
} }
} }
void desktop_damage_box(struct wlr_box *box) {
for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *cont = root_container.children->items[i];
output_damage_box(cont->sway_output, box);
}
}
void desktop_damage_view(struct sway_view *view) {
desktop_damage_whole_container(view->swayc);
struct wlr_box box = {
.x = view->swayc->current.view_x - view->geometry.x,
.y = view->swayc->current.view_y - view->geometry.y,
.width = view->surface->current.width,
.height = view->surface->current.height,
};
desktop_damage_box(&box);
}

@ -140,23 +140,20 @@ void output_surface_for_each_surface(struct sway_output *output,
void output_view_for_each_surface(struct sway_output *output, void output_view_for_each_surface(struct sway_output *output,
struct sway_view *view, sway_surface_iterator_func_t iterator, struct sway_view *view, sway_surface_iterator_func_t iterator,
void *user_data) { void *user_data) {
struct wlr_box geometry;
view_get_geometry(view, &geometry);
struct surface_iterator_data data = { struct surface_iterator_data data = {
.user_iterator = iterator, .user_iterator = iterator,
.user_data = user_data, .user_data = user_data,
.output = output, .output = output,
.ox = view->swayc->current.view_x - output->swayc->current.swayc_x .ox = view->swayc->current.view_x - output->swayc->current.swayc_x
- geometry.x, - view->geometry.x,
.oy = view->swayc->current.view_y - output->swayc->current.swayc_y .oy = view->swayc->current.view_y - output->swayc->current.swayc_y
- geometry.y, - view->geometry.y,
.width = view->swayc->current.view_width, .width = view->swayc->current.view_width,
.height = view->swayc->current.view_height, .height = view->swayc->current.view_height,
.rotation = 0, // TODO .rotation = 0, // TODO
}; };
view_for_each_surface(view, view_for_each_surface(view, output_for_each_surface_iterator, &data);
output_for_each_surface_iterator, &data);
} }
void output_view_for_each_popup(struct sway_output *output, void output_view_for_each_popup(struct sway_output *output,

@ -192,12 +192,12 @@ static void render_view_toplevels(struct sway_view *view,
.damage = damage, .damage = damage,
.alpha = alpha, .alpha = alpha,
}; };
struct wlr_box geometry;
view_get_geometry(view, &geometry);
// Render all toplevels without descending into popups // Render all toplevels without descending into popups
output_surface_for_each_surface(output, view->surface, double ox =
view->swayc->current.view_x - output->wlr_output->lx - geometry.x, view->swayc->current.view_x - output->wlr_output->lx - view->geometry.x;
view->swayc->current.view_y - output->wlr_output->ly - geometry.y, double oy =
view->swayc->current.view_y - output->wlr_output->ly - view->geometry.y;
output_surface_for_each_surface(output, view->surface, ox, oy,
render_surface_iterator, &data); render_surface_iterator, &data);
} }

@ -6,6 +6,7 @@
#include <time.h> #include <time.h>
#include <wlr/types/wlr_buffer.h> #include <wlr/types/wlr_buffer.h>
#include "sway/debug.h" #include "sway/debug.h"
#include "sway/desktop.h"
#include "sway/desktop/idle_inhibit_v1.h" #include "sway/desktop/idle_inhibit_v1.h"
#include "sway/desktop/transaction.h" #include "sway/desktop/transaction.h"
#include "sway/output.h" #include "sway/output.h"
@ -169,51 +170,17 @@ static void transaction_apply(struct sway_transaction *transaction) {
transaction->instructions->items[i]; transaction->instructions->items[i];
struct sway_container *container = instruction->container; struct sway_container *container = instruction->container;
// Damage the old and new locations // Damage the old location
struct wlr_box old_con_box = { desktop_damage_whole_container(container);
.x = container->current.swayc_x, if (container->type == C_VIEW && container->sway_view->saved_buffer) {
.y = container->current.swayc_y,
.width = container->current.swayc_width,
.height = container->current.swayc_height,
};
struct wlr_box new_con_box = {
.x = instruction->state.swayc_x,
.y = instruction->state.swayc_y,
.width = instruction->state.swayc_width,
.height = instruction->state.swayc_height,
};
// Handle geometry, which may overflow the bounds of the container
struct wlr_box old_surface_box = {0,0,0,0};
struct wlr_box new_surface_box = {0,0,0,0};
if (container->type == C_VIEW) {
struct sway_view *view = container->sway_view; struct sway_view *view = container->sway_view;
if (container->sway_view->saved_buffer) { struct wlr_box box = {
old_surface_box.x = .x = container->current.view_x - view->saved_geometry.x,
container->current.view_x - view->saved_geometry.x; .y = container->current.view_y - view->saved_geometry.y,
old_surface_box.y = .width = view->saved_buffer_width,
container->current.view_y - view->saved_geometry.y; .height = view->saved_buffer_height,
old_surface_box.width = view->saved_buffer_width; };
old_surface_box.height = view->saved_buffer_height; desktop_damage_box(&box);
}
struct wlr_surface *surface = container->sway_view->surface;
if (surface) {
struct wlr_box geometry;
view_get_geometry(view, &geometry);
new_surface_box.x = instruction->state.view_x - geometry.x;
new_surface_box.y = instruction->state.view_y - geometry.y;
new_surface_box.width = surface->current.width;
new_surface_box.height = surface->current.height;
}
}
for (int j = 0; j < root_container.current.children->length; ++j) {
struct sway_container *output =
root_container.current.children->items[j];
if (output->sway_output) {
output_damage_box(output->sway_output, &old_con_box);
output_damage_box(output->sway_output, &new_con_box);
output_damage_box(output->sway_output, &old_surface_box);
output_damage_box(output->sway_output, &new_surface_box);
}
} }
// There are separate children lists for each instruction state, the // There are separate children lists for each instruction state, the
@ -230,6 +197,20 @@ static void transaction_apply(struct sway_transaction *transaction) {
view_remove_saved_buffer(container->sway_view); view_remove_saved_buffer(container->sway_view);
} }
// Damage the new location
desktop_damage_whole_container(container);
if (container->type == C_VIEW && container->sway_view->surface) {
struct sway_view *view = container->sway_view;
struct wlr_surface *surface = view->surface;
struct wlr_box box = {
.x = container->current.view_x - view->geometry.x,
.y = container->current.view_y - view->geometry.y,
.width = surface->current.width,
.height = surface->current.height,
};
desktop_damage_box(&box);
}
container->instruction = NULL; container->instruction = NULL;
} }
} }
@ -323,7 +304,8 @@ static void transaction_commit(struct sway_transaction *transaction) {
} }
if (con->type == C_VIEW) { if (con->type == C_VIEW) {
view_save_buffer(con->sway_view); view_save_buffer(con->sway_view);
view_get_geometry(con->sway_view, &con->sway_view->saved_geometry); memcpy(&con->sway_view->saved_geometry, &con->sway_view->geometry,
sizeof(struct wlr_box));
} }
con->instruction = instruction; con->instruction = instruction;
} }

@ -7,6 +7,7 @@
#include <wlr/util/edges.h> #include <wlr/util/edges.h>
#include "log.h" #include "log.h"
#include "sway/decoration.h" #include "sway/decoration.h"
#include "sway/desktop.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/server.h" #include "sway/server.h"
@ -122,16 +123,6 @@ static const char *get_string_prop(struct sway_view *view,
} }
} }
static void get_geometry(struct sway_view *view, struct wlr_box *box) {
struct sway_xdg_shell_view *xdg_shell_view =
xdg_shell_view_from_view(view);
if (xdg_shell_view == NULL) {
return;
}
struct wlr_xdg_surface *surface = view->wlr_xdg_surface;
wlr_xdg_surface_get_geometry(surface, box);
}
static uint32_t configure(struct sway_view *view, double lx, double ly, static uint32_t configure(struct sway_view *view, double lx, double ly,
int width, int height) { int width, int height) {
struct sway_xdg_shell_view *xdg_shell_view = struct sway_xdg_shell_view *xdg_shell_view =
@ -242,7 +233,6 @@ static void destroy(struct sway_view *view) {
static const struct sway_view_impl view_impl = { static const struct sway_view_impl view_impl = {
.get_constraints = get_constraints, .get_constraints = get_constraints,
.get_string_prop = get_string_prop, .get_string_prop = get_string_prop,
.get_geometry = get_geometry,
.configure = configure, .configure = configure,
.set_activated = set_activated, .set_activated = set_activated,
.set_tiled = set_tiled, .set_tiled = set_tiled,
@ -267,8 +257,24 @@ static void handle_commit(struct wl_listener *listener, void *data) {
} }
if (view->swayc->instruction) { if (view->swayc->instruction) {
wlr_xdg_surface_get_geometry(xdg_surface, &view->geometry);
transaction_notify_view_ready_by_serial(view, transaction_notify_view_ready_by_serial(view,
xdg_surface->configure_serial); xdg_surface->configure_serial);
} else {
struct wlr_box new_geo;
wlr_xdg_surface_get_geometry(xdg_surface, &new_geo);
if ((new_geo.width != view->width || new_geo.height != view->height) &&
container_is_floating(view->swayc)) {
// A floating view has unexpectedly sent a new size
desktop_damage_view(view);
view_update_size(view, new_geo.width, new_geo.height);
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
desktop_damage_view(view);
transaction_commit_dirty();
} else {
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
}
} }
view_damage_from(view); view_damage_from(view);

@ -6,6 +6,7 @@
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include "log.h" #include "log.h"
#include "sway/decoration.h" #include "sway/decoration.h"
#include "sway/desktop.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/server.h" #include "sway/server.h"
@ -121,16 +122,6 @@ static const char *get_string_prop(struct sway_view *view,
} }
} }
static void get_geometry(struct sway_view *view, struct wlr_box *box) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
xdg_shell_v6_view_from_view(view);
if (xdg_shell_v6_view == NULL) {
return;
}
struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6;
wlr_xdg_surface_v6_get_geometry(surface, box);
}
static uint32_t configure(struct sway_view *view, double lx, double ly, static uint32_t configure(struct sway_view *view, double lx, double ly,
int width, int height) { int width, int height) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view = struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
@ -239,7 +230,6 @@ static void destroy(struct sway_view *view) {
static const struct sway_view_impl view_impl = { static const struct sway_view_impl view_impl = {
.get_constraints = get_constraints, .get_constraints = get_constraints,
.get_string_prop = get_string_prop, .get_string_prop = get_string_prop,
.get_geometry = get_geometry,
.configure = configure, .configure = configure,
.set_activated = set_activated, .set_activated = set_activated,
.set_tiled = set_tiled, .set_tiled = set_tiled,
@ -262,9 +252,26 @@ static void handle_commit(struct wl_listener *listener, void *data) {
if (!view->swayc) { if (!view->swayc) {
return; return;
} }
if (view->swayc->instruction) { if (view->swayc->instruction) {
wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &view->geometry);
transaction_notify_view_ready_by_serial(view, transaction_notify_view_ready_by_serial(view,
xdg_surface_v6->configure_serial); xdg_surface_v6->configure_serial);
} else {
struct wlr_box new_geo;
wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &new_geo);
if ((new_geo.width != view->width || new_geo.height != view->height) &&
container_is_floating(view->swayc)) {
// A floating view has unexpectedly sent a new size
desktop_damage_view(view);
view_update_size(view, new_geo.width, new_geo.height);
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
desktop_damage_view(view);
transaction_commit_dirty();
} else {
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
}
} }
view_damage_from(view); view_damage_from(view);

@ -277,6 +277,17 @@ static const struct sway_view_impl view_impl = {
.destroy = destroy, .destroy = destroy,
}; };
static void get_geometry(struct sway_view *view, struct wlr_box *box) {
box->x = box->y = 0;
if (view->surface) {
box->width = view->surface->current.width;
box->height = view->surface->current.height;
} else {
box->width = 0;
box->height = 0;
}
}
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view = struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, commit); wl_container_of(listener, xwayland_view, commit);
@ -285,18 +296,25 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct wlr_surface_state *state = &xsurface->surface->current; struct wlr_surface_state *state = &xsurface->surface->current;
if (view->swayc->instruction) { if (view->swayc->instruction) {
get_geometry(view, &view->geometry);
transaction_notify_view_ready_by_size(view, transaction_notify_view_ready_by_size(view,
state->width, state->height); state->width, state->height);
} else if ((state->width != view->width || state->height != view->height) && } else {
struct wlr_box new_geo;
get_geometry(view, &new_geo);
if ((new_geo.width != view->width || new_geo.height != view->height) &&
container_is_floating(view->swayc)) { container_is_floating(view->swayc)) {
// eg. The Firefox "Save As" dialog when downloading a file // A floating view has unexpectedly sent a new size
// It maps at a small size then changes afterwards. // eg. The Firefox "Save As" dialog when downloading a file
view->width = state->width; desktop_damage_view(view);
view->height = state->height; view_update_size(view, new_geo.width, new_geo.height);
view->swayc->current.view_width = state->width; memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
view->swayc->current.view_height = state->height; desktop_damage_view(view);
container_set_geometry_from_floating_view(view->swayc); transaction_commit_dirty();
transaction_commit_dirty(); } else {
memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box));
}
} }
view_damage_from(view); view_damage_from(view);

@ -522,13 +522,8 @@ static void surface_at_view(struct sway_container *swayc, double lx, double ly,
return; return;
} }
struct sway_view *sview = swayc->sway_view; struct sway_view *sview = swayc->sway_view;
double view_sx = lx - sview->x; double view_sx = lx - sview->x + sview->geometry.x;
double view_sy = ly - sview->y; double view_sy = ly - sview->y + sview->geometry.y;
struct wlr_box geometry;
view_get_geometry(sview, &geometry);
view_sx += geometry.x;
view_sy += geometry.y;
double _sx, _sy; double _sx, _sy;
struct wlr_surface *_surface = NULL; struct wlr_surface *_surface = NULL;

@ -162,20 +162,6 @@ void view_get_constraints(struct sway_view *view, double *min_width,
} }
} }
void view_get_geometry(struct sway_view *view, struct wlr_box *box) {
if (view->surface == NULL) {
box->x = box->y = box->width = box->height = 0;
return;
}
if (view->impl->get_geometry) {
view->impl->get_geometry(view, box);
return;
}
box->x = box->y = 0;
box->width = view->surface->current.width;
box->height = view->surface->current.height;
}
uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
int height) { int height) {
if (view->impl->configure) { if (view->impl->configure) {
@ -629,6 +615,18 @@ void view_unmap(struct sway_view *view) {
view->surface = NULL; view->surface = NULL;
} }
void view_update_size(struct sway_view *view, int width, int height) {
if (!sway_assert(container_is_floating(view->swayc),
"Expected a floating container")) {
return;
}
view->width = width;
view->height = height;
view->swayc->current.view_width = width;
view->swayc->current.view_height = height;
container_set_geometry_from_floating_view(view->swayc);
}
static void view_subsurface_create(struct sway_view *view, static void view_subsurface_create(struct sway_view *view,
struct wlr_subsurface *subsurface) { struct wlr_subsurface *subsurface) {
struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child));

Loading…
Cancel
Save