mirror of
https://github.com/labwc/labwc.git
synced 2026-04-12 08:21:13 -04:00
Use system directory as fallback location for environment and autostart
This commit is contained in:
parent
351d0a30ad
commit
91f8889785
4 changed files with 45 additions and 27 deletions
|
|
@ -4,17 +4,15 @@
|
|||
|
||||
/**
|
||||
* session_environment_init - set enrivonment variables based on <key>=<value>
|
||||
* @dir: path to config directory
|
||||
* pairs in `${XDG_CONFIG_DIRS:-/etc/xdg}/lawbc/environment` with user override
|
||||
* in `${XDG_CONFIG_HOME:-$HOME/.config}`
|
||||
*/
|
||||
void session_environment_init(const char *dir);
|
||||
void session_environment_init(void);
|
||||
|
||||
/**
|
||||
* session_autostart_init - run autostart file as shell script
|
||||
* @dir: path to config directory
|
||||
* Note: Same as `sh ~/.config/labwc/autostart` (or equivalent XDG config dir)
|
||||
*/
|
||||
void session_autostart_init(const char *dir);
|
||||
void session_autostart_init(void);
|
||||
|
||||
#endif /* LABWC_SESSION_H */
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "common/buf.h"
|
||||
#include "common/dir.h"
|
||||
#include "common/file-helpers.h"
|
||||
#include "common/spawn.h"
|
||||
#include "common/string-helpers.h"
|
||||
|
|
@ -45,14 +46,14 @@ error:
|
|||
free(value.buf);
|
||||
}
|
||||
|
||||
static void
|
||||
static bool
|
||||
read_environment_file(const char *filename)
|
||||
{
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
FILE *stream = fopen(filename, "r");
|
||||
if (!stream) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
wlr_log(WLR_INFO, "read environment file %s", filename);
|
||||
while (getline(&line, &len, stream) != -1) {
|
||||
|
|
@ -64,6 +65,7 @@ read_environment_file(const char *filename)
|
|||
}
|
||||
free(line);
|
||||
fclose(stream);
|
||||
return true;
|
||||
}
|
||||
|
||||
static char *
|
||||
|
|
@ -96,7 +98,7 @@ update_activation_env(const char *env_keys)
|
|||
}
|
||||
|
||||
void
|
||||
session_environment_init(const char *dir)
|
||||
session_environment_init(void)
|
||||
{
|
||||
/*
|
||||
* Set default for XDG_CURRENT_DESKTOP so xdg-desktop-portal-wlr is happy.
|
||||
|
|
@ -114,32 +116,50 @@ session_environment_init(const char *dir)
|
|||
*/
|
||||
setenv("_JAVA_AWT_WM_NONREPARENTING", "1", 0);
|
||||
|
||||
char *environment = build_path(dir, "environment");
|
||||
if (!environment) {
|
||||
return;
|
||||
int i;
|
||||
bool read = false;
|
||||
char *environment;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
environment = build_path(i ? sys_config_dir() : user_config_dir(), "environment");
|
||||
if (environment) {
|
||||
read = read_environment_file(environment);
|
||||
free(environment);
|
||||
}
|
||||
if (read) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
read_environment_file(environment);
|
||||
free(environment);
|
||||
}
|
||||
|
||||
void
|
||||
session_autostart_init(const char *dir)
|
||||
session_autostart_init(void)
|
||||
{
|
||||
/* Update dbus and systemd user environment, each may fail gracefully */
|
||||
update_activation_env("DISPLAY WAYLAND_DISPLAY XDG_CURRENT_DESKTOP");
|
||||
|
||||
char *autostart = build_path(dir, "autostart");
|
||||
if (!autostart) {
|
||||
return;
|
||||
int i;
|
||||
char *autostart;
|
||||
for (i = 0; i < 2; i++)
|
||||
{
|
||||
autostart = build_path(i ? sys_config_dir() : user_config_dir(), "autostart");
|
||||
|
||||
if (autostart) {
|
||||
if (file_exists(autostart)) {
|
||||
break;
|
||||
}
|
||||
free(autostart);
|
||||
autostart = NULL;
|
||||
}
|
||||
}
|
||||
if (!file_exists(autostart)) {
|
||||
|
||||
if (autostart) {
|
||||
wlr_log(WLR_INFO, "run autostart file %s", autostart);
|
||||
char *cmd = strdup_printf("sh %s", autostart);
|
||||
spawn_async_no_shell(cmd);
|
||||
free(cmd);
|
||||
free(autostart);
|
||||
} else {
|
||||
wlr_log(WLR_ERROR, "no autostart file");
|
||||
goto out;
|
||||
}
|
||||
wlr_log(WLR_INFO, "run autostart file %s", autostart);
|
||||
char *cmd = strdup_printf("sh %s", autostart);
|
||||
spawn_async_no_shell(cmd);
|
||||
free(cmd);
|
||||
out:
|
||||
free(autostart);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
wlr_log(WLR_INFO, "using config dir (%s)\n", rc.config_dir);
|
||||
session_environment_init(rc.config_dir);
|
||||
session_environment_init();
|
||||
rcxml_read(config_file);
|
||||
|
||||
/*
|
||||
|
|
@ -184,7 +184,7 @@ main(int argc, char *argv[])
|
|||
|
||||
menu_init(&server);
|
||||
|
||||
session_autostart_init(rc.config_dir);
|
||||
session_autostart_init();
|
||||
if (startup_cmd) {
|
||||
spawn_async_no_shell(startup_cmd);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ reload_config_and_theme(void)
|
|||
static int
|
||||
handle_sighup(int signal, void *data)
|
||||
{
|
||||
session_environment_init(rc.config_dir);
|
||||
session_environment_init();
|
||||
reload_config_and_theme();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue