Add support for workspace [name] output [name]

master
Drew DeVault 9 years ago
parent 3f3d1ffee4
commit 780893a933

@ -21,10 +21,16 @@ struct sway_mode {
list_t *bindings;
};
struct workspace_output {
char *output;
char *workspace;
};
struct sway_config {
list_t *symbols;
list_t *modes;
list_t *cmd_queue;
list_t *workspace_outputs;
struct sway_mode *current_mode;
// Flags

@ -410,37 +410,51 @@ static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) {
}
static bool cmd_workspace(struct sway_config *config, int argc, char **argv) {
if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 1)) {
if (!checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1)) {
return false;
}
// Handle workspace next/prev
if (strcmp(argv[0], "next") == 0) {
workspace_next();
return true;
}
if (argc == 1) {
// Handle workspace next/prev
if (strcmp(argv[0], "next") == 0) {
workspace_next();
return true;
}
if (strcmp(argv[0], "prev") == 0) {
workspace_next();
return true;
}
if (strcmp(argv[0], "prev") == 0) {
workspace_next();
return true;
}
// Handle workspace output_next/prev
if (strcmp(argv[0], "next_on_output") == 0) {
workspace_output_next();
return true;
}
// Handle workspace output_next/prev
if (strcmp(argv[0], "next_on_output") == 0) {
workspace_output_next();
return true;
}
if (strcmp(argv[0], "prev_on_output") == 0) {
workspace_output_prev();
return true;
}
if (strcmp(argv[0], "prev_on_output") == 0) {
workspace_output_prev();
return true;
}
swayc_t *workspace = workspace_find_by_name(argv[0]);
if (!workspace) {
workspace = workspace_create(argv[0]);
swayc_t *workspace = workspace_find_by_name(argv[0]);
if (!workspace) {
workspace = workspace_create(argv[0]);
}
workspace_switch(workspace);
} else {
if (strcasecmp(argv[1], "output") == 0) {
if (!checkarg(argc, "workspace", EXPECTED_EQUAL_TO, 3)) {
return false;
}
struct workspace_output *wso = calloc(1, sizeof(struct workspace_output));
sway_log(L_DEBUG, "Assigning workspace %s to output %s", argv[0], argv[2]);
wso->workspace = strdup(argv[0]);
wso->output = strdup(argv[2]);
list_add(config->workspace_outputs, wso);
// TODO: Consider moving any existing workspace to that output? This might be executed sometime after config load
}
}
workspace_switch(workspace);
return true;
}

@ -159,6 +159,7 @@ void config_defaults(struct sway_config *config) {
config->symbols = create_list();
config->modes = create_list();
config->cmd_queue = create_list();
config->workspace_outputs = create_list();
config->current_mode = malloc(sizeof(struct sway_mode));
config->current_mode->name = NULL;
config->current_mode->bindings = create_list();

@ -1,6 +1,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <strings.h>
#include "config.h"
#include "container.h"
#include "workspace.h"
#include "layout.h"
@ -63,14 +64,28 @@ swayc_t *new_output(wlc_handle handle) {
container_map(&root_container, add_output_widths, &total_width);
//Create workspace
char *ws_name = workspace_next_name();
char *ws_name = NULL;
if (name) {
int i;
for (i = 0; i < config->workspace_outputs->length; ++i) {
struct workspace_output *wso = config->workspace_outputs->items[i];
if (strcasecmp(wso->output, name) == 0) {
sway_log(L_DEBUG, "Matched workspace to output: %s for %s", wso->workspace, wso->output);
ws_name = strdup(wso->workspace);
break;
}
}
}
if (!ws_name) {
ws_name = workspace_next_name();
}
new_workspace(output, ws_name);
free(ws_name);
return output;
}
swayc_t *new_workspace(swayc_t * output, const char *name) {
swayc_t *new_workspace(swayc_t *output, const char *name) {
sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle);
swayc_t *workspace = new_swayc(C_WORKSPACE);

Loading…
Cancel
Save