From f3ab895916ca1a0f004b5ceaefa90eee90676532 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 4 May 2018 08:24:25 -0400 Subject: Implement `floating enable` --- sway/commands/floating.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 sway/commands/floating.c (limited to 'sway/commands') 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); +} -- cgit v1.2.3 From 1132efe42e8086216c7bab6b405d09a22231dde5 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 4 May 2018 08:41:16 -0400 Subject: 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 --- sway/commands/floating.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'sway/commands') 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) { -- cgit v1.2.3 From 1f2e399ade77070a2d0b82856ad9a3eef96b8676 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 24 May 2018 22:30:44 +1000 Subject: Implement floating --- sway/commands/floating.c | 25 ++----------------------- sway/commands/sticky.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 23 deletions(-) create mode 100644 sway/commands/sticky.c (limited to 'sway/commands') 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); +} -- cgit v1.2.3 From aaba7642b3e4e9a63aea49412b10221f399b17af Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 09:26:23 +1000 Subject: Replace is_floating boolean with function --- sway/commands/floating.c | 2 +- sway/commands/layout.c | 10 +++------- sway/commands/sticky.c | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) (limited to 'sway/commands') 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"); } -- cgit v1.2.3 From 5d69a56209dc6138272de6cdbd8f066d37199727 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Fri, 25 May 2018 17:10:58 +1000 Subject: Prevent splitting a floating view --- sway/commands/split.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'sway/commands') 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); } -- cgit v1.2.3 From f7cadf23332c469d34e7b5811469842d68ad9474 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Tue, 29 May 2018 22:46:43 +1000 Subject: Adjust move command to account for changed coordinate system --- sway/commands/move.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'sway/commands') 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; -- cgit v1.2.3 From 70c2c504452eccbe5a74bc014e99b5b03db14124 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Thu, 31 May 2018 22:02:20 +1000 Subject: Fix changing borders on floating views --- sway/commands/border.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'sway/commands') 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) { -- cgit v1.2.3