diff options
-rw-r--r-- | include/sway/output.h | 4 | ||||
-rw-r--r-- | include/sway/server.h | 2 | ||||
-rw-r--r-- | sway/commands/output/background.c | 63 | ||||
-rw-r--r-- | sway/desktop/layer_shell.c | 9 | ||||
-rw-r--r-- | sway/desktop/output.c | 3 | ||||
-rw-r--r-- | sway/desktop/xdg_shell.c | 9 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 10 | ||||
-rw-r--r-- | sway/input/cursor.c | 9 | ||||
-rw-r--r-- | sway/main.c | 5 | ||||
-rw-r--r-- | sway/server.c | 13 |
10 files changed, 86 insertions, 41 deletions
diff --git a/include/sway/output.h b/include/sway/output.h index 70f746dc..8180ce3d 100644 --- a/include/sway/output.h +++ b/include/sway/output.h | |||
@@ -32,6 +32,10 @@ struct sway_output { | |||
32 | struct wl_list link; | 32 | struct wl_list link; |
33 | 33 | ||
34 | pid_t bg_pid; | 34 | pid_t bg_pid; |
35 | |||
36 | struct { | ||
37 | struct wl_signal destroy; | ||
38 | } events; | ||
35 | }; | 39 | }; |
36 | 40 | ||
37 | void output_damage_whole(struct sway_output *output); | 41 | void output_damage_whole(struct sway_output *output); |
diff --git a/include/sway/server.h b/include/sway/server.h index 96cad69d..b016aba8 100644 --- a/include/sway/server.h +++ b/include/sway/server.h | |||
@@ -44,6 +44,8 @@ struct sway_server { | |||
44 | 44 | ||
45 | struct sway_server server; | 45 | struct sway_server server; |
46 | 46 | ||
47 | /* Prepares an unprivileged server_init by performing all privileged operations in advance */ | ||
48 | bool server_privileged_prepare(struct sway_server *server); | ||
47 | bool server_init(struct sway_server *server); | 49 | bool server_init(struct sway_server *server); |
48 | void server_fini(struct sway_server *server); | 50 | void server_fini(struct sway_server *server); |
49 | void server_run(struct sway_server *server); | 51 | void server_run(struct sway_server *server); |
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index 0c5c164f..55cbdff0 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <strings.h> | 3 | #include <strings.h> |
4 | #include <unistd.h> | 4 | #include <unistd.h> |
5 | #include <wordexp.h> | 5 | #include <wordexp.h> |
6 | #include <errno.h> | ||
6 | #include "sway/commands.h" | 7 | #include "sway/commands.h" |
7 | #include "sway/config.h" | 8 | #include "sway/config.h" |
8 | #include "log.h" | 9 | #include "log.h" |
@@ -61,40 +62,56 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { | |||
61 | wordexp_t p; | 62 | wordexp_t p; |
62 | char *src = join_args(argv, j); | 63 | char *src = join_args(argv, j); |
63 | if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { | 64 | if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) { |
64 | return cmd_results_new(CMD_INVALID, "output", | 65 | struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID, "output", |
65 | "Invalid syntax (%s).", src); | 66 | "Invalid syntax (%s)", src); |
67 | free(src); | ||
68 | wordfree(&p); | ||
69 | return cmd_res; | ||
66 | } | 70 | } |
67 | free(src); | 71 | free(src); |
68 | src = p.we_wordv[0]; | 72 | src = strdup(p.we_wordv[0]); |
73 | wordfree(&p); | ||
74 | if (!src) { | ||
75 | wlr_log(L_ERROR, "Failed to duplicate string"); | ||
76 | return cmd_results_new(CMD_FAILURE, "output", | ||
77 | "Unable to allocate resource"); | ||
78 | } | ||
79 | |||
69 | if (config->reading && *src != '/') { | 80 | if (config->reading && *src != '/') { |
81 | // src file is inside configuration dir | ||
82 | |||
70 | char *conf = strdup(config->current_config); | 83 | char *conf = strdup(config->current_config); |
71 | if (conf) { | 84 | if(!conf) { |
72 | char *conf_path = dirname(conf); | 85 | wlr_log(L_ERROR, "Failed to duplicate string"); |
73 | src = malloc(strlen(conf_path) + strlen(src) + 2); | 86 | return cmd_results_new(CMD_FAILURE, "output", |
74 | if (src) { | 87 | "Unable to allocate resources"); |
75 | sprintf(src, "%s/%s", conf_path, p.we_wordv[0]); | 88 | } |
76 | } else { | 89 | |
77 | wlr_log(L_ERROR, | 90 | char *conf_path = dirname(conf); |
78 | "Unable to allocate background source"); | 91 | char *rel_path = src; |
79 | } | 92 | src = malloc(strlen(conf_path) + strlen(src) + 2); |
93 | if (!src) { | ||
94 | free(rel_path); | ||
80 | free(conf); | 95 | free(conf); |
81 | } else { | 96 | wlr_log(L_ERROR, "Unable to allocate memory"); |
82 | wlr_log(L_ERROR, "Unable to allocate background source"); | 97 | return cmd_results_new(CMD_FAILURE, "output", |
98 | "Unable to allocate resources"); | ||
83 | } | 99 | } |
84 | } | 100 | |
85 | if (!src || access(src, F_OK) == -1) { | 101 | sprintf(src, "%s/%s", conf_path, rel_path); |
86 | wordfree(&p); | 102 | free(rel_path); |
87 | return cmd_results_new(CMD_INVALID, "output", | 103 | free(conf); |
88 | "Background file unreadable (%s).", src); | ||
89 | } | 104 | } |
90 | 105 | ||
91 | output->background = strdup(src); | 106 | if (access(src, F_OK) == -1) { |
92 | output->background_option = strdup(mode); | 107 | struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output", |
93 | if (src != p.we_wordv[0]) { | 108 | "Unable to access background file '%s': %s", src, strerror(errno)); |
94 | free(src); | 109 | free(src); |
110 | return cmd_res; | ||
95 | } | 111 | } |
96 | wordfree(&p); | ||
97 | 112 | ||
113 | output->background = src; | ||
114 | output->background_option = strdup(mode); | ||
98 | argc -= j + 1; argv += j + 1; | 115 | argc -= j + 1; argv += j + 1; |
99 | } | 116 | } |
100 | 117 | ||
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 3accdefb..b57d1ee6 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c | |||
@@ -219,6 +219,8 @@ static void handle_output_destroy(struct wl_listener *listener, void *data) { | |||
219 | struct sway_layer_surface *sway_layer = | 219 | struct sway_layer_surface *sway_layer = |
220 | wl_container_of(listener, sway_layer, output_destroy); | 220 | wl_container_of(listener, sway_layer, output_destroy); |
221 | wl_list_remove(&sway_layer->output_destroy.link); | 221 | wl_list_remove(&sway_layer->output_destroy.link); |
222 | wl_list_remove(&sway_layer->link); | ||
223 | wl_list_init(&sway_layer->link); | ||
222 | sway_layer->layer_surface->output = NULL; | 224 | sway_layer->layer_surface->output = NULL; |
223 | wlr_layer_surface_close(sway_layer->layer_surface); | 225 | wlr_layer_surface_close(sway_layer->layer_surface); |
224 | } | 226 | } |
@@ -350,10 +352,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { | |||
350 | wl_signal_add(&layer_surface->surface->events.commit, | 352 | wl_signal_add(&layer_surface->surface->events.commit, |
351 | &sway_layer->surface_commit); | 353 | &sway_layer->surface_commit); |
352 | 354 | ||
353 | sway_layer->output_destroy.notify = handle_output_destroy; | ||
354 | wl_signal_add(&layer_surface->output->events.destroy, | ||
355 | &sway_layer->output_destroy); | ||
356 | |||
357 | sway_layer->destroy.notify = handle_destroy; | 355 | sway_layer->destroy.notify = handle_destroy; |
358 | wl_signal_add(&layer_surface->events.destroy, &sway_layer->destroy); | 356 | wl_signal_add(&layer_surface->events.destroy, &sway_layer->destroy); |
359 | sway_layer->map.notify = handle_map; | 357 | sway_layer->map.notify = handle_map; |
@@ -366,6 +364,9 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { | |||
366 | layer_surface->data = sway_layer; | 364 | layer_surface->data = sway_layer; |
367 | 365 | ||
368 | struct sway_output *output = layer_surface->output->data; | 366 | struct sway_output *output = layer_surface->output->data; |
367 | sway_layer->output_destroy.notify = handle_output_destroy; | ||
368 | wl_signal_add(&output->events.destroy, &sway_layer->output_destroy); | ||
369 | |||
369 | wl_list_insert(&output->layers[layer_surface->layer], &sway_layer->link); | 370 | wl_list_insert(&output->layers[layer_surface->layer], &sway_layer->link); |
370 | 371 | ||
371 | // Temporarily set the layer's current state to client_pending | 372 | // Temporarily set the layer's current state to client_pending |
diff --git a/sway/desktop/output.c b/sway/desktop/output.c index d4115be8..f0f1603a 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c | |||
@@ -1199,6 +1199,8 @@ static void damage_handle_destroy(struct wl_listener *listener, void *data) { | |||
1199 | 1199 | ||
1200 | static void handle_destroy(struct wl_listener *listener, void *data) { | 1200 | static void handle_destroy(struct wl_listener *listener, void *data) { |
1201 | struct sway_output *output = wl_container_of(listener, output, destroy); | 1201 | struct sway_output *output = wl_container_of(listener, output, destroy); |
1202 | wl_signal_emit(&output->events.destroy, output); | ||
1203 | |||
1202 | if (output->swayc) { | 1204 | if (output->swayc) { |
1203 | container_destroy(output->swayc); | 1205 | container_destroy(output->swayc); |
1204 | } | 1206 | } |
@@ -1277,6 +1279,7 @@ void output_enable(struct sway_output *output) { | |||
1277 | for (size_t i = 0; i < len; ++i) { | 1279 | for (size_t i = 0; i < len; ++i) { |
1278 | wl_list_init(&output->layers[i]); | 1280 | wl_list_init(&output->layers[i]); |
1279 | } | 1281 | } |
1282 | wl_signal_init(&output->events.destroy); | ||
1280 | 1283 | ||
1281 | input_manager_configure_xcursor(input_manager); | 1284 | input_manager_configure_xcursor(input_manager); |
1282 | 1285 | ||
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index d2b8822c..8457c06b 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c | |||
@@ -120,11 +120,12 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { | |||
120 | } | 120 | } |
121 | 121 | ||
122 | static bool wants_floating(struct sway_view *view) { | 122 | static bool wants_floating(struct sway_view *view) { |
123 | struct wlr_xdg_toplevel_state *state = | 123 | struct wlr_xdg_toplevel *toplevel = view->wlr_xdg_surface->toplevel; |
124 | &view->wlr_xdg_surface->toplevel->current; | 124 | struct wlr_xdg_toplevel_state *state = &toplevel->current; |
125 | return state->min_width != 0 && state->min_height != 0 | 125 | return (state->min_width != 0 && state->min_height != 0 |
126 | && state->min_width == state->max_width | 126 | && state->min_width == state->max_width |
127 | && state->min_height == state->max_height; | 127 | && state->min_height == state->max_height) |
128 | || toplevel->parent; | ||
128 | } | 129 | } |
129 | 130 | ||
130 | static void for_each_surface(struct sway_view *view, | 131 | static void for_each_surface(struct sway_view *view, |
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 6ffe334a..eb1cef26 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c | |||
@@ -119,11 +119,13 @@ static void set_fullscreen(struct sway_view *view, bool fullscreen) { | |||
119 | } | 119 | } |
120 | 120 | ||
121 | static bool wants_floating(struct sway_view *view) { | 121 | static bool wants_floating(struct sway_view *view) { |
122 | struct wlr_xdg_toplevel_v6_state *state = | 122 | struct wlr_xdg_toplevel_v6 *toplevel = |
123 | &view->wlr_xdg_surface_v6->toplevel->current; | 123 | view->wlr_xdg_surface_v6->toplevel; |
124 | return state->min_width != 0 && state->min_height != 0 | 124 | struct wlr_xdg_toplevel_v6_state *state = &toplevel->current; |
125 | return (state->min_width != 0 && state->min_height != 0 | ||
125 | && state->min_width == state->max_width | 126 | && state->min_width == state->max_width |
126 | && state->min_height == state->max_height; | 127 | && state->min_height == state->max_height) |
128 | || toplevel->parent; | ||
127 | } | 129 | } |
128 | 130 | ||
129 | static void for_each_surface(struct sway_view *view, | 131 | static void for_each_surface(struct sway_view *view, |
diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 37a87756..944e35aa 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c | |||
@@ -174,10 +174,13 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor, uint32_t time_msec, | |||
174 | seat_set_focus_warp(seat, c, false); | 174 | seat_set_focus_warp(seat, c, false); |
175 | } | 175 | } |
176 | } else if (c->type == C_VIEW) { | 176 | } else if (c->type == C_VIEW) { |
177 | // Focus c if both of the following are true: | 177 | // Focus c if the following are true: |
178 | // - cursor is over a new view, i.e. entered a new window; and | 178 | // - cursor is over a new view, i.e. entered a new window; and |
179 | // - the new view is visible, i.e. not hidden in a stack or tab. | 179 | // - the new view is visible, i.e. not hidden in a stack or tab; and |
180 | if (c != prev_c && view_is_visible(c->sway_view)) { | 180 | // - the seat does not have a keyboard grab |
181 | if (!wlr_seat_keyboard_has_grab(cursor->seat->wlr_seat) && | ||
182 | c != prev_c && | ||
183 | view_is_visible(c->sway_view)) { | ||
181 | seat_set_focus_warp(seat, c, false); | 184 | seat_set_focus_warp(seat, c, false); |
182 | } else { | 185 | } else { |
183 | struct sway_container *next_focus = | 186 | struct sway_container *next_focus = |
diff --git a/sway/main.c b/sway/main.c index a7e808ad..a325dc3a 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -359,6 +359,11 @@ int main(int argc, char **argv) { | |||
359 | 359 | ||
360 | executable_sanity_check(); | 360 | executable_sanity_check(); |
361 | bool suid = false; | 361 | bool suid = false; |
362 | |||
363 | if (!server_privileged_prepare(&server)) { | ||
364 | return 1; | ||
365 | } | ||
366 | |||
362 | #ifdef __linux__ | 367 | #ifdef __linux__ |
363 | if (getuid() != geteuid() || getgid() != getegid()) { | 368 | if (getuid() != geteuid() || getgid() != getegid()) { |
364 | // Retain capabilities after setuid() | 369 | // Retain capabilities after setuid() |
diff --git a/sway/server.c b/sway/server.c index 878b530d..5b052494 100644 --- a/sway/server.c +++ b/sway/server.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <wlr/types/wlr_idle.h> | 11 | #include <wlr/types/wlr_idle.h> |
12 | #include <wlr/types/wlr_layer_shell.h> | 12 | #include <wlr/types/wlr_layer_shell.h> |
13 | #include <wlr/types/wlr_linux_dmabuf.h> | 13 | #include <wlr/types/wlr_linux_dmabuf.h> |
14 | #include <wlr/types/wlr_export_dmabuf_v1.h> | ||
14 | #include <wlr/types/wlr_primary_selection.h> | 15 | #include <wlr/types/wlr_primary_selection.h> |
15 | #include <wlr/types/wlr_screenshooter.h> | 16 | #include <wlr/types/wlr_screenshooter.h> |
16 | #include <wlr/types/wlr_server_decoration.h> | 17 | #include <wlr/types/wlr_server_decoration.h> |
@@ -24,9 +25,8 @@ | |||
24 | #include "sway/tree/layout.h" | 25 | #include "sway/tree/layout.h" |
25 | #include "sway/xwayland.h" | 26 | #include "sway/xwayland.h" |
26 | 27 | ||
27 | bool server_init(struct sway_server *server) { | 28 | bool server_privileged_prepare(struct sway_server *server) { |
28 | wlr_log(L_DEBUG, "Initializing Wayland server"); | 29 | wlr_log(L_DEBUG, "Preparing Wayland server initialization"); |
29 | |||
30 | server->wl_display = wl_display_create(); | 30 | server->wl_display = wl_display_create(); |
31 | server->wl_event_loop = wl_display_get_event_loop(server->wl_display); | 31 | server->wl_event_loop = wl_display_get_event_loop(server->wl_display); |
32 | server->backend = wlr_backend_autocreate(server->wl_display, NULL); | 32 | server->backend = wlr_backend_autocreate(server->wl_display, NULL); |
@@ -35,6 +35,12 @@ bool server_init(struct sway_server *server) { | |||
35 | wlr_log(L_ERROR, "Unable to create backend"); | 35 | wlr_log(L_ERROR, "Unable to create backend"); |
36 | return false; | 36 | return false; |
37 | } | 37 | } |
38 | return true; | ||
39 | } | ||
40 | |||
41 | bool server_init(struct sway_server *server) { | ||
42 | wlr_log(L_DEBUG, "Initializing Wayland server"); | ||
43 | |||
38 | struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); | 44 | struct wlr_renderer *renderer = wlr_backend_get_renderer(server->backend); |
39 | assert(renderer); | 45 | assert(renderer); |
40 | 46 | ||
@@ -99,6 +105,7 @@ bool server_init(struct sway_server *server) { | |||
99 | deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); | 105 | deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); |
100 | 106 | ||
101 | wlr_linux_dmabuf_create(server->wl_display, renderer); | 107 | wlr_linux_dmabuf_create(server->wl_display, renderer); |
108 | wlr_export_dmabuf_manager_v1_create(server->wl_display); | ||
102 | 109 | ||
103 | server->socket = wl_display_add_socket_auto(server->wl_display); | 110 | server->socket = wl_display_add_socket_auto(server->wl_display); |
104 | if (!server->socket) { | 111 | if (!server->socket) { |