diff --git a/sway/commands/backend.c b/sway/commands/backend.c index d6d2bd87d..4dfe363ee 100644 --- a/sway/commands/backend.c +++ b/sway/commands/backend.c @@ -48,7 +48,16 @@ static struct cmd_results *backend_cmd_add(int argc, char **argv) { static struct cmd_results *backend_cmd_add_output(int argc, char **argv, struct sway_subbackend *backend) { // TODO allow to name the output - sway_subbackend_add_output(&server, backend, NULL); + char *name = NULL; + if (argc > 0) { + name = argv[0]; + if (strlen(name) > 16) { + return cmd_results_new(CMD_INVALID, "backend [args]", + "output name must be less than 16 characters"); + } + } + + sway_subbackend_add_output(&server, backend, name); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } @@ -58,20 +67,7 @@ static struct cmd_results *backend_cmd_del_output(int argc, char **argv, if ((error = checkarg(argc, "backend", EXPECTED_AT_LEAST, 1))) { return error; } - - for (int i = 0; i < root_container.children->length; ++i) { - swayc_t *output = root_container.children->items[i]; - if (output->type != C_OUTPUT) { - continue; - } - - const char *name = output->sway_output->wlr_output->name; - - if (output->sway_output->wlr_output->backend == backend->backend && - strcmp(argv[0], name) == 0) { - wlr_output_destroy(output->sway_output->wlr_output); - } - } + sway_subbackend_remove_output(&server, backend, argv[0]); return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/server.c b/sway/server.c index efbbdd1cd..8731ae605 100644 --- a/sway/server.c +++ b/sway/server.c @@ -1,5 +1,7 @@ #define _POSIX_C_SOURCE 200112L +#define _XOPEN_SOURCE 700 #include +#include #include #include #include @@ -19,6 +21,7 @@ #include #include "sway/commands.h" #include "sway/config.h" +#include "sway/output.h" #include "sway/server.h" #include "sway/input/input-manager.h" #include "log.h" @@ -296,7 +299,6 @@ void sway_subbackend_add_output(struct sway_server *server, wlr_log(L_DEBUG, "creating DRM subbackend outputs is not supported"); break; case SWAY_SUBBACKEND_HEADLESS: - // TODO allow to name the output wlr_output = wlr_headless_add_output(subbackend->backend, 1280, 960); break; @@ -310,10 +312,25 @@ void sway_subbackend_add_output(struct sway_server *server, struct subbackend_output *output = calloc(1, sizeof(struct subbackend_output)); if (output == NULL) { + wlr_output_destroy(wlr_output); wlr_log(L_ERROR, "could not allocate subbackend output"); return; } + strncpy(wlr_output->name, name, sizeof(wlr_output->name)); + for (int i = 0; i < root_container.children->length; ++i) { + swayc_t *output = root_container.children->items[i]; + if (output->type != C_OUTPUT) { + continue; + } + + if (output->sway_output->wlr_output == wlr_output) { + free(output->name); + output->name = strdup(name); + break; + } + } + output->wlr_output = wlr_output; wl_signal_add(&wlr_output->events.destroy, &output->output_destroy);