Merge branch 'master' into disable_titlebar

This commit is contained in:
neuromagus 2024-03-28 16:56:44 +03:00 committed by GitHub
commit af5c748094
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 207 additions and 125 deletions

View file

@ -291,6 +291,14 @@ struct output_config {
char *background_fallback; char *background_fallback;
}; };
/**
* An output config pre-matched to an output
*/
struct matched_output_config {
struct sway_output *output;
struct output_config *config;
};
/** /**
* Stores size of gaps for each side * Stores size of gaps for each side
*/ */
@ -681,20 +689,15 @@ const char *sway_output_scale_filter_to_string(enum scale_filter_mode scale_filt
struct output_config *new_output_config(const char *name); struct output_config *new_output_config(const char *name);
void merge_output_config(struct output_config *dst, struct output_config *src); bool apply_output_configs(struct matched_output_config *configs,
size_t configs_len, bool test_only);
bool apply_output_config(struct output_config *oc, struct sway_output *output); void apply_all_output_configs(void);
bool test_output_config(struct output_config *oc, struct sway_output *output);
struct output_config *store_output_config(struct output_config *oc); struct output_config *store_output_config(struct output_config *oc);
struct output_config *find_output_config(struct sway_output *output); struct output_config *find_output_config(struct sway_output *output);
void apply_output_config_to_outputs(struct output_config *oc);
void reset_outputs(void);
void free_output_config(struct output_config *oc); void free_output_config(struct output_config *oc);
bool spawn_swaybg(void); bool spawn_swaybg(void);

View file

@ -103,13 +103,13 @@ struct cmd_results *cmd_output(int argc, char **argv) {
bool background = output->background; bool background = output->background;
output = store_output_config(output); store_output_config(output);
// If reloading, the output configs will be applied after reading the // If reloading, the output configs will be applied after reading the
// entire config and before the deferred commands so that an auto generated // entire config and before the deferred commands so that an auto generated
// workspace name is not given to re-enabled outputs. // workspace name is not given to re-enabled outputs.
if (!config->reloading && !config->validating) { if (!config->reloading && !config->validating) {
apply_output_config_to_outputs(output); apply_all_output_configs();
if (background) { if (background) {
if (!spawn_swaybg()) { if (!spawn_swaybg()) {
return cmd_results_new(CMD_FAILURE, return cmd_results_new(CMD_FAILURE,

View file

@ -29,7 +29,7 @@ struct cmd_results *output_cmd_toggle(int argc, char **argv) {
config->handler_context.output_config->enabled = 1; config->handler_context.output_config->enabled = 1;
} }
free(oc); free_output_config(oc);
config->handler_context.leftovers.argc = argc; config->handler_context.leftovers.argc = argc;
config->handler_context.leftovers.argv = argv; config->handler_context.leftovers.argv = argv;
return NULL; return NULL;

View file

@ -533,7 +533,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
} }
sway_switch_retrigger_bindings_for_all(); sway_switch_retrigger_bindings_for_all();
reset_outputs(); apply_all_output_configs();
spawn_swaybg(); spawn_swaybg();
config->reloading = false; config->reloading = false;

View file

@ -9,6 +9,7 @@
#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_swapchain_manager.h>
#include "sway/config.h" #include "sway/config.h"
#include "sway/input/cursor.h" #include "sway/input/cursor.h"
#include "sway/output.h" #include "sway/output.h"
@ -78,7 +79,7 @@ struct output_config *new_output_config(const char *name) {
return oc; return oc;
} }
void merge_output_config(struct output_config *dst, struct output_config *src) { static void merge_output_config(struct output_config *dst, struct output_config *src) {
if (src->enabled != -1) { if (src->enabled != -1) {
dst->enabled = src->enabled; dst->enabled = src->enabled;
} }
@ -503,25 +504,12 @@ static void queue_output_config(struct output_config *oc,
} }
} }
bool apply_output_config(struct output_config *oc, struct sway_output *output) { static bool finalize_output_config(struct output_config *oc, struct sway_output *output) {
if (output == root->fallback_output) { if (output == root->fallback_output) {
return false; return false;
} }
struct wlr_output *wlr_output = output->wlr_output; struct wlr_output *wlr_output = output->wlr_output;
struct wlr_output_state pending = {0};
queue_output_config(oc, output, &pending);
sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name);
if (!wlr_output_commit_state(wlr_output, &pending)) {
// Failed to commit output changes, 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.
sway_log(SWAY_ERROR, "Failed to commit output %s", wlr_output->name);
return false;
}
if (oc && !oc->enabled) { if (oc && !oc->enabled) {
sway_log(SWAY_DEBUG, "Disabling output %s", oc->name); sway_log(SWAY_DEBUG, "Disabling output %s", oc->name);
if (output->enabled) { if (output->enabled) {
@ -577,25 +565,9 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
output->max_render_time = oc->max_render_time; output->max_render_time = oc->max_render_time;
} }
// Reconfigure all devices, since input config may have been applied before
// this output came online, and some config items (like map_to_output) are
// dependent on an output being present.
input_manager_configure_all_input_mappings();
// Reconfigure the cursor images, since the scale may have changed.
input_manager_configure_xcursor();
return true; return true;
} }
bool test_output_config(struct output_config *oc, struct sway_output *output) {
if (output == root->fallback_output) {
return false;
}
struct wlr_output_state pending = {0};
queue_output_config(oc, output, &pending);
return wlr_output_test_state(output->wlr_output, &pending);
}
static void default_output_config(struct output_config *oc, static void default_output_config(struct output_config *oc,
struct wlr_output *wlr_output) { struct wlr_output *wlr_output) {
oc->enabled = 1; oc->enabled = 1;
@ -705,50 +677,124 @@ struct output_config *find_output_config(struct sway_output *output) {
return get_output_config(id, output); return get_output_config(id, output);
} }
void apply_output_config_to_outputs(struct output_config *oc) { bool apply_output_configs(struct matched_output_config *configs,
// Try to find the output container and apply configuration now. If size_t configs_len, bool test_only) {
// this is during startup then there will be no container and config struct wlr_backend_output_state *states = calloc(configs_len, sizeof(*states));
// will be applied during normal "new output" event from wlroots. if (!states) {
bool wildcard = strcmp(oc->name, "*") == 0; return false;
struct sway_output *sway_output, *tmp; }
wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) {
if (output_match_name_or_id(sway_output, oc->name)) {
char id[128];
output_get_identifier(id, sizeof(id), sway_output);
struct output_config *current = get_output_config(id, sway_output);
if (!current) {
// No stored output config matched, apply oc directly
sway_log(SWAY_DEBUG, "Applying oc directly");
current = new_output_config(oc->name);
merge_output_config(current, oc);
}
apply_output_config(current, sway_output);
free_output_config(current);
if (!wildcard) { sway_log(SWAY_DEBUG, "Committing %zd outputs", configs_len);
// Stop looking if the output config isn't applicable to all for (size_t idx = 0; idx < configs_len; idx++) {
// outputs struct matched_output_config *cfg = &configs[idx];
break; struct wlr_backend_output_state *backend_state = &states[idx];
}
backend_state->output = cfg->output->wlr_output;
wlr_output_state_init(&backend_state->base);
sway_log(SWAY_DEBUG, "Preparing config for %s",
cfg->output->wlr_output->name);
queue_output_config(cfg->config, cfg->output, &backend_state->base);
}
struct wlr_output_swapchain_manager swapchain_mgr;
wlr_output_swapchain_manager_init(&swapchain_mgr, server.backend);
bool ok = wlr_output_swapchain_manager_prepare(&swapchain_mgr, states, configs_len);
if (!ok) {
sway_log(SWAY_ERROR, "Swapchain prepare failed");
goto out;
}
if (test_only) {
// The swapchain manager already did a test for us
goto out;
}
for (size_t idx = 0; idx < configs_len; idx++) {
struct matched_output_config *cfg = &configs[idx];
struct wlr_backend_output_state *backend_state = &states[idx];
struct wlr_scene_output_state_options opts = {
.swapchain = wlr_output_swapchain_manager_get_swapchain(
&swapchain_mgr, backend_state->output),
};
struct wlr_scene_output *scene_output = cfg->output->scene_output;
struct wlr_output_state *state = &backend_state->base;
if (!wlr_scene_output_build_state(scene_output, state, &opts)) {
sway_log(SWAY_ERROR, "Building output state for '%s' failed",
backend_state->output->name);
goto out;
} }
} }
ok = wlr_backend_commit(server.backend, states, configs_len);
if (!ok) {
sway_log(SWAY_ERROR, "Backend commit failed");
goto out;
}
sway_log(SWAY_DEBUG, "Commit of %zd outputs succeeded", configs_len);
wlr_output_swapchain_manager_apply(&swapchain_mgr);
for (size_t idx = 0; idx < configs_len; idx++) {
struct matched_output_config *cfg = &configs[idx];
sway_log(SWAY_DEBUG, "Finalizing config for %s",
cfg->output->wlr_output->name);
finalize_output_config(cfg->config, cfg->output);
}
out:
wlr_output_swapchain_manager_finish(&swapchain_mgr);
for (size_t idx = 0; idx < configs_len; idx++) {
struct wlr_backend_output_state *backend_state = &states[idx];
wlr_output_state_finish(&backend_state->base);
}
free(states);
// Reconfigure all devices, since input config may have been applied before
// this output came online, and some config items (like map_to_output) are
// dependent on an output being present.
input_manager_configure_all_input_mappings();
// Reconfigure the cursor images, since the scale may have changed.
input_manager_configure_xcursor();
struct sway_seat *seat; struct sway_seat *seat;
wl_list_for_each(seat, &server.input->seats, link) { wl_list_for_each(seat, &server.input->seats, link) {
wlr_seat_pointer_notify_clear_focus(seat->wlr_seat); wlr_seat_pointer_notify_clear_focus(seat->wlr_seat);
cursor_rebase(seat->cursor); cursor_rebase(seat->cursor);
} }
return ok;
} }
void reset_outputs(void) { void apply_all_output_configs(void) {
struct output_config *oc = NULL; size_t configs_len = wl_list_length(&root->all_outputs);
int i = list_seq_find(config->output_configs, output_name_cmp, "*"); struct matched_output_config *configs = calloc(configs_len, sizeof(*configs));
if (i >= 0) { if (!configs) {
oc = config->output_configs->items[i]; return;
} else {
oc = store_output_config(new_output_config("*"));
} }
apply_output_config_to_outputs(oc);
int config_idx = 0;
struct sway_output *sway_output;
wl_list_for_each(sway_output, &root->all_outputs, link) {
if (sway_output == root->fallback_output) {
configs_len--;
continue;
}
struct matched_output_config *config = &configs[config_idx++];
config->output = sway_output;
config->config = find_output_config(sway_output);
}
apply_output_configs(configs, configs_len, false);
for (size_t idx = 0; idx < configs_len; idx++) {
struct matched_output_config *cfg = &configs[idx];
free_output_config(cfg->config);
}
free(configs);
} }
void free_output_config(struct output_config *oc) { void free_output_config(struct output_config *oc) {

View file

@ -521,9 +521,7 @@ void handle_new_output(struct wl_listener *listener, void *data) {
sway_session_lock_add_output(server->session_lock.lock, output); sway_session_lock_add_output(server->session_lock.lock, output);
} }
struct output_config *oc = find_output_config(output); apply_all_output_configs();
apply_output_config(oc, output);
free_output_config(oc);
transaction_commit_dirty(); transaction_commit_dirty();
@ -552,63 +550,88 @@ void handle_gamma_control_set_gamma(struct wl_listener *listener, void *data) {
wlr_output_schedule_frame(output->wlr_output); wlr_output_schedule_frame(output->wlr_output);
} }
static struct output_config *output_config_for_config_head(
struct wlr_output_configuration_head_v1 *config_head,
struct sway_output *output) {
struct output_config *oc = new_output_config(output->wlr_output->name);
oc->enabled = config_head->state.enabled;
if (!oc->enabled) {
return oc;
}
if (config_head->state.mode != NULL) {
struct wlr_output_mode *mode = config_head->state.mode;
oc->width = mode->width;
oc->height = mode->height;
oc->refresh_rate = mode->refresh / 1000.f;
} else {
oc->width = config_head->state.custom_mode.width;
oc->height = config_head->state.custom_mode.height;
oc->refresh_rate =
config_head->state.custom_mode.refresh / 1000.f;
}
oc->x = config_head->state.x;
oc->y = config_head->state.y;
oc->transform = config_head->state.transform;
oc->scale = config_head->state.scale;
oc->adaptive_sync = config_head->state.adaptive_sync_enabled;
return oc;
}
static void output_manager_apply(struct sway_server *server, static void output_manager_apply(struct sway_server *server,
struct wlr_output_configuration_v1 *config, bool test_only) { struct wlr_output_configuration_v1 *config, bool test_only) {
// TODO: perform atomic tests on the whole backend atomically size_t configs_len = wl_list_length(&root->all_outputs);
struct matched_output_config *configs = calloc(configs_len, sizeof(*configs));
if (!configs) {
return;
}
struct wlr_output_configuration_head_v1 *config_head; int config_idx = 0;
// First disable outputs we need to disable struct sway_output *sway_output;
bool ok = true; wl_list_for_each(sway_output, &root->all_outputs, link) {
wl_list_for_each(config_head, &config->heads, link) { if (sway_output == root->fallback_output) {
struct wlr_output *wlr_output = config_head->state.output; configs_len--;
struct sway_output *output = wlr_output->data;
if (!output->enabled || config_head->state.enabled) {
continue; continue;
} }
struct output_config *oc = new_output_config(output->wlr_output->name);
oc->enabled = false;
if (test_only) { struct matched_output_config *cfg = &configs[config_idx++];
ok &= test_output_config(oc, output); cfg->output = sway_output;
} else {
oc = store_output_config(oc); struct wlr_output_configuration_head_v1 *config_head;
ok &= apply_output_config(oc, output); wl_list_for_each(config_head, &config->heads, link) {
if (config_head->state.output == sway_output->wlr_output) {
cfg->config = output_config_for_config_head(config_head, sway_output);
break;
}
}
if (!cfg->config) {
cfg->config = find_output_config(sway_output);
} }
} }
// Then enable outputs that need to bool ok = apply_output_configs(configs, configs_len, test_only);
wl_list_for_each(config_head, &config->heads, link) { for (size_t idx = 0; idx < configs_len; idx++) {
struct wlr_output *wlr_output = config_head->state.output; struct matched_output_config *cfg = &configs[idx];
struct sway_output *output = wlr_output->data;
if (!config_head->state.enabled) {
continue;
}
struct output_config *oc = new_output_config(output->wlr_output->name);
oc->enabled = true;
if (config_head->state.mode != NULL) {
struct wlr_output_mode *mode = config_head->state.mode;
oc->width = mode->width;
oc->height = mode->height;
oc->refresh_rate = mode->refresh / 1000.f;
} else {
oc->width = config_head->state.custom_mode.width;
oc->height = config_head->state.custom_mode.height;
oc->refresh_rate =
config_head->state.custom_mode.refresh / 1000.f;
}
oc->x = config_head->state.x;
oc->y = config_head->state.y;
oc->transform = config_head->state.transform;
oc->scale = config_head->state.scale;
oc->adaptive_sync = config_head->state.adaptive_sync_enabled;
if (test_only) { // Only store new configs for successful non-test commits. Old configs,
ok &= test_output_config(oc, output); // test-only and failed commits just get freed.
bool store_config = false;
if (!test_only && ok) {
struct wlr_output_configuration_head_v1 *config_head;
wl_list_for_each(config_head, &config->heads, link) {
if (config_head->state.output == sway_output->wlr_output) {
store_config = true;
break;
}
}
}
if (store_config) {
store_output_config(cfg->config);
} else { } else {
oc = store_output_config(oc); free_output_config(cfg->config);
ok &= apply_output_config(oc, output);
} }
} }
free(configs);
if (ok) { if (ok) {
wlr_output_configuration_v1_send_succeeded(config); wlr_output_configuration_v1_send_succeeded(config);
@ -652,6 +675,6 @@ void handle_output_power_manager_set_mode(struct wl_listener *listener,
oc->power = 1; oc->power = 1;
break; break;
} }
oc = store_output_config(oc); store_output_config(oc);
apply_output_config(oc, output); apply_all_output_configs();
} }

View file

@ -117,7 +117,11 @@ static void handle_touch_cancel(struct sway_seat *seat,
} }
if (e->surface) { if (e->surface) {
wlr_seat_touch_notify_cancel(seat->wlr_seat, e->surface); struct wl_client *client = wl_resource_get_client(e->surface->resource);
struct wlr_seat_client *seat_client = wlr_seat_client_for_wl_client(seat->wlr_seat, client);
if (seat_client != NULL) {
wlr_seat_touch_notify_cancel(seat->wlr_seat, seat_client);
}
} }
if (wl_list_empty(&e->point_events)) { if (wl_list_empty(&e->point_events)) {

View file

@ -400,6 +400,12 @@ runtime.
only be available for that group. By default, if you overwrite a binding, only be available for that group. By default, if you overwrite a binding,
swaynag will give you a warning. To silence this, use the _--no-warn_ flag. swaynag will give you a warning. To silence this, use the _--no-warn_ flag.
For specifying modifier keys, you can use the XKB modifier names _Shift_,
_Lock_ (for Caps Lock), _Control_, _Mod1_ (for Alt), _Mod2_ (for Num Lock),
_Mod3_ (for XKB modifier Mod3), _Mod4_ (for the Logo key), and _Mod5_ (for
AltGr). In addition, you can use the aliases _Ctrl_ (for Control) and _Alt_
(for Alt).
Unless the flag _--locked_ is set, the command will not be run when a Unless the flag _--locked_ is set, the command will not be run when a
screen locking program is active. If there is a matching binding with screen locking program is active. If there is a matching binding with
and without _--locked_, the one with will be preferred when locked and the and without _--locked_, the one with will be preferred when locked and the