示例#1
0
def borders(data: Iterable[Tuple[WindowGroup, LayoutData, LayoutData]],
            is_horizontal: bool,
            all_windows: WindowList,
            start_offset: int = 1,
            end_offset: int = 1) -> Generator[BorderLine, None, None]:
    borders: List[BorderLine] = []
    active_group = all_windows.active_group
    needs_borders_map = all_windows.compute_needs_borders_map(
        lgd.draw_active_borders)
    try:
        bw = next(all_windows.iter_all_layoutable_groups()).effective_border()
    except StopIteration:
        bw = 0
    if not bw:
        return

    for wg, xl, yl in data:
        if is_horizontal:
            e1 = Edges(xl.content_pos - xl.space_before,
                       yl.content_pos - yl.space_before,
                       xl.content_pos - xl.space_before + bw,
                       yl.content_pos + yl.content_size + yl.space_after)
            e2 = Edges(xl.content_pos + xl.content_size + xl.space_after - bw,
                       yl.content_pos - yl.space_before,
                       xl.content_pos + xl.content_size + xl.space_after,
                       yl.content_pos + yl.content_size + yl.space_after)
        else:
            e1 = Edges(xl.content_pos - xl.space_before,
                       yl.content_pos - yl.space_before,
                       xl.content_pos + xl.content_size + xl.space_after,
                       yl.content_pos - yl.space_before + bw)
            e2 = Edges(xl.content_pos - xl.space_before,
                       yl.content_pos + yl.content_size + yl.space_after - bw,
                       xl.content_pos + xl.content_size + xl.space_after,
                       yl.content_pos + yl.content_size + yl.space_after)
        color = BorderColor.inactive
        if needs_borders_map.get(wg.id):
            color = BorderColor.active if wg is active_group else BorderColor.bell
        borders.append(BorderLine(e1, color))
        borders.append(BorderLine(e2, color))

    last_idx = len(borders) - 1 - end_offset
    for i, x in enumerate(borders):
        if start_offset <= i <= last_idx:
            yield x
示例#2
0
 def minimal_borders(self, all_windows: WindowList) -> Generator[BorderLine, None, None]:
     groups = tuple(all_windows.iter_all_layoutable_groups())
     window_count = len(groups)
     if not lgd.draw_minimal_borders or window_count < 2:
         return
     for pair in self.pairs_root.self_and_descendants():
         for edges in pair.between_borders:
             yield BorderLine(edges)
     needs_borders_map = all_windows.compute_needs_borders_map(lgd.draw_active_borders)
     ag = all_windows.active_group
     active_group_id = -1 if ag is None else ag.id
     for grp_id, needs_borders in needs_borders_map.items():
         if needs_borders:
             qpair = self.pairs_root.pair_for_window(grp_id)
             if qpair is not None:
                 color = BorderColor.active if grp_id is active_group_id else BorderColor.bell
                 for edges in qpair.borders_for_window(self, grp_id):
                     yield BorderLine(edges, color)
示例#3
0
    def minimal_borders(
            self,
            all_windows: WindowList) -> Generator[BorderLine, None, None]:
        num = all_windows.num_groups
        if num < 2 or not lgd.draw_minimal_borders:
            return
        try:
            bw = next(
                all_windows.iter_all_layoutable_groups()).effective_border()
        except StopIteration:
            bw = 0
        if not bw:
            return
        if num <= self.num_full_size_windows + 1:
            layout = (x[:3] for x in self.simple_layout(all_windows))
            yield from borders(layout, self.main_is_horizontal, all_windows)
            return
        main_layouts: List[Tuple[WindowGroup, LayoutData, LayoutData]] = []
        perp_borders: List[BorderLine] = []
        layouts = (self.simple_layout if num <= self.num_full_size_windows else
                   self.full_layout)(all_windows)
        needs_borders_map = all_windows.compute_needs_borders_map(
            lgd.draw_active_borders)
        active_group = all_windows.active_group
        mirrored = self.layout_opts.mirrored
        for wg, xl, yl, is_full_size in layouts:
            if is_full_size:
                main_layouts.append((wg, xl, yl))
            else:
                color = BorderColor.inactive
                if needs_borders_map.get(wg.id):
                    color = BorderColor.active if wg is active_group else BorderColor.bell
                if self.main_is_horizontal:
                    e1 = Edges(
                        xl.content_pos - xl.space_before,
                        yl.content_pos - yl.space_before,
                        xl.content_pos + xl.content_size + xl.space_after,
                        yl.content_pos - yl.space_before + bw)
                    e3 = Edges(
                        xl.content_pos - xl.space_before,
                        yl.content_pos + yl.content_size + yl.space_after - bw,
                        xl.content_pos + xl.content_size + xl.space_after,
                        yl.content_pos + yl.content_size + yl.space_after,
                    )
                    e2 = Edges(
                        xl.content_pos +
                        ((xl.content_size + xl.space_after -
                          bw) if mirrored else -xl.space_before),
                        yl.content_pos - yl.space_before,
                        xl.content_pos +
                        ((xl.content_size + xl.space_after) if mirrored else
                         (bw - xl.space_before)),
                        yl.content_pos + yl.content_size + yl.space_after,
                    )
                else:
                    e1 = Edges(
                        xl.content_pos - xl.space_before,
                        yl.content_pos - yl.space_before,
                        xl.content_pos - xl.space_before + bw,
                        yl.content_pos + yl.content_size + yl.space_after,
                    )
                    e3 = Edges(
                        xl.content_pos + xl.content_size + xl.space_after - bw,
                        yl.content_pos - yl.space_before,
                        xl.content_pos + xl.content_size + xl.space_after,
                        yl.content_pos + yl.content_size + yl.space_after,
                    )
                    e2 = Edges(
                        xl.content_pos - xl.space_before,
                        yl.content_pos +
                        ((yl.content_size + yl.space_after -
                          bw) if mirrored else -yl.space_before),
                        xl.content_pos + xl.content_size + xl.space_after,
                        yl.content_pos +
                        ((yl.content_size + yl.space_after) if mirrored else
                         (bw - yl.space_before)),
                    )
                perp_borders.append(BorderLine(e1, color))
                perp_borders.append(BorderLine(e2, color))
                perp_borders.append(BorderLine(e3, color))

        mirrored = self.layout_opts.mirrored
        yield from borders(main_layouts,
                           self.main_is_horizontal,
                           all_windows,
                           start_offset=int(not mirrored),
                           end_offset=int(mirrored))
        yield from perp_borders[1:-1]
示例#4
0
    def minimal_borders(self, all_windows: WindowList) -> Generator[BorderLine, None, None]:
        n = all_windows.num_groups
        if not lgd.draw_minimal_borders or n < 2:
            return
        needs_borders_map = all_windows.compute_needs_borders_map(lgd.draw_active_borders)
        ncols, nrows, special_rows, special_col = calc_grid_size(n)
        is_first_row: Set[int] = set()
        is_last_row: Set[int] = set()
        is_first_column: Set[int] = set()
        is_last_column: Set[int] = set()
        groups = tuple(all_windows.iter_all_layoutable_groups())
        bw = groups[0].effective_border()
        if not bw:
            return
        xl: LayoutData = LayoutData()
        yl: LayoutData = LayoutData()
        prev_col_windows: List[int] = []
        layout_data_map: Dict[int, Tuple[LayoutData, LayoutData]] = {}

        def on_col_done(col_windows: List[int]) -> None:
            nonlocal prev_col_windows, is_first_column
            if col_windows:
                is_first_row.add(groups[col_windows[0]].id)
                is_last_row.add(groups[col_windows[-1]].id)
            if not prev_col_windows:
                is_first_column = {groups[x].id for x in col_windows}
            prev_col_windows = col_windows

        all_groups_in_order: List[WindowGroup] = []
        for window_idx, xl, yl in self.layout_windows(n, nrows, ncols, special_rows, special_col, on_col_done):
            wg = groups[window_idx]
            all_groups_in_order.append(wg)
            layout_data_map[wg.id] = xl, yl
        is_last_column = {groups[x].id for x in prev_col_windows}
        active_group = all_windows.active_group

        def ends(yl: LayoutData) -> Tuple[int, int]:
            return yl.content_pos - yl.space_before, yl.content_pos + yl.content_size + yl.space_after

        def borders_for_window(gid: int) -> Generator[Edges, None, None]:
            xl, yl = layout_data_map[gid]
            left, right = ends(xl)
            top, bottom = ends(yl)
            first_row, last_row = gid in is_first_row, gid in is_last_row
            first_column, last_column = gid in is_first_column, gid in is_last_column

            # Horizontal
            if not first_row:
                yield Edges(left, top, right, top + bw)
            if not last_row:
                yield Edges(left, bottom - bw, right, bottom)

            # Vertical
            if not first_column:
                yield Edges(left, top, left + bw, bottom)
            if not last_column:
                yield Edges(right - bw, top, right, bottom)

        for wg in all_groups_in_order:
            for edges in borders_for_window(wg.id):
                yield BorderLine(edges)
        for wg in all_groups_in_order:
            if needs_borders_map.get(wg.id):
                color = BorderColor.active if wg is active_group else BorderColor.bell
                for edges in borders_for_window(wg.id):
                    yield BorderLine(edges, color)
示例#5
0
 def compute_needs_borders_map(self,
                               all_windows: WindowList) -> Dict[int, bool]:
     return all_windows.compute_needs_borders_map(lgd.draw_active_borders)