def test_center_window(manager):
    """Check that floating windows are centered correctly."""
    manager.test_window("one")

    manager.c.window.set_position_floating(50, 50)
    manager.c.window.set_size_floating(200, 100)
    info = manager.c.window.info()
    assert info["x"] == 50
    assert info["y"] == 50
    assert info["width"] == 200
    assert info["height"] == 100

    manager.c.window.center()
    info = manager.c.window.info()
    assert info["x"] == (800 - 200) / 2  # (screen width - window width) / 2
    assert info["y"] == (600 - 100) / 2  # (screen height - window height) / 2
    assert info["width"] == 200
    assert info["height"] == 100

    manager.c.window.togroup("b")  # Second screen
    manager.c.to_screen(1)  # Focus screen
    manager.c.group["b"].toscreen()  # Make sure group b is on that screen

    # Second screen is 640x480 at offset (800, 0)
    manager.c.window.center()
    info = manager.c.window.info()
    assert info["x"] == 800 + (640 - 200) / 2  # offset + (screen width - window width) / 2
    assert info["y"] == (480 - 100) / 2  # (screen height - window height) / 2
    assert info["width"] == 200
    assert info["height"] == 100
Check that floating windows are centered correctly.
test/test_window.py