From 4940a93f03e29a54624236b27ccc5f2a5d3681f9 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Wed, 22 Aug 2018 13:26:42 +0100 Subject: [PATCH] c2.h cleanup Move most of the static functions into c2.c itself, and only keep the public functions in c2.h --- src/c2.c | 343 ++++++++++++++++++++++++++++++++++++++++++++++++ src/c2.h | 353 +++----------------------------------------------- src/common.h | 47 ++----- src/compton.h | 5 +- src/config.c | 1 + 5 files changed, 375 insertions(+), 374 deletions(-) diff --git a/src/c2.c b/src/c2.c index 6baf133..2ea045e 100644 --- a/src/c2.c +++ b/src/c2.c @@ -8,8 +8,351 @@ * */ +#include +#include + +// libpcre +#ifdef CONFIG_REGEX_PCRE +#include + +// For compatiblity with opr1 = p1; + p.b->opr2 = p2; + p.b->op = op; + + return p; +} + +/** + * Get the precedence value of a condition branch operator. + */ +static inline int +c2h_b_opp(c2_b_op_t op) { + switch (op) { + case C2_B_OAND: return 2; + case C2_B_OOR: return 1; + case C2_B_OXOR: return 1; + default: break; + } + + assert(0); + return 0; +} + +/** + * Compare precedence of two condition branch operators. + * + * Associativity is left-to-right, forever. + * + * @return positive number if op1 > op2, 0 if op1 == op2 in precedence, + * negative number otherwise + */ +static inline int +c2h_b_opcmp(c2_b_op_t op1, c2_b_op_t op2) { + return c2h_b_opp(op1) - c2h_b_opp(op2); +} + +static int +c2_parse_grp(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult, int level); + +static int +c2_parse_target(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult); + +static int +c2_parse_op(const char *pattern, int offset, c2_ptr_t *presult); + +static int +c2_parse_pattern(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult); + +static int +c2_parse_legacy(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult); + +static bool +c2_l_postprocess(session_t *ps, c2_l_t *pleaf); + +static void +c2_free(c2_ptr_t p); + +/** + * Wrapper of c2_free(). + */ +static inline void +c2_freep(c2_ptr_t *pp) { + if (pp) { + c2_free(*pp); + c2_ptr_reset(pp); + } +} + +static const char * +c2h_dump_str_tgt(const c2_l_t *pleaf); + +static const char * +c2h_dump_str_type(const c2_l_t *pleaf); + +static void +c2_dump_raw(c2_ptr_t p); + +/** + * Wrapper of c2_dump_raw(). + */ +static inline void __attribute__((unused)) +c2_dump(c2_ptr_t p) { + c2_dump_raw(p); + printf("\n"); + fflush(stdout); +} + +static Atom +c2_get_atom_type(const c2_l_t *pleaf); + +static bool +c2_match_once(session_t *ps, win *w, const c2_ptr_t cond); + /** * Parse a condition string. */ diff --git a/src/c2.h b/src/c2.h index e9aaf8b..0f8ad02 100644 --- a/src/c2.h +++ b/src/c2.h @@ -8,347 +8,26 @@ * */ -#include "common.h" +#pragma once -#include -#include +#include -// libpcre -#ifdef CONFIG_REGEX_PCRE -#include +typedef struct _c2_lptr c2_lptr_t; +typedef struct session session_t; +typedef struct win win; -// For compatiblity with opr1 = p1; - p.b->opr2 = p2; - p.b->op = op; - - return p; -} - -/** - * Get the precedence value of a condition branch operator. - */ -static inline int -c2h_b_opp(c2_b_op_t op) { - switch (op) { - case C2_B_OAND: return 2; - case C2_B_OOR: return 1; - case C2_B_OXOR: return 1; - default: break; - } - - assert(0); - return 0; -} - -/** - * Compare precedence of two condition branch operators. - * - * Associativity is left-to-right, forever. - * - * @return positive number if op1 > op2, 0 if op1 == op2 in precedence, - * negative number otherwise - */ -static inline int -c2h_b_opcmp(c2_b_op_t op1, c2_b_op_t op2) { - return c2h_b_opp(op1) - c2h_b_opp(op2); -} - -static int -c2_parse_grp(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult, int level); - -static int -c2_parse_target(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult); - -static int -c2_parse_op(const char *pattern, int offset, c2_ptr_t *presult); - -static int -c2_parse_pattern(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult); - -static int -c2_parse_legacy(session_t *ps, const char *pattern, int offset, c2_ptr_t *presult); - -static bool -c2_l_postprocess(session_t *ps, c2_l_t *pleaf); - -static void -c2_free(c2_ptr_t p); - -/** - * Wrapper of c2_free(). - */ -static inline void -c2_freep(c2_ptr_t *pp) { - if (pp) { - c2_free(*pp); - c2_ptr_reset(pp); - } -} - -static const char * -c2h_dump_str_tgt(const c2_l_t *pleaf); - -static const char * -c2h_dump_str_type(const c2_l_t *pleaf); - -static void -c2_dump_raw(c2_ptr_t p); - -/** - * Wrapper of c2_dump_raw(). - */ -static inline void -c2_dump(c2_ptr_t p) { - c2_dump_raw(p); - printf("\n"); - fflush(stdout); -} - -static Atom -c2_get_atom_type(const c2_l_t *pleaf); - -static bool -c2_match_once(session_t *ps, win *w, const c2_ptr_t cond); +bool +c2_matchd(session_t *ps, win *w, const c2_lptr_t *condlst, + const c2_lptr_t **cache, void **pdata); +#define c2_match(ps, w, condlst, cache) c2_matchd((ps), (w), (condlst), \ + (cache), NULL) diff --git a/src/common.h b/src/common.h index 3641f63..2179b92 100644 --- a/src/common.h +++ b/src/common.h @@ -227,6 +227,7 @@ typedef uint32_t opacity_t; typedef long time_ms_t; +typedef struct _c2_lptr c2_lptr_t; typedef enum { WINTYPE_UNKNOWN, @@ -519,9 +520,7 @@ typedef struct { struct _timeout_t; -struct _win; - -typedef struct _c2_lptr c2_lptr_t; +typedef struct win win; /// Structure representing all options. typedef struct _options_t { @@ -787,7 +786,7 @@ typedef struct { #endif /// Structure containing all necessary data for a compton session. -typedef struct _session_t { +typedef struct session { // === Display related === /// Display in use. Display *dpy; @@ -888,13 +887,13 @@ typedef struct _session_t { // === Window related === /// Linked list of all windows. - struct _win *list; + win *list; /// Pointer to win of current active window. Used by /// EWMH _NET_ACTIVE_WINDOW focus detection. In theory, /// it's more reliable to store the window ID directly here, just in /// case the WM does something extraordinary, but caching the pointer /// means another layer of complexity. - struct _win *active_win; + win *active_win; /// Window ID of leader window of currently active window. Used for /// subsidiary window detection. Window active_leader; @@ -1038,11 +1037,11 @@ typedef struct _session_t { } session_t; /// Structure representing a top-level window compton manages. -typedef struct _win { +struct win { /// Pointer to the next structure in the linked list. - struct _win *next; + win *next; /// Pointer to the next higher window to paint. - struct _win *prev_trans; + win *prev_trans; // Core members /// ID of the top-level frame window. @@ -1164,7 +1163,7 @@ typedef struct _win { /// Override value of window fade state. Set by D-Bus method calls. switch_t fade_force; /// Callback to be called after fading completed. - void (*fade_callback) (session_t *ps, struct _win *w); + void (*fade_callback) (session_t *ps, win *w); // Frame-opacity-related members /// Current window frame opacity. Affected by window opacity. @@ -1216,7 +1215,7 @@ typedef struct _win { /// Textures and FBO background blur use. glx_blur_cache_t glx_blur_cache; #endif -} win; +}; /// Temporary structure used for communication between /// get_cfg() and parse_config(). @@ -1879,7 +1878,7 @@ find_win(session_t *ps, Window id) { * Find out the WM frame of a client window using existing data. * * @param id window ID - * @return struct _win object of the found window, NULL if not found + * @return struct win object of the found window, NULL if not found */ static inline win * find_toplevel(session_t *ps, Window id) { @@ -1936,7 +1935,7 @@ win_is_focused_real(session_t *ps, const win *w) { /** * Find out the currently focused window. * - * @return struct _win object of the found window, NULL if not found + * @return struct win object of the found window, NULL if not found */ static inline win * find_focused(session_t *ps) { @@ -2466,28 +2465,6 @@ opts_set_no_fading_openclose(session_t *ps, bool newval); //!@} #endif -/** @name c2 - */ -///@{ - -c2_lptr_t * -c2_parsed(session_t *ps, c2_lptr_t **pcondlst, const char *pattern, - void *data); - -#define c2_parse(ps, pcondlst, pattern) c2_parsed((ps), (pcondlst), (pattern), NULL) - -c2_lptr_t * -c2_free_lptr(c2_lptr_t *lp); - -bool -c2_matchd(session_t *ps, win *w, const c2_lptr_t *condlst, - const c2_lptr_t **cache, void **pdata); - -#define c2_match(ps, w, condlst, cache) c2_matchd((ps), (w), (condlst), \ - (cache), NULL) - -///@} - /** * @brief Dump the given data to a file. */ diff --git a/src/compton.h b/src/compton.h index 5ad6c30..4e03058 100644 --- a/src/compton.h +++ b/src/compton.h @@ -7,8 +7,6 @@ // === Includes === -#include "common.h" - #include #include #include @@ -27,6 +25,9 @@ #include #endif +#include "common.h" +#include "c2.h" + // == Functions == // inline functions must be made static to compile correctly under clang: diff --git a/src/config.c b/src/config.c index 5e297c0..1611404 100644 --- a/src/config.c +++ b/src/config.c @@ -3,6 +3,7 @@ #include "common.h" #include "config.h" +#include "c2.h" /** * Parse a long number.