|
| @@ -774,3 +771,115 @@ func TestFlashFollowsInnerBorderAndRadius(t *testing.T) { |
| 774 | 771 | | }) |
| 775 | 772 | | } |
| 776 | 773 | | } |
| 774 | + | |
| 775 | + | func TestFlashClickFocus(t *testing.T) { |
| 776 | + | for _, test := range []struct { |
| 777 | + | name string |
| 778 | + | target WindowID |
| 779 | + | enabled bool |
| 780 | + | want bool |
| 781 | + | }{ |
| 782 | + | {"different window", 1, true, true}, |
| 783 | + | {"already focused", 3, true, false}, |
| 784 | + | {"disabled", 1, false, false}, |
| 785 | + | } { |
| 786 | + | t.Run(test.name, func(t *testing.T) { |
| 787 | + | c, clock := flashCore(t) |
| 788 | + | c.cfg.Focus.Flash = test.enabled |
| 789 | + | indicatorScene(t, c) |
| 790 | + | if c.keyboardFocus() != 3 { |
| 791 | + | t.Fatal("setup: expected window 3 focused") |
| 792 | + | } |
| 793 | + | c.pointer = test.target |
| 794 | + | if err := c.pointerButton(context.Background(), ports.PointerButton{Button: btnLeft, Pressed: true}); err != nil { |
| 795 | + | t.Fatal(err) |
| 796 | + | } |
| 797 | + | if c.keyboardFocus() != test.target { |
| 798 | + | t.Fatalf("focus = %d, want %d", c.keyboardFocus(), test.target) |
| 799 | + | } |
| 800 | + | if (c.flash.pending != nil) != test.want { |
| 801 | + | t.Fatalf("flash request = %+v, want flash %v", c.flash.pending, test.want) |
| 802 | + | } |
| 803 | + | // Let the click's viewport transition settle before the flash. |
| 804 | + | clock.now = clock.now.Add(time.Second) |
| 805 | + | stepScenes(t, c, c.cur()) |
| 806 | + | if c.flashTick() != test.want { |
| 807 | + | t.Fatalf("flash start: want %v", test.want) |
| 808 | + | } |
| 809 | + | if test.want && (c.flash.running.window != test.target || c.flash.running.level != flashWindow || c.flashFor(c.cur()) == nil) { |
| 810 | + | t.Fatalf("wrong running flash: %+v", c.flash.running) |
| 811 | + | } |
| 812 | + | }) |
| 813 | + | } |
| 814 | + | } |
| 815 | + | |
| 816 | + | func TestFlashClickModalFocus(t *testing.T) { |
| 817 | + | for _, unchanged := range []bool{false, true} { |
| 818 | + | t.Run(map[bool]string{false: "changed", true: "unchanged"}[unchanged], func(t *testing.T) { |
| 819 | + | c, _ := flashCore(t) |
| 820 | + | w := c.cur().mon.Current() |
| 821 | + | c.windows.mapped(ports.WindowMapped{ID: 4}, c.now()) |
| 822 | + | w.AddDialog(4, 1, 100, 80) |
| 823 | + | w.SetModal(4, true) |
| 824 | + | if !unchanged { |
| 825 | + | w.Click(2) |
| 826 | + | } |
| 827 | + | indicatorScene(t, c) |
| 828 | + | c.pointer = 1 |
| 829 | + | if err := c.pointerButton(context.Background(), ports.PointerButton{Button: btnLeft, Pressed: true}); err != nil { |
| 830 | + | t.Fatal(err) |
| 831 | + | } |
| 832 | + | if c.keyboardFocus() != 4 { |
| 833 | + | t.Fatalf("focus = %d, want modal 4", c.keyboardFocus()) |
| 834 | + | } |
| 835 | + | if unchanged { |
| 836 | + | if c.flash.pending != nil { |
| 837 | + | t.Fatalf("unchanged modal flashed: %+v", c.flash.pending) |
| 838 | + | } |
| 839 | + | } else if c.flash.pending == nil || c.flash.pending.window != 4 { |
| 840 | + | t.Fatalf("want modal flash, got %+v", c.flash.pending) |
| 841 | + | } |
| 842 | + | }) |
| 843 | + | } |
| 844 | + | } |
| 845 | + | |
| 846 | + | func TestFlashModifierClickDrag(t *testing.T) { |
| 847 | + | for _, resize := range []bool{false, true} { |
| 848 | + | for _, mode := range []string{"changed", "unchanged", "disabled"} { |
| 849 | + | t.Run(map[bool]string{false: "move", true: "resize"}[resize]+"/"+mode, func(t *testing.T) { |
| 850 | + | c, clock := flashCore(t) |
| 851 | + | w := c.cur().mon.Current() |
| 852 | + | w.Click(1) |
| 853 | + | if resize { |
| 854 | + | w.Apply(ActionToggleFloating) |
| 855 | + | } |
| 856 | + | if mode != "unchanged" { |
| 857 | + | w.Click(3) |
| 858 | + | } |
| 859 | + | c.cfg.Focus.Flash = mode != "disabled" |
| 860 | + | indicatorScene(t, c) |
| 861 | + | c.pointer = 1 |
| 862 | + | c.mods = c.cmdMod |
| 863 | + | button := uint32(btnLeft) |
| 864 | + | if resize { |
| 865 | + | button = btnRight |
| 866 | + | } |
| 867 | + | if err := c.pointerButton(context.Background(), ports.PointerButton{Button: button, Pressed: true}); err != nil { |
| 868 | + | t.Fatal(err) |
| 869 | + | } |
| 870 | + | if c.drag == nil || c.drag.id != 1 || c.drag.resize != resize { |
| 871 | + | t.Fatalf("drag not started: %+v", c.drag) |
| 872 | + | } |
| 873 | + | want := mode == "changed" |
| 874 | + | if (c.flash.pending != nil) != want { |
| 875 | + | t.Fatalf("flash = %+v, want %v", c.flash.pending, want) |
| 876 | + | } |
| 877 | + | clock.now = clock.now.Add(time.Second) |
| 878 | + | stepScenes(t, c, c.cur()) |
| 879 | + | if c.flashTick() != want { |
| 880 | + | t.Fatalf("flash start: want %v", want) |
| 881 | + | } |
| 882 | + | }) |
| 883 | + | } |
| 884 | + | } |
| 885 | + | } |