2021-09-24 21:45:48 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2020-10-08 20:50:20 +01:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
2024-02-18 12:23:14 -05:00
|
|
|
#include <assert.h>
|
2024-03-09 12:03:30 -05:00
|
|
|
#include <dirent.h>
|
2020-10-08 20:50:20 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/stat.h>
|
2024-03-09 12:03:30 -05:00
|
|
|
#include <sys/types.h>
|
2024-03-03 15:04:24 -05:00
|
|
|
#include <wlr/backend/drm.h>
|
|
|
|
|
#include <wlr/backend/multi.h>
|
2021-07-22 21:30:17 +01:00
|
|
|
#include <wlr/util/log.h>
|
2021-10-11 22:15:44 +01:00
|
|
|
#include "common/buf.h"
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
#include "common/dir.h"
|
2023-08-21 21:07:28 +01:00
|
|
|
#include "common/file-helpers.h"
|
2024-02-18 12:23:14 -05:00
|
|
|
#include "common/mem.h"
|
2024-03-03 15:04:24 -05:00
|
|
|
#include "common/parse-bool.h"
|
2020-10-08 20:50:20 +01:00
|
|
|
#include "common/spawn.h"
|
2020-10-09 19:46:59 +01:00
|
|
|
#include "common/string-helpers.h"
|
2023-01-31 03:35:13 +01:00
|
|
|
#include "config/session.h"
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
#include "labwc.h"
|
2020-10-08 20:50:20 +01:00
|
|
|
|
2024-02-18 12:23:14 -05:00
|
|
|
static const char *const env_vars[] = {
|
|
|
|
|
"DISPLAY",
|
|
|
|
|
"WAYLAND_DISPLAY",
|
|
|
|
|
"XDG_CURRENT_DESKTOP",
|
2024-03-03 18:47:58 +01:00
|
|
|
"XCURSOR_SIZE",
|
|
|
|
|
"XCURSOR_THEME",
|
|
|
|
|
"XDG_SESSION_TYPE",
|
|
|
|
|
"LABWC_PID",
|
|
|
|
|
NULL
|
2024-02-18 12:23:14 -05:00
|
|
|
};
|
|
|
|
|
|
2020-10-08 20:50:20 +01:00
|
|
|
static void
|
|
|
|
|
process_line(char *line)
|
|
|
|
|
{
|
2024-01-19 19:06:07 +00:00
|
|
|
if (string_null_or_empty(line) || line[0] == '#') {
|
2020-10-08 20:50:20 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2021-10-11 22:15:44 +01:00
|
|
|
char *key = NULL;
|
2020-10-08 20:50:20 +01:00
|
|
|
char *p = strchr(line, '=');
|
|
|
|
|
if (!p) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
*p = '\0';
|
2020-10-09 19:46:59 +01:00
|
|
|
key = string_strip(line);
|
2024-03-13 06:14:55 -04:00
|
|
|
if (string_null_or_empty(key)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-10-11 22:15:44 +01:00
|
|
|
|
2024-04-14 14:20:57 -04:00
|
|
|
struct buf value = BUF_INIT;
|
2021-10-11 22:15:44 +01:00
|
|
|
buf_add(&value, string_strip(++p));
|
|
|
|
|
buf_expand_shell_variables(&value);
|
2023-09-21 23:09:05 +01:00
|
|
|
buf_expand_tilde(&value);
|
2024-04-16 23:36:32 -04:00
|
|
|
setenv(key, value.data, 1);
|
2024-04-14 14:20:57 -04:00
|
|
|
buf_reset(&value);
|
2020-10-08 20:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
/* return true on successful read */
|
|
|
|
|
static bool
|
2020-10-08 20:50:20 +01:00
|
|
|
read_environment_file(const char *filename)
|
|
|
|
|
{
|
|
|
|
|
char *line = NULL;
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
FILE *stream = fopen(filename, "r");
|
|
|
|
|
if (!stream) {
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
return false;
|
2020-10-08 20:50:20 +01:00
|
|
|
}
|
2021-07-22 21:30:17 +01:00
|
|
|
wlr_log(WLR_INFO, "read environment file %s", filename);
|
2020-10-08 20:50:20 +01:00
|
|
|
while (getline(&line, &len, stream) != -1) {
|
|
|
|
|
char *p = strrchr(line, '\n');
|
|
|
|
|
if (p) {
|
|
|
|
|
*p = '\0';
|
|
|
|
|
}
|
|
|
|
|
process_line(line);
|
|
|
|
|
}
|
|
|
|
|
free(line);
|
|
|
|
|
fclose(stream);
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
return true;
|
2020-10-08 20:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
2024-03-09 12:03:30 -05:00
|
|
|
static char *
|
|
|
|
|
strdup_env_path_validate(const char *prefix, struct dirent *dirent)
|
|
|
|
|
{
|
|
|
|
|
assert(prefix);
|
|
|
|
|
|
|
|
|
|
char *full_path = strdup_printf("%s/%s", prefix, dirent->d_name);
|
|
|
|
|
if (!full_path) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Valid environment files must be regular files */
|
|
|
|
|
struct stat statbuf;
|
|
|
|
|
if (stat(full_path, &statbuf) == 0 && S_ISREG(statbuf.st_mode)) {
|
|
|
|
|
return full_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(full_path);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 07:11:18 -04:00
|
|
|
static int
|
|
|
|
|
env_file_filter(const struct dirent *dirent)
|
|
|
|
|
{
|
|
|
|
|
/* Valid environment files always end in '.env' */
|
|
|
|
|
return str_endswith(dirent->d_name, ".env");
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-09 12:03:30 -05:00
|
|
|
static bool
|
|
|
|
|
read_environment_dir(const char *path_prefix)
|
|
|
|
|
{
|
|
|
|
|
bool success = false;
|
|
|
|
|
char *path = strdup_printf("%s.d", path_prefix);
|
|
|
|
|
|
2024-04-16 07:11:18 -04:00
|
|
|
struct dirent **dirlist = NULL;
|
|
|
|
|
|
2024-03-09 12:03:30 -05:00
|
|
|
errno = 0;
|
2024-04-16 07:11:18 -04:00
|
|
|
int num_entries = scandir(path, &dirlist, env_file_filter, alphasort);
|
2024-03-09 12:03:30 -05:00
|
|
|
|
2024-04-16 07:11:18 -04:00
|
|
|
if (num_entries < 0) {
|
2024-03-09 12:03:30 -05:00
|
|
|
if (errno != ENOENT) {
|
|
|
|
|
const char *err_msg = strerror(errno);
|
|
|
|
|
wlr_log(WLR_INFO,
|
|
|
|
|
"failed to read environment directory: %s",
|
|
|
|
|
err_msg ? err_msg : "reason unknown");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
goto env_dir_cleanup;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 07:11:18 -04:00
|
|
|
for (int i = 0; i < num_entries; i++) {
|
|
|
|
|
char *env_file_path = strdup_env_path_validate(path, dirlist[i]);
|
|
|
|
|
free(dirlist[i]);
|
|
|
|
|
|
2024-03-09 12:03:30 -05:00
|
|
|
if (!env_file_path) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (read_environment_file(env_file_path)) {
|
|
|
|
|
success = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free(env_file_path);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-16 07:11:18 -04:00
|
|
|
free(dirlist);
|
2024-03-13 00:22:49 -05:00
|
|
|
|
|
|
|
|
env_dir_cleanup:
|
2024-03-09 12:03:30 -05:00
|
|
|
free(path);
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 01:06:56 +02:00
|
|
|
static void
|
2024-03-03 15:04:24 -05:00
|
|
|
backend_check_drm(struct wlr_backend *backend, void *is_drm)
|
2022-07-28 01:06:56 +02:00
|
|
|
{
|
2024-03-03 15:04:24 -05:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-28 01:06:56 +02:00
|
|
|
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;
|
|
|
|
|
}
|
2024-03-03 15:04:24 -05:00
|
|
|
|
2022-07-28 01:06:56 +02:00
|
|
|
wlr_log(WLR_INFO, "Updating dbus execution environment");
|
|
|
|
|
|
2024-02-18 12:23:14 -05:00
|
|
|
char *env_keys = str_join(env_vars, "%s", " ");
|
|
|
|
|
char *env_unset_keys = initialize ? NULL : str_join(env_vars, "%s=", " ");
|
|
|
|
|
|
|
|
|
|
char *cmd =
|
|
|
|
|
strdup_printf("dbus-update-activation-environment %s",
|
|
|
|
|
initialize ? env_keys : env_unset_keys);
|
2022-09-16 18:41:02 -04:00
|
|
|
spawn_async_no_shell(cmd);
|
|
|
|
|
free(cmd);
|
2022-07-28 01:06:56 +02:00
|
|
|
|
2024-02-18 12:23:14 -05:00
|
|
|
cmd = strdup_printf("systemctl --user %s %s",
|
|
|
|
|
initialize ? "import-environment" : "unset-environment", env_keys);
|
2022-09-16 18:41:02 -04:00
|
|
|
spawn_async_no_shell(cmd);
|
|
|
|
|
free(cmd);
|
2024-02-18 12:23:14 -05:00
|
|
|
|
|
|
|
|
free(env_keys);
|
|
|
|
|
free(env_unset_keys);
|
2022-07-28 01:06:56 +02:00
|
|
|
}
|
|
|
|
|
|
2020-10-08 20:50:20 +01:00
|
|
|
void
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
session_environment_init(void)
|
2020-10-08 20:50:20 +01:00
|
|
|
{
|
2022-07-28 01:06:56 +02:00
|
|
|
/*
|
|
|
|
|
* Set default for XDG_CURRENT_DESKTOP so xdg-desktop-portal-wlr is happy.
|
2024-01-04 19:42:26 +02:00
|
|
|
* May be overridden either by already having a value set or by the user
|
2022-07-28 01:06:56 +02:00
|
|
|
* supplied environment file.
|
|
|
|
|
*/
|
|
|
|
|
setenv("XDG_CURRENT_DESKTOP", "wlroots", 0);
|
|
|
|
|
|
2023-10-18 21:46:55 +01:00
|
|
|
/*
|
|
|
|
|
* Set default for _JAVA_AWT_WM_NONREPARENTING so that Java applications
|
|
|
|
|
* such as JetBrains/Intellij Idea do render blank windows and menus
|
|
|
|
|
* with incorrect offset. See https://github.com/swaywm/sway/issues/595
|
2024-01-04 19:42:26 +02:00
|
|
|
* May be overridden either by already having a value set or by the user
|
2023-10-18 21:46:55 +01:00
|
|
|
* supplied environment file.
|
|
|
|
|
*/
|
|
|
|
|
setenv("_JAVA_AWT_WM_NONREPARENTING", "1", 0);
|
|
|
|
|
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
struct wl_list paths;
|
|
|
|
|
paths_config_create(&paths, "environment");
|
|
|
|
|
|
|
|
|
|
bool should_merge_config = rc.merge_config;
|
|
|
|
|
struct wl_list *(*iter)(struct wl_list *list);
|
|
|
|
|
iter = should_merge_config ? paths_get_prev : paths_get_next;
|
|
|
|
|
|
|
|
|
|
for (struct wl_list *elm = iter(&paths); elm != &paths; elm = iter(elm)) {
|
|
|
|
|
struct path *path = wl_container_of(elm, path, link);
|
2024-03-09 12:03:30 -05:00
|
|
|
|
|
|
|
|
/* Process an environment file itself */
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
bool success = read_environment_file(path->string);
|
2024-03-09 12:03:30 -05:00
|
|
|
|
|
|
|
|
/* Process a correponding environment.d directory */
|
|
|
|
|
success |= read_environment_dir(path->string);
|
|
|
|
|
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
if (success && !should_merge_config) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-10-22 19:42:06 +01:00
|
|
|
}
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
paths_destroy(&paths);
|
2020-10-08 20:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-20 04:40:11 -04:00
|
|
|
void
|
|
|
|
|
session_run_script(const char *script)
|
2020-10-08 20:50:20 +01:00
|
|
|
{
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
struct wl_list paths;
|
2024-02-18 12:23:14 -05:00
|
|
|
paths_config_create(&paths, script);
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
|
|
|
|
|
bool should_merge_config = rc.merge_config;
|
|
|
|
|
struct wl_list *(*iter)(struct wl_list *list);
|
|
|
|
|
iter = should_merge_config ? paths_get_prev : paths_get_next;
|
|
|
|
|
|
|
|
|
|
for (struct wl_list *elm = iter(&paths); elm != &paths; elm = iter(elm)) {
|
|
|
|
|
struct path *path = wl_container_of(elm, path, link);
|
|
|
|
|
if (!file_exists(path->string)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-02-18 12:23:14 -05:00
|
|
|
wlr_log(WLR_INFO, "run session script %s", path->string);
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
char *cmd = strdup_printf("sh %s", path->string);
|
|
|
|
|
spawn_async_no_shell(cmd);
|
|
|
|
|
free(cmd);
|
|
|
|
|
|
|
|
|
|
if (!should_merge_config) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-10-08 20:50:20 +01:00
|
|
|
}
|
config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.
For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).
When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.
XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.
ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.
This change affects the following config/theme files:
- rc.xml
- menu.xml
- autostart
- environment
- themerc
- themerc-override
- Theme buttons, for example max.xbm
Instead of caching global config/theme directories, create lists of paths
(e.g. '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.
Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.
Avoid using stat() in most situations and just go straight to fopen().
Fixes #1406
2024-01-09 22:00:45 +00:00
|
|
|
paths_destroy(&paths);
|
2020-10-08 20:50:20 +01:00
|
|
|
}
|
2024-02-18 12:23:14 -05:00
|
|
|
|
|
|
|
|
void
|
2024-03-03 15:04:24 -05:00
|
|
|
session_autostart_init(struct server *server)
|
2024-02-18 12:23:14 -05:00
|
|
|
{
|
|
|
|
|
/* Update dbus and systemd user environment, each may fail gracefully */
|
2024-03-03 15:04:24 -05:00
|
|
|
update_activation_env(server, /* initialize */ true);
|
2024-07-20 04:40:11 -04:00
|
|
|
session_run_script("autostart");
|
2024-02-18 12:23:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2024-03-03 15:04:24 -05:00
|
|
|
session_shutdown(struct server *server)
|
2024-02-18 12:23:14 -05:00
|
|
|
{
|
2024-07-20 04:40:11 -04:00
|
|
|
session_run_script("shutdown");
|
2024-02-18 12:23:14 -05:00
|
|
|
|
|
|
|
|
/* Clear the dbus and systemd user environment, each may fail gracefully */
|
2024-03-03 15:04:24 -05:00
|
|
|
update_activation_env(server, /* initialize */ false);
|
2024-02-18 12:23:14 -05:00
|
|
|
}
|