sway-patched-tray-menu-github/sway/commands/output/transform.c
Brian Ashworth 88d96bc41f Combine output_by_name and output_by_identifier
This combines `output_by_name` and `output_by_identifier` into a single
function called `output_by_name_or_id`. This allows for output
identifiers to be used in all commands, simplifies the logic of the
callers, and is more efficient since worst case is a single pass through
the output list.
2018-12-20 19:55:29 +01:00

63 lines
2.3 KiB
C

#include <string.h>
#include "sway/commands.h"
#include "sway/config.h"
#include "log.h"
#include "sway/output.h"
struct cmd_results *output_cmd_transform(int argc, char **argv) {
if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "output", "Missing output config");
}
if (!argc) {
return cmd_results_new(CMD_INVALID, "output",
"Missing transform argument.");
}
enum wl_output_transform transform;
if (strcmp(*argv, "normal") == 0) {
transform = WL_OUTPUT_TRANSFORM_NORMAL;
} else if (strcmp(*argv, "90") == 0) {
transform = WL_OUTPUT_TRANSFORM_90;
} else if (strcmp(*argv, "180") == 0) {
transform = WL_OUTPUT_TRANSFORM_180;
} else if (strcmp(*argv, "270") == 0) {
transform = WL_OUTPUT_TRANSFORM_270;
} else if (strcmp(*argv, "flipped") == 0) {
transform = WL_OUTPUT_TRANSFORM_FLIPPED;
} else if (strcmp(*argv, "flipped-90") == 0) {
transform = WL_OUTPUT_TRANSFORM_FLIPPED_90;
} else if (strcmp(*argv, "flipped-180") == 0) {
transform = WL_OUTPUT_TRANSFORM_FLIPPED_180;
} else if (strcmp(*argv, "flipped-270") == 0) {
transform = WL_OUTPUT_TRANSFORM_FLIPPED_270;
} else {
return cmd_results_new(CMD_INVALID, "output",
"Invalid output transform.");
}
struct output_config *output = config->handler_context.output_config;
config->handler_context.leftovers.argc = argc - 1;
config->handler_context.leftovers.argv = argv + 1;
if (argc > 1 &&
(strcmp(argv[1], "clockwise") == 0 || strcmp(argv[1], "anticlockwise") == 0)) {
if (!sway_assert(output->name != NULL, "Output config name not set")) {
return NULL;
}
if (strcmp(output->name, "*") == 0) {
return cmd_results_new(CMD_INVALID, "output",
"Cannot apply relative transform to all outputs.");
}
struct sway_output *s_output = output_by_name_or_id(output->name);
if (s_output == NULL) {
return cmd_results_new(CMD_INVALID, "output",
"Cannot apply relative transform to unknown output %s", output->name);
}
if (strcmp(argv[1], "anticlockwise") == 0) {
transform = wlr_output_transform_invert(transform);
}
struct wlr_output *w_output = s_output->wlr_output;
transform = wlr_output_transform_compose(w_output->transform, transform);
config->handler_context.leftovers.argv += 1;
config->handler_context.leftovers.argc -= 1;
}
output->transform = transform;
return NULL;
}