2017-12-06 12:36:06 +01:00
|
|
|
#include "sway/commands.h"
|
|
|
|
#include "sway/config.h"
|
2018-06-05 23:56:32 +02:00
|
|
|
#include "sway/output.h"
|
|
|
|
#include "sway/tree/layout.h"
|
2017-12-06 12:36:06 +01:00
|
|
|
#include "list.h"
|
|
|
|
#include "log.h"
|
|
|
|
|
2018-06-03 03:33:16 +02:00
|
|
|
// must be in order for the bsearch
|
|
|
|
static struct cmd_handler output_handlers[] = {
|
|
|
|
{ "background", output_cmd_background },
|
|
|
|
{ "bg", output_cmd_background },
|
|
|
|
{ "disable", output_cmd_disable },
|
|
|
|
{ "dpms", output_cmd_dpms },
|
|
|
|
{ "enable", output_cmd_enable },
|
|
|
|
{ "mode", output_cmd_mode },
|
|
|
|
{ "pos", output_cmd_position },
|
|
|
|
{ "position", output_cmd_position },
|
|
|
|
{ "res", output_cmd_mode },
|
|
|
|
{ "resolution", output_cmd_mode },
|
|
|
|
{ "scale", output_cmd_scale },
|
|
|
|
{ "transform", output_cmd_transform },
|
2017-12-06 12:36:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct cmd_results *cmd_output(int argc, char **argv) {
|
2017-12-29 19:04:16 +01:00
|
|
|
struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1);
|
|
|
|
if (error != NULL) {
|
2017-12-06 12:36:06 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2017-12-27 21:23:30 +01:00
|
|
|
struct output_config *output = new_output_config(argv[0]);
|
2017-12-06 12:36:06 +01:00
|
|
|
if (!output) {
|
2018-01-05 22:32:51 +01:00
|
|
|
wlr_log(L_ERROR, "Failed to allocate output config");
|
2017-12-12 21:09:51 +01:00
|
|
|
return NULL;
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
2018-06-03 03:33:16 +02:00
|
|
|
argc--; argv++;
|
2017-12-06 12:36:06 +01:00
|
|
|
|
2018-06-03 03:33:16 +02:00
|
|
|
config->handler_context.output_config = output;
|
2017-12-06 12:36:06 +01:00
|
|
|
|
2018-06-03 03:33:16 +02:00
|
|
|
while (argc > 0) {
|
2018-06-03 16:29:00 +02:00
|
|
|
config->handler_context.leftovers.argc = 0;
|
|
|
|
config->handler_context.leftovers.argv = NULL;
|
|
|
|
|
2018-06-03 03:33:16 +02:00
|
|
|
if (find_handler(*argv, output_handlers, sizeof(output_handlers))) {
|
|
|
|
error = config_subcommand(argv, argc, output_handlers,
|
|
|
|
sizeof(output_handlers));
|
2017-12-14 00:50:01 +01:00
|
|
|
} else {
|
2017-12-14 02:23:33 +01:00
|
|
|
error = cmd_results_new(CMD_INVALID, "output",
|
2018-06-03 03:33:16 +02:00
|
|
|
"Invalid output subcommand: %s.", *argv);
|
2017-12-27 21:23:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (error != NULL) {
|
2017-12-14 00:50:01 +01:00
|
|
|
goto fail;
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
2018-06-03 03:33:16 +02:00
|
|
|
|
|
|
|
argc = config->handler_context.leftovers.argc;
|
|
|
|
argv = config->handler_context.leftovers.argv;
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
|
|
|
|
2018-06-03 03:33:16 +02:00
|
|
|
config->handler_context.output_config = NULL;
|
|
|
|
config->handler_context.leftovers.argc = 0;
|
|
|
|
config->handler_context.leftovers.argv = NULL;
|
|
|
|
|
2017-12-27 21:23:30 +01:00
|
|
|
int i = list_seq_find(config->output_configs, output_name_cmp, output->name);
|
2017-12-06 12:36:06 +01:00
|
|
|
if (i >= 0) {
|
2017-12-29 19:04:16 +01:00
|
|
|
// Merge existing config
|
|
|
|
struct output_config *current = config->output_configs->items[i];
|
|
|
|
merge_output_config(current, output);
|
2017-12-06 12:36:06 +01:00
|
|
|
free_output_config(output);
|
2017-12-29 19:04:16 +01:00
|
|
|
output = current;
|
2017-12-06 12:36:06 +01:00
|
|
|
} else {
|
|
|
|
list_add(config->output_configs, output);
|
|
|
|
}
|
|
|
|
|
2018-01-05 22:32:51 +01:00
|
|
|
wlr_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
|
2018-04-17 09:54:02 +02:00
|
|
|
"position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)",
|
2017-12-14 02:23:33 +01:00
|
|
|
output->name, output->enabled, output->width, output->height,
|
|
|
|
output->refresh_rate, output->x, output->y, output->scale,
|
2018-04-17 09:54:02 +02:00
|
|
|
output->transform, output->background, output->background_option, output->dpms_state);
|
2017-12-06 12:36:06 +01:00
|
|
|
|
2017-12-29 19:04:16 +01:00
|
|
|
// Try to find the output container and apply configuration now. If
|
|
|
|
// this is during startup then there will be no container and config
|
|
|
|
// will be applied during normal "new output" event from wlroots.
|
|
|
|
char identifier[128];
|
|
|
|
bool all = strcmp(output->name, "*") == 0;
|
2018-06-05 23:56:32 +02:00
|
|
|
list_t *sway_outputs = root_container.sway_root->outputs;
|
|
|
|
for (int i = 0; i < sway_outputs->length; ++i) {
|
|
|
|
struct sway_output *sway_output = sway_outputs->items[i];
|
|
|
|
output_get_identifier(identifier, sizeof(identifier), sway_output);
|
|
|
|
wlr_log(L_DEBUG, "Checking identifier %s", identifier);
|
|
|
|
if (all || strcmp(sway_output->wlr_output->name, output->name) == 0
|
|
|
|
|| strcmp(identifier, output->name) == 0) {
|
|
|
|
if (!sway_output->swayc) {
|
|
|
|
if (!output->enabled) {
|
|
|
|
if (!all) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
output_enable(sway_output);
|
|
|
|
}
|
2017-12-06 12:36:06 +01:00
|
|
|
|
2018-06-05 23:56:32 +02:00
|
|
|
apply_output_config(output, sway_output->swayc);
|
2017-12-29 19:04:16 +01:00
|
|
|
|
|
|
|
if (!all) {
|
|
|
|
// Stop looking if the output config isn't applicable to all
|
|
|
|
// outputs
|
|
|
|
break;
|
2017-12-06 12:36:06 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
|
|
|
|
|
|
|
fail:
|
2018-06-03 03:33:16 +02:00
|
|
|
config->handler_context.output_config = NULL;
|
2017-12-06 12:36:06 +01:00
|
|
|
free_output_config(output);
|
|
|
|
return error;
|
|
|
|
}
|