diff options
author | emersion <contact@emersion.fr> | 2017-12-06 19:11:46 +0100 |
---|---|---|
committer | emersion <contact@emersion.fr> | 2017-12-06 19:11:46 +0100 |
commit | c25ad5e7c4dc49cdcda23c25558253e77be8894a (patch) | |
tree | f7099bed2222900d975f866b3571b067921818dd /sway | |
parent | Init, merge output config params, use wlr_output_layout (diff) | |
parent | Merge pull request #1501 from emersion/command-include (diff) | |
download | sway-c25ad5e7c4dc49cdcda23c25558253e77be8894a.tar.gz sway-c25ad5e7c4dc49cdcda23c25558253e77be8894a.tar.zst sway-c25ad5e7c4dc49cdcda23c25558253e77be8894a.zip |
Merge branch 'wlroots' into output-config
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/include.c | 15 | ||||
-rw-r--r-- | sway/config.c | 89 | ||||
-rw-r--r-- | sway/desktop/wl_shell.c | 5 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 11 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 9 | ||||
-rw-r--r-- | sway/meson.build | 1 |
7 files changed, 131 insertions, 0 deletions
diff --git a/sway/commands.c b/sway/commands.c index 961cb867..d6cf7a64 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -95,6 +95,7 @@ static struct cmd_handler handlers[] = { | |||
95 | { "exec", cmd_exec }, | 95 | { "exec", cmd_exec }, |
96 | { "exec_always", cmd_exec_always }, | 96 | { "exec_always", cmd_exec_always }, |
97 | { "exit", cmd_exit }, | 97 | { "exit", cmd_exit }, |
98 | { "include", cmd_include }, | ||
98 | { "output", cmd_output }, | 99 | { "output", cmd_output }, |
99 | }; | 100 | }; |
100 | 101 | ||
diff --git a/sway/commands/include.c b/sway/commands/include.c new file mode 100644 index 00000000..1ba9a10d --- /dev/null +++ b/sway/commands/include.c | |||
@@ -0,0 +1,15 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/config.h" | ||
3 | |||
4 | struct cmd_results *cmd_include(int argc, char **argv) { | ||
5 | struct cmd_results *error = NULL; | ||
6 | if ((error = checkarg(argc, "include", EXPECTED_EQUAL_TO, 1))) { | ||
7 | return error; | ||
8 | } | ||
9 | |||
10 | if (!load_include_configs(argv[0], config)) { | ||
11 | return cmd_results_new(CMD_INVALID, "include", "Failed to include sub configuration file: %s", argv[0]); | ||
12 | } | ||
13 | |||
14 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
15 | } | ||
diff --git a/sway/config.c b/sway/config.c index 475e8b04..61131845 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -311,6 +311,95 @@ bool load_main_config(const char *file, bool is_active) { | |||
311 | return success; | 311 | return success; |
312 | } | 312 | } |
313 | 313 | ||
314 | static bool load_include_config(const char *path, const char *parent_dir, struct sway_config *config) { | ||
315 | // save parent config | ||
316 | const char *parent_config = config->current_config; | ||
317 | |||
318 | char *full_path = strdup(path); | ||
319 | int len = strlen(path); | ||
320 | if (len >= 1 && path[0] != '/') { | ||
321 | len = len + strlen(parent_dir) + 2; | ||
322 | full_path = malloc(len * sizeof(char)); | ||
323 | if (!full_path) { | ||
324 | sway_log(L_ERROR, "Unable to allocate full path to included config"); | ||
325 | return false; | ||
326 | } | ||
327 | snprintf(full_path, len, "%s/%s", parent_dir, path); | ||
328 | } | ||
329 | |||
330 | char *real_path = realpath(full_path, NULL); | ||
331 | free(full_path); | ||
332 | |||
333 | if (real_path == NULL) { | ||
334 | sway_log(L_DEBUG, "%s not found.", path); | ||
335 | return false; | ||
336 | } | ||
337 | |||
338 | // check if config has already been included | ||
339 | int j; | ||
340 | for (j = 0; j < config->config_chain->length; ++j) { | ||
341 | char *old_path = config->config_chain->items[j]; | ||
342 | if (strcmp(real_path, old_path) == 0) { | ||
343 | sway_log(L_DEBUG, "%s already included once, won't be included again.", real_path); | ||
344 | free(real_path); | ||
345 | return false; | ||
346 | } | ||
347 | } | ||
348 | |||
349 | config->current_config = real_path; | ||
350 | list_add(config->config_chain, real_path); | ||
351 | int index = config->config_chain->length - 1; | ||
352 | |||
353 | if (!load_config(real_path, config)) { | ||
354 | free(real_path); | ||
355 | config->current_config = parent_config; | ||
356 | list_del(config->config_chain, index); | ||
357 | return false; | ||
358 | } | ||
359 | |||
360 | // restore current_config | ||
361 | config->current_config = parent_config; | ||
362 | return true; | ||
363 | } | ||
364 | |||
365 | bool load_include_configs(const char *path, struct sway_config *config) { | ||
366 | char *wd = getcwd(NULL, 0); | ||
367 | char *parent_path = strdup(config->current_config); | ||
368 | const char *parent_dir = dirname(parent_path); | ||
369 | |||
370 | if (chdir(parent_dir) < 0) { | ||
371 | free(parent_path); | ||
372 | free(wd); | ||
373 | return false; | ||
374 | } | ||
375 | |||
376 | wordexp_t p; | ||
377 | |||
378 | if (wordexp(path, &p, 0) < 0) { | ||
379 | free(parent_path); | ||
380 | free(wd); | ||
381 | return false; | ||
382 | } | ||
383 | |||
384 | char **w = p.we_wordv; | ||
385 | size_t i; | ||
386 | for (i = 0; i < p.we_wordc; ++i) { | ||
387 | load_include_config(w[i], parent_dir, config); | ||
388 | } | ||
389 | free(parent_path); | ||
390 | wordfree(&p); | ||
391 | |||
392 | // restore wd | ||
393 | if (chdir(wd) < 0) { | ||
394 | free(wd); | ||
395 | sway_log(L_ERROR, "failed to restore working directory"); | ||
396 | return false; | ||
397 | } | ||
398 | |||
399 | free(wd); | ||
400 | return true; | ||
401 | } | ||
402 | |||
314 | bool read_config(FILE *file, struct sway_config *config) { | 403 | bool read_config(FILE *file, struct sway_config *config) { |
315 | bool success = true; | 404 | bool success = true; |
316 | enum cmd_status block = CMD_BLOCK_END; | 405 | enum cmd_status block = CMD_BLOCK_END; |
diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index b2e026ef..3f5a358a 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c | |||
@@ -45,6 +45,10 @@ static void set_position(struct sway_view *view, double ox, double oy) { | |||
45 | view->swayc->y = oy; | 45 | view->swayc->y = oy; |
46 | } | 46 | } |
47 | 47 | ||
48 | static void set_activated(struct sway_view *view, bool activated) { | ||
49 | // no way to activate wl_shell | ||
50 | } | ||
51 | |||
48 | static void handle_commit(struct wl_listener *listener, void *data) { | 52 | static void handle_commit(struct wl_listener *listener, void *data) { |
49 | struct sway_wl_shell_surface *sway_surface = | 53 | struct sway_wl_shell_surface *sway_surface = |
50 | wl_container_of(listener, sway_surface, commit); | 54 | wl_container_of(listener, sway_surface, commit); |
@@ -96,6 +100,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { | |||
96 | sway_view->iface.get_prop = get_prop; | 100 | sway_view->iface.get_prop = get_prop; |
97 | sway_view->iface.set_size = set_size; | 101 | sway_view->iface.set_size = set_size; |
98 | sway_view->iface.set_position = set_position; | 102 | sway_view->iface.set_position = set_position; |
103 | sway_view->iface.set_activated = set_activated; | ||
99 | sway_view->wlr_wl_shell_surface = shell_surface; | 104 | sway_view->wlr_wl_shell_surface = shell_surface; |
100 | sway_view->sway_wl_shell_surface = sway_surface; | 105 | sway_view->sway_wl_shell_surface = sway_surface; |
101 | sway_view->surface = shell_surface->surface; | 106 | sway_view->surface = shell_surface->surface; |
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 37e39f37..2435c256 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -45,6 +45,16 @@ static void set_position(struct sway_view *view, double ox, double oy) { | |||
45 | view->swayc->y = oy; | 45 | view->swayc->y = oy; |
46 | } | 46 | } |
47 | 47 | ||
48 | static void set_activated(struct sway_view *view, bool activated) { | ||
49 | if (!assert_xdg(view)) { | ||
50 | return; | ||
51 | } | ||
52 | struct wlr_xdg_surface_v6 *surface = view->wlr_xdg_surface_v6; | ||
53 | if (surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) { | ||
54 | wlr_xdg_toplevel_v6_set_activated(surface, activated); | ||
55 | } | ||
56 | } | ||
57 | |||
48 | static void handle_commit(struct wl_listener *listener, void *data) { | 58 | static void handle_commit(struct wl_listener *listener, void *data) { |
49 | struct sway_xdg_surface_v6 *sway_surface = | 59 | struct sway_xdg_surface_v6 *sway_surface = |
50 | wl_container_of(listener, sway_surface, commit); | 60 | wl_container_of(listener, sway_surface, commit); |
@@ -96,6 +106,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { | |||
96 | sway_view->iface.get_prop = get_prop; | 106 | sway_view->iface.get_prop = get_prop; |
97 | sway_view->iface.set_size = set_size; | 107 | sway_view->iface.set_size = set_size; |
98 | sway_view->iface.set_position = set_position; | 108 | sway_view->iface.set_position = set_position; |
109 | sway_view->iface.set_activated = set_activated; | ||
99 | sway_view->wlr_xdg_surface_v6 = xdg_surface; | 110 | sway_view->wlr_xdg_surface_v6 = xdg_surface; |
100 | sway_view->sway_xdg_surface_v6 = sway_surface; | 111 | sway_view->sway_xdg_surface_v6 = sway_surface; |
101 | sway_view->surface = xdg_surface->surface; | 112 | sway_view->surface = xdg_surface->surface; |
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 266a5869..65c7e1ec 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c | |||
@@ -70,6 +70,14 @@ static void set_position(struct sway_view *view, double ox, double oy) { | |||
70 | view->width, view->height); | 70 | view->width, view->height); |
71 | } | 71 | } |
72 | 72 | ||
73 | static void set_activated(struct sway_view *view, bool activated) { | ||
74 | if (!assert_xwayland(view)) { | ||
75 | return; | ||
76 | } | ||
77 | struct wlr_xwayland_surface *surface = view->wlr_xwayland_surface; | ||
78 | wlr_xwayland_surface_activate(surface, activated); | ||
79 | } | ||
80 | |||
73 | static void handle_commit(struct wl_listener *listener, void *data) { | 81 | static void handle_commit(struct wl_listener *listener, void *data) { |
74 | struct sway_xwayland_surface *sway_surface = | 82 | struct sway_xwayland_surface *sway_surface = |
75 | wl_container_of(listener, sway_surface, commit); | 83 | wl_container_of(listener, sway_surface, commit); |
@@ -133,6 +141,7 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { | |||
133 | sway_view->iface.get_prop = get_prop; | 141 | sway_view->iface.get_prop = get_prop; |
134 | sway_view->iface.set_size = set_size; | 142 | sway_view->iface.set_size = set_size; |
135 | sway_view->iface.set_position = set_position; | 143 | sway_view->iface.set_position = set_position; |
144 | sway_view->iface.set_activated = set_activated; | ||
136 | sway_view->wlr_xwayland_surface = xsurface; | 145 | sway_view->wlr_xwayland_surface = xsurface; |
137 | sway_view->sway_xwayland_surface = sway_surface; | 146 | sway_view->sway_xwayland_surface = sway_surface; |
138 | // TODO remove from the tree when the surface goes away (unmapped) | 147 | // TODO remove from the tree when the surface goes away (unmapped) |
diff --git a/sway/meson.build b/sway/meson.build index 5ae7fbb3..e16691a8 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -5,6 +5,7 @@ sway_sources = files( | |||
5 | 'commands/exit.c', | 5 | 'commands/exit.c', |
6 | 'commands/exec.c', | 6 | 'commands/exec.c', |
7 | 'commands/exec_always.c', | 7 | 'commands/exec_always.c', |
8 | 'commands/include.c', | ||
8 | 'commands/output.c', | 9 | 'commands/output.c', |
9 | 'config.c', | 10 | 'config.c', |
10 | 'config/output.c', | 11 | 'config/output.c', |