def _set_marks(container: i3ipc.Con, marks: List[str]): container.marks = marks if not marks: return container.command('mark "{}"'.format(marks[0])) for mark in marks[1:]: _add_mark(container, mark)
def get_workspace(self, tree: i3ipc.Con, group_to_workspaces: GroupToWorkspaces) -> i3ipc.Con: active_group_name = self.get_group_name(tree, group_to_workspaces) focused_workspace = tree.find_focused().workspace() if get_workspace_group(focused_workspace) == active_group_name: return focused_workspace group_to_workspaces = get_group_to_workspaces(tree.workspaces()) active_group_workspaces = next(iter(group_to_workspaces.items()))[1] # Return the first group which is defined as the active one. return active_group_workspaces[0]
def print_scratchpad_containers(tree: i3ipc.Con) -> None: scratchpad_workspace_id = tree.scratchpad().id table = [_LIST_CONTAINERS_HEADER] for con in get_scratchpad_containers(tree): in_scratchpad = (con.workspace().id == scratchpad_workspace_id) table.append( [con.id, in_scratchpad, con.window_class, con.window_instance]) print('\n'.join('\t'.join(str(e) for e in row) for row in table))
def get_workspace_icons_representation(workspace: i3ipc.Con) -> str: icon_to_count = collections.OrderedDict() for window in workspace.leaves(): icon = get_window_icon(window) if icon not in icon_to_count: icon_to_count[icon] = 0 icon_to_count[icon] += 1 icons_texts = [] for icon, count in icon_to_count.items(): if count < 3: icon_text = ' '.join(icon for i in range(count)) else: icon_text = '{}x{}'.format(count, icon) icons_texts.append(icon_text) return ' '.join(icons_texts)
def get_workspace_icons(self, workspace: i3ipc.Con) -> str: icon_to_count = collections.OrderedDict() for window in workspace.leaves(): icon = self.get_window_icon(window) if icon not in icon_to_count: icon_to_count[icon] = 0 icon_to_count[icon] += 1 icons_texts = [] delim = self.config['delimiter'] for icon, count in icon_to_count.items(): if count < self.config['min_duplicates_count']: icon_text = delim.join(icon for i in range(count)) else: icon_text = '{}x{}'.format(count, icon) icons_texts.append(icon_text) return delim.join(icons_texts)
def get_workspace_icons(self, workspace: i3ipc.Con) -> str: icon_to_count = collections.OrderedDict() for window in workspace.leaves(): icon = self.get_window_icon(window) if icon not in icon_to_count: icon_to_count[icon] = 0 icon_to_count[icon] += 1 if not icon_to_count: return '' icons_texts = [] delim = self.config['delimiter'] for icon, count in icon_to_count.items(): if count < self.config['min_duplicates_count']: icon_text = delim.join(icon for i in range(count)) else: icon_text = f'{count}x{icon}' icons_texts.append(icon_text) prefix = self.config.get('prefix', '') suffix = self.config.get('suffix', '') return prefix + delim.join(icons_texts) + suffix
def adjust_container(container: i3ipc.Con, ideal_dim: float, direction: str) -> Tuple[str, i3ipc.CommandReply, float]: """ Function to deterministically adjust a single container Args: container (i3ipc.Con): i3ipc.Container to adjust ideal_dim (float): Target dimension in pixels direction (str): Direction in which growing/shrinking should happen Returns: msg (str): Command sent out to i3 reply (i3ipc.CommandReply): Reply of resizing command given to i3 diff (float): Difference metric applied in resizing """ # Retrieve dimensions of provided container current_dims = [container.rect.width, container.rect.height] # Adjust containers by either resizing rightwards or downwards # since i3 tree layout provides containers from left to right # and consequently from upwards to downwards if direction == "width": # If width is to be adjusted, compute difference and adjust diff = ideal_dim - current_dims[0] if diff >= 0: msg = "resize grow right %d px" % diff else: msg = "resize shrink right %d px" % abs(diff) elif direction == "height": # If height is to be adjusted, compute difference and adjust diff = ideal_dim - current_dims[1] if diff >= 0: msg = "resize grow down %d px" % diff else: msg = "resize shrink down %d px" % abs(diff) # Capture the reply of the command to check success reply = container.command(msg) # Return both reply and the actual message, in case an error occurs return msg, reply, diff
def get_workspace(tree: i3ipc.Con, _: GroupToWorkspaces) -> i3ipc.Con: return tree.find_focused().workspace()
def get_group_name(tree: i3ipc.Con, _: GroupToWorkspaces) -> str: focused_workspace = tree.find_focused().workspace() return get_workspace_group(focused_workspace)
def _is_scratchpad(con: Con) -> bool: return con.window and con.parent.type != 'dockarea' and con.workspace( ).name == '__i3_scratch'
def _add_mark(container: i3ipc.Con, mark: str): container.command('mark --add "{}"'.format(mark))