mirror of
https://github.com/labwc/labwc.git
synced 2026-03-22 05:33:57 -04:00
Add command line option -C to specify config directory
Also expand usage message to explain what each option means
This commit is contained in:
parent
d0b9680d00
commit
edc5338af4
8 changed files with 47 additions and 27 deletions
|
|
@ -6,7 +6,7 @@ labwc - A Wayland stacking compositor
|
||||||
|
|
||||||
# SYNOPSIS
|
# SYNOPSIS
|
||||||
|
|
||||||
*labwc* [options...] [command]
|
*labwc* [options...]
|
||||||
|
|
||||||
# DESCRIPTION
|
# DESCRIPTION
|
||||||
|
|
||||||
|
|
@ -19,8 +19,11 @@ on.
|
||||||
|
|
||||||
# OPTIONS
|
# OPTIONS
|
||||||
|
|
||||||
*-c* <config>
|
*-c* <config-file>
|
||||||
Specify a config file
|
Specify a config file with path
|
||||||
|
|
||||||
|
*-C* <config-directory>
|
||||||
|
Specify a config directory
|
||||||
|
|
||||||
*-d*
|
*-d*
|
||||||
Enable full logging, including debug information
|
Enable full logging, including debug information
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@
|
||||||
#include "theme.h"
|
#include "theme.h"
|
||||||
|
|
||||||
struct rcxml {
|
struct rcxml {
|
||||||
|
char *config_dir;
|
||||||
|
|
||||||
/* core */
|
/* core */
|
||||||
bool xdg_shell_server_side_deco;
|
bool xdg_shell_server_side_deco;
|
||||||
int gap;
|
int gap;
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,17 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* session_environment_init - set enrivonment variables based on <key>=<value>
|
* 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
|
* pairs in `${XDG_CONFIG_DIRS:-/etc/xdg}/lawbc/environment` with user override
|
||||||
* in `${XDG_CONFIG_HOME:-$HOME/.config}`
|
* 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
|
* 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)
|
* 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 */
|
#endif /* __LABWC_SESSION_H */
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@
|
||||||
#include <wayland-server-core.h>
|
#include <wayland-server-core.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "action.h"
|
#include "action.h"
|
||||||
#include "common/dir.h"
|
|
||||||
#include "common/nodename.h"
|
#include "common/nodename.h"
|
||||||
#include "common/string-helpers.h"
|
#include "common/string-helpers.h"
|
||||||
#include "common/zfree.h"
|
#include "common/zfree.h"
|
||||||
|
|
@ -626,10 +625,10 @@ post_processing(void)
|
||||||
static void
|
static void
|
||||||
rcxml_path(char *buf, size_t len)
|
rcxml_path(char *buf, size_t len)
|
||||||
{
|
{
|
||||||
if (!strlen(config_dir())) {
|
if (!rc.config_dir) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
snprintf(buf, len, "%s/rc.xml", config_dir());
|
snprintf(buf, len, "%s/rc.xml", rc.config_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "common/buf.h"
|
#include "common/buf.h"
|
||||||
#include "common/dir.h"
|
|
||||||
#include "common/spawn.h"
|
#include "common/spawn.h"
|
||||||
#include "common/string-helpers.h"
|
#include "common/string-helpers.h"
|
||||||
|
|
||||||
|
|
@ -73,24 +72,23 @@ read_environment_file(const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
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(dir) || string_empty(filename)) {
|
||||||
if (string_empty(config) || string_empty(append)) {
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
int len = strlen(config) + strlen(append) + 2;
|
int len = strlen(dir) + strlen(filename) + 2;
|
||||||
char *buffer = calloc(len, 1);
|
char *buffer = calloc(len, 1);
|
||||||
strcat(buffer, config);
|
strcat(buffer, dir);
|
||||||
strcat(buffer, "/");
|
strcat(buffer, "/");
|
||||||
strcat(buffer, append);
|
strcat(buffer, filename);
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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) {
|
if (!environment) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -99,9 +97,9 @@ session_environment_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
if (!autostart) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
25
src/main.c
25
src/main.c
|
|
@ -1,4 +1,7 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-only
|
// 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/font.h"
|
||||||
#include "common/spawn.h"
|
#include "common/spawn.h"
|
||||||
#include "config/session.h"
|
#include "config/session.h"
|
||||||
|
|
@ -10,7 +13,14 @@
|
||||||
struct rcxml rc = { 0 };
|
struct rcxml rc = { 0 };
|
||||||
|
|
||||||
static const char labwc_usage[] =
|
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
|
static void
|
||||||
usage(void)
|
usage(void)
|
||||||
|
|
@ -27,11 +37,14 @@ main(int argc, char *argv[])
|
||||||
enum wlr_log_importance verbosity = WLR_ERROR;
|
enum wlr_log_importance verbosity = WLR_ERROR;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "c:dhs:vV")) != -1) {
|
while ((c = getopt(argc, argv, "c:C:dhs:vV")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
config_file = optarg;
|
config_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'C':
|
||||||
|
rc.config_dir = strdup(optarg);
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
verbosity = WLR_DEBUG;
|
verbosity = WLR_DEBUG;
|
||||||
break;
|
break;
|
||||||
|
|
@ -55,7 +68,11 @@ main(int argc, char *argv[])
|
||||||
|
|
||||||
wlr_log_init(verbosity, NULL);
|
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);
|
rcxml_read(config_file);
|
||||||
|
|
||||||
if (!getenv("XDG_RUNTIME_DIR")) {
|
if (!getenv("XDG_RUNTIME_DIR")) {
|
||||||
|
|
@ -75,7 +92,7 @@ main(int argc, char *argv[])
|
||||||
menu_init_rootmenu(&server);
|
menu_init_rootmenu(&server);
|
||||||
menu_init_windowmenu(&server);
|
menu_init_windowmenu(&server);
|
||||||
|
|
||||||
session_autostart_init();
|
session_autostart_init(rc.config_dir);
|
||||||
if (startup_cmd) {
|
if (startup_cmd) {
|
||||||
spawn_async_no_shell(startup_cmd);
|
spawn_async_no_shell(startup_cmd);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "common/buf.h"
|
#include "common/buf.h"
|
||||||
#include "common/dir.h"
|
|
||||||
#include "common/font.h"
|
#include "common/font.h"
|
||||||
#include "common/nodename.h"
|
#include "common/nodename.h"
|
||||||
#include "common/string-helpers.h"
|
#include "common/string-helpers.h"
|
||||||
|
|
@ -295,10 +294,10 @@ parse_xml(const char *filename, struct server *server)
|
||||||
struct buf b;
|
struct buf b;
|
||||||
static char menuxml[4096] = { 0 };
|
static char menuxml[4096] = { 0 };
|
||||||
|
|
||||||
if (!strlen(config_dir())) {
|
if (!rc.config_dir) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
snprintf(menuxml, sizeof(menuxml), "%s/%s", config_dir(), filename);
|
snprintf(menuxml, sizeof(menuxml), "%s/%s", rc.config_dir, filename);
|
||||||
|
|
||||||
stream = fopen(menuxml, "r");
|
stream = fopen(menuxml, "r");
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ reload_config_and_theme(void)
|
||||||
static int
|
static int
|
||||||
handle_sighup(int signal, void *data)
|
handle_sighup(int signal, void *data)
|
||||||
{
|
{
|
||||||
session_environment_init();
|
session_environment_init(rc.config_dir);
|
||||||
reload_config_and_theme();
|
reload_config_and_theme();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue