move workspace create to workspace.c

master
Tony Crisci 7 years ago
parent 97b171649d
commit a001890fb8

@ -95,7 +95,7 @@ struct sway_container *container_create(enum sway_container_type type);
const char *container_type_to_str(enum sway_container_type type);
struct sway_container *container_output_create(
struct sway_container *output_create(
struct sway_output *sway_output);
/**
@ -108,13 +108,13 @@ struct sway_container *container_container_create();
* Create a new output. Outputs are children of the root container and have no
* order in the tree structure.
*/
struct sway_container *container_output_create(struct sway_output *sway_output);
struct sway_container *output_create(struct sway_output *sway_output);
/**
* Create a new workspace container. Workspaces are children of an output
* container and are ordered alphabetically by name.
*/
struct sway_container *container_workspace_create(struct sway_container *output, const char *name);
struct sway_container *workspace_create(struct sway_container *output, const char *name);
/*
* Create a new view container. A view can be a child of a workspace container
@ -178,4 +178,6 @@ bool container_has_anscestor(struct sway_container *container,
bool container_has_child(struct sway_container *con,
struct sway_container *child);
void container_create_notify(struct sway_container *container);
#endif

@ -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;

@ -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);
}

@ -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;

@ -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;
}

@ -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);
}

@ -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)

Loading…
Cancel
Save