mirror of
https://github.com/swaywm/sway.git
synced 2025-11-16 06:59:49 -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
|
|
@ -200,7 +200,7 @@ static struct sway_container *container_at_tabbed(struct sway_node *parent,
|
|||
if (ly < box.y || ly > box.y + box.height) {
|
||||
return NULL;
|
||||
}
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
list_t *children = node_get_children(parent);
|
||||
if (!children->length) {
|
||||
return NULL;
|
||||
|
|
@ -234,7 +234,7 @@ static struct sway_container *container_at_stacked(struct sway_node *parent,
|
|||
if (ly < box.y || ly > box.y + box.height) {
|
||||
return NULL;
|
||||
}
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
list_t *children = node_get_children(parent);
|
||||
|
||||
// Title bars
|
||||
|
|
@ -358,7 +358,7 @@ struct sway_container *container_at(struct sway_workspace *workspace,
|
|||
struct wlr_surface **surface, double *sx, double *sy) {
|
||||
struct sway_container *c;
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_container *focus = seat_get_focused_container(seat);
|
||||
bool is_floating = focus && container_is_floating_or_child(focus);
|
||||
// Focused view's popups
|
||||
|
|
@ -651,7 +651,7 @@ void container_set_floating(struct sway_container *container, bool enable) {
|
|||
return;
|
||||
}
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *workspace = container->workspace;
|
||||
|
||||
if (enable) {
|
||||
|
|
@ -843,7 +843,7 @@ bool container_has_urgent_child(struct sway_container *container) {
|
|||
|
||||
void container_end_mouse_operation(struct sway_container *container) {
|
||||
struct sway_seat *seat;
|
||||
wl_list_for_each(seat, &input_manager->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
if (seat->op_container == container) {
|
||||
seat->op_target_node = NULL; // ensure tiling move doesn't apply
|
||||
seat_end_mouse_operation(seat);
|
||||
|
|
@ -890,7 +890,7 @@ void container_set_fullscreen(struct sway_container *container, bool enable) {
|
|||
|
||||
struct sway_seat *seat;
|
||||
struct sway_workspace *focus_ws;
|
||||
wl_list_for_each(seat, &input_manager->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
focus_ws = seat_get_focused_workspace(seat);
|
||||
if (focus_ws) {
|
||||
if (focus_ws == workspace) {
|
||||
|
|
@ -1033,7 +1033,7 @@ void container_add_gaps(struct sway_container *c) {
|
|||
struct sway_view *view = c->view;
|
||||
if (!view) {
|
||||
struct sway_seat *seat =
|
||||
input_manager_get_default_seat(input_manager);
|
||||
input_manager_get_default_seat();
|
||||
struct sway_container *focus =
|
||||
seat_get_focus_inactive_view(seat, &c->node);
|
||||
view = focus ? focus->view : NULL;
|
||||
|
|
@ -1187,7 +1187,7 @@ void container_replace(struct sway_container *container,
|
|||
|
||||
struct sway_container *container_split(struct sway_container *child,
|
||||
enum sway_container_layout layout) {
|
||||
struct sway_seat *seat = input_manager_get_default_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_get_default_seat();
|
||||
bool set_focus = (seat_get_focus(seat) == &child->node);
|
||||
|
||||
struct sway_container *cont = container_create(NULL);
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ void output_enable(struct sway_output *output, struct output_config *oc) {
|
|||
struct sway_workspace *ws = workspace_create(output, ws_name);
|
||||
// Set each seat's focus if not already set
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &input_manager->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
if (!seat->has_focus) {
|
||||
seat_set_focus_workspace(seat, ws);
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ void output_enable(struct sway_output *output, struct output_config *oc) {
|
|||
}
|
||||
wl_signal_init(&output->events.destroy);
|
||||
|
||||
input_manager_configure_xcursor(input_manager);
|
||||
input_manager_configure_xcursor();
|
||||
|
||||
wl_signal_add(&wlr_output->events.mode, &output->mode);
|
||||
wl_signal_add(&wlr_output->events.transform, &output->transform);
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ void root_scratchpad_add_container(struct sway_container *con) {
|
|||
container_set_floating(con, true);
|
||||
container_detach(con);
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
if (parent) {
|
||||
arrange_container(parent);
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, &parent->node));
|
||||
|
|
@ -89,7 +89,7 @@ void root_scratchpad_remove_container(struct sway_container *con) {
|
|||
}
|
||||
|
||||
void root_scratchpad_show(struct sway_container *con) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *ws = seat_get_focused_workspace(seat);
|
||||
|
||||
// If the current con or any of its parents are in fullscreen mode, we
|
||||
|
|
@ -127,7 +127,7 @@ void root_scratchpad_show(struct sway_container *con) {
|
|||
}
|
||||
|
||||
void root_scratchpad_hide(struct sway_container *con) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_node *focus = seat_get_focus(seat);
|
||||
struct sway_workspace *ws = con->workspace;
|
||||
|
||||
|
|
@ -210,7 +210,7 @@ void root_record_workspace_pid(pid_t pid) {
|
|||
wl_list_init(&pid_workspaces);
|
||||
}
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *ws = seat_get_focused_workspace(seat);
|
||||
if (!ws) {
|
||||
wlr_log(WLR_DEBUG, "Bailing out, no workspace");
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ void view_request_activate(struct sway_view *view) {
|
|||
if (!ws) { // hidden scratchpad container
|
||||
return;
|
||||
}
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
|
||||
switch (config->focus_on_window_activation) {
|
||||
case FOWA_SMART:
|
||||
|
|
@ -443,7 +443,7 @@ void view_execute_criteria(struct sway_view *view) {
|
|||
}
|
||||
|
||||
static struct sway_workspace *select_workspace(struct sway_view *view) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
|
||||
// Check if there's any `assign` criteria for the view
|
||||
list_t *criterias = criteria_for_view(view,
|
||||
|
|
@ -517,7 +517,7 @@ static struct sway_workspace *select_workspace(struct sway_view *view) {
|
|||
}
|
||||
|
||||
static bool should_focus(struct sway_view *view) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_container *prev_con = seat_get_focused_container(seat);
|
||||
struct sway_workspace *prev_ws = seat_get_focused_workspace(seat);
|
||||
struct sway_workspace *map_ws = view->container->workspace;
|
||||
|
|
@ -551,7 +551,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
|
|||
}
|
||||
view->surface = wlr_surface;
|
||||
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *ws = select_workspace(view);
|
||||
struct sway_node *node = seat_get_focus_inactive(seat, &ws->node);
|
||||
struct sway_container *target_sibling = node->type == N_CONTAINER ?
|
||||
|
|
@ -616,7 +616,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface,
|
|||
}
|
||||
|
||||
if (should_focus(view)) {
|
||||
input_manager_set_focus(input_manager, &view->container->node);
|
||||
input_manager_set_focus(&view->container->node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -645,7 +645,7 @@ void view_unmap(struct sway_view *view) {
|
|||
}
|
||||
|
||||
struct sway_seat *seat;
|
||||
wl_list_for_each(seat, &input_manager->seats, link) {
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
if (config->mouse_warping == WARP_CONTAINER) {
|
||||
struct sway_node *node = seat_get_focus(seat);
|
||||
if (node && node->type == N_CONTAINER) {
|
||||
|
|
@ -1106,7 +1106,7 @@ bool view_is_visible(struct sway_view *view) {
|
|||
return false;
|
||||
}
|
||||
// Check view isn't in a tabbed or stacked container on an inactive tab
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_container *con = view->container;
|
||||
while (con) {
|
||||
enum sway_container_layout layout = container_parent_layout(con);
|
||||
|
|
@ -1138,7 +1138,7 @@ void view_set_urgent(struct sway_view *view, bool enable) {
|
|||
return;
|
||||
}
|
||||
if (enable) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
if (seat_get_focused_container(seat) == view->container) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ struct sway_output *workspace_get_initial_output(const char *name) {
|
|||
}
|
||||
}
|
||||
// Otherwise put it on the focused output
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *focus = seat_get_focused_workspace(seat);
|
||||
return focus->output;
|
||||
}
|
||||
|
|
@ -287,7 +287,7 @@ static bool _workspace_by_name(struct sway_workspace *ws, void *data) {
|
|||
}
|
||||
|
||||
struct sway_workspace *workspace_by_name(const char *name) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *current = seat_get_focused_workspace(seat);
|
||||
|
||||
if (strcmp(name, "prev") == 0) {
|
||||
|
|
@ -316,7 +316,7 @@ struct sway_workspace *workspace_by_name(const char *name) {
|
|||
*/
|
||||
static struct sway_workspace *workspace_output_prev_next_impl(
|
||||
struct sway_output *output, int dir) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *workspace = seat_get_focused_workspace(seat);
|
||||
|
||||
int index = list_find(output->workspaces, workspace);
|
||||
|
|
@ -368,7 +368,7 @@ struct sway_workspace *workspace_prev(struct sway_workspace *current) {
|
|||
|
||||
bool workspace_switch(struct sway_workspace *workspace,
|
||||
bool no_auto_back_and_forth) {
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_current_seat();
|
||||
struct sway_workspace *active_ws = seat_get_focused_workspace(seat);
|
||||
|
||||
if (!no_auto_back_and_forth && config->auto_back_and_forth
|
||||
|
|
@ -619,7 +619,7 @@ void workspace_add_gaps(struct sway_workspace *ws) {
|
|||
return;
|
||||
}
|
||||
if (config->smart_gaps) {
|
||||
struct sway_seat *seat = input_manager_get_default_seat(input_manager);
|
||||
struct sway_seat *seat = input_manager_get_default_seat();
|
||||
struct sway_container *focus =
|
||||
seat_get_focus_inactive_tiling(seat, ws);
|
||||
if (focus && !focus->view) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue