Skip to content

Commit

Permalink
Add support for manually setting subpixel order on outputs.
Browse files Browse the repository at this point in the history
Many laptop screens report unknown subpixel order. Allow users to manually set subpixel order to work around this.

Addresses swaywm#3163
  • Loading branch information
ggreer committed Feb 11, 2019
1 parent a64a3ee commit 6230211
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/sway/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ sway_cmd output_cmd_enable;
sway_cmd output_cmd_mode;
sway_cmd output_cmd_position;
sway_cmd output_cmd_scale;
sway_cmd output_cmd_subpixel;
sway_cmd output_cmd_transform;

sway_cmd seat_cmd_attach;
Expand Down
1 change: 1 addition & 0 deletions include/sway/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ struct output_config {
int x, y;
float scale;
int32_t transform;
enum wl_output_subpixel subpixel;

char *background;
char *background_option;
Expand Down
1 change: 1 addition & 0 deletions sway/commands/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static struct cmd_handler output_handlers[] = {
{ "res", output_cmd_mode },
{ "resolution", output_cmd_mode },
{ "scale", output_cmd_scale },
{ "subpixel", output_cmd_subpixel },
{ "transform", output_cmd_transform },
};

Expand Down
36 changes: 36 additions & 0 deletions sway/commands/output/subpixel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <string.h>
#include "sway/commands.h"
#include "sway/config.h"
#include "log.h"
#include "sway/output.h"

struct cmd_results *output_cmd_subpixel(int argc, char **argv) {
if (!config->handler_context.output_config) {
return cmd_results_new(CMD_FAILURE, "Missing output config");
}
if (!argc) {
return cmd_results_new(CMD_INVALID, "Missing subpixel argument.");
}
enum wl_output_subpixel subpixel;

if (strcmp(*argv, "rgb") == 0) {
subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB;
} else if (strcmp(*argv, "bgr") == 0) {
subpixel = WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR;
} else if (strcmp(*argv, "vrgb") == 0) {
subpixel = WL_OUTPUT_SUBPIXEL_VERTICAL_RGB;
} else if (strcmp(*argv, "vbgr") == 0) {
subpixel = WL_OUTPUT_SUBPIXEL_VERTICAL_BGR;
} else if (strcmp(*argv, "none") == 0) {
subpixel = WL_OUTPUT_SUBPIXEL_NONE;
} else {
return cmd_results_new(CMD_INVALID, "Invalid output subpixel.");
}

struct output_config *output = config->handler_context.output_config;
config->handler_context.leftovers.argc = argc - 1;
config->handler_context.leftovers.argv = argv + 1;

output->subpixel = subpixel;
return NULL;
}
17 changes: 14 additions & 3 deletions sway/config/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <unistd.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/util/subpixel.h>
#include "sway/config.h"
#include "sway/output.h"
#include "sway/tree/root.h"
Expand Down Expand Up @@ -42,6 +43,7 @@ struct output_config *new_output_config(const char *name) {
oc->x = oc->y = -1;
oc->scale = -1;
oc->transform = -1;
oc->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
return oc;
}

Expand All @@ -64,6 +66,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
if (src->scale != -1) {
dst->scale = src->scale;
}
if (src->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN) {
dst->subpixel = src->subpixel;
}
if (src->refresh_rate != -1) {
dst->refresh_rate = src->refresh_rate;
}
Expand Down Expand Up @@ -129,10 +134,10 @@ struct output_config *store_output_config(struct output_config *oc) {
}

sway_log(SWAY_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz "
"position %d,%d scale %f transform %d) (bg %s %s) (dpms %d)",
"position %d,%d scale %f subpixel %s transform %d) (bg %s %s) (dpms %d)",
oc->name, oc->enabled, oc->width, oc->height, oc->refresh_rate,
oc->x, oc->y, oc->scale, oc->transform, oc->background,
oc->background_option, oc->dpms_state);
oc->x, oc->y, oc->scale, wlr_wl_output_subpixel_to_string(oc->subpixel),
oc->transform, oc->background, oc->background_option, oc->dpms_state);

return oc;
}
Expand Down Expand Up @@ -225,6 +230,11 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
sway_log(SWAY_DEBUG, "Set %s scale to %f", oc->name, oc->scale);
wlr_output_set_scale(wlr_output, oc->scale);
}
if (oc && oc->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN) {
sway_log(SWAY_DEBUG, "Set %s subpixel to %s", oc->name,
wlr_wl_output_subpixel_to_string(oc->subpixel));
wlr_output_set_subpixel(wlr_output, oc->subpixel);
}
if (oc && oc->transform >= 0) {
sway_log(SWAY_DEBUG, "Set %s transform to %d", oc->name, oc->transform);
wlr_output_set_transform(wlr_output, oc->transform);
Expand Down Expand Up @@ -293,6 +303,7 @@ static void default_output_config(struct output_config *oc,
}
oc->x = oc->y = -1;
oc->scale = 1;
oc->subpixel = WL_OUTPUT_SUBPIXEL_UNKNOWN;
oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
}

Expand Down
3 changes: 3 additions & 0 deletions sway/ipc-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <sys/un.h>
#include <unistd.h>
#include <wayland-server.h>
#include <wlr/util/subpixel.h>
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/desktop/transaction.h"
Expand Down Expand Up @@ -644,6 +645,8 @@ void ipc_client_handle_command(struct ipc_client *client) {
json_object_object_add(output_json, "focused",
json_object_new_boolean(focused));

const char *subpixel = wlr_wl_output_subpixel_to_string(output->wlr_output->subpixel);
json_object_object_add(output_json, "subpixel order", json_object_new_string(subpixel));
json_object_array_add(outputs, output_json);
}
struct sway_output *output;
Expand Down
1 change: 1 addition & 0 deletions sway/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ sway_sources = files(
'commands/output/mode.c',
'commands/output/position.c',
'commands/output/scale.c',
'commands/output/subpixel.c',
'commands/output/transform.c',

'tree/arrange.c',
Expand Down

0 comments on commit 6230211

Please sign in to comment.