diff options
author | emersion <contact@emersion.fr> | 2017-12-06 12:57:13 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2017-12-06 12:57:13 +0100 |
commit | 68ae989ceef0a144988c0a55b13aaacf514b957d (patch) | |
tree | 1b15d250117736185d287b65c4841163eaecff48 | |
parent | Add output config (diff) | |
download | sway-68ae989ceef0a144988c0a55b13aaacf514b957d.tar.gz sway-68ae989ceef0a144988c0a55b13aaacf514b957d.tar.zst sway-68ae989ceef0a144988c0a55b13aaacf514b957d.zip |
Init, merge output config params, use wlr_output_layout
-rw-r--r-- | include/sway/config.h | 3 | ||||
-rw-r--r-- | sway/commands/output.c | 4 | ||||
-rw-r--r-- | sway/config/output.c | 45 | ||||
-rw-r--r-- | sway/tree/container.c | 6 |
4 files changed, 33 insertions, 25 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 1b49c5c9..231356f2 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -84,7 +84,7 @@ struct output_config { | |||
84 | float refresh_rate; | 84 | float refresh_rate; |
85 | int x, y; | 85 | int x, y; |
86 | int scale; | 86 | int scale; |
87 | enum wl_output_transform transform; | 87 | int32_t transform; |
88 | 88 | ||
89 | char *background; | 89 | char *background; |
90 | char *background_option; | 90 | char *background_option; |
@@ -364,6 +364,7 @@ void apply_input_config(struct input_config *ic, struct libinput_device *dev); | |||
364 | void free_input_config(struct input_config *ic); | 364 | void free_input_config(struct input_config *ic); |
365 | 365 | ||
366 | int output_name_cmp(const void *item, const void *data); | 366 | int output_name_cmp(const void *item, const void *data); |
367 | void output_config_defaults(struct output_config *oc); | ||
367 | void merge_output_config(struct output_config *dst, struct output_config *src); | 368 | void merge_output_config(struct output_config *dst, struct output_config *src); |
368 | /** Sets up a WLC output handle based on a given output_config. | 369 | /** Sets up a WLC output handle based on a given output_config. |
369 | */ | 370 | */ |
diff --git a/sway/commands/output.c b/sway/commands/output.c index c964bef7..bbf8efc3 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c | |||
@@ -31,10 +31,8 @@ struct cmd_results *cmd_output(int argc, char **argv) { | |||
31 | if (!output) { | 31 | if (!output) { |
32 | return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config"); | 32 | return cmd_results_new(CMD_FAILURE, "output", "Unable to allocate output config"); |
33 | } | 33 | } |
34 | output->x = output->y = output->width = output->height = -1; | 34 | output_config_defaults(output); |
35 | output->name = strdup(name); | 35 | output->name = strdup(name); |
36 | output->enabled = -1; | ||
37 | output->scale = 1; | ||
38 | 36 | ||
39 | // TODO: atoi doesn't handle invalid numbers | 37 | // TODO: atoi doesn't handle invalid numbers |
40 | 38 | ||
diff --git a/sway/config/output.c b/sway/config/output.c index 02e18e59..4ed2c531 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <string.h> | 2 | #include <string.h> |
3 | #include <assert.h> | 3 | #include <assert.h> |
4 | #include <wlr/types/wlr_output.h> | 4 | #include <wlr/types/wlr_output.h> |
5 | #include <wlr/types/wlr_output_layout.h> | ||
5 | #include "sway/config.h" | 6 | #include "sway/config.h" |
6 | #include "sway/output.h" | 7 | #include "sway/output.h" |
7 | #include "log.h" | 8 | #include "log.h" |
@@ -13,6 +14,15 @@ int output_name_cmp(const void *item, const void *data) { | |||
13 | return strcmp(output->name, name); | 14 | return strcmp(output->name, name); |
14 | } | 15 | } |
15 | 16 | ||
17 | void output_config_defaults(struct output_config *oc) { | ||
18 | oc->enabled = -1; | ||
19 | oc->width = oc->height -1; | ||
20 | oc->refresh_rate = -1; | ||
21 | oc->x = oc->y = -1; | ||
22 | oc->scale = -1; | ||
23 | oc->transform = -1; | ||
24 | } | ||
25 | |||
16 | void merge_output_config(struct output_config *dst, struct output_config *src) { | 26 | void merge_output_config(struct output_config *dst, struct output_config *src) { |
17 | if (src->name) { | 27 | if (src->name) { |
18 | if (dst->name) { | 28 | if (dst->name) { |
@@ -38,6 +48,12 @@ void merge_output_config(struct output_config *dst, struct output_config *src) { | |||
38 | if (src->scale != -1) { | 48 | if (src->scale != -1) { |
39 | dst->scale = src->scale; | 49 | dst->scale = src->scale; |
40 | } | 50 | } |
51 | if (src->refresh_rate != -1) { | ||
52 | dst->refresh_rate = src->refresh_rate; | ||
53 | } | ||
54 | if (src->transform != -1) { | ||
55 | dst->transform = src->transform; | ||
56 | } | ||
41 | if (src->background) { | 57 | if (src->background) { |
42 | if (dst->background) { | 58 | if (dst->background) { |
43 | free(dst->background); | 59 | free(dst->background); |
@@ -86,29 +102,28 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { | |||
86 | set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate); | 102 | set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate); |
87 | } | 103 | } |
88 | if (oc && oc->scale > 0) { | 104 | if (oc && oc->scale > 0) { |
105 | sway_log(L_DEBUG, "Set %s scale to %d", oc->name, oc->scale); | ||
89 | wlr_output->scale = oc->scale; | 106 | wlr_output->scale = oc->scale; |
90 | } | 107 | } |
91 | if (oc && oc->transform != WL_OUTPUT_TRANSFORM_NORMAL) { | 108 | if (oc && oc->transform >= 0) { |
109 | sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform); | ||
92 | wlr_output_transform(wlr_output, oc->transform); | 110 | wlr_output_transform(wlr_output, oc->transform); |
93 | } | 111 | } |
94 | 112 | ||
95 | // Find position for it | 113 | // Find position for it |
96 | if (oc && oc->x != -1 && oc->y != -1) { | 114 | if (oc && (oc->x != -1 || oc->y != -1)) { |
97 | sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); | 115 | sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); |
98 | output->x = oc->x; | 116 | wlr_output_layout_add(root_container.output_layout, wlr_output, oc->x, |
99 | output->y = oc->y; | 117 | oc->y); |
100 | } else { | 118 | } else { |
101 | int x = 0; | 119 | wlr_output_layout_add_auto(root_container.output_layout, wlr_output); |
102 | for (int i = 0; i < root_container.children->length; ++i) { | ||
103 | swayc_t *c = root_container.children->items[i]; | ||
104 | if (c->type == C_OUTPUT) { | ||
105 | if (c->width + c->x > x) { | ||
106 | x = c->width + c->x; | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | output->x = x; | ||
111 | } | 120 | } |
121 | struct wlr_box *output_layout_box = | ||
122 | wlr_output_layout_get_box(root_container.output_layout, wlr_output); | ||
123 | output->x = output_layout_box->x; | ||
124 | output->y = output_layout_box->y; | ||
125 | output->width = output_layout_box->width; | ||
126 | output->height = output_layout_box->height; | ||
112 | 127 | ||
113 | if (!oc || !oc->background) { | 128 | if (!oc || !oc->background) { |
114 | // Look for a * config for background | 129 | // Look for a * config for background |
@@ -128,7 +143,7 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { | |||
128 | } | 143 | } |
129 | 144 | ||
130 | if (oc && oc->background) { | 145 | if (oc && oc->background) { |
131 | // TODO: swaybg | 146 | // TODO swaybg |
132 | /*if (output->bg_pid != 0) { | 147 | /*if (output->bg_pid != 0) { |
133 | terminate_swaybg(output->bg_pid); | 148 | terminate_swaybg(output->bg_pid); |
134 | } | 149 | } |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 7720718f..ba305efa 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -100,12 +100,6 @@ swayc_t *new_output(struct sway_output *sway_output) { | |||
100 | swayc_t *output = new_swayc(C_OUTPUT); | 100 | swayc_t *output = new_swayc(C_OUTPUT); |
101 | output->sway_output = sway_output; | 101 | output->sway_output = sway_output; |
102 | output->name = name ? strdup(name) : NULL; | 102 | output->name = name ? strdup(name) : NULL; |
103 | output->width = size.width; | ||
104 | output->height = size.width; | ||
105 | |||
106 | // TODO configure output layout position | ||
107 | wlr_output_layout_add_auto(root_container.output_layout, | ||
108 | sway_output->wlr_output); | ||
109 | 103 | ||
110 | apply_output_config(oc, output); | 104 | apply_output_config(oc, output); |
111 | 105 | ||