diff --git a/include/config/session.h b/include/config/session.h index 6de5f05d..e882f0e8 100644 --- a/include/config/session.h +++ b/include/config/session.h @@ -2,6 +2,8 @@ #ifndef LABWC_SESSION_H #define LABWC_SESSION_H +struct server; + /** * session_environment_init - set enrivonment variables based on = * pairs in `${XDG_CONFIG_DIRS:-/etc/xdg}/lawbc/environment` with user override @@ -13,12 +15,12 @@ void session_environment_init(void); * session_autostart_init - run autostart file as shell script * Note: Same as `sh ~/.config/labwc/autostart` (or equivalent XDG config dir) */ -void session_autostart_init(void); +void session_autostart_init(struct server *server); /** * session_shutdown - run session shutdown file as shell script * Note: Same as `sh ~/.config/labwc/shutdown` (or equivalent XDG config dir) */ -void session_shutdown(void); +void session_shutdown(struct server *server); #endif /* LABWC_SESSION_H */ diff --git a/src/common/parse-bool.c b/src/common/parse-bool.c index 289ac0af..edef698a 100644 --- a/src/common/parse-bool.c +++ b/src/common/parse-bool.c @@ -14,12 +14,16 @@ parse_bool(const char *str, int default_value) return true; } else if (!strcasecmp(str, "on")) { return true; + } else if (!strcmp(str, "1")) { + return true; } else if (!strcasecmp(str, "no")) { return false; } else if (!strcasecmp(str, "false")) { return false; } else if (!strcasecmp(str, "off")) { return false; + } else if (!strcmp(str, "0")) { + return false; } error_not_a_boolean: wlr_log(WLR_ERROR, "(%s) is not a boolean value", str); diff --git a/src/config/session.c b/src/config/session.c index 73ecb49b..56cef717 100644 --- a/src/config/session.c +++ b/src/config/session.c @@ -6,11 +6,14 @@ #include #include #include +#include +#include #include #include "common/buf.h" #include "common/dir.h" #include "common/file-helpers.h" #include "common/mem.h" +#include "common/parse-bool.h" #include "common/spawn.h" #include "common/string-helpers.h" #include "config/session.h" @@ -78,14 +81,53 @@ read_environment_file(const char *filename) } static void -update_activation_env(bool initialize) +backend_check_drm(struct wlr_backend *backend, void *is_drm) { + if (wlr_backend_is_drm(backend)) { + *(bool *)is_drm = true; + } +} + +static bool +should_update_activation(struct server *server) +{ + assert(server); + + static const char *act_env = "LABWC_UPDATE_ACTIVATION_ENV"; + char *env = getenv(act_env); + if (env) { + /* Respect any valid preference from the environment */ + int enabled = parse_bool(env, -1); + + if (enabled == -1) { + wlr_log(WLR_ERROR, "ignoring non-Boolean variable %s", act_env); + } else { + wlr_log(WLR_DEBUG, "%s is %s", + act_env, enabled ? "true" : "false"); + return enabled; + } + } + + /* With no valid preference, update when a DRM backend is in use */ + bool have_drm = false; + wlr_multi_for_each_backend(server->backend, backend_check_drm, &have_drm); + return have_drm; +} + +static void +update_activation_env(struct server *server, bool initialize) +{ + if (!should_update_activation(server)) { + return; + } + if (!getenv("DBUS_SESSION_BUS_ADDRESS")) { /* Prevent accidentally auto-launching a dbus session */ wlr_log(WLR_INFO, "Not updating dbus execution environment: " "DBUS_SESSION_BUS_ADDRESS not set"); return; } + wlr_log(WLR_INFO, "Updating dbus execution environment"); char *env_keys = str_join(env_vars, "%s", " "); @@ -170,18 +212,18 @@ run_session_script(const char *script) } void -session_autostart_init(void) +session_autostart_init(struct server *server) { /* Update dbus and systemd user environment, each may fail gracefully */ - update_activation_env(/* initialize */ true); + update_activation_env(server, /* initialize */ true); run_session_script("autostart"); } void -session_shutdown(void) +session_shutdown(struct server *server) { run_session_script("shutdown"); /* Clear the dbus and systemd user environment, each may fail gracefully */ - update_activation_env(/* initialize */ false); + update_activation_env(server, /* initialize */ false); } diff --git a/src/main.c b/src/main.c index d4a12a80..35b2f3fa 100644 --- a/src/main.c +++ b/src/main.c @@ -171,14 +171,14 @@ main(int argc, char *argv[]) menu_init(&server); - session_autostart_init(); + session_autostart_init(&server); if (startup_cmd) { spawn_async_no_shell(startup_cmd); } wl_display_run(server.wl_display); - session_shutdown(); + session_shutdown(&server); server_finish(&server);