assert_pointer_focus none
assert_keyboard_focus none

new_client w wayland
create w/1 csd
resize w/1 100 100
show w/1
wait

move w/1 100 100
move_cursor_to 150 150
assert_pointer_focus w/1
assert_keyboard_focus w/1

# Check implicit pointer grabs on main window
click_and_hold
move_cursor_to 250 150
assert_pointer_focus w/1
release_click
assert_pointer_focus none

popup_at w/p1 1 right 100 100 grab
assert_position w/p1 200 100
assert_size w/p1 100 100
assert_keyboard_focus w/p1
assert_pointer_focus w/p1

click_and_hold
move_cursor_to 250 250
# This currently fails
assert_pointer_focus w/p1
release_click
assert_pointer_focus none

dismiss w/p1

# Check that focus can move to a popup despite a implicit pointer grab
move_cursor_to 150 150
assert_pointer_focus w/1

click_and_hold
popup_at w/p2 1 right 100 100 grab
assert_position w/p2 200 100
assert_size w/p2 100 100
assert_keyboard_focus w/p2
assert_pointer_focus w/1

# Move inside the popup, focus should move there
move_cursor_to 220 120
assert_pointer_focus w/p2
# Move outside the client, focus should move to the implicit grab surface
move_cursor_to 420 420
assert_pointer_focus w/1
# Move focus back to popup
move_cursor_to 220 120
assert_pointer_focus w/p2
release_click

dismiss w/p2

# Check non-grabbing popup
move_cursor_to 150 150
assert_pointer_focus w/1

click_and_hold
popup_at w/p3 1 right 100 100
assert_position w/p3 200 100
assert_size w/p3 100 100
assert_keyboard_focus w/1
assert_pointer_focus w/1

move_cursor_to 250 150
assert_keyboard_focus w/1
assert_pointer_focus w/p3

release_click
dismiss w/p3

# Check non-grabbing popup after implicit grab ends
move_cursor_to 150 150
assert_pointer_focus w/1

click_and_hold
release_click
popup_at w/p4 1 right 100 100
assert_position w/p4 200 100
assert_size w/p4 100 100
assert_keyboard_focus w/1
assert_pointer_focus w/1

move_cursor_to 250 150
assert_keyboard_focus w/1
assert_pointer_focus w/p4

dismiss w/p4
