Oh hey totallynotkermit
Nice to see you again. Small world!
Sorry I took forever to reply, I’m not really visiting these (or any) forums any more, just popped by to get this done.
Any way, this is all in good hands without my input, so I guess this is all just for conversation and contemplation’s sake 
Agreed! Such an app might be pretty awful. For purposes of conversation we might imagine an app that sends output to a printer or blinks keyboard lights or plays sounds or something silly, but it wasn’t really intended as an example of a real application, but as a demonstration of why the logic will fail if we don’t do it this way.
More of a thought experiment. The point is that the time between starting the app and opening a window is unbounded and unknown so we kinda have to treat it like it’s possibly infinite if we want things to work. (and also possibly zero and everywhere inbetween, of course)
Sorry, what I meant (I worded it badly) was that the app should receive input as soon as it’s ready. Like, once you start an application, and let’s assume that application doesn’t have any delay and is ready immediately, and you start typing immediately, you expect that typing to go into that app.
This is real simple if we’re talking about an app that starts in 5ms because we press enter and bam it’s there. But for an app that takes 5s (like steam) what can we do? Do we wait until it is ready? Well that obviously sucks as you’ve noticed
Otherwise what, wait some weird amount of time inbetween when we start it and when it is ready, and then swap? Swap at some time after it’s ready? Then we would have a whole new problem. Obviously the only choice is to give focus immediately.
This is the kind of thought experiment I was doing earlier
This is a good one.
Yeh, maybe our app opens a window in 2 seconds, or 5, or two windows, or maybe it renders a 3D model for 20 minutes and then creates a window to show it, or maybe it just never shows a window at all.
In any of those cases it’s fine if it is given focus immediately because it could still be accepting keyboard input; and as above, probably best that way because a delay of giving it focus until the window finally does appear, will feel like stealing.
And if it has a window but doesn’t accept input, it should still take focus so we can send WM commands to it, like closing or minimising the window…
But what about when it doesn’t (yet, or forever) have a window AND does not take keyboard input? I wouldn’t want that to immediately take focus if I run sleep 9000
But in my experiments here, it already doesn’t. An app like that effectively runs as a systemd service in it’s own unit containment with disconnected standard IO and stays that way until it ends, never taking focus.
I guess a more direct way of saying this is: we should not wait until the output (window) is ready, before we direct input to (focus) the application; because the application might be ready for input even if there is no output; and even if it’s not ready, the experience of a ‘delayed focus’ will be pseudo-focus-stealing as you’ve reported here; and even if it never will be ready, plasma can never know that. So we need to send input to the app immediately, window or no…
This works correctly for all apps with or without windows OR with or without input AND those which have either but delay in using them. BUT if you run an app with no UI at all, it will still get focus - which makes perfect sense because the system can never know beforehand, whether the UI is never coming or just delayed.
At the moment, it appears to be assuming there will be no UI (it doesn’t shift focus) until it sees one, which strikes me as kinda weird since it’s so rare and basically operator error to actually run something with no UI which doesn’t return in a very short time (I mean, one should not run a service from krunner, that’s for systemd), and there’s no way to avoid the behaviour you observed unless it’s done the other way, assuming the UI is coming, and shifting focus accordingly.
Anyway sorry that was a bit long. Kinda got a few gears grinding in my brain here courtesy of your “what about no UI at all” thought experiment
I guess this whole message is just an explanation of my answer to that, “I don’t think we care about that” 
You’ve presented a really interesting conundrum because logically there’s no other choice here - we either have to endure focus stealing as you’ve reported, or we have to endure that if we run a service from our UI then our previously active app will lose focus and we will have to focus it manually. I think the latter is the best choice.
Always nice to talk with you.