mirror of
https://github.com/swaywm/sway.git
synced 2025-11-20 06:59:46 -05:00
Minor refactor of input manager
The input manager is a singleton object. Passing the sway_input_manager argument to each of its functions is unnecessary, while removing the argument makes it obvious to the caller that it's a singleton. This patch removes the argument and makes the input manager use server.input instead. On a similar note: * sway_input_manager.server is removed in favour of using the server global. * seat.input is removed because it can get it from server.input. Due to a circular dependency, creating seat0 is now done directly in server_init rather than in input_manager_create. This is because creating seats must be done after server.input is set. Lastly, it now stores the default seat name using a constant and removes a second reference to seat0 (in input_manager_get_default_seat).
This commit is contained in:
parent
5b8257b88f
commit
c006717910
28 changed files with 116 additions and 149 deletions
|
|
@ -680,7 +680,7 @@ void cursor_send_pointer_motion(struct sway_cursor *cursor,
|
|||
|
||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, motion);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_pointer_motion *event = data;
|
||||
wlr_cursor_move(cursor->cursor, event->device,
|
||||
event->delta_x, event->delta_y);
|
||||
|
|
@ -692,7 +692,7 @@ static void handle_cursor_motion_absolute(
|
|||
struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor =
|
||||
wl_container_of(listener, cursor, motion_absolute);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_pointer_motion_absolute *event = data;
|
||||
wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, event->y);
|
||||
cursor_send_pointer_motion(cursor, event->time_msec);
|
||||
|
|
@ -970,7 +970,7 @@ void dispatch_cursor_button(struct sway_cursor *cursor,
|
|||
|
||||
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, button);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_pointer_button *event = data;
|
||||
dispatch_cursor_button(cursor, event->device,
|
||||
event->time_msec, event->button, event->state);
|
||||
|
|
@ -1019,7 +1019,7 @@ static void dispatch_cursor_axis(struct sway_cursor *cursor,
|
|||
|
||||
static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, axis);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_pointer_axis *event = data;
|
||||
dispatch_cursor_axis(cursor, event);
|
||||
transaction_commit_dirty();
|
||||
|
|
@ -1027,7 +1027,7 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_touch_down(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_down);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_touch_down *event = data;
|
||||
|
||||
struct sway_seat *seat = cursor->seat;
|
||||
|
|
@ -1058,7 +1058,7 @@ static void handle_touch_down(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_touch_up(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, touch_up);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_touch_up *event = data;
|
||||
struct wlr_seat *seat = cursor->seat->wlr_seat;
|
||||
// TODO: fall back to cursor simulation if client has not bound to touch
|
||||
|
|
@ -1068,7 +1068,7 @@ static void handle_touch_up(struct wl_listener *listener, void *data) {
|
|||
static void handle_touch_motion(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor =
|
||||
wl_container_of(listener, cursor, touch_motion);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_touch_motion *event = data;
|
||||
|
||||
struct sway_seat *seat = cursor->seat;
|
||||
|
|
@ -1132,7 +1132,7 @@ static void apply_mapping_from_region(struct wlr_input_device *device,
|
|||
|
||||
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_tablet_tool_axis *event = data;
|
||||
struct sway_input_device *input_device = event->device->data;
|
||||
|
||||
|
|
@ -1156,7 +1156,7 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_tip);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_tablet_tool_tip *event = data;
|
||||
dispatch_cursor_button(cursor, event->device, event->time_msec,
|
||||
BTN_LEFT, event->state == WLR_TABLET_TOOL_TIP_DOWN ?
|
||||
|
|
@ -1166,7 +1166,7 @@ static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
|||
|
||||
static void handle_tool_button(struct wl_listener *listener, void *data) {
|
||||
struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_button);
|
||||
wlr_idle_notify_activity(cursor->seat->input->server->idle, cursor->seat->wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, cursor->seat->wlr_seat);
|
||||
struct wlr_event_tablet_tool_button *event = data;
|
||||
// TODO: the user may want to configure which tool buttons are mapped to
|
||||
// which simulated pointer buttons
|
||||
|
|
|
|||
|
|
@ -17,32 +17,28 @@
|
|||
#include "list.h"
|
||||
#include "log.h"
|
||||
|
||||
static const char *default_seat = "seat0";
|
||||
|
||||
// TODO make me not global
|
||||
struct sway_input_manager *input_manager;
|
||||
#define DEFAULT_SEAT "seat0"
|
||||
|
||||
struct input_config *current_input_config = NULL;
|
||||
struct seat_config *current_seat_config = NULL;
|
||||
|
||||
struct sway_seat *input_manager_current_seat(struct sway_input_manager *input) {
|
||||
struct sway_seat *input_manager_current_seat(void) {
|
||||
struct sway_seat *seat = config->handler_context.seat;
|
||||
if (!seat) {
|
||||
seat = input_manager_get_default_seat(input_manager);
|
||||
seat = input_manager_get_default_seat();
|
||||
}
|
||||
return seat;
|
||||
}
|
||||
|
||||
struct sway_seat *input_manager_get_seat(
|
||||
struct sway_input_manager *input, const char *seat_name) {
|
||||
struct sway_seat *input_manager_get_seat(const char *seat_name) {
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
if (strcmp(seat->wlr_seat->name, seat_name) == 0) {
|
||||
return seat;
|
||||
}
|
||||
}
|
||||
|
||||
return seat_create(input, seat_name);
|
||||
return seat_create(seat_name);
|
||||
}
|
||||
|
||||
char *input_device_get_identifier(struct wlr_input_device *device) {
|
||||
|
|
@ -72,9 +68,9 @@ char *input_device_get_identifier(struct wlr_input_device *device) {
|
|||
}
|
||||
|
||||
static struct sway_input_device *input_sway_device_from_wlr(
|
||||
struct sway_input_manager *input, struct wlr_input_device *device) {
|
||||
struct wlr_input_device *device) {
|
||||
struct sway_input_device *input_device = NULL;
|
||||
wl_list_for_each(input_device, &input->devices, link) {
|
||||
wl_list_for_each(input_device, &server.input->devices, link) {
|
||||
if (input_device->wlr_device == device) {
|
||||
return input_device;
|
||||
}
|
||||
|
|
@ -82,9 +78,9 @@ static struct sway_input_device *input_sway_device_from_wlr(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static bool input_has_seat_configuration(struct sway_input_manager *input) {
|
||||
static bool input_has_seat_configuration(void) {
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
struct seat_config *seat_config = seat_get_config(seat);
|
||||
if (seat_config) {
|
||||
return true;
|
||||
|
|
@ -244,8 +240,7 @@ static void input_manager_libinput_config_pointer(
|
|||
static void handle_device_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_input_device *device = data;
|
||||
|
||||
struct sway_input_device *input_device =
|
||||
input_sway_device_from_wlr(input_manager, device);
|
||||
struct sway_input_device *input_device = input_sway_device_from_wlr(device);
|
||||
|
||||
if (!sway_assert(input_device, "could not find sway device")) {
|
||||
return;
|
||||
|
|
@ -255,7 +250,7 @@ static void handle_device_destroy(struct wl_listener *listener, void *data) {
|
|||
input_device->identifier);
|
||||
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input_manager->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
seat_remove_device(seat, input_device);
|
||||
}
|
||||
|
||||
|
|
@ -297,9 +292,9 @@ static void handle_new_input(struct wl_listener *listener, void *data) {
|
|||
input_device->device_destroy.notify = handle_device_destroy;
|
||||
|
||||
struct sway_seat *seat = NULL;
|
||||
if (!input_has_seat_configuration(input)) {
|
||||
if (!input_has_seat_configuration()) {
|
||||
wlr_log(WLR_DEBUG, "no seat configuration, using default seat");
|
||||
seat = input_manager_get_seat(input, default_seat);
|
||||
seat = input_manager_get_seat(DEFAULT_SEAT);
|
||||
seat_add_device(seat, input_device);
|
||||
return;
|
||||
}
|
||||
|
|
@ -364,7 +359,7 @@ void handle_virtual_keyboard(struct wl_listener *listener, void *data) {
|
|||
struct wlr_virtual_keyboard_v1 *keyboard = data;
|
||||
struct wlr_input_device *device = &keyboard->input_device;
|
||||
|
||||
struct sway_seat *seat = input_manager_get_default_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_get_default_seat();
|
||||
|
||||
// TODO: The user might want this on a different seat
|
||||
struct sway_input_device *input_device =
|
||||
|
|
@ -387,21 +382,16 @@ void handle_virtual_keyboard(struct wl_listener *listener, void *data) {
|
|||
seat_add_device(seat, input_device);
|
||||
}
|
||||
|
||||
struct sway_input_manager *input_manager_create(
|
||||
struct sway_server *server) {
|
||||
struct sway_input_manager *input_manager_create(struct sway_server *server) {
|
||||
struct sway_input_manager *input =
|
||||
calloc(1, sizeof(struct sway_input_manager));
|
||||
if (!input) {
|
||||
return NULL;
|
||||
}
|
||||
input->server = server;
|
||||
|
||||
wl_list_init(&input->devices);
|
||||
wl_list_init(&input->seats);
|
||||
|
||||
// create the default seat
|
||||
input_manager_get_seat(input, default_seat);
|
||||
|
||||
input->new_input.notify = handle_new_input;
|
||||
wl_signal_add(&server->backend->events.new_input, &input->new_input);
|
||||
|
||||
|
|
@ -422,10 +412,9 @@ struct sway_input_manager *input_manager_create(
|
|||
return input;
|
||||
}
|
||||
|
||||
bool input_manager_has_focus(struct sway_input_manager *input,
|
||||
struct sway_node *node) {
|
||||
bool input_manager_has_focus(struct sway_node *node) {
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
if (seat_get_focus(seat) == node) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -434,19 +423,17 @@ bool input_manager_has_focus(struct sway_input_manager *input,
|
|||
return false;
|
||||
}
|
||||
|
||||
void input_manager_set_focus(struct sway_input_manager *input,
|
||||
struct sway_node *node) {
|
||||
void input_manager_set_focus(struct sway_node *node) {
|
||||
struct sway_seat *seat;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
seat_set_focus(seat, node);
|
||||
}
|
||||
}
|
||||
|
||||
void input_manager_apply_input_config(struct sway_input_manager *input,
|
||||
struct input_config *input_config) {
|
||||
void input_manager_apply_input_config(struct input_config *input_config) {
|
||||
struct sway_input_device *input_device = NULL;
|
||||
bool wildcard = strcmp(input_config->identifier, "*") == 0;
|
||||
wl_list_for_each(input_device, &input->devices, link) {
|
||||
wl_list_for_each(input_device, &server.input->devices, link) {
|
||||
if (strcmp(input_device->identifier, input_config->identifier) == 0
|
||||
|| wildcard) {
|
||||
if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER ||
|
||||
|
|
@ -459,18 +446,17 @@ void input_manager_apply_input_config(struct sway_input_manager *input,
|
|||
}
|
||||
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
seat_configure_device(seat, input_device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void input_manager_apply_seat_config(struct sway_input_manager *input,
|
||||
struct seat_config *seat_config) {
|
||||
void input_manager_apply_seat_config(struct seat_config *seat_config) {
|
||||
wlr_log(WLR_DEBUG, "applying new seat config for seat %s",
|
||||
seat_config->name);
|
||||
struct sway_seat *seat = input_manager_get_seat(input, seat_config->name);
|
||||
struct sway_seat *seat = input_manager_get_seat(seat_config->name);
|
||||
if (!seat) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -480,10 +466,10 @@ void input_manager_apply_seat_config(struct sway_input_manager *input,
|
|||
// for every device, try to add it to a seat and if no seat has it
|
||||
// attached, add it to the fallback seats.
|
||||
struct sway_input_device *input_device = NULL;
|
||||
wl_list_for_each(input_device, &input->devices, link) {
|
||||
wl_list_for_each(input_device, &server.input->devices, link) {
|
||||
list_t *seat_list = create_list();
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
struct seat_config *seat_config = seat_get_config(seat);
|
||||
if (!seat_config) {
|
||||
continue;
|
||||
|
|
@ -496,7 +482,7 @@ void input_manager_apply_seat_config(struct sway_input_manager *input,
|
|||
}
|
||||
|
||||
if (seat_list->length) {
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
bool attached = false;
|
||||
for (int i = 0; i < seat_list->length; ++i) {
|
||||
if (seat == seat_list->items[i]) {
|
||||
|
|
@ -511,7 +497,7 @@ void input_manager_apply_seat_config(struct sway_input_manager *input,
|
|||
}
|
||||
}
|
||||
} else {
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
struct seat_config *seat_config = seat_get_config(seat);
|
||||
if (seat_config && seat_config->fallback == 1) {
|
||||
seat_add_device(seat, input_device);
|
||||
|
|
@ -524,18 +510,17 @@ void input_manager_apply_seat_config(struct sway_input_manager *input,
|
|||
}
|
||||
}
|
||||
|
||||
void input_manager_configure_xcursor(struct sway_input_manager *input) {
|
||||
void input_manager_configure_xcursor(void) {
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
seat_configure_xcursor(seat);
|
||||
}
|
||||
}
|
||||
|
||||
struct sway_seat *input_manager_get_default_seat(
|
||||
struct sway_input_manager *input) {
|
||||
struct sway_seat *input_manager_get_default_seat(void) {
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input->seats, link) {
|
||||
if (strcmp(seat->wlr_seat->name, "seat0") == 0) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
if (strcmp(seat->wlr_seat->name, DEFAULT_SEAT) == 0) {
|
||||
return seat;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ static void handle_keyboard_key(struct wl_listener *listener, void *data) {
|
|||
struct wlr_input_device *wlr_device =
|
||||
keyboard->seat_device->input_device->wlr_device;
|
||||
char *device_identifier = input_device_get_identifier(wlr_device);
|
||||
wlr_idle_notify_activity(seat->input->server->idle, wlr_seat);
|
||||
wlr_idle_notify_activity(server.idle, wlr_seat);
|
||||
struct wlr_event_keyboard_key *event = data;
|
||||
bool input_inhibited = seat->exclusive_client != NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -95,8 +95,7 @@ static void seat_send_focus(struct sway_node *node, struct sway_seat *seat) {
|
|||
if (view && seat_is_input_allowed(seat, view->surface)) {
|
||||
#ifdef HAVE_XWAYLAND
|
||||
if (view->type == SWAY_VIEW_XWAYLAND) {
|
||||
struct wlr_xwayland *xwayland =
|
||||
seat->input->server->xwayland.wlr_xwayland;
|
||||
struct wlr_xwayland *xwayland = server.xwayland.wlr_xwayland;
|
||||
wlr_xwayland_set_seat(xwayland, seat->wlr_seat);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -328,14 +327,13 @@ static void collect_focus_container_iter(struct sway_container *container,
|
|||
collect_focus_iter(&container->node, data);
|
||||
}
|
||||
|
||||
struct sway_seat *seat_create(struct sway_input_manager *input,
|
||||
const char *seat_name) {
|
||||
struct sway_seat *seat_create(const char *seat_name) {
|
||||
struct sway_seat *seat = calloc(1, sizeof(struct sway_seat));
|
||||
if (!seat) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
seat->wlr_seat = wlr_seat_create(input->server->wl_display, seat_name);
|
||||
seat->wlr_seat = wlr_seat_create(server.wl_display, seat_name);
|
||||
if (!sway_assert(seat->wlr_seat, "could not allocate seat")) {
|
||||
free(seat);
|
||||
return NULL;
|
||||
|
|
@ -361,10 +359,9 @@ struct sway_seat *seat_create(struct sway_input_manager *input,
|
|||
wl_signal_add(&seat->wlr_seat->events.new_drag_icon, &seat->new_drag_icon);
|
||||
seat->new_drag_icon.notify = handle_new_drag_icon;
|
||||
|
||||
seat->input = input;
|
||||
wl_list_init(&seat->devices);
|
||||
|
||||
wl_list_insert(&input->seats, &seat->link);
|
||||
wl_list_insert(&server.input->seats, &seat->link);
|
||||
|
||||
return seat;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue