name backend outputs

This commit is contained in:
Tony Crisci 2018-02-25 12:20:57 -05:00
parent 6b9ae074fa
commit 91841e6ee4
2 changed files with 29 additions and 16 deletions

View file

@ -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, static struct cmd_results *backend_cmd_add_output(int argc, char **argv,
struct sway_subbackend *backend) { struct sway_subbackend *backend) {
// TODO allow to name the output // 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 <cmd> [args]",
"output name must be less than 16 characters");
}
}
sway_subbackend_add_output(&server, backend, name);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); 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))) { if ((error = checkarg(argc, "backend", EXPECTED_AT_LEAST, 1))) {
return error; return error;
} }
sway_subbackend_remove_output(&server, backend, argv[0]);
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);
}
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -1,5 +1,7 @@
#define _POSIX_C_SOURCE 200112L #define _POSIX_C_SOURCE 200112L
#define _XOPEN_SOURCE 700
#include <strings.h> #include <strings.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <wayland-server.h> #include <wayland-server.h>
@ -19,6 +21,7 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/config.h" #include "sway/config.h"
#include "sway/output.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "log.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"); wlr_log(L_DEBUG, "creating DRM subbackend outputs is not supported");
break; break;
case SWAY_SUBBACKEND_HEADLESS: case SWAY_SUBBACKEND_HEADLESS:
// TODO allow to name the output
wlr_output = wlr_output =
wlr_headless_add_output(subbackend->backend, 1280, 960); wlr_headless_add_output(subbackend->backend, 1280, 960);
break; break;
@ -310,10 +312,25 @@ void sway_subbackend_add_output(struct sway_server *server,
struct subbackend_output *output = struct subbackend_output *output =
calloc(1, sizeof(struct subbackend_output)); calloc(1, sizeof(struct subbackend_output));
if (output == NULL) { if (output == NULL) {
wlr_output_destroy(wlr_output);
wlr_log(L_ERROR, "could not allocate subbackend output"); wlr_log(L_ERROR, "could not allocate subbackend output");
return; 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; output->wlr_output = wlr_output;
wl_signal_add(&wlr_output->events.destroy, &output->output_destroy); wl_signal_add(&wlr_output->events.destroy, &output->output_destroy);