Add --custom to `output mode` command

This forces to set the mode as a custom mode.
master
Simon Ser 5 years ago committed by Brian Ashworth
parent eaee087c17
commit 38b37247ff

@ -198,6 +198,7 @@ struct output_config {
int enabled; int enabled;
int width, height; int width, height;
float refresh_rate; float refresh_rate;
int custom_mode;
int x, y; int x, y;
float scale; float scale;
int32_t transform; int32_t transform;

@ -12,6 +12,14 @@ struct cmd_results *output_cmd_mode(int argc, char **argv) {
struct output_config *output = config->handler_context.output_config; struct output_config *output = config->handler_context.output_config;
if (strcmp(argv[0], "--custom") == 0) {
argv++;
argc--;
output->custom_mode = 1;
} else {
output->custom_mode = 0;
}
char *end; char *end;
output->width = strtol(*argv, &end, 10); output->width = strtol(*argv, &end, 10);
if (*end) { if (*end) {

@ -42,6 +42,7 @@ struct output_config *new_output_config(const char *name) {
oc->enabled = -1; oc->enabled = -1;
oc->width = oc->height = -1; oc->width = oc->height = -1;
oc->refresh_rate = -1; oc->refresh_rate = -1;
oc->custom_mode = -1;
oc->x = oc->y = -1; oc->x = oc->y = -1;
oc->scale = -1; oc->scale = -1;
oc->transform = -1; oc->transform = -1;
@ -74,6 +75,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
if (src->refresh_rate != -1) { if (src->refresh_rate != -1) {
dst->refresh_rate = src->refresh_rate; dst->refresh_rate = src->refresh_rate;
} }
if (src->custom_mode != -1) {
dst->custom_mode = src->custom_mode;
}
if (src->transform != -1) { if (src->transform != -1) {
dst->transform = src->transform; dst->transform = src->transform;
} }
@ -202,11 +206,13 @@ struct output_config *store_output_config(struct output_config *oc) {
} }
static bool set_mode(struct wlr_output *output, int width, int height, static bool set_mode(struct wlr_output *output, int width, int height,
float refresh_rate) { float refresh_rate, bool custom) {
int mhz = (int)(refresh_rate * 1000); int mhz = (int)(refresh_rate * 1000);
if (wl_list_empty(&output->modes)) {
if (wl_list_empty(&output->modes) || custom) {
sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name); sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
return wlr_output_set_custom_mode(output, width, height, mhz); return wlr_output_set_custom_mode(output, width, height,
refresh_rate > 0 ? mhz : 0);
} }
struct wlr_output_mode *mode, *best = NULL; struct wlr_output_mode *mode, *best = NULL;
@ -261,8 +267,8 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
if (oc && oc->width > 0 && oc->height > 0) { if (oc && oc->width > 0 && oc->height > 0) {
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)", oc->name, oc->width, sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)", oc->name, oc->width,
oc->height, oc->refresh_rate); oc->height, oc->refresh_rate);
modeset_success = modeset_success = set_mode(wlr_output, oc->width, oc->height,
set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate); oc->refresh_rate, oc->custom_mode == 1);
} else if (!wl_list_empty(&wlr_output->modes)) { } else if (!wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *mode = struct wlr_output_mode *mode =
wl_container_of(wlr_output->modes.prev, mode, link); wl_container_of(wlr_output->modes.prev, mode, link);

@ -24,12 +24,16 @@ must be separated by one space. For example:
# COMMANDS # COMMANDS
*output* <name> mode|resolution|res <WIDTHxHEIGHT>[@<RATE>[Hz]] *output* <name> mode|resolution|res [--custom] <WIDTHxHEIGHT>[@<RATE>[Hz]]
Configures the specified output to use the given mode. Modes are a Configures the specified output to use the given mode. Modes are a
combination of width and height (in pixels) and a refresh rate that your combination of width and height (in pixels) and a refresh rate that your
display can be configured to use. For a list of available modes for each display can be configured to use. For a list of available modes for each
output, use *swaymsg -t get_outputs*. output, use *swaymsg -t get_outputs*.
To set a custom mode not listed in the list of available modes, use
*--custom*. You should probably only use this if you know what you're
doing.
Examples: Examples:
output HDMI-A-1 mode 1920x1080 output HDMI-A-1 mode 1920x1080

Loading…
Cancel
Save