]> git.mdlowis.com Git - proto/labwc.git/commitdiff
session: only update activation environment...
authorAndrew J. Hesford <ajh@sideband.org>
Sun, 3 Mar 2024 20:04:24 +0000 (15:04 -0500)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 4 Mar 2024 00:57:32 +0000 (01:57 +0100)
...when running DRM backend or by explicit request

include/config/session.h
src/common/parse-bool.c
src/config/session.c
src/main.c

index 6de5f05d3cae3b7f8b936eedfb42a0d30fd24dc1..e882f0e844bcd4a9d3b9921048992d9342a93fa0 100644 (file)
@@ -2,6 +2,8 @@
 #ifndef LABWC_SESSION_H
 #define LABWC_SESSION_H
 
+struct server;
+
 /**
  * session_environment_init - set enrivonment variables based on <key>=<value>
  * 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 */
index 289ac0afb30be515639ad94c7eea77975503ddb8..edef698ad5b7406feffe8be7c71a2d350dabd60e 100644 (file)
@@ -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);
index 73ecb49b177b7dc4a10b6a253fa46b6951720736..56cef7177e081502faa56852badd6e481a65d30a 100644 (file)
@@ -6,11 +6,14 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <wlr/backend/drm.h>
+#include <wlr/backend/multi.h>
 #include <wlr/util/log.h>
 #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);
 }
index d4a12a800db4bb0d361ffffce06e8b29788c2694..35b2f3fad53e2038b6ce28bc2d9512e19e478fe4 100644 (file)
@@ -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);