aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/seat.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-08-26 19:00:59 +0100
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-08-27 13:25:01 +0100
commit3bf849d993270c48cf144586912076ae6ae3bc0e (patch)
treeaf06a63f084fcbec7e0b973542c32c95ee8b08c8 /sway/input/seat.c
parentMerge pull request #2522 from ascent12/build_fix (diff)
downloadsway-3bf849d993270c48cf144586912076ae6ae3bc0e.tar.gz
sway-3bf849d993270c48cf144586912076ae6ae3bc0e.tar.zst
sway-3bf849d993270c48cf144586912076ae6ae3bc0e.zip
seat.c: clean-up seat_set_focus_warp function
Diffstat (limited to 'sway/input/seat.c')
-rw-r--r--sway/input/seat.c97
1 files changed, 46 insertions, 51 deletions
diff --git a/sway/input/seat.c b/sway/input/seat.c
index 269823ee..36e1d232 100644
--- a/sway/input/seat.c
+++ b/sway/input/seat.c
@@ -593,7 +593,7 @@ void seat_set_focus_warp(struct sway_seat *seat,
593 } 593 }
594 594
595 struct sway_container *last_focus = seat_get_focus(seat); 595 struct sway_container *last_focus = seat_get_focus(seat);
596 if (container && last_focus == container) { 596 if (last_focus == container) {
597 return; 597 return;
598 } 598 }
599 599
@@ -601,14 +601,26 @@ void seat_set_focus_warp(struct sway_seat *seat,
601 if (last_workspace && last_workspace->type != C_WORKSPACE) { 601 if (last_workspace && last_workspace->type != C_WORKSPACE) {
602 last_workspace = container_parent(last_workspace, C_WORKSPACE); 602 last_workspace = container_parent(last_workspace, C_WORKSPACE);
603 } 603 }
604
605 if (container == NULL) {
606 // Close any popups on the old focus
607 if (last_focus->type == C_VIEW) {
608 view_close_popups(last_focus->sway_view);
609 }
610 seat_send_unfocus(last_focus, seat);
611 seat->has_focus = false;
612 update_debug_tree();
613 return;
614 }
615
604 struct sway_container *new_workspace = container; 616 struct sway_container *new_workspace = container;
605 if (new_workspace && new_workspace->type != C_WORKSPACE) { 617 if (new_workspace->type != C_WORKSPACE) {
606 new_workspace = container_parent(new_workspace, C_WORKSPACE); 618 new_workspace = container_parent(new_workspace, C_WORKSPACE);
607 } 619 }
608 620
609 if (last_workspace && last_workspace == new_workspace 621 if (last_workspace == new_workspace
610 && last_workspace->sway_workspace->fullscreen 622 && last_workspace->sway_workspace->fullscreen
611 && container && !container_is_fullscreen_or_child(container)) { 623 && !container_is_fullscreen_or_child(container)) {
612 return; 624 return;
613 } 625 }
614 626
@@ -617,17 +629,17 @@ void seat_set_focus_warp(struct sway_seat *seat,
617 last_output = container_parent(last_output, C_OUTPUT); 629 last_output = container_parent(last_output, C_OUTPUT);
618 } 630 }
619 struct sway_container *new_output = container; 631 struct sway_container *new_output = container;
620 if (new_output && new_output->type != C_OUTPUT) { 632 if (new_output->type != C_OUTPUT) {
621 new_output = container_parent(new_output, C_OUTPUT); 633 new_output = container_parent(new_output, C_OUTPUT);
622 } 634 }
623 635
624 // find new output's old workspace, which might have to be removed if empty 636 // find new output's old workspace, which might have to be removed if empty
625 struct sway_container *new_output_last_ws = NULL; 637 struct sway_container *new_output_last_ws = NULL;
626 if (last_output && new_output && last_output != new_output) { 638 if (last_output != new_output) {
627 new_output_last_ws = seat_get_active_child(seat, new_output); 639 new_output_last_ws = seat_get_active_child(seat, new_output);
628 } 640 }
629 641
630 if (container && container->parent) { 642 if (container->parent) {
631 struct sway_seat_container *seat_con = 643 struct sway_seat_container *seat_con =
632 seat_container_from_container(seat, container); 644 seat_container_from_container(seat, container);
633 if (seat_con == NULL) { 645 if (seat_con == NULL) {
@@ -642,8 +654,7 @@ void seat_set_focus_warp(struct sway_seat *seat,
642 wl_list_insert(&seat->focus_stack, &parent->link); 654 wl_list_insert(&seat->focus_stack, &parent->link);
643 container_set_dirty(parent->container); 655 container_set_dirty(parent->container);
644 656
645 parent = 657 parent = seat_container_from_container(seat,
646 seat_container_from_container(seat,
647 parent->container->parent); 658 parent->container->parent);
648 } 659 }
649 660
@@ -652,19 +663,33 @@ void seat_set_focus_warp(struct sway_seat *seat,
652 663
653 if (last_focus) { 664 if (last_focus) {
654 seat_send_unfocus(last_focus, seat); 665 seat_send_unfocus(last_focus, seat);
666 container_set_dirty(last_focus);
655 } 667 }
656 seat_send_focus(container, seat); 668 seat_send_focus(container, seat);
657 669
658 container_set_dirty(container); 670 container_set_dirty(container);
659 container_set_dirty(container->parent); // for focused_inactive_child 671 container_set_dirty(container->parent); // for focused_inactive_child
660 if (last_focus) { 672 }
661 container_set_dirty(last_focus); 673
662 } 674 // emit ipc events
675 if (notify && new_workspace && last_workspace != new_workspace) {
676 ipc_event_workspace(last_workspace, new_workspace, "focus");
677 }
678 if (container->type == C_VIEW) {
679 ipc_event_window(container, "focus");
680 }
681
682 if (new_output_last_ws) {
683 workspace_consider_destroy(new_output_last_ws);
684 }
685
686 // Close any popups on the old focus
687 if (last_focus && last_focus->type == C_VIEW) {
688 view_close_popups(last_focus->sway_view);
663 } 689 }
664 690
665 // If urgent, either unset the urgency or start a timer to unset it 691 // If urgent, either unset the urgency or start a timer to unset it
666 if (container && container->type == C_VIEW && 692 if (container->type == C_VIEW && view_is_urgent(container->sway_view) &&
667 view_is_urgent(container->sway_view) &&
668 !container->sway_view->urgent_timer) { 693 !container->sway_view->urgent_timer) {
669 struct sway_view *view = container->sway_view; 694 struct sway_view *view = container->sway_view;
670 if (last_workspace && last_workspace != new_workspace && 695 if (last_workspace && last_workspace != new_workspace &&
@@ -686,41 +711,20 @@ void seat_set_focus_warp(struct sway_seat *seat,
686 711
687 // If we've focused a floating container, bring it to the front. 712 // If we've focused a floating container, bring it to the front.
688 // We do this by putting it at the end of the floating list. 713 // We do this by putting it at the end of the floating list.
689 if (container && container_is_floating(container)) { 714 struct sway_container *floater = container;
690 list_move_to_end( 715 while (floater->parent && floater->parent->type != C_WORKSPACE) {
691 container->parent->sway_workspace->floating, container); 716 floater = floater->parent;
692 } 717 }
693 718 if (container_is_floating(floater)) {
694 // clean up unfocused empty workspace on new output 719 list_move_to_end(floater->parent->sway_workspace->floating, floater);
695 if (new_output_last_ws) {
696 workspace_consider_destroy(new_output_last_ws);
697 if (new_output_last_ws->destroying &&
698 last_workspace == new_output_last_ws) {
699 last_focus = NULL;
700 last_workspace = NULL;
701 }
702 }
703
704 // Close any popups on the old focus
705 if (last_focus && last_focus != container) {
706 if (last_focus->type == C_VIEW) {
707 view_close_popups(last_focus->sway_view);
708 }
709 } 720 }
710 721
711 if (last_focus) { 722 if (last_focus) {
712 if (last_workspace) { 723 if (last_workspace) {
713 if (notify && last_workspace != new_workspace) {
714 ipc_event_workspace(last_workspace, new_workspace, "focus");
715 }
716 workspace_consider_destroy(last_workspace); 724 workspace_consider_destroy(last_workspace);
717 if (last_workspace->destroying && last_workspace == last_focus) {
718 last_focus = NULL;
719 }
720 } 725 }
721 726
722 if (config->mouse_warping && warp) { 727 if (config->mouse_warping && warp && new_output != last_output) {
723 if (new_output && last_output && new_output != last_output) {
724 double x = container->x + container->width / 2.0; 728 double x = container->x + container->width / 2.0;
725 double y = container->y + container->height / 2.0; 729 double y = container->y + container->height / 2.0;
726 struct wlr_output *wlr_output = 730 struct wlr_output *wlr_output =
@@ -731,20 +735,11 @@ void seat_set_focus_warp(struct sway_seat *seat,
731 seat->cursor->cursor->y)) { 735 seat->cursor->cursor->y)) {
732 wlr_cursor_warp(seat->cursor->cursor, NULL, x, y); 736 wlr_cursor_warp(seat->cursor->cursor, NULL, x, y);
733 cursor_send_pointer_motion(seat->cursor, 0, true); 737 cursor_send_pointer_motion(seat->cursor, 0, true);
734 }
735 } 738 }
736 } 739 }
737 } 740 }
738 741
739 if (container) { 742 seat->has_focus = true;
740 if (container->type == C_VIEW) {
741 ipc_event_window(container, "focus");
742 } else if (container->type == C_WORKSPACE) {
743 ipc_event_workspace(NULL, container, "focus");
744 }
745 }
746
747 seat->has_focus = (container != NULL);
748 743
749 update_debug_tree(); 744 update_debug_tree();
750} 745}