mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 09:51:29 +00:00
Add support for workspace [name] output [name]
This commit is contained in:
parent
3f3d1ffee4
commit
780893a933
|
@ -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
|
||||||
|
|
|
@ -410,10 +410,11 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (argc == 1) {
|
||||||
// Handle workspace next/prev
|
// Handle workspace next/prev
|
||||||
if (strcmp(argv[0], "next") == 0) {
|
if (strcmp(argv[0], "next") == 0) {
|
||||||
workspace_next();
|
workspace_next();
|
||||||
|
@ -441,6 +442,19 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) {
|
||||||
workspace = workspace_create(argv[0]);
|
workspace = workspace_create(argv[0]);
|
||||||
}
|
}
|
||||||
workspace_switch(workspace);
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
|
@ -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,7 +64,21 @@ 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);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue