From 9ef866bfea19dd0e52b7608a11c0e0d34df7f5e4 Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 18 Aug 2015 12:50:15 +0100 Subject: [PATCH 01/23] Beguin work on the move command. Stubbed method. --- sway/commands.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sway/commands.c b/sway/commands.c index 51de7a50c..2ecfeb983 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -281,6 +281,11 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * return true; } +static bool cmd_move(struct sway_config *config, int argc, char **argv) { + sway_log(L_DEBUG, "move cmd stub called");//Stubbed method until I get back. + return true; +} + static bool cmd_kill(struct sway_config *config, int argc, char **argv) { swayc_t *view = get_focused_container(&root_container); wlc_view_close(view->handle); From d6ab5e481be2faa0e911d0b3109ae01fe79eb25f Mon Sep 17 00:00:00 2001 From: Will Hunt Date: Tue, 18 Aug 2015 12:50:15 +0100 Subject: [PATCH 02/23] Beguin work on the move command. Stubbed method. --- sway/commands.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sway/commands.c b/sway/commands.c index 51de7a50c..197040640 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -281,6 +281,11 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * return true; } +static bool cmd_move(struct sway_config *config, int argc, char **argv) { + sway_log(L_DEBUG, "move cmd stub called");//Stubbed method until I get back. + return true; +} + static bool cmd_kill(struct sway_config *config, int argc, char **argv) { swayc_t *view = get_focused_container(&root_container); wlc_view_close(view->handle); @@ -492,7 +497,8 @@ static struct cmd_handler handlers[] = { { "split", cmd_split }, { "splith", cmd_splith }, { "splitv", cmd_splitv }, - { "workspace", cmd_workspace } + { "workspace", cmd_workspace }, + { "cmd_move",cmd_move} }; static char **split_directive(char *line, int *argc) { From 15d9f1edcb69fec18104fc5d40780cf1306731ef Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 20 Aug 2015 11:30:11 -0500 Subject: [PATCH 03/23] Added in basic resize command --- include/layout.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/layout.h b/include/layout.h index 75e72d2fe..4dff81b7e 100644 --- a/include/layout.h +++ b/include/layout.h @@ -29,4 +29,6 @@ swayc_t *get_focused_container(swayc_t *parent); swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent); swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); +void recursive_resize(swayc_t *container, double amount, enum movement_direction dir); + #endif From bc3babf566f1f8ad9db4d1f7b70a859f54ba6c48 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 20 Aug 2015 11:30:32 -0500 Subject: [PATCH 04/23] Added in basic resize command --- include/ipc.h | 12 ++-- sway/commands.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++ sway/layout.c | 32 +++++++++++ 3 files changed, 183 insertions(+), 6 deletions(-) diff --git a/include/ipc.h b/include/ipc.h index 0b6441f66..2d71c666b 100644 --- a/include/ipc.h +++ b/include/ipc.h @@ -2,14 +2,14 @@ #define _SWAY_IPC_H enum ipc_command_type { - IPC_COMMAND = 0, + IPC_COMMAND = 0, IPC_GET_WORKSPACES = 1, - IPC_SUBSCRIBE = 2, - IPC_GET_OUTPUTS = 3, - IPC_GET_TREE = 4, - IPC_GET_MARKS = 5, + IPC_SUBSCRIBE = 2, + IPC_GET_OUTPUTS = 3, + IPC_GET_TREE = 4, + IPC_GET_MARKS = 5, IPC_GET_BAR_CONFIG = 6, - IPC_GET_VERSION = 7, + IPC_GET_VERSION = 7, }; void ipc_init(void); diff --git a/sway/commands.c b/sway/commands.c index 644b80050..cdc80a0bf 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -422,6 +422,150 @@ static bool cmd_reload(struct sway_config *config, int argc, char **argv) { return true; } +static bool cmd_resize(struct sway_config *config, int argc, char **argv) { + if (!checkarg(argc, "resize", EXPECTED_AT_LEAST, 3)) { + return false; + } + char *end; + int amount = (int)strtol(argv[2], &end, 10); + if (errno == ERANGE || amount == 0) { + errno = 0; + return false; + } + if (strcmp(argv[0], "shrink") != 0 && strcmp(argv[0], "grow") != 0) { + return false; + } + if (strcmp(argv[0], "shrink") == 0) { + amount *= -1; + } + + swayc_t *parent = get_focused_view(active_workspace); + swayc_t *focused = parent; + swayc_t *sibling; + if (!parent) { + return true; + } + // Find the closest possible sibling and resize using that edge + int i; + if (strcmp(argv[1], "width") == 0) { + int lnumber = 0; + int rnumber = 0; + while (parent->parent) { + if (parent->parent->layout == L_HORIZ) { + for (i = 0; i < parent->parent->children->length; i++) { + sibling = parent->parent->children->items[i]; + if (sibling->x != focused->x) { + if (sibling->x < parent->x) { + lnumber++; + } else if (sibling->x > parent->x) { + rnumber++; + } + } + } + if (rnumber || lnumber) { + break; + } + } + parent = parent->parent; + } + if (parent == &root_container) { + return true; + } + sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber); + //TODO: Ensure rounding is done in such a way that there are NO pixel leaks + for (i = 0; i < parent->parent->children->length; i++) { + sibling = parent->parent->children->items[i]; + if (sibling->x != focused->x) { + if (sibling->x < parent->x) { + double pixels = -1 * (amount/lnumber); + if (lnumber) { + recursive_resize(sibling, pixels/2, MOVE_RIGHT); + } else { + recursive_resize(sibling, pixels, MOVE_RIGHT); + } + } else if (sibling->x > parent->x) { + double pixels = -1 * (amount/rnumber); + if (rnumber) { + recursive_resize(sibling, pixels/2, MOVE_LEFT); + } else { + recursive_resize(sibling, pixels, MOVE_LEFT); + } + } + } else { + if (rnumber != 0 && lnumber != 0) { + recursive_resize(parent, amount/2, MOVE_LEFT); + recursive_resize(parent, amount/2, MOVE_RIGHT); + } else if (rnumber) { + recursive_resize(parent, amount, MOVE_RIGHT); + } else if (lnumber) { + recursive_resize(parent, amount, MOVE_LEFT); + } + } + } + arrange_windows(active_workspace, -1, -1); + return true; + } else if (strcmp(argv[1], "height") == 0) { + int tnumber = 0; + int bnumber = 0; + while (parent->parent) { + if (parent->parent->layout == L_VERT) { + for (i = 0; i < parent->parent->children->length; i++) { + sibling = parent->parent->children->items[i]; + if (sibling->y != focused->y) { + if (sibling->y < parent->y) { + bnumber++; + } else if (sibling->y > parent->y) { + tnumber++; + } + } + } + if (bnumber || tnumber) { + break; + } + } + parent = parent->parent; + } + if (parent == &root_container) { + return true; + } + sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber); + //TODO: Ensure rounding is done in such a way that there are NO pixel leaks + for (i = 0; i < parent->parent->children->length; i++) { + sibling = parent->parent->children->items[i]; + if (sibling->y != focused->y) { + if (sibling->y < parent->y) { + double pixels = -1 * (amount/bnumber); + if (tnumber) { + recursive_resize(sibling, pixels/2, MOVE_UP); + } else { + recursive_resize(sibling, pixels, MOVE_UP); + } + } else if (sibling->x > parent->x) { + double pixels = -1 * (amount/tnumber); + if (bnumber) { + recursive_resize(sibling, pixels/2, MOVE_DOWN); + } else { + recursive_resize(sibling, pixels, MOVE_DOWN); + } + } + } else { + if (bnumber != 0 && tnumber != 0) { + recursive_resize(parent, amount/2, MOVE_UP); + recursive_resize(parent, amount/2, MOVE_DOWN); + } else if (tnumber) { + recursive_resize(parent, amount, MOVE_UP); + } else if (bnumber) { + recursive_resize(parent, amount, MOVE_DOWN); + } + } + } + arrange_windows(active_workspace, -1, -1); + return true; + } + sway_log(L_INFO, "Done with resize"); + return true; +} + static bool cmd_set(struct sway_config *config, int argc, char **argv) { if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { return false; @@ -587,6 +731,7 @@ static struct cmd_handler handlers[] = { { "layout", cmd_layout }, { "log_colors", cmd_log_colors }, { "reload", cmd_reload }, + { "resize", cmd_resize }, { "set", cmd_set }, { "split", cmd_split }, { "splith", cmd_splith }, diff --git a/sway/layout.c b/sway/layout.c index 78b3dd279..b70e10415 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -370,3 +370,35 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) } } } + +void recursive_resize(swayc_t *container, double amount, enum movement_direction dir) { + int i; + bool layout_match = true; + if (dir == MOVE_LEFT) { + container->x += (int) amount; + container->width += (int) amount; + layout_match = container->layout == L_HORIZ; + } else if(dir == MOVE_RIGHT) { + container->width += (int) amount; + layout_match = container->layout == L_HORIZ; + } else if(dir == MOVE_UP) { + container->y += (int) amount; + container->height += (int) amount; + layout_match = container->layout == L_VERT; + } else if(dir == MOVE_DOWN) { + container->height += (int) amount; + layout_match = container->layout == L_VERT; + } + if (container->type == C_VIEW) { + return; + } + if (layout_match) { + for (i = 0; i < container->children->length; i++) { + recursive_resize(container->children->items[i], amount/container->children->length, dir); + } + } else { + for (i = 0; i < container->children->length; i++) { + recursive_resize(container->children->items[i], amount, dir); + } + } +} From d06732e1a8c2df4d1523c1c0efeff5534156e387 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 20 Aug 2015 11:35:01 -0500 Subject: [PATCH 05/23] Altered incorrect comment --- sway/commands.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sway/commands.c b/sway/commands.c index cdc80a0bf..be6bc8cff 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -445,7 +445,8 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) { if (!parent) { return true; } - // Find the closest possible sibling and resize using that edge + // Find the closest parent container which has siblings of the proper layout. + // Then apply the resize to all of them. int i; if (strcmp(argv[1], "width") == 0) { int lnumber = 0; From c9935507f2bc8e2471f6642e99a2fb52ab1310f0 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 20 Aug 2015 11:42:01 -0500 Subject: [PATCH 06/23] Style fixes --- sway/commands.c | 1 - sway/layout.c | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index be6bc8cff..27dbb44b3 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -563,7 +563,6 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) { arrange_windows(active_workspace, -1, -1); return true; } - sway_log(L_INFO, "Done with resize"); return true; } diff --git a/sway/layout.c b/sway/layout.c index b70e10415..c9c8fa7f7 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -378,14 +378,14 @@ void recursive_resize(swayc_t *container, double amount, enum movement_direction container->x += (int) amount; container->width += (int) amount; layout_match = container->layout == L_HORIZ; - } else if(dir == MOVE_RIGHT) { + } else if (dir == MOVE_RIGHT) { container->width += (int) amount; layout_match = container->layout == L_HORIZ; - } else if(dir == MOVE_UP) { + } else if (dir == MOVE_UP) { container->y += (int) amount; container->height += (int) amount; layout_match = container->layout == L_VERT; - } else if(dir == MOVE_DOWN) { + } else if (dir == MOVE_DOWN) { container->height += (int) amount; layout_match = container->layout == L_VERT; } From 36e07e9ebc55b3fc8a8b8cd76ee743202691ad56 Mon Sep 17 00:00:00 2001 From: taiyu Date: Thu, 20 Aug 2015 09:52:54 -0700 Subject: [PATCH 07/23] find_parent_by_type --- include/container.h | 11 ++++ sway/commands.c | 5 +- sway/container.c | 138 ++++++++++++++++++++++++++++++-------------- sway/handlers.c | 15 +---- sway/layout.c | 10 +--- sway/workspace.c | 4 +- 6 files changed, 112 insertions(+), 71 deletions(-) diff --git a/include/container.h b/include/container.h index bd92058d6..fd621490d 100644 --- a/include/container.h +++ b/include/container.h @@ -55,6 +55,7 @@ struct sway_container { struct sway_container *focused; }; +// Container Creation swayc_t *new_output(wlc_handle handle); swayc_t *new_workspace(swayc_t *output, const char *name); @@ -65,13 +66,23 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle); // Creates view as a new floating view which is in the active workspace swayc_t *new_floating_view(wlc_handle handle); +// Container Destroying swayc_t *destroy_output(swayc_t *output); // Destroys workspace if empty and returns parent pointer, else returns NULL swayc_t *destroy_workspace(swayc_t *workspace); +// Destroyes container and all parent container if they are empty, returns +// topmost non-empty parent. returns NULL otherwise swayc_t *destroy_container(swayc_t *container); +// Destroys view and all empty parent containers. return topmost non-empty +// parent swayc_t *destroy_view(swayc_t *view); +// Container Lookup + +swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types); +swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts); + swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); diff --git a/sway/commands.c b/sway/commands.c index 644b80050..3ac7f4dd4 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -390,7 +390,6 @@ static bool cmd_layout(struct sway_config *config, int argc, char **argv) { return false; } swayc_t *parent = get_focused_container(&root_container); - while (parent->type == C_VIEW) { parent = parent->parent; } @@ -512,9 +511,7 @@ static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { // Resize workspace if going from fullscreen -> notfullscreen // otherwise just resize container if (current) { - while (container->type != C_WORKSPACE) { - container = container->parent; - } + container = swayc_parent_by_type(container, C_WORKSPACE); } // Only resize container when going into fullscreen arrange_windows(container, -1, -1); diff --git a/sway/container.c b/sway/container.c index 4559a5f56..7ccc2e098 100644 --- a/sway/container.c +++ b/sway/container.c @@ -8,6 +8,8 @@ #include "layout.h" #include "log.h" +#define ASSERT_NONNULL(PTR) \ + sway_assert (PTR, "%s: " #PTR "must be non-null", __func__) static swayc_t *new_swayc(enum swayc_types type) { swayc_t *c = calloc(1, sizeof(swayc_t)); @@ -20,37 +22,40 @@ static swayc_t *new_swayc(enum swayc_types type) { return c; } -static void free_swayc(swayc_t *c) { +static void free_swayc(swayc_t *cont) { + if (!ASSERT_NONNULL(cont)) { + return; + } // TODO does not properly handle containers with children, // TODO but functions that call this usually check for that - if (c->children) { - if (c->children->length) { + if (cont->children) { + if (cont->children->length) { int i; - for (i = 0; i < c->children->length; ++i) { - free_swayc(c->children->items[i]); + for (i = 0; i < cont->children->length; ++i) { + free_swayc(cont->children->items[i]); } } - list_free(c->children); + list_free(cont->children); } - if (c->floating) { - if (c->floating->length) { + if (cont->floating) { + if (cont->floating->length) { int i; - for (i = 0; i < c->floating->length; ++i) { - free_swayc(c->floating->items[i]); + for (i = 0; i < cont->floating->length; ++i) { + free_swayc(cont->floating->items[i]); } } - list_free(c->floating); + list_free(cont->floating); } - if (c->parent) { - remove_child(c); + if (cont->parent) { + remove_child(cont); } - if (c->name) { - free(c->name); + if (cont->name) { + free(cont->name); } - free(c); + free(cont); } -/* New containers */ +// New containers static bool workspace_test(swayc_t *view, void *name) { return strcasecmp(view->name, (char *)name) == 0; @@ -103,6 +108,9 @@ swayc_t *new_output(wlc_handle handle) { } swayc_t *new_workspace(swayc_t *output, const char *name) { + if (!ASSERT_NONNULL(output)) { + return NULL; + } sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle); swayc_t *workspace = new_swayc(C_WORKSPACE); @@ -120,6 +128,9 @@ swayc_t *new_workspace(swayc_t *output, const char *name) { } swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { + if (!ASSERT_NONNULL(child)) { + return NULL; + } swayc_t *cont = new_swayc(C_CONTAINER); sway_log(L_DEBUG, "creating container %p around %p", cont, child); @@ -162,6 +173,9 @@ swayc_t *new_container(swayc_t *child, enum swayc_layouts layout) { } swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { + if (!ASSERT_NONNULL(sibling)) { + return NULL; + } const char *title = wlc_view_get_title(handle); swayc_t *view = new_swayc(C_VIEW); sway_log(L_DEBUG, "Adding new view %lu:%s to container %p %d", @@ -172,14 +186,14 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { view->visible = true; view->is_focused = true; // Setup geometry + const struct wlc_geometry* geometry = wlc_view_get_geometry(handle); view->width = 0; view->height = 0; + view->desired_width = geometry->size.w; + view->desired_height = geometry->size.h; view->gaps = config->gaps_inner; - view->desired_width = -1; - view->desired_height = -1; - view->is_floating = false; if (sibling->type == C_WORKSPACE) { @@ -225,9 +239,12 @@ swayc_t *new_floating_view(wlc_handle handle) { return view; } -/* Destroy container */ +// Destroy container swayc_t *destroy_output(swayc_t *output) { + if (!ASSERT_NONNULL(output)) { + return NULL; + } if (output->children->length == 0) { // TODO move workspaces to other outputs } @@ -237,23 +254,21 @@ swayc_t *destroy_output(swayc_t *output) { } swayc_t *destroy_workspace(swayc_t *workspace) { + if (!ASSERT_NONNULL(workspace)) { + return NULL; + } // NOTE: This is called from elsewhere without checking children length // TODO move containers to other workspaces? // for now just dont delete // Do not destroy this if it's the last workspace on this output - swayc_t *output = workspace->parent; - while (output && output->type != C_OUTPUT) { - output = output->parent; - } - if (output) { - if (output->children->length == 1) { - return NULL; - } + swayc_t *output = swayc_parent_by_type(workspace, C_OUTPUT); + if (output && output->children->length == 1) { + return NULL; } if (workspace->children->length == 0) { - sway_log(L_DEBUG, "Workspace: Destroying workspace '%s'", workspace->name); + sway_log(L_DEBUG, "%s: '%s'", __func__, workspace->name); swayc_t *parent = workspace->parent; free_swayc(workspace); return parent; @@ -262,6 +277,9 @@ swayc_t *destroy_workspace(swayc_t *workspace) { } swayc_t *destroy_container(swayc_t *container) { + if (!ASSERT_NONNULL(container)) { + return NULL; + } while (container->children->length == 0 && container->type == C_CONTAINER) { sway_log(L_DEBUG, "Container: Destroying container '%p'", container); swayc_t *parent = container->parent; @@ -272,8 +290,7 @@ swayc_t *destroy_container(swayc_t *container) { } swayc_t *destroy_view(swayc_t *view) { - if (view == NULL) { - sway_log(L_DEBUG, "Warning: NULL passed into destroy_view"); + if (!ASSERT_NONNULL(view)) { return NULL; } sway_log(L_DEBUG, "Destroying view '%p'", view); @@ -287,6 +304,34 @@ swayc_t *destroy_view(swayc_t *view) { return parent; } +// Container lookup + +swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) { + if (!ASSERT_NONNULL(container)) { + return NULL; + } + if (!sway_assert(type < C_TYPES && type >= C_ROOT, "%s: invalid type", __func__)) { + return NULL; + } + do { + container = container->parent; + } while(container && container->type != type); + return container; +} + +swayc_t *swayc_parent_by_layout(swayc_t *container, enum swayc_layouts layout) { + if (!ASSERT_NONNULL(container)) { + return NULL; + } + if (!sway_assert(layout < L_LAYOUTS && layout >= L_NONE, "%s: invalid layout", __func__)) { + return NULL; + } + do { + container = container->parent; + } while (container && container->layout != layout); + return container; +} + swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data) { if (!container->children) { return NULL; @@ -316,25 +361,27 @@ swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *da } void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { - if (!container || !container->children || !container->children->length) { - return; - } - int i; - for (i = 0; i < container->children->length; ++i) { - swayc_t *child = container->children->items[i]; - f(child, data); - container_map(child, f, data); - } - if (container->type == C_WORKSPACE) { - for (i = 0; i < container->floating->length; ++i) { - swayc_t *child = container->floating->items[i]; + if (container && container->children && container->children->length) { + int i; + for (i = 0; i < container->children->length; ++i) { + swayc_t *child = container->children->items[i]; f(child, data); container_map(child, f, data); } + if (container->type == C_WORKSPACE) { + for (i = 0; i < container->floating->length; ++i) { + swayc_t *child = container->floating->items[i]; + f(child, data); + container_map(child, f, data); + } + } } } void set_view_visibility(swayc_t *view, void *data) { + if (!ASSERT_NONNULL(view)) { + return; + } uint32_t *p = data; if (view->type == C_VIEW) { wlc_view_set_mask(view->handle, *p); @@ -348,6 +395,9 @@ void set_view_visibility(swayc_t *view, void *data) { } void reset_gaps(swayc_t *view, void *data) { + if (!ASSERT_NONNULL(view)) { + return; + } if (view->type == C_OUTPUT) { view->gaps = config->gaps_outer; } diff --git a/sway/handlers.c b/sway/handlers.c index 5993223d3..79628fe5c 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -20,10 +20,7 @@ static struct wlc_origin mouse_origin; static bool pointer_test(swayc_t *view, void *_origin) { const struct wlc_origin *origin = _origin; // Determine the output that the view is under - swayc_t *parent = view; - while (parent->type != C_OUTPUT) { - parent = parent->parent; - } + swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); if (origin->x >= view->x && origin->y >= view->y && origin->x < view->x + view->width && origin->y < view->y + view->height && view->visible && parent == root_container.focused) { @@ -191,10 +188,7 @@ static bool handle_view_created(wlc_handle handle) { if (newview) { set_focused_container(newview); - swayc_t *output = newview->parent; - while (output && output->type != C_OUTPUT) { - output = output->parent; - } + swayc_t *output = swayc_parent_by_type(newview, C_OUTPUT); arrange_windows(output, -1, -1); } return true; @@ -262,10 +256,7 @@ static void handle_view_state_request(wlc_handle view, enum wlc_view_state_bit s arrange_windows(c->parent, -1, -1); // Set it as focused window for that workspace if its going fullscreen if (toggle) { - swayc_t *ws = c; - while (ws->type != C_WORKSPACE) { - ws = ws->parent; - } + swayc_t *ws = swayc_parent_by_type(c, C_WORKSPACE); // Set ws focus to c set_focused_container_for(ws, c); } diff --git a/sway/layout.c b/sway/layout.c index 78b3dd279..8c011fdb5 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -161,10 +161,7 @@ void arrange_windows(swayc_t *container, int width, int height) { } }; if (wlc_view_get_state(container->handle) & WLC_BIT_FULLSCREEN) { - swayc_t *parent = container; - while (parent->type != C_OUTPUT) { - parent = parent->parent; - } + swayc_t *parent = swayc_parent_by_type(container, C_OUTPUT); geometry.origin.x = 0; geometry.origin.y = 0; geometry.size.w = parent->width; @@ -263,10 +260,7 @@ void arrange_windows(swayc_t *container, int width, int height) { } }; if (wlc_view_get_state(view->handle) & WLC_BIT_FULLSCREEN) { - swayc_t *parent = view; - while (parent->type != C_OUTPUT) { - parent = parent->parent; - } + swayc_t *parent = swayc_parent_by_type(view, C_OUTPUT); geometry.origin.x = 0; geometry.origin.y = 0; geometry.size.w = parent->width; diff --git a/sway/workspace.c b/sway/workspace.c index 0f44d3b06..d436da8e2 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -75,9 +75,7 @@ char *workspace_next_name(void) { swayc_t *workspace_create(const char* name) { swayc_t *parent = get_focused_container(&root_container); - while (parent->type != C_OUTPUT) { - parent = parent->parent; - } + parent = swayc_parent_by_type(parent, C_OUTPUT); return new_workspace(parent, name); } From 754793aad4c0f0b93e30804c70807e9984741ae0 Mon Sep 17 00:00:00 2001 From: minus Date: Thu, 20 Aug 2015 21:08:13 +0200 Subject: [PATCH 08/23] added IPC messages get_workspaces and get_outputs No escaping on container names is done yet, as well as some values are hardcoded because they don't exist yet. --- include/stringop.h | 1 + sway/ipc.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++ sway/stringop.c | 39 ++++++++++++++++++++ 3 files changed, 132 insertions(+) diff --git a/include/stringop.h b/include/stringop.h index a53468299..4300f9edf 100644 --- a/include/stringop.h +++ b/include/stringop.h @@ -10,5 +10,6 @@ char *code_strchr(const char *string, char delimiter); char *code_strstr(const char *haystack, const char *needle); int unescape_string(char *string); char *join_args(char **argv, int argc); +char *join_list(list_t *list, char *separator); #endif diff --git a/sway/ipc.c b/sway/ipc.c index 505c17f83..39e580cd7 100644 --- a/sway/ipc.c +++ b/sway/ipc.c @@ -11,10 +11,13 @@ #include #include #include +#include #include "ipc.h" #include "log.h" #include "config.h" #include "commands.h" +#include "list.h" +#include "stringop.h" static int ipc_socket = -1; static struct wlc_event_source *ipc_event_source = NULL; @@ -37,6 +40,10 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data); void ipc_client_disconnect(struct ipc_client *client); void ipc_client_handle_command(struct ipc_client *client); bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t payload_length); +void ipc_get_workspaces_callback(swayc_t *container, void *data); +void ipc_get_outputs_callback(swayc_t *container, void *data); + +char *json_list(list_t *items); void ipc_init(void) { ipc_socket = socket(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, 0); @@ -195,6 +202,26 @@ void ipc_client_handle_command(struct ipc_client *client) { ipc_send_reply(client, reply, (uint32_t) length); break; } + case IPC_GET_WORKSPACES: + { + list_t *workspaces = create_list(); + container_map(&root_container, ipc_get_workspaces_callback, workspaces); + char *json = json_list(workspaces); + free_flat_list(workspaces); + ipc_send_reply(client, json, strlen(json)); + free(json); + break; + } + case IPC_GET_OUTPUTS: + { + list_t *outputs = create_list(); + container_map(&root_container, ipc_get_outputs_callback, outputs); + char *json = json_list(outputs); + free_flat_list(outputs); + ipc_send_reply(client, json, strlen(json)); + free(json); + break; + } default: sway_log(L_INFO, "Unknown IPC command type %i", client->current_command); ipc_client_disconnect(client); @@ -227,3 +254,68 @@ bool ipc_send_reply(struct ipc_client *client, const char *payload, uint32_t pay return true; } + +char *json_list(list_t *items) { + char *json_elements = join_list(items, ","); + size_t len = strlen(json_elements); + char *json = malloc(len + 3); + json[0] = '['; + memcpy(json + 1, json_elements, len); + json[len+1] = ']'; + json[len+2] = '\0'; + free(json_elements); + return json; +} + +void ipc_get_workspaces_callback(swayc_t *container, void *data) { + if (container->type == C_WORKSPACE) { + char *json = malloc(512); // Output should usually be around 180 chars + int num = isdigit(container->name[0]) ? atoi(container->name) : -1; + // TODO: escape the name (quotation marks, unicode) + sprintf(json, + "{" + "\"num\":%d," + "\"name\":\"%s\"," + "\"visible\":%s," + "\"focused\":%s," + "\"rect\":{" + "\"x\":%d," + "\"y\":%d," + "\"width\":%d," + "\"height\":%d" + "}," + "\"output\":\"%s\"," + "\"urgent\":%s" + "}", + num, container->name, container->visible ? "true" : "false", container->is_focused ? "true" : "false", + container->x, container->y, container->width, container->height, + container->parent->name, "false" // TODO: urgent hint + ); + list_add((list_t *)data, json); + } +} + +void ipc_get_outputs_callback(swayc_t *container, void *data) { + if (container->type == C_OUTPUT) { + char *json = malloc(512); // Output should usually be around 130 chars + // TODO: escape the name (quotation marks, unicode) + sprintf(json, + "{" + "\"name\":\"%s\"," + "\"active\":%s," + "\"primary\":%s," + "\"rect\":{" + "\"x\":%d," + "\"y\":%d," + "\"width\":%d," + "\"height\":%d" + "}," + "\"current_workspace\":\"%s\"" + "}", + container->name, "true", "false", // TODO: active, primary + container->x, container->y, container->width, container->height, + container->focused ? container->focused->name : "" + ); + list_add((list_t *)data, json); + } +} diff --git a/sway/stringop.c b/sway/stringop.c index 1dff97bf1..c39e2c348 100644 --- a/sway/stringop.c +++ b/sway/stringop.c @@ -4,6 +4,7 @@ #include "string.h" #include "list.h" #include +#include /* Note: This returns 8 characters for trimmed_start per tab character. */ char *strip_whitespace(char *_str, int *trimmed_start) { @@ -197,3 +198,41 @@ char *join_args(char **argv, int argc) { res[len - 1] = '\0'; return res; } + +/* + * Join a list of strings, adding separator in between. Separator can be NULL. + */ +char *join_list(list_t *list, char *separator) { + if (!sway_assert(list != NULL, "list != NULL") || list->length == 0) { + return NULL; + } + + size_t len = 1; // NULL terminator + size_t sep_len = 0; + if (separator != NULL) { + sep_len = strlen(separator); + len += (list->length - 1) * sep_len; + } + + for (int i = 0; i < list->length; i++) { + len += strlen(list->items[i]); + } + + char *res = malloc(len); + + char *p = res + strlen(list->items[0]); + strcpy(res, list->items[0]); + + for (int i = 1; i < list->length; i++) { + if (sep_len) { + memcpy(p, separator, sep_len); + p += sep_len; + } + strcpy(p, list->items[i]); + p += strlen(list->items[i]); + } + + *p = '\0'; + + return res; +} From 2a62c5c7fb71fc815663281793ba6a89d2b246ed Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 20 Aug 2015 21:27:38 +0100 Subject: [PATCH 09/23] Basic left right move command implemented. --- include/container.h | 2 ++ include/layout.h | 3 +++ sway/commands.c | 25 ++++++++++++++++++++++--- sway/layout.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 71 insertions(+), 4 deletions(-) diff --git a/include/container.h b/include/container.h index 186ee8b6b..63529e441 100644 --- a/include/container.h +++ b/include/container.h @@ -15,6 +15,7 @@ enum swayc_types{ C_TYPES, }; + enum swayc_layouts{ L_NONE, L_HORIZ, @@ -75,6 +76,7 @@ swayc_t *destroy_view(swayc_t *view); swayc_t *find_container(swayc_t *container, bool (*test)(swayc_t *view, void *data), void *data); void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); + // Mappings void set_view_visibility(swayc_t *view, void *data); diff --git a/include/layout.h b/include/layout.h index 282f92ee0..79241698a 100644 --- a/include/layout.h +++ b/include/layout.h @@ -15,6 +15,9 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); swayc_t *replace_child(swayc_t *child, swayc_t *new_child); swayc_t *remove_child(swayc_t *child); +void move_container(swayc_t* container,swayc_t* root,int direction); + + // Layout void arrange_windows(swayc_t *container, int width, int height); diff --git a/sway/commands.c b/sway/commands.c index 9a3ea5d66..1ca5c17ff 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -282,8 +282,27 @@ static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char * } static bool cmd_move(struct sway_config *config, int argc, char **argv) { - sway_log(L_DEBUG, "move cmd stub called");//Stubbed method until I get back. + if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) { + return false; + } + + swayc_t *view = get_focused_container(&root_container); + + if (strcasecmp(argv[0], "left") == 0) { + move_container(view,&root_container,MOVE_LEFT); + } else if (strcasecmp(argv[0], "right") == 0) { + move_container(view,&root_container,MOVE_RIGHT); + } else if (strcasecmp(argv[0], "up") == 0) { + move_container(view,&root_container,MOVE_UP); + } else if (strcasecmp(argv[0], "down") == 0) { + move_container(view,&root_container,MOVE_DOWN); + } else + { + return false; + } + return true; + } static bool cmd_kill(struct sway_config *config, int argc, char **argv) { @@ -492,13 +511,13 @@ static struct cmd_handler handlers[] = { { "kill", cmd_kill }, { "layout", cmd_layout }, { "log_colors", cmd_log_colors }, + { "move",cmd_move}, { "reload", cmd_reload }, { "set", cmd_set }, { "split", cmd_split }, { "splith", cmd_splith }, { "splitv", cmd_splitv }, - { "workspace", cmd_workspace }, - { "cmd_move",cmd_move} + { "workspace", cmd_workspace } }; static char **split_directive(char *line, int *argc) { diff --git a/sway/layout.c b/sway/layout.c index 105359d26..9fdfd62a9 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -91,6 +91,50 @@ swayc_t *remove_child(swayc_t *child) { return parent; } +void move_container(swayc_t *container,swayc_t* root,int direction){ + sway_log(L_DEBUG, "Moved window"); + swayc_t *temp; + int i; + uint clength = root->children->length; + //Rearrange + for (i = 0; i < clength; ++i) { + swayc_t *child = root->children->items[i]; + if(child->handle == container->handle){ + if(clength == 1){ + //Only one container, meh. + break; + } + + //TODO: Implement move to a different workspace. + if(direction == MOVE_LEFT && i > 0){ + temp = root->children->items[i-1]; + root->children->items[i] = temp; + root->children->items[i-1] = container; + arrange_windows(&root_container,-1,-1); + } + else if(direction == MOVE_RIGHT && i < clength-1){ + temp = root->children->items[i+1]; + root->children->items[i] = temp; + root->children->items[i+1] = container; + arrange_windows(&root_container,-1,-1); + + } + else if(direction == MOVE_UP){ + sway_log(L_INFO, "Moving up not implemented"); + } + else if(direction == MOVE_DOWN){ + sway_log(L_INFO, "Moving down not implemented"); + } + + break; + } + else if(child->children != NULL){ + move_container(container,child,direction); + } + } + +} + void arrange_windows(swayc_t *container, int width, int height) { int i; @@ -282,4 +326,3 @@ swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent) { } return NULL; } - From 713bf29ec901b711d782e96721898c32fcd5d56e Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 20 Aug 2015 21:45:00 +0100 Subject: [PATCH 10/23] Few stray bits --- include/layout.h | 2 +- sway/commands.c | 1 + sway/layout.c | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/layout.h b/include/layout.h index c1d7d8b46..5c73af997 100644 --- a/include/layout.h +++ b/include/layout.h @@ -17,7 +17,7 @@ swayc_t *add_sibling(swayc_t *sibling, swayc_t *child); swayc_t *replace_child(swayc_t *child, swayc_t *new_child); swayc_t *remove_child(swayc_t *child); -void move_container(swayc_t* container,swayc_t* root,int direction); +void move_container(swayc_t* container,swayc_t* root,enum movement_direction direction); // Layout diff --git a/sway/commands.c b/sway/commands.c index e39b781a2..5d79104f6 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -362,6 +362,7 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) { } return true; +} static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { diff --git a/sway/layout.c b/sway/layout.c index a48f15c4f..0c1f736d9 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -108,7 +108,9 @@ swayc_t *remove_child(swayc_t *child) { return parent; } -void move_container(swayc_t *container,swayc_t* root,int direction){ +//TODO: Implement horizontal movement. +//TODO: Implement move to a different workspace. +void move_container(swayc_t *container,swayc_t* root,enum movement_direction direction){ sway_log(L_DEBUG, "Moved window"); swayc_t *temp; int i; @@ -121,8 +123,6 @@ void move_container(swayc_t *container,swayc_t* root,int direction){ //Only one container, meh. break; } - //TODO: Implement horizontal movement. - //TODO: Implement move to a different workspace. if(direction == MOVE_LEFT && i > 0){ temp = root->children->items[i-1]; root->children->items[i] = temp; From 0ac6409a757fe6720adf896cd47bdc2d7912f4b7 Mon Sep 17 00:00:00 2001 From: Max Bruckner Date: Thu, 20 Aug 2015 23:12:34 +0200 Subject: [PATCH 11/23] Add Wayland and Xorg session files This allows display managers to detect sway. --- CMakeLists.txt | 8 ++++++++ sway-xorg.desktop | 5 +++++ sway.desktop | 5 +++++ 3 files changed, 18 insertions(+) create mode 100644 sway-xorg.desktop create mode 100644 sway.desktop diff --git a/CMakeLists.txt b/CMakeLists.txt index d190cd8b8..3ed6fc02f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,3 +69,11 @@ INSTALL( FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sway.5 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man5 ) + +INSTALL( + FILES ${PROJECT_SOURCE_DIR}/sway.desktop + DESTINATION ${CMAKE_INSTALL_PREFIX}/share/wayland-sessions/) + +INSTALL( + FILES ${PROJECT_SOURCE_DIR}/sway-xorg.desktop + DESTINATION ${CMAKE_INSTALL_PREFIX}/share/xsessions/) diff --git a/sway-xorg.desktop b/sway-xorg.desktop new file mode 100644 index 000000000..e93a4284a --- /dev/null +++ b/sway-xorg.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Sway (Xorg) +Comment=SirCmpwn's Wayland window manager +Exec=sway +Type=Application diff --git a/sway.desktop b/sway.desktop new file mode 100644 index 000000000..98c9af293 --- /dev/null +++ b/sway.desktop @@ -0,0 +1,5 @@ +[Desktop Entry] +Name=Sway +Comment=SirCmpwn's Wayland window manager +Exec=sway +Type=Application From 3a5fce339f8dcc22db8cafdfeba7b2748df02d18 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 20 Aug 2015 17:14:26 -0400 Subject: [PATCH 12/23] Reset key buffer on reload To preserve my sanity --- include/input_state.h | 1 + sway/config.c | 3 +++ sway/input_state.c | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/include/input_state.h b/include/input_state.h index 782b4b19c..a7e0c1ca4 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -44,6 +44,7 @@ extern struct pointer_state { void start_floating(swayc_t *view); void reset_floating(swayc_t *view); +void input_init(void); #endif diff --git a/sway/config.c b/sway/config.c index 9f65e8a26..0afb02051 100644 --- a/sway/config.c +++ b/sway/config.c @@ -9,6 +9,7 @@ #include "commands.h" #include "config.h" #include "layout.h" +#include "input_state.h" struct sway_config *config; @@ -147,6 +148,8 @@ _continue: bool load_config(const char *file) { sway_log(L_INFO, "Loading config"); + input_init(); + char *path; if (file != NULL) { path = strdup(file); diff --git a/sway/input_state.c b/sway/input_state.c index a7f88d4a6..7f312c540 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -8,6 +8,13 @@ static keycode key_state_array[KEY_STATE_MAX_LENGTH]; +void input_init(void) { + int i; + for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { + key_state_array[i] = 0; + } +} + static uint8_t find_key(keycode key) { int i; for (i = 0; i < KEY_STATE_MAX_LENGTH; ++i) { From 68213d57c5c758d05582ef8a9f0db226ddbaefc7 Mon Sep 17 00:00:00 2001 From: Half-Shot Date: Thu, 20 Aug 2015 22:29:36 +0100 Subject: [PATCH 13/23] Fixed style errors --- sway/commands.c | 8 +++----- sway/layout.c | 14 +++++++------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index 5d79104f6..af4cd56f1 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -206,7 +206,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { if (!view->is_floating) { // Remove view from its current location destroy_container(remove_child(view)); - + // and move it into workspace floating add_floating(active_workspace,view); view->x = (active_workspace->width - view->width)/2; @@ -356,11 +356,9 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) { move_container(view,&root_container,MOVE_UP); } else if (strcasecmp(argv[0], "down") == 0) { move_container(view,&root_container,MOVE_DOWN); - } else - { + } else { return false; } - return true; } @@ -606,7 +604,7 @@ static struct cmd_handler handlers[] = { { "kill", cmd_kill }, { "layout", cmd_layout }, { "log_colors", cmd_log_colors }, - { "move",cmd_move}, + { "move", cmd_move}, { "reload", cmd_reload }, { "set", cmd_set }, { "split", cmd_split }, diff --git a/sway/layout.c b/sway/layout.c index 0c1f736d9..a75367275 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -118,34 +118,34 @@ void move_container(swayc_t *container,swayc_t* root,enum movement_direction dir //Rearrange for (i = 0; i < clength; ++i) { swayc_t *child = root->children->items[i]; - if(child->handle == container->handle){ - if(clength == 1){ + if (child->handle == container->handle){ + if (clength == 1){ //Only one container, meh. break; } - if(direction == MOVE_LEFT && i > 0){ + if (direction == MOVE_LEFT && i > 0){ temp = root->children->items[i-1]; root->children->items[i] = temp; root->children->items[i-1] = container; arrange_windows(&root_container,-1,-1); } - else if(direction == MOVE_RIGHT && i < clength-1){ + else if (direction == MOVE_RIGHT && i < clength-1){ temp = root->children->items[i+1]; root->children->items[i] = temp; root->children->items[i+1] = container; arrange_windows(&root_container,-1,-1); } - else if(direction == MOVE_UP){ + else if (direction == MOVE_UP){ sway_log(L_INFO, "Moving up not implemented"); } - else if(direction == MOVE_DOWN){ + else if (direction == MOVE_DOWN){ sway_log(L_INFO, "Moving down not implemented"); } break; } - else if(child->children != NULL){ + else if (child->children != NULL){ move_container(container,child,direction); } } From f589731f2912660bab6fdffc14ddcdbac3edd41c Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 20 Aug 2015 21:37:59 -0500 Subject: [PATCH 14/23] Rewrite of resize command to make it more sane --- include/container.h | 4 ++-- include/layout.h | 2 +- sway/commands.c | 53 ++++++++++++++++++++++++++------------------- sway/layout.c | 44 ++++++++++++++++++++----------------- sway/log.c | 4 ++-- 5 files changed, 60 insertions(+), 47 deletions(-) diff --git a/include/container.h b/include/container.h index bd92058d6..d3026011a 100644 --- a/include/container.h +++ b/include/container.h @@ -33,12 +33,12 @@ struct sway_container { enum swayc_layouts layout; // Not including borders or margins - int width, height; + double width, height; // Used for setting floating geometry int desired_width, desired_height; - int x, y; + double x, y; bool visible; bool is_floating; diff --git a/include/layout.h b/include/layout.h index 4dff81b7e..566e32465 100644 --- a/include/layout.h +++ b/include/layout.h @@ -29,6 +29,6 @@ swayc_t *get_focused_container(swayc_t *parent); swayc_t *get_swayc_for_handle(wlc_handle handle, swayc_t *parent); swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir); -void recursive_resize(swayc_t *container, double amount, enum movement_direction dir); +void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge); #endif diff --git a/sway/commands.c b/sway/commands.c index 27dbb44b3..0f743b4e3 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -478,31 +478,37 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) { sibling = parent->parent->children->items[i]; if (sibling->x != focused->x) { if (sibling->x < parent->x) { - double pixels = -1 * (amount/lnumber); - if (lnumber) { - recursive_resize(sibling, pixels/2, MOVE_RIGHT); + double pixels = -1 * amount; + pixels /= lnumber; + if (rnumber) { + recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_RIGHT); } else { - recursive_resize(sibling, pixels, MOVE_RIGHT); + recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_RIGHT); } } else if (sibling->x > parent->x) { - double pixels = -1 * (amount/rnumber); - if (rnumber) { - recursive_resize(sibling, pixels/2, MOVE_LEFT); + double pixels = -1 * amount; + pixels /= rnumber; + if (lnumber) { + recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_LEFT); } else { - recursive_resize(sibling, pixels, MOVE_LEFT); + recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_LEFT); } } } else { if (rnumber != 0 && lnumber != 0) { - recursive_resize(parent, amount/2, MOVE_LEFT); - recursive_resize(parent, amount/2, MOVE_RIGHT); + double pixels = amount; + pixels /= 2; + recursive_resize(parent, pixels, WLC_RESIZE_EDGE_LEFT); + recursive_resize(parent, pixels, WLC_RESIZE_EDGE_RIGHT); } else if (rnumber) { - recursive_resize(parent, amount, MOVE_RIGHT); + recursive_resize(parent, amount, WLC_RESIZE_EDGE_RIGHT); } else if (lnumber) { - recursive_resize(parent, amount, MOVE_LEFT); + recursive_resize(parent, amount, WLC_RESIZE_EDGE_LEFT); } } } + // Recursive resize does not handle positions, let arrange_windows + // take care of that. arrange_windows(active_workspace, -1, -1); return true; } else if (strcmp(argv[1], "height") == 0) { @@ -535,28 +541,31 @@ static bool cmd_resize(struct sway_config *config, int argc, char **argv) { sibling = parent->parent->children->items[i]; if (sibling->y != focused->y) { if (sibling->y < parent->y) { - double pixels = -1 * (amount/bnumber); + double pixels = -1 * amount; + pixels /= bnumber; if (tnumber) { - recursive_resize(sibling, pixels/2, MOVE_UP); + recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_BOTTOM); } else { - recursive_resize(sibling, pixels, MOVE_UP); + recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_BOTTOM); } } else if (sibling->x > parent->x) { - double pixels = -1 * (amount/tnumber); + double pixels = -1 * amount; + pixels /= tnumber; if (bnumber) { - recursive_resize(sibling, pixels/2, MOVE_DOWN); + recursive_resize(sibling, pixels/2, WLC_RESIZE_EDGE_TOP); } else { - recursive_resize(sibling, pixels, MOVE_DOWN); + recursive_resize(sibling, pixels, WLC_RESIZE_EDGE_TOP); } } } else { if (bnumber != 0 && tnumber != 0) { - recursive_resize(parent, amount/2, MOVE_UP); - recursive_resize(parent, amount/2, MOVE_DOWN); + double pixels = amount/2; + recursive_resize(parent, pixels, WLC_RESIZE_EDGE_TOP); + recursive_resize(parent, pixels, WLC_RESIZE_EDGE_BOTTOM); } else if (tnumber) { - recursive_resize(parent, amount, MOVE_UP); + recursive_resize(parent, amount, WLC_RESIZE_EDGE_TOP); } else if (bnumber) { - recursive_resize(parent, amount, MOVE_DOWN); + recursive_resize(parent, amount, WLC_RESIZE_EDGE_BOTTOM); } } } diff --git a/sway/layout.c b/sway/layout.c index c9c8fa7f7..50e7b5925 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -29,7 +29,7 @@ static int index_child(swayc_t *parent, swayc_t *child) { } void add_child(swayc_t *parent, swayc_t *child) { - sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, + sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, child->width, child->height, parent, parent->type, parent->width, parent->height); list_add(parent->children, child); child->parent = parent; @@ -40,7 +40,7 @@ void add_child(swayc_t *parent, swayc_t *child) { } void add_floating(swayc_t *ws, swayc_t *child) { - sway_log(L_DEBUG, "Adding %p (%d, %dx%d) to %p (%d, %dx%d)", child, child->type, + sway_log(L_DEBUG, "Adding %p (%d, %fx%f) to %p (%d, %fx%f)", child, child->type, child->width, child->height, ws, ws->type, ws->width, ws->height); list_add(ws->floating, child); child->parent = ws; @@ -144,7 +144,7 @@ void arrange_windows(swayc_t *container, int width, int height) { child->y = y + container->gaps; child->width = width - container->gaps * 2; child->height = height - container->gaps * 2; - sway_log(L_DEBUG, "Arranging workspace #%d at %d, %d", i, child->x, child->y); + sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y); arrange_windows(child, -1, -1); } return; @@ -193,7 +193,7 @@ void arrange_windows(swayc_t *container, int width, int height) { default: // Calculate total width for (i = 0; i < container->children->length; ++i) { - int *old_width = &((swayc_t *)container->children->items[i])->width; + double *old_width = &((swayc_t *)container->children->items[i])->width; if (*old_width <= 0) { if (container->children->length > 1) { *old_width = width / (container->children->length - 1); @@ -220,7 +220,7 @@ void arrange_windows(swayc_t *container, int width, int height) { case L_VERT: // Calculate total height for (i = 0; i < container->children->length; ++i) { - int *old_height = &((swayc_t *)container->children->items[i])->height; + double *old_height = &((swayc_t *)container->children->items[i])->height; if (*old_height <= 0) { if (container->children->length > 1) { *old_height = height / (container->children->length - 1); @@ -371,34 +371,38 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) } } -void recursive_resize(swayc_t *container, double amount, enum movement_direction dir) { +void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge edge) { int i; bool layout_match = true; - if (dir == MOVE_LEFT) { - container->x += (int) amount; - container->width += (int) amount; + sway_log(L_DEBUG, "Resizing %p with amount: %f", container, amount); + if (edge == WLC_RESIZE_EDGE_LEFT || edge == WLC_RESIZE_EDGE_RIGHT) { + container->width += amount; layout_match = container->layout == L_HORIZ; - } else if (dir == MOVE_RIGHT) { - container->width += (int) amount; - layout_match = container->layout == L_HORIZ; - } else if (dir == MOVE_UP) { - container->y += (int) amount; - container->height += (int) amount; - layout_match = container->layout == L_VERT; - } else if (dir == MOVE_DOWN) { - container->height += (int) amount; + } else if (edge == WLC_RESIZE_EDGE_TOP || edge == WLC_RESIZE_EDGE_BOTTOM) { + container->height += amount; layout_match = container->layout == L_VERT; } if (container->type == C_VIEW) { + struct wlc_geometry geometry = { + .origin = { + .x = container->x + container->gaps / 2, + .y = container->y + container->gaps / 2 + }, + .size = { + .w = container->width - container->gaps, + .h = container->height - container->gaps + } + }; + wlc_view_set_geometry(container->handle, edge, &geometry); return; } if (layout_match) { for (i = 0; i < container->children->length; i++) { - recursive_resize(container->children->items[i], amount/container->children->length, dir); + recursive_resize(container->children->items[i], amount/container->children->length, edge); } } else { for (i = 0; i < container->children->length; i++) { - recursive_resize(container->children->items[i], amount, dir); + recursive_resize(container->children->items[i], amount, edge); } } } diff --git a/sway/log.c b/sway/log.c index 6e01421bc..eda0c88ee 100644 --- a/sway/log.c +++ b/sway/log.c @@ -142,8 +142,8 @@ static void container_log(const swayc_t *c) { c->layout == L_STACKED ? "Stacked|": c->layout == L_FLOATING ? "Floating|": "Unknown|"); - fprintf(stderr, "w:%d|h:%d|", c->width, c->height); - fprintf(stderr, "x:%d|y:%d|", c->x, c->y); + fprintf(stderr, "w:%f|h:%f|", c->width, c->height); + fprintf(stderr, "x:%f|y:%f|", c->x, c->y); fprintf(stderr, "vis:%c|", c->visible?'t':'f'); fprintf(stderr, "name:%.16s|", c->name); fprintf(stderr, "children:%d\n",c->children?c->children->length:0); From 461da7f87fa970ce4ba1a124e6197554c85d42e5 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Fri, 21 Aug 2015 00:17:26 -0500 Subject: [PATCH 15/23] Added in bspwm like mouse resizing --- include/input_state.h | 3 ++ include/layout.h | 2 +- sway/handlers.c | 109 ++++++++++++++++++++++++++++++++++++---- sway/input_state.c | 3 +- sway/layout.c | 6 +-- sway/type | 113 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 221 insertions(+), 15 deletions(-) create mode 100644 sway/type diff --git a/include/input_state.h b/include/input_state.h index 782b4b19c..711ad6338 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -34,6 +34,9 @@ extern struct pointer_state { bool drag; bool resize; } floating; + struct pointer_tiling { + bool resize; + } tiling; struct pointer_lock { bool left; bool right; diff --git a/include/layout.h b/include/layout.h index 566e32465..20044b953 100644 --- a/include/layout.h +++ b/include/layout.h @@ -18,7 +18,7 @@ swayc_t *replace_child(swayc_t *child, swayc_t *new_child); swayc_t *remove_child(swayc_t *child); // Layout -void arrange_windows(swayc_t *container, int width, int height); +void arrange_windows(swayc_t *container, double width, double height); // Focus void unfocus_all(swayc_t *container); diff --git a/sway/handlers.c b/sway/handlers.c index 5993223d3..a71328e3d 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -351,7 +352,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct return false; } // Do checks to determine if proper keys are being held - swayc_t *view = get_focused_view(active_workspace); + swayc_t *view = container_under_pointer(); uint32_t edge = 0; if (pointer_state.floating.drag && view) { if (view->is_floating) { @@ -426,6 +427,91 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } } + } + } else if (pointer_state.tiling.resize && view) { + if (!view->is_floating) { + // Handle layout resizes -- Find the biggest parent container then apply resizes to that + // and its bordering siblings + swayc_t *parent = view; + double dx = mouse_origin.x - prev_pos.x; + double dy = mouse_origin.y - prev_pos.y; + if (pointer_state.lock.top) { + while (parent->type != C_WORKSPACE) { + // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better + // way of doing this. + if (fabs(parent->parent->y + parent->parent->height - (view->y + view->height)) <= 1) { + parent = parent->parent; + } else { + break; + } + } + if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { + sway_log(L_DEBUG, "Top is locked, found biggest valid parent at: %p", parent); + swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN); + if (sibling) { + sway_log(L_DEBUG, "Found sibling at: %p", sibling); + recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); + recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); + } + } + } else { + while (parent->type != C_WORKSPACE) { + if (fabs(parent->parent->y - view->y) <= 1) { + parent = parent->parent; + } else { + break; + } + } + if (parent->parent->children->length > 1 && parent->parent->layout == L_VERT) { + sway_log(L_DEBUG, "Bot is locked, found biggest valid parent at: %p", parent); + swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP); + if (sibling) { + sway_log(L_DEBUG, "Found sibling at: %p", sibling); + recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); + recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); + } + } + } + + parent = view; + if (pointer_state.lock.left) { + while (parent->type != C_WORKSPACE) { + if (fabs(parent->parent->x + parent->parent->width - (view->x + view->width)) <= 1) { + parent = parent->parent; + } else { + sway_log(L_DEBUG, "view: %f vs parent: %f", view->x + view->width, parent->parent->x + parent->parent->width); + break; + } + } + sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent); + if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { + sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent); + swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT); + if (sibling) { + sway_log(L_DEBUG, "Found sibling at: %p", sibling); + recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); + recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); + } + } + } else { + while (parent->type != C_WORKSPACE) { + if (fabs(parent->parent->x - view->x) <= 1 && parent->parent) { + parent = parent->parent; + } else { + break; + } + } + if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { + sway_log(L_DEBUG, "Right is locked, found biggest valid parent at: %p", parent); + swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT); + if (sibling) { + sway_log(L_DEBUG, "Found sibling at: %p", sibling); + recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); + recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); + } + } + } + arrange_windows(active_workspace, -1, -1); } } if (config->focus_follows_mouse && prev_handle != handle) { @@ -472,7 +558,16 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w pointer_state.r_held = true; } swayc_t *pointer = container_under_pointer(); - set_focused_container(pointer); + if (pointer) { + set_focused_container(pointer); + int midway_x = pointer->x + pointer->width/2; + int midway_y = pointer->y + pointer->height/2; + pointer_state.lock.bottom = origin->y < midway_y; + pointer_state.lock.top = !pointer_state.lock.bottom; + pointer_state.lock.right = origin->x < midway_x; + pointer_state.lock.left = !pointer_state.lock.right; + } + if (pointer->is_floating) { int i; for (i = 0; i < pointer->parent->floating->length; i++) { @@ -484,19 +579,14 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w } arrange_windows(pointer->parent, -1, -1); if (modifiers->mods & config->floating_mod) { - int midway_x = pointer->x + pointer->width/2; - int midway_y = pointer->y + pointer->height/2; - pointer_state.floating.drag = pointer_state.l_held; pointer_state.floating.resize = pointer_state.r_held; - pointer_state.lock.bottom = origin->y < midway_y; - pointer_state.lock.top = !pointer_state.lock.bottom; - pointer_state.lock.right = origin->x < midway_x; - pointer_state.lock.left = !pointer_state.lock.right; start_floating(pointer); } // Dont want pointer sent to window while dragging or resizing return (pointer_state.floating.drag || pointer_state.floating.resize); + } else { + pointer_state.tiling.resize = pointer_state.r_held; } return (pointer && pointer != focused); } else { @@ -508,6 +598,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w if (button == M_RIGHT_CLICK) { pointer_state.r_held = false; pointer_state.floating.resize = false; + pointer_state.tiling.resize = false; pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; } } diff --git a/sway/input_state.c b/sway/input_state.c index a7f88d4a6..e592cfc15 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -41,7 +41,7 @@ void release_key(keycode key) { } } -struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, 0, 0}}; +struct pointer_state pointer_state = {0, 0, {0, 0}, {0}, {0, 0, 0, 0}}; static struct wlc_geometry saved_floating; @@ -65,4 +65,3 @@ void reset_floating(swayc_t *view) { pointer_state.floating = (struct pointer_floating){0,0}; pointer_state.lock = (struct pointer_lock){0,0,0,0}; } - diff --git a/sway/layout.c b/sway/layout.c index 50e7b5925..12b279876 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -109,7 +109,7 @@ swayc_t *remove_child(swayc_t *child) { } -void arrange_windows(swayc_t *container, int width, int height) { +void arrange_windows(swayc_t *container, double width, double height) { int i; if (width == -1 || height == -1) { sway_log(L_DEBUG, "Arranging layout for %p", container); @@ -209,7 +209,7 @@ void arrange_windows(swayc_t *container, int width, int height) { sway_log(L_DEBUG, "Arranging %p horizontally", container); for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; - sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, width, scale); + sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); child->x = x + container->x; child->y = y + container->y; arrange_windows(child, child->width * scale, height); @@ -236,7 +236,7 @@ void arrange_windows(swayc_t *container, int width, int height) { sway_log(L_DEBUG, "Arranging %p vertically", container); for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; - sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %d by %f)", child, child->type, height, scale); + sway_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); child->x = x + container->x; child->y = y + container->y; arrange_windows(child, width, child->height * scale); diff --git a/sway/type b/sway/type new file mode 100644 index 000000000..c7bebe5e4 --- /dev/null +++ b/sway/type @@ -0,0 +1,113 @@ +workspace.c:78:9: while (parent->type != C_OUTPUT) { +workspace.c:79:12: parent = parent->parent; + +focus.c:16:6: if (parent->focused != c) { +focus.c:30:8: if (parent->focused) { +focus.c:31:19: swayc_t *ws = parent->focused; +focus.c:38:25: wlc_output_set_mask(parent->handle, 2); +focus.c:39:8: c->parent->focused = c; +focus.c:53:5: c->parent->focused = c; +focus.c:71:20: while (parent && !parent->is_focused) { +focus.c:72:12: parent = parent->focused; +focus.c:143:13: if (find->parent->focused != find) { +focus.c:167:19: while (parent && parent->type != C_VIEW) { +focus.c:168:7: if (parent->type == C_WORKSPACE && parent->focused == NULL) { +focus.c:171:12: parent = parent->focused; + +handlers.c:24:9: while (parent->type != C_OUTPUT) { +handlers.c:25:12: parent = parent->parent; +handlers.c:436:18: while (parent->parent && parent->y + parent->height == view->y + view->height && parent->type != L_WORKSPACE) { +handlers.c:437:30: parent = parent->parent; +handlers.c:440:50: if (parent == &root_container || parent->children->length == 1) { +handlers.c:444:18: while (parent->parent && parent->y == view->y) { +handlers.c:445:30: parent = parent->parent; +handlers.c:448:50: if (parent == &root_container || parent->children->length == 1) { +handlers.c:454:18: while (parent->parent && parent->x + parent->width == view->x + view->width) { +handlers.c:455:30: parent = parent->parent; +handlers.c:458:50: if (parent == &root_container || parent->children->length == 1) { +handlers.c:462:18: while (parent->parent && parent->x + parent->width == view->x) { +handlers.c:463:30: parent = parent->parent; +handlers.c:466:50: if (parent == &root_container || parent->children->length == 1) { +handlers.c:528:29: for (i = 0; i < pointer->parent->floating->length; i++) { +handlers.c:529:18: if (pointer->parent->floating->items[i] == pointer) { +handlers.c:530:24: list_del(pointer->parent->floating, i); +handlers.c:531:24: list_add(pointer->parent->floating, pointer); + +container.c:284:6: if (parent->type == C_CONTAINER) { + +layout.c:23:18: for (i = 0; i < parent->children->length; ++i) { +layout.c:24:7: if (parent->children->items[i] == child) { +layout.c:33:40: child->width, child->height, parent, parent->type, parent->width, parent->height); +layout.c:34:11: list_add(parent->children, child); +layout.c:37:6: if (parent->children->length == 1) { +layout.c:56:11: if (i == parent->children->length) { +layout.c:59:14: list_insert(parent->children, i+1, child); +layout.c:70:2: parent->children->items[i] = new_child; +layout.c:73:13: if (child->parent->focused == child) { +layout.c:85:19: for (i = 0; i < parent->floating->length; ++i) { +layout.c:86:8: if (parent->floating->items[i] == child) { +layout.c:87:14: list_del(parent->floating, i); +layout.c:93:19: for (i = 0; i < parent->children->length; ++i) { +layout.c:94:8: if (parent->children->items[i] == child) { +layout.c:95:14: list_del(parent->children, i); +layout.c:101:6: if (parent->focused == child) { +layout.c:102:7: if (parent->children->length > 0) { +layout.c:103:38: set_focused_container_for(parent, parent->children->items[i?i-1:0]); +layout.c:105:4: parent->focused = NULL; +layout.c:165:12: while (parent->type != C_OUTPUT) { +layout.c:166:15: parent = parent->parent; +layout.c:170:23: geometry.size.w = parent->width; +layout.c:171:23: geometry.size.h = parent->height; +layout.c:267:13: while (parent->type != C_OUTPUT) { +layout.c:268:16: parent = parent->parent; +layout.c:272:24: geometry.size.w = parent->width; +layout.c:273:24: geometry.size.h = parent->height; +layout.c:294:6: if (parent->children == NULL) { +layout.c:300:6: if (parent->type == C_WORKSPACE) { +layout.c:301:19: for (i = 0; i < parent->floating->length; ++i) { +layout.c:302:21: swayc_t *child = parent->floating->items[i]; +layout.c:309:18: for (i = 0; i < parent->children->length; ++i) { +layout.c:310:20: swayc_t *child = parent->children->items[i]; +layout.c:327:7: if (parent->type == C_OUTPUT) { +layout.c:338:8: if (parent->layout == L_HORIZ || parent->type == C_ROOT) { +layout.c:343:8: if (parent->layout == L_VERT) { +layout.c:350:20: for (i = 0; i < parent->children->length; ++i) { +layout.c:351:22: swayc_t *child = parent->children->items[i]; +layout.c:357:34: if (desired < 0 || desired >= parent->children->length) { +layout.c:360:12: return parent->children->items[desired]; +layout.c:365:13: parent = parent->parent; + +commands.c:394:9: while (parent->type == C_VIEW) { +commands.c:395:12: parent = parent->parent; +commands.c:399:3: parent->layout = L_HORIZ; +commands.c:401:3: parent->layout = L_VERT; +commands.c:403:7: if (parent->layout == L_VERT) { +commands.c:404:4: parent->layout = L_HORIZ; +commands.c:406:4: parent->layout = L_VERT; +commands.c:409:26: arrange_windows(parent, parent->width, parent->height); +commands.c:454:10: while (parent->parent) { +commands.c:455:8: if (parent->parent->layout == L_HORIZ) { +commands.c:456:21: for (i = 0; i < parent->parent->children->length; i++) { +commands.c:457:16: sibling = parent->parent->children->items[i]; +commands.c:459:24: if (sibling->x < parent->x) { +commands.c:461:31: } else if (sibling->x > parent->x) { +commands.c:470:13: parent = parent->parent; +commands.c:475:87: sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber); +commands.c:477:19: for (i = 0; i < parent->parent->children->length; i++) { +commands.c:478:14: sibling = parent->parent->children->items[i]; +commands.c:480:22: if (sibling->x < parent->x) { +commands.c:488:29: } else if (sibling->x > parent->x) { +commands.c:517:10: while (parent->parent) { +commands.c:518:8: if (parent->parent->layout == L_VERT) { +commands.c:519:21: for (i = 0; i < parent->parent->children->length; i++) { +commands.c:520:16: sibling = parent->parent->children->items[i]; +commands.c:522:24: if (sibling->y < parent->y) { +commands.c:524:31: } else if (sibling->y > parent->y) { +commands.c:533:13: parent = parent->parent; +commands.c:538:87: sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber); +commands.c:540:19: for (i = 0; i < parent->parent->children->length; i++) { +commands.c:541:14: sibling = parent->parent->children->items[i]; +commands.c:543:22: if (sibling->y < parent->y) { +commands.c:551:29: } else if (sibling->x > parent->x) { +commands.c:603:54: } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { +commands.c:606:12: focused->parent->layout = layout; From 96ab21b2766096bdb42d79a0169d42b9ff00e2fb Mon Sep 17 00:00:00 2001 From: Luminarys Date: Fri, 21 Aug 2015 00:49:47 -0500 Subject: [PATCH 16/23] Fixes to resizing and added in resize lock once boundaries are exceeded --- include/input_state.h | 1 + sway/handlers.c | 45 +++++++++++++++++++++++++++++++------------ sway/log.c | 1 + 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/include/input_state.h b/include/input_state.h index 711ad6338..7119c68b9 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -36,6 +36,7 @@ extern struct pointer_state { } floating; struct pointer_tiling { bool resize; + swayc_t *init_view; } tiling; struct pointer_lock { bool left; diff --git a/sway/handlers.c b/sway/handlers.c index a71328e3d..571dd2a69 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -348,6 +348,9 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct static wlc_handle prev_handle = 0; mouse_origin = *origin; bool changed_floating = false; + bool changed_tiling = false; + int min_sane_w = 100; + int min_sane_h = 60; if (!active_workspace) { return false; } @@ -366,8 +369,6 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct if (view->is_floating) { int dx = mouse_origin.x - prev_pos.x; int dy = mouse_origin.y - prev_pos.y; - int min_sane_w = 100; - int min_sane_h = 60; // Move and resize the view based on the dx/dy and mouse position int midway_x = view->x + view->width/2; @@ -429,7 +430,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } } else if (pointer_state.tiling.resize && view) { - if (!view->is_floating) { + if (view != pointer_state.tiling.init_view) { + // Quit out of the resize + pointer_state.tiling.init_view = NULL; + } + if (!view->is_floating && view == pointer_state.tiling.init_view) { // Handle layout resizes -- Find the biggest parent container then apply resizes to that // and its bordering siblings swayc_t *parent = view; @@ -450,8 +455,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct swayc_t *sibling = get_swayc_in_direction(parent, MOVE_DOWN); if (sibling) { sway_log(L_DEBUG, "Found sibling at: %p", sibling); - recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); - recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); + if ((parent->height > min_sane_h || dy > 0) && (sibling->height > min_sane_h || dy < 0)) { + recursive_resize(parent, dy, WLC_RESIZE_EDGE_BOTTOM); + recursive_resize(sibling, -1 * dy, WLC_RESIZE_EDGE_TOP); + changed_tiling = true; + } } } } else { @@ -467,8 +475,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct swayc_t *sibling = get_swayc_in_direction(parent, MOVE_UP); if (sibling) { sway_log(L_DEBUG, "Found sibling at: %p", sibling); - recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); - recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); + if ((parent->height > min_sane_h || dy < 0) && (sibling->height > min_sane_h || dy > 0)) { + recursive_resize(parent, -1 * dy, WLC_RESIZE_EDGE_TOP); + recursive_resize(sibling, dy, WLC_RESIZE_EDGE_BOTTOM); + changed_tiling = true; + } } } } @@ -483,14 +494,16 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct break; } } - sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent); if (parent->parent->children->length > 1 && parent->parent->layout == L_HORIZ) { sway_log(L_DEBUG, "Left is locked, found biggest valid parent at: %p", parent); swayc_t *sibling = get_swayc_in_direction(parent, MOVE_RIGHT); if (sibling) { sway_log(L_DEBUG, "Found sibling at: %p", sibling); - recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); - recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); + if ((parent->width > min_sane_w || dx > 0) && (sibling->width > min_sane_w || dx < 0)) { + recursive_resize(parent, dx, WLC_RESIZE_EDGE_RIGHT); + recursive_resize(sibling, -1 * dx, WLC_RESIZE_EDGE_LEFT); + changed_tiling = true; + } } } } else { @@ -506,8 +519,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct swayc_t *sibling = get_swayc_in_direction(parent, MOVE_LEFT); if (sibling) { sway_log(L_DEBUG, "Found sibling at: %p", sibling); - recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); - recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); + if ((parent->width > min_sane_w || dx < 0) && (sibling->width > min_sane_w || dx > 0)) { + recursive_resize(parent, -1 * dx, WLC_RESIZE_EDGE_LEFT); + recursive_resize(sibling, dx, WLC_RESIZE_EDGE_RIGHT); + changed_tiling = true; + } } } } @@ -538,6 +554,9 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct wlc_view_set_geometry(view->handle, edge, &geometry); return true; } + if (changed_tiling) { + return true; + } return false; } @@ -587,6 +606,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w return (pointer_state.floating.drag || pointer_state.floating.resize); } else { pointer_state.tiling.resize = pointer_state.r_held; + pointer_state.tiling.init_view = pointer; } return (pointer && pointer != focused); } else { @@ -599,6 +619,7 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w pointer_state.r_held = false; pointer_state.floating.resize = false; pointer_state.tiling.resize = false; + pointer_state.tiling.init_view = NULL; pointer_state.lock = (struct pointer_lock){false ,false ,false ,false}; } } diff --git a/sway/log.c b/sway/log.c index eda0c88ee..21aa9b8e3 100644 --- a/sway/log.c +++ b/sway/log.c @@ -149,6 +149,7 @@ static void container_log(const swayc_t *c) { fprintf(stderr, "children:%d\n",c->children?c->children->length:0); } void layout_log(const swayc_t *c, int depth) { + if (L_DEBUG > v) return; int i, d; int e = c->children ? c->children->length : 0; container_log(c); From 0266b0666a837db946bc9bbb599136da0b569320 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 21 Aug 2015 07:15:00 -0400 Subject: [PATCH 17/23] Fix compiler warnings (which were really errors) --- sway/ipc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/ipc.c b/sway/ipc.c index 39e580cd7..63117defc 100644 --- a/sway/ipc.c +++ b/sway/ipc.c @@ -288,7 +288,7 @@ void ipc_get_workspaces_callback(swayc_t *container, void *data) { "\"urgent\":%s" "}", num, container->name, container->visible ? "true" : "false", container->is_focused ? "true" : "false", - container->x, container->y, container->width, container->height, + (int)container->x, (int)container->y, (int)container->width, (int)container->height, container->parent->name, "false" // TODO: urgent hint ); list_add((list_t *)data, json); @@ -313,7 +313,7 @@ void ipc_get_outputs_callback(swayc_t *container, void *data) { "\"current_workspace\":\"%s\"" "}", container->name, "true", "false", // TODO: active, primary - container->x, container->y, container->width, container->height, + (int)container->x, (int)container->y, (int)container->width, (int)container->height, container->focused ? container->focused->name : "" ); list_add((list_t *)data, json); From 1c4b50894c2a7c5ef8d60a6661ecf73fc4744ba8 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 21 Aug 2015 08:12:56 -0400 Subject: [PATCH 18/23] Use $term in default config --- config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config b/config index 1e94973cb..7e34c0b90 100644 --- a/config +++ b/config @@ -22,7 +22,7 @@ set $menu dmenu_run # Basics: # # start a terminal - bindsym $mod+Return exec urxvt + bindsym $mod+Return exec $term # kill focused window bindsym $mod+Shift+q kill From 6278922f7afd077bb679a9bb225b45a35f57159e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 21 Aug 2015 08:24:48 -0400 Subject: [PATCH 19/23] Fix clang warnings These particular warnings have always struck me as stupid --- sway/log.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sway/log.c b/sway/log.c index 21aa9b8e3..e0734109e 100644 --- a/sway/log.c +++ b/sway/log.c @@ -54,7 +54,7 @@ void sway_log(int verbosity, const char* format, ...) { } if (colored) { - fprintf(stderr, verbosity_colors[c]); + fprintf(stderr, "%s", verbosity_colors[c]); } va_list args; @@ -77,7 +77,7 @@ void sway_log_errno(int verbosity, char* format, ...) { } if (colored) { - fprintf(stderr, verbosity_colors[c]); + fprintf(stderr, "%s", verbosity_colors[c]); } va_list args; @@ -88,7 +88,7 @@ void sway_log_errno(int verbosity, char* format, ...) { fprintf(stderr, ": "); char error[256]; strerror_r(errno, error, sizeof(error)); - fprintf(stderr, error); + fprintf(stderr, "%s", error); if (colored) { fprintf(stderr, "\x1B[0m"); From de86c5f4ea20d005a1f5512406725fb44827e339 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Fri, 21 Aug 2015 09:24:26 -0500 Subject: [PATCH 20/23] Cleanup and minor fixes --- include/input_state.h | 1 + sway/handlers.c | 12 ++--- sway/input_state.c | 2 +- sway/type | 113 ------------------------------------------ 4 files changed, 8 insertions(+), 120 deletions(-) delete mode 100644 sway/type diff --git a/include/input_state.h b/include/input_state.h index 27dd6cff9..528d5e123 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -37,6 +37,7 @@ extern struct pointer_state { struct pointer_tiling { bool resize; swayc_t *init_view; + wlc_origin *lock_pos; } tiling; struct pointer_lock { bool left; diff --git a/sway/handlers.c b/sway/handlers.c index 53eae4397..78f8927da 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -419,11 +419,11 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } } - } + } } else if (pointer_state.tiling.resize && view) { if (view != pointer_state.tiling.init_view) { // Quit out of the resize - pointer_state.tiling.init_view = NULL; + //pointer_state.tiling.init_view = NULL; } if (!view->is_floating && view == pointer_state.tiling.init_view) { // Handle layout resizes -- Find the biggest parent container then apply resizes to that @@ -431,7 +431,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct swayc_t *parent = view; double dx = mouse_origin.x - prev_pos.x; double dy = mouse_origin.y - prev_pos.y; - if (pointer_state.lock.top) { + if (!pointer_state.lock.bottom) { while (parent->type != C_WORKSPACE) { // TODO: Absolute value is a bad hack here to compensate for rounding. Find a better // way of doing this. @@ -453,7 +453,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } } - } else { + } else if (!pointer_state.lock.top) { while (parent->type != C_WORKSPACE) { if (fabs(parent->parent->y - view->y) <= 1) { parent = parent->parent; @@ -476,7 +476,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } parent = view; - if (pointer_state.lock.left) { + if (!pointer_state.lock.right) { while (parent->type != C_WORKSPACE) { if (fabs(parent->parent->x + parent->parent->width - (view->x + view->width)) <= 1) { parent = parent->parent; @@ -497,7 +497,7 @@ static bool handle_pointer_motion(wlc_handle handle, uint32_t time, const struct } } } - } else { + } else if (!pointer_state.lock.left) { while (parent->type != C_WORKSPACE) { if (fabs(parent->parent->x - view->x) <= 1 && parent->parent) { parent = parent->parent; diff --git a/sway/input_state.c b/sway/input_state.c index ef5d6df07..28a8b2f00 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -48,7 +48,7 @@ void release_key(keycode key) { } } -struct pointer_state pointer_state = {0, 0, {0, 0}, {0}, {0, 0, 0, 0}}; +struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0}, {0, 0, 0, 0}}; static struct wlc_geometry saved_floating; diff --git a/sway/type b/sway/type deleted file mode 100644 index c7bebe5e4..000000000 --- a/sway/type +++ /dev/null @@ -1,113 +0,0 @@ -workspace.c:78:9: while (parent->type != C_OUTPUT) { -workspace.c:79:12: parent = parent->parent; - -focus.c:16:6: if (parent->focused != c) { -focus.c:30:8: if (parent->focused) { -focus.c:31:19: swayc_t *ws = parent->focused; -focus.c:38:25: wlc_output_set_mask(parent->handle, 2); -focus.c:39:8: c->parent->focused = c; -focus.c:53:5: c->parent->focused = c; -focus.c:71:20: while (parent && !parent->is_focused) { -focus.c:72:12: parent = parent->focused; -focus.c:143:13: if (find->parent->focused != find) { -focus.c:167:19: while (parent && parent->type != C_VIEW) { -focus.c:168:7: if (parent->type == C_WORKSPACE && parent->focused == NULL) { -focus.c:171:12: parent = parent->focused; - -handlers.c:24:9: while (parent->type != C_OUTPUT) { -handlers.c:25:12: parent = parent->parent; -handlers.c:436:18: while (parent->parent && parent->y + parent->height == view->y + view->height && parent->type != L_WORKSPACE) { -handlers.c:437:30: parent = parent->parent; -handlers.c:440:50: if (parent == &root_container || parent->children->length == 1) { -handlers.c:444:18: while (parent->parent && parent->y == view->y) { -handlers.c:445:30: parent = parent->parent; -handlers.c:448:50: if (parent == &root_container || parent->children->length == 1) { -handlers.c:454:18: while (parent->parent && parent->x + parent->width == view->x + view->width) { -handlers.c:455:30: parent = parent->parent; -handlers.c:458:50: if (parent == &root_container || parent->children->length == 1) { -handlers.c:462:18: while (parent->parent && parent->x + parent->width == view->x) { -handlers.c:463:30: parent = parent->parent; -handlers.c:466:50: if (parent == &root_container || parent->children->length == 1) { -handlers.c:528:29: for (i = 0; i < pointer->parent->floating->length; i++) { -handlers.c:529:18: if (pointer->parent->floating->items[i] == pointer) { -handlers.c:530:24: list_del(pointer->parent->floating, i); -handlers.c:531:24: list_add(pointer->parent->floating, pointer); - -container.c:284:6: if (parent->type == C_CONTAINER) { - -layout.c:23:18: for (i = 0; i < parent->children->length; ++i) { -layout.c:24:7: if (parent->children->items[i] == child) { -layout.c:33:40: child->width, child->height, parent, parent->type, parent->width, parent->height); -layout.c:34:11: list_add(parent->children, child); -layout.c:37:6: if (parent->children->length == 1) { -layout.c:56:11: if (i == parent->children->length) { -layout.c:59:14: list_insert(parent->children, i+1, child); -layout.c:70:2: parent->children->items[i] = new_child; -layout.c:73:13: if (child->parent->focused == child) { -layout.c:85:19: for (i = 0; i < parent->floating->length; ++i) { -layout.c:86:8: if (parent->floating->items[i] == child) { -layout.c:87:14: list_del(parent->floating, i); -layout.c:93:19: for (i = 0; i < parent->children->length; ++i) { -layout.c:94:8: if (parent->children->items[i] == child) { -layout.c:95:14: list_del(parent->children, i); -layout.c:101:6: if (parent->focused == child) { -layout.c:102:7: if (parent->children->length > 0) { -layout.c:103:38: set_focused_container_for(parent, parent->children->items[i?i-1:0]); -layout.c:105:4: parent->focused = NULL; -layout.c:165:12: while (parent->type != C_OUTPUT) { -layout.c:166:15: parent = parent->parent; -layout.c:170:23: geometry.size.w = parent->width; -layout.c:171:23: geometry.size.h = parent->height; -layout.c:267:13: while (parent->type != C_OUTPUT) { -layout.c:268:16: parent = parent->parent; -layout.c:272:24: geometry.size.w = parent->width; -layout.c:273:24: geometry.size.h = parent->height; -layout.c:294:6: if (parent->children == NULL) { -layout.c:300:6: if (parent->type == C_WORKSPACE) { -layout.c:301:19: for (i = 0; i < parent->floating->length; ++i) { -layout.c:302:21: swayc_t *child = parent->floating->items[i]; -layout.c:309:18: for (i = 0; i < parent->children->length; ++i) { -layout.c:310:20: swayc_t *child = parent->children->items[i]; -layout.c:327:7: if (parent->type == C_OUTPUT) { -layout.c:338:8: if (parent->layout == L_HORIZ || parent->type == C_ROOT) { -layout.c:343:8: if (parent->layout == L_VERT) { -layout.c:350:20: for (i = 0; i < parent->children->length; ++i) { -layout.c:351:22: swayc_t *child = parent->children->items[i]; -layout.c:357:34: if (desired < 0 || desired >= parent->children->length) { -layout.c:360:12: return parent->children->items[desired]; -layout.c:365:13: parent = parent->parent; - -commands.c:394:9: while (parent->type == C_VIEW) { -commands.c:395:12: parent = parent->parent; -commands.c:399:3: parent->layout = L_HORIZ; -commands.c:401:3: parent->layout = L_VERT; -commands.c:403:7: if (parent->layout == L_VERT) { -commands.c:404:4: parent->layout = L_HORIZ; -commands.c:406:4: parent->layout = L_VERT; -commands.c:409:26: arrange_windows(parent, parent->width, parent->height); -commands.c:454:10: while (parent->parent) { -commands.c:455:8: if (parent->parent->layout == L_HORIZ) { -commands.c:456:21: for (i = 0; i < parent->parent->children->length; i++) { -commands.c:457:16: sibling = parent->parent->children->items[i]; -commands.c:459:24: if (sibling->x < parent->x) { -commands.c:461:31: } else if (sibling->x > parent->x) { -commands.c:470:13: parent = parent->parent; -commands.c:475:87: sway_log(L_DEBUG, "Found the proper parent: %p. It has %d l conts, and %d r conts", parent->parent, lnumber, rnumber); -commands.c:477:19: for (i = 0; i < parent->parent->children->length; i++) { -commands.c:478:14: sibling = parent->parent->children->items[i]; -commands.c:480:22: if (sibling->x < parent->x) { -commands.c:488:29: } else if (sibling->x > parent->x) { -commands.c:517:10: while (parent->parent) { -commands.c:518:8: if (parent->parent->layout == L_VERT) { -commands.c:519:21: for (i = 0; i < parent->parent->children->length; i++) { -commands.c:520:16: sibling = parent->parent->children->items[i]; -commands.c:522:24: if (sibling->y < parent->y) { -commands.c:524:31: } else if (sibling->y > parent->y) { -commands.c:533:13: parent = parent->parent; -commands.c:538:87: sway_log(L_DEBUG, "Found the proper parent: %p. It has %d b conts, and %d t conts", parent->parent, bnumber, tnumber); -commands.c:540:19: for (i = 0; i < parent->parent->children->length; i++) { -commands.c:541:14: sibling = parent->parent->children->items[i]; -commands.c:543:22: if (sibling->y < parent->y) { -commands.c:551:29: } else if (sibling->x > parent->x) { -commands.c:603:54: } else if (focused->type != C_WORKSPACE && focused->parent->children->length == 1) { -commands.c:606:12: focused->parent->layout = layout; From 97bd548456f83420134c3316f56add2a8b6b2563 Mon Sep 17 00:00:00 2001 From: Luminarys Date: Fri, 21 Aug 2015 09:26:22 -0500 Subject: [PATCH 21/23] More minor fixes --- include/input_state.h | 2 +- sway/input_state.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/input_state.h b/include/input_state.h index 528d5e123..27a82809d 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -37,7 +37,7 @@ extern struct pointer_state { struct pointer_tiling { bool resize; swayc_t *init_view; - wlc_origin *lock_pos; + struct wlc_origin *lock_pos; } tiling; struct pointer_lock { bool left; diff --git a/sway/input_state.c b/sway/input_state.c index 28a8b2f00..5119930ad 100644 --- a/sway/input_state.c +++ b/sway/input_state.c @@ -48,7 +48,7 @@ void release_key(keycode key) { } } -struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0}, {0, 0, 0, 0}}; +struct pointer_state pointer_state = {0, 0, {0, 0}, {0, 0, 0}, {0, 0, 0, 0}}; static struct wlc_geometry saved_floating; From 7ecb55f218666ec5c30371eeb9e5982a487fdb4b Mon Sep 17 00:00:00 2001 From: Luminarys Date: Fri, 21 Aug 2015 09:29:52 -0500 Subject: [PATCH 22/23] Minor style fix --- include/input_state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/input_state.h b/include/input_state.h index 27a82809d..000996e0c 100644 --- a/include/input_state.h +++ b/include/input_state.h @@ -37,7 +37,7 @@ extern struct pointer_state { struct pointer_tiling { bool resize; swayc_t *init_view; - struct wlc_origin *lock_pos; + struct wlc_origin *lock_pos; } tiling; struct pointer_lock { bool left; From 8dfaf6265be52a582cc990f4332808d55063766f Mon Sep 17 00:00:00 2001 From: minus Date: Fri, 21 Aug 2015 16:53:11 +0200 Subject: [PATCH 23/23] fixed #108 signed/unsigned comparison --- CMakeLists.txt | 2 +- include/log.h | 6 +++--- sway/commands.c | 4 ++-- sway/config.c | 2 +- sway/ipc.c | 8 ++++++-- sway/layout.c | 2 +- sway/log.c | 12 ++++++------ 7 files changed, 20 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ed6fc02f..1365a9aee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 2.8.5) project(sway C) set(CMAKE_C_FLAGS "-g") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/") -add_definitions("-Wall") +add_definitions("-Wall -Wextra -Wno-unused-parameter") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMake) find_package(XKBCommon REQUIRED) diff --git a/include/log.h b/include/log.h index 47a83321d..3d77769c2 100644 --- a/include/log.h +++ b/include/log.h @@ -10,10 +10,10 @@ typedef enum { L_DEBUG = 3, } log_importance_t; -void init_log(int verbosity); +void init_log(log_importance_t verbosity); void sway_log_colors(int mode); -void sway_log(int verbosity, const char* format, ...) __attribute__((format(printf,2,3))); -void sway_log_errno(int verbosity, char* format, ...) __attribute__((format(printf,2,3))); +void sway_log(log_importance_t verbosity, const char* format, ...) __attribute__((format(printf,2,3))); +void sway_log_errno(log_importance_t verbosity, char* format, ...) __attribute__((format(printf,2,3))); void sway_abort(const char* format, ...) __attribute__((format(printf,1,2))); bool sway_assert(bool condition, const char* format, ...) __attribute__((format(printf,2,3))); diff --git a/sway/commands.c b/sway/commands.c index cb96703ed..e90a40a3a 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -106,7 +106,7 @@ static bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { // Check for a modifier key int j; bool is_mod = false; - for (j = 0; j < sizeof(modifiers) / sizeof(struct modifier_key); ++j) { + for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { binding->modifiers |= modifiers[j].mod; is_mod = true; @@ -261,7 +261,7 @@ static bool cmd_floating_mod(struct sway_config *config, int argc, char **argv) // set modifer keys for (i = 0; i < split->length; ++i) { - for (j = 0; j < sizeof(modifiers) / sizeof(struct modifier_key); ++j) { + for (j = 0; j < (int)(sizeof(modifiers) / sizeof(struct modifier_key)); ++j) { if (strcasecmp(modifiers[j].name, split->items[i]) == 0) { config->floating_mod |= modifiers[j].mod; } diff --git a/sway/config.c b/sway/config.c index 0afb02051..1ebd95ff8 100644 --- a/sway/config.c +++ b/sway/config.c @@ -107,7 +107,7 @@ static char *get_config_path() { char *test = NULL; int i; - for (i = 0; i < sizeof(search_paths) / sizeof(char *); ++i) { + for (i = 0; i < (int)(sizeof(search_paths) / sizeof(char *)); ++i) { test = strdup(search_paths[i]); test = do_var_replacement(temp_config, test); sway_log(L_DEBUG, "Checking for config at %s", test); diff --git a/sway/ipc.c b/sway/ipc.c index 63117defc..0b36d7582 100644 --- a/sway/ipc.c +++ b/sway/ipc.c @@ -121,11 +121,15 @@ int ipc_client_handle_readable(int client_fd, uint32_t mask, void *data) { } int read_available; - ioctl(client_fd, FIONREAD, &read_available); + if (ioctl(client_fd, FIONREAD, &read_available) == -1) { + sway_log_errno(L_INFO, "Unable to read IPC socket buffer size"); + ipc_client_disconnect(client); + return 0; + } // Wait for the rest of the command payload in case the header has already been read if (client->payload_length > 0) { - if (read_available >= client->payload_length) { + if ((uint32_t)read_available >= client->payload_length) { ipc_client_handle_command(client); } else { diff --git a/sway/layout.c b/sway/layout.c index 7eaa9ea4b..573c6f708 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -114,7 +114,7 @@ void move_container(swayc_t *container,swayc_t* root,enum movement_direction dir sway_log(L_DEBUG, "Moved window"); swayc_t *temp; int i; - uint clength = root->children->length; + int clength = root->children->length; //Rearrange for (i = 0; i < clength; ++i) { swayc_t *child = root->children->items[i]; diff --git a/sway/log.c b/sway/log.c index e0734109e..a1e89bade 100644 --- a/sway/log.c +++ b/sway/log.c @@ -10,7 +10,7 @@ #include int colored = 1; -int v = 0; +log_importance_t v = L_SILENT; static const char *verbosity_colors[] = { "", // L_SILENT @@ -19,7 +19,7 @@ static const char *verbosity_colors[] = { "\x1B[1;30m", // L_DEBUG }; -void init_log(int verbosity) { +void init_log(log_importance_t verbosity) { v = verbosity; /* set FD_CLOEXEC flag to prevent programs called with exec to write into logs */ int i; @@ -46,9 +46,9 @@ void sway_abort(const char *format, ...) { sway_terminate(); } -void sway_log(int verbosity, const char* format, ...) { +void sway_log(log_importance_t verbosity, const char* format, ...) { if (verbosity <= v) { - int c = verbosity; + unsigned int c = verbosity; if (c > sizeof(verbosity_colors) / sizeof(char *)) { c = sizeof(verbosity_colors) / sizeof(char *) - 1; } @@ -69,9 +69,9 @@ void sway_log(int verbosity, const char* format, ...) { } } -void sway_log_errno(int verbosity, char* format, ...) { +void sway_log_errno(log_importance_t verbosity, char* format, ...) { if (verbosity <= v) { - int c = verbosity; + unsigned int c = verbosity; if (c > sizeof(verbosity_colors) / sizeof(char *)) { c = sizeof(verbosity_colors) / sizeof(char *) - 1; }