Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Atomic layout updates #2072

Merged
merged 39 commits into from
Jun 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
59c9488
WIP: Atomic layout updates ground work
RyanDwyer Jun 3, 2018
f9e6d70
Make main properties be the pending state
RyanDwyer Jun 6, 2018
bb66e6d
Refactor everything that needs to arrange windows
RyanDwyer Jun 6, 2018
9e96cfd
Merge remote-tracking branch 'upstream/master' into atomic
RyanDwyer Jun 11, 2018
645bf44
Merge remote-tracking branch 'upstream/master' into atomic
RyanDwyer Jun 18, 2018
1c89f32
Preserve buffers during transactions
RyanDwyer Jun 18, 2018
38398e2
Implement atomic layout updates for tree operations
RyanDwyer Jun 23, 2018
b11c919
Merge remote-tracking branch 'upstream/master' into atomic
RyanDwyer Jun 23, 2018
32b865e
Fix crash when deleting last child in a tabbed or stacked container
RyanDwyer Jun 23, 2018
f08a30d
Force transactions to complete in order
RyanDwyer Jun 24, 2018
33e03cb
Fix crash related to stacks and tabs
RyanDwyer Jun 24, 2018
b864ac0
Fix crash when unmapping a view with reapable parents
RyanDwyer Jun 24, 2018
b6a238c
Fix crash when running move <direction> in an empty workspace
RyanDwyer Jun 24, 2018
1549fb7
Implement atomic layout updates for xwayland views
RyanDwyer Jun 24, 2018
a3976e2
Fix another crash when moving out of stacks or tabs
RyanDwyer Jun 24, 2018
289d696
Implement transaction timings debug
RyanDwyer Jun 24, 2018
c371ff3
Implement per-configure debug timings
RyanDwyer Jun 24, 2018
9b15e81
Fix potential crash when fullscreen view unmaps
RyanDwyer Jun 25, 2018
beacd4d
Rename progress_queue to transaction_progress_queue
RyanDwyer Jun 25, 2018
7a922c6
Damage output when a fullscreen view unmaps
RyanDwyer Jun 26, 2018
50190bc
Rename view's free callback to destroy
RyanDwyer Jun 26, 2018
e8001e6
Damage output when views toggle fullscreen
RyanDwyer Jun 26, 2018
0085f64
Remove timer when transaction destroys
RyanDwyer Jun 26, 2018
834805f
Fix crash when disconnecting output
RyanDwyer Jun 26, 2018
93696b7
Fix crash when closing output window from outer session
RyanDwyer Jun 26, 2018
a7b3f29
Remove incorrect assertion and supporting code
RyanDwyer Jun 26, 2018
61c1187
Fix nitpicks
RyanDwyer Jun 27, 2018
be86d3a
Remove transaction_add_damage
RyanDwyer Jun 27, 2018
8773ed3
Fix memleak in container_get_box
RyanDwyer Jun 27, 2018
e6829c5
Move unsetting of view->surface into view_unmap
RyanDwyer Jun 27, 2018
9652529
Allow views to skip configures
RyanDwyer Jun 27, 2018
e8fb6b3
Fix crash when moving last child of a container to workspace or output
RyanDwyer Jun 29, 2018
d7169ee
Replace list_empty with a simple alternative
RyanDwyer Jun 29, 2018
3c81a90
Add comment about usage to arrange_windows declaration
RyanDwyer Jun 29, 2018
a2fbb20
Merge remote-tracking branch 'upstream/master' into atomic
RyanDwyer Jun 29, 2018
3a6ed51
Render saved buffers with the surface's dimensions
RyanDwyer Jun 29, 2018
96c8c02
Fix flash of background when xwayland views are mapped
RyanDwyer Jun 30, 2018
fc6fde7
Fix compile error
RyanDwyer Jun 30, 2018
e396af8
Merge remote-tracking branch 'upstream/master' into atomic
RyanDwyer Jun 30, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions include/sway/desktop/transaction.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#ifndef _SWAY_TRANSACTION_H
#define _SWAY_TRANSACTION_H
#include <wlr/render/wlr_texture.h>
#include "sway/tree/container.h"

/**
* Transactions enable us to perform atomic layout updates.
*
* When we want to make adjustments to the layout, we create a transaction.
* A transaction contains a list of affected containers and their new state.
* A state might contain a new size, or new border settings, or new parent/child
* relationships.
*
* Calling transaction_commit() makes sway notify of all the affected clients
* with their new sizes. We then wait for all the views to respond with their
* new surface sizes. When all are ready, or when a timeout has passed, we apply
* the updates all at the same time.
*/

struct sway_transaction;

/**
* Create a new transaction.
*/
struct sway_transaction *transaction_create(void);

/**
* Add a container's pending state to the transaction.
*/
void transaction_add_container(struct sway_transaction *transaction,
struct sway_container *container);

/**
* Submit a transaction to the client views for configuration.
*/
void transaction_commit(struct sway_transaction *transaction);

/**
* Notify the transaction system that a view is ready for the new layout.
*
* When all views in the transaction are ready, the layout will be applied.
*/
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 saved texture that should be rendered for a view.
*
* The addresses pointed at by the width and height pointers will be populated
* with the surface's dimensions, which may be different to the texture's
* dimensions if output scaling is used.
*
* This function should only be called if it is known that the view has
* instructions.
*/
struct wlr_texture *transaction_get_saved_texture(struct sway_view *view,
int *width, int *height);

#endif
11 changes: 11 additions & 0 deletions include/sway/input/seat.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat,
struct sway_container *seat_get_active_child(struct sway_seat *seat,
struct sway_container *container);

/**
* Return the immediate child of container which was most recently focused, with
* fallback to selecting the child in the parent's `current` (rendered) children
* list.
*
* This is useful for when a tabbed container and its children are destroyed but
* still being rendered, and we have to render an appropriate child.
*/
struct sway_container *seat_get_active_current_child(struct sway_seat *seat,
struct sway_container *container);

/**
* Iterate over the focus-inactive children of the container calling the
* function on each.
Expand Down
2 changes: 2 additions & 0 deletions include/sway/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ void output_damage_surface(struct sway_output *output, double ox, double oy,
void output_damage_from_view(struct sway_output *output,
struct sway_view *view);

void output_damage_box(struct sway_output *output, struct wlr_box *box);

void output_damage_whole_container(struct sway_output *output,
struct sway_container *con);

Expand Down
9 changes: 9 additions & 0 deletions include/sway/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/render/wlr_renderer.h>
// TODO WLR: make Xwayland optional
#include "list.h"
#include "sway/xwayland.h"

struct sway_server {
Expand Down Expand Up @@ -40,6 +41,14 @@ struct sway_server {
struct sway_xwayland xwayland;
struct wl_listener xwayland_surface;
struct wl_listener xwayland_ready;

bool debug_txn_timings;

list_t *transactions;

// When a view is being destroyed and is waiting for a transaction to
// complete it will be stored here.
list_t *destroying_containers;
};

struct sway_server server;
Expand Down
34 changes: 23 additions & 11 deletions include/sway/tree/arrange.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef _SWAY_ARRANGE_H
#define _SWAY_ARRANGE_H
#include "sway/desktop/transaction.h"

struct sway_container;

Expand All @@ -9,16 +10,27 @@ void remove_gaps(struct sway_container *c);
// Add gaps around container
void add_gaps(struct sway_container *c);

// Determine the root container's geometry, then iterate to everything below
void arrange_root(void);

// Determine the output's geometry, then iterate to everything below
void arrange_output(struct sway_container *output);

// Determine the workspace's geometry, then iterate to everything below
void arrange_workspace(struct sway_container *workspace);

// Arrange layout for all the children of the given workspace/container
void arrange_children_of(struct sway_container *parent);
/**
* Arrange layout for all the children of the given container, and add them to
* the given transaction.
*
* Use this function if you need to arrange multiple sections of the tree in one
* transaction.
*
* You must set the desired state of the container before calling
* arrange_windows, then don't change any state-tracked properties in the
* container until you've called transaction_commit.
*/
void arrange_windows(struct sway_container *container,
struct sway_transaction *transaction);

/**
* Arrange layout for the given container and commit the transaction.
*
* This function is a wrapper around arrange_windows, and handles creating and
* committing the transaction for you. Use this function if you're only doing
* one arrange operation.
*/
void arrange_and_commit(struct sway_container *container);

#endif
48 changes: 46 additions & 2 deletions include/sway/tree/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ struct sway_output;
struct sway_workspace;
struct sway_view;

struct sway_container_state {
// Container/swayc properties
enum sway_container_layout layout;
double swayc_x, swayc_y;
double swayc_width, swayc_height;

bool has_gaps;
double current_gaps;
double gaps_inner;
double gaps_outer;

struct sway_container *parent;
list_t *children;

// View properties
double view_x, view_y;
double view_width, view_height;
bool is_fullscreen;

enum sway_container_border border;
int border_thickness;
bool border_top;
bool border_bottom;
bool border_left;
bool border_right;

// Workspace properties
struct sway_view *ws_fullscreen;
struct sway_container *ws_floating;
};

struct sway_container {
union {
// TODO: Encapsulate state for other node types as well like C_CONTAINER
Expand All @@ -69,6 +100,10 @@ struct sway_container {
*/
size_t id;

// The pending state is the main container properties, and the current state is in the below struct.
// This means most places of the code can refer to the main variables (pending state) and it'll just work.
struct sway_container_state current;

char *name; // The view's title (unformatted)
char *formatted_title; // The title displayed in the title bar

Expand Down Expand Up @@ -97,8 +132,6 @@ struct sway_container {

struct sway_container *parent;

list_t *marks; // list of char*

float alpha;

struct wlr_texture *title_focused;
Expand All @@ -107,6 +140,10 @@ struct sway_container {
struct wlr_texture *title_urgent;
size_t title_height;

list_t *instructions; // struct sway_transaction_instruction *

bool destroying;

struct {
struct wl_signal destroy;
// Raised after the tree updates, but before arrange_windows
Expand Down Expand Up @@ -150,6 +187,8 @@ struct sway_container *workspace_create(struct sway_container *output,
struct sway_container *container_view_create(
struct sway_container *sibling, struct sway_view *sway_view);

void container_free(struct sway_container *cont);

struct sway_container *container_destroy(struct sway_container *container);

struct sway_container *container_close(struct sway_container *container);
Expand Down Expand Up @@ -253,4 +292,9 @@ void container_set_geometry_from_floating_view(struct sway_container *con);
*/
bool container_is_floating(struct sway_container *container);

/**
* Get a container's box in layout coordinates.
*/
void container_get_box(struct sway_container *container, struct wlr_box *box);

#endif
22 changes: 12 additions & 10 deletions include/sway/tree/view.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ struct sway_view_impl {
const char *(*get_string_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 (*configure)(struct sway_view *view, double lx, double ly, int width,
int height);
uint32_t (*configure)(struct sway_view *view, double lx, double ly,
int width, int height);
void (*set_activated)(struct sway_view *view, bool activated);
void (*set_tiled)(struct sway_view *view, bool tiled);
void (*set_fullscreen)(struct sway_view *view, bool fullscreen);
Expand Down Expand Up @@ -69,6 +69,8 @@ struct sway_view {
bool border_left;
bool border_right;

bool destroying;

list_t *executed_criteria; // struct criteria *
list_t *marks; // char *

Expand Down Expand Up @@ -104,8 +106,6 @@ struct sway_xdg_shell_v6_view {
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener destroy;

int pending_width, pending_height;
};

struct sway_xdg_shell_view {
Expand All @@ -120,8 +120,6 @@ struct sway_xdg_shell_view {
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener destroy;

int pending_width, pending_height;
};

struct sway_xwayland_view {
Expand All @@ -139,9 +137,6 @@ struct sway_xwayland_view {
struct wl_listener map;
struct wl_listener unmap;
struct wl_listener destroy;

int pending_lx, pending_ly;
int pending_width, pending_height;
};

struct sway_xwayland_unmanaged {
Expand Down Expand Up @@ -213,9 +208,14 @@ uint32_t view_get_window_type(struct sway_view *view);

const char *view_get_shell(struct sway_view *view);

void view_configure(struct sway_view *view, double ox, double oy, int width,
uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
int height);

/**
* Center the view in its workspace and build the swayc decorations around it.
*/
void view_init_floating(struct sway_view *view);

/**
* Configure the view's position and size based on the swayc's position and
* size, taking borders into consideration.
Expand All @@ -242,6 +242,8 @@ void view_for_each_surface(struct sway_view *view,
void view_init(struct sway_view *view, enum sway_view_type type,
const struct sway_view_impl *impl);

void view_free(struct sway_view *view);

void view_destroy(struct sway_view *view);

void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);
Expand Down
7 changes: 3 additions & 4 deletions sway/commands/border.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "sway/config.h"
#include "sway/input/cursor.h"
#include "sway/input/input-manager.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/view.h"

Expand Down Expand Up @@ -38,13 +39,11 @@ struct cmd_results *cmd_border(int argc, char **argv) {
}

if (container_is_floating(view->swayc)) {
container_damage_whole(view->swayc);
container_set_geometry_from_floating_view(view->swayc);
container_damage_whole(view->swayc);
} else {
view_autoconfigure(view);
}

arrange_and_commit(view->swayc);

struct sway_seat *seat = input_manager_current_seat(input_manager);
if (seat->cursor) {
cursor_send_pointer_motion(seat->cursor, 0, false);
Expand Down
3 changes: 3 additions & 0 deletions sway/commands/floating.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@ struct cmd_results *cmd_floating(int argc, char **argv) {

container_set_floating(container, wants_floating);

struct sway_container *workspace = container_parent(container, C_WORKSPACE);
arrange_and_commit(workspace);

return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
4 changes: 4 additions & 0 deletions sway/commands/fullscreen.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "log.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/view.h"
#include "sway/tree/layout.h"
Expand Down Expand Up @@ -32,5 +33,8 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {

view_set_fullscreen(view, wants_fullscreen);

struct sway_container *workspace = container_parent(container, C_WORKSPACE);
arrange_and_commit(workspace->parent);

return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
Loading