]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add command line option -C to specify config directory
authorJohan Malm <jgm323@gmail.com>
Fri, 22 Apr 2022 16:00:36 +0000 (17:00 +0100)
committerJohan Malm <jgm323@gmail.com>
Fri, 22 Apr 2022 16:00:36 +0000 (17:00 +0100)
Also expand usage message to explain what each option means

docs/labwc.1.scd
include/config/rcxml.h
include/config/session.h
src/config/rcxml.c
src/config/session.c
src/main.c
src/menu/menu.c
src/server.c

index 248844e5f9d7d8affea6b547473a5c79e9677d3c..6b2993c3531546597dc3489c7532dd0fe1a3223b 100644 (file)
@@ -6,7 +6,7 @@ labwc - A Wayland stacking compositor
 
 # SYNOPSIS
 
-*labwc*  [options...] [command]
+*labwc*  [options...]
 
 # DESCRIPTION
 
@@ -19,8 +19,11 @@ on.
 
 # 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
index 25910549eed7f8705cac73903487e245ab83598f..99a2be461308efa60aad6f5179cecb4558ae3ef0 100644 (file)
@@ -11,6 +11,8 @@
 #include "theme.h"
 
 struct rcxml {
+       char *config_dir;
+
        /* core */
        bool xdg_shell_server_side_deco;
        int gap;
index 674b6f76ef6cfef1138518f46b82ab8dd459a20b..e6534539e4cbafb4667b70319b7c0b12df2791af 100644 (file)
@@ -4,15 +4,17 @@
 
 /**
  * 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 */
index b5d2921cefa1f1f77cc2e56e72a461bf8243e302..894ca5fa610f600cabe0061fa61bed11b7df35e1 100644 (file)
@@ -14,7 +14,6 @@
 #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"
@@ -626,10 +625,10 @@ post_processing(void)
 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
index 880eaeae774db5543655a21c9cabfdd0cb255e7f..39e23f12849dd3e9dcaa9742ecefeb8a493cd7ad 100644 (file)
@@ -8,7 +8,6 @@
 #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"
 
@@ -73,24 +72,23 @@ read_environment_file(const char *filename)
 }
 
 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;
        }
@@ -99,9 +97,9 @@ session_environment_init(void)
 }
 
 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;
        }
index 9a486397cf96e31bb92f57514c28b2539df5cfbd..3ee2b6efd7acd1e040b5bc5d5b98f79b3af28223 100644 (file)
@@ -1,4 +1,7 @@
 // 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)
@@ -27,11 +37,14 @@ main(int argc, char *argv[])
        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;
@@ -55,7 +68,11 @@ main(int argc, char *argv[])
 
        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")) {
@@ -75,7 +92,7 @@ main(int argc, char *argv[])
        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);
        }
index c74b8daa4f6a09032669f2a186fd7a50d1e5c78c..b23fcbcb43541fcd6368e16903bb27ee87f08021 100644 (file)
@@ -10,7 +10,6 @@
 #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"
@@ -295,10 +294,10 @@ parse_xml(const char *filename, struct server *server)
        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) {
index d9deb251f5c4715f2ae3fbad5f5f93c41e344384..ca7d92dfef32324f156d7cf5b9ab32c3c4c158b7 100644 (file)
@@ -51,7 +51,7 @@ reload_config_and_theme(void)
 static int
 handle_sighup(int signal, void *data)
 {
-       session_environment_init();
+       session_environment_init(rc.config_dir);
        reload_config_and_theme();
        return 0;
 }