From 0c67b84349c9408b5dc659a5227d599f7a9ed01f Mon Sep 17 00:00:00 2001 From: Richard Grenville <pyxlcy@gmail.com> Date: Tue, 25 Sep 2012 10:19:20 +0800 Subject: Feature: Configuration file parsing - Add support for parsing configuration files using libconfig. (Dependency on libconfig could be made optional once we get some better building system.) Few tests has been done, bugs to be expected. compton searches for a configuration file mostly according to the XDG standard. Firstly the configuration file requested by --config, then $XDG_CONFIG_HOME/compton.conf (~/.config/compton.conf, usually), then ~/.compton.conf, then compton.conf under $XDG_DATA_DIRS (often /etc/xdg/compton.conf). A sample configuration file is supplied as compton.sample.conf. Configuration file syntax may change in the future. Commandline switches has higher priority than configuration file, except for --shadow-exclude. Use --config /dev/null to temporarily disable configuration file. - Fix a bug that causes windows to disappear or be partially rendered on opacity changes. - Fix a bug that causes some windows to ignore -i (inactive_opacity) and --inactive-dim, caused by the default window type change in a5d9955ca4. --- compton.h | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) (limited to 'compton.h') diff --git a/compton.h b/compton.h index c57dd2fd2..88ecbf9fc 100644 --- a/compton.h +++ b/compton.h @@ -24,6 +24,8 @@ // Whether to enable JIT support of libpcre. This may cause problems on PaX // kernels. #define CONFIG_REGEX_PCRE_JIT 1 +// Whether to enable parsing of configuration files using libconfig +#define CONFIG_LIBCONFIG 1 // === Includes === @@ -44,10 +46,16 @@ #include <locale.h> #include <fnmatch.h> + #ifdef CONFIG_REGEX_PCRE #include <pcre.h> #endif +#ifdef CONFIG_LIBCONFIG +#include <libgen.h> +#include <libconfig.h> +#endif + #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xatom.h> @@ -277,6 +285,34 @@ mstrcpy(const char *src) { return str; } +/** + * Allocate the space and join two strings. + */ +static inline char * +mstrjoin(const char *src1, const char *src2) { + char *str = malloc(sizeof(char) * (strlen(src1) + strlen(src2) + 1)); + + strcpy(str, src1); + strcat(str, src2); + + return str; +} + +/** + * Allocate the space and join two strings; + */ +static inline char * +mstrjoin3(const char *src1, const char *src2, const char *src3) { + char *str = malloc(sizeof(char) * (strlen(src1) + strlen(src2) + + strlen(src3) + 1)); + + strcpy(str, src1); + strcat(str, src2); + strcat(str, src3); + + return str; +} + /** * Normalize an int value to a specific range. * @@ -285,13 +321,29 @@ mstrcpy(const char *src) { * @param max maximum value * @return normalized value */ -static inline double +static inline int normalize_i_range(int i, int min, int max) { if (i > max) return max; if (i < min) return min; return i; } +/** + * Select the larger integer of two. + */ +static inline int +max_i(int a, int b) { + return (a > b ? a : b); +} + +/** + * Select the smaller integer of two. + */ +static inline int +min_i(int a, int b) { + return (a > b ? b : a); +} + /** * Normalize a double value to a specific range. * @@ -530,6 +582,12 @@ static Picture solid_picture(Display *dpy, Bool argb, double a, double r, double g, double b); +static inline bool is_normal_win(const win *w) { + return (WINTYPE_NORMAL == w->window_type + || WINTYPE_UTILITY == w->window_type + || WINTYPE_UNKNOWN == w->window_type); +} + static bool win_match_once(win *w, const wincond *cond); @@ -789,5 +847,16 @@ ev_handle(XEvent *ev); static void fork_after(void); +#ifdef CONFIG_LIBCONFIG +static FILE * +open_config_file(char *cpath, char **path); + +static void +parse_config(char *cpath); +#endif + +static void +get_cfg(int argc, char *const *argv); + static void get_atoms(void); -- cgit v1.2.1