Add view_get_geometry

master
emersion 7 years ago committed by Ryan Dwyer
parent db4b4935b3
commit b3ee9af0c8

@ -38,6 +38,7 @@ 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);
@ -285,10 +286,6 @@ 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_position(struct sway_view *view, double lx, double ly);
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);

@ -107,7 +107,8 @@ static void get_constraints(struct sway_view *view, double *min_width,
*max_height = state->max_height > 0 ? state->max_height : DBL_MAX; *max_height = state->max_height > 0 ? state->max_height : DBL_MAX;
} }
static const char *get_string_prop(struct sway_view *view, enum sway_view_prop prop) { static const char *get_string_prop(struct sway_view *view,
enum sway_view_prop prop) {
if (xdg_shell_view_from_view(view) == NULL) { if (xdg_shell_view_from_view(view) == NULL) {
return NULL; return NULL;
} }
@ -121,6 +122,16 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p
} }
} }
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 =
@ -231,6 +242,7 @@ 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,

@ -287,8 +287,6 @@ static void handle_commit(struct wl_listener *listener, void *data) {
if (view->swayc->instruction) { if (view->swayc->instruction) {
transaction_notify_view_ready_by_size(view, transaction_notify_view_ready_by_size(view,
surface_state->width, surface_state->height); surface_state->width, surface_state->height);
} else if (container_is_floating(view->swayc)) {
view_update_size(view, surface_state->width, surface_state->height);
} }
view_damage_from(view); view_damage_from(view);

@ -162,6 +162,20 @@ 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) {
@ -615,36 +629,6 @@ void view_unmap(struct sway_view *view) {
view->surface = NULL; view->surface = NULL;
} }
void view_update_position(struct sway_view *view, double lx, double ly) {
if (view->x == lx && view->y == ly) {
return;
}
container_damage_whole(view->swayc);
view->x = lx;
view->y = ly;
view->swayc->current.view_x = lx;
view->swayc->current.view_y = ly;
if (container_is_floating(view->swayc)) {
container_set_geometry_from_floating_view(view->swayc);
}
container_damage_whole(view->swayc);
}
void view_update_size(struct sway_view *view, int width, int height) {
if (view->width == width && view->height == height) {
return;
}
container_damage_whole(view->swayc);
view->width = width;
view->height = height;
view->swayc->current.view_width = width;
view->swayc->current.view_height = height;
if (container_is_floating(view->swayc)) {
container_set_geometry_from_floating_view(view->swayc);
}
container_damage_whole(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