mirror of
https://github.com/swaywm/sway.git
synced 2024-11-17 21:49:16 +00:00
Rebase the cursor after applying transactions
This approaches cursor rebasing from a different angle. Rather than littering the codebase with cursor_rebase calls and using transaction callbacks, this just runs cursor_rebase after applying every transaction - but only if there's outputs connected, because otherwise it causes a crash during shutdown. There is one known case where we still need to call cursor_rebase directly, and that's when running `seat seat0 cursor move ...`. This command doesn't set anything as dirty so no transaction occurs.
This commit is contained in:
parent
ea2497d35c
commit
60a1d79de7
|
@ -28,13 +28,6 @@ struct sway_view;
|
||||||
*/
|
*/
|
||||||
void transaction_commit_dirty(void);
|
void transaction_commit_dirty(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Same as above, but runs the specific callback when the transaction is
|
|
||||||
* applied.
|
|
||||||
*/
|
|
||||||
void transaction_commit_dirty_with_callback(
|
|
||||||
void (*callback)(void *data), void *data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify the transaction system that a view is ready for the new layout.
|
* Notify the transaction system that a view is ready for the new layout.
|
||||||
*
|
*
|
||||||
|
|
|
@ -94,10 +94,5 @@ struct cmd_results *cmd_border(int argc, char **argv) {
|
||||||
|
|
||||||
arrange_container(view->container);
|
arrange_container(view->container);
|
||||||
|
|
||||||
struct sway_seat *seat = input_manager_current_seat();
|
|
||||||
if (seat->cursor) {
|
|
||||||
cursor_rebase(seat->cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,7 +236,6 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
|
||||||
if (argc == 0 && container) {
|
if (argc == 0 && container) {
|
||||||
seat_set_focus_container(seat, container);
|
seat_set_focus_container(seat, container);
|
||||||
seat_consider_warp_to_focus(seat);
|
seat_consider_warp_to_focus(seat);
|
||||||
cursor_rebase(seat->cursor);
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,7 +293,6 @@ struct cmd_results *cmd_focus(int argc, char **argv) {
|
||||||
if (next_focus) {
|
if (next_focus) {
|
||||||
seat_set_focus(seat, next_focus);
|
seat_set_focus(seat, next_focus);
|
||||||
seat_consider_warp_to_focus(seat);
|
seat_consider_warp_to_focus(seat);
|
||||||
cursor_rebase(seat->cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#include "sway/desktop.h"
|
#include "sway/desktop.h"
|
||||||
#include "sway/desktop/idle_inhibit_v1.h"
|
#include "sway/desktop/idle_inhibit_v1.h"
|
||||||
#include "sway/desktop/transaction.h"
|
#include "sway/desktop/transaction.h"
|
||||||
|
#include "sway/input/cursor.h"
|
||||||
|
#include "sway/input/input-manager.h"
|
||||||
#include "sway/output.h"
|
#include "sway/output.h"
|
||||||
#include "sway/tree/container.h"
|
#include "sway/tree/container.h"
|
||||||
#include "sway/tree/node.h"
|
#include "sway/tree/node.h"
|
||||||
|
@ -25,8 +27,6 @@ struct sway_transaction {
|
||||||
size_t num_waiting;
|
size_t num_waiting;
|
||||||
size_t num_configures;
|
size_t num_configures;
|
||||||
struct timespec commit_time;
|
struct timespec commit_time;
|
||||||
void (*callback)(void *data);
|
|
||||||
void *callback_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sway_transaction_instruction {
|
struct sway_transaction_instruction {
|
||||||
|
@ -298,8 +298,11 @@ static void transaction_apply(struct sway_transaction *transaction) {
|
||||||
node->instruction = NULL;
|
node->instruction = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (transaction->callback) {
|
if (root->outputs->length) {
|
||||||
transaction->callback(transaction->callback_data);
|
struct sway_seat *seat;
|
||||||
|
wl_list_for_each(seat, &server.input->seats, link) {
|
||||||
|
cursor_rebase(seat->cursor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +508,14 @@ void transaction_notify_view_ready_by_size(struct sway_view *view,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_commit_dirty(struct sway_transaction *transaction) {
|
void transaction_commit_dirty(void) {
|
||||||
|
if (!server.dirty_nodes->length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct sway_transaction *transaction = transaction_create();
|
||||||
|
if (!transaction) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (int i = 0; i < server.dirty_nodes->length; ++i) {
|
for (int i = 0; i < server.dirty_nodes->length; ++i) {
|
||||||
struct sway_node *node = server.dirty_nodes->items[i];
|
struct sway_node *node = server.dirty_nodes->items[i];
|
||||||
transaction_add_node(transaction, node);
|
transaction_add_node(transaction, node);
|
||||||
|
@ -524,28 +534,3 @@ static void do_commit_dirty(struct sway_transaction *transaction) {
|
||||||
transaction_progress_queue();
|
transaction_progress_queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void transaction_commit_dirty(void) {
|
|
||||||
if (!server.dirty_nodes->length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
struct sway_transaction *transaction = transaction_create();
|
|
||||||
if (!transaction) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
do_commit_dirty(transaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
void transaction_commit_dirty_with_callback(
|
|
||||||
void (*callback)(void *data), void *data) {
|
|
||||||
if (!server.dirty_nodes->length) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
struct sway_transaction *transaction = transaction_create();
|
|
||||||
if (!transaction) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
transaction->callback = callback;
|
|
||||||
transaction->callback_data = data;
|
|
||||||
do_commit_dirty(transaction);
|
|
||||||
}
|
|
||||||
|
|
|
@ -397,11 +397,6 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
|
||||||
wl_list_remove(&xdg_shell_view->set_app_id.link);
|
wl_list_remove(&xdg_shell_view->set_app_id.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_rebase(void *data) {
|
|
||||||
struct sway_cursor *cursor = data;
|
|
||||||
cursor_rebase(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_map(struct wl_listener *listener, void *data) {
|
static void handle_map(struct wl_listener *listener, void *data) {
|
||||||
struct sway_xdg_shell_view *xdg_shell_view =
|
struct sway_xdg_shell_view *xdg_shell_view =
|
||||||
wl_container_of(listener, xdg_shell_view, map);
|
wl_container_of(listener, xdg_shell_view, map);
|
||||||
|
@ -428,8 +423,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
|
||||||
view_map(view, view->wlr_xdg_surface->surface,
|
view_map(view, view->wlr_xdg_surface->surface,
|
||||||
xdg_surface->toplevel->client_pending.fullscreen, csd);
|
xdg_surface->toplevel->client_pending.fullscreen, csd);
|
||||||
|
|
||||||
struct sway_seat *seat = input_manager_current_seat();
|
transaction_commit_dirty();
|
||||||
transaction_commit_dirty_with_callback(do_rebase, seat->cursor);
|
|
||||||
|
|
||||||
xdg_shell_view->commit.notify = handle_commit;
|
xdg_shell_view->commit.notify = handle_commit;
|
||||||
wl_signal_add(&xdg_surface->surface->events.commit,
|
wl_signal_add(&xdg_surface->surface->events.commit,
|
||||||
|
|
|
@ -394,11 +394,6 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
|
||||||
wl_list_remove(&xdg_shell_v6_view->set_app_id.link);
|
wl_list_remove(&xdg_shell_v6_view->set_app_id.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_rebase(void *data) {
|
|
||||||
struct sway_cursor *cursor = data;
|
|
||||||
cursor_rebase(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_map(struct wl_listener *listener, void *data) {
|
static void handle_map(struct wl_listener *listener, void *data) {
|
||||||
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
|
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
|
||||||
wl_container_of(listener, xdg_shell_v6_view, map);
|
wl_container_of(listener, xdg_shell_v6_view, map);
|
||||||
|
@ -419,8 +414,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
|
||||||
view_map(view, view->wlr_xdg_surface_v6->surface,
|
view_map(view, view->wlr_xdg_surface_v6->surface,
|
||||||
xdg_surface->toplevel->client_pending.fullscreen, csd);
|
xdg_surface->toplevel->client_pending.fullscreen, csd);
|
||||||
|
|
||||||
struct sway_seat *seat = input_manager_current_seat();
|
transaction_commit_dirty();
|
||||||
transaction_commit_dirty_with_callback(do_rebase, seat->cursor);
|
|
||||||
|
|
||||||
xdg_shell_v6_view->commit.notify = handle_commit;
|
xdg_shell_v6_view->commit.notify = handle_commit;
|
||||||
wl_signal_add(&xdg_surface->surface->events.commit,
|
wl_signal_add(&xdg_surface->surface->events.commit,
|
||||||
|
|
|
@ -391,11 +391,6 @@ static void handle_unmap(struct wl_listener *listener, void *data) {
|
||||||
wl_list_remove(&xwayland_view->commit.link);
|
wl_list_remove(&xwayland_view->commit.link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_rebase(void *data) {
|
|
||||||
struct sway_cursor *cursor = data;
|
|
||||||
cursor_rebase(cursor);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void handle_map(struct wl_listener *listener, void *data) {
|
static void handle_map(struct wl_listener *listener, void *data) {
|
||||||
struct sway_xwayland_view *xwayland_view =
|
struct sway_xwayland_view *xwayland_view =
|
||||||
wl_container_of(listener, xwayland_view, map);
|
wl_container_of(listener, xwayland_view, map);
|
||||||
|
@ -422,8 +417,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
|
||||||
// Put it back into the tree
|
// Put it back into the tree
|
||||||
view_map(view, xsurface->surface, xsurface->fullscreen, false);
|
view_map(view, xsurface->surface, xsurface->fullscreen, false);
|
||||||
|
|
||||||
struct sway_seat *seat = input_manager_current_seat();
|
transaction_commit_dirty();
|
||||||
transaction_commit_dirty_with_callback(do_rebase, seat->cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_request_configure(struct wl_listener *listener, void *data) {
|
static void handle_request_configure(struct wl_listener *listener, void *data) {
|
||||||
|
|
|
@ -1196,5 +1196,4 @@ void seat_consider_warp_to_focus(struct sway_seat *seat) {
|
||||||
} else {
|
} else {
|
||||||
cursor_warp_to_workspace(seat->cursor, focus->sway_workspace);
|
cursor_warp_to_workspace(seat->cursor, focus->sway_workspace);
|
||||||
}
|
}
|
||||||
cursor_rebase(seat->cursor);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -661,7 +661,6 @@ void view_unmap(struct sway_view *view) {
|
||||||
cursor_warp_to_workspace(seat->cursor, node->sway_workspace);
|
cursor_warp_to_workspace(seat->cursor, node->sway_workspace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cursor_rebase(seat->cursor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
transaction_commit_dirty();
|
transaction_commit_dirty();
|
||||||
|
|
|
@ -404,7 +404,6 @@ bool workspace_switch(struct sway_workspace *workspace,
|
||||||
}
|
}
|
||||||
seat_set_focus(seat, next);
|
seat_set_focus(seat, next);
|
||||||
arrange_workspace(workspace);
|
arrange_workspace(workspace);
|
||||||
cursor_rebase(seat->cursor);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue