From f3ab895916ca1a0f004b5ceaefa90eee90676532 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 4 May 2018 08:24:25 -0400 Subject: [PATCH 01/34] Implement `floating enable` --- include/sway/tree/container.h | 3 +++ include/sway/tree/layout.h | 3 +++ include/sway/tree/workspace.h | 1 + sway/commands.c | 3 ++- sway/commands/floating.c | 48 +++++++++++++++++++++++++++++++++++ sway/meson.build | 1 + sway/tree/layout.c | 43 ++++++++++++++++++++++++++++--- sway/tree/workspace.c | 2 ++ 8 files changed, 99 insertions(+), 5 deletions(-) create mode 100644 sway/commands/floating.c diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index bb6c04a6..fa2f9286 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -76,6 +76,9 @@ struct sway_container { enum sway_container_layout layout; enum sway_container_layout prev_layout; + // Saves us from searching the list of children/floating in the parent + bool is_floating; + // For C_ROOT, this has no meaning // For C_OUTPUT, this is the output position in layout coordinates // For other types, this is the position in output-local coordinates diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 2e0f2abf..33d0a5d0 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h @@ -46,6 +46,9 @@ struct sway_container *container_add_sibling(struct sway_container *parent, struct sway_container *container_remove_child(struct sway_container *child); +void container_add_floating(struct sway_container *workspace, + struct sway_container *child); + struct sway_container *container_replace_child(struct sway_container *child, struct sway_container *new_child); diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index 35e1df3b..ece0ab5c 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -8,6 +8,7 @@ struct sway_view; struct sway_workspace { struct sway_container *swayc; struct sway_view *fullscreen; + list_t *floating; }; extern char *prev_workspace_name; diff --git a/sway/commands.c b/sway/commands.c index 6f5113f8..4a8d11ba 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -110,7 +110,6 @@ static struct cmd_handler handlers[] = { { "font", cmd_font }, { "for_window", cmd_for_window }, { "force_focus_wrapping", cmd_force_focus_wrapping }, - { "fullscreen", cmd_fullscreen }, { "hide_edge_borders", cmd_hide_edge_borders }, { "include", cmd_include }, { "input", cmd_input }, @@ -176,7 +175,9 @@ static struct cmd_handler config_handlers[] = { static struct cmd_handler command_handlers[] = { { "border", cmd_border }, { "exit", cmd_exit }, + { "floating", cmd_floating }, { "focus", cmd_focus }, + { "fullscreen", cmd_fullscreen }, { "kill", cmd_kill }, { "layout", cmd_layout }, { "mark", cmd_mark }, diff --git a/sway/commands/floating.c b/sway/commands/floating.c new file mode 100644 index 00000000..8432b0dc --- /dev/null +++ b/sway/commands/floating.c @@ -0,0 +1,48 @@ +#include +#include +#include "sway/commands.h" +#include "sway/input/seat.h" +#include "sway/ipc-server.h" +#include "sway/tree/arrange.h" +#include "sway/tree/container.h" +#include "sway/tree/layout.h" +#include "list.h" + +struct cmd_results *cmd_floating(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1))) { + return error; + } + struct sway_container *container = + config->handler_context.current_container; + if (container->type != C_VIEW) { + // TODO: This doesn't strictly speaking have to be true + return cmd_results_new(CMD_INVALID, "float", "Only views can float"); + } + + bool wants_floating; + if (strcasecmp(argv[0], "enable") == 0) { + wants_floating = true; + } else if (strcasecmp(argv[0], "disable") == 0) { + wants_floating = false; + } else if (strcasecmp(argv[0], "toggle") == 0) { + wants_floating = !container->is_floating; + } else { + return cmd_results_new(CMD_FAILURE, "floating", + "Expected 'floating "); + } + + // Change from tiled to floating + if (!container->is_floating && wants_floating) { + struct sway_container *workspace = container_parent( + container, C_WORKSPACE); + container_remove_child(container); + container_add_floating(workspace, container); + seat_set_focus(config->handler_context.seat, container); + arrange_workspace(workspace); + } else if (container->is_floating && !wants_floating) { + // TODO + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/meson.build b/sway/meson.build index 68675f67..5618a257 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -36,6 +36,7 @@ sway_sources = files( 'commands/exit.c', 'commands/exec.c', 'commands/exec_always.c', + 'commands/floating.c', 'commands/focus.c', 'commands/focus_follows_mouse.c', 'commands/focus_wrapping.c', diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 2f4ae667..7bbeb4b1 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -142,11 +142,26 @@ struct sway_container *container_remove_child(struct sway_container *child) { } struct sway_container *parent = child->parent; - for (int i = 0; i < parent->children->length; ++i) { - if (parent->children->items[i] == child) { - list_del(parent->children, i); - break; + if (!child->is_floating) { + for (int i = 0; i < parent->children->length; ++i) { + if (parent->children->items[i] == child) { + list_del(parent->children, i); + break; + } } + } else { + if (!sway_assert(parent->type == C_WORKSPACE && child->type == C_VIEW, + "Found floating non-view and/or in non-workspace")) { + return parent; + } + struct sway_workspace *ws = parent->sway_workspace; + for (int i = 0; i < ws->floating->length; ++i) { + if (ws->floating->items[i] == child) { + list_del(ws->floating, i); + break; + } + } + child->is_floating = false; } child->parent = NULL; container_notify_subtree_changed(parent); @@ -154,6 +169,26 @@ struct sway_container *container_remove_child(struct sway_container *child) { return parent; } +void container_add_floating(struct sway_container *workspace, + struct sway_container *child) { + if (!sway_assert(workspace->type == C_WORKSPACE && child->type == C_VIEW, + "Attempted to float non-view and/or in non-workspace")) { + return; + } + if (!sway_assert(!child->parent, + "child already has a parent (invalid call)")) { + return; + } + if (!sway_assert(!child->is_floating, + "child is already floating (invalid state)")) { + return; + } + struct sway_workspace *ws = workspace->sway_workspace; + list_add(ws->floating, child); + child->parent = workspace; + child->is_floating = true; +} + void container_move_to(struct sway_container *container, struct sway_container *destination) { if (container == destination diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index f34baa9e..c4f8ac5e 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -12,6 +12,7 @@ #include "sway/tree/arrange.h" #include "sway/tree/container.h" #include "sway/tree/workspace.h" +#include "list.h" #include "log.h" #include "util.h" @@ -64,6 +65,7 @@ struct sway_container *workspace_create(struct sway_container *output, return NULL; } swayws->swayc = workspace; + swayws->floating = create_list(); workspace->sway_workspace = swayws; container_add_child(output, workspace); From 71db8de4be53fc9ec2fab5ed89dd2646468fa15f Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 4 May 2018 08:27:53 -0400 Subject: [PATCH 02/34] Render floating views --- sway/desktop/output.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 0deb86ca..95479819 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -818,6 +818,7 @@ static void render_output(struct sway_output *output, struct timespec *when, } } else { float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; + wlr_renderer_clear(renderer, clear_color); int nrects; pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); From 1132efe42e8086216c7bab6b405d09a22231dde5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 4 May 2018 08:41:16 -0400 Subject: [PATCH 03/34] Send frame done to floating views Also centers them on the screen when initially floated In the future we'll need a more sophisticated solution than that --- include/sway/tree/container.h | 1 - sway/commands/floating.c | 13 +++++++++++++ sway/debug-tree.c | 2 -- sway/ipc-json.c | 2 -- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index fa2f9286..a4ffd25b 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -40,7 +40,6 @@ enum sway_container_layout { L_VERT, L_STACKED, L_TABBED, - L_FLOATING, }; enum sway_container_border { diff --git a/sway/commands/floating.c b/sway/commands/floating.c index 8432b0dc..9e0be9d0 100644 --- a/sway/commands/floating.c +++ b/sway/commands/floating.c @@ -3,9 +3,11 @@ #include "sway/commands.h" #include "sway/input/seat.h" #include "sway/ipc-server.h" +#include "sway/output.h" #include "sway/tree/arrange.h" #include "sway/tree/container.h" #include "sway/tree/layout.h" +#include "sway/tree/view.h" #include "list.h" struct cmd_results *cmd_floating(int argc, char **argv) { @@ -38,6 +40,17 @@ struct cmd_results *cmd_floating(int argc, char **argv) { container, C_WORKSPACE); container_remove_child(container); container_add_floating(workspace, container); + + struct sway_output *output = workspace->parent->sway_output; + output_damage_whole_container(output, container); + // Reset to sane size and position + container->width = 640; + container->height = 480; + container->x = workspace->width / 2 - container->width / 2; + container->y = workspace->height / 2 - container->height / 2; + view_autoconfigure(container->sway_view); + output_damage_whole_container(output, container); + seat_set_focus(config->handler_context.seat, container); arrange_workspace(workspace); } else if (container->is_floating && !wants_floating) { diff --git a/sway/debug-tree.c b/sway/debug-tree.c index ae0a1869..5af5b565 100644 --- a/sway/debug-tree.c +++ b/sway/debug-tree.c @@ -22,8 +22,6 @@ static const char *layout_to_str(enum sway_container_layout layout) { return "L_STACKED"; case L_TABBED: return "L_TABBED"; - case L_FLOATING: - return "L_FLOATING"; case L_NONE: default: return "L_NONE"; diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 03582950..da4bef60 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -21,8 +21,6 @@ static const char *ipc_json_layout_description(enum sway_container_layout l) { return "tabbed"; case L_STACKED: return "stacked"; - case L_FLOATING: - return "floating"; case L_NONE: break; } From 1f2e399ade77070a2d0b82856ad9a3eef96b8676 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 24 May 2018 22:30:44 +1000 Subject: [PATCH 04/34] Implement floating --- include/sway/tree/container.h | 22 ++++++ include/sway/tree/layout.h | 3 - include/sway/tree/view.h | 10 ++- include/sway/tree/workspace.h | 4 +- sway/commands.c | 1 + sway/commands/floating.c | 25 +------ sway/commands/sticky.c | 40 ++++++++++ sway/criteria.c | 9 ++- sway/desktop/output.c | 114 ++++++++++++++++++++++++++--- sway/desktop/xdg_shell.c | 32 ++++++-- sway/desktop/xdg_shell_v6.c | 32 ++++++-- sway/desktop/xwayland.c | 97 ++++++++++++++++++++----- sway/input/cursor.c | 3 + sway/input/seat.c | 16 +++- sway/ipc-json.c | 10 +++ sway/meson.build | 1 + sway/tree/arrange.c | 12 +++ sway/tree/container.c | 133 +++++++++++++++++++++++++++++++--- sway/tree/layout.c | 73 ++++++------------- sway/tree/view.c | 87 ++++++++++++++-------- sway/tree/workspace.c | 17 ++++- 21 files changed, 572 insertions(+), 169 deletions(-) create mode 100644 sway/commands/sticky.c diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index a4ffd25b..b802e1d1 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -75,8 +75,13 @@ struct sway_container { enum sway_container_layout layout; enum sway_container_layout prev_layout; + // Allow the container to be automatically removed if it's empty. True by + // default, false for the magic floating container that each workspace has. + bool reapable; + // Saves us from searching the list of children/floating in the parent bool is_floating; + bool is_sticky; // For C_ROOT, this has no meaning // For C_OUTPUT, this is the output position in layout coordinates @@ -173,6 +178,13 @@ struct sway_container *container_at(struct sway_container *container, double ox, double oy, struct wlr_surface **surface, double *sx, double *sy); +/** + * Same as container_at, but only checks floating views and expects coordinates + * to be layout coordinates, as that's what floating views use. + */ +struct sway_container *floating_container_at(double lx, double ly, + struct wlr_surface **surface, double *sx, double *sy); + /** * Apply the function for each descendant of the container breadth first. */ @@ -229,4 +241,14 @@ void container_notify_subtree_changed(struct sway_container *container); */ size_t container_titlebar_height(void); +void container_set_floating(struct sway_container *container, bool enable); + +void container_set_geometry_from_view(struct sway_container *container); + +/** + * Determine if the given container is itself floating or has a floating + * ancestor. + */ +bool container_self_or_parent_floating(struct sway_container *container); + #endif diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 33d0a5d0..2e0f2abf 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h @@ -46,9 +46,6 @@ struct sway_container *container_add_sibling(struct sway_container *parent, struct sway_container *container_remove_child(struct sway_container *child); -void container_add_floating(struct sway_container *workspace, - struct sway_container *child); - struct sway_container *container_replace_child(struct sway_container *child, struct sway_container *new_child); diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index a8bf4955..6990e5b6 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -32,7 +32,9 @@ struct sway_view_impl { void (*configure)(struct sway_view *view, double ox, double oy, int width, int height); void (*set_activated)(struct sway_view *view, bool activated); + void (*set_maximized)(struct sway_view *view, bool maximized); void (*set_fullscreen)(struct sway_view *view, bool fullscreen); + bool (*wants_floating)(struct sway_view *view); void (*for_each_surface)(struct sway_view *view, wlr_surface_iterator_func_t iterator, void *user_data); void (*close)(struct sway_view *view); @@ -50,6 +52,10 @@ struct sway_view { double x, y; int width, height; + // The size the view would want to be if it weren't tiled. + // Used when changing a view from tiled to floating. + int natural_width, natural_height; + bool is_fullscreen; char *title_format; @@ -214,6 +220,8 @@ void view_autoconfigure(struct sway_view *view); void view_set_activated(struct sway_view *view, bool activated); +void view_set_maximized(struct sway_view *view, bool maximized); + void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen); void view_set_fullscreen(struct sway_view *view, bool fullscreen); @@ -236,7 +244,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface); void view_unmap(struct sway_view *view); -void view_update_position(struct sway_view *view, double ox, double oy); +void view_update_position(struct sway_view *view, double lx, double ly); void view_update_size(struct sway_view *view, int width, int height); diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index ece0ab5c..81321fc8 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -8,7 +8,7 @@ struct sway_view; struct sway_workspace { struct sway_container *swayc; struct sway_view *fullscreen; - list_t *floating; + struct sway_container *floating; }; extern char *prev_workspace_name; @@ -31,4 +31,6 @@ struct sway_container *workspace_prev(struct sway_container *current); bool workspace_is_visible(struct sway_container *ws); +bool workspace_is_empty(struct sway_container *ws); + #endif diff --git a/sway/commands.c b/sway/commands.c index 4a8d11ba..e9762bef 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -190,6 +190,7 @@ static struct cmd_handler command_handlers[] = { { "splith", cmd_splith }, { "splitt", cmd_splitt }, { "splitv", cmd_splitv }, + { "sticky", cmd_sticky }, { "swap", cmd_swap }, { "title_format", cmd_title_format }, { "unmark", cmd_unmark }, diff --git a/sway/commands/floating.c b/sway/commands/floating.c index 9e0be9d0..38a4e1da 100644 --- a/sway/commands/floating.c +++ b/sway/commands/floating.c @@ -31,31 +31,10 @@ struct cmd_results *cmd_floating(int argc, char **argv) { wants_floating = !container->is_floating; } else { return cmd_results_new(CMD_FAILURE, "floating", - "Expected 'floating "); + "Expected 'floating '"); } - // Change from tiled to floating - if (!container->is_floating && wants_floating) { - struct sway_container *workspace = container_parent( - container, C_WORKSPACE); - container_remove_child(container); - container_add_floating(workspace, container); - - struct sway_output *output = workspace->parent->sway_output; - output_damage_whole_container(output, container); - // Reset to sane size and position - container->width = 640; - container->height = 480; - container->x = workspace->width / 2 - container->width / 2; - container->y = workspace->height / 2 - container->height / 2; - view_autoconfigure(container->sway_view); - output_damage_whole_container(output, container); - - seat_set_focus(config->handler_context.seat, container); - arrange_workspace(workspace); - } else if (container->is_floating && !wants_floating) { - // TODO - } + container_set_floating(container, wants_floating); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c new file mode 100644 index 00000000..4bb4bd39 --- /dev/null +++ b/sway/commands/sticky.c @@ -0,0 +1,40 @@ +#include +#include +#include "sway/commands.h" +#include "sway/input/seat.h" +#include "sway/ipc-server.h" +#include "sway/output.h" +#include "sway/tree/arrange.h" +#include "sway/tree/container.h" +#include "sway/tree/layout.h" +#include "sway/tree/view.h" +#include "list.h" + +struct cmd_results *cmd_sticky(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "sticky", EXPECTED_EQUAL_TO, 1))) { + return error; + } + struct sway_container *container = + config->handler_context.current_container; + if (!container->is_floating) { + return cmd_results_new(CMD_FAILURE, "sticky", + "Can't set sticky on a tiled container"); + } + + bool wants_sticky; + if (strcasecmp(argv[0], "enable") == 0) { + wants_sticky = true; + } else if (strcasecmp(argv[0], "disable") == 0) { + wants_sticky = false; + } else if (strcasecmp(argv[0], "toggle") == 0) { + wants_sticky = !container->is_sticky; + } else { + return cmd_results_new(CMD_FAILURE, "sticky", + "Expected 'sticky '"); + } + + container->is_sticky = wants_sticky; + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/criteria.c b/sway/criteria.c index dec5fed7..e97b12f8 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -121,12 +121,15 @@ static bool criteria_matches_view(struct criteria *criteria, } if (criteria->floating) { - // TODO - return false; + if (!view->swayc->is_floating) { + return false; + } } if (criteria->tiling) { - // TODO + if (view->swayc->is_floating) { + return false; + } } if (criteria->urgent) { diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 95479819..1d21e80f 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -754,9 +754,87 @@ static void render_container(struct sway_output *output, case L_TABBED: render_container_tabbed(output, damage, con, parent_focused); break; - case L_FLOATING: - // TODO - break; + } +} + +static bool floater_intersects_output(struct sway_container *floater, + struct sway_container *output) { + struct wlr_box box = { + .x = floater->x, + .y = floater->y, + .width = floater->width, + .height = floater->height, + }; + return wlr_output_layout_intersects(root_container.sway_root->output_layout, + output->sway_output->wlr_output, &box); +} + +static void container_translate(struct sway_container *con, int x, int y) { + con->x += x; + con->y += y; + if (con->type == C_VIEW) { + con->sway_view->x += x; + con->sway_view->y += y; + } else { + for (int i = 0; i < con->children->length; ++i) { + struct sway_container *child = con->children->items[i]; + container_translate(child, x, y); + } + } +} + +static void render_floating_container(struct sway_output *soutput, + pixman_region32_t *damage, struct sway_container *con) { + // We need to translate the floating container's coordinates from layout + // coordinates into output-local coordinates. This needs to happen for all + // children of the floating container too. + struct sway_container *output = container_parent(con, C_OUTPUT); + container_translate(con, -output->x, -output->y); + + if (con->type == C_VIEW) { + struct sway_view *view = con->sway_view; + struct sway_seat *seat = input_manager_current_seat(input_manager); + struct sway_container *focus = seat_get_focus(seat); + struct border_colors *colors; + struct wlr_texture *title_texture; + struct wlr_texture *marks_texture; + + if (focus == con) { + colors = &config->border_colors.focused; + title_texture = con->title_focused; + marks_texture = view->marks_focused; + } else { + colors = &config->border_colors.unfocused; + title_texture = con->title_unfocused; + marks_texture = view->marks_unfocused; + } + render_titlebar(soutput, damage, con, con->x, con->y, con->width, + colors, title_texture, marks_texture); + render_view(soutput, damage, con, colors); + } else { + render_container(soutput, damage, con, false); + } + // Undo the translation + container_translate(con, output->x, output->y); +} + +static void render_floating(struct sway_output *soutput, + pixman_region32_t *damage) { + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *output = root_container.children->items[i]; + for (int j = 0; j < output->children->length; ++j) { + struct sway_container *workspace = output->children->items[j]; + struct sway_workspace *ws = workspace->sway_workspace; + bool ws_is_visible = workspace_is_visible(workspace); + for (int k = 0; k < ws->floating->children->length; ++k) { + struct sway_container *floater = + ws->floating->children->items[k]; + if ((ws_is_visible || floater->is_sticky) + && floater_intersects_output(floater, soutput->swayc)) { + render_floating_container(soutput, damage, floater); + } + } + } } } @@ -794,8 +872,6 @@ static void render_output(struct sway_output *output, struct timespec *when, goto renderer_end; } - //wlr_renderer_clear(renderer, (float[]){1, 1, 0, 1}); - struct sway_container *workspace = output_get_active_workspace(output); if (workspace->sway_workspace->fullscreen) { @@ -818,7 +894,6 @@ static void render_output(struct sway_output *output, struct timespec *when, } } else { float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; - wlr_renderer_clear(renderer, clear_color); int nrects; pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); @@ -840,6 +915,8 @@ static void render_output(struct sway_output *output, struct timespec *when, &root_container.sway_root->xwayland_unmanaged); render_layer(output, damage, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); + + render_floating(output, damage); } render_layer(output, damage, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); @@ -916,6 +993,7 @@ static void send_frame_done(struct sway_output *output, struct timespec *when) { struct sway_container *workspace = output_get_active_workspace(output); send_frame_done_container(&data, workspace); + send_frame_done_container(&data, workspace->sway_workspace->floating); send_frame_done_unmanaged(&data, &root_container.sway_root->xwayland_unmanaged); @@ -1037,7 +1115,15 @@ static void output_damage_view(struct sway_output *output, void output_damage_from_view(struct sway_output *output, struct sway_view *view) { - output_damage_view(output, view, false); + if (container_self_or_parent_floating(view->swayc)) { + view->x -= output->swayc->x; + view->y -= output->swayc->y; + output_damage_view(output, view, false); + view->x += output->swayc->x; + view->y += output->swayc->y; + } else { + output_damage_view(output, view, false); + } } static void output_damage_whole_container_iterator(struct sway_container *con, @@ -1053,13 +1139,17 @@ static void output_damage_whole_container_iterator(struct sway_container *con, void output_damage_whole_container(struct sway_output *output, struct sway_container *con) { - float scale = output->wlr_output->scale; struct wlr_box box = { - .x = con->x * scale, - .y = con->y * scale, - .width = con->width * scale, - .height = con->height * scale, + .x = con->x, + .y = con->y, + .width = con->width, + .height = con->height, }; + if (con->is_floating) { + box.x -= output->wlr_output->lx; + box.y -= output->wlr_output->ly; + } + scale_box(&box, output->wlr_output->scale); wlr_output_damage_add_box(output->damage, &box); if (con->type == C_VIEW) { diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index b2b95fa0..e1a73b20 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -98,6 +98,7 @@ static void configure(struct sway_view *view, double ox, double oy, int width, xdg_shell_view->pending_width = width; xdg_shell_view->pending_height = height; wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height); + view_update_position(view, ox, oy); } static void set_activated(struct sway_view *view, bool activated) { @@ -110,6 +111,14 @@ static void set_activated(struct sway_view *view, bool activated) { } } +static void set_maximized(struct sway_view *view, bool maximized) { + if (xdg_shell_view_from_view(view) == NULL) { + return; + } + struct wlr_xdg_surface *surface = view->wlr_xdg_surface; + wlr_xdg_toplevel_set_maximized(surface, maximized); +} + static void set_fullscreen(struct sway_view *view, bool fullscreen) { if (xdg_shell_view_from_view(view) == NULL) { return; @@ -118,6 +127,11 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { wlr_xdg_toplevel_set_fullscreen(surface, fullscreen); } +static bool wants_floating(struct sway_view *view) { + // TODO + return false; +} + static void for_each_surface(struct sway_view *view, wlr_surface_iterator_func_t iterator, void *user_data) { if (xdg_shell_view_from_view(view) == NULL) { @@ -154,7 +168,9 @@ static const struct sway_view_impl view_impl = { .get_string_prop = get_string_prop, .configure = configure, .set_activated = set_activated, + .set_maximized = set_maximized, .set_fullscreen = set_fullscreen, + .wants_floating = wants_floating, .for_each_surface = for_each_surface, .close = _close, .destroy = destroy, @@ -164,11 +180,17 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit); struct sway_view *view = &xdg_shell_view->view; - // NOTE: We intentionally discard the view's desired width here - // TODO: Store this for restoration when moving to floating plane - // TODO: Let floating views do whatever - view_update_size(view, xdg_shell_view->pending_width, - xdg_shell_view->pending_height); + struct wlr_box *geometry = &view->wlr_xdg_surface->geometry; + if (!view->natural_width && !view->natural_height) { + view->natural_width = geometry->width; + view->natural_height = geometry->height; + } + if (view->swayc && view->swayc->is_floating) { + view_update_size(view, geometry->width, geometry->height); + } else { + view_update_size(view, xdg_shell_view->pending_width, + xdg_shell_view->pending_height); + } view_update_title(view, false); view_damage_from(view); } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index d098c797..47e4162a 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -97,6 +97,7 @@ static void configure(struct sway_view *view, double ox, double oy, int width, xdg_shell_v6_view->pending_width = width; xdg_shell_v6_view->pending_height = height; wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height); + view_update_position(view, ox, oy); } static void set_activated(struct sway_view *view, bool activated) { @@ -109,6 +110,14 @@ static void set_activated(struct sway_view *view, bool activated) { } } +static void set_maximized(struct sway_view *view, bool maximized) { + if (xdg_shell_v6_view_from_view(view) == NULL) { + return; + } + struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; + wlr_xdg_toplevel_v6_set_maximized(surface, maximized); +} + static void set_fullscreen(struct sway_view *view, bool fullscreen) { if (xdg_shell_v6_view_from_view(view) == NULL) { return; @@ -117,6 +126,11 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { wlr_xdg_toplevel_v6_set_fullscreen(surface, fullscreen); } +static bool wants_floating(struct sway_view *view) { + // TODO + return false; +} + static void for_each_surface(struct sway_view *view, wlr_surface_iterator_func_t iterator, void *user_data) { if (xdg_shell_v6_view_from_view(view) == NULL) { @@ -153,7 +167,9 @@ static const struct sway_view_impl view_impl = { .get_string_prop = get_string_prop, .configure = configure, .set_activated = set_activated, + .set_maximized = set_maximized, .set_fullscreen = set_fullscreen, + .wants_floating = wants_floating, .for_each_surface = for_each_surface, .close = _close, .destroy = destroy, @@ -163,11 +179,17 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_shell_v6_view *xdg_shell_v6_view = wl_container_of(listener, xdg_shell_v6_view, commit); struct sway_view *view = &xdg_shell_v6_view->view; - // NOTE: We intentionally discard the view's desired width here - // TODO: Store this for restoration when moving to floating plane - // TODO: Let floating views do whatever - view_update_size(view, xdg_shell_v6_view->pending_width, - xdg_shell_v6_view->pending_height); + struct wlr_box *geometry = &view->wlr_xdg_surface_v6->geometry; + if (!view->natural_width && !view->natural_height) { + view->natural_width = geometry->width; + view->natural_height = geometry->height; + } + if (view->swayc && view->swayc->is_floating) { + view_update_size(view, geometry->width, geometry->height); + } else { + view_update_size(view, xdg_shell_v6_view->pending_width, + xdg_shell_v6_view->pending_height); + } view_update_title(view, false); view_damage_from(view); } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 6a99a66a..56cac1bd 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -152,7 +152,9 @@ static uint32_t get_int_prop(struct sway_view *view, enum sway_view_prop prop) { } } -static void configure(struct sway_view *view, double ox, double oy, int width, +// The x and y arguments are output-local for tiled views, and layout +// coordinates for floating views. +static void configure(struct sway_view *view, double x, double y, int width, int height) { struct sway_xwayland_view *xwayland_view = xwayland_view_from_view(view); if (xwayland_view == NULL) { @@ -160,25 +162,33 @@ static void configure(struct sway_view *view, double ox, double oy, int width, } struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - struct sway_container *output = container_parent(view->swayc, C_OUTPUT); - if (!sway_assert(output, "view must be within tree to set position")) { - return; - } - struct sway_container *root = container_parent(output, C_ROOT); - if (!sway_assert(root, "output must be within tree to set position")) { - return; - } - struct wlr_output_layout *layout = root->sway_root->output_layout; - struct wlr_output_layout_output *loutput = - wlr_output_layout_get(layout, output->sway_output->wlr_output); - if (!sway_assert(loutput, "output must be within layout to set position")) { - return; + double lx, ly; + if (view->swayc->is_floating) { + lx = x; + ly = y; + } else { + struct sway_container *output = container_parent(view->swayc, C_OUTPUT); + if (!sway_assert(output, "view must be within tree to set position")) { + return; + } + struct sway_container *root = container_parent(output, C_ROOT); + if (!sway_assert(root, "output must be within tree to set position")) { + return; + } + struct wlr_output_layout *layout = root->sway_root->output_layout; + struct wlr_output_layout_output *loutput = + wlr_output_layout_get(layout, output->sway_output->wlr_output); + if (!sway_assert(loutput, + "output must be within layout to set position")) { + return; + } + lx = x + loutput->x; + ly = y + loutput->y; } xwayland_view->pending_width = width; xwayland_view->pending_height = height; - wlr_xwayland_surface_configure(xsurface, ox + loutput->x, oy + loutput->y, - width, height); + wlr_xwayland_surface_configure(xsurface, lx, ly, width, height); } static void set_activated(struct sway_view *view, bool activated) { @@ -189,6 +199,14 @@ static void set_activated(struct sway_view *view, bool activated) { wlr_xwayland_surface_activate(surface, activated); } +static void set_maximized(struct sway_view *view, bool maximized) { + if (xwayland_view_from_view(view) == NULL) { + return; + } + struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface; + wlr_xwayland_surface_set_maximized(surface, maximized); +} + static void set_fullscreen(struct sway_view *view, bool fullscreen) { if (xwayland_view_from_view(view) == NULL) { return; @@ -197,6 +215,35 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { wlr_xwayland_surface_set_fullscreen(surface, fullscreen); } +static bool wants_floating(struct sway_view *view) { + // TODO: + // We want to return true if the window type contains any of these: + // NET_WM_WINDOW_TYPE_DIALOG + // NET_WM_WINDOW_TYPE_UTILITY + // NET_WM_WINDOW_TYPE_TOOLBAR + // NET_WM_WINDOW_TYPE_SPLASH + // + // We also want to return true if the NET_WM_STATE is MODAL. + // wlroots doesn't appear to provide all this information at the moment. + struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; + uint32_t *atom = xsurface->window_type; + for (size_t i = 0; i < xsurface->window_type_len; ++i) { + wlr_log(L_DEBUG, "xwayland window type %i", *atom); + // TODO: Come up with a better way of doing this + switch (*atom) { + case 36: // NET_WM_WINDOW_TYPE_UTILITY + case 44: // NET_WM_WINDOW_TYPE_SPLASH + case 276: // ? PGP passphrase dialog + case 337: // ? Firefox open file dialog + case 338: // ? Firefox open file dialog + return true; + } + ++atom; + } + + return false; +} + static void _close(struct sway_view *view) { if (xwayland_view_from_view(view) == NULL) { return; @@ -225,7 +272,9 @@ static const struct sway_view_impl view_impl = { .get_int_prop = get_int_prop, .configure = configure, .set_activated = set_activated, + .set_maximized = set_maximized, .set_fullscreen = set_fullscreen, + .wants_floating = wants_floating, .close = _close, .destroy = destroy, }; @@ -234,10 +283,18 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, commit); struct sway_view *view = &xwayland_view->view; - // NOTE: We intentionally discard the view's desired width here - // TODO: Let floating views do whatever - view_update_size(view, xwayland_view->pending_width, - xwayland_view->pending_height); + struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; + if (!view->natural_width && !view->natural_height) { + view->natural_width = xsurface->width; + view->natural_height = xsurface->height; + } + if (view->swayc && view->swayc->is_floating) { + view_update_size(view, xsurface->width, xsurface->height); + view_update_position(view, xsurface->x, xsurface->y); + } else { + view_update_size(view, xwayland_view->pending_width, + xwayland_view->pending_height); + } view_damage_from(view); } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 6751931d..96bf574c 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -108,6 +108,9 @@ static struct sway_container *container_at_coords( } struct sway_container *c; + if ((c = floating_container_at(x, y, surface, sx, sy))) { + return c; + } if ((c = container_at(ws, ox, oy, surface, sx, sy))) { return c; } diff --git a/sway/input/seat.c b/sway/input/seat.c index 0295212c..6a266fba 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -113,7 +113,14 @@ static void seat_send_focus(struct sway_container *con, static struct sway_container *seat_get_focus_by_type(struct sway_seat *seat, struct sway_container *container, enum sway_container_type type) { - if (container->type == C_VIEW || container->children->length == 0) { + if (container->type == C_VIEW) { + return container; + } + + struct sway_container *floating = container->type == C_WORKSPACE ? + container->sway_workspace->floating : NULL; + if (container->children->length == 0 && + (!floating || floating->children->length == 0)) { return container; } @@ -126,6 +133,9 @@ static struct sway_container *seat_get_focus_by_type(struct sway_seat *seat, if (container_has_child(container, current->container)) { return current->container; } + if (floating && container_has_child(floating, current->container)) { + return current->container; + } } return NULL; @@ -568,7 +578,7 @@ void seat_set_focus_warp(struct sway_seat *seat, // clean up unfocused empty workspace on new output if (new_output_last_ws) { if (!workspace_is_visible(new_output_last_ws) - && new_output_last_ws->children->length == 0) { + && workspace_is_empty(new_output_last_ws)) { if (last_workspace == new_output_last_ws) { last_focus = NULL; last_workspace = NULL; @@ -581,7 +591,7 @@ void seat_set_focus_warp(struct sway_seat *seat, if (last_workspace) { ipc_event_workspace(last_workspace, container, "focus"); if (!workspace_is_visible(last_workspace) - && last_workspace->children->length == 0) { + && workspace_is_empty(last_workspace)) { if (last_workspace == last_focus) { last_focus = NULL; } diff --git a/sway/ipc-json.c b/sway/ipc-json.c index da4bef60..4d7024a8 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -4,6 +4,7 @@ #include "log.h" #include "sway/ipc-json.h" #include "sway/tree/container.h" +#include "sway/tree/workspace.h" #include "sway/output.h" #include "sway/input/input-manager.h" #include "sway/input/seat.h" @@ -150,6 +151,15 @@ static void ipc_json_describe_workspace(struct sway_container *workspace, const char *layout = ipc_json_layout_description(workspace->layout); json_object_object_add(object, "layout", json_object_new_string(layout)); + + // Floating + json_object *floating_array = json_object_new_array(); + struct sway_container *floating = workspace->sway_workspace->floating; + for (int i = 0; i < floating->children->length; ++i) { + struct sway_container *floater = floating->children->items[i]; + json_object_array_add(floating_array, ipc_json_describe_container_recursive(floater)); + } + json_object_object_add(object, "floating_nodes", floating_array); } static void ipc_json_describe_view(struct sway_container *c, json_object *object) { diff --git a/sway/meson.build b/sway/meson.build index 5618a257..4c038583 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -65,6 +65,7 @@ sway_sources = files( 'commands/set.c', 'commands/show_marks.c', 'commands/split.c', + 'commands/sticky.c', 'commands/swaybg_command.c', 'commands/swap.c', 'commands/title_format.c', diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index bdef56ea..da4f7889 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -247,6 +247,18 @@ void arrange_children_of(struct sway_container *parent) { arrange_children_of(child); } } + + // If container is a workspace, process floating containers too + if (parent->type == C_WORKSPACE) { + struct sway_workspace *ws = workspace->sway_workspace; + for (int i = 0; i < ws->floating->children->length; ++i) { + struct sway_container *child = ws->floating->children->items[i]; + if (child->type != C_VIEW) { + arrange_children_of(child); + } + } + } + container_damage_whole(parent); update_debug_tree(); } diff --git a/sway/tree/container.c b/sway/tree/container.c index 33d88d7f..f9a0474c 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -123,6 +123,7 @@ struct sway_container *container_create(enum sway_container_type type) { c->layout = L_NONE; c->type = type; c->alpha = 1.0f; + c->reapable = true; if (type != C_VIEW) { c->children = create_list(); @@ -189,14 +190,13 @@ static struct sway_container *container_workspace_destroy( } struct sway_container *parent = workspace->parent; - if (workspace->children->length == 0) { - // destroy the WS if there are no children (TODO check for floating) + if (workspace_is_empty(workspace)) { + // destroy the WS if there are no children wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); ipc_event_workspace(workspace, NULL, "empty"); } else if (output) { // Move children to a different workspace on this output struct sway_container *new_workspace = NULL; - // TODO move floating for (int i = 0; i < output->children->length; i++) { if (output->children->items[i] != workspace) { new_workspace = output->children->items[i]; @@ -209,6 +209,11 @@ static struct sway_container *container_workspace_destroy( for (int i = 0; i < workspace->children->length; i++) { container_move_to(workspace->children->items[i], new_workspace); } + struct sway_container *floating = workspace->sway_workspace->floating; + for (int i = 0; i < floating->children->length; i++) { + container_move_to(floating->children->items[i], + new_workspace->sway_workspace->floating); + } } free(workspace->sway_workspace); @@ -275,13 +280,16 @@ static void container_root_finish(struct sway_container *con) { } bool container_reap_empty(struct sway_container *con) { + if (!con->reapable) { + return false; + } switch (con->type) { case C_ROOT: case C_OUTPUT: // dont reap these break; case C_WORKSPACE: - if (!workspace_is_visible(con) && con->children->length == 0) { + if (!workspace_is_visible(con) && workspace_is_empty(con)) { wlr_log(L_DEBUG, "Destroying workspace via reaper"); container_workspace_destroy(con); return true; @@ -436,7 +444,6 @@ struct sway_container *container_find(struct sway_container *container, if (!container->children) { return NULL; } - // TODO: floating windows for (int i = 0; i < container->children->length; ++i) { struct sway_container *child = container->children->items[i]; if (test(child, data)) { @@ -448,6 +455,9 @@ struct sway_container *container_find(struct sway_container *container, } } } + if (container->type == C_WORKSPACE) { + return container_find(container->sway_workspace->floating, test, data); + } return NULL; } @@ -608,8 +618,6 @@ struct sway_container *container_at(struct sway_container *parent, return container_at_tabbed(parent, ox, oy, surface, sx, sy); case L_STACKED: return container_at_stacked(parent, ox, oy, surface, sx, sy); - case L_FLOATING: - return NULL; // TODO case L_NONE: return NULL; } @@ -617,6 +625,34 @@ struct sway_container *container_at(struct sway_container *parent, return NULL; } +struct sway_container *floating_container_at(double lx, double ly, + struct wlr_surface **surface, double *sx, double *sy) { + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *output = root_container.children->items[i]; + for (int j = 0; j < output->children->length; ++j) { + struct sway_container *workspace = output->children->items[j]; + struct sway_workspace *ws = workspace->sway_workspace; + bool ws_is_visible = workspace_is_visible(workspace); + for (int k = 0; k < ws->floating->children->length; ++k) { + struct sway_container *floater = + ws->floating->children->items[k]; + if (ws_is_visible || floater->is_sticky) { + struct wlr_box box = { + .x = floater->x, + .y = floater->y, + .width = floater->width, + .height = floater->height, + }; + if (wlr_box_contains_point(&box, lx, ly)) { + return container_at(floater, lx, ly, surface, sx, sy); + } + } + } + } + } + return NULL; +} + void container_for_each_descendant_dfs(struct sway_container *container, void (*f)(struct sway_container *container, void *data), void *data) { @@ -674,7 +710,7 @@ static bool find_child_func(struct sway_container *con, void *data) { bool container_has_child(struct sway_container *con, struct sway_container *child) { - if (con == NULL || con->type == C_VIEW || con->children->length == 0) { + if (con == NULL || con->type == C_VIEW) { return false; } return container_find(con, find_child_func, child); @@ -806,9 +842,6 @@ static size_t get_tree_representation(struct sway_container *parent, char *buffe case L_STACKED: lenient_strcat(buffer, "S["); break; - case L_FLOATING: - lenient_strcat(buffer, "F["); - break; case L_NONE: lenient_strcat(buffer, "D["); break; @@ -866,3 +899,81 @@ void container_notify_subtree_changed(struct sway_container *container) { size_t container_titlebar_height() { return config->font_height + TITLEBAR_V_PADDING * 2; } + +static void configure_floating_view(struct sway_view *view) { + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + int max_width = ws->width * 0.6666; + int max_height = ws->height * 0.6666; + int width = + view->natural_width > max_width ? max_width : view->natural_width; + int height = + view->natural_height > max_height ? max_height : view->natural_height; + struct sway_container *output = ws->parent; + int lx = output->x + (ws->width - width) / 2; + int ly = output->y + (ws->height - height) / 2; + + view->border_left = view->border_right = view->border_bottom = true; + view_set_maximized(view, false); + view_configure(view, lx, ly, width, height); +} + +void container_set_floating(struct sway_container *container, bool enable) { + if (container->is_floating == enable) { + return; + } + + struct sway_container *workspace = container_parent(container, C_WORKSPACE); + struct sway_seat *seat = input_manager_current_seat(input_manager); + container_damage_whole(container); + + if (enable) { + container_remove_child(container); + container_add_child(workspace->sway_workspace->floating, container); + container->is_floating = true; + if (container->type == C_VIEW) { + configure_floating_view(container->sway_view); + } + seat_set_focus(seat, seat_get_focus_inactive(seat, container)); + container_reap_empty_recursive(workspace); + } else { + // Returning to tiled + container_remove_child(container); + container_add_child(workspace, container); + container->width = container->parent->width; + container->height = container->parent->height; + if (container->type == C_VIEW) { + view_set_maximized(container->sway_view, true); + } + container->is_floating = false; + container->is_sticky = false; + container_reap_empty_recursive(workspace->sway_workspace->floating); + } + arrange_workspace(workspace); + container_damage_whole(container); +} + +void container_set_geometry_from_view(struct sway_container *container) { + if (!sway_assert(container->type == C_VIEW, "Expected a view")) { + return; + } + if (!sway_assert(container->is_floating, "Expected a floating view")) { + return; + } + struct sway_view *view = container->sway_view; + size_t border_width = view->border_thickness * (view->border != B_NONE); + size_t top = + view->border == B_NORMAL ? container_titlebar_height() : border_width; + + container->x = view->x - border_width; + container->y = view->y - top; + container->width = view->width + border_width * 2; + container->height = top + view->height + border_width; +} + +bool container_self_or_parent_floating(struct sway_container *container) { + while (container->parent->type != C_WORKSPACE + && container->parent->parent->type != C_WORKSPACE) { + container = container->parent; + } + return container->is_floating; +} diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 7bbeb4b1..59ad0b53 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -45,20 +45,14 @@ void layout_init(void) { } static int index_child(const struct sway_container *child) { - // TODO handle floating struct sway_container *parent = child->parent; - int i, len; - len = parent->children->length; - for (i = 0; i < len; ++i) { + for (int i = 0; i < parent->children->length; ++i) { if (parent->children->items[i] == child) { - break; + return i; } } - - if (!sway_assert(i < len, "Stray container")) { - return -1; - } - return i; + // This happens if the child is a floating container + return -1; } static void container_handle_fullscreen_reparent(struct sway_container *viewcon, @@ -142,26 +136,11 @@ struct sway_container *container_remove_child(struct sway_container *child) { } struct sway_container *parent = child->parent; - if (!child->is_floating) { - for (int i = 0; i < parent->children->length; ++i) { - if (parent->children->items[i] == child) { - list_del(parent->children, i); - break; - } + for (int i = 0; i < parent->children->length; ++i) { + if (parent->children->items[i] == child) { + list_del(parent->children, i); + break; } - } else { - if (!sway_assert(parent->type == C_WORKSPACE && child->type == C_VIEW, - "Found floating non-view and/or in non-workspace")) { - return parent; - } - struct sway_workspace *ws = parent->sway_workspace; - for (int i = 0; i < ws->floating->length; ++i) { - if (ws->floating->items[i] == child) { - list_del(ws->floating, i); - break; - } - } - child->is_floating = false; } child->parent = NULL; container_notify_subtree_changed(parent); @@ -169,32 +148,16 @@ struct sway_container *container_remove_child(struct sway_container *child) { return parent; } -void container_add_floating(struct sway_container *workspace, - struct sway_container *child) { - if (!sway_assert(workspace->type == C_WORKSPACE && child->type == C_VIEW, - "Attempted to float non-view and/or in non-workspace")) { - return; - } - if (!sway_assert(!child->parent, - "child already has a parent (invalid call)")) { - return; - } - if (!sway_assert(!child->is_floating, - "child is already floating (invalid state)")) { - return; - } - struct sway_workspace *ws = workspace->sway_workspace; - list_add(ws->floating, child); - child->parent = workspace; - child->is_floating = true; -} - void container_move_to(struct sway_container *container, struct sway_container *destination) { if (container == destination || container_has_ancestor(container, destination)) { return; } + if (container->is_floating) { + // TODO + return; + } struct sway_container *old_parent = container_remove_child(container); container->width = container->height = 0; container->saved_width = container->saved_height = 0; @@ -207,8 +170,9 @@ void container_move_to(struct sway_container *container, } wl_signal_emit(&container->events.reparent, old_parent); if (container->type == C_WORKSPACE) { - struct sway_seat *seat = input_manager_get_default_seat( - input_manager); + // If moving a workspace to a new output, maybe create a new workspace + // on the previous output + struct sway_seat *seat = input_manager_get_default_seat(input_manager); if (old_parent->children->length == 0) { char *ws_name = workspace_next_name(old_parent->name); struct sway_container *ws = @@ -754,6 +718,10 @@ struct sway_container *container_get_in_direction( enum movement_direction dir) { struct sway_container *parent = container->parent; + if (container->is_floating) { + return NULL; + } + if (container->type == C_VIEW && container->sway_view->is_fullscreen) { if (dir == MOVE_PARENT || dir == MOVE_CHILD) { return NULL; @@ -778,6 +746,9 @@ struct sway_container *container_get_in_direction( bool can_move = false; int desired; int idx = index_child(container); + if (idx == -1) { + return NULL; + } if (parent->type == C_ROOT) { enum wlr_direction wlr_dir = 0; if (!sway_assert(sway_dir_to_wlr(dir, &wlr_dir), diff --git a/sway/tree/view.c b/sway/tree/view.c index 26ff1e8d..651a2be6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -158,21 +158,19 @@ void view_autoconfigure(struct sway_view *view) { view->border_top = view->border_bottom = true; view->border_left = view->border_right = true; - if (view->swayc->layout != L_FLOATING) { - if (config->hide_edge_borders == E_BOTH - || config->hide_edge_borders == E_VERTICAL - || (config->hide_edge_borders == E_SMART && !other_views)) { - view->border_left = view->swayc->x != ws->x; - int right_x = view->swayc->x + view->swayc->width; - view->border_right = right_x != ws->x + ws->width; - } - if (config->hide_edge_borders == E_BOTH - || config->hide_edge_borders == E_HORIZONTAL - || (config->hide_edge_borders == E_SMART && !other_views)) { - view->border_top = view->swayc->y != ws->y; - int bottom_y = view->swayc->y + view->swayc->height; - view->border_bottom = bottom_y != ws->y + ws->height; - } + if (config->hide_edge_borders == E_BOTH + || config->hide_edge_borders == E_VERTICAL + || (config->hide_edge_borders == E_SMART && !other_views)) { + view->border_left = view->swayc->x != ws->x; + int right_x = view->swayc->x + view->swayc->width; + view->border_right = right_x != ws->x + ws->width; + } + if (config->hide_edge_borders == E_BOTH + || config->hide_edge_borders == E_HORIZONTAL + || (config->hide_edge_borders == E_SMART && !other_views)) { + view->border_top = view->swayc->y != ws->y; + int bottom_y = view->swayc->y + view->swayc->height; + view->border_bottom = bottom_y != ws->y + ws->height; } double x, y, width, height; @@ -184,11 +182,11 @@ void view_autoconfigure(struct sway_view *view) { // disable any top border because we'll always have the title bar. if (view->swayc->parent->layout == L_TABBED) { y_offset = container_titlebar_height(); - view->border_top = 0; + view->border_top = false; } else if (view->swayc->parent->layout == L_STACKED) { y_offset = container_titlebar_height() * view->swayc->parent->children->length; - view->border_top = 0; + view->border_top = false; } switch (view->border) { @@ -237,6 +235,12 @@ void view_set_activated(struct sway_view *view, bool activated) { } } +void view_set_maximized(struct sway_view *view, bool maximized) { + if (view->impl->set_maximized) { + view->impl->set_maximized(view, maximized); + } +} + // Set fullscreen, but without IPC events or arranging windows. void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { if (view->is_fullscreen == fullscreen) { @@ -452,6 +456,11 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { // TODO: CT_ASSIGN_OUTPUT } } + // If we're about to launch the view into the floating container, then + // launch it as a tiled view in the root of the workspace instead. + if (focus->is_floating) { + focus = focus->parent->parent; + } free(criterias); cont = container_view_create(focus, view); @@ -468,7 +477,12 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { wl_signal_add(&view->swayc->events.reparent, &view->container_reparent); view->container_reparent.notify = view_handle_container_reparent; - arrange_children_of(cont->parent); + if (view->impl->wants_floating && view->impl->wants_floating(view)) { + container_set_floating(view->swayc, true); + } else { + arrange_children_of(cont->parent); + } + input_manager_set_focus(input_manager, cont); if (workspace) { workspace_switch(workspace); @@ -516,16 +530,14 @@ void view_unmap(struct sway_view *view) { } } -void view_update_position(struct sway_view *view, double ox, double oy) { - if (view->swayc->x == ox && view->swayc->y == oy) { +void view_update_position(struct sway_view *view, double lx, double ly) { + if (!view->swayc->is_floating) { return; } - - // TODO: Only allow this if the view is floating (this function will only be - // called in response to wayland clients wanting to reposition themselves). container_damage_whole(view->swayc); - view->swayc->x = ox; - view->swayc->y = oy; + view->x = lx; + view->y = ly; + container_set_geometry_from_view(view->swayc); container_damage_whole(view->swayc); } @@ -533,15 +545,15 @@ 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); - // Should we update the swayc width/height here too? view->width = width; view->height = height; + if (view->swayc->is_floating) { + container_set_geometry_from_view(view->swayc); + } container_damage_whole(view->swayc); } - static void view_subsurface_create(struct sway_view *view, struct wlr_subsurface *subsurface) { struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); @@ -888,6 +900,19 @@ bool view_is_visible(struct sway_view *view) { if (!view->swayc) { return false; } + struct sway_container *workspace = + container_parent(view->swayc, C_WORKSPACE); + // Determine if view is nested inside a floating container which is sticky. + // A simple floating view will have this ancestry: + // C_VIEW (is_floating=true) -> floating -> workspace + // A more complex ancestry could be: + // C_VIEW -> C_CONTAINER (tabbed and is_floating) -> floating -> workspace + struct sway_container *floater = view->swayc; + while (floater->parent->type != C_WORKSPACE + && floater->parent->parent->type != C_WORKSPACE) { + floater = floater->parent; + } + bool is_sticky = floater->is_floating && floater->is_sticky; // Check view isn't in a tabbed or stacked container on an inactive tab struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *container = view->swayc; @@ -901,10 +926,12 @@ bool view_is_visible(struct sway_view *view) { container = container->parent; } // Check view isn't hidden by another fullscreen view - struct sway_container *workspace = container; if (workspace->sway_workspace->fullscreen && !view->is_fullscreen) { return false; } // Check the workspace is visible - return workspace_is_visible(workspace); + if (!is_sticky) { + return workspace_is_visible(workspace); + } + return true; } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index c4f8ac5e..5bef409a 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -65,7 +65,9 @@ struct sway_container *workspace_create(struct sway_container *output, return NULL; } swayws->swayc = workspace; - swayws->floating = create_list(); + swayws->floating = container_create(C_CONTAINER); + swayws->floating->parent = swayws->swayc; + swayws->floating->reapable = false; workspace->sway_workspace = swayws; container_add_child(output, workspace); @@ -408,3 +410,16 @@ bool workspace_is_visible(struct sway_container *ws) { } return focus == ws; } + +bool workspace_is_empty(struct sway_container *ws) { + if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) { + return false; + } + if (ws->children->length) { + return false; + } + if (ws->sway_workspace->floating->children->length) { + return false; + } + return true; +} From 34f35f0badc767d9b0cbaf2fd429af1d30592d08 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 09:10:35 +1000 Subject: [PATCH 05/34] Use L_FLOATING instead of reapable boolean --- include/sway/tree/container.h | 5 +---- sway/desktop/output.c | 2 ++ sway/ipc-json.c | 2 ++ sway/tree/container.c | 10 ++++++++-- sway/tree/workspace.c | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index b802e1d1..906088f0 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -40,6 +40,7 @@ enum sway_container_layout { L_VERT, L_STACKED, L_TABBED, + L_FLOATING, }; enum sway_container_border { @@ -75,10 +76,6 @@ struct sway_container { enum sway_container_layout layout; enum sway_container_layout prev_layout; - // Allow the container to be automatically removed if it's empty. True by - // default, false for the magic floating container that each workspace has. - bool reapable; - // Saves us from searching the list of children/floating in the parent bool is_floating; bool is_sticky; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 1d21e80f..e91be4d4 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -754,6 +754,8 @@ static void render_container(struct sway_output *output, case L_TABBED: render_container_tabbed(output, damage, con, parent_focused); break; + case L_FLOATING: + sway_assert(false, "Didn't expect to see floating here"); } } diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 4d7024a8..6d185449 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -22,6 +22,8 @@ static const char *ipc_json_layout_description(enum sway_container_layout l) { return "tabbed"; case L_STACKED: return "stacked"; + case L_FLOATING: + return "floating"; case L_NONE: break; } diff --git a/sway/tree/container.c b/sway/tree/container.c index f9a0474c..17d29d92 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -123,7 +123,6 @@ struct sway_container *container_create(enum sway_container_type type) { c->layout = L_NONE; c->type = type; c->alpha = 1.0f; - c->reapable = true; if (type != C_VIEW) { c->children = create_list(); @@ -280,7 +279,8 @@ static void container_root_finish(struct sway_container *con) { } bool container_reap_empty(struct sway_container *con) { - if (!con->reapable) { + if (con->layout == L_FLOATING) { + // Don't reap the magical floating container that each workspace has return false; } switch (con->type) { @@ -618,6 +618,9 @@ struct sway_container *container_at(struct sway_container *parent, return container_at_tabbed(parent, ox, oy, surface, sx, sy); case L_STACKED: return container_at_stacked(parent, ox, oy, surface, sx, sy); + case L_FLOATING: + sway_assert(false, "Didn't expect to see floating here"); + return NULL; case L_NONE: return NULL; } @@ -842,6 +845,9 @@ static size_t get_tree_representation(struct sway_container *parent, char *buffe case L_STACKED: lenient_strcat(buffer, "S["); break; + case L_FLOATING: + strcpy(buffer, "F["); + break; case L_NONE: lenient_strcat(buffer, "D["); break; diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 5bef409a..37d4a06a 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -67,7 +67,7 @@ struct sway_container *workspace_create(struct sway_container *output, swayws->swayc = workspace; swayws->floating = container_create(C_CONTAINER); swayws->floating->parent = swayws->swayc; - swayws->floating->reapable = false; + swayws->floating->layout = L_FLOATING; workspace->sway_workspace = swayws; container_add_child(output, workspace); From aaba7642b3e4e9a63aea49412b10221f399b17af Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 09:26:23 +1000 Subject: [PATCH 06/34] Replace is_floating boolean with function --- include/sway/tree/container.h | 12 ++++++++---- sway/commands/floating.c | 2 +- sway/commands/layout.c | 10 +++------- sway/commands/sticky.c | 2 +- sway/criteria.c | 4 ++-- sway/desktop/output.c | 2 +- sway/desktop/xdg_shell.c | 2 +- sway/desktop/xdg_shell_v6.c | 2 +- sway/desktop/xwayland.c | 4 ++-- sway/tree/container.c | 24 ++++++++++++++++-------- sway/tree/layout.c | 4 ++-- sway/tree/view.c | 12 ++++++------ 12 files changed, 44 insertions(+), 36 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 906088f0..71935697 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -76,8 +76,6 @@ struct sway_container { enum sway_container_layout layout; enum sway_container_layout prev_layout; - // Saves us from searching the list of children/floating in the parent - bool is_floating; bool is_sticky; // For C_ROOT, this has no meaning @@ -243,8 +241,14 @@ void container_set_floating(struct sway_container *container, bool enable); void container_set_geometry_from_view(struct sway_container *container); /** - * Determine if the given container is itself floating or has a floating - * ancestor. + * Determine if the given container is itself floating. + * This will return false for any descendants of a floating container. + */ +bool container_is_floating(struct sway_container *container); + +/** + * Determine if the given container is itself floating or is a child of a + * floating container. */ bool container_self_or_parent_floating(struct sway_container *container); diff --git a/sway/commands/floating.c b/sway/commands/floating.c index 38a4e1da..46b761da 100644 --- a/sway/commands/floating.c +++ b/sway/commands/floating.c @@ -28,7 +28,7 @@ struct cmd_results *cmd_floating(int argc, char **argv) { } else if (strcasecmp(argv[0], "disable") == 0) { wants_floating = false; } else if (strcasecmp(argv[0], "toggle") == 0) { - wants_floating = !container->is_floating; + wants_floating = !container_is_floating(container); } else { return cmd_results_new(CMD_FAILURE, "floating", "Expected 'floating '"); diff --git a/sway/commands/layout.c b/sway/commands/layout.c index 6b44b001..a009e38f 100644 --- a/sway/commands/layout.c +++ b/sway/commands/layout.c @@ -12,19 +12,15 @@ struct cmd_results *cmd_layout(int argc, char **argv) { } struct sway_container *parent = config->handler_context.current_container; - // TODO: floating - /* - if (parent->is_floating) { - return cmd_results_new(CMD_FAILURE, "layout", "Unable to change layout of floating windows"); + if (container_is_floating(parent)) { + return cmd_results_new(CMD_FAILURE, "layout", + "Unable to change layout of floating windows"); } - */ while (parent->type == C_VIEW) { parent = parent->parent; } - // TODO: stacks and tabs - if (strcasecmp(argv[0], "default") == 0) { parent->layout = parent->prev_layout; if (parent->layout == L_NONE) { diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c index 4bb4bd39..732ccb98 100644 --- a/sway/commands/sticky.c +++ b/sway/commands/sticky.c @@ -17,7 +17,7 @@ struct cmd_results *cmd_sticky(int argc, char **argv) { } struct sway_container *container = config->handler_context.current_container; - if (!container->is_floating) { + if (!container_is_floating(container)) { return cmd_results_new(CMD_FAILURE, "sticky", "Can't set sticky on a tiled container"); } diff --git a/sway/criteria.c b/sway/criteria.c index e97b12f8..a263485a 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -121,13 +121,13 @@ static bool criteria_matches_view(struct criteria *criteria, } if (criteria->floating) { - if (!view->swayc->is_floating) { + if (!container_is_floating(view->swayc)) { return false; } } if (criteria->tiling) { - if (view->swayc->is_floating) { + if (container_is_floating(view->swayc)) { return false; } } diff --git a/sway/desktop/output.c b/sway/desktop/output.c index e91be4d4..4e5d106f 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -1147,7 +1147,7 @@ void output_damage_whole_container(struct sway_output *output, .width = con->width, .height = con->height, }; - if (con->is_floating) { + if (container_is_floating(con)) { box.x -= output->wlr_output->lx; box.y -= output->wlr_output->ly; } diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index e1a73b20..ebb12211 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -185,7 +185,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { view->natural_width = geometry->width; view->natural_height = geometry->height; } - if (view->swayc && view->swayc->is_floating) { + if (view->swayc && container_is_floating(view->swayc)) { view_update_size(view, geometry->width, geometry->height); } else { view_update_size(view, xdg_shell_view->pending_width, diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 47e4162a..f3df2fe8 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -184,7 +184,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { view->natural_width = geometry->width; view->natural_height = geometry->height; } - if (view->swayc && view->swayc->is_floating) { + if (view->swayc && container_is_floating(view->swayc)) { view_update_size(view, geometry->width, geometry->height); } else { view_update_size(view, xdg_shell_v6_view->pending_width, diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 56cac1bd..1373d968 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -163,7 +163,7 @@ static void configure(struct sway_view *view, double x, double y, int width, struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; double lx, ly; - if (view->swayc->is_floating) { + if (container_is_floating(view->swayc)) { lx = x; ly = y; } else { @@ -288,7 +288,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { view->natural_width = xsurface->width; view->natural_height = xsurface->height; } - if (view->swayc && view->swayc->is_floating) { + if (view->swayc && container_is_floating(view->swayc)) { view_update_size(view, xsurface->width, xsurface->height); view_update_position(view, xsurface->x, xsurface->y); } else { diff --git a/sway/tree/container.c b/sway/tree/container.c index 17d29d92..c16f1748 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -924,7 +924,7 @@ static void configure_floating_view(struct sway_view *view) { } void container_set_floating(struct sway_container *container, bool enable) { - if (container->is_floating == enable) { + if (container_is_floating(container) == enable) { return; } @@ -935,7 +935,6 @@ void container_set_floating(struct sway_container *container, bool enable) { if (enable) { container_remove_child(container); container_add_child(workspace->sway_workspace->floating, container); - container->is_floating = true; if (container->type == C_VIEW) { configure_floating_view(container->sway_view); } @@ -950,7 +949,6 @@ void container_set_floating(struct sway_container *container, bool enable) { if (container->type == C_VIEW) { view_set_maximized(container->sway_view, true); } - container->is_floating = false; container->is_sticky = false; container_reap_empty_recursive(workspace->sway_workspace->floating); } @@ -962,7 +960,8 @@ void container_set_geometry_from_view(struct sway_container *container) { if (!sway_assert(container->type == C_VIEW, "Expected a view")) { return; } - if (!sway_assert(container->is_floating, "Expected a floating view")) { + if (!sway_assert(container_is_floating(container), + "Expected a floating view")) { return; } struct sway_view *view = container->sway_view; @@ -977,9 +976,18 @@ void container_set_geometry_from_view(struct sway_container *container) { } bool container_self_or_parent_floating(struct sway_container *container) { - while (container->parent->type != C_WORKSPACE - && container->parent->parent->type != C_WORKSPACE) { - container = container->parent; + struct sway_container *workspace = container_parent(container, C_WORKSPACE); + if (!workspace) { + return false; } - return container->is_floating; + return container_has_anscestor(container, + workspace->sway_workspace->floating); +} + +bool container_is_floating(struct sway_container *container) { + struct sway_container *workspace = container_parent(container, C_WORKSPACE); + if (!workspace) { + return false; + } + return container->parent == workspace->sway_workspace->floating; } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 59ad0b53..28775253 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -154,7 +154,7 @@ void container_move_to(struct sway_container *container, || container_has_ancestor(container, destination)) { return; } - if (container->is_floating) { + if (container_is_floating(container)) { // TODO return; } @@ -718,7 +718,7 @@ struct sway_container *container_get_in_direction( enum movement_direction dir) { struct sway_container *parent = container->parent; - if (container->is_floating) { + if (container_is_floating(container)) { return NULL; } diff --git a/sway/tree/view.c b/sway/tree/view.c index 651a2be6..8548d9b8 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -458,7 +458,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { } // If we're about to launch the view into the floating container, then // launch it as a tiled view in the root of the workspace instead. - if (focus->is_floating) { + if (container_is_floating(focus)) { focus = focus->parent->parent; } free(criterias); @@ -531,7 +531,7 @@ void view_unmap(struct sway_view *view) { } void view_update_position(struct sway_view *view, double lx, double ly) { - if (!view->swayc->is_floating) { + if (!container_is_floating(view->swayc)) { return; } container_damage_whole(view->swayc); @@ -548,7 +548,7 @@ void view_update_size(struct sway_view *view, int width, int height) { container_damage_whole(view->swayc); view->width = width; view->height = height; - if (view->swayc->is_floating) { + if (container_is_floating(view->swayc)) { container_set_geometry_from_view(view->swayc); } container_damage_whole(view->swayc); @@ -904,15 +904,15 @@ bool view_is_visible(struct sway_view *view) { container_parent(view->swayc, C_WORKSPACE); // Determine if view is nested inside a floating container which is sticky. // A simple floating view will have this ancestry: - // C_VIEW (is_floating=true) -> floating -> workspace + // C_VIEW -> floating -> workspace // A more complex ancestry could be: - // C_VIEW -> C_CONTAINER (tabbed and is_floating) -> floating -> workspace + // C_VIEW -> C_CONTAINER (tabbed) -> floating -> workspace struct sway_container *floater = view->swayc; while (floater->parent->type != C_WORKSPACE && floater->parent->parent->type != C_WORKSPACE) { floater = floater->parent; } - bool is_sticky = floater->is_floating && floater->is_sticky; + bool is_sticky = container_is_floating(floater) && floater->is_sticky; // Check view isn't in a tabbed or stacked container on an inactive tab struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *container = view->swayc; From 754cb7944c2f05b35e39dab9605a184ee9f53efd Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 09:32:25 +1000 Subject: [PATCH 07/34] Respect view's border config for floating containers --- sway/desktop/output.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 4e5d106f..c0e368d0 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -810,8 +810,13 @@ static void render_floating_container(struct sway_output *soutput, title_texture = con->title_unfocused; marks_texture = view->marks_unfocused; } - render_titlebar(soutput, damage, con, con->x, con->y, con->width, - colors, title_texture, marks_texture); + + if (con->sway_view->border == B_NORMAL) { + render_titlebar(soutput, damage, con, con->x, con->y, con->width, + colors, title_texture, marks_texture); + } else { + render_top_border(soutput, damage, con, colors); + } render_view(soutput, damage, con, colors); } else { render_container(soutput, damage, con, false); From 13a4b0512e25b8da6e16ca1286f8b62fcc24c5cc Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 11:15:43 +1000 Subject: [PATCH 08/34] Fix unfullscreening a floating view --- include/sway/tree/container.h | 1 + sway/tree/container.c | 19 +------------------ sway/tree/view.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 71935697..e4f74b08 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -84,6 +84,7 @@ struct sway_container { // Includes borders double x, y; double width, height; + double saved_x, saved_y; double saved_width, saved_height; list_t *children; diff --git a/sway/tree/container.c b/sway/tree/container.c index c16f1748..fd7ee2c3 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -906,23 +906,6 @@ size_t container_titlebar_height() { return config->font_height + TITLEBAR_V_PADDING * 2; } -static void configure_floating_view(struct sway_view *view) { - struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); - int max_width = ws->width * 0.6666; - int max_height = ws->height * 0.6666; - int width = - view->natural_width > max_width ? max_width : view->natural_width; - int height = - view->natural_height > max_height ? max_height : view->natural_height; - struct sway_container *output = ws->parent; - int lx = output->x + (ws->width - width) / 2; - int ly = output->y + (ws->height - height) / 2; - - view->border_left = view->border_right = view->border_bottom = true; - view_set_maximized(view, false); - view_configure(view, lx, ly, width, height); -} - void container_set_floating(struct sway_container *container, bool enable) { if (container_is_floating(container) == enable) { return; @@ -936,7 +919,7 @@ void container_set_floating(struct sway_container *container, bool enable) { container_remove_child(container); container_add_child(workspace->sway_workspace->floating, container); if (container->type == C_VIEW) { - configure_floating_view(container->sway_view); + view_autoconfigure(container->sway_view); } seat_set_focus(seat, seat_get_focus_inactive(seat, container)); container_reap_empty_recursive(workspace); diff --git a/sway/tree/view.c b/sway/tree/view.c index 8548d9b8..65961dd9 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -126,6 +126,23 @@ void view_configure(struct sway_view *view, double ox, double oy, int width, } } +static void view_autoconfigure_floating(struct sway_view *view) { + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + int max_width = ws->width * 0.6666; + int max_height = ws->height * 0.6666; + int width = + view->natural_width > max_width ? max_width : view->natural_width; + int height = + view->natural_height > max_height ? max_height : view->natural_height; + struct sway_container *output = ws->parent; + int lx = output->x + (ws->width - width) / 2; + int ly = output->y + (ws->height - height) / 2; + + view->border_left = view->border_right = view->border_bottom = true; + view_set_maximized(view, false); + view_configure(view, lx, ly, width, height); +} + void view_autoconfigure(struct sway_view *view) { if (!sway_assert(view->swayc, "Called view_autoconfigure() on a view without a swayc")) { @@ -140,6 +157,11 @@ void view_autoconfigure(struct sway_view *view) { return; } + if (container_is_floating(view->swayc)) { + view_autoconfigure_floating(view); + return; + } + struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); int other_views = 0; @@ -261,6 +283,8 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { view_set_fullscreen(workspace->sway_workspace->fullscreen, false); } workspace->sway_workspace->fullscreen = view; + view->swayc->saved_x = view->swayc->x; + view->swayc->saved_y = view->swayc->y; view->swayc->saved_width = view->swayc->width; view->swayc->saved_height = view->swayc->height; @@ -283,6 +307,11 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { workspace->sway_workspace->fullscreen = NULL; view->swayc->width = view->swayc->saved_width; view->swayc->height = view->swayc->saved_height; + if (container_is_floating(view->swayc)) { + view->swayc->x = view->swayc->saved_x; + view->swayc->y = view->swayc->saved_y; + view_autoconfigure(view); + } } } From dc83b158e12ae33f03165cfd64a50aa7f0a52e26 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 15:39:14 +1000 Subject: [PATCH 09/34] Fix issues with sticky containers and workspaces * Attach sticky containers to new workspaces when switching * Fire the close event *before* we start destroying the workspace to prevent a crash Because the sticky container now follows the visible workspace, this simplifies the rendering and container_at logic. --- sway/desktop/output.c | 7 ++++--- sway/tree/container.c | 45 +++++++++++++++++-------------------------- sway/tree/workspace.c | 35 ++++++++++++++++++++++++++++++--- 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index c0e368d0..fb80fd87 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -832,12 +832,13 @@ static void render_floating(struct sway_output *soutput, for (int j = 0; j < output->children->length; ++j) { struct sway_container *workspace = output->children->items[j]; struct sway_workspace *ws = workspace->sway_workspace; - bool ws_is_visible = workspace_is_visible(workspace); + if (!workspace_is_visible(workspace)) { + continue; + } for (int k = 0; k < ws->floating->children->length; ++k) { struct sway_container *floater = ws->floating->children->items[k]; - if ((ws_is_visible || floater->is_sticky) - && floater_intersects_output(floater, soutput->swayc)) { + if (floater_intersects_output(floater, soutput->swayc)) { render_floating_container(soutput, damage, floater); } } diff --git a/sway/tree/container.c b/sway/tree/container.c index fd7ee2c3..532722e8 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -64,16 +64,6 @@ void container_create_notify(struct sway_container *container) { } } -static void container_close_notify(struct sway_container *container) { - if (container == NULL) { - return; - } - // TODO send ipc event type based on the container type - if (container->type == C_VIEW || container->type == C_WORKSPACE) { - ipc_event_window(container, "close"); - } -} - static void container_update_textures_recursive(struct sway_container *con) { container_update_title_textures(con); @@ -143,7 +133,6 @@ static void _container_destroy(struct sway_container *cont) { } wl_signal_emit(&cont->events.destroy, cont); - container_close_notify(cont); struct sway_container *parent = cont->parent; if (cont->children != NULL && cont->children->length) { @@ -151,6 +140,7 @@ static void _container_destroy(struct sway_container *cont) { // container_remove_child, which removes child from this container while (cont->children != NULL && cont->children->length > 0) { struct sway_container *child = cont->children->items[0]; + ipc_event_window(child, "close"); container_remove_child(child); _container_destroy(child); } @@ -188,12 +178,11 @@ static struct sway_container *container_workspace_destroy( return NULL; } + wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); + ipc_event_window(workspace, "close"); + struct sway_container *parent = workspace->parent; - if (workspace_is_empty(workspace)) { - // destroy the WS if there are no children - wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); - ipc_event_workspace(workspace, NULL, "empty"); - } else if (output) { + if (!workspace_is_empty(workspace) && output) { // Move children to a different workspace on this output struct sway_container *new_workspace = NULL; for (int i = 0; i < output->children->length; i++) { @@ -357,10 +346,12 @@ struct sway_container *container_destroy(struct sway_container *con) { if (con->children->length) { for (int i = 0; i < con->children->length; ++i) { struct sway_container *child = con->children->items[0]; + ipc_event_window(child, "close"); container_remove_child(child); container_add_child(parent, child); } } + ipc_event_window(con, "close"); _container_destroy(con); break; case C_VIEW: @@ -635,20 +626,20 @@ struct sway_container *floating_container_at(double lx, double ly, for (int j = 0; j < output->children->length; ++j) { struct sway_container *workspace = output->children->items[j]; struct sway_workspace *ws = workspace->sway_workspace; - bool ws_is_visible = workspace_is_visible(workspace); + if (!workspace_is_visible(workspace)) { + continue; + } for (int k = 0; k < ws->floating->children->length; ++k) { struct sway_container *floater = ws->floating->children->items[k]; - if (ws_is_visible || floater->is_sticky) { - struct wlr_box box = { - .x = floater->x, - .y = floater->y, - .width = floater->width, - .height = floater->height, - }; - if (wlr_box_contains_point(&box, lx, ly)) { - return container_at(floater, lx, ly, surface, sx, sy); - } + struct wlr_box box = { + .x = floater->x, + .y = floater->y, + .width = floater->width, + .height = floater->height, + }; + if (wlr_box_contains_point(&box, lx, ly)) { + return container_at(floater, lx, ly, surface, sx, sy); } } } diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 37d4a06a..f78ae9a5 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -387,7 +387,21 @@ bool workspace_switch(struct sway_container *workspace) { strcpy(prev_workspace_name, active_ws->name); } - // TODO: Deal with sticky containers + // Move sticky containers to new workspace + struct sway_container *next_output = workspace->parent; + struct sway_container *next_output_prev_ws = + seat_get_active_child(seat, next_output); + struct sway_container *floating = + next_output_prev_ws->sway_workspace->floating; + bool has_sticky = false; + for (int i = 0; i < floating->children->length; ++i) { + struct sway_container *floater = floating->children->items[i]; + if (floater->is_sticky) { + has_sticky = true; + container_remove_child(floater); + container_add_child(workspace->sway_workspace->floating, floater); + } + } wlr_log(L_DEBUG, "Switching to workspace %p:%s", workspace, workspace->name); @@ -395,6 +409,16 @@ bool workspace_switch(struct sway_container *workspace) { if (next == NULL) { next = workspace; } + if (has_sticky) { + // If there's a sticky container, we might be setting focus to the same + // container that's already focused, so seat_set_focus is effectively a + // no op. We therefore need to send the IPC event and clean up the old + // workspace here. + ipc_event_workspace(active_ws, workspace, "focus"); + if (!workspace_is_visible(active_ws) && workspace_is_empty(active_ws)) { + container_destroy(active_ws); + } + } seat_set_focus(seat, next); struct sway_container *output = container_parent(workspace, C_OUTPUT); arrange_output(output); @@ -418,8 +442,13 @@ bool workspace_is_empty(struct sway_container *ws) { if (ws->children->length) { return false; } - if (ws->sway_workspace->floating->children->length) { - return false; + // Sticky views are not considered to be part of this workspace + struct sway_container *floating = ws->sway_workspace->floating; + for (int i = 0; i < floating->children->length; ++i) { + struct sway_container *floater = floating->children->items[i]; + if (!floater->is_sticky) { + return false; + } } return true; } From 5d69a56209dc6138272de6cdbd8f066d37199727 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 17:10:58 +1000 Subject: [PATCH 10/34] Prevent splitting a floating view --- sway/commands/split.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sway/commands/split.c b/sway/commands/split.c index 0a61ac8d..57e42a5a 100644 --- a/sway/commands/split.c +++ b/sway/commands/split.c @@ -10,6 +10,10 @@ static struct cmd_results *do_split(int layout) { struct sway_container *con = config->handler_context.current_container; + if (container_is_floating(con)) { + return cmd_results_new(CMD_FAILURE, "split", + "Can't split a floating view"); + } struct sway_container *parent = container_split(con, layout); container_create_notify(parent); arrange_children_of(parent); @@ -23,24 +27,23 @@ struct cmd_results *cmd_split(int argc, char **argv) { return error; } if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { - do_split(L_VERT); + return do_split(L_VERT); } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { - do_split(L_HORIZ); + return do_split(L_HORIZ); } else if (strcasecmp(argv[0], "t") == 0 || strcasecmp(argv[0], "toggle") == 0) { struct sway_container *focused = config->handler_context.current_container; if (focused->parent->layout == L_VERT) { - do_split(L_HORIZ); + return do_split(L_HORIZ); } else { - do_split(L_VERT); + return do_split(L_VERT); } } else { - error = cmd_results_new(CMD_FAILURE, "split", + return cmd_results_new(CMD_FAILURE, "split", "Invalid split command (expected either horizontal or vertical)."); - return error; } return cmd_results_new(CMD_SUCCESS, NULL, NULL); } From 02de2a6f65c189bf563cca5b4d3fbc11826ea7f7 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 09:22:10 +1000 Subject: [PATCH 11/34] Rename set_maximized functions to set_tiled --- include/sway/tree/view.h | 4 ++-- sway/desktop/xdg_shell.c | 6 +++--- sway/desktop/xdg_shell_v6.c | 6 +++--- sway/desktop/xwayland.c | 6 +++--- sway/tree/container.c | 2 +- sway/tree/view.c | 8 ++++---- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 6990e5b6..7a94b2c2 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -32,7 +32,7 @@ struct sway_view_impl { void (*configure)(struct sway_view *view, double ox, double oy, int width, int height); void (*set_activated)(struct sway_view *view, bool activated); - void (*set_maximized)(struct sway_view *view, bool maximized); + void (*set_tiled)(struct sway_view *view, bool tiled); void (*set_fullscreen)(struct sway_view *view, bool fullscreen); bool (*wants_floating)(struct sway_view *view); void (*for_each_surface)(struct sway_view *view, @@ -220,7 +220,7 @@ void view_autoconfigure(struct sway_view *view); void view_set_activated(struct sway_view *view, bool activated); -void view_set_maximized(struct sway_view *view, bool maximized); +void view_set_tiled(struct sway_view *view, bool tiled); void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen); diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index ebb12211..73d9477f 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -111,12 +111,12 @@ static void set_activated(struct sway_view *view, bool activated) { } } -static void set_maximized(struct sway_view *view, bool maximized) { +static void set_tiled(struct sway_view *view, bool tiled) { if (xdg_shell_view_from_view(view) == NULL) { return; } struct wlr_xdg_surface *surface = view->wlr_xdg_surface; - wlr_xdg_toplevel_set_maximized(surface, maximized); + wlr_xdg_toplevel_set_maximized(surface, tiled); } static void set_fullscreen(struct sway_view *view, bool fullscreen) { @@ -168,7 +168,7 @@ static const struct sway_view_impl view_impl = { .get_string_prop = get_string_prop, .configure = configure, .set_activated = set_activated, - .set_maximized = set_maximized, + .set_tiled = set_tiled, .set_fullscreen = set_fullscreen, .wants_floating = wants_floating, .for_each_surface = for_each_surface, diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index f3df2fe8..6c98744c 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -110,12 +110,12 @@ static void set_activated(struct sway_view *view, bool activated) { } } -static void set_maximized(struct sway_view *view, bool maximized) { +static void set_tiled(struct sway_view *view, bool tiled) { if (xdg_shell_v6_view_from_view(view) == NULL) { return; } struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; - wlr_xdg_toplevel_v6_set_maximized(surface, maximized); + wlr_xdg_toplevel_v6_set_maximized(surface, tiled); } static void set_fullscreen(struct sway_view *view, bool fullscreen) { @@ -167,7 +167,7 @@ static const struct sway_view_impl view_impl = { .get_string_prop = get_string_prop, .configure = configure, .set_activated = set_activated, - .set_maximized = set_maximized, + .set_tiled = set_tiled, .set_fullscreen = set_fullscreen, .wants_floating = wants_floating, .for_each_surface = for_each_surface, diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 1373d968..783868bc 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -199,12 +199,12 @@ static void set_activated(struct sway_view *view, bool activated) { wlr_xwayland_surface_activate(surface, activated); } -static void set_maximized(struct sway_view *view, bool maximized) { +static void set_tiled(struct sway_view *view, bool tiled) { if (xwayland_view_from_view(view) == NULL) { return; } struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface; - wlr_xwayland_surface_set_maximized(surface, maximized); + wlr_xwayland_surface_set_maximized(surface, tiled); } static void set_fullscreen(struct sway_view *view, bool fullscreen) { @@ -272,7 +272,7 @@ static const struct sway_view_impl view_impl = { .get_int_prop = get_int_prop, .configure = configure, .set_activated = set_activated, - .set_maximized = set_maximized, + .set_tiled = set_tiled, .set_fullscreen = set_fullscreen, .wants_floating = wants_floating, .close = _close, diff --git a/sway/tree/container.c b/sway/tree/container.c index 532722e8..12f74e37 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -921,7 +921,7 @@ void container_set_floating(struct sway_container *container, bool enable) { container->width = container->parent->width; container->height = container->parent->height; if (container->type == C_VIEW) { - view_set_maximized(container->sway_view, true); + view_set_tiled(container->sway_view, true); } container->is_sticky = false; container_reap_empty_recursive(workspace->sway_workspace->floating); diff --git a/sway/tree/view.c b/sway/tree/view.c index 65961dd9..3de9879e 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -139,7 +139,7 @@ static void view_autoconfigure_floating(struct sway_view *view) { int ly = output->y + (ws->height - height) / 2; view->border_left = view->border_right = view->border_bottom = true; - view_set_maximized(view, false); + view_set_tiled(view, false); view_configure(view, lx, ly, width, height); } @@ -257,9 +257,9 @@ void view_set_activated(struct sway_view *view, bool activated) { } } -void view_set_maximized(struct sway_view *view, bool maximized) { - if (view->impl->set_maximized) { - view->impl->set_maximized(view, maximized); +void view_set_tiled(struct sway_view *view, bool tiled) { + if (view->impl->set_tiled) { + view->impl->set_tiled(view, tiled); } } From 00f6e179cd22ea046a25eb8a099f434de9e8fe57 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 09:23:12 +1000 Subject: [PATCH 12/34] Add L_FLOATING back to debug tree --- sway/debug-tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sway/debug-tree.c b/sway/debug-tree.c index 5af5b565..f3465afe 100644 --- a/sway/debug-tree.c +++ b/sway/debug-tree.c @@ -22,10 +22,12 @@ static const char *layout_to_str(enum sway_container_layout layout) { return "L_STACKED"; case L_TABBED: return "L_TABBED"; + case L_FLOATING: + return "L_FLOATING"; case L_NONE: - default: return "L_NONE"; } + return "L_NONE"; } static int draw_container(cairo_t *cairo, struct sway_container *container, From e4e912ea91a5a36d9f17c1730ffbf29707984399 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:26:10 +1000 Subject: [PATCH 13/34] Store swayc coordinates as layout-local --- include/sway/tree/container.h | 3 +- include/sway/tree/view.h | 4 +- sway/desktop/output.c | 83 +++++++++++------------------------ sway/desktop/xdg_shell.c | 4 +- sway/desktop/xdg_shell_v6.c | 4 +- sway/desktop/xwayland.c | 28 +----------- sway/input/cursor.c | 14 +++--- sway/tree/arrange.c | 4 +- sway/tree/container.c | 42 +++++++++--------- sway/tree/view.c | 15 ++++--- 10 files changed, 71 insertions(+), 130 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index e4f74b08..4b686040 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -79,8 +79,7 @@ struct sway_container { bool is_sticky; // For C_ROOT, this has no meaning - // For C_OUTPUT, this is the output position in layout coordinates - // For other types, this is the position in output-local coordinates + // For other types, this is the position in layout coordinates // Includes borders double x, y; double width, height; diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 7a94b2c2..65a23902 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -29,7 +29,7 @@ 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 ox, double oy, int width, + void (*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); @@ -48,7 +48,7 @@ struct sway_view { struct sway_container *swayc; // NULL for unmapped views struct wlr_surface *surface; // NULL for unmapped views - // Geometry of the view itself (excludes borders) + // Geometry of the view itself (excludes borders) in layout coordinates double x, y; int width, height; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index fb80fd87..8600d049 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -65,6 +65,13 @@ struct root_geometry { float rotation; }; +struct render_data { + struct root_geometry root_geo; + struct sway_output *output; + pixman_region32_t *damage; + float alpha; +}; + static bool get_surface_box(struct root_geometry *geo, struct sway_output *output, struct wlr_surface *surface, int sx, int sy, struct wlr_box *surface_box) { @@ -116,8 +123,9 @@ static void surface_for_each_surface(struct wlr_surface *surface, static void output_view_for_each_surface(struct sway_view *view, struct root_geometry *geo, wlr_surface_iterator_func_t iterator, void *user_data) { - geo->x = view->x; - geo->y = view->y; + struct render_data *data = user_data; + geo->x = view->x - data->output->wlr_output->lx; + geo->y = view->y - data->output->wlr_output->ly; geo->width = view->surface->current->width; geo->height = view->surface->current->height; geo->rotation = 0; // TODO @@ -160,13 +168,6 @@ static void scale_box(struct wlr_box *box, float scale) { box->height *= scale; } -struct render_data { - struct root_geometry root_geo; - struct sway_output *output; - pixman_region32_t *damage; - float alpha; -}; - static void scissor_output(struct wlr_output *wlr_output, pixman_box32_t *rect) { struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); @@ -275,7 +276,10 @@ static void render_rect(struct wlr_output *wlr_output, struct wlr_renderer *renderer = wlr_backend_get_renderer(wlr_output->backend); - struct wlr_box box = *_box; + struct wlr_box box; + memcpy(&box, _box, sizeof(struct wlr_box)); + box.x -= wlr_output->lx * wlr_output->scale; + box.y -= wlr_output->ly * wlr_output->scale; pixman_region32_t damage; pixman_region32_init(&damage); @@ -450,8 +454,10 @@ static void render_titlebar(struct sway_output *output, wlr_texture_get_size(marks_texture, &texture_box.width, &texture_box.height); texture_box.x = - (x + width - TITLEBAR_H_PADDING) * output_scale - texture_box.width; - texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; + (x - output->wlr_output->lx + width - TITLEBAR_H_PADDING) + * output_scale - texture_box.width; + texture_box.y = (y - output->wlr_output->ly + TITLEBAR_V_PADDING) + * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, @@ -472,8 +478,10 @@ static void render_titlebar(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(title_texture, &texture_box.width, &texture_box.height); - texture_box.x = (x + TITLEBAR_H_PADDING) * output_scale; - texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; + texture_box.x = (x - output->wlr_output->lx + TITLEBAR_H_PADDING) + * output_scale; + texture_box.y = (y - output->wlr_output->ly + TITLEBAR_V_PADDING) + * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, @@ -771,28 +779,8 @@ static bool floater_intersects_output(struct sway_container *floater, output->sway_output->wlr_output, &box); } -static void container_translate(struct sway_container *con, int x, int y) { - con->x += x; - con->y += y; - if (con->type == C_VIEW) { - con->sway_view->x += x; - con->sway_view->y += y; - } else { - for (int i = 0; i < con->children->length; ++i) { - struct sway_container *child = con->children->items[i]; - container_translate(child, x, y); - } - } -} - static void render_floating_container(struct sway_output *soutput, pixman_region32_t *damage, struct sway_container *con) { - // We need to translate the floating container's coordinates from layout - // coordinates into output-local coordinates. This needs to happen for all - // children of the floating container too. - struct sway_container *output = container_parent(con, C_OUTPUT); - container_translate(con, -output->x, -output->y); - if (con->type == C_VIEW) { struct sway_view *view = con->sway_view; struct sway_seat *seat = input_manager_current_seat(input_manager); @@ -821,8 +809,6 @@ static void render_floating_container(struct sway_output *soutput, } else { render_container(soutput, damage, con, false); } - // Undo the translation - container_translate(con, output->x, output->y); } static void render_floating(struct sway_output *soutput, @@ -1123,15 +1109,7 @@ static void output_damage_view(struct sway_output *output, void output_damage_from_view(struct sway_output *output, struct sway_view *view) { - if (container_self_or_parent_floating(view->swayc)) { - view->x -= output->swayc->x; - view->y -= output->swayc->y; - output_damage_view(output, view, false); - view->x += output->swayc->x; - view->y += output->swayc->y; - } else { - output_damage_view(output, view, false); - } + output_damage_view(output, view, false); } static void output_damage_whole_container_iterator(struct sway_container *con, @@ -1148,24 +1126,13 @@ static void output_damage_whole_container_iterator(struct sway_container *con, void output_damage_whole_container(struct sway_output *output, struct sway_container *con) { struct wlr_box box = { - .x = con->x, - .y = con->y, + .x = con->x - output->wlr_output->lx, + .y = con->y - output->wlr_output->ly, .width = con->width, .height = con->height, }; - if (container_is_floating(con)) { - box.x -= output->wlr_output->lx; - box.y -= output->wlr_output->ly; - } scale_box(&box, output->wlr_output->scale); wlr_output_damage_add_box(output->damage, &box); - - if (con->type == C_VIEW) { - output_damage_whole_container_iterator(con, output); - } else { - container_descendants(con, C_VIEW, - output_damage_whole_container_iterator, output); - } } static void damage_handle_destroy(struct wl_listener *listener, void *data) { diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 73d9477f..412488b3 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -87,7 +87,7 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p } } -static void configure(struct sway_view *view, double ox, double oy, int width, +static void configure(struct sway_view *view, double lx, double ly, int width, int height) { struct sway_xdg_shell_view *xdg_shell_view = xdg_shell_view_from_view(view); @@ -98,7 +98,7 @@ static void configure(struct sway_view *view, double ox, double oy, int width, xdg_shell_view->pending_width = width; xdg_shell_view->pending_height = height; wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height); - view_update_position(view, ox, oy); + view_update_position(view, lx, ly); } static void set_activated(struct sway_view *view, bool activated) { diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 6c98744c..b3653913 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -86,7 +86,7 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p } } -static void configure(struct sway_view *view, double ox, double oy, int width, +static void configure(struct sway_view *view, double lx, double ly, int width, int height) { struct sway_xdg_shell_v6_view *xdg_shell_v6_view = xdg_shell_v6_view_from_view(view); @@ -97,7 +97,7 @@ static void configure(struct sway_view *view, double ox, double oy, int width, xdg_shell_v6_view->pending_width = width; xdg_shell_v6_view->pending_height = height; wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height); - view_update_position(view, ox, oy); + view_update_position(view, lx, ly); } static void set_activated(struct sway_view *view, bool activated) { diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 783868bc..fc488162 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -152,9 +152,7 @@ static uint32_t get_int_prop(struct sway_view *view, enum sway_view_prop prop) { } } -// The x and y arguments are output-local for tiled views, and layout -// coordinates for floating views. -static void configure(struct sway_view *view, double x, double y, int width, +static void configure(struct sway_view *view, double lx, double ly, int width, int height) { struct sway_xwayland_view *xwayland_view = xwayland_view_from_view(view); if (xwayland_view == NULL) { @@ -162,30 +160,6 @@ static void configure(struct sway_view *view, double x, double y, int width, } struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - double lx, ly; - if (container_is_floating(view->swayc)) { - lx = x; - ly = y; - } else { - struct sway_container *output = container_parent(view->swayc, C_OUTPUT); - if (!sway_assert(output, "view must be within tree to set position")) { - return; - } - struct sway_container *root = container_parent(output, C_ROOT); - if (!sway_assert(root, "output must be within tree to set position")) { - return; - } - struct wlr_output_layout *layout = root->sway_root->output_layout; - struct wlr_output_layout_output *loutput = - wlr_output_layout_get(layout, output->sway_output->wlr_output); - if (!sway_assert(loutput, - "output must be within layout to set position")) { - return; - } - lx = x + loutput->x; - ly = y + loutput->y; - } - xwayland_view->pending_width = width; xwayland_view->pending_height = height; wlr_xwayland_surface_configure(xsurface, lx, ly, width, height); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 96bf574c..16e5427b 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -46,7 +46,7 @@ static struct wlr_surface *layer_surface_at(struct sway_output *output, * location, it is stored in **surface (it may not be a view). */ static struct sway_container *container_at_coords( - struct sway_seat *seat, double x, double y, + struct sway_seat *seat, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { // check for unmanaged views first struct wl_list *unmanaged = &root_container.sway_root->xwayland_unmanaged; @@ -55,8 +55,8 @@ static struct sway_container *container_at_coords( struct wlr_xwayland_surface *xsurface = unmanaged_surface->wlr_xwayland_surface; - double _sx = x - unmanaged_surface->lx; - double _sy = y - unmanaged_surface->ly; + double _sx = lx - unmanaged_surface->lx; + double _sy = ly - unmanaged_surface->ly; if (wlr_surface_point_accepts_input(xsurface->surface, _sx, _sy)) { *surface = xsurface->surface; *sx = _sx; @@ -69,12 +69,12 @@ static struct sway_container *container_at_coords( struct wlr_output_layout *output_layout = root_container.sway_root->output_layout; struct wlr_output *wlr_output = wlr_output_layout_output_at( - output_layout, x, y); + output_layout, lx, ly); if (wlr_output == NULL) { return NULL; } struct sway_output *output = wlr_output->data; - double ox = x, oy = y; + double ox = lx, oy = ly; wlr_output_layout_output_coords(output_layout, wlr_output, &ox, &oy); // find the focused workspace on the output for this seat @@ -108,10 +108,10 @@ static struct sway_container *container_at_coords( } struct sway_container *c; - if ((c = floating_container_at(x, y, surface, sx, sy))) { + if ((c = floating_container_at(lx, ly, surface, sx, sy))) { return c; } - if ((c = container_at(ws, ox, oy, surface, sx, sy))) { + if ((c = container_at(ws, lx, ly, surface, sx, sy))) { return c; } diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index da4f7889..721b557e 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -73,8 +73,8 @@ void arrange_workspace(struct sway_container *workspace) { area->width, area->height, area->x, area->y); workspace->width = area->width; workspace->height = area->height; - workspace->x = area->x; - workspace->y = area->y; + workspace->x = output->x + area->x; + workspace->y = output->y + area->y; wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, workspace->x, workspace->y); arrange_children_of(workspace); diff --git a/sway/tree/container.c b/sway/tree/container.c index 12f74e37..7928ffc3 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -467,14 +467,14 @@ struct sway_container *container_parent(struct sway_container *container, } static struct sway_container *container_at_view(struct sway_container *swayc, - double ox, double oy, + double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (!sway_assert(swayc->type == C_VIEW, "Expected a view")) { return NULL; } struct sway_view *sview = swayc->sway_view; - double view_sx = ox - sview->x; - double view_sy = oy - sview->y; + double view_sx = lx - sview->x; + double view_sy = ly - sview->y; double _sx, _sy; struct wlr_surface *_surface = NULL; @@ -516,18 +516,18 @@ static struct sway_container *container_at_view(struct sway_container *swayc, * container_at for a container with layout L_TABBED. */ static struct sway_container *container_at_tabbed(struct sway_container *parent, - double ox, double oy, + double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { - if (oy < parent->y || oy > parent->y + parent->height) { + if (ly < parent->y || ly > parent->y + parent->height) { return NULL; } struct sway_seat *seat = input_manager_current_seat(input_manager); // Tab titles int title_height = container_titlebar_height(); - if (oy < parent->y + title_height) { + if (ly < parent->y + title_height) { int tab_width = parent->width / parent->children->length; - int child_index = (ox - parent->x) / tab_width; + int child_index = (lx - parent->x) / tab_width; if (child_index >= parent->children->length) { child_index = parent->children->length - 1; } @@ -538,23 +538,23 @@ static struct sway_container *container_at_tabbed(struct sway_container *parent, // Surfaces struct sway_container *current = seat_get_active_child(seat, parent); - return container_at(current, ox, oy, surface, sx, sy); + return container_at(current, lx, ly, surface, sx, sy); } /** * container_at for a container with layout L_STACKED. */ static struct sway_container *container_at_stacked( - struct sway_container *parent, double ox, double oy, + struct sway_container *parent, double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { - if (oy < parent->y || oy > parent->y + parent->height) { + if (ly < parent->y || ly > parent->y + parent->height) { return NULL; } struct sway_seat *seat = input_manager_current_seat(input_manager); // Title bars int title_height = container_titlebar_height(); - int child_index = (oy - parent->y) / title_height; + int child_index = (ly - parent->y) / title_height; if (child_index < parent->children->length) { struct sway_container *child = parent->children->items[child_index]; return seat_get_focus_inactive(seat, child); @@ -563,14 +563,14 @@ static struct sway_container *container_at_stacked( // Surfaces struct sway_container *current = seat_get_active_child(seat, parent); - return container_at(current, ox, oy, surface, sx, sy); + return container_at(current, lx, ly, surface, sx, sy); } /** * container_at for a container with layout L_HORIZ or L_VERT. */ static struct sway_container *container_at_linear(struct sway_container *parent, - double ox, double oy, + double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { for (int i = 0; i < parent->children->length; ++i) { struct sway_container *child = parent->children->items[i]; @@ -580,22 +580,22 @@ static struct sway_container *container_at_linear(struct sway_container *parent, .width = child->width, .height = child->height, }; - if (wlr_box_contains_point(&box, ox, oy)) { - return container_at(child, ox, oy, surface, sx, sy); + if (wlr_box_contains_point(&box, lx, ly)) { + return container_at(child, lx, ly, surface, sx, sy); } } return NULL; } struct sway_container *container_at(struct sway_container *parent, - double ox, double oy, + double lx, double ly, struct wlr_surface **surface, double *sx, double *sy) { if (!sway_assert(parent->type >= C_WORKSPACE, "Expected workspace or deeper")) { return NULL; } if (parent->type == C_VIEW) { - return container_at_view(parent, ox, oy, surface, sx, sy); + return container_at_view(parent, lx, ly, surface, sx, sy); } if (!parent->children->length) { return NULL; @@ -604,11 +604,11 @@ struct sway_container *container_at(struct sway_container *parent, switch (parent->layout) { case L_HORIZ: case L_VERT: - return container_at_linear(parent, ox, oy, surface, sx, sy); + return container_at_linear(parent, lx, ly, surface, sx, sy); case L_TABBED: - return container_at_tabbed(parent, ox, oy, surface, sx, sy); + return container_at_tabbed(parent, lx, ly, surface, sx, sy); case L_STACKED: - return container_at_stacked(parent, ox, oy, surface, sx, sy); + return container_at_stacked(parent, lx, ly, surface, sx, sy); case L_FLOATING: sway_assert(false, "Didn't expect to see floating here"); return NULL; @@ -837,7 +837,7 @@ static size_t get_tree_representation(struct sway_container *parent, char *buffe lenient_strcat(buffer, "S["); break; case L_FLOATING: - strcpy(buffer, "F["); + lenient_strcat(buffer, "F["); break; case L_NONE: lenient_strcat(buffer, "D["); diff --git a/sway/tree/view.c b/sway/tree/view.c index 3de9879e..065d00db 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -119,10 +119,10 @@ const char *view_get_shell(struct sway_view *view) { return "unknown"; } -void view_configure(struct sway_view *view, double ox, double oy, int width, +void view_configure(struct sway_view *view, double lx, double ly, int width, int height) { if (view->impl->configure) { - view->impl->configure(view, ox, oy, width, height); + view->impl->configure(view, lx, ly, width, height); } } @@ -134,9 +134,8 @@ static void view_autoconfigure_floating(struct sway_view *view) { view->natural_width > max_width ? max_width : view->natural_width; int height = view->natural_height > max_height ? max_height : view->natural_height; - struct sway_container *output = ws->parent; - int lx = output->x + (ws->width - width) / 2; - int ly = output->y + (ws->height - height) / 2; + int lx = ws->x + (ws->width - width) / 2; + int ly = ws->y + (ws->height - height) / 2; view->border_left = view->border_right = view->border_bottom = true; view_set_tiled(view, false); @@ -152,8 +151,7 @@ void view_autoconfigure(struct sway_view *view) { struct sway_container *output = container_parent(view->swayc, C_OUTPUT); if (view->is_fullscreen) { - view_configure(view, 0, 0, output->width, output->height); - view->x = view->y = 0; + view_configure(view, output->x, output->y, output->width, output->height); return; } @@ -560,6 +558,9 @@ void view_unmap(struct sway_view *view) { } void view_update_position(struct sway_view *view, double lx, double ly) { + if (view->x == lx && view->y == ly) { + return; + } if (!container_is_floating(view->swayc)) { return; } From 7d2b33a4589df5cd130936fcb2016fda4014123b Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:26:59 +1000 Subject: [PATCH 14/34] Render floating views before top layer and unmanaged --- sway/desktop/output.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 8600d049..3dd10ac2 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -904,13 +904,12 @@ static void render_output(struct sway_output *output, struct timespec *when, struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_container *focus = seat_get_focus(seat); render_container(output, damage, workspace, focus == workspace); + render_floating(output, damage); render_unmanaged(output, damage, &root_container.sway_root->xwayland_unmanaged); render_layer(output, damage, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]); - - render_floating(output, damage); } render_layer(output, damage, &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]); From 3281574fa3199d649401e69e3d41493957b7d690 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:30:18 +1000 Subject: [PATCH 15/34] Remove check for if floating view intersects output --- sway/desktop/output.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 3dd10ac2..f58c5332 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -767,18 +767,6 @@ static void render_container(struct sway_output *output, } } -static bool floater_intersects_output(struct sway_container *floater, - struct sway_container *output) { - struct wlr_box box = { - .x = floater->x, - .y = floater->y, - .width = floater->width, - .height = floater->height, - }; - return wlr_output_layout_intersects(root_container.sway_root->output_layout, - output->sway_output->wlr_output, &box); -} - static void render_floating_container(struct sway_output *soutput, pixman_region32_t *damage, struct sway_container *con) { if (con->type == C_VIEW) { @@ -824,9 +812,7 @@ static void render_floating(struct sway_output *soutput, for (int k = 0; k < ws->floating->children->length; ++k) { struct sway_container *floater = ws->floating->children->items[k]; - if (floater_intersects_output(floater, soutput->swayc)) { - render_floating_container(soutput, damage, floater); - } + render_floating_container(soutput, damage, floater); } } } From 70f5d6fcf3219f122077b7e8d0b43a464f4e3fd4 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:32:24 +1000 Subject: [PATCH 16/34] Rename container_set_geometry_from_view --- include/sway/tree/container.h | 2 +- sway/tree/container.c | 16 ++++++++-------- sway/tree/view.c | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 4b686040..38c0f35d 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -238,7 +238,7 @@ size_t container_titlebar_height(void); void container_set_floating(struct sway_container *container, bool enable); -void container_set_geometry_from_view(struct sway_container *container); +void container_set_geometry_from_floating_view(struct sway_container *con); /** * Determine if the given container is itself floating. diff --git a/sway/tree/container.c b/sway/tree/container.c index 7928ffc3..7430aebb 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -930,23 +930,23 @@ void container_set_floating(struct sway_container *container, bool enable) { container_damage_whole(container); } -void container_set_geometry_from_view(struct sway_container *container) { - if (!sway_assert(container->type == C_VIEW, "Expected a view")) { +void container_set_geometry_from_floating_view(struct sway_container *con) { + if (!sway_assert(con->type == C_VIEW, "Expected a view")) { return; } - if (!sway_assert(container_is_floating(container), + if (!sway_assert(container_is_floating(con), "Expected a floating view")) { return; } - struct sway_view *view = container->sway_view; + struct sway_view *view = con->sway_view; size_t border_width = view->border_thickness * (view->border != B_NONE); size_t top = view->border == B_NORMAL ? container_titlebar_height() : border_width; - container->x = view->x - border_width; - container->y = view->y - top; - container->width = view->width + border_width * 2; - container->height = top + view->height + border_width; + con->x = view->x - border_width; + con->y = view->y - top; + con->width = view->width + border_width * 2; + con->height = top + view->height + border_width; } bool container_self_or_parent_floating(struct sway_container *container) { diff --git a/sway/tree/view.c b/sway/tree/view.c index 065d00db..30d5c7b4 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -567,7 +567,7 @@ void view_update_position(struct sway_view *view, double lx, double ly) { container_damage_whole(view->swayc); view->x = lx; view->y = ly; - container_set_geometry_from_view(view->swayc); + container_set_geometry_from_floating_view(view->swayc); container_damage_whole(view->swayc); } @@ -579,7 +579,7 @@ void view_update_size(struct sway_view *view, int width, int height) { view->width = width; view->height = height; if (container_is_floating(view->swayc)) { - container_set_geometry_from_view(view->swayc); + container_set_geometry_from_floating_view(view->swayc); } container_damage_whole(view->swayc); } From d4ed204d4da742ccabae29db2c90a62d90244a90 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 16:34:15 +1000 Subject: [PATCH 17/34] Remove container_self_or_parent_floating --- include/sway/tree/container.h | 6 ------ sway/tree/container.c | 9 --------- 2 files changed, 15 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 38c0f35d..7ed6aab1 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -246,10 +246,4 @@ void container_set_geometry_from_floating_view(struct sway_container *con); */ bool container_is_floating(struct sway_container *container); -/** - * Determine if the given container is itself floating or is a child of a - * floating container. - */ -bool container_self_or_parent_floating(struct sway_container *container); - #endif diff --git a/sway/tree/container.c b/sway/tree/container.c index 7430aebb..4e041508 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -949,15 +949,6 @@ void container_set_geometry_from_floating_view(struct sway_container *con) { con->height = top + view->height + border_width; } -bool container_self_or_parent_floating(struct sway_container *container) { - struct sway_container *workspace = container_parent(container, C_WORKSPACE); - if (!workspace) { - return false; - } - return container_has_anscestor(container, - workspace->sway_workspace->floating); -} - bool container_is_floating(struct sway_container *container) { struct sway_container *workspace = container_parent(container, C_WORKSPACE); if (!workspace) { From 4371c746e4d46c866ba4cdac2b3fba63a8de762e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 20:04:59 +1000 Subject: [PATCH 18/34] Implement wants_floating for xdg_shell and xdg_shell_v6 --- sway/desktop/xdg_shell.c | 6 ++++-- sway/desktop/xdg_shell_v6.c | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 412488b3..ae6945c2 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -128,8 +128,10 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { } static bool wants_floating(struct sway_view *view) { - // TODO - return false; + struct wlr_xdg_toplevel_state *state = + &view->wlr_xdg_surface->toplevel->current; + return state->min_width == state->max_width + && state->min_height == state->max_height; } static void for_each_surface(struct sway_view *view, diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index b3653913..fc0abf56 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -127,8 +127,10 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { } static bool wants_floating(struct sway_view *view) { - // TODO - return false; + struct wlr_xdg_toplevel_v6_state *state = + &view->wlr_xdg_surface_v6->toplevel->current; + return state->min_width == state->max_width + && state->min_height == state->max_height; } static void for_each_surface(struct sway_view *view, From 3b1db30a5e5758ec099b79250681cbf4be5ae0e9 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 20:37:04 +1000 Subject: [PATCH 19/34] Use surface size if xdg shell's geometry isn't set --- sway/desktop/xdg_shell.c | 13 +++++++++---- sway/desktop/xdg_shell_v6.c | 13 +++++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index ae6945c2..30990f67 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -182,13 +182,18 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit); struct sway_view *view = &xdg_shell_view->view; - struct wlr_box *geometry = &view->wlr_xdg_surface->geometry; + int width = view->wlr_xdg_surface->geometry.width; + int height = view->wlr_xdg_surface->geometry.height; + if (!width && !height) { + width = view->wlr_xdg_surface->surface->current->width; + height = view->wlr_xdg_surface->surface->current->height; + } if (!view->natural_width && !view->natural_height) { - view->natural_width = geometry->width; - view->natural_height = geometry->height; + view->natural_width = width; + view->natural_height = height; } if (view->swayc && container_is_floating(view->swayc)) { - view_update_size(view, geometry->width, geometry->height); + view_update_size(view, width, height); } else { view_update_size(view, xdg_shell_view->pending_width, xdg_shell_view->pending_height); diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index fc0abf56..7cba6e49 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -181,13 +181,18 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_shell_v6_view *xdg_shell_v6_view = wl_container_of(listener, xdg_shell_v6_view, commit); struct sway_view *view = &xdg_shell_v6_view->view; - struct wlr_box *geometry = &view->wlr_xdg_surface_v6->geometry; + int width = view->wlr_xdg_surface_v6->geometry.width; + int height = view->wlr_xdg_surface_v6->geometry.height; + if (!width && !height) { + width = view->wlr_xdg_surface_v6->surface->current->width; + height = view->wlr_xdg_surface_v6->surface->current->height; + } if (!view->natural_width && !view->natural_height) { - view->natural_width = geometry->width; - view->natural_height = geometry->height; + view->natural_width = width; + view->natural_height = height; } if (view->swayc && container_is_floating(view->swayc)) { - view_update_size(view, geometry->width, geometry->height); + view_update_size(view, width, height); } else { view_update_size(view, xdg_shell_v6_view->pending_width, xdg_shell_v6_view->pending_height); From 02d385e06f9ca6baccc9fdb35d4ab10532b6c22c Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 21:12:10 +1000 Subject: [PATCH 20/34] Use swayc rather than wlr_output when rendering --- sway/desktop/output.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/sway/desktop/output.c b/sway/desktop/output.c index f58c5332..4047fa3f 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -124,8 +124,8 @@ static void output_view_for_each_surface(struct sway_view *view, struct root_geometry *geo, wlr_surface_iterator_func_t iterator, void *user_data) { struct render_data *data = user_data; - geo->x = view->x - data->output->wlr_output->lx; - geo->y = view->y - data->output->wlr_output->ly; + geo->x = view->x - data->output->swayc->x; + geo->y = view->y - data->output->swayc->y; geo->width = view->surface->current->width; geo->height = view->surface->current->height; geo->rotation = 0; // TODO @@ -453,10 +453,9 @@ static void render_titlebar(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(marks_texture, &texture_box.width, &texture_box.height); - texture_box.x = - (x - output->wlr_output->lx + width - TITLEBAR_H_PADDING) + texture_box.x = (x - output->swayc->x + width - TITLEBAR_H_PADDING) * output_scale - texture_box.width; - texture_box.y = (y - output->wlr_output->ly + TITLEBAR_V_PADDING) + texture_box.y = (y - output->swayc->y + TITLEBAR_V_PADDING) * output_scale; float matrix[9]; @@ -478,9 +477,9 @@ static void render_titlebar(struct sway_output *output, struct wlr_box texture_box; wlr_texture_get_size(title_texture, &texture_box.width, &texture_box.height); - texture_box.x = (x - output->wlr_output->lx + TITLEBAR_H_PADDING) + texture_box.x = (x - output->swayc->x + TITLEBAR_H_PADDING) * output_scale; - texture_box.y = (y - output->wlr_output->ly + TITLEBAR_V_PADDING) + texture_box.y = (y - output->swayc->y + TITLEBAR_V_PADDING) * output_scale; float matrix[9]; From 5b1601c2e32b43cbb253fcd396ab9096f51b7e6c Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 21:33:18 +1000 Subject: [PATCH 21/34] Don't let xwayland views set position unless unmanaged --- include/sway/tree/view.h | 1 + sway/desktop/xwayland.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 65a23902..5c2f759c 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -137,6 +137,7 @@ struct sway_xwayland_view { struct wl_listener unmap; struct wl_listener destroy; + int pending_lx, pending_ly; int pending_width, pending_height; }; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index fc488162..f3264ddc 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -160,6 +160,8 @@ static void configure(struct sway_view *view, double lx, double ly, int width, } struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; + xwayland_view->pending_lx = lx; + xwayland_view->pending_ly = ly; xwayland_view->pending_width = width; xwayland_view->pending_height = height; wlr_xwayland_surface_configure(xsurface, lx, ly, width, height); @@ -264,7 +266,8 @@ static void handle_commit(struct wl_listener *listener, void *data) { } if (view->swayc && container_is_floating(view->swayc)) { view_update_size(view, xsurface->width, xsurface->height); - view_update_position(view, xsurface->x, xsurface->y); + view_update_position(view, + xwayland_view->pending_lx, xwayland_view->pending_ly); } else { view_update_size(view, xwayland_view->pending_width, xwayland_view->pending_height); From becceafa7f12f1a1668daca0b27c4102282d9076 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 26 May 2018 23:45:27 +1000 Subject: [PATCH 22/34] Remove unfinished wants_floating implementation for xwayland --- sway/desktop/xwayland.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index f3264ddc..7dc860aa 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -201,22 +201,6 @@ static bool wants_floating(struct sway_view *view) { // // We also want to return true if the NET_WM_STATE is MODAL. // wlroots doesn't appear to provide all this information at the moment. - struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - uint32_t *atom = xsurface->window_type; - for (size_t i = 0; i < xsurface->window_type_len; ++i) { - wlr_log(L_DEBUG, "xwayland window type %i", *atom); - // TODO: Come up with a better way of doing this - switch (*atom) { - case 36: // NET_WM_WINDOW_TYPE_UTILITY - case 44: // NET_WM_WINDOW_TYPE_SPLASH - case 276: // ? PGP passphrase dialog - case 337: // ? Firefox open file dialog - case 338: // ? Firefox open file dialog - return true; - } - ++atom; - } - return false; } From 40af5d81a1da972cdd59ecb0372ee756433aba26 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 27 May 2018 09:46:40 +1000 Subject: [PATCH 23/34] Fix getting adjacent output --- sway/tree/layout.c | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 28775253..d88948dc 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -680,26 +680,6 @@ static struct sway_container *get_swayc_in_output_direction( return ws; } -static void get_layout_center_position(struct sway_container *container, - int *x, int *y) { - // FIXME view coords are inconsistently referred to in layout/output systems - if (container->type == C_OUTPUT) { - *x = container->x + container->width/2; - *y = container->y + container->height/2; - } else { - struct sway_container *output = container_parent(container, C_OUTPUT); - if (container->type == C_WORKSPACE) { - // Workspace coordinates are actually wrong/arbitrary, but should - // be same as output. - *x = output->x; - *y = output->y; - } else { - *x = output->x + container->x; - *y = output->y + container->y; - } - } -} - static struct sway_container *sway_output_from_wlr(struct wlr_output *output) { if (output == NULL) { return NULL; @@ -755,8 +735,8 @@ struct sway_container *container_get_in_direction( "got invalid direction: %d", dir)) { return NULL; } - int lx, ly; - get_layout_center_position(container, &lx, &ly); + int lx = container->x + container->width / 2; + int ly = container->y + container->height / 2; struct wlr_output_layout *layout = root_container.sway_root->output_layout; struct wlr_output *wlr_adjacent = From 97672295ed50d1d6272876c4a3b6b5607cab05c6 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 27 May 2018 23:43:05 +1000 Subject: [PATCH 24/34] Don't unmaximize floating views --- include/sway/tree/view.h | 3 --- sway/desktop/xdg_shell.c | 9 --------- sway/desktop/xdg_shell_v6.c | 9 --------- sway/desktop/xwayland.c | 9 --------- sway/tree/container.c | 3 --- sway/tree/view.c | 7 ------- 6 files changed, 40 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 5c2f759c..7362df5c 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -32,7 +32,6 @@ struct sway_view_impl { void (*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); bool (*wants_floating)(struct sway_view *view); void (*for_each_surface)(struct sway_view *view, @@ -221,8 +220,6 @@ void view_autoconfigure(struct sway_view *view); void view_set_activated(struct sway_view *view, bool activated); -void view_set_tiled(struct sway_view *view, bool tiled); - void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen); void view_set_fullscreen(struct sway_view *view, bool fullscreen); diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 30990f67..7a39a84c 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -111,14 +111,6 @@ static void set_activated(struct sway_view *view, bool activated) { } } -static void set_tiled(struct sway_view *view, bool tiled) { - if (xdg_shell_view_from_view(view) == NULL) { - return; - } - struct wlr_xdg_surface *surface = view->wlr_xdg_surface; - wlr_xdg_toplevel_set_maximized(surface, tiled); -} - static void set_fullscreen(struct sway_view *view, bool fullscreen) { if (xdg_shell_view_from_view(view) == NULL) { return; @@ -170,7 +162,6 @@ static const struct sway_view_impl view_impl = { .get_string_prop = get_string_prop, .configure = configure, .set_activated = set_activated, - .set_tiled = set_tiled, .set_fullscreen = set_fullscreen, .wants_floating = wants_floating, .for_each_surface = for_each_surface, diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 7cba6e49..b1b8091b 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -110,14 +110,6 @@ static void set_activated(struct sway_view *view, bool activated) { } } -static void set_tiled(struct sway_view *view, bool tiled) { - if (xdg_shell_v6_view_from_view(view) == NULL) { - return; - } - struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; - wlr_xdg_toplevel_v6_set_maximized(surface, tiled); -} - static void set_fullscreen(struct sway_view *view, bool fullscreen) { if (xdg_shell_v6_view_from_view(view) == NULL) { return; @@ -169,7 +161,6 @@ static const struct sway_view_impl view_impl = { .get_string_prop = get_string_prop, .configure = configure, .set_activated = set_activated, - .set_tiled = set_tiled, .set_fullscreen = set_fullscreen, .wants_floating = wants_floating, .for_each_surface = for_each_surface, diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 7dc860aa..d0fbcaeb 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -175,14 +175,6 @@ static void set_activated(struct sway_view *view, bool activated) { wlr_xwayland_surface_activate(surface, activated); } -static void set_tiled(struct sway_view *view, bool tiled) { - if (xwayland_view_from_view(view) == NULL) { - return; - } - struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface; - wlr_xwayland_surface_set_maximized(surface, tiled); -} - static void set_fullscreen(struct sway_view *view, bool fullscreen) { if (xwayland_view_from_view(view) == NULL) { return; @@ -232,7 +224,6 @@ static const struct sway_view_impl view_impl = { .get_int_prop = get_int_prop, .configure = configure, .set_activated = set_activated, - .set_tiled = set_tiled, .set_fullscreen = set_fullscreen, .wants_floating = wants_floating, .close = _close, diff --git a/sway/tree/container.c b/sway/tree/container.c index 4e041508..9e70da09 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -920,9 +920,6 @@ void container_set_floating(struct sway_container *container, bool enable) { container_add_child(workspace, container); container->width = container->parent->width; container->height = container->parent->height; - if (container->type == C_VIEW) { - view_set_tiled(container->sway_view, true); - } container->is_sticky = false; container_reap_empty_recursive(workspace->sway_workspace->floating); } diff --git a/sway/tree/view.c b/sway/tree/view.c index 30d5c7b4..6e589611 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -138,7 +138,6 @@ static void view_autoconfigure_floating(struct sway_view *view) { int ly = ws->y + (ws->height - height) / 2; view->border_left = view->border_right = view->border_bottom = true; - view_set_tiled(view, false); view_configure(view, lx, ly, width, height); } @@ -255,12 +254,6 @@ void view_set_activated(struct sway_view *view, bool activated) { } } -void view_set_tiled(struct sway_view *view, bool tiled) { - if (view->impl->set_tiled) { - view->impl->set_tiled(view, tiled); - } -} - // Set fullscreen, but without IPC events or arranging windows. void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { if (view->is_fullscreen == fullscreen) { From f24087d1045bbee8642ee0703f6513ae605f2c47 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 28 May 2018 17:42:56 +1000 Subject: [PATCH 25/34] Fix fullscreen position --- sway/tree/view.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sway/tree/view.c b/sway/tree/view.c index 6e589611..2eaa5d49 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -554,13 +554,12 @@ void view_update_position(struct sway_view *view, double lx, double ly) { if (view->x == lx && view->y == ly) { return; } - if (!container_is_floating(view->swayc)) { - return; - } container_damage_whole(view->swayc); view->x = lx; view->y = ly; - container_set_geometry_from_floating_view(view->swayc); + if (container_is_floating(view->swayc)) { + container_set_geometry_from_floating_view(view->swayc); + } container_damage_whole(view->swayc); } From f7cadf23332c469d34e7b5811469842d68ad9474 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 29 May 2018 22:46:43 +1000 Subject: [PATCH 26/34] Adjust move command to account for changed coordinate system --- sway/commands/move.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sway/commands/move.c b/sway/commands/move.c index 890b1a8c..dc9a6f6f 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c @@ -13,16 +13,14 @@ #include "stringop.h" #include "list.h" -static const char* expected_syntax = +static const char* expected_syntax = "Expected 'move <[px] px>' or " "'move to workspace ' or " "'move to output ' or " "'move position mouse'"; static struct sway_container *output_in_direction(const char *direction, - struct wlr_output *reference, int ref_ox, int ref_oy) { - int ref_lx = ref_ox + reference->lx, - ref_ly = ref_oy + reference->ly; + struct wlr_output *reference, int ref_lx, int ref_ly) { struct { char *name; enum wlr_direction direction; From 9119f876552a47716bd317524bf5d786f909e5e5 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 30 May 2018 10:22:35 +1000 Subject: [PATCH 27/34] Fix floating position when view is floated when mapped --- sway/desktop/xdg_shell.c | 22 ++++++++++++---------- sway/desktop/xdg_shell_v6.c | 22 ++++++++++++---------- sway/desktop/xwayland.c | 7 +++---- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 7a39a84c..32d1e3ca 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -173,17 +173,13 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit); struct sway_view *view = &xdg_shell_view->view; - int width = view->wlr_xdg_surface->geometry.width; - int height = view->wlr_xdg_surface->geometry.height; - if (!width && !height) { - width = view->wlr_xdg_surface->surface->current->width; - height = view->wlr_xdg_surface->surface->current->height; - } - if (!view->natural_width && !view->natural_height) { - view->natural_width = width; - view->natural_height = height; - } if (view->swayc && container_is_floating(view->swayc)) { + int width = view->wlr_xdg_surface->geometry.width; + int height = view->wlr_xdg_surface->geometry.height; + if (!width && !height) { + width = view->wlr_xdg_surface->surface->current->width; + height = view->wlr_xdg_surface->surface->current->height; + } view_update_size(view, width, height); } else { view_update_size(view, xdg_shell_view->pending_width, @@ -216,6 +212,12 @@ static void handle_map(struct wl_listener *listener, void *data) { struct sway_view *view = &xdg_shell_view->view; struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface; + view->natural_width = view->wlr_xdg_surface->geometry.width; + view->natural_height = view->wlr_xdg_surface->geometry.height; + if (!view->natural_width && !view->natural_height) { + view->natural_width = view->wlr_xdg_surface->surface->current->width; + view->natural_height = view->wlr_xdg_surface->surface->current->height; + } view_map(view, view->wlr_xdg_surface->surface); xdg_shell_view->commit.notify = handle_commit; diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index b1b8091b..6cb489db 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -172,17 +172,13 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_shell_v6_view *xdg_shell_v6_view = wl_container_of(listener, xdg_shell_v6_view, commit); struct sway_view *view = &xdg_shell_v6_view->view; - int width = view->wlr_xdg_surface_v6->geometry.width; - int height = view->wlr_xdg_surface_v6->geometry.height; - if (!width && !height) { - width = view->wlr_xdg_surface_v6->surface->current->width; - height = view->wlr_xdg_surface_v6->surface->current->height; - } - if (!view->natural_width && !view->natural_height) { - view->natural_width = width; - view->natural_height = height; - } if (view->swayc && container_is_floating(view->swayc)) { + int width = view->wlr_xdg_surface_v6->geometry.width; + int height = view->wlr_xdg_surface_v6->geometry.height; + if (!width && !height) { + width = view->wlr_xdg_surface_v6->surface->current->width; + height = view->wlr_xdg_surface_v6->surface->current->height; + } view_update_size(view, width, height); } else { view_update_size(view, xdg_shell_v6_view->pending_width, @@ -215,6 +211,12 @@ static void handle_map(struct wl_listener *listener, void *data) { struct sway_view *view = &xdg_shell_v6_view->view; struct wlr_xdg_surface_v6 *xdg_surface = view->wlr_xdg_surface_v6; + view->natural_width = view->wlr_xdg_surface_v6->geometry.width; + view->natural_height = view->wlr_xdg_surface_v6->geometry.height; + if (!view->natural_width && !view->natural_height) { + view->natural_width = view->wlr_xdg_surface_v6->surface->current->width; + view->natural_height = view->wlr_xdg_surface_v6->surface->current->height; + } view_map(view, view->wlr_xdg_surface_v6->surface); xdg_shell_v6_view->commit.notify = handle_commit; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index d0fbcaeb..76265ea9 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -235,10 +235,6 @@ static void handle_commit(struct wl_listener *listener, void *data) { wl_container_of(listener, xwayland_view, commit); struct sway_view *view = &xwayland_view->view; struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - if (!view->natural_width && !view->natural_height) { - view->natural_width = xsurface->width; - view->natural_height = xsurface->height; - } if (view->swayc && container_is_floating(view->swayc)) { view_update_size(view, xsurface->width, xsurface->height); view_update_position(view, @@ -263,6 +259,9 @@ static void handle_map(struct wl_listener *listener, void *data) { struct wlr_xwayland_surface *xsurface = data; struct sway_view *view = &xwayland_view->view; + view->natural_width = xsurface->width; + view->natural_height = xsurface->height; + // Wire up the commit listener here, because xwayland map/unmap can change // the underlying wlr_surface wl_signal_add(&xsurface->surface->events.commit, &xwayland_view->commit); From c9f8d35ca9b74dc7b059b097a6e55441d7405a77 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 30 May 2018 10:27:16 +1000 Subject: [PATCH 28/34] Consider floating views when calculating title height --- sway/config.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sway/config.c b/sway/config.c index cf05c236..14064cde 100644 --- a/sway/config.c +++ b/sway/config.c @@ -26,6 +26,7 @@ #include "sway/config.h" #include "sway/tree/arrange.h" #include "sway/tree/layout.h" +#include "sway/tree/workspace.h" #include "cairo.h" #include "pango.h" #include "readline.h" @@ -751,6 +752,16 @@ void config_update_font_height(bool recalculate) { container_for_each_descendant_dfs(&root_container, find_font_height_iterator, &recalculate); + // Also consider floating views + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *output = root_container.children->items[i]; + for (int j = 0; j < output->children->length; ++j) { + struct sway_container *ws = output->children->items[i]; + container_for_each_descendant_dfs(ws->sway_workspace->floating, + find_font_height_iterator, &recalculate); + } + } + if (config->font_height != prev_max_height) { arrange_root(); } From e605dc43bb4880fa3f36a9d4eee94e985150baa0 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 29 May 2018 20:50:02 -0400 Subject: [PATCH 29/34] Fix mouse warping interaction with layout coords --- sway/input/seat.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sway/input/seat.c b/sway/input/seat.c index 6a266fba..d35cbeef 100644 --- a/sway/input/seat.c +++ b/sway/input/seat.c @@ -601,10 +601,8 @@ void seat_set_focus_warp(struct sway_seat *seat, if (config->mouse_warping && warp) { if (new_output && last_output && new_output != last_output) { - double x = new_output->x + container->x + - container->width / 2.0; - double y = new_output->y + container->y + - container->height / 2.0; + double x = container->x + container->width / 2.0; + double y = container->y + container->height / 2.0; struct wlr_output *wlr_output = new_output->sway_output->wlr_output; if (!wlr_output_layout_contains_point( From 00cac220389ffbe8f2061b11f936931a29688a22 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 31 May 2018 08:22:19 +1000 Subject: [PATCH 30/34] Fix crash when using multiple outputs --- sway/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/config.c b/sway/config.c index 14064cde..27308066 100644 --- a/sway/config.c +++ b/sway/config.c @@ -756,7 +756,7 @@ void config_update_font_height(bool recalculate) { for (int i = 0; i < root_container.children->length; ++i) { struct sway_container *output = root_container.children->items[i]; for (int j = 0; j < output->children->length; ++j) { - struct sway_container *ws = output->children->items[i]; + struct sway_container *ws = output->children->items[j]; container_for_each_descendant_dfs(ws->sway_workspace->floating, find_font_height_iterator, &recalculate); } From c9e3a313b440c171ae0bf78eb5b85bf63c3121b9 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 31 May 2018 08:30:07 +1000 Subject: [PATCH 31/34] Fix fullscreen position of xwayland views --- sway/desktop/xwayland.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 76265ea9..75bfb7b2 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -237,12 +237,12 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; if (view->swayc && container_is_floating(view->swayc)) { view_update_size(view, xsurface->width, xsurface->height); - view_update_position(view, - xwayland_view->pending_lx, xwayland_view->pending_ly); } else { view_update_size(view, xwayland_view->pending_width, xwayland_view->pending_height); } + view_update_position(view, + xwayland_view->pending_lx, xwayland_view->pending_ly); view_damage_from(view); } From a2c1cb9072b990de9181bffeb69e43f9b3030804 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 31 May 2018 18:21:49 +1000 Subject: [PATCH 32/34] Fix mpv damage issue when unfullscreening into floating --- include/sway/tree/view.h | 3 +++ sway/tree/view.c | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 7362df5c..3df38e2d 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -51,6 +51,9 @@ struct sway_view { double x, y; int width, height; + double saved_x, saved_y; + int saved_width, saved_height; + // The size the view would want to be if it weren't tiled. // Used when changing a view from tiled to floating. int natural_width, natural_height; diff --git a/sway/tree/view.c b/sway/tree/view.c index 2eaa5d49..3117ded6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -274,6 +274,10 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { view_set_fullscreen(workspace->sway_workspace->fullscreen, false); } workspace->sway_workspace->fullscreen = view; + view->saved_x = view->x; + view->saved_y = view->y; + view->saved_width = view->width; + view->saved_height = view->height; view->swayc->saved_x = view->swayc->x; view->swayc->saved_y = view->swayc->y; view->swayc->saved_width = view->swayc->width; @@ -296,11 +300,12 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) { } } else { workspace->sway_workspace->fullscreen = NULL; - view->swayc->width = view->swayc->saved_width; - view->swayc->height = view->swayc->saved_height; if (container_is_floating(view->swayc)) { - view->swayc->x = view->swayc->saved_x; - view->swayc->y = view->swayc->saved_y; + view_configure(view, view->saved_x, view->saved_y, + view->saved_width, view->saved_height); + } else { + view->swayc->width = view->swayc->saved_width; + view->swayc->height = view->swayc->saved_height; view_autoconfigure(view); } } From d466b8fa7b5ba8dff4b5ea5520aa523f50815316 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 31 May 2018 21:58:28 +1000 Subject: [PATCH 33/34] Don't auto float xdg views if their dimensions are not set --- sway/desktop/xdg_shell.c | 3 ++- sway/desktop/xdg_shell_v6.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 32d1e3ca..d2b8822c 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -122,7 +122,8 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { static bool wants_floating(struct sway_view *view) { struct wlr_xdg_toplevel_state *state = &view->wlr_xdg_surface->toplevel->current; - return state->min_width == state->max_width + return state->min_width != 0 && state->min_height != 0 + && state->min_width == state->max_width && state->min_height == state->max_height; } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 6cb489db..6ffe334a 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -121,7 +121,8 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { static bool wants_floating(struct sway_view *view) { struct wlr_xdg_toplevel_v6_state *state = &view->wlr_xdg_surface_v6->toplevel->current; - return state->min_width == state->max_width + return state->min_width != 0 && state->min_height != 0 + && state->min_width == state->max_width && state->min_height == state->max_height; } From 70c2c504452eccbe5a74bc014e99b5b03db14124 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 31 May 2018 22:02:20 +1000 Subject: [PATCH 34/34] Fix changing borders on floating views --- sway/commands/border.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sway/commands/border.c b/sway/commands/border.c index 4ba361da..0b059562 100644 --- a/sway/commands/border.c +++ b/sway/commands/border.c @@ -37,7 +37,13 @@ struct cmd_results *cmd_border(int argc, char **argv) { "or 'border pixel '"); } - view_autoconfigure(view); + 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); + } struct sway_seat *seat = input_manager_current_seat(input_manager); if (seat->cursor) {