swaywsr
is a small program that uses Sways's IPC Interface
to change the name of a workspace based on its contents.
It is a port from Daniel Berg's (roosta) i3wsr which I also contributed to. Most of the code is the same.
The chosen name for a workspace is a composite of the app_id
(wayland native) or WM_CLASS
X11 window
property for each window in a workspace. In action it would look something like this:
Build a release binary,
cargo build --release
Just launch the program and it'll listen for events if you are running sway. Another option is to put something like this in your sway config
exec_always --no-startup-id $PATH_TO_RELEASE_BINARY
You can configure icons for the respective classes, a very basic preset for font-awesome is configured, to enable it use the option --icons awesome
(requires font-awesome to be installed).
If you have icons and don't want the names to be displayed, you can use the --no-names
flag.
For further customization, use the --config path_to_file.toml
option. The toml
file has to fields, icons
to assign icons to classes, and aliases
to assign alternative names to be displayed.
Example config can be found in assets/example_config.toml
[icons]
# font awesome
TelegramDesktop = ""
Firefox = ""
Alacritty = ""
Thunderbird = ""
# smile emoji
MyNiceProgram = "😛"
[aliases]
TelegramDesktop = "Telegram"
"Org.gnome.Nautilus" = "Nautilus"
[general]
seperator = ""
For an overview of available options
$ swaywsr -h
swaywsr - sway workspace renamer 1.0.0
Pedro Scaff <pedro@scaff.me>
USAGE:
swaywsr [FLAGS] [OPTIONS]
FLAGS:
-h, --help Prints help information
--no-names Set to no to display only icons (if available)
-V, --version Prints version information
OPTIONS:
-c, --config <config> Path to toml config file
--icons <icons> Sets icons to be used [possible values: awesome]
This program depends on numbered workspaces, since we're constantly changing the workspace name. So your sway configuration need to reflect this:
bindsym $mod+1 workspace number 1
If you don't necessarily bind your workspaces to only numbers, or you want to keep a part of the name constant you can do like this:
bindsym $mod+q workspace number 1:[Q]
This way the workspace would look something like this when it gets changed:
1:[Q] Emacs|Firefox
You can take this a bit further by using a bar that trims the workspace number and be left with only
[Q] Emacs|Firefox
Thanks Daniel Berg (roosta) for the original i3wsr implementation. This program would not be possible without swayipc-rs, a rust library for controlling sway-wm through its IPC interface.