surface: better buffer position handling

This commit is contained in:
emersion 2018-06-25 22:38:40 +01:00
parent e6399c61b7
commit adf0423f7c
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
3 changed files with 14 additions and 8 deletions

View file

@ -23,7 +23,7 @@ struct wlr_surface_state {
uint32_t committed; // enum wlr_surface_state_field
struct wl_resource *buffer;
int32_t sx, sy;
int32_t dx, dy; // relative to previous position
pixman_region32_t surface_damage, buffer_damage;
pixman_region32_t opaque, input;
enum wl_output_transform transform;
@ -32,6 +32,7 @@ struct wlr_surface_state {
int width, height; // in surface-local coordinates
int buffer_width, buffer_height;
int sx, sy; // in surface-local coordinates
struct wl_listener buffer_destroy_listener;
};

View file

@ -341,8 +341,8 @@ static void drag_icon_handle_surface_destroy(struct wl_listener *listener,
static void drag_icon_handle_surface_commit(struct wlr_surface *surface,
void *role_data) {
struct wlr_drag_icon *icon = role_data;
icon->sx += icon->surface->current.sx;
icon->sy += icon->surface->current.sy;
icon->sx += icon->surface->current.dx;
icon->sy += icon->surface->current.dy;
drag_icon_set_mapped(icon, wlr_surface_has_buffer(surface));
}

View file

@ -64,12 +64,12 @@ static void surface_destroy(struct wl_client *client,
static void surface_attach(struct wl_client *client,
struct wl_resource *resource,
struct wl_resource *buffer, int32_t sx, int32_t sy) {
struct wl_resource *buffer, int32_t dx, int32_t dy) {
struct wlr_surface *surface = wlr_surface_from_resource(resource);
surface->pending.committed |= WLR_SURFACE_STATE_BUFFER;
surface->pending.sx = sx;
surface->pending.sy = sy;
surface->pending.dx = dx;
surface->pending.dy = dy;
surface_state_set_buffer(&surface->pending, buffer);
}
@ -203,9 +203,14 @@ static void surface_move_state(struct wlr_surface *surface,
if ((next->committed & WLR_SURFACE_STATE_BUFFER)) {
surface_state_set_buffer(state, next->buffer);
surface_state_reset_buffer(next);
state->sx = next->sx;
state->sy = next->sy;
state->dx = next->dx;
state->dy = next->dy;
next->dx = next->dy = 0;
state->sx += state->dx;
state->sy += state->dy;
update_size = true;
} else {
state->dx = state->dy = 0;
}
if (update_size) {
update_damage = surface_update_size(surface, state);