Sway challenge ... autostart puzzlement

Greetings to those who have made headway setting up sway… I’m trying to see if I can make the transition from i3wm and the jury is still out. Here’s my latest challenge:

Tl;dr: How do you start up sway with various programs opened across various workspaces, but not be stuck with these assignments for the entire session?

In i3wm you can set up a program to open during logon in a particular workspace (via autostart configs). That program can subsequently be opened by the user in other workspaces, too. It’s not fixed to open only in that same initial single workspace assignment for all time. You can auto-open a terminal in workspace #1 during startup, but later on open other terminal instances in various other workspaces.)

Challenge: I cannot get this same behavior to work in sway.

Sure, I can assign kitty to autostart in workspace #1 upon startup (in a ‘workspace’ or ‘autostart’ config file) . But any future instances of kitty will then only open in workspace #1 - regardless of which other workspace has focus at the time.

What’s more, when I run ranger file mgr (specifically: exec kitty -e ranger) then it too will only open in workspace #1 due to the kitty connection. And this initial assignment affects not only the initial terminal instance during autostart but persists throughout the entire sway session.

On the other hand: If I avoid making a workspace assignment during the autostart routine, then all of the various programs opened on startup all get crammed into workspace #1. I have to then manually move them over to various other workspaces where I’d like them to be after startup.

I’ve tried messing with the swaymsg command and the move command. So far, no luck.

Of course I’ve searched online quite a bit and find that many have asked to solve this… but no one seems to have come up with a solution yet. So I’m tempted to conclude it cannot be done.

But this is such a basic use case - i.e., starting up a session with various programs appearing in various individual workspaces without being stuck with those assignments going forward - I’m convinced there’s got to be way to achieve this. Sway is far more sophisticated and programmable than i3wm, right?

But thus far I’m stumped.

Anyone figure this one out? If so I’d sure appreciate knowing how you’ve done it! :folded_hands:

Would something like this work? exec swaymsg "workspace 1; exec your_program

EDIT: I added this as a test, worked as expected:

exec swaymsg "workspace 3; exec $term"
exec swaymsg "workspace 6; exec thunar"

With slow-loading programs, you may have to add in some delays.

There are numerous workflow related xorg approaches that are cumbersome at best and impossible at worst to make ‘smooth’ in Wayland. Wayland- like xorg- shows its biases. I personally gave up on Wayland (after 12 months of struggle) because of how dependent I am on conky, wmctrl, xdotool, dwm… to mention a few. I am hopeful that xlibre will save the day… or I will die before xorg goes away. :rofl: :old_man:

@ajgringo619 Thanks for the suggestions. They’re similar to what I’ve tried.

The specific examples above work great upon start up… But then any future instance of $term puts it on the same workspace as the original, regardless of which workspace has focus at that time.

It seems the “assignment” between program and workspace seems to persist. Do you not experience the same? If not, there’s hope I can overcome this issue and replicate the i3 experience.

Put differently, do you have various programs open in multiple workspaces upon start up… And then open future instances (like $term) wherever you like?

My main system is Hyprland, no startup programs except for ones that sit in the system tray. When I ran Sway last year, it was the same (not a fan of startup apps).

That being said, it should not be the default behavior. I’ll run some more tests and let you know.

OK, the good news is that I’m able to start programs launched by autostart in any other workspace (tested with kitty and thunar). The bad news is that more complicated programs, like vivaldi, don’t autostart at all (swaymsg "workspace 7; exec vivaldi" does work from the terminal). I can’t say if this is specific to vivaldi.

I would try adding all of your preferred startup programs into a separate script, then use exec to call that.

@ajgringo619 Thank you kindly for your continuing efforts!

Between your post and my prior efforts, here’s a subtle revision that finally works to open 3 distinct workspaces (1,2,3), each program in its own workspace (carefully note the ’ and " as they are shown) - and subsequent instances of kitty or ranger open wherever sway has focus at that time:

exec $term
exec swaymsg "workspace $ws2; exec 'kitty -e ranger'"
exec swaymsg "workspace $ws3; exec vivaldi"

There are still some strange artifacts that pop up - I’ll update this post with further edits to address. But in the large picture. This now works as hoped!

Additional note: I’ve actually had no problem opening various programs (including vivaldi) in distinct workspaces. The challenge then became when opening new workspace (eg, #5) and trying to also open another terminal (kitty) in that same #5 workspace, it would open another terminal instance back in workspace #1 - not in #5. This was happening when using the “assign” procedure, but failing to use it created jumbled programs all in a single (#1) workspace.

For some combination of reasons, the above commands (placed in an autostart config script) hits the right combo without using “assign” - which becomes problematic for my preferred use case.

Again, there’s more fiddling to do and I’ll update this post to share whatever I learn along the way. I suspect the move command also has promise. It works beautifully in terminal/shell mode, but cannot seem to invoke it with a sway script. :man_shrugging:

I use xlibre on all of my X11-based systems, even use it with my main Hyprland system (mainly for older games that don’t run well with Wayland). I too was heavily invested in conky and wmctrl. But after embracing tiling WMs, I don’t need wmctrl anymore.

I use wmctrl on all my tilers… (dwm, i3wm, hlwm,… and stackers openbox…