mirror of
				https://github.com/labwc/labwc.git
				synced 2025-10-29 05:40:24 -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 | ||||
| 
 | ||||
| *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 | ||||
|  |  | |||
|  | @ -11,6 +11,8 @@ | |||
| #include "theme.h" | ||||
| 
 | ||||
| struct rcxml { | ||||
| 	char *config_dir; | ||||
| 
 | ||||
| 	/* core */ | ||||
| 	bool xdg_shell_server_side_deco; | ||||
| 	int gap; | ||||
|  |  | |||
|  | @ -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 */ | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
|  | @ -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; | ||||
| 	} | ||||
|  |  | |||
							
								
								
									
										25
									
								
								src/main.c
									
										
									
									
									
								
							
							
						
						
									
										25
									
								
								src/main.c
									
										
									
									
									
								
							|  | @ -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" | ||||
|  | @ -10,7 +13,14 @@ | |||
| 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); | ||||
| 	} | ||||
|  |  | |||
|  | @ -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) { | ||||
|  |  | |||
|  | @ -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; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Johan Malm
						Johan Malm