strawberry/app/autostart.hpp
trvon 2e5637fe6c
Some checks failed
Build and Test / build (debug, clang) (push) Has been cancelled
Build and Test / build (debug, gcc) (push) Has been cancelled
Build and Test / build (release, clang) (push) Has been cancelled
Build and Test / build (release, gcc) (push) Has been cancelled
Build and Test / docker (push) Has been cancelled
Add "Start at login" to the tray app
A checkable tray menu item and a Diagnostics-tab checkbox write or
remove ~/.config/autostart/strawberry-tray.desktop (XDG autostart,
atomic write), pointing at the installed strawberry-tray when there is
one. Sessions that do not run autostart entries on their own (sway, i3,
Hyprland, niri without uwsm/dex) get a note with the exact line to add
to the compositor config instead of a silent no-op; GNOME, KDE, XFCE and
the like, or an active xdg-desktop-autostart.target, need nothing more.

The logic is Qt-free (app/autostart.cpp) with a unit test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 20:59:52 -06:00

48 lines
1.9 KiB
C++

#ifndef STRAWBERRY_APP_AUTOSTART_HPP
#define STRAWBERRY_APP_AUTOSTART_HPP
// "Start at login" for the tray app, via the XDG autostart standard:
// $XDG_CONFIG_HOME/autostart/strawberry-tray.desktop (default
// ~/.config/autostart). GNOME, KDE, XFCE, LXQt, Cinnamon, MATE and systemd's
// xdg-desktop-autostart.target (uwsm, some sway setups) run these entries.
// Plain sway/i3/Hyprland sessions do not; session_hint() then says how to
// start the tray from the compositor config instead of pretending it worked.
//
// No Qt here, so it is unit-tested without a display.
#include <string>
namespace strawberry::app {
struct AutostartEnv {
std::string xdg_config_home; // $XDG_CONFIG_HOME, may be empty
std::string home; // $HOME
std::string current_desktop; // $XDG_CURRENT_DESKTOP, e.g. "sway:wlroots"
bool autostart_target_active = false; // systemctl --user is-active xdg-desktop-autostart.target
};
AutostartEnv autostart_env_from_process();
/// The entry file this app owns.
std::string autostart_file(const AutostartEnv& env);
/// The .desktop entry written for `exec_path` (an absolute path).
std::string autostart_entry(const std::string& exec_path);
/// True if the entry exists and is not disabled (Hidden=true or
/// X-GNOME-Autostart-enabled=false).
bool autostart_enabled(const AutostartEnv& env);
/// Writes (atomically: temp file + rename) or removes the entry.
bool set_autostart(const AutostartEnv& env, bool enable, const std::string& exec_path, std::string& error);
/// True when the session is known to run XDG autostart entries.
bool session_runs_xdg_autostart(const AutostartEnv& env);
/// Empty when the entry is enough; otherwise one sentence on how to start
/// the tray in this session (e.g. a sway `exec` line).
std::string session_hint(const AutostartEnv& env, const std::string& exec_path);
} // namespace strawberry::app
#endif // STRAWBERRY_APP_AUTOSTART_HPP