Now accepts options from config file
This commit is contained in:
parent
89ba780e4a
commit
c113b04eaf
4 changed files with 38 additions and 6 deletions
17
README.md
17
README.md
|
@ -1,5 +1,5 @@
|
|||
# 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
|
||||
|
||||
|
@ -20,12 +20,23 @@ sudo dnf install swayswitch
|
|||
|
||||
## Usage
|
||||
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
|
||||
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.
|
||||
|
||||
### 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 to tobiaspc for the startingpoint for this code: <https://github.com/tobiaspc/wofi-scripts>
|
||||
|
||||
|
|
2
debian/control
vendored
2
debian/control
vendored
|
@ -10,6 +10,6 @@ Package: swayswitch
|
|||
Section: utils
|
||||
Priority: optional
|
||||
Architecture: all
|
||||
Depends: python3-cairosvg, python3-wxgtk4.0, sway
|
||||
Depends: python3-cairosvg, python3-toml, python3-wxgtk4.0, sway
|
||||
Essential: no
|
||||
Description: SwaySwitch is a simple window switcher for Sway
|
||||
|
|
|
@ -2,7 +2,7 @@ Buildroot: /home/micke/sources/swayswitch-##VERSION##
|
|||
Name: swayswitch
|
||||
Version: ##VERSION##
|
||||
Release: 1
|
||||
Requires: python3-wxpython4
|
||||
Requires: python3-cairosvg, python3-toml, python3-wxpython4, sway
|
||||
Summary: SwaySwitch is a simple window switcher for sway
|
||||
License: GPLv3+
|
||||
Distribution: Fedora
|
||||
|
@ -18,6 +18,8 @@ SwaySwitch is a simple window switcher for sway:
|
|||
<https://swaywm.org>
|
||||
|
||||
%files
|
||||
%dir "/etc/sway/config.d/"
|
||||
"/etc/sway/config.d/swayswitch.conf"
|
||||
"/usr/bin/swayswitch"
|
||||
%dir "/usr/share/doc/swayswitch/"
|
||||
"/usr/share/doc/swayswitch/changelog.gz"
|
||||
|
|
|
@ -13,6 +13,7 @@ import subprocess
|
|||
from io import BytesIO
|
||||
|
||||
import cairosvg
|
||||
import toml
|
||||
import wx
|
||||
|
||||
|
||||
|
@ -30,9 +31,11 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
|
|||
# get windows from sway
|
||||
windows = get_windows()
|
||||
|
||||
# Get config
|
||||
# Config defaults
|
||||
self.label_len = 20
|
||||
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()
|
||||
|
||||
|
@ -207,6 +210,22 @@ class SwaySwitch(wx.Frame): # pylint: disable=no-member
|
|||
inner_sizer.Layout()
|
||||
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
|
||||
"""Switches the focus to the given id and enter normalmode"""
|
||||
command = 'swaymsg [con_id={}] focus, mode "default"'.format(winid)
|
||||
|
|
Loading…
Add table
Reference in a new issue