mirror of
https://github.com/swaywm/sway.git
synced 2024-11-14 14:34:07 +01:00
seat.c: clean-up seat_set_focus_warp function
This commit is contained in:
parent
fed6976840
commit
3bf849d993
@ -593,7 +593,7 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct sway_container *last_focus = seat_get_focus(seat);
|
struct sway_container *last_focus = seat_get_focus(seat);
|
||||||
if (container && last_focus == container) {
|
if (last_focus == container) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,14 +601,26 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
|||||||
if (last_workspace && last_workspace->type != C_WORKSPACE) {
|
if (last_workspace && last_workspace->type != C_WORKSPACE) {
|
||||||
last_workspace = container_parent(last_workspace, C_WORKSPACE);
|
last_workspace = container_parent(last_workspace, C_WORKSPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (container == NULL) {
|
||||||
|
// Close any popups on the old focus
|
||||||
|
if (last_focus->type == C_VIEW) {
|
||||||
|
view_close_popups(last_focus->sway_view);
|
||||||
|
}
|
||||||
|
seat_send_unfocus(last_focus, seat);
|
||||||
|
seat->has_focus = false;
|
||||||
|
update_debug_tree();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
struct sway_container *new_workspace = container;
|
struct sway_container *new_workspace = container;
|
||||||
if (new_workspace && new_workspace->type != C_WORKSPACE) {
|
if (new_workspace->type != C_WORKSPACE) {
|
||||||
new_workspace = container_parent(new_workspace, C_WORKSPACE);
|
new_workspace = container_parent(new_workspace, C_WORKSPACE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last_workspace && last_workspace == new_workspace
|
if (last_workspace == new_workspace
|
||||||
&& last_workspace->sway_workspace->fullscreen
|
&& last_workspace->sway_workspace->fullscreen
|
||||||
&& container && !container_is_fullscreen_or_child(container)) {
|
&& !container_is_fullscreen_or_child(container)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,17 +629,17 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
|||||||
last_output = container_parent(last_output, C_OUTPUT);
|
last_output = container_parent(last_output, C_OUTPUT);
|
||||||
}
|
}
|
||||||
struct sway_container *new_output = container;
|
struct sway_container *new_output = container;
|
||||||
if (new_output && new_output->type != C_OUTPUT) {
|
if (new_output->type != C_OUTPUT) {
|
||||||
new_output = container_parent(new_output, C_OUTPUT);
|
new_output = container_parent(new_output, C_OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// find new output's old workspace, which might have to be removed if empty
|
// find new output's old workspace, which might have to be removed if empty
|
||||||
struct sway_container *new_output_last_ws = NULL;
|
struct sway_container *new_output_last_ws = NULL;
|
||||||
if (last_output && new_output && last_output != new_output) {
|
if (last_output != new_output) {
|
||||||
new_output_last_ws = seat_get_active_child(seat, new_output);
|
new_output_last_ws = seat_get_active_child(seat, new_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (container && container->parent) {
|
if (container->parent) {
|
||||||
struct sway_seat_container *seat_con =
|
struct sway_seat_container *seat_con =
|
||||||
seat_container_from_container(seat, container);
|
seat_container_from_container(seat, container);
|
||||||
if (seat_con == NULL) {
|
if (seat_con == NULL) {
|
||||||
@ -642,8 +654,7 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
|||||||
wl_list_insert(&seat->focus_stack, &parent->link);
|
wl_list_insert(&seat->focus_stack, &parent->link);
|
||||||
container_set_dirty(parent->container);
|
container_set_dirty(parent->container);
|
||||||
|
|
||||||
parent =
|
parent = seat_container_from_container(seat,
|
||||||
seat_container_from_container(seat,
|
|
||||||
parent->container->parent);
|
parent->container->parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -652,19 +663,33 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
|||||||
|
|
||||||
if (last_focus) {
|
if (last_focus) {
|
||||||
seat_send_unfocus(last_focus, seat);
|
seat_send_unfocus(last_focus, seat);
|
||||||
|
container_set_dirty(last_focus);
|
||||||
}
|
}
|
||||||
seat_send_focus(container, seat);
|
seat_send_focus(container, seat);
|
||||||
|
|
||||||
container_set_dirty(container);
|
container_set_dirty(container);
|
||||||
container_set_dirty(container->parent); // for focused_inactive_child
|
container_set_dirty(container->parent); // for focused_inactive_child
|
||||||
if (last_focus) {
|
}
|
||||||
container_set_dirty(last_focus);
|
|
||||||
}
|
// emit ipc events
|
||||||
|
if (notify && new_workspace && last_workspace != new_workspace) {
|
||||||
|
ipc_event_workspace(last_workspace, new_workspace, "focus");
|
||||||
|
}
|
||||||
|
if (container->type == C_VIEW) {
|
||||||
|
ipc_event_window(container, "focus");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (new_output_last_ws) {
|
||||||
|
workspace_consider_destroy(new_output_last_ws);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close any popups on the old focus
|
||||||
|
if (last_focus && last_focus->type == C_VIEW) {
|
||||||
|
view_close_popups(last_focus->sway_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If urgent, either unset the urgency or start a timer to unset it
|
// If urgent, either unset the urgency or start a timer to unset it
|
||||||
if (container && container->type == C_VIEW &&
|
if (container->type == C_VIEW && view_is_urgent(container->sway_view) &&
|
||||||
view_is_urgent(container->sway_view) &&
|
|
||||||
!container->sway_view->urgent_timer) {
|
!container->sway_view->urgent_timer) {
|
||||||
struct sway_view *view = container->sway_view;
|
struct sway_view *view = container->sway_view;
|
||||||
if (last_workspace && last_workspace != new_workspace &&
|
if (last_workspace && last_workspace != new_workspace &&
|
||||||
@ -686,41 +711,20 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
|||||||
|
|
||||||
// If we've focused a floating container, bring it to the front.
|
// If we've focused a floating container, bring it to the front.
|
||||||
// We do this by putting it at the end of the floating list.
|
// We do this by putting it at the end of the floating list.
|
||||||
if (container && container_is_floating(container)) {
|
struct sway_container *floater = container;
|
||||||
list_move_to_end(
|
while (floater->parent && floater->parent->type != C_WORKSPACE) {
|
||||||
container->parent->sway_workspace->floating, container);
|
floater = floater->parent;
|
||||||
}
|
}
|
||||||
|
if (container_is_floating(floater)) {
|
||||||
// clean up unfocused empty workspace on new output
|
list_move_to_end(floater->parent->sway_workspace->floating, floater);
|
||||||
if (new_output_last_ws) {
|
|
||||||
workspace_consider_destroy(new_output_last_ws);
|
|
||||||
if (new_output_last_ws->destroying &&
|
|
||||||
last_workspace == new_output_last_ws) {
|
|
||||||
last_focus = NULL;
|
|
||||||
last_workspace = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close any popups on the old focus
|
|
||||||
if (last_focus && last_focus != container) {
|
|
||||||
if (last_focus->type == C_VIEW) {
|
|
||||||
view_close_popups(last_focus->sway_view);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (last_focus) {
|
if (last_focus) {
|
||||||
if (last_workspace) {
|
if (last_workspace) {
|
||||||
if (notify && last_workspace != new_workspace) {
|
|
||||||
ipc_event_workspace(last_workspace, new_workspace, "focus");
|
|
||||||
}
|
|
||||||
workspace_consider_destroy(last_workspace);
|
workspace_consider_destroy(last_workspace);
|
||||||
if (last_workspace->destroying && last_workspace == last_focus) {
|
|
||||||
last_focus = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config->mouse_warping && warp) {
|
if (config->mouse_warping && warp && new_output != last_output) {
|
||||||
if (new_output && last_output && new_output != last_output) {
|
|
||||||
double x = container->x + container->width / 2.0;
|
double x = container->x + container->width / 2.0;
|
||||||
double y = container->y + container->height / 2.0;
|
double y = container->y + container->height / 2.0;
|
||||||
struct wlr_output *wlr_output =
|
struct wlr_output *wlr_output =
|
||||||
@ -731,20 +735,11 @@ void seat_set_focus_warp(struct sway_seat *seat,
|
|||||||
seat->cursor->cursor->y)) {
|
seat->cursor->cursor->y)) {
|
||||||
wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
|
wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
|
||||||
cursor_send_pointer_motion(seat->cursor, 0, true);
|
cursor_send_pointer_motion(seat->cursor, 0, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (container) {
|
seat->has_focus = true;
|
||||||
if (container->type == C_VIEW) {
|
|
||||||
ipc_event_window(container, "focus");
|
|
||||||
} else if (container->type == C_WORKSPACE) {
|
|
||||||
ipc_event_workspace(NULL, container, "focus");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
seat->has_focus = (container != NULL);
|
|
||||||
|
|
||||||
update_debug_tree();
|
update_debug_tree();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user