Add support for workspace [name] output [name]

This commit is contained in:
Drew DeVault 2015-08-17 20:34:53 -04:00
parent 3f3d1ffee4
commit 780893a933
4 changed files with 61 additions and 25 deletions

View file

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

View file

@ -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) { 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; return false;
} }
// Handle workspace next/prev if (argc == 1) {
if (strcmp(argv[0], "next") == 0) { // Handle workspace next/prev
workspace_next(); if (strcmp(argv[0], "next") == 0) {
return true; workspace_next();
} return true;
}
if (strcmp(argv[0], "prev") == 0) { if (strcmp(argv[0], "prev") == 0) {
workspace_next(); workspace_next();
return true; return true;
} }
// Handle workspace output_next/prev // Handle workspace output_next/prev
if (strcmp(argv[0], "next_on_output") == 0) { if (strcmp(argv[0], "next_on_output") == 0) {
workspace_output_next(); workspace_output_next();
return true; return true;
} }
if (strcmp(argv[0], "prev_on_output") == 0) { if (strcmp(argv[0], "prev_on_output") == 0) {
workspace_output_prev(); workspace_output_prev();
return true; return true;
} }
swayc_t *workspace = workspace_find_by_name(argv[0]); swayc_t *workspace = workspace_find_by_name(argv[0]);
if (!workspace) { if (!workspace) {
workspace = workspace_create(argv[0]); 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; return true;
} }

View file

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

View file

@ -1,6 +1,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <strings.h> #include <strings.h>
#include "config.h"
#include "container.h" #include "container.h"
#include "workspace.h" #include "workspace.h"
#include "layout.h" #include "layout.h"
@ -63,14 +64,28 @@ swayc_t *new_output(wlc_handle handle) {
container_map(&root_container, add_output_widths, &total_width); container_map(&root_container, add_output_widths, &total_width);
//Create workspace //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); new_workspace(output, ws_name);
free(ws_name); free(ws_name);
return output; 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); sway_log(L_DEBUG, "Added workspace %s for output %u", name, (unsigned int)output->handle);
swayc_t *workspace = new_swayc(C_WORKSPACE); swayc_t *workspace = new_swayc(C_WORKSPACE);