I am a Sway user since quite some time. I'd say a happy user but from time to time I encounter some rough edges that most of the time can be solved with some scripting or with a better understanding of the documentation (RTFM!). I will illustrate the latter case as I tried to answer the question "How can I open a Firefox window and place it into a specific workspace?".
Since quite some time I have Sway configured with the directive xwayland disable
, that is I have disabled the X11 translation layer and forced myself to not use X11 applications at all. This is to test how the Wayland story is improving over time. This detail will become important later.
According to man 5 sway
you can assign a window to a workspace in many ways, example like this:
for_window [app_id="<APP_ID>"] move window to workspace <workspace>
The app_id
is a Wayland identifier for each window opened on the desktop. By using swaymsg -t get_tree
I can get the list of windows and nodes and understand how Firefox is called:
$ swaymsg -t get_tree | jq -c '.nodes[].nodes[].nodes[] | {id, app_id, name}'
{"id":52,"app_id":"firefox-aurora","name":"Firefox Developer Edition"}
Alright, I am using Firefox Developer Edition so its app_id
is "firefox-aurora". The corresponding Sway configuration to place the browser on workspace 1 could be:
for_window [app_id="firefox-aurora"] move window to workspace 1
Problem solved? Let's see.
If I open another Firefox window it goes to the same workspace, so from now on all Firefox windows will open there. Hm, not ideal? My usecase is actually to leverage Firefox profiles to have siloed environments (e.g. a profile focused on privacy, one more relaxed for testing web applications, etc.) and I'd like these different Firefox instances to open in different workspaces. However:
$ swaymsg -t get_tree | jq -c '.nodes[].nodes[].nodes[] | {id, app_id, name}'
{"id":68,"app_id":"firefox-aurora","name":"Example Domain – Firefox Developer Edition"}
{"id":69,"app_id":"firefox-aurora","name":"DuckDuckGo — Privacy, simplified. – Firefox Developer Edition"}
So, I need to distinguish them somehow.
On of the first suggestions encountered are about using an undocumented --class=WM_CLASS
parameter when launching Firefox. Weird. Also it seems it doesn't work:
$ firefox -P Profile1 --class profile1 www.duck.com &
$ firefox -P Profile2 --class profile2 www.example.org &
# however, nothing changed
$ swaymsg -t get_tree | jq -c '.nodes[].nodes[].nodes[] | {id, app_id, name}'
{"id":96,"app_id":"firefox-aurora","name":"Example Domain – Firefox Developer Edition"}
{"id":95,"app_id":"firefox-aurora","name":"DuckDuckGo — Privacy, simplified. – Firefox Developer Edition"}
After some searching for app_id
I end up once again on man 5 sway
and read more carefully:
%app_id - The wayland app ID (applicable to wayland windows only)
%class - The X11 classname (applicable to xwayland windows only)
So, if I am on "pure" Wayland I need to set that app_id
, but how? I assume there's another sigh undocumented Firefox parameter?
Yes.
Let's try again now:
$ firefox -P Profile1 --name profile1 www.example.org &
$ firefox -P Profile2 --name profile2 www.duck.com &
# yay!
$ swaymsg -t get_tree | jq -c '.nodes[].nodes[].nodes[] | {id, app_id, name}'
{"id":96,"app_id":"profile1","name":"Example Domain – Firefox Developer Edition"}
{"id":95,"app_id":"profile2","name":"DuckDuckGo — Privacy, simplified. – Firefox Developer Edition"}
Now I can have Sway get hold of the correct Firefox instance and send it to the desired workspace:
for_window [app_id="profile1"] move window to workspace 1
for_window [app_id="profile2"] move window to workspace 2