2019-01-20 20:05:28 +11:00
|
|
|
#include <strings.h>
|
2017-12-06 22:36:06 +11:00
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
2018-06-06 07:56:32 +10:00
|
|
|
#include "sway/output.h"
|
2017-12-06 22:36:06 +11:00
|
|
|
#include "list.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
2018-06-03 11:33:16 +10:00
|
|
|
// must be in order for the bsearch
|
2021-02-03 11:54:35 +11:00
|
|
|
static const struct cmd_handler output_handlers[] = {
|
2020-03-03 01:30:50 +11:00
|
|
|
{ "adaptive_sync", output_cmd_adaptive_sync },
|
2018-06-03 11:33:16 +10:00
|
|
|
{ "background", output_cmd_background },
|
|
|
|
{ "bg", output_cmd_background },
|
|
|
|
{ "disable", output_cmd_disable },
|
|
|
|
{ "dpms", output_cmd_dpms },
|
|
|
|
{ "enable", output_cmd_enable },
|
2019-09-25 20:58:27 +10:00
|
|
|
{ "max_render_time", output_cmd_max_render_time },
|
2018-06-03 11:33:16 +10:00
|
|
|
{ "mode", output_cmd_mode },
|
2021-07-18 20:05:47 +10:00
|
|
|
{ "modeline", output_cmd_modeline },
|
2018-06-03 11:33:16 +10:00
|
|
|
{ "pos", output_cmd_position },
|
|
|
|
{ "position", output_cmd_position },
|
2021-09-03 11:45:23 +10:00
|
|
|
{ "render_bit_depth", output_cmd_render_bit_depth },
|
2018-06-03 11:33:16 +10:00
|
|
|
{ "res", output_cmd_mode },
|
|
|
|
{ "resolution", output_cmd_mode },
|
|
|
|
{ "scale", output_cmd_scale },
|
2019-11-14 05:23:36 +11:00
|
|
|
{ "scale_filter", output_cmd_scale_filter },
|
2019-02-11 11:56:57 +11:00
|
|
|
{ "subpixel", output_cmd_subpixel },
|
2019-05-11 16:57:53 +10:00
|
|
|
{ "toggle", output_cmd_toggle },
|
2018-06-03 11:33:16 +10:00
|
|
|
{ "transform", output_cmd_transform },
|
2017-12-06 22:36:06 +11:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cmd_results *cmd_output(int argc, char **argv) {
|
2017-12-30 05:04:16 +11:00
|
|
|
struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1);
|
|
|
|
if (error != NULL) {
|
2017-12-06 22:36:06 +11:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2021-10-05 01:04:46 +11:00
|
|
|
// The HEADLESS-1 output is a dummy output used when there's no outputs
|
2019-01-20 20:05:28 +11:00
|
|
|
// connected. It should never be configured.
|
2021-10-05 01:04:46 +11:00
|
|
|
if (strcasecmp(argv[0], root->fallback_output->wlr_output->name) == 0) {
|
2019-01-20 20:05:28 +11:00
|
|
|
return cmd_results_new(CMD_FAILURE,
|
|
|
|
"Refusing to configure the no op output");
|
|
|
|
}
|
|
|
|
|
2019-07-18 09:48:28 +10:00
|
|
|
struct output_config *output = NULL;
|
|
|
|
if (strcmp(argv[0], "-") == 0 || strcmp(argv[0], "--") == 0) {
|
|
|
|
if (config->reading) {
|
|
|
|
return cmd_results_new(CMD_FAILURE,
|
|
|
|
"Current output alias (%s) cannot be used in the config",
|
|
|
|
argv[0]);
|
|
|
|
}
|
|
|
|
struct sway_output *sway_output = config->handler_context.node ?
|
|
|
|
node_get_output(config->handler_context.node) : NULL;
|
|
|
|
if (!sway_output) {
|
|
|
|
return cmd_results_new(CMD_FAILURE, "Unknown output");
|
|
|
|
}
|
2021-10-05 01:04:46 +11:00
|
|
|
if (sway_output == root->fallback_output) {
|
2019-07-18 09:48:28 +10:00
|
|
|
return cmd_results_new(CMD_FAILURE,
|
|
|
|
"Refusing to configure the no op output");
|
|
|
|
}
|
|
|
|
if (strcmp(argv[0], "-") == 0) {
|
|
|
|
output = new_output_config(sway_output->wlr_output->name);
|
|
|
|
} else {
|
|
|
|
char identifier[128];
|
|
|
|
output_get_identifier(identifier, 128, sway_output);
|
|
|
|
output = new_output_config(identifier);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
output = new_output_config(argv[0]);
|
|
|
|
}
|
2017-12-06 22:36:06 +11:00
|
|
|
if (!output) {
|
2019-01-21 05:51:12 +11:00
|
|
|
sway_log(SWAY_ERROR, "Failed to allocate output config");
|
2017-12-13 07:09:51 +11:00
|
|
|
return NULL;
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
2018-06-03 11:33:16 +10:00
|
|
|
argc--; argv++;
|
2017-12-06 22:36:06 +11:00
|
|
|
|
2018-06-03 11:33:16 +10:00
|
|
|
config->handler_context.output_config = output;
|
2017-12-06 22:36:06 +11:00
|
|
|
|
2018-06-03 11:33:16 +10:00
|
|
|
while (argc > 0) {
|
2018-06-04 00:29:00 +10:00
|
|
|
config->handler_context.leftovers.argc = 0;
|
|
|
|
config->handler_context.leftovers.argv = NULL;
|
|
|
|
|
2018-06-03 11:33:16 +10:00
|
|
|
if (find_handler(*argv, output_handlers, sizeof(output_handlers))) {
|
|
|
|
error = config_subcommand(argv, argc, output_handlers,
|
|
|
|
sizeof(output_handlers));
|
2017-12-14 10:50:01 +11:00
|
|
|
} else {
|
2019-01-11 10:27:21 +11:00
|
|
|
error = cmd_results_new(CMD_INVALID,
|
2018-06-03 11:33:16 +10:00
|
|
|
"Invalid output subcommand: %s.", *argv);
|
2017-12-28 07:23:30 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error != NULL) {
|
2017-12-14 10:50:01 +11:00
|
|
|
goto fail;
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
2018-06-03 11:33:16 +10:00
|
|
|
|
|
|
|
argc = config->handler_context.leftovers.argc;
|
|
|
|
argv = config->handler_context.leftovers.argv;
|
2017-12-06 22:36:06 +11:00
|
|
|
}
|
|
|
|
|
2018-06-03 11:33:16 +10:00
|
|
|
config->handler_context.output_config = NULL;
|
|
|
|
config->handler_context.leftovers.argc = 0;
|
|
|
|
config->handler_context.leftovers.argv = NULL;
|
|
|
|
|
2019-04-04 12:53:43 +11:00
|
|
|
bool background = output->background;
|
|
|
|
|
2018-07-21 02:32:29 +10:00
|
|
|
output = store_output_config(output);
|
2018-07-21 12:17:20 +10:00
|
|
|
|
|
|
|
// If reloading, the output configs will be applied after reading the
|
|
|
|
// entire config and before the deferred commands so that an auto generated
|
|
|
|
// workspace name is not given to re-enabled outputs.
|
2020-02-11 13:25:07 +11:00
|
|
|
if (!config->reloading && !config->validating) {
|
2018-07-21 12:17:20 +10:00
|
|
|
apply_output_config_to_outputs(output);
|
2019-04-04 12:53:43 +11:00
|
|
|
if (background) {
|
|
|
|
spawn_swaybg();
|
|
|
|
}
|
2018-07-21 12:17:20 +10:00
|
|
|
}
|
2017-12-06 22:36:06 +11:00
|
|
|
|
2019-01-11 10:27:21 +11:00
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL);
|
2017-12-06 22:36:06 +11:00
|
|
|
|
|
|
|
fail:
|
2018-06-03 11:33:16 +10:00
|
|
|
config->handler_context.output_config = NULL;
|
2017-12-06 22:36:06 +11:00
|
|
|
free_output_config(output);
|
|
|
|
return error;
|
|
|
|
}
|