bindings: defer while initiailizing

This adds the logic to defer binding execution while sway is still
initializing. Without this, the binding command would be executed, but
the command handler would return CMD_DEFER, which was being treated as
a failure to run. To avoid partial executions, this will defer all
bindings while config->active is false.
This commit is contained in:
Brian Ashworth 2019-06-11 21:41:02 -04:00 committed by Simon Ser
parent 2b5bf78faf
commit 9670ccee68
6 changed files with 47 additions and 2 deletions

View file

@ -558,6 +558,11 @@ bool read_config(FILE *file, struct sway_config *config,
*/ */
void run_deferred_commands(void); void run_deferred_commands(void);
/**
* Run the binding commands that were deferred when initializing the inputs
*/
void run_deferred_bindings(void);
/** /**
* Adds a warning entry to the swaynag instance used for errors. * Adds a warning entry to the swaynag instance used for errors.
*/ */

View file

@ -78,6 +78,8 @@ struct sway_seat {
uint32_t last_button_serial; uint32_t last_button_serial;
list_t *deferred_bindings; // struct sway_binding
struct wl_listener focus_destroy; struct wl_listener focus_destroy;
struct wl_listener new_node; struct wl_listener new_node;
struct wl_listener request_start_drag; struct wl_listener request_start_drag;

View file

@ -559,8 +559,20 @@ struct cmd_results *cmd_unbindswitch(int argc, char **argv) {
* Execute the command associated to a binding * Execute the command associated to a binding
*/ */
void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) { void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding) {
sway_log(SWAY_DEBUG, "running command for binding: %s", binding->command); if (!config->active) {
sway_log(SWAY_DEBUG, "deferring command for binding: %s",
binding->command);
struct sway_binding *deferred = calloc(1, sizeof(struct sway_binding));
if (!deferred) {
sway_log(SWAY_ERROR, "Failed to allocate deferred binding");
return;
}
memcpy(deferred, binding, sizeof(struct sway_binding));
list_add(seat->deferred_bindings, deferred);
return;
}
sway_log(SWAY_DEBUG, "running command for binding: %s", binding->command);
struct sway_container *con = NULL; struct sway_container *con = NULL;
if (binding->type == BINDING_MOUSESYM if (binding->type == BINDING_MOUSESYM
|| binding->type == BINDING_MOUSECODE) { || binding->type == BINDING_MOUSECODE) {

View file

@ -644,7 +644,23 @@ void run_deferred_commands(void) {
list_free(res_list); list_free(res_list);
free(line); free(line);
} }
transaction_commit_dirty(); }
void run_deferred_bindings(void) {
struct sway_seat *seat;
wl_list_for_each(seat, &(server.input->seats), link) {
if (!seat->deferred_bindings->length) {
continue;
}
sway_log(SWAY_DEBUG, "Running deferred bindings for seat %s",
seat->wlr_seat->name);
while (seat->deferred_bindings->length) {
struct sway_binding *binding = seat->deferred_bindings->items[0];
seat_execute_command(seat, binding);
list_del(seat->deferred_bindings, 0);
free_sway_binding(binding);
}
}
} }
// get line, with backslash continuation // get line, with backslash continuation

View file

@ -9,6 +9,7 @@
#include <wlr/types/wlr_primary_selection.h> #include <wlr/types/wlr_primary_selection.h>
#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xcursor_manager.h>
#include "config.h" #include "config.h"
#include "list.h"
#include "log.h" #include "log.h"
#include "sway/desktop.h" #include "sway/desktop.h"
#include "sway/input/cursor.h" #include "sway/input/cursor.h"
@ -51,6 +52,10 @@ void seat_destroy(struct sway_seat *seat) {
wl_list_remove(&seat->request_set_primary_selection.link); wl_list_remove(&seat->request_set_primary_selection.link);
wl_list_remove(&seat->link); wl_list_remove(&seat->link);
wlr_seat_destroy(seat->wlr_seat); wlr_seat_destroy(seat->wlr_seat);
for (int i = 0; i < seat->deferred_bindings->length; i++) {
free_sway_binding(seat->deferred_bindings->items[i]);
}
list_free(seat->deferred_bindings);
free(seat->prev_workspace_name); free(seat->prev_workspace_name);
free(seat); free(seat);
} }
@ -445,6 +450,8 @@ struct sway_seat *seat_create(const char *seat_name) {
root_for_each_workspace(collect_focus_workspace_iter, seat); root_for_each_workspace(collect_focus_workspace_iter, seat);
root_for_each_container(collect_focus_container_iter, seat); root_for_each_container(collect_focus_container_iter, seat);
seat->deferred_bindings = create_list();
if (!wl_list_empty(&server.input->seats)) { if (!wl_list_empty(&server.input->seats)) {
// Since this is not the first seat, attempt to set initial focus // Since this is not the first seat, attempt to set initial focus
struct sway_seat *current_seat = input_manager_current_seat(); struct sway_seat *current_seat = input_manager_current_seat();

View file

@ -16,6 +16,7 @@
#include "sway/config.h" #include "sway/config.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/swaynag.h" #include "sway/swaynag.h"
#include "sway/desktop/transaction.h"
#include "sway/tree/root.h" #include "sway/tree/root.h"
#include "sway/ipc-server.h" #include "sway/ipc-server.h"
#include "ipc-client.h" #include "ipc-client.h"
@ -389,6 +390,8 @@ int main(int argc, char **argv) {
config->active = true; config->active = true;
load_swaybars(); load_swaybars();
run_deferred_commands(); run_deferred_commands();
run_deferred_bindings();
transaction_commit_dirty();
if (config->swaynag_config_errors.client != NULL) { if (config->swaynag_config_errors.client != NULL) {
swaynag_show(&config->swaynag_config_errors); swaynag_show(&config->swaynag_config_errors);