Skip to content

Commit

Permalink
Now accepts options from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
mickenordin committed Jan 5, 2021
1 parent 89ba780 commit c113b04
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion rpm/swayswitch-TEMPLATE.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
21 changes: 20 additions & 1 deletion src/swayswitch
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import subprocess
from io import BytesIO

import cairosvg
import toml
import wx


Expand All @@ -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()

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c113b04

Please sign in to comment.