Implement atomic layout updates for xwayland views

This commit is contained in:
Ryan Dwyer 2018-06-24 23:01:09 +10:00
parent b6a238c7b7
commit 1549fb719a
3 changed files with 40 additions and 27 deletions

View File

@ -49,6 +49,15 @@ void transaction_commit(struct sway_transaction *transaction);
*/ */
void transaction_notify_view_ready(struct sway_view *view, uint32_t serial); void transaction_notify_view_ready(struct sway_view *view, uint32_t serial);
/**
* Notify the transaction system that a view is ready for the new layout, but
* identifying the instruction by width and height rather than by serial.
*
* This is used by xwayland views, as they don't have serials.
*/
void transaction_notify_view_ready_by_size(struct sway_view *view,
int width, int height);
/** /**
* Get the texture that should be rendered for a view. * Get the texture that should be rendered for a view.
* *

View File

@ -267,9 +267,7 @@ void transaction_commit(struct sway_transaction *transaction) {
instruction->state.view_y, instruction->state.view_y,
instruction->state.view_width, instruction->state.view_width,
instruction->state.view_height); instruction->state.view_height);
if (instruction->serial) { ++transaction->num_waiting;
++transaction->num_waiting;
}
} }
list_add(con->instructions, instruction); list_add(con->instructions, instruction);
} }
@ -307,20 +305,8 @@ void transaction_commit(struct sway_transaction *transaction) {
update_debug_tree(); update_debug_tree();
} }
void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) { static void set_instruction_ready(
// Find the instruction struct sway_transaction_instruction *instruction) {
struct sway_transaction_instruction *instruction = NULL;
for (int i = 0; i < view->swayc->instructions->length; ++i) {
struct sway_transaction_instruction *tmp_instruction =
view->swayc->instructions->items[i];
if (tmp_instruction->serial == serial && !tmp_instruction->ready) {
instruction = tmp_instruction;
break;
}
}
if (!instruction) {
return;
}
instruction->ready = true; instruction->ready = true;
// If all views are ready, apply the transaction. // If all views are ready, apply the transaction.
@ -335,6 +321,30 @@ void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) {
} }
} }
void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) {
for (int i = 0; i < view->swayc->instructions->length; ++i) {
struct sway_transaction_instruction *instruction =
view->swayc->instructions->items[i];
if (instruction->serial == serial && !instruction->ready) {
set_instruction_ready(instruction);
return;
}
}
}
void transaction_notify_view_ready_by_size(struct sway_view *view,
int width, int height) {
for (int i = 0; i < view->swayc->instructions->length; ++i) {
struct sway_transaction_instruction *instruction =
view->swayc->instructions->items[i];
if (!instruction->ready && instruction->state.view_width == width &&
instruction->state.view_height == height) {
set_instruction_ready(instruction);
return;
}
}
}
struct wlr_texture *transaction_get_texture(struct sway_view *view) { struct wlr_texture *transaction_get_texture(struct sway_view *view) {
if (!view->swayc || !view->swayc->instructions->length) { if (!view->swayc || !view->swayc->instructions->length) {
return view->surface->buffer->texture; return view->surface->buffer->texture;

View File

@ -7,6 +7,7 @@
#include <wlr/xwayland.h> #include <wlr/xwayland.h>
#include "log.h" #include "log.h"
#include "sway/desktop.h" #include "sway/desktop.h"
#include "sway/desktop/transaction.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/output.h" #include "sway/output.h"
@ -243,16 +244,9 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_view *view = &xwayland_view->view; struct sway_view *view = &xwayland_view->view;
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
// Don't allow xwayland views to do resize or reposition themselves if if (view->swayc->instructions->length) {
// they're involved in a transaction. Once the transaction has finished transaction_notify_view_ready_by_size(view,
// they'll apply the next time a commit happens. xsurface->width, xsurface->height);
if (view->swayc && view->swayc->instructions->length) {
if (view->swayc && container_is_floating(view->swayc)) {
view_update_size(view, xsurface->width, xsurface->height);
} else {
view_update_size(view, view->swayc->width, view->swayc->height);
}
view_update_position(view, view->x, view->y);
} }
view_damage_from(view); view_damage_from(view);
} }