Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
|
51eb844678 | ||
|
2e09a4c4a9 | ||
df47274af9 |
2 changed files with 37 additions and 37 deletions
|
@ -1,5 +1,5 @@
|
||||||
# swayswitch
|
# 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
|
## Installation
|
||||||
|
|
||||||
|
@ -28,14 +28,14 @@ the switcher window somehow.
|
||||||
|
|
||||||
### Config files
|
### 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.
|
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:
|
Possible options are:
|
||||||
```
|
```
|
||||||
label_len = 20
|
label_len = 20
|
||||||
icon_size = 128
|
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
|
||||||
Thanks to tobiaspc for the startingpoint for this code: <https://github.com/tobiaspc/wofi-scripts>
|
Thanks to tobiaspc for the startingpoint for this code: <https://github.com/tobiaspc/wofi-scripts>
|
||||||
|
|
|
@ -96,13 +96,6 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
|
||||||
bitmap = wx.Bitmap() # pylint: disable=no-member
|
bitmap = wx.Bitmap() # pylint: disable=no-member
|
||||||
return bitmap
|
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):
|
def get_icon_dirs(self):
|
||||||
"""Find icon dirs"""
|
"""Find icon dirs"""
|
||||||
icon_dirs = []
|
icon_dirs = []
|
||||||
|
@ -116,6 +109,13 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
|
||||||
|
|
||||||
return icon_dirs
|
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):
|
def get_label(self, window):
|
||||||
"""Construct the label for the window"""
|
"""Construct the label for the window"""
|
||||||
try:
|
try:
|
||||||
|
@ -233,6 +233,33 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
|
||||||
self.Close(True)
|
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):
|
def get_command(pid):
|
||||||
"""Returns a list of all json window objects"""
|
"""Returns a list of all json window objects"""
|
||||||
command = "ps h c -p {} -o command".format(pid)
|
command = "ps h c -p {} -o command".format(pid)
|
||||||
|
@ -269,33 +296,6 @@ def get_windows():
|
||||||
return 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):
|
def run_command(command):
|
||||||
"""Run a command on system and capture result"""
|
"""Run a command on system and capture result"""
|
||||||
process = subprocess.Popen(command,
|
process = subprocess.Popen(command,
|
||||||
|
|
Loading…
Add table
Reference in a new issue