Detect X autostart a bit better with a separate service. The service
relies on a shell script which searches for a socket which X creates on
startup and only finishes when it finds the socket succesfully.
This makes services which need X to start successfully a bit more
robust, and while it can still break if X takes too long, it should be
more stable now.
Finally, services can restart more quickly when ended since they don't
require the 2+ `RestartSec` option to be present anymore to successfully
start.
Flashfocus did not start up correctly since it was not required for the
`default.target` which is the only (?) valid target when systemd
operates in user-mode.
Instead of overwriting just part of the flashfocus service file, and
subsequently having it enabled for default.target and a non-existent
graphical.target user environment, we overwrite the whole file and set
it to `default.target`.
Additionally, the service should be restarted when it fails and slow
down on its restart attempts (I kept 5 seconds for this one, since it is
not as time critical as others -- no one cares if windows only flash
5 seconds after starting the machine.)
Added (wishful) After components to many service units, in case I figure
out one day how to make a useful target for the systemd user mode.
Main issue the restart delay fixes is that services don't wait for X to
be ready on startup (which is bad if the application being started
requires X being ready to actually work.)
I have still not found a way to work around waiting for X being ready
other then the ugly delay hack (for systemd --user modules at least).
However, the delay can be --- in most cases --- smaller than 5 seconds.
All my machines start reasonably fast and have X up and running from
pressing login to staring at the wallpaper in a couple seconds at most.
If services don't start correctly and the error is X not being ready,
increase the startup delay once again.
Dropdown services need an X server to connect to and fail autostarting
if there's no available server.
HACK
Increasing their restart timer will alleviate this problem, *but* it
also means the dropdowns will start more slowly when closed by the user.
There should be another way to alleviate one issue (start automatically
after X is available) without exacerbating the other (restart when you
have been closed).