aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorTony Crisci <tony@dubstepdish.com>2018-04-03 19:52:17 -0400
committerTony Crisci <tony@dubstepdish.com>2018-04-03 19:52:17 -0400
commita001890fb8a9fc8c7f0b8eac03ca5912be2de479 (patch)
tree2127025dfa5c7cfed6e75188d38ffdda448f9163 /sway
parent97b171649dd0f387ecd471dc75feda6307e7dbe3 (diff)
move workspace create to workspace.c
Diffstat (limited to 'sway')
-rw-r--r--sway/commands/move.c2
-rw-r--r--sway/commands/workspace.c6
-rw-r--r--sway/desktop/output.c2
-rw-r--r--sway/tree/container.c62
-rw-r--r--sway/tree/layout.c2
-rw-r--r--sway/tree/workspace.c54
6 files changed, 64 insertions, 64 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c
index 7ac5f009..c954ab94 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -74,7 +74,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
ws = workspace_by_name(ws_name);
}
if (!ws) {
- ws = container_workspace_create(NULL, ws_name ? ws_name : num_name);
+ ws = workspace_create(NULL, ws_name ? ws_name : num_name);
}
free(ws_name);
struct sway_container *old_parent = current->parent;
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index a3702803..958b3222 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -61,7 +61,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
if (strcasecmp(argv[0], "number") == 0) {
if (!(ws = workspace_by_number(argv[1]))) {
char *name = join_args(argv + 1, argc - 1);
- ws = container_workspace_create(NULL, name);
+ ws = workspace_create(NULL, name);
free(name);
}
} else if (strcasecmp(argv[0], "next") == 0) {
@@ -80,12 +80,12 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
ws = old_workspace;
} else if (prev_workspace_name
&& !(ws = workspace_by_name(prev_workspace_name))) {
- ws = container_workspace_create(NULL, prev_workspace_name);
+ ws = workspace_create(NULL, prev_workspace_name);
}
} else {
char *name = join_args(argv, argc);
if (!(ws = workspace_by_name(name))) {
- ws = container_workspace_create(NULL, name);
+ ws = workspace_create(NULL, name);
}
free(name);
}
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index de5076d8..96f23291 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -396,7 +396,7 @@ void handle_new_output(struct wl_listener *listener, void *data) {
output->damage = wlr_output_damage_create(wlr_output);
- output->swayc = container_output_create(output);
+ output->swayc = output_create(output);
if (!output->swayc) {
free(output);
return;
diff --git a/sway/tree/container.c b/sway/tree/container.c
index fdbb2922..8ed30b44 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -51,7 +51,7 @@ const char *container_type_to_str(enum sway_container_type type) {
}
}
-static void notify_new_container(struct sway_container *container) {
+void container_create_notify(struct sway_container *container) {
wl_signal_emit(&root_container.sway_root->events.new_container, container);
ipc_event_window(container, "new");
}
@@ -312,7 +312,7 @@ struct sway_container *container_close(struct sway_container *con) {
return parent;
}
-struct sway_container *container_output_create(
+struct sway_container *output_create(
struct sway_output *sway_output) {
struct wlr_box size;
wlr_output_effective_resolution(sway_output->wlr_output, &size.width,
@@ -363,7 +363,7 @@ struct sway_container *container_output_create(
// Create workspace
char *ws_name = workspace_next_name(output->name);
wlr_log(L_DEBUG, "Creating default workspace %s", ws_name);
- struct sway_container *ws = container_workspace_create(output, ws_name);
+ struct sway_container *ws = workspace_create(output, ws_name);
// Set each seat's focus if not already set
struct sway_seat *seat = NULL;
wl_list_for_each(seat, &input_manager->seats, link) {
@@ -373,62 +373,10 @@ struct sway_container *container_output_create(
}
free(ws_name);
- notify_new_container(output);
+ container_create_notify(output);
return output;
}
-static struct sway_container *get_workspace_initial_output(const char *name) {
- struct sway_container *parent;
- // Search for workspace<->output pair
- int e = config->workspace_outputs->length;
- for (int i = 0; i < config->workspace_outputs->length; ++i) {
- struct workspace_output *wso = config->workspace_outputs->items[i];
- if (strcasecmp(wso->workspace, name) == 0) {
- // Find output to use if it exists
- e = root_container.children->length;
- for (i = 0; i < e; ++i) {
- parent = root_container.children->items[i];
- if (strcmp(parent->name, wso->output) == 0) {
- return parent;
- }
- }
- break;
- }
- }
- // Otherwise put it on the focused output
- struct sway_seat *seat = input_manager_current_seat(input_manager);
- struct sway_container *focus =
- seat_get_focus_inactive(seat, &root_container);
- parent = focus;
- parent = container_parent(parent, C_OUTPUT);
- return parent;
-}
-
-struct sway_container *container_workspace_create(struct sway_container *output,
- const char *name) {
- if (output == NULL) {
- output = get_workspace_initial_output(name);
- }
-
- wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name);
- struct sway_container *workspace = container_create(C_WORKSPACE);
-
- workspace->x = output->x;
- workspace->y = output->y;
- workspace->width = output->width;
- workspace->height = output->height;
- workspace->name = !name ? NULL : strdup(name);
- workspace->prev_layout = L_NONE;
- workspace->layout = container_get_default_layout(output);
- workspace->workspace_layout = workspace->layout;
-
- container_add_child(output, workspace);
- container_sort_workspaces(output);
- notify_new_container(workspace);
-
- return workspace;
-}
-
struct sway_container *container_view_create(struct sway_container *sibling,
struct sway_view *sway_view) {
if (!sway_assert(sibling,
@@ -452,7 +400,7 @@ struct sway_container *container_view_create(struct sway_container *sibling,
// Regular case, create as sibling of current container
container_add_sibling(sibling, swayc);
}
- notify_new_container(swayc);
+ container_create_notify(swayc);
return swayc;
}
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 3cbbf3b4..a46359bd 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -149,7 +149,7 @@ void container_move_to(struct sway_container *container,
if (old_parent->children->length == 0) {
char *ws_name = workspace_next_name(old_parent->name);
struct sway_container *ws =
- container_workspace_create(old_parent, ws_name);
+ workspace_create(old_parent, ws_name);
free(ws_name);
seat_set_focus(seat, ws);
}
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index d5a16410..6ba3d973 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -14,6 +14,58 @@
#include "log.h"
#include "util.h"
+static struct sway_container *get_workspace_initial_output(const char *name) {
+ struct sway_container *parent;
+ // Search for workspace<->output pair
+ int e = config->workspace_outputs->length;
+ for (int i = 0; i < config->workspace_outputs->length; ++i) {
+ struct workspace_output *wso = config->workspace_outputs->items[i];
+ if (strcasecmp(wso->workspace, name) == 0) {
+ // Find output to use if it exists
+ e = root_container.children->length;
+ for (i = 0; i < e; ++i) {
+ parent = root_container.children->items[i];
+ if (strcmp(parent->name, wso->output) == 0) {
+ return parent;
+ }
+ }
+ break;
+ }
+ }
+ // Otherwise put it on the focused output
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_container *focus =
+ seat_get_focus_inactive(seat, &root_container);
+ parent = focus;
+ parent = container_parent(parent, C_OUTPUT);
+ return parent;
+}
+
+struct sway_container *workspace_create(struct sway_container *output,
+ const char *name) {
+ if (output == NULL) {
+ output = get_workspace_initial_output(name);
+ }
+
+ wlr_log(L_DEBUG, "Added workspace %s for output %s", name, output->name);
+ struct sway_container *workspace = container_create(C_WORKSPACE);
+
+ workspace->x = output->x;
+ workspace->y = output->y;
+ workspace->width = output->width;
+ workspace->height = output->height;
+ workspace->name = !name ? NULL : strdup(name);
+ workspace->prev_layout = L_NONE;
+ workspace->layout = container_get_default_layout(output);
+ workspace->workspace_layout = workspace->layout;
+
+ container_add_child(output, workspace);
+ container_sort_workspaces(output);
+ container_create_notify(workspace);
+
+ return workspace;
+}
+
char *prev_workspace_name = NULL;
struct workspace_by_number_data {
int len;
@@ -292,7 +344,7 @@ bool workspace_switch(struct sway_container *workspace) {
struct sway_container *new_ws = workspace_by_name(prev_workspace_name);
workspace = new_ws ?
new_ws :
- container_workspace_create(NULL, prev_workspace_name);
+ workspace_create(NULL, prev_workspace_name);
}
if (!prev_workspace_name || (strcmp(prev_workspace_name, active_ws->name)