view: add lock/unlock functions

This commit is contained in:
Kirill Primak 2021-07-30 11:34:10 +03:00
parent 3809e80ef9
commit 258f167528
2 changed files with 26 additions and 0 deletions

View file

@ -70,6 +70,9 @@ struct sway_view {
// Used when changing a view from tiled to floating.
int natural_width, natural_height;
bool surface_locked;
uint32_t lock_seq;
char *title_format;
bool using_csd;
@ -341,6 +344,10 @@ void view_set_urgent(struct sway_view *view, bool enable);
bool view_is_urgent(struct sway_view *view);
void view_lock_pending(struct sway_view *view);
void view_unlock_cached(struct sway_view *view);
bool view_is_transient_for(struct sway_view *child, struct sway_view *ancestor);
#endif

View file

@ -875,6 +875,11 @@ void view_unmap(struct sway_view *view) {
}
transaction_commit_dirty();
if (view->surface_locked) {
view_unlock_cached(view);
}
view->surface = NULL;
}
@ -1377,3 +1382,17 @@ bool view_is_transient_for(struct sway_view *child,
return child->impl->is_transient_for &&
child->impl->is_transient_for(child, ancestor);
}
void view_lock_pending(struct sway_view *view) {
sway_assert(!view->surface_locked, "Can't lock a locked view");
if (view->surface) {
view->surface_locked = true;
view->lock_seq = wlr_surface_lock_pending(view->surface);
}
}
void view_unlock_cached(struct sway_view *view) {
sway_assert(view->surface_locked, "Can't unlock an unlocked view");
view->surface_locked = false;
wlr_surface_unlock_cached(view->surface, view->lock_seq);
}