Now accepts options from config file

main
Micke Nordin 3 years ago
parent 89ba780e4a
commit c113b04eaf

@ -1,5 +1,5 @@
# swayswitch # swayswitch
A simple window switcher for Sway wayland compositor written in python using wxPython A simple window switcher for the Sway Wayland compositor written in python using wxPython.
## Installation ## Installation
@ -20,12 +20,23 @@ sudo dnf install swayswitch
## Usage ## Usage
Reload config and open up window switcher with Mod4+tab. Move around the switcher using arrow-keys or Tab. Reload config and open up window switcher with Mod4+tab. Move around the switcher using arrow-keys or Tab.
Esc aborts and enter switches window. It is also possible to select window with the mouse. Configuration is installed to /etc/sway/config.d/swayswitch.conf Esc aborts and enter switches window. It is also possible to select window with the mouse.
Two keybindings work by default, Mod4+f to toggle fullscreen mode, that is if you manage to bring up the switcher while in fullscreen mode you can display the Two keybindings work by default, Mod4+f to toggle fullscreen mode, that is if you manage to bring up the switcher while in fullscreen mode you can display the
switcher window by exiting fullscreen mode. You can also exit switcher mode by pressing Mod4+q, this is usefull if you manage to get another window on to of switcher window by exiting fullscreen mode. You can also exit switcher mode by pressing Mod4+q, this is usefull if you manage to get another window on top of
the switcher window somehow. 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.
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.
## 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>

2
debian/control vendored

@ -10,6 +10,6 @@ Package: swayswitch
Section: utils Section: utils
Priority: optional Priority: optional
Architecture: all Architecture: all
Depends: python3-cairosvg, python3-wxgtk4.0, sway Depends: python3-cairosvg, python3-toml, python3-wxgtk4.0, sway
Essential: no Essential: no
Description: SwaySwitch is a simple window switcher for Sway Description: SwaySwitch is a simple window switcher for Sway

@ -2,7 +2,7 @@ Buildroot: /home/micke/sources/swayswitch-##VERSION##
Name: swayswitch Name: swayswitch
Version: ##VERSION## Version: ##VERSION##
Release: 1 Release: 1
Requires: python3-wxpython4 Requires: python3-cairosvg, python3-toml, python3-wxpython4, sway
Summary: SwaySwitch is a simple window switcher for sway Summary: SwaySwitch is a simple window switcher for sway
License: GPLv3+ License: GPLv3+
Distribution: Fedora Distribution: Fedora
@ -18,6 +18,8 @@ SwaySwitch is a simple window switcher for sway:
<https://swaywm.org> <https://swaywm.org>
%files %files
%dir "/etc/sway/config.d/"
"/etc/sway/config.d/swayswitch.conf"
"/usr/bin/swayswitch" "/usr/bin/swayswitch"
%dir "/usr/share/doc/swayswitch/" %dir "/usr/share/doc/swayswitch/"
"/usr/share/doc/swayswitch/changelog.gz" "/usr/share/doc/swayswitch/changelog.gz"

@ -13,6 +13,7 @@ import subprocess
from io import BytesIO from io import BytesIO
import cairosvg import cairosvg
import toml
import wx import wx
@ -30,9 +31,11 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
# get windows from sway # get windows from sway
windows = get_windows() windows = get_windows()
# Get config # Config defaults
self.label_len = 20 self.label_len = 20
self.icon_size = 128 self.icon_size = 128
# Can be overwritten in config_file $HOME/.local/swayswitch/config
self.set_config_from_file()
self.icon_dirs = self.get_icon_dirs() self.icon_dirs = self.get_icon_dirs()
@ -207,6 +210,22 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
inner_sizer.Layout() inner_sizer.Layout()
self.sizer.Add(inner_sizer, 0, wx.ALIGN_CENTER) # pylint: disable=no-member self.sizer.Add(inner_sizer, 0, wx.ALIGN_CENTER) # pylint: disable=no-member
def set_config_from_file(self):
"""If user has created a config file we will use values from there"""
config_file = self.home + "/.local/swayswitch/config"
if os.path.exists(config_file):
try:
cfg = toml.load(config_file)
if cfg["label_len"]:
self.label_len = cfg["label_len"]
if cfg["icon_size"]:
self.icon_size = cfg["icon_size"]
except toml.TomlDecodeError:
#If use has formating errors we warn to stderr, but move on with defaults
os.write(
2, b"WARNING: formatting errors in " +
config_file.encode() + b"\n")
def switch_window(self, event, winid): # pylint: disable=unused-argument def switch_window(self, event, winid): # pylint: disable=unused-argument
"""Switches the focus to the given id and enter normalmode""" """Switches the focus to the given id and enter normalmode"""
command = 'swaymsg [con_id={}] focus, mode "default"'.format(winid) command = 'swaymsg [con_id={}] focus, mode "default"'.format(winid)

Loading…
Cancel
Save