diff options
-rw-r--r-- | include/sway/config.h | 2 | ||||
-rw-r--r-- | include/sway/output.h | 4 | ||||
-rw-r--r-- | sway/commands/output/background.c | 18 | ||||
-rw-r--r-- | sway/config/output.c | 38 | ||||
-rw-r--r-- | sway/desktop/output.c | 62 | ||||
-rw-r--r-- | sway/tree/output.c | 27 |
6 files changed, 89 insertions, 62 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 978606a6..8215ff59 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -568,7 +568,7 @@ struct output_config *new_output_config(const char *name); void merge_output_config(struct output_config *dst, struct output_config *src); -void apply_output_config(struct output_config *oc, struct sway_output *output); +bool apply_output_config(struct output_config *oc, struct sway_output *output); struct output_config *store_output_config(struct output_config *oc); diff --git a/include/sway/output.h b/include/sway/output.h index bdf9614d..9ebdb6c1 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -31,7 +31,7 @@ struct sway_output { int lx, ly; int width, height; - bool enabled; + bool enabled, configured; list_t *workspaces; struct sway_output_state current; @@ -144,8 +144,6 @@ void output_get_box(struct sway_output *output, struct wlr_box *box); enum sway_container_layout output_get_default_layout( struct sway_output *output); -void output_add_listeners(struct sway_output *output); - void render_rect(struct wlr_output *wlr_output, pixman_region32_t *output_damage, const struct wlr_box *_box, float color[static 4]); diff --git a/sway/commands/output/background.c b/sway/commands/output/background.c index ae2f0640..00038e67 100644 --- a/sway/commands/output/background.c +++ b/sway/commands/output/background.c @@ -34,8 +34,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { struct output_config *output = config->handler_context.output_config; if (strcasecmp(argv[1], "solid_color") == 0) { - output->background = calloc(1, strlen(argv[0]) + 3); - snprintf(output->background, strlen(argv[0]) + 3, "\"%s\"", argv[0]); + output->background = strdup(argv[0]); output->background_option = strdup("solid_color"); output->background_fallback = NULL; argc -= 2; argv += 2; @@ -119,16 +118,6 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { src); free(src); } else { - // Escape double quotes in the final path for swaybg - for (size_t i = 0; i < strlen(src); i++) { - if (src[i] == '"') { - src = realloc(src, strlen(src) + 2); - memmove(src + i + 1, src + i, strlen(src + i) + 1); - *(src + i) = '\\'; - i++; - } - } - output->background = src; output->background_option = strdup(mode); } @@ -136,9 +125,7 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { output->background_fallback = NULL; if (argc && *argv[0] == '#') { - output->background_fallback = calloc(1, strlen(argv[0]) + 3); - snprintf(output->background_fallback, strlen(argv[0]) + 3, - "\"%s\"", argv[0]); + output->background_fallback = strdup(argv[0]); argc--; argv++; if (!can_access) { @@ -153,4 +140,3 @@ struct cmd_results *output_cmd_background(int argc, char **argv) { config->handler_context.leftovers.argv = argv; return NULL; } - diff --git a/sway/config/output.c b/sway/config/output.c index f23d316d..6e504751 100644 --- a/sway/config/output.c +++ b/sway/config/output.c @@ -137,13 +137,12 @@ struct output_config *store_output_config(struct output_config *oc) { return oc; } -static void set_mode(struct wlr_output *output, int width, int height, +static bool set_mode(struct wlr_output *output, int width, int height, float refresh_rate) { int mhz = (int)(refresh_rate * 1000); if (wl_list_empty(&output->modes)) { wlr_log(WLR_DEBUG, "Assigning custom mode to %s", output->name); - wlr_output_set_custom_mode(output, width, height, mhz); - return; + return wlr_output_set_custom_mode(output, width, height, mhz); } struct wlr_output_mode *mode, *best = NULL; @@ -158,10 +157,12 @@ static void set_mode(struct wlr_output *output, int width, int height, } if (!best) { wlr_log(WLR_ERROR, "Configured mode for %s not available", output->name); + wlr_log(WLR_INFO, "Picking default mode instead"); + best = wl_container_of(output->modes.prev, mode, link); } else { wlr_log(WLR_DEBUG, "Assigning configured mode to %s", output->name); - wlr_output_set_mode(output, best); } + return wlr_output_set_mode(output, best); } void terminate_swaybg(pid_t pid) { @@ -174,33 +175,48 @@ void terminate_swaybg(pid_t pid) { } } -void apply_output_config(struct output_config *oc, struct sway_output *output) { +bool apply_output_config(struct output_config *oc, struct sway_output *output) { struct wlr_output *wlr_output = output->wlr_output; - if (oc && oc->enabled == 0) { + if (oc && !oc->enabled) { + // Output is configured to be disabled if (output->enabled) { output_disable(output); wlr_output_layout_remove(root->output_layout, wlr_output); } wlr_output_enable(wlr_output, false); - return; + return true; } else if (!output->enabled) { + // Output is not enabled. Enable it, output_enable will call us again. if (!oc || oc->dpms_state != DPMS_OFF) { wlr_output_enable(wlr_output, true); } output_enable(output, oc); - return; + return true; } + bool modeset_success; if (oc && oc->width > 0 && oc->height > 0) { wlr_log(WLR_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width, oc->height, oc->refresh_rate); - set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate); + modeset_success = + set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate); } else if (!wl_list_empty(&wlr_output->modes)) { struct wlr_output_mode *mode = wl_container_of(wlr_output->modes.prev, mode, link); - wlr_output_set_mode(wlr_output, mode); + modeset_success = wlr_output_set_mode(wlr_output, mode); + } else { + // Output doesn't support modes + modeset_success = true; } + if (!modeset_success) { + // Failed to modeset, maybe the output is missing a CRTC. Leave the + // output disabled for now and try again when the output gets the mode + // we asked for. + wlr_log(WLR_ERROR, "Failed to modeset output %s", wlr_output->name); + return false; + } + if (oc && oc->scale > 0) { wlr_log(WLR_DEBUG, "Set %s scale to %f", oc->name, oc->scale); wlr_output_set_scale(wlr_output, oc->scale); @@ -264,6 +280,8 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) { break; } } + + return true; } static void default_output_config(struct output_config *oc, diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 04c9b4f6..37651d66 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -359,8 +359,7 @@ static void send_frame_done(struct sway_output *output, struct timespec *when) { static void damage_handle_frame(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, damage_frame); - - if (!output->wlr_output->enabled) { + if (!output->enabled || !output->wlr_output->enabled) { return; } @@ -475,6 +474,9 @@ void output_damage_whole_container(struct sway_output *output, static void damage_handle_destroy(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, damage_destroy); + if (!output->enabled) { + return; + } output_disable(output); transaction_commit_dirty(); } @@ -488,11 +490,33 @@ static void handle_destroy(struct wl_listener *listener, void *data) { } output_begin_destroy(output); + wl_list_remove(&output->destroy.link); + wl_list_remove(&output->mode.link); + wl_list_remove(&output->transform.link); + wl_list_remove(&output->scale.link); + wl_list_remove(&output->present.link); + wl_list_remove(&output->damage_destroy.link); + wl_list_remove(&output->damage_frame.link); + transaction_commit_dirty(); } static void handle_mode(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, mode); + if (!output->configured) { + return; + } + if (!output->enabled) { + struct output_config *oc = output_find_config(output); + if (output->wlr_output->current_mode != NULL && + (!oc || oc->enabled)) { + // We want to enable this output, but it didn't work last time, + // possibly because we hadn't enough CRTCs. Try again now that the + // output has a mode. + output_enable(output, oc); + } + return; + } arrange_layers(output); arrange_output(output); transaction_commit_dirty(); @@ -500,6 +524,9 @@ static void handle_mode(struct wl_listener *listener, void *data) { static void handle_transform(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, transform); + if (!output->enabled) { + return; + } arrange_layers(output); arrange_output(output); transaction_commit_dirty(); @@ -512,6 +539,9 @@ static void update_textures(struct sway_container *con, void *data) { static void handle_scale(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, scale); + if (!output->enabled) { + return; + } arrange_layers(output); output_for_each_container(output, update_textures, NULL); arrange_output(output); @@ -530,6 +560,10 @@ static void handle_present(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, present); struct wlr_output_event_present *output_event = data; + if (!output->enabled) { + return; + } + struct wlr_presentation_event event = { .output = output->wlr_output, .tv_sec = (uint64_t)output_event->when->tv_sec, @@ -552,10 +586,23 @@ void handle_new_output(struct wl_listener *listener, void *data) { } output->server = server; output->damage = wlr_output_damage_create(wlr_output); + + wl_signal_add(&wlr_output->events.destroy, &output->destroy); output->destroy.notify = handle_destroy; + wl_signal_add(&wlr_output->events.mode, &output->mode); + output->mode.notify = handle_mode; + wl_signal_add(&wlr_output->events.transform, &output->transform); + output->transform.notify = handle_transform; + wl_signal_add(&wlr_output->events.scale, &output->scale); + output->scale.notify = handle_scale; + wl_signal_add(&wlr_output->events.present, &output->present); + output->present.notify = handle_present; + wl_signal_add(&output->damage->events.frame, &output->damage_frame); + output->damage_frame.notify = damage_handle_frame; + wl_signal_add(&output->damage->events.destroy, &output->damage_destroy); + output->damage_destroy.notify = damage_handle_destroy; struct output_config *oc = output_find_config(output); - if (!oc || oc->enabled) { output_enable(output, oc); } else { @@ -564,12 +611,3 @@ void handle_new_output(struct wl_listener *listener, void *data) { transaction_commit_dirty(); } - -void output_add_listeners(struct sway_output *output) { - output->mode.notify = handle_mode; - output->transform.notify = handle_transform; - output->scale.notify = handle_scale; - output->present.notify = handle_present; - output->damage_frame.notify = damage_handle_frame; - output->damage_destroy.notify = damage_handle_destroy; -} diff --git a/sway/tree/output.c b/sway/tree/output.c index f24be010..b79e70d4 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -57,7 +57,6 @@ struct sway_output *output_create(struct wlr_output *wlr_output) { output->wlr_output = wlr_output; wlr_output->data = output; - wl_signal_add(&wlr_output->events.destroy, &output->destroy); wl_signal_init(&output->events.destroy); wl_list_insert(&root->all_outputs, &output->link); @@ -79,6 +78,12 @@ void output_enable(struct sway_output *output, struct output_config *oc) { } output->enabled = true; + if (!apply_output_config(oc, output)) { + output->enabled = false; + return; + } + + output->configured = true; list_add(root->outputs, output); output->lx = wlr_output->lx; @@ -105,8 +110,6 @@ void output_enable(struct sway_output *output, struct output_config *oc) { ipc_event_workspace(NULL, ws, "init"); } - apply_output_config(oc, output); - if (ws && config->default_orientation == L_NONE) { // Since the output transformation and resolution could have changed // due to applying the output config, the previously set layout for the @@ -116,15 +119,6 @@ void output_enable(struct sway_output *output, struct output_config *oc) { input_manager_configure_xcursor(); - wl_signal_add(&wlr_output->events.mode, &output->mode); - wl_signal_add(&wlr_output->events.transform, &output->transform); - wl_signal_add(&wlr_output->events.scale, &output->scale); - wl_signal_add(&wlr_output->events.present, &output->present); - wl_signal_add(&output->damage->events.frame, &output->damage_frame); - wl_signal_add(&output->damage->events.destroy, &output->damage_destroy); - - output_add_listeners(output); - wl_signal_emit(&root->events.new_node, &output->node); arrange_layers(output); @@ -233,14 +227,8 @@ void output_disable(struct sway_output *output) { int index = list_find(root->outputs, output); list_del(root->outputs, index); - wl_list_remove(&output->mode.link); - wl_list_remove(&output->transform.link); - wl_list_remove(&output->scale.link); - wl_list_remove(&output->present.link); - wl_list_remove(&output->damage_destroy.link); - wl_list_remove(&output->damage_frame.link); - output->enabled = false; + output->configured = false; arrange_root(); } @@ -255,7 +243,6 @@ void output_begin_destroy(struct sway_output *output) { node_set_dirty(&output->node); wl_list_remove(&output->link); - wl_list_remove(&output->destroy.link); output->wlr_output->data = NULL; output->wlr_output = NULL; } |