Compare commits

..

No commits in common. "main" and "0.1.0" have entirely different histories.
main ... 0.1.0

2 changed files with 37 additions and 37 deletions

View file

@ -1,5 +1,5 @@
# swayswitch
A simple window switcher for the [Sway](https://swaywm.org/) Wayland compositor written in python using wxPython.
A simple window switcher for the Sway Wayland compositor written in python using wxPython.
## Installation
@ -28,14 +28,14 @@ the switcher window somehow.
### Config files
SwaySwitch uses two configuration files, one is supplied with the package and is installed to /etc/sway/config.d/swayswitch.conf. It contains default keybindings for Sway.
The other one is optionally supplied by the user as $HOME/.local/swayswitch/config in toml format.
The other on is optionally supplied by the user as $HOME/.local/swayswitch/config in toml format.
Possible options are:
```
label_len = 20
icon_size = 128
```
The example above is the default options. ```label_len``` is the total length of the text label above buttons in number of characters and ```icon_size``` is the size of the icons in pixels.
The example above is the default options. ```label_len``` is the total length of the text label above buttons and ```icon_size``` is the size of the icons in pixels.
## Thanks
Thanks to tobiaspc for the startingpoint for this code: <https://github.com/tobiaspc/wofi-scripts>

View file

@ -96,6 +96,13 @@ 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 = []
@ -109,13 +116,6 @@ 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,33 +233,6 @@ 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)
@ -296,6 +269,33 @@ 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,