From db2845963408dd0d66a3587469c6f26bfa4d9e1f Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Wed, 19 Sep 2018 21:54:27 +1000 Subject: [PATCH] Introduce create_output command (for developer use) Should help with testing hotplugging. --- include/sway/commands.h | 1 + sway/commands.c | 1 + sway/commands/create_output.c | 39 +++++++++++++++++++++++++++++++++++ sway/meson.build | 1 + 4 files changed, 42 insertions(+) create mode 100644 sway/commands/create_output.c diff --git a/include/sway/commands.h b/include/sway/commands.h index e51b12fd..226cf932 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h @@ -103,6 +103,7 @@ sway_cmd cmd_client_urgent; sway_cmd cmd_client_placeholder; sway_cmd cmd_client_background; sway_cmd cmd_commands; +sway_cmd cmd_create_output; sway_cmd cmd_debuglog; sway_cmd cmd_default_border; sway_cmd cmd_default_floating_border; diff --git a/sway/commands.c b/sway/commands.c index 41e1c653..27a88319 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -143,6 +143,7 @@ static struct cmd_handler config_handlers[] = { /* Runtime-only commands. Keep alphabetized */ static struct cmd_handler command_handlers[] = { { "border", cmd_border }, + { "create_output", cmd_create_output }, { "exit", cmd_exit }, { "floating", cmd_floating }, { "fullscreen", cmd_fullscreen }, diff --git a/sway/commands/create_output.c b/sway/commands/create_output.c new file mode 100644 index 00000000..a852c2a0 --- /dev/null +++ b/sway/commands/create_output.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include "sway/commands.h" +#include "sway/server.h" +#include "log.h" + +static void create_output(struct wlr_backend *backend, void *data) { + bool *done = data; + if (*done) { + return; + } + + if (wlr_backend_is_wl(backend)) { + wlr_wl_output_create(backend); + *done = true; + } else if (wlr_backend_is_x11(backend)) { + wlr_x11_output_create(backend); + *done = true; + } +} + +/** + * This command is intended for developer use only. + */ +struct cmd_results *cmd_create_output(int argc, char **argv) { + sway_assert(wlr_backend_is_multi(server.backend), + "Expected a multi backend"); + + bool done = false; + wlr_multi_for_each_backend(server.backend, create_output, &done); + + if (!done) { + return cmd_results_new(CMD_INVALID, "create_output", + "Can only create outputs for Wayland or X11 backends"); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} diff --git a/sway/meson.build b/sway/meson.build index 01c83a33..d67a4c64 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -35,6 +35,7 @@ sway_sources = files( 'commands/bind.c', 'commands/border.c', 'commands/client.c', + 'commands/create_output.c', 'commands/default_border.c', 'commands/default_floating_border.c', 'commands/default_orientation.c',