diff options
author | Tony Crisci <tony@dubstepdish.com> | 2017-12-16 07:33:23 -0500 |
---|---|---|
committer | Tony Crisci <tony@dubstepdish.com> | 2017-12-16 07:33:23 -0500 |
commit | 9fa70ce426a78921fa61f25f8b30a73a2a7d9ad7 (patch) | |
tree | 823cce0da3f7e0dc21c26bef7e639e8370e29b3d | |
parent | keyboard cleanup (diff) | |
parent | Merge pull request #1503 from emersion/output-config (diff) | |
download | sway-9fa70ce426a78921fa61f25f8b30a73a2a7d9ad7.tar.gz sway-9fa70ce426a78921fa61f25f8b30a73a2a7d9ad7.tar.zst sway-9fa70ce426a78921fa61f25f8b30a73a2a7d9ad7.zip |
Merge branch 'wlroots' into feature/input
-rw-r--r-- | include/sway/config.h | 6 | ||||
-rw-r--r-- | include/sway/container.h | 5 | ||||
-rw-r--r-- | include/sway/layout.h | 8 | ||||
-rw-r--r-- | include/sway/output.h | 2 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/output.c | 311 | ||||
-rw-r--r-- | sway/config/output.c | 185 | ||||
-rw-r--r-- | sway/desktop/output.c | 48 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 6 | ||||
-rw-r--r-- | sway/input/cursor.c | 3 | ||||
-rw-r--r-- | sway/main.c | 4 | ||||
-rw-r--r-- | sway/meson.build | 2 | ||||
-rw-r--r-- | sway/tree/container.c | 67 | ||||
-rw-r--r-- | sway/tree/layout.c | 37 |
14 files changed, 648 insertions, 37 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 9bfda259..777fb5a8 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -102,8 +102,11 @@ struct output_config { | |||
102 | char *name; | 102 | char *name; |
103 | int enabled; | 103 | int enabled; |
104 | int width, height; | 104 | int width, height; |
105 | float refresh_rate; | ||
105 | int x, y; | 106 | int x, y; |
106 | int scale; | 107 | int scale; |
108 | int32_t transform; | ||
109 | |||
107 | char *background; | 110 | char *background; |
108 | char *background_option; | 111 | char *background_option; |
109 | }; | 112 | }; |
@@ -391,9 +394,8 @@ struct seat_attachment_config *seat_config_get_attachment( | |||
391 | struct seat_config *seat_config, char *identifier); | 394 | struct seat_config *seat_config, char *identifier); |
392 | 395 | ||
393 | int output_name_cmp(const void *item, const void *data); | 396 | int output_name_cmp(const void *item, const void *data); |
397 | struct output_config *new_output_config(); | ||
394 | void merge_output_config(struct output_config *dst, struct output_config *src); | 398 | void merge_output_config(struct output_config *dst, struct output_config *src); |
395 | /** Sets up a WLC output handle based on a given output_config. | ||
396 | */ | ||
397 | void apply_output_config(struct output_config *oc, swayc_t *output); | 399 | void apply_output_config(struct output_config *oc, swayc_t *output); |
398 | void free_output_config(struct output_config *oc); | 400 | void free_output_config(struct output_config *oc); |
399 | 401 | ||
diff --git a/include/sway/container.h b/include/sway/container.h index f13745ee..9a5e312b 100644 --- a/include/sway/container.h +++ b/include/sway/container.h | |||
@@ -58,9 +58,9 @@ enum swayc_border_types { | |||
58 | B_NORMAL, /**< Normal border with title bar */ | 58 | B_NORMAL, /**< Normal border with title bar */ |
59 | }; | 59 | }; |
60 | 60 | ||
61 | struct sway_root; | ||
61 | struct sway_output; | 62 | struct sway_output; |
62 | struct sway_view; | 63 | struct sway_view; |
63 | struct wlr_output_layout; | ||
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Stores information about a container. | 66 | * Stores information about a container. |
@@ -70,7 +70,7 @@ struct wlr_output_layout; | |||
70 | struct sway_container { | 70 | struct sway_container { |
71 | union { | 71 | union { |
72 | // TODO: Encapsulate state for other node types as well like C_CONTAINER | 72 | // TODO: Encapsulate state for other node types as well like C_CONTAINER |
73 | struct wlr_output_layout *output_layout; // C_ROOT | 73 | struct sway_root *sway_root; // C_ROOT |
74 | struct sway_output *sway_output; // C_OUTPUT | 74 | struct sway_output *sway_output; // C_OUTPUT |
75 | struct sway_view *sway_view; // C_VIEW | 75 | struct sway_view *sway_view; // C_VIEW |
76 | }; | 76 | }; |
@@ -137,6 +137,7 @@ swayc_t *new_output(struct sway_output *sway_output); | |||
137 | swayc_t *new_workspace(swayc_t *output, const char *name); | 137 | swayc_t *new_workspace(swayc_t *output, const char *name); |
138 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view); | 138 | swayc_t *new_view(swayc_t *sibling, struct sway_view *sway_view); |
139 | 139 | ||
140 | swayc_t *destroy_output(swayc_t *output); | ||
140 | swayc_t *destroy_view(swayc_t *view); | 141 | swayc_t *destroy_view(swayc_t *view); |
141 | 142 | ||
142 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type); | 143 | swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type); |
diff --git a/include/sway/layout.h b/include/sway/layout.h index f3b62b05..bfd96a02 100644 --- a/include/sway/layout.h +++ b/include/sway/layout.h | |||
@@ -1,8 +1,16 @@ | |||
1 | #ifndef _SWAY_LAYOUT_H | 1 | #ifndef _SWAY_LAYOUT_H |
2 | #define _SWAY_LAYOUT_H | 2 | #define _SWAY_LAYOUT_H |
3 | 3 | ||
4 | #include <wlr/types/wlr_output_layout.h> | ||
5 | |||
4 | struct sway_container; | 6 | struct sway_container; |
5 | 7 | ||
8 | struct sway_root { | ||
9 | struct wlr_output_layout *output_layout; | ||
10 | |||
11 | struct wl_listener output_layout_change; | ||
12 | }; | ||
13 | |||
6 | void init_layout(void); | 14 | void init_layout(void); |
7 | void add_child(struct sway_container *parent, struct sway_container *child); | 15 | void add_child(struct sway_container *parent, struct sway_container *child); |
8 | struct sway_container *remove_child(struct sway_container *child); | 16 | struct sway_container *remove_child(struct sway_container *child); |
diff --git a/include/sway/output.h b/include/sway/output.h index 895cb07d..7ca02d7b 100644 --- a/include/sway/output.h +++ b/include/sway/output.h | |||
@@ -12,8 +12,8 @@ struct sway_output { | |||
12 | struct sway_container *swayc; | 12 | struct sway_container *swayc; |
13 | struct sway_server *server; | 13 | struct sway_server *server; |
14 | struct timespec last_frame; | 14 | struct timespec last_frame; |
15 | |||
15 | struct wl_listener frame; | 16 | struct wl_listener frame; |
16 | struct wl_listener resolution; | ||
17 | }; | 17 | }; |
18 | 18 | ||
19 | #endif | 19 | #endif |
diff --git a/sway/commands.c b/sway/commands.c index b8948fb7..7485f2f6 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -132,6 +132,7 @@ static struct cmd_handler handlers[] = { | |||
132 | { "exit", cmd_exit }, | 132 | { "exit", cmd_exit }, |
133 | { "include", cmd_include }, | 133 | { "include", cmd_include }, |
134 | { "input", cmd_input }, | 134 | { "input", cmd_input }, |
135 | { "output", cmd_output }, | ||
135 | { "seat", cmd_seat }, | 136 | { "seat", cmd_seat }, |
136 | }; | 137 | }; |
137 | 138 | ||
diff --git a/sway/commands/output.c b/sway/commands/output.c new file mode 100644 index 00000000..d71e4d8d --- /dev/null +++ b/sway/commands/output.c | |||
@@ -0,0 +1,311 @@ | |||
1 | #define _XOPEN_SOURCE 500 | ||
2 | #include <ctype.h> | ||
3 | #include <libgen.h> | ||
4 | #include <stdlib.h> | ||
5 | #include <string.h> | ||
6 | #include <strings.h> | ||
7 | #include <unistd.h> | ||
8 | #include <wordexp.h> | ||
9 | #include "sway/commands.h" | ||
10 | #include "sway/config.h" | ||
11 | #include "list.h" | ||
12 | #include "log.h" | ||
13 | #include "stringop.h" | ||
14 | |||
15 | static char *bg_options[] = { | ||
16 | "stretch", | ||
17 | "center", | ||
18 | "fill", | ||
19 | "fit", | ||
20 | "tile", | ||
21 | }; | ||
22 | |||
23 | struct cmd_results *cmd_output(int argc, char **argv) { | ||
24 | struct cmd_results *error = NULL; | ||
25 | if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { | ||
26 | return error; | ||
27 | } | ||
28 | const char *name = argv[0]; | ||
29 | |||
30 | struct output_config *output = new_output_config(); | ||
31 | if (!output) { | ||
32 | sway_log(L_ERROR, "Failed to allocate output config"); | ||
33 | return NULL; | ||
34 | } | ||
35 | output->name = strdup(name); | ||
36 | |||
37 | int i; | ||
38 | for (i = 1; i < argc; ++i) { | ||
39 | const char *command = argv[i]; | ||
40 | |||
41 | if (strcasecmp(command, "disable") == 0) { | ||
42 | output->enabled = 0; | ||
43 | } else if (strcasecmp(command, "mode") == 0 || | ||
44 | strcasecmp(command, "resolution") == 0 || | ||
45 | strcasecmp(command, "res") == 0) { | ||
46 | if (++i >= argc) { | ||
47 | error = cmd_results_new(CMD_INVALID, "output", | ||
48 | "Missing mode argument."); | ||
49 | goto fail; | ||
50 | } | ||
51 | |||
52 | int width = -1, height = -1; | ||
53 | float refresh_rate = -1; | ||
54 | |||
55 | char *end; | ||
56 | width = strtol(argv[i], &end, 10); | ||
57 | if (*end) { | ||
58 | // Format is 1234x4321 | ||
59 | if (*end != 'x') { | ||
60 | error = cmd_results_new(CMD_INVALID, "output", | ||
61 | "Invalid mode width."); | ||
62 | goto fail; | ||
63 | } | ||
64 | ++end; | ||
65 | height = strtol(end, &end, 10); | ||
66 | if (*end) { | ||
67 | if (*end != '@') { | ||
68 | error = cmd_results_new(CMD_INVALID, "output", | ||
69 | "Invalid mode height."); | ||
70 | goto fail; | ||
71 | } | ||
72 | ++end; | ||
73 | refresh_rate = strtof(end, &end); | ||
74 | if (strcasecmp("Hz", end) != 0) { | ||
75 | error = cmd_results_new(CMD_INVALID, "output", | ||
76 | "Invalid mode refresh rate."); | ||
77 | goto fail; | ||
78 | } | ||
79 | } | ||
80 | } else { | ||
81 | // Format is 1234 4321 | ||
82 | if (++i >= argc) { | ||
83 | error = cmd_results_new(CMD_INVALID, "output", | ||
84 | "Missing mode argument (height)."); | ||
85 | goto fail; | ||
86 | } | ||
87 | height = strtol(argv[i], &end, 10); | ||
88 | if (*end) { | ||
89 | error = cmd_results_new(CMD_INVALID, "output", | ||
90 | "Invalid mode height."); | ||
91 | goto fail; | ||
92 | } | ||
93 | } | ||
94 | output->width = width; | ||
95 | output->height = height; | ||
96 | output->refresh_rate = refresh_rate; | ||
97 | } else if (strcasecmp(command, "position") == 0 || | ||
98 | strcasecmp(command, "pos") == 0) { | ||
99 | if (++i >= argc) { | ||
100 | error = cmd_results_new(CMD_INVALID, "output", | ||
101 | "Missing position argument."); | ||
102 | goto fail; | ||
103 | } | ||
104 | |||
105 | int x = -1, y = -1; | ||
106 | |||
107 | char *end; | ||
108 | x = strtol(argv[i], &end, 10); | ||
109 | if (*end) { | ||
110 | // Format is 1234,4321 | ||
111 | if (*end != ',') { | ||
112 | error = cmd_results_new(CMD_INVALID, "output", | ||
113 | "Invalid position x."); | ||
114 | goto fail; | ||
115 | } | ||
116 | ++end; | ||
117 | y = strtol(end, &end, 10); | ||
118 | if (*end) { | ||
119 | error = cmd_results_new(CMD_INVALID, "output", | ||
120 | "Invalid position y."); | ||
121 | goto fail; | ||
122 | } | ||
123 | } else { | ||
124 | // Format is 1234 4321 (legacy) | ||
125 | if (++i >= argc) { | ||
126 | error = cmd_results_new(CMD_INVALID, "output", | ||
127 | "Missing position argument (y)."); | ||
128 | goto fail; | ||
129 | } | ||
130 | y = strtol(argv[i], &end, 10); | ||
131 | if (*end) { | ||
132 | error = cmd_results_new(CMD_INVALID, "output", | ||
133 | "Invalid position y."); | ||
134 | goto fail; | ||
135 | } | ||
136 | } | ||
137 | |||
138 | output->x = x; | ||
139 | output->y = y; | ||
140 | } else if (strcasecmp(command, "scale") == 0) { | ||
141 | if (++i >= argc) { | ||
142 | error = cmd_results_new(CMD_INVALID, "output", | ||
143 | "Missing scale parameter."); | ||
144 | goto fail; | ||
145 | } | ||
146 | char *end; | ||
147 | output->scale = strtol(argv[i], &end, 10); | ||
148 | if (*end) { | ||
149 | error = cmd_results_new(CMD_INVALID, "output", | ||
150 | "Invalid scale."); | ||
151 | goto fail; | ||
152 | } | ||
153 | } else if (strcasecmp(command, "transform") == 0) { | ||
154 | if (++i >= argc) { | ||
155 | error = cmd_results_new(CMD_INVALID, "output", | ||
156 | "Missing transform parameter."); | ||
157 | goto fail; | ||
158 | } | ||
159 | char *value = argv[i]; | ||
160 | if (strcmp(value, "normal") == 0) { | ||
161 | output->transform = WL_OUTPUT_TRANSFORM_NORMAL; | ||
162 | } else if (strcmp(value, "90") == 0) { | ||
163 | output->transform = WL_OUTPUT_TRANSFORM_90; | ||
164 | } else if (strcmp(value, "180") == 0) { | ||
165 | output->transform = WL_OUTPUT_TRANSFORM_180; | ||
166 | } else if (strcmp(value, "270") == 0) { | ||
167 | output->transform = WL_OUTPUT_TRANSFORM_270; | ||
168 | } else if (strcmp(value, "flipped") == 0) { | ||
169 | output->transform = WL_OUTPUT_TRANSFORM_FLIPPED; | ||
170 | } else if (strcmp(value, "flipped-90") == 0) { | ||
171 | output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_90; | ||
172 | } else if (strcmp(value, "flipped-180") == 0) { | ||
173 | output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_180; | ||
174 | } else if (strcmp(value, "flipped-270") == 0) { | ||
175 | output->transform = WL_OUTPUT_TRANSFORM_FLIPPED_270; | ||
176 | } else { | ||
177 | error = cmd_results_new(CMD_INVALID, "output", | ||
178 | "Invalid output transform."); | ||
179 | goto fail; | ||
180 | } | ||
181 | } else if (strcasecmp(command, "background") == 0 || | ||
182 | strcasecmp(command, "bg") == 0) { | ||
183 | wordexp_t p; | ||
184 | if (++i >= argc) { | ||
185 | error = cmd_results_new(CMD_INVALID, "output", | ||
186 | "Missing background file or color specification."); | ||
187 | goto fail; | ||
188 | } | ||
189 | if (i + 1 >= argc) { | ||
190 | error = cmd_results_new(CMD_INVALID, "output", | ||
191 | "Missing background scaling mode or `solid_color`."); | ||
192 | goto fail; | ||
193 | } | ||
194 | if (strcasecmp(argv[i + 1], "solid_color") == 0) { | ||
195 | output->background = strdup(argv[argc - 2]); | ||
196 | output->background_option = strdup("solid_color"); | ||
197 | } else { | ||
198 | // argv[i+j]=bg_option | ||
199 | bool valid = false; | ||
200 | char *mode; | ||
201 | size_t j; | ||
202 | for (j = 0; j < (size_t) (argc - i); ++j) { | ||
203 | mode = argv[i + j]; | ||
204 | size_t n = sizeof(bg_options) / sizeof(char *); | ||
205 | for (size_t k = 0; k < n; ++k) { | ||
206 | if (strcasecmp(mode, bg_options[k]) == 0) { | ||
207 | valid = true; | ||
208 | break; | ||
209 | } | ||
210 | } | ||
211 | if (valid) { | ||
212 | break; | ||
213 | } | ||
214 | } | ||
215 | if (!valid) { | ||
216 | error = cmd_results_new(CMD_INVALID, "output", | ||
217 | "Missing background scaling mode."); | ||
218 | goto fail; | ||
219 | } | ||
220 | |||
221 | char *src = join_args(argv + i, j); | ||
222 | if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { | ||
223 | error = cmd_results_new(CMD_INVALID, "output", | ||
224 | "Invalid syntax (%s).", src); | ||
225 | goto fail; | ||
226 | } | ||
227 | free(src); | ||
228 | src = p.we_wordv[0]; | ||
229 | if (config->reading && *src != '/') { | ||
230 | char *conf = strdup(config->current_config); | ||
231 | if (conf) { | ||
232 | char *conf_path = dirname(conf); | ||
233 | src = malloc(strlen(conf_path) + strlen(src) + 2); | ||
234 | if (src) { | ||
235 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | ||
236 | } else { | ||
237 | sway_log(L_ERROR, | ||
238 | "Unable to allocate background source"); | ||
239 | } | ||
240 | free(conf); | ||
241 | } else { | ||
242 | sway_log(L_ERROR, | ||
243 | "Unable to allocate background source"); | ||
244 | } | ||
245 | } | ||
246 | if (!src || access(src, F_OK) == -1) { | ||
247 | error = cmd_results_new(CMD_INVALID, "output", | ||
248 | "Background file unreadable (%s).", src); | ||
249 | wordfree(&p); | ||
250 | goto fail; | ||
251 | } | ||
252 | |||
253 | output->background = strdup(src); | ||
254 | output->background_option = strdup(mode); | ||
255 | if (src != p.we_wordv[0]) { | ||
256 | free(src); | ||
257 | } | ||
258 | wordfree(&p); | ||
259 | |||
260 | i += j; | ||
261 | } | ||
262 | } else { | ||
263 | error = cmd_results_new(CMD_INVALID, "output", | ||
264 | "Invalid output subcommand: %s.", command); | ||
265 | goto fail; | ||
266 | } | ||
267 | } | ||
268 | |||
269 | i = list_seq_find(config->output_configs, output_name_cmp, name); | ||
270 | if (i >= 0) { | ||
271 | // merge existing config | ||
272 | struct output_config *oc = config->output_configs->items[i]; | ||
273 | merge_output_config(oc, output); | ||
274 | free_output_config(output); | ||
275 | output = oc; | ||
276 | } else { | ||
277 | list_add(config->output_configs, output); | ||
278 | } | ||
279 | |||
280 | sway_log(L_DEBUG, "Config stored for output %s (enabled: %d) (%dx%d@%fHz " | ||
281 | "position %d,%d scale %d transform %d) (bg %s %s)", | ||
282 | output->name, output->enabled, output->width, output->height, | ||
283 | output->refresh_rate, output->x, output->y, output->scale, | ||
284 | output->transform, output->background, output->background_option); | ||
285 | |||
286 | if (output->name) { | ||
287 | // Try to find the output container and apply configuration now. If | ||
288 | // this is during startup then there will be no container and config | ||
289 | // will be applied during normal "new output" event from wlroots. | ||
290 | swayc_t *cont = NULL; | ||
291 | for (int i = 0; i < root_container.children->length; ++i) { | ||
292 | cont = root_container.children->items[i]; | ||
293 | if (cont->name && ((strcmp(cont->name, output->name) == 0) || | ||
294 | (strcmp(output->name, "*") == 0))) { | ||
295 | apply_output_config(output, cont); | ||
296 | |||
297 | if (strcmp(output->name, "*") != 0) { | ||
298 | // Stop looking if the output config isn't applicable to all | ||
299 | // outputs | ||
300 | break; | ||
301 | } | ||
302 | } | ||
303 | } | ||
304 | } | ||
305 | |||
306 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
307 | |||
308 | fail: | ||
309 | free_output_config(output); | ||
310 | return error; | ||
311 | } | ||
diff --git a/sway/config/output.c b/sway/config/output.c new file mode 100644 index 00000000..dc9ee37c --- /dev/null +++ b/sway/config/output.c | |||
@@ -0,0 +1,185 @@ | |||
1 | #define _XOPEN_SOURCE 700 | ||
2 | #include <string.h> | ||
3 | #include <assert.h> | ||
4 | #include <wlr/types/wlr_output.h> | ||
5 | #include <wlr/types/wlr_output_layout.h> | ||
6 | #include "sway/config.h" | ||
7 | #include "sway/output.h" | ||
8 | #include "log.h" | ||
9 | |||
10 | int output_name_cmp(const void *item, const void *data) { | ||
11 | const struct output_config *output = item; | ||
12 | const char *name = data; | ||
13 | |||
14 | return strcmp(output->name, name); | ||
15 | } | ||
16 | |||
17 | struct output_config *new_output_config() { | ||
18 | struct output_config *oc = calloc(1, sizeof(struct output_config)); | ||
19 | if (oc == NULL) { | ||
20 | return NULL; | ||
21 | } | ||
22 | oc->enabled = -1; | ||
23 | oc->width = oc->height = -1; | ||
24 | oc->refresh_rate = -1; | ||
25 | oc->x = oc->y = -1; | ||
26 | oc->scale = -1; | ||
27 | oc->transform = -1; | ||
28 | return oc; | ||
29 | } | ||
30 | |||
31 | void merge_output_config(struct output_config *dst, struct output_config *src) { | ||
32 | if (src->name) { | ||
33 | free(dst->name); | ||
34 | dst->name = strdup(src->name); | ||
35 | } | ||
36 | if (src->enabled != -1) { | ||
37 | dst->enabled = src->enabled; | ||
38 | } | ||
39 | if (src->width != -1) { | ||
40 | dst->width = src->width; | ||
41 | } | ||
42 | if (src->height != -1) { | ||
43 | dst->height = src->height; | ||
44 | } | ||
45 | if (src->x != -1) { | ||
46 | dst->x = src->x; | ||
47 | } | ||
48 | if (src->y != -1) { | ||
49 | dst->y = src->y; | ||
50 | } | ||
51 | if (src->scale != -1) { | ||
52 | dst->scale = src->scale; | ||
53 | } | ||
54 | if (src->refresh_rate != -1) { | ||
55 | dst->refresh_rate = src->refresh_rate; | ||
56 | } | ||
57 | if (src->transform != -1) { | ||
58 | dst->transform = src->transform; | ||
59 | } | ||
60 | if (src->background) { | ||
61 | free(dst->background); | ||
62 | dst->background = strdup(src->background); | ||
63 | } | ||
64 | if (src->background_option) { | ||
65 | free(dst->background_option); | ||
66 | dst->background_option = strdup(src->background_option); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | static void set_mode(struct wlr_output *output, int width, int height, | ||
71 | float refresh_rate) { | ||
72 | int mhz = (int)(refresh_rate * 1000); | ||
73 | if (wl_list_empty(&output->modes)) { | ||
74 | sway_log(L_DEBUG, "Assigning custom mode to %s", output->name); | ||
75 | wlr_output_set_custom_mode(output, width, height, mhz); | ||
76 | return; | ||
77 | } | ||
78 | |||
79 | struct wlr_output_mode *mode, *best = NULL; | ||
80 | wl_list_for_each(mode, &output->modes, link) { | ||
81 | if (mode->width == width && mode->height == height) { | ||
82 | if (mode->refresh == mhz) { | ||
83 | best = mode; | ||
84 | break; | ||
85 | } | ||
86 | best = mode; | ||
87 | } | ||
88 | } | ||
89 | if (!best) { | ||
90 | sway_log(L_ERROR, "Configured mode for %s not available", output->name); | ||
91 | } else { | ||
92 | sway_log(L_DEBUG, "Assigning configured mode to %s", output->name); | ||
93 | wlr_output_set_mode(output, best); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | void apply_output_config(struct output_config *oc, swayc_t *output) { | ||
98 | assert(output->type == C_OUTPUT); | ||
99 | |||
100 | struct wlr_output *wlr_output = output->sway_output->wlr_output; | ||
101 | if (oc && oc->enabled == 0) { | ||
102 | wlr_output_layout_remove(root_container.sway_root->output_layout, | ||
103 | wlr_output); | ||
104 | destroy_output(output); | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | if (oc && oc->width > 0 && oc->height > 0) { | ||
109 | sway_log(L_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width, | ||
110 | oc->height, oc->refresh_rate); | ||
111 | set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate); | ||
112 | } | ||
113 | if (oc && oc->scale > 0) { | ||
114 | sway_log(L_DEBUG, "Set %s scale to %d", oc->name, oc->scale); | ||
115 | wlr_output_set_scale(wlr_output, oc->scale); | ||
116 | } | ||
117 | if (oc && oc->transform >= 0) { | ||
118 | sway_log(L_DEBUG, "Set %s transform to %d", oc->name, oc->transform); | ||
119 | wlr_output_set_transform(wlr_output, oc->transform); | ||
120 | } | ||
121 | |||
122 | // Find position for it | ||
123 | if (oc && (oc->x != -1 || oc->y != -1)) { | ||
124 | sway_log(L_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); | ||
125 | wlr_output_layout_add(root_container.sway_root->output_layout, | ||
126 | wlr_output, oc->x, oc->y); | ||
127 | } else { | ||
128 | wlr_output_layout_add_auto(root_container.sway_root->output_layout, | ||
129 | wlr_output); | ||
130 | } | ||
131 | |||
132 | if (!oc || !oc->background) { | ||
133 | // Look for a * config for background | ||
134 | int i = list_seq_find(config->output_configs, output_name_cmp, "*"); | ||
135 | if (i >= 0) { | ||
136 | oc = config->output_configs->items[i]; | ||
137 | } else { | ||
138 | oc = NULL; | ||
139 | } | ||
140 | } | ||
141 | |||
142 | int output_i; | ||
143 | for (output_i = 0; output_i < root_container.children->length; ++output_i) { | ||
144 | if (root_container.children->items[output_i] == output) { | ||
145 | break; | ||
146 | } | ||
147 | } | ||
148 | |||
149 | if (oc && oc->background) { | ||
150 | // TODO swaybg | ||
151 | /*if (output->bg_pid != 0) { | ||
152 | terminate_swaybg(output->bg_pid); | ||
153 | } | ||
154 | |||
155 | sway_log(L_DEBUG, "Setting background for output %d to %s", output_i, oc->background); | ||
156 | |||
157 | size_t bufsize = 12; | ||
158 | char output_id[bufsize]; | ||
159 | snprintf(output_id, bufsize, "%d", output_i); | ||
160 | output_id[bufsize-1] = 0; | ||
161 | |||
162 | char *const cmd[] = { | ||
163 | "swaybg", | ||
164 | output_id, | ||
165 | oc->background, | ||
166 | oc->background_option, | ||
167 | NULL, | ||
168 | }; | ||
169 | |||
170 | output->bg_pid = fork(); | ||
171 | if (output->bg_pid == 0) { | ||
172 | execvp(cmd[0], cmd); | ||
173 | }*/ | ||
174 | } | ||
175 | } | ||
176 | |||
177 | void free_output_config(struct output_config *oc) { | ||
178 | if (!oc) { | ||
179 | return; | ||
180 | } | ||
181 | free(oc->name); | ||
182 | free(oc->background); | ||
183 | free(oc->background_option); | ||
184 | free(oc); | ||
185 | } | ||
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index af067326..3b87c2e7 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -88,8 +88,7 @@ static void output_frame_view(swayc_t *view, void *data) { | |||
88 | } | 88 | } |
89 | 89 | ||
90 | static void output_frame_notify(struct wl_listener *listener, void *data) { | 90 | static void output_frame_notify(struct wl_listener *listener, void *data) { |
91 | struct sway_output *soutput = wl_container_of( | 91 | struct sway_output *soutput = wl_container_of(listener, soutput, frame); |
92 | listener, soutput, frame); | ||
93 | struct wlr_output *wlr_output = data; | 92 | struct wlr_output *wlr_output = data; |
94 | struct sway_server *server = soutput->server; | 93 | struct sway_server *server = soutput->server; |
95 | 94 | ||
@@ -108,42 +107,53 @@ static void output_frame_notify(struct wl_listener *listener, void *data) { | |||
108 | soutput->last_frame = now; | 107 | soutput->last_frame = now; |
109 | } | 108 | } |
110 | 109 | ||
111 | static void output_resolution_notify(struct wl_listener *listener, void *data) { | ||
112 | struct sway_output *soutput = wl_container_of( | ||
113 | listener, soutput, resolution); | ||
114 | arrange_windows(soutput->swayc, -1, -1); | ||
115 | } | ||
116 | |||
117 | void output_add_notify(struct wl_listener *listener, void *data) { | 110 | void output_add_notify(struct wl_listener *listener, void *data) { |
118 | struct sway_server *server = wl_container_of(listener, server, output_add); | 111 | struct sway_server *server = wl_container_of(listener, server, output_add); |
119 | struct wlr_output *wlr_output = data; | 112 | struct wlr_output *wlr_output = data; |
120 | sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); | 113 | sway_log(L_DEBUG, "New output %p: %s", wlr_output, wlr_output->name); |
121 | 114 | ||
122 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); | 115 | struct sway_output *output = calloc(1, sizeof(struct sway_output)); |
116 | if (!output) { | ||
117 | return; | ||
118 | } | ||
123 | output->wlr_output = wlr_output; | 119 | output->wlr_output = wlr_output; |
124 | output->server = server; | 120 | output->server = server; |
125 | output->swayc = new_output(output); | ||
126 | 121 | ||
127 | if (wl_list_length(&wlr_output->modes) > 0) { | 122 | if (!wl_list_empty(&wlr_output->modes)) { |
128 | struct wlr_output_mode *mode = NULL; | 123 | struct wlr_output_mode *mode = |
129 | mode = wl_container_of((&wlr_output->modes)->prev, mode, link); | 124 | wl_container_of(wlr_output->modes.prev, mode, link); |
130 | wlr_output_set_mode(wlr_output, mode); | 125 | wlr_output_set_mode(wlr_output, mode); |
131 | } | 126 | } |
132 | 127 | ||
133 | output->frame.notify = output_frame_notify; | 128 | output->swayc = new_output(output); |
134 | wl_signal_add(&wlr_output->events.frame, &output->frame); | 129 | if (!output->swayc) { |
135 | 130 | free(output); | |
136 | output->resolution.notify = output_resolution_notify; | 131 | return; |
137 | wl_signal_add(&wlr_output->events.resolution, &output->resolution); | 132 | } |
138 | 133 | ||
139 | sway_input_manager_configure_xcursor(input_manager); | 134 | sway_input_manager_configure_xcursor(input_manager); |
140 | 135 | ||
141 | arrange_windows(output->swayc, -1, -1); | 136 | output->frame.notify = output_frame_notify; |
137 | wl_signal_add(&wlr_output->events.frame, &output->frame); | ||
142 | } | 138 | } |
143 | 139 | ||
144 | void output_remove_notify(struct wl_listener *listener, void *data) { | 140 | void output_remove_notify(struct wl_listener *listener, void *data) { |
145 | struct sway_server *server = wl_container_of(listener, server, output_remove); | 141 | struct sway_server *server = wl_container_of(listener, server, output_remove); |
146 | struct wlr_output *wlr_output = data; | 142 | struct wlr_output *wlr_output = data; |
147 | sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); | 143 | sway_log(L_DEBUG, "Output %p %s removed", wlr_output, wlr_output->name); |
148 | // TODO | 144 | |
145 | swayc_t *output_container = NULL; | ||
146 | for (int i = 0 ; i < root_container.children->length; ++i) { | ||
147 | swayc_t *child = root_container.children->items[i]; | ||
148 | if (child->type == C_OUTPUT && | ||
149 | child->sway_output->wlr_output == wlr_output) { | ||
150 | output_container = child; | ||
151 | break; | ||
152 | } | ||
153 | } | ||
154 | if (!output_container) { | ||
155 | return; | ||
156 | } | ||
157 | |||
158 | destroy_output(output_container); | ||
149 | } | 159 | } |
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index a7e84aa1..29bed955 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -57,7 +57,7 @@ static void set_position(struct sway_view *view, double ox, double oy) { | |||
57 | if (!sway_assert(root, "output must be within tree to set position")) { | 57 | if (!sway_assert(root, "output must be within tree to set position")) { |
58 | return; | 58 | return; |
59 | } | 59 | } |
60 | struct wlr_output_layout *layout = root->output_layout; | 60 | struct wlr_output_layout *layout = root->sway_root->output_layout; |
61 | struct wlr_output_layout_output *loutput = | 61 | struct wlr_output_layout_output *loutput = |
62 | wlr_output_layout_get(layout, output->sway_output->wlr_output); | 62 | wlr_output_layout_get(layout, output->sway_output->wlr_output); |
63 | if (!sway_assert(loutput, "output must be within layout to set position")) { | 63 | if (!sway_assert(loutput, "output must be within layout to set position")) { |
@@ -149,14 +149,14 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { | |||
149 | // TODO remove from the tree when the surface goes away (unmapped) | 149 | // TODO remove from the tree when the surface goes away (unmapped) |
150 | sway_view->surface = xsurface->surface; | 150 | sway_view->surface = xsurface->surface; |
151 | sway_surface->view = sway_view; | 151 | sway_surface->view = sway_view; |
152 | 152 | ||
153 | // TODO: | 153 | // TODO: |
154 | // - Wire up listeners | 154 | // - Wire up listeners |
155 | // - Handle popups | 155 | // - Handle popups |
156 | // - Look up pid and open on appropriate workspace | 156 | // - Look up pid and open on appropriate workspace |
157 | // - Set new view to maximized so it behaves nicely | 157 | // - Set new view to maximized so it behaves nicely |
158 | // - Criteria | 158 | // - Criteria |
159 | 159 | ||
160 | sway_surface->commit.notify = handle_commit; | 160 | sway_surface->commit.notify = handle_commit; |
161 | wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit); | 161 | wl_signal_add(&xsurface->surface->events.commit, &sway_surface->commit); |
162 | sway_surface->destroy.notify = handle_destroy; | 162 | sway_surface->destroy.notify = handle_destroy; |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 3aa2d1bc..24d4642d 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -140,7 +140,8 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) { | |||
140 | } | 140 | } |
141 | 141 | ||
142 | cursor->seat = seat; | 142 | cursor->seat = seat; |
143 | wlr_cursor_attach_output_layout(wlr_cursor, root_container.output_layout); | 143 | wlr_cursor_attach_output_layout(wlr_cursor, |
144 | root_container.sway_root->output_layout); | ||
144 | 145 | ||
145 | // input events | 146 | // input events |
146 | wl_signal_add(&wlr_cursor->events.motion, &cursor->motion); | 147 | wl_signal_add(&wlr_cursor->events.motion, &cursor->motion); |
diff --git a/sway/main.c b/sway/main.c index 25032aa0..bd69395a 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -406,6 +406,10 @@ int main(int argc, char **argv) { | |||
406 | 406 | ||
407 | security_sanity_check(); | 407 | security_sanity_check(); |
408 | 408 | ||
409 | // TODO: wait for server to be ready | ||
410 | // TODO: consume config->cmd_queue | ||
411 | config->active = true; | ||
412 | |||
409 | if (!terminate_request) { | 413 | if (!terminate_request) { |
410 | server_run(&server); | 414 | server_run(&server); |
411 | } | 415 | } |
diff --git a/sway/meson.build b/sway/meson.build index c81e1c2c..c1f75b13 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -29,7 +29,9 @@ sway_sources = files( | |||
29 | 'commands/input/xkb_options.c', | 29 | 'commands/input/xkb_options.c', |
30 | 'commands/input/xkb_rules.c', | 30 | 'commands/input/xkb_rules.c', |
31 | 'commands/input/xkb_variant.c', | 31 | 'commands/input/xkb_variant.c', |
32 | 'commands/output.c', | ||
32 | 'config.c', | 33 | 'config.c', |
34 | 'config/output.c', | ||
33 | 'ipc-json.c', | 35 | 'ipc-json.c', |
34 | 'ipc-server.c', | 36 | 'ipc-server.c', |
35 | 'desktop/output.c', | 37 | 'desktop/output.c', |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 78c8625f..6f2a3abf 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -2,11 +2,14 @@ | |||
2 | #include <stdint.h> | 2 | #include <stdint.h> |
3 | #include <stdlib.h> | 3 | #include <stdlib.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include <strings.h> | ||
5 | #include <wlr/types/wlr_output_layout.h> | 6 | #include <wlr/types/wlr_output_layout.h> |
6 | #include <wlr/types/wlr_wl_shell.h> | 7 | #include <wlr/types/wlr_wl_shell.h> |
8 | #include "sway/config.h" | ||
7 | #include "sway/container.h" | 9 | #include "sway/container.h" |
8 | #include "sway/layout.h" | 10 | #include "sway/layout.h" |
9 | #include "sway/output.h" | 11 | #include "sway/output.h" |
12 | #include "sway/server.h" | ||
10 | #include "sway/view.h" | 13 | #include "sway/view.h" |
11 | #include "sway/workspace.h" | 14 | #include "sway/workspace.h" |
12 | #include "log.h" | 15 | #include "log.h" |
@@ -48,19 +51,38 @@ static swayc_t *new_swayc(enum swayc_types type) { | |||
48 | 51 | ||
49 | swayc_t *new_output(struct sway_output *sway_output) { | 52 | swayc_t *new_output(struct sway_output *sway_output) { |
50 | struct wlr_box size; | 53 | struct wlr_box size; |
51 | wlr_output_effective_resolution( | 54 | wlr_output_effective_resolution(sway_output->wlr_output, &size.width, |
52 | sway_output->wlr_output, &size.width, &size.height); | 55 | &size.height); |
53 | const char *name = sway_output->wlr_output->name; | 56 | const char *name = sway_output->wlr_output->name; |
54 | 57 | ||
58 | struct output_config *oc = NULL, *all = NULL; | ||
59 | for (int i = 0; i < config->output_configs->length; ++i) { | ||
60 | struct output_config *cur = config->output_configs->items[i]; | ||
61 | if (strcasecmp(name, cur->name) == 0) { | ||
62 | sway_log(L_DEBUG, "Matched output config for %s", name); | ||
63 | oc = cur; | ||
64 | } | ||
65 | if (strcasecmp("*", cur->name) == 0) { | ||
66 | sway_log(L_DEBUG, "Matched wildcard output config for %s", name); | ||
67 | all = cur; | ||
68 | } | ||
69 | |||
70 | if (oc && all) { | ||
71 | break; | ||
72 | } | ||
73 | } | ||
74 | if (!oc) { | ||
75 | oc = all; | ||
76 | } | ||
77 | if (oc && !oc->enabled) { | ||
78 | return NULL; | ||
79 | } | ||
80 | |||
55 | swayc_t *output = new_swayc(C_OUTPUT); | 81 | swayc_t *output = new_swayc(C_OUTPUT); |
56 | output->sway_output = sway_output; | 82 | output->sway_output = sway_output; |
57 | output->name = name ? strdup(name) : NULL; | 83 | output->name = name ? strdup(name) : NULL; |
58 | output->width = size.width; | ||
59 | output->height = size.width; | ||
60 | 84 | ||
61 | // TODO configure output layout position | 85 | apply_output_config(oc, output); |
62 | wlr_output_layout_add_auto(root_container.output_layout, | ||
63 | sway_output->wlr_output); | ||
64 | 86 | ||
65 | add_child(&root_container, output); | 87 | add_child(&root_container, output); |
66 | 88 | ||
@@ -146,6 +168,34 @@ static void free_swayc(swayc_t *cont) { | |||
146 | free(cont); | 168 | free(cont); |
147 | } | 169 | } |
148 | 170 | ||
171 | swayc_t *destroy_output(swayc_t *output) { | ||
172 | if (!sway_assert(output, "null output passed to destroy_output")) { | ||
173 | return NULL; | ||
174 | } | ||
175 | |||
176 | if (output->children->length > 0) { | ||
177 | // TODO save workspaces when there are no outputs. | ||
178 | // TODO also check if there will ever be no outputs except for exiting | ||
179 | // program | ||
180 | if (root_container.children->length > 1) { | ||
181 | int p = root_container.children->items[0] == output; | ||
182 | // Move workspace from this output to another output | ||
183 | while (output->children->length) { | ||
184 | swayc_t *child = output->children->items[0]; | ||
185 | remove_child(child); | ||
186 | add_child(root_container.children->items[p], child); | ||
187 | } | ||
188 | sort_workspaces(root_container.children->items[p]); | ||
189 | arrange_windows(root_container.children->items[p], -1, -1); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | sway_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); | ||
194 | free_swayc(output); | ||
195 | |||
196 | return &root_container; | ||
197 | } | ||
198 | |||
149 | swayc_t *destroy_view(swayc_t *view) { | 199 | swayc_t *destroy_view(swayc_t *view) { |
150 | if (!sway_assert(view, "null view passed to destroy_view")) { | 200 | if (!sway_assert(view, "null view passed to destroy_view")) { |
151 | return NULL; | 201 | return NULL; |
@@ -189,7 +239,8 @@ swayc_t *swayc_at(swayc_t *parent, double lx, double ly, | |||
189 | struct sway_view *sview = swayc->sway_view; | 239 | struct sway_view *sview = swayc->sway_view; |
190 | swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); | 240 | swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT); |
191 | struct wlr_box *output_box = | 241 | struct wlr_box *output_box = |
192 | wlr_output_layout_get_box(root_container.output_layout, | 242 | wlr_output_layout_get_box( |
243 | root_container.sway_root->output_layout, | ||
193 | soutput->sway_output->wlr_output); | 244 | soutput->sway_output->wlr_output); |
194 | double ox = lx - output_box->x; | 245 | double ox = lx - output_box->x; |
195 | double oy = ly - output_box->y; | 246 | double oy = ly - output_box->y; |
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index cb39a361..4bcf0e2f 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <wlr/types/wlr_output.h> | 7 | #include <wlr/types/wlr_output.h> |
8 | #include <wlr/types/wlr_output_layout.h> | 8 | #include <wlr/types/wlr_output_layout.h> |
9 | #include "sway/container.h" | 9 | #include "sway/container.h" |
10 | #include "sway/layout.h" | ||
10 | #include "sway/output.h" | 11 | #include "sway/output.h" |
11 | #include "sway/view.h" | 12 | #include "sway/view.h" |
12 | #include "list.h" | 13 | #include "list.h" |
@@ -14,13 +15,47 @@ | |||
14 | 15 | ||
15 | swayc_t root_container; | 16 | swayc_t root_container; |
16 | 17 | ||
18 | static void output_layout_change_notify(struct wl_listener *listener, void *data) { | ||
19 | struct wlr_box *layout_box = wlr_output_layout_get_box( | ||
20 | root_container.sway_root->output_layout, NULL); | ||
21 | root_container.width = layout_box->width; | ||
22 | root_container.height = layout_box->height; | ||
23 | |||
24 | for (int i = 0 ; i < root_container.children->length; ++i) { | ||
25 | swayc_t *output_container = root_container.children->items[i]; | ||
26 | if (output_container->type != C_OUTPUT) { | ||
27 | continue; | ||
28 | } | ||
29 | struct sway_output *output = output_container->sway_output; | ||
30 | |||
31 | struct wlr_box *output_box = wlr_output_layout_get_box( | ||
32 | root_container.sway_root->output_layout, output->wlr_output); | ||
33 | if (!output_box) { | ||
34 | continue; | ||
35 | } | ||
36 | output_container->x = output_box->x; | ||
37 | output_container->y = output_box->y; | ||
38 | output_container->width = output_box->width; | ||
39 | output_container->height = output_box->height; | ||
40 | } | ||
41 | |||
42 | arrange_windows(&root_container, -1, -1); | ||
43 | } | ||
44 | |||
17 | void init_layout(void) { | 45 | void init_layout(void) { |
18 | root_container.id = 0; // normally assigned in new_swayc() | 46 | root_container.id = 0; // normally assigned in new_swayc() |
19 | root_container.type = C_ROOT; | 47 | root_container.type = C_ROOT; |
20 | root_container.layout = L_NONE; | 48 | root_container.layout = L_NONE; |
21 | root_container.name = strdup("root"); | 49 | root_container.name = strdup("root"); |
22 | root_container.children = create_list(); | 50 | root_container.children = create_list(); |
23 | root_container.output_layout = wlr_output_layout_create(); | 51 | |
52 | root_container.sway_root = calloc(1, sizeof(*root_container.sway_root)); | ||
53 | root_container.sway_root->output_layout = wlr_output_layout_create(); | ||
54 | |||
55 | root_container.sway_root->output_layout_change.notify = | ||
56 | output_layout_change_notify; | ||
57 | wl_signal_add(&root_container.sway_root->output_layout->events.change, | ||
58 | &root_container.sway_root->output_layout_change); | ||
24 | } | 59 | } |
25 | 60 | ||
26 | void add_child(swayc_t *parent, swayc_t *child) { | 61 | void add_child(swayc_t *parent, swayc_t *child) { |