aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/sway/output.h4
-rw-r--r--sway/commands/output/background.c56
-rw-r--r--sway/desktop/layer_shell.c9
-rw-r--r--sway/desktop/output.c3
4 files changed, 45 insertions, 27 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 {
struct wl_list link;
pid_t bg_pid;
+
+ struct {
+ struct wl_signal destroy;
+ } events;
};
void output_damage_whole(struct sway_output *output);
diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c
index 82bccf68..55cbdff0 100644
--- a/sway/commands/output/background.c
+++ b/sway/commands/output/background.c
@@ -62,46 +62,56 @@ struct cmd_results *output_cmd_background(int argc, char **argv) {
wordexp_t p;
char *src = join_args(argv, j);
if (wordexp(src, &p, 0) != 0 || p.we_wordv[0] == NULL) {
- return cmd_results_new(CMD_INVALID, "output",
- "Invalid syntax (%s).", src);
+ struct cmd_results *cmd_res = cmd_results_new(CMD_INVALID, "output",
+ "Invalid syntax (%s)", src);
+ free(src);
+ wordfree(&p);
+ return cmd_res;
}
free(src);
- src = p.we_wordv[0];
+ src = strdup(p.we_wordv[0]);
+ wordfree(&p);
+ if (!src) {
+ wlr_log(L_ERROR, "Failed to duplicate string");
+ return cmd_results_new(CMD_FAILURE, "output",
+ "Unable to allocate resource");
+ }
+
if (config->reading && *src != '/') {
+ // src file is inside configuration dir
+
char *conf = strdup(config->current_config);
- if (conf) {
- char *conf_path = dirname(conf);
- src = malloc(strlen(conf_path) + strlen(src) + 2);
- if (!src) {
- free(conf);
- wordfree(&p);
- wlr_log(L_ERROR,
- "Unable to allocate resource: Not enough memory");
- return cmd_results_new(CMD_FAILURE, "output",
+ if(!conf) {
+ wlr_log(L_ERROR, "Failed to duplicate string");
+ return cmd_results_new(CMD_FAILURE, "output",
"Unable to allocate resources");
- }
- sprintf(src, "%s/%s", conf_path, p.we_wordv[0]);
+ }
+
+ char *conf_path = dirname(conf);
+ char *rel_path = src;
+ src = malloc(strlen(conf_path) + strlen(src) + 2);
+ if (!src) {
+ free(rel_path);
free(conf);
- } else {
- wlr_log(L_ERROR, "Unable to allocate background source");
+ wlr_log(L_ERROR, "Unable to allocate memory");
+ return cmd_results_new(CMD_FAILURE, "output",
+ "Unable to allocate resources");
}
+
+ sprintf(src, "%s/%s", conf_path, rel_path);
+ free(rel_path);
+ free(conf);
}
if (access(src, F_OK) == -1) {
struct cmd_results *cmd_res = cmd_results_new(CMD_FAILURE, "output",
"Unable to access background file '%s': %s", src, strerror(errno));
free(src);
- wordfree(&p);
return cmd_res;
}
- output->background = strdup(src);
+ output->background = src;
output->background_option = strdup(mode);
- if (src != p.we_wordv[0]) {
- free(src);
- }
- wordfree(&p);
-
argc -= j + 1; argv += j + 1;
}
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) {
struct sway_layer_surface *sway_layer =
wl_container_of(listener, sway_layer, output_destroy);
wl_list_remove(&sway_layer->output_destroy.link);
+ wl_list_remove(&sway_layer->link);
+ wl_list_init(&sway_layer->link);
sway_layer->layer_surface->output = NULL;
wlr_layer_surface_close(sway_layer->layer_surface);
}
@@ -350,10 +352,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
wl_signal_add(&layer_surface->surface->events.commit,
&sway_layer->surface_commit);
- sway_layer->output_destroy.notify = handle_output_destroy;
- wl_signal_add(&layer_surface->output->events.destroy,
- &sway_layer->output_destroy);
-
sway_layer->destroy.notify = handle_destroy;
wl_signal_add(&layer_surface->events.destroy, &sway_layer->destroy);
sway_layer->map.notify = handle_map;
@@ -366,6 +364,9 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
layer_surface->data = sway_layer;
struct sway_output *output = layer_surface->output->data;
+ sway_layer->output_destroy.notify = handle_output_destroy;
+ wl_signal_add(&output->events.destroy, &sway_layer->output_destroy);
+
wl_list_insert(&output->layers[layer_surface->layer], &sway_layer->link);
// 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) {
static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, destroy);
+ wl_signal_emit(&output->events.destroy, output);
+
if (output->swayc) {
container_destroy(output->swayc);
}
@@ -1277,6 +1279,7 @@ void output_enable(struct sway_output *output) {
for (size_t i = 0; i < len; ++i) {
wl_list_init(&output->layers[i]);
}
+ wl_signal_init(&output->events.destroy);
input_manager_configure_xcursor(input_manager);