From eac0920f49a728ad6a3809528c4757b73e4cd8af Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 22 Aug 2015 14:44:47 -0400 Subject: Set x/y positions for output containers --- sway/container.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'sway/container.c') diff --git a/sway/container.c b/sway/container.c index 5d544934..41d21c3b 100644 --- a/sway/container.c +++ b/sway/container.c @@ -59,7 +59,7 @@ swayc_t *new_output(wlc_handle handle) { const char *name = wlc_output_get_name(handle); sway_log(L_DEBUG, "Added output %lu:%s", handle, name); - struct output_config *oc ; + struct output_config *oc = NULL; int i; for (i = 0; i < config->output_configs->length; ++i) { oc = config->output_configs->items[i]; @@ -83,6 +83,23 @@ swayc_t *new_output(wlc_handle handle) { output->handle = handle; output->name = name ? strdup(name) : NULL; output->gaps = config->gaps_outer + config->gaps_inner / 2; + + // Find position for it + if (oc && oc->x != -1 && oc->y != -1) { + output->x = oc->x; + output->y = oc->y; + } else { + int x = 0; + for (i = 0; i < root_container.children->length; ++i) { + swayc_t *c = root_container.children->items[i]; + if (c->type == C_OUTPUT) { + if (c->width + c->x > x) { + x = c->width + c->x; + } + } + } + output->x = x; + } add_child(&root_container, output); -- cgit v1.2.3 From 07229edfe627762df9c27ed2700d737f74bb7b88 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 22 Aug 2015 15:19:02 -0400 Subject: Implement output positioning :tada: --- sway/container.c | 1 + sway/layout.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 68 insertions(+), 9 deletions(-) (limited to 'sway/container.c') diff --git a/sway/container.c b/sway/container.c index 41d21c3b..67a34551 100644 --- a/sway/container.c +++ b/sway/container.c @@ -86,6 +86,7 @@ swayc_t *new_output(wlc_handle handle) { // Find position for it if (oc && oc->x != -1 && oc->y != -1) { + sway_log(L_DEBUG, "Set %s position to %d, %d", name, oc->x, oc->y); output->x = oc->x; output->y = oc->y; } else { diff --git a/sway/layout.c b/sway/layout.c index 7f3adc31..7a7ccc0e 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -169,8 +169,6 @@ void arrange_windows(swayc_t *container, double width, double height) { for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; sway_log(L_DEBUG, "Arranging output at %d", x); - child->x = x; - child->y = y; arrange_windows(child, -1, -1); x += child->width; } @@ -340,19 +338,79 @@ swayc_t *get_swayc_in_direction(swayc_t *container, enum movement_direction dir) // Test if we can even make a difference here bool can_move = false; int diff = 0; - if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { - if (parent->layout == L_HORIZ || parent->type == C_ROOT) { + int i; + if (parent->type == C_ROOT) { + // Find the next output + int target = -1, max_x = 0, max_y = 0, self = -1; + sway_log(L_DEBUG, "Moving between outputs"); + + for (i = 0; i < parent->children->length; ++i) { + swayc_t *next = parent->children->items[i]; + if (next == container) { + self = i; + sway_log(L_DEBUG, "self is %p %d", next, self); + continue; + } + if (next->type == C_OUTPUT) { + sway_log(L_DEBUG, "Testing with %p %d (dir %d)", next, i, dir); + // Check if it's more extreme + if (dir == MOVE_RIGHT) { + if (container->x + container->width <= next->x) { + if (target == -1 || next->x < max_x) { + target = i; + max_x = next->x; + } + } + } else if (dir == MOVE_LEFT) { + sway_log(L_DEBUG, "next->x: %d, next->width: %d, container->x: %d", + (int)next->x, (int)next->width, (int)container->x); + if (container->x > next->x + next->width) { + sway_log(L_DEBUG, "match"); + if (target == -1 || max_x < next->x) { + sway_log(L_DEBUG, "hit"); + target = i; + max_x = next->x; + } + } + } else if (dir == MOVE_DOWN) { + if (container->y + container->height <= next->y) { + if (target == -1 || next->y < max_y) { + target = i; + max_y = next->y; + } + } + } else if (dir == MOVE_UP) { + if (container->y > next->y + next->height) { + if (target == -1 || max_y < next->y) { + target = i; + max_y = next->y; + } + } + } + } + } + + if (target == -1) { + can_move = false; + } else { can_move = true; - diff = dir == MOVE_LEFT ? -1 : 1; + diff = target - self; } } else { - if (parent->layout == L_VERT) { - can_move = true; - diff = dir == MOVE_UP ? -1 : 1; + if (dir == MOVE_LEFT || dir == MOVE_RIGHT) { + if (parent->layout == L_HORIZ) { + can_move = true; + diff = dir == MOVE_LEFT ? -1 : 1; + } + } else { + if (parent->layout == L_VERT) { + can_move = true; + diff = dir == MOVE_UP ? -1 : 1; + } } } + if (can_move) { - int i; for (i = 0; i < parent->children->length; ++i) { swayc_t *child = parent->children->items[i]; if (child == container) { -- cgit v1.2.3 From 36cd180f02cf032fa1d041540fff236061c3df5a Mon Sep 17 00:00:00 2001 From: taiyu Date: Sat, 22 Aug 2015 18:25:05 -0700 Subject: fixed vanishing floating view --- sway/container.c | 17 ++++++++++------- sway/focus.c | 1 - 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'sway/container.c') diff --git a/sway/container.c b/sway/container.c index 67a34551..127e1ecd 100644 --- a/sway/container.c +++ b/sway/container.c @@ -299,7 +299,8 @@ swayc_t *destroy_workspace(swayc_t *workspace) { return NULL; } - if (workspace->children->length == 0) { + // Do not destroy if there are children + if (workspace->children->length == 0 && workspace->floating->length == 0) { sway_log(L_DEBUG, "%s: '%s'", __func__, workspace->name); swayc_t *parent = workspace->parent; free_swayc(workspace); @@ -466,14 +467,16 @@ bool swayc_is_fullscreen(swayc_t *view) { // Mapping void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { - if (container && container->children && container->children->length) { + if (container) { 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->children) { + 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) { + if (container->floating) { for (i = 0; i < container->floating->length; ++i) { swayc_t *child = container->floating->items[i]; f(child, data); diff --git a/sway/focus.c b/sway/focus.c index a3e5e77a..e369de30 100644 --- a/sway/focus.c +++ b/sway/focus.c @@ -34,7 +34,6 @@ static void update_focus(swayc_t *c) { mask = 2; container_map(c, set_view_visibility, &mask); wlc_output_set_mask(parent->handle, 2); - c->parent->focused = c; destroy_workspace(ws); } break; -- cgit v1.2.3 From 98fad060e28c81c8340afbb473615f7889a6097a Mon Sep 17 00:00:00 2001 From: Luminarys Date: Sun, 23 Aug 2015 12:22:33 -0500 Subject: Added in glitchy disabling --- include/config.h | 1 + sway/commands.c | 5 +++++ sway/container.c | 4 ++++ sway/handlers.c | 11 +++++++++++ 4 files changed, 21 insertions(+) (limited to 'sway/container.c') diff --git a/include/config.h b/include/config.h index c896b423..3d501cbe 100644 --- a/include/config.h +++ b/include/config.h @@ -24,6 +24,7 @@ struct sway_mode { struct output_config { char *name; + bool enabled; int width, height; int x, y; }; diff --git a/sway/commands.c b/sway/commands.c index 5de1fb0c..9a0bc076 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -372,8 +372,13 @@ static bool cmd_output(struct sway_config *config, int argc, char **argv) { struct output_config *output = calloc(1, sizeof(struct output_config)); output->x = output->y = output->width = output->height = -1; output->name = strdup(argv[0]); + output->enabled = true; // TODO: atoi doesn't handle invalid numbers + + if (strcmp(argv[1], "disable") == 0) { + output->enabled = false; + } int i; for (i = 1; i < argc; ++i) { diff --git a/sway/container.c b/sway/container.c index 127e1ecd..6debeea3 100644 --- a/sway/container.c +++ b/sway/container.c @@ -70,6 +70,10 @@ swayc_t *new_output(wlc_handle handle) { oc = NULL; } + if (oc && !oc->enabled) { + return NULL; + } + swayc_t *output = new_swayc(C_OUTPUT); if (oc && oc->width != -1 && oc->height != -1) { output->width = oc->width; diff --git a/sway/handlers.c b/sway/handlers.c index e4018811..9fca6387 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -86,11 +86,22 @@ swayc_t *container_under_pointer(void) { static bool handle_output_created(wlc_handle output) { swayc_t *op = new_output(output); + if (!op) { + return false; + } + + wlc_output_focus(output); // Switch to workspace if we need to if (swayc_active_workspace() == NULL) { + sway_log(L_INFO, "Focus switch"); swayc_t *ws = op->children->items[0]; workspace_switch(ws); } + /* + if (wlc_output_get_sleep(wlc_get_focused_output())) { + wlc_output_focus(output); + } + */ return true; } -- cgit v1.2.3 From e01cf0b56654ff459a98a90e5e35615ad8d9203e Mon Sep 17 00:00:00 2001 From: Luminarys Date: Sun, 23 Aug 2015 12:22:45 -0500 Subject: Added in glitchy disabling --- sway/commands.c | 10 +++++----- sway/container.c | 6 +++--- sway/handlers.c | 20 ++++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) (limited to 'sway/container.c') diff --git a/sway/commands.c b/sway/commands.c index 9a0bc076..ae75ec67 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -372,13 +372,13 @@ static bool cmd_output(struct sway_config *config, int argc, char **argv) { struct output_config *output = calloc(1, sizeof(struct output_config)); output->x = output->y = output->width = output->height = -1; output->name = strdup(argv[0]); - output->enabled = true; + output->enabled = true; // TODO: atoi doesn't handle invalid numbers - - if (strcmp(argv[1], "disable") == 0) { - output->enabled = false; - } + + if (strcmp(argv[1], "disable") == 0) { + output->enabled = false; + } int i; for (i = 1; i < argc; ++i) { diff --git a/sway/container.c b/sway/container.c index 6debeea3..d4f7c693 100644 --- a/sway/container.c +++ b/sway/container.c @@ -70,9 +70,9 @@ swayc_t *new_output(wlc_handle handle) { oc = NULL; } - if (oc && !oc->enabled) { - return NULL; - } + if (oc && !oc->enabled) { + return NULL; + } swayc_t *output = new_swayc(C_OUTPUT); if (oc && oc->width != -1 && oc->height != -1) { diff --git a/sway/handlers.c b/sway/handlers.c index 9fca6387..1ff430f2 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -86,22 +86,22 @@ swayc_t *container_under_pointer(void) { static bool handle_output_created(wlc_handle output) { swayc_t *op = new_output(output); - if (!op) { - return false; - } + if (!op) { + return false; + } - wlc_output_focus(output); + wlc_output_focus(output); // Switch to workspace if we need to if (swayc_active_workspace() == NULL) { - sway_log(L_INFO, "Focus switch"); + sway_log(L_INFO, "Focus switch"); swayc_t *ws = op->children->items[0]; workspace_switch(ws); } - /* - if (wlc_output_get_sleep(wlc_get_focused_output())) { - wlc_output_focus(output); - } - */ + /* + if (wlc_output_get_sleep(wlc_get_focused_output())) { + wlc_output_focus(output); + } + */ return true; } -- cgit v1.2.3