mirror of
https://github.com/labwc/labwc.git
synced 2025-11-02 09:01:47 -05:00
session: only update activation environment...
...when running DRM backend or by explicit request
This commit is contained in:
parent
22fe8cf546
commit
c9d08f8218
4 changed files with 57 additions and 9 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue