diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-06-01 15:41:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-01 15:41:49 -0700 |
commit | 96446fdbf748acfdbd4c60fbc0d12e45a27199fe (patch) | |
tree | 6d46cc61a1e7c74efe36565796ccbf8b47e7e4a7 /sway | |
parent | fd885d5779ef9aa408fa856a66fa7343ce01fa19 (diff) | |
parent | 70c2c504452eccbe5a74bc014e99b5b03db14124 (diff) |
Merge pull request #2027 from RyanDwyer/implement-floating
Implement floating
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 4 | ||||
-rw-r--r-- | sway/commands/border.c | 8 | ||||
-rw-r--r-- | sway/commands/floating.c | 40 | ||||
-rw-r--r-- | sway/commands/layout.c | 10 | ||||
-rw-r--r-- | sway/commands/move.c | 6 | ||||
-rw-r--r-- | sway/commands/split.c | 15 | ||||
-rw-r--r-- | sway/commands/sticky.c | 40 | ||||
-rw-r--r-- | sway/config.c | 11 | ||||
-rw-r--r-- | sway/criteria.c | 9 | ||||
-rw-r--r-- | sway/debug-tree.c | 2 | ||||
-rw-r--r-- | sway/desktop/output.c | 112 | ||||
-rw-r--r-- | sway/desktop/xdg_shell.c | 35 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 35 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 52 | ||||
-rw-r--r-- | sway/input/cursor.c | 15 | ||||
-rw-r--r-- | sway/input/seat.c | 22 | ||||
-rw-r--r-- | sway/ipc-json.c | 10 | ||||
-rw-r--r-- | sway/meson.build | 2 | ||||
-rw-r--r-- | sway/tree/arrange.c | 16 | ||||
-rw-r--r-- | sway/tree/container.c | 169 | ||||
-rw-r--r-- | sway/tree/layout.c | 54 | ||||
-rw-r--r-- | sway/tree/view.c | 126 | ||||
-rw-r--r-- | sway/tree/workspace.c | 48 |
23 files changed, 626 insertions, 215 deletions
diff --git a/sway/commands.c b/sway/commands.c index 6f5113f8..e9762bef 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 }, @@ -189,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/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 <px>'"); } - 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) { diff --git a/sway/commands/floating.c b/sway/commands/floating.c new file mode 100644 index 00000000..46b761da --- /dev/null +++ b/sway/commands/floating.c @@ -0,0 +1,40 @@ +#include <string.h> +#include <strings.h> +#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) { + 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(container); + } else { + return cmd_results_new(CMD_FAILURE, "floating", + "Expected 'floating <enable|disable|toggle>'"); + } + + container_set_floating(container, wants_floating); + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} 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/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 <left|right|up|down> <[px] px>' or " "'move <container|window> to workspace <name>' or " "'move <container|window|workspace> to output <name|direction>' 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; 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); } diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c new file mode 100644 index 00000000..732ccb98 --- /dev/null +++ b/sway/commands/sticky.c @@ -0,0 +1,40 @@ +#include <string.h> +#include <strings.h> +#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(container)) { + 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 <enable|disable|toggle>'"); + } + + container->is_sticky = wants_sticky; + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/config.c b/sway/config.c index cf05c236..27308066 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[j]; + container_for_each_descendant_dfs(ws->sway_workspace->floating, + find_font_height_iterator, &recalculate); + } + } + if (config->font_height != prev_max_height) { arrange_root(); } diff --git a/sway/criteria.c b/sway/criteria.c index dec5fed7..a263485a 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 (!container_is_floating(view->swayc)) { + return false; + } } if (criteria->tiling) { - // TODO + if (container_is_floating(view->swayc)) { + return false; + } } if (criteria->urgent) { diff --git a/sway/debug-tree.c b/sway/debug-tree.c index ae0a1869..f3465afe 100644 --- a/sway/debug-tree.c +++ b/sway/debug-tree.c @@ -25,9 +25,9 @@ static const char *layout_to_str(enum sway_container_layout layout) { 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, diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 0deb86ca..4047fa3f 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->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 @@ -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); @@ -449,9 +453,10 @@ 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 + width - TITLEBAR_H_PADDING) * output_scale - texture_box.width; - texture_box.y = (y + TITLEBAR_V_PADDING) * output_scale; + texture_box.x = (x - output->swayc->x + width - TITLEBAR_H_PADDING) + * output_scale - texture_box.width; + texture_box.y = (y - output->swayc->y + TITLEBAR_V_PADDING) + * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, @@ -472,8 +477,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->swayc->x + TITLEBAR_H_PADDING) + * output_scale; + texture_box.y = (y - output->swayc->y + TITLEBAR_V_PADDING) + * output_scale; float matrix[9]; wlr_matrix_project_box(matrix, &texture_box, @@ -755,8 +762,58 @@ static void render_container(struct sway_output *output, render_container_tabbed(output, damage, con, parent_focused); break; case L_FLOATING: - // TODO - break; + sway_assert(false, "Didn't expect to see floating here"); + } +} + +static void render_floating_container(struct sway_output *soutput, + pixman_region32_t *damage, struct sway_container *con) { + 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; + } + + 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); + } +} + +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; + 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]; + render_floating_container(soutput, damage, floater); + } + } } } @@ -794,8 +851,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) { @@ -834,6 +889,7 @@ 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); @@ -915,6 +971,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); @@ -1052,21 +1109,14 @@ 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 - output->wlr_output->lx, + .y = con->y - output->wlr_output->ly, + .width = con->width, + .height = con->height, }; + 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 b2b95fa0..d2b8822c 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,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, lx, ly); } static void set_activated(struct sway_view *view, bool activated) { @@ -118,6 +119,14 @@ 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) { + struct wlr_xdg_toplevel_state *state = + &view->wlr_xdg_surface->toplevel->current; + return state->min_width != 0 && state->min_height != 0 + && state->min_width == state->max_width + && state->min_height == state->max_height; +} + 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) { @@ -155,6 +164,7 @@ static const struct sway_view_impl view_impl = { .configure = configure, .set_activated = set_activated, .set_fullscreen = set_fullscreen, + .wants_floating = wants_floating, .for_each_surface = for_each_surface, .close = _close, .destroy = destroy, @@ -164,11 +174,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; - // 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); + 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, + xdg_shell_view->pending_height); + } view_update_title(view, false); view_damage_from(view); } @@ -196,6 +213,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 d098c797..6ffe334a 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,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, lx, ly); } static void set_activated(struct sway_view *view, bool activated) { @@ -117,6 +118,14 @@ 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) { + struct wlr_xdg_toplevel_v6_state *state = + &view->wlr_xdg_surface_v6->toplevel->current; + return state->min_width != 0 && state->min_height != 0 + && state->min_width == state->max_width + && state->min_height == state->max_height; +} + 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) { @@ -154,6 +163,7 @@ static const struct sway_view_impl view_impl = { .configure = configure, .set_activated = set_activated, .set_fullscreen = set_fullscreen, + .wants_floating = wants_floating, .for_each_surface = for_each_surface, .close = _close, .destroy = destroy, @@ -163,11 +173,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; - // 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); + 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, + xdg_shell_v6_view->pending_height); + } view_update_title(view, false); view_damage_from(view); } @@ -195,6 +212,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 6a99a66a..75bfb7b2 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -152,7 +152,7 @@ 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, +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) { @@ -160,25 +160,11 @@ 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; - } - + 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, 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) { @@ -197,6 +183,19 @@ 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. + return false; +} + static void _close(struct sway_view *view) { if (xwayland_view_from_view(view) == NULL) { return; @@ -226,6 +225,7 @@ static const struct sway_view_impl view_impl = { .configure = configure, .set_activated = set_activated, .set_fullscreen = set_fullscreen, + .wants_floating = wants_floating, .close = _close, .destroy = destroy, }; @@ -234,10 +234,15 @@ 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->swayc && container_is_floating(view->swayc)) { + view_update_size(view, xsurface->width, xsurface->height); + } 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); } @@ -254,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); diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 6751931d..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,7 +108,10 @@ static struct sway_container *container_at_coords( } struct sway_container *c; - if ((c = container_at(ws, ox, oy, surface, sx, sy))) { + if ((c = floating_container_at(lx, ly, surface, sx, sy))) { + return c; + } + if ((c = container_at(ws, lx, ly, surface, sx, sy))) { return c; } diff --git a/sway/input/seat.c b/sway/input/seat.c index 0295212c..d35cbeef 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; } @@ -591,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( diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 03582950..6d185449 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" @@ -152,6 +153,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 68675f67..4c038583 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', @@ -64,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..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); @@ -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..9e70da09 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,15 +178,13 @@ 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->children->length == 0) { - // destroy the WS if there are no children (TODO check for floating) - 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; - // 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 +197,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 +268,17 @@ static void container_root_finish(struct sway_container *con) { } bool container_reap_empty(struct sway_container *con) { + if (con->layout == L_FLOATING) { + // Don't reap the magical floating container that each workspace has + 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; @@ -349,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: @@ -436,7 +435,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 +446,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; } @@ -466,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; @@ -515,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; } @@ -537,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); @@ -562,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]; @@ -579,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; @@ -603,13 +604,14 @@ 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: - return NULL; // TODO + sway_assert(false, "Didn't expect to see floating here"); + return NULL; case L_NONE: return NULL; } @@ -617,6 +619,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; + 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]; + 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 +704,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); @@ -866,3 +896,60 @@ void container_notify_subtree_changed(struct sway_container *container) { size_t container_titlebar_height() { return config->font_height + TITLEBAR_V_PADDING * 2; } + +void container_set_floating(struct sway_container *container, bool enable) { + if (container_is_floating(container) == 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); + if (container->type == C_VIEW) { + view_autoconfigure(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; + container->is_sticky = false; + container_reap_empty_recursive(workspace->sway_workspace->floating); + } + arrange_workspace(workspace); + container_damage_whole(container); +} + +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(con), + "Expected a floating view")) { + return; + } + 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; + + 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_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 2f4ae667..d88948dc 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, @@ -160,6 +154,10 @@ void container_move_to(struct sway_container *container, || container_has_ancestor(container, destination)) { return; } + if (container_is_floating(container)) { + // TODO + return; + } struct sway_container *old_parent = container_remove_child(container); container->width = container->height = 0; container->saved_width = container->saved_height = 0; @@ -172,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 = @@ -681,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; @@ -719,6 +698,10 @@ struct sway_container *container_get_in_direction( enum movement_direction dir) { struct sway_container *parent = container->parent; + if (container_is_floating(container)) { + return NULL; + } + if (container->type == C_VIEW && container->sway_view->is_fullscreen) { if (dir == MOVE_PARENT || dir == MOVE_CHILD) { return NULL; @@ -743,14 +726,17 @@ 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), "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 = diff --git a/sway/tree/view.c b/sway/tree/view.c index 26ff1e8d..3117ded6 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -119,13 +119,28 @@ 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); } } +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; + 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_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")) { @@ -135,8 +150,12 @@ 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; + } + + if (container_is_floating(view->swayc)) { + view_autoconfigure_floating(view); return; } @@ -158,21 +177,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 +201,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) { @@ -257,6 +274,12 @@ 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; view->swayc->saved_height = view->swayc->height; @@ -277,8 +300,14 @@ 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_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); + } } } @@ -452,6 +481,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 (container_is_floating(focus)) { + focus = focus->parent->parent; + } free(criterias); cont = container_view_create(focus, view); @@ -468,7 +502,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 +555,16 @@ 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->x == lx && view->y == ly) { 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; + if (container_is_floating(view->swayc)) { + container_set_geometry_from_floating_view(view->swayc); + } container_damage_whole(view->swayc); } @@ -533,15 +572,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 (container_is_floating(view->swayc)) { + container_set_geometry_from_floating_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 +927,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 -> floating -> workspace + // A more complex ancestry could be: + // 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 = 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; @@ -901,10 +953,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 f34baa9e..f78ae9a5 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,9 @@ struct sway_container *workspace_create(struct sway_container *output, return NULL; } swayws->swayc = workspace; + swayws->floating = container_create(C_CONTAINER); + swayws->floating->parent = swayws->swayc; + swayws->floating->layout = L_FLOATING; workspace->sway_workspace = swayws; container_add_child(output, workspace); @@ -383,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); @@ -391,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); @@ -406,3 +434,21 @@ 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; + } + // 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; +} |