From df47274af90095420f6073663cf9d2e62ffc6486 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 5 Jan 2021 11:38:26 +0100 Subject: [PATCH] Sorting functions --- src/swayswitch | 68 +++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/swayswitch b/src/swayswitch index 2eacf95..baaf764 100755 --- a/src/swayswitch +++ b/src/swayswitch @@ -96,13 +96,6 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member bitmap = wx.Bitmap() # pylint: disable=no-member return bitmap - def get_icon_path(self, desktop_file): - """Glue function to get icon path""" - icon_name = get_icon_name(desktop_file) - pos_icons = self.get_pos_icons(icon_name) - icon_path = self.get_right_size_icon(pos_icons) - return icon_path - def get_icon_dirs(self): """Find icon dirs""" icon_dirs = [] @@ -116,6 +109,13 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member return icon_dirs + def get_icon_path(self, desktop_file): + """Glue function to get icon path""" + icon_name = get_icon_name(desktop_file) + pos_icons = self.get_pos_icons(icon_name) + icon_path = self.get_right_size_icon(pos_icons) + return icon_path + def get_label(self, window): """Construct the label for the window""" try: @@ -233,6 +233,33 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member self.Close(True) +def extract_nodes_iterative(workspace): + """Extracts all windows from a sway workspace json object""" + all_nodes = [] + + floating_nodes = workspace.get('floating_nodes') + + for floating_node in floating_nodes: + floating_node['workspace'] = workspace['num'] + all_nodes.append(floating_node) + + nodes = workspace.get('nodes') + + for node in nodes: + + # Leaf node + if len(node.get('nodes')) == 0: + node['workspace'] = workspace['num'] + all_nodes.append(node) + # Nested node, handled iterative + else: + for inner_node in node.get('nodes'): + inner_node['workspace'] = workspace['num'] + nodes.append(inner_node) + + return all_nodes + + def get_command(pid): """Returns a list of all json window objects""" command = "ps h c -p {} -o command".format(pid) @@ -269,33 +296,6 @@ def get_windows(): return windows -def extract_nodes_iterative(workspace): - """Extracts all windows from a sway workspace json object""" - all_nodes = [] - - floating_nodes = workspace.get('floating_nodes') - - for floating_node in floating_nodes: - floating_node['workspace'] = workspace['num'] - all_nodes.append(floating_node) - - nodes = workspace.get('nodes') - - for node in nodes: - - # Leaf node - if len(node.get('nodes')) == 0: - node['workspace'] = workspace['num'] - all_nodes.append(node) - # Nested node, handled iterative - else: - for inner_node in node.get('nodes'): - inner_node['workspace'] = workspace['num'] - nodes.append(inner_node) - - return all_nodes - - def run_command(command): """Run a command on system and capture result""" process = subprocess.Popen(command,