# SYNOPSIS
-*labwc* [options...] [command]
+*labwc* [options...]
# DESCRIPTION
# OPTIONS
-*-c* <config>
- Specify a config file
+*-c* <config-file>
+ Specify a config file with path
+
+*-C* <config-directory>
+ Specify a config directory
*-d*
Enable full logging, including debug information
#include "theme.h"
struct rcxml {
+ char *config_dir;
+
/* core */
bool xdg_shell_server_side_deco;
int gap;
/**
* 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(void);
+void session_environment_init(const char *dir);
/**
* 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(void);
+void session_autostart_init(const char *dir);
#endif /* __LABWC_SESSION_H */
#include <wayland-server-core.h>
#include <wlr/util/log.h>
#include "action.h"
-#include "common/dir.h"
#include "common/nodename.h"
#include "common/string-helpers.h"
#include "common/zfree.h"
static void
rcxml_path(char *buf, size_t len)
{
- if (!strlen(config_dir())) {
+ if (!rc.config_dir) {
return;
}
- snprintf(buf, len, "%s/rc.xml", config_dir());
+ snprintf(buf, len, "%s/rc.xml", rc.config_dir);
}
static void
#include <sys/stat.h>
#include <wlr/util/log.h>
#include "common/buf.h"
-#include "common/dir.h"
#include "common/spawn.h"
#include "common/string-helpers.h"
}
static const char *
-config_dir_append(const char *append)
+build_path(const char *dir, const char *filename)
{
- const char *config = config_dir();
- if (string_empty(config) || string_empty(append)) {
+ if (string_empty(dir) || string_empty(filename)) {
return NULL;
}
- int len = strlen(config) + strlen(append) + 2;
+ int len = strlen(dir) + strlen(filename) + 2;
char *buffer = calloc(len, 1);
- strcat(buffer, config);
+ strcat(buffer, dir);
strcat(buffer, "/");
- strcat(buffer, append);
+ strcat(buffer, filename);
return buffer;
}
void
-session_environment_init(void)
+session_environment_init(const char *dir)
{
- const char *environment = config_dir_append("environment");
+ const char *environment = build_path(dir, "environment");
if (!environment) {
return;
}
}
void
-session_autostart_init(void)
+session_autostart_init(const char *dir)
{
- const char *autostart = config_dir_append("autostart");
+ const char *autostart = build_path(dir, "autostart");
if (!autostart) {
return;
}
// SPDX-License-Identifier: GPL-2.0-only
+#define _POSIX_C_SOURCE 200809L
+#include <string.h>
+#include "common/dir.h"
#include "common/font.h"
#include "common/spawn.h"
#include "config/session.h"
struct rcxml rc = { 0 };
static const char labwc_usage[] =
- "Usage: labwc [-h] [-s <command>] [-c <config-file>] [-d] [-V] [-v]\n";
+"Usage: labwc [options...]\n"
+" -c <config-file> specify config file (with path)\n"
+" -C <config-dir> specify config directory\n"
+" -d enable full logging, including debug information\n"
+" -h show help message and quit\n"
+" -s <command> run command on startup\n"
+" -v show version number and quit\n"
+" -V enable more verbose logging\n";
static void
usage(void)
enum wlr_log_importance verbosity = WLR_ERROR;
int c;
- while ((c = getopt(argc, argv, "c:dhs:vV")) != -1) {
+ while ((c = getopt(argc, argv, "c:C:dhs:vV")) != -1) {
switch (c) {
case 'c':
config_file = optarg;
break;
+ case 'C':
+ rc.config_dir = strdup(optarg);
+ break;
case 'd':
verbosity = WLR_DEBUG;
break;
wlr_log_init(verbosity, NULL);
- session_environment_init();
+ if (!rc.config_dir) {
+ rc.config_dir = config_dir();
+ }
+ wlr_log(WLR_INFO, "using config dir (%s)\n", rc.config_dir);
+ session_environment_init(rc.config_dir);
rcxml_read(config_file);
if (!getenv("XDG_RUNTIME_DIR")) {
menu_init_rootmenu(&server);
menu_init_windowmenu(&server);
- session_autostart_init();
+ session_autostart_init(rc.config_dir);
if (startup_cmd) {
spawn_async_no_shell(startup_cmd);
}
#include <strings.h>
#include <wlr/util/log.h>
#include "common/buf.h"
-#include "common/dir.h"
#include "common/font.h"
#include "common/nodename.h"
#include "common/string-helpers.h"
struct buf b;
static char menuxml[4096] = { 0 };
- if (!strlen(config_dir())) {
+ if (!rc.config_dir) {
return;
}
- snprintf(menuxml, sizeof(menuxml), "%s/%s", config_dir(), filename);
+ snprintf(menuxml, sizeof(menuxml), "%s/%s", rc.config_dir, filename);
stream = fopen(menuxml, "r");
if (!stream) {
static int
handle_sighup(int signal, void *data)
{
- session_environment_init();
+ session_environment_init(rc.config_dir);
reload_config_and_theme();
return 0;
}