Compare commits

...

3 commits
0.1.0 ... main

Author SHA1 Message Date
Mikael Nordin
51eb844678
Update README.md 2021-01-05 23:41:23 +01:00
Mikael Nordin
2e09a4c4a9
Update README.md 2021-01-05 19:43:43 +01:00
df47274af9 Sorting functions 2021-01-05 11:38:26 +01:00
2 changed files with 37 additions and 37 deletions

View file

@ -1,5 +1,5 @@
# swayswitch
A simple window switcher for the Sway Wayland compositor written in python using wxPython.
A simple window switcher for the [Sway](https://swaywm.org/) 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 on is optionally supplied by the user as $HOME/.local/swayswitch/config in toml format.
The other one 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 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 in number of characters 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,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,