def _fix_double_margins(
        self, win_x: int, win_y: int, win_w: int, win_h: int
    ) -> tuple[Rect, list[int]]:
        """Prevent doubling up of margins by halving margins for internal margins."""
        if isinstance(self.margin, int):
            margins = [self.margin] * 4
        else:
            margins = self.margin

        # Top
        if win_y - margins[0] > self.last_screen.y:
            win_y -= margins[0] // 2
            win_h += margins[0] // 2

        # Right
        if win_x + win_w + margins[1] < (self.last_screen.x + self.last_screen.width):
            win_w += margins[1] // 2

        # Bottom
        if win_y + win_h + margins[2] < (self.last_screen.y + self.last_screen.height):
            win_h += margins[2] // 2

        # Left
        if win_x - margins[3] > self.last_screen.x:
            win_x -= margins[3] // 2
            win_w += margins[3] // 2

        return (win_x, win_y, win_w, win_h), margins
Prevent doubling up of margins by halving margins for internal margins.
libqtile/layout/spiral.py