Debian Codegraph @

src/c2.h

raw symbols SCIP
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2011-2013, Christopher Jeffrey
3 // Copyright (c) 2018 Yuxuan Shui <[email protected]>
4
5 #pragma once
6
7 #include <stdbool.h>
8 #include <stddef.h>
9 #include <xcb/xproto.h>
10
11 #include "utils/list.h"
12
13 typedef struct c2_condition c2_condition;
14 typedef struct session session_t;
15 struct c2_state;
16 /// Per-window state used for c2 condition matching.
17 struct c2_window_state {
18 /// An array of window properties. Exact how many
19 /// properties there are is stored inside `struct c2_state`.
20 struct c2_property_value *values;
21 };
22 struct atom;
23 struct win;
24 struct list_node;
25
26 typedef void (*c2_userdata_free)(void *);
27 struct c2_condition *
28 c2_parse(struct list_node *list, const char *pattern, void *data, bool *deprecated);
29
30 /// Parse a condition that has a prefix. The prefix is parsed by `parse_prefix`. If
31 /// `free_value` is not NULL, it will be called to free the value returned by
32 /// `parse_prefix` when error occurs.
33 c2_condition *
34 c2_parse_with_prefix(struct list_node *list, const char *pattern,
35 void *(*parse_prefix)(const char *input, const char **end, void *),
36 void (*free_value)(void *), void *user_data, bool *deprecated);
37
38 void c2_free_condition(c2_condition *lp, c2_userdata_free f);
39
40 /// Create a new c2_state object. This is used for maintaining the internal state
41 /// used for c2 condition matching. This state object holds a reference to the
42 /// pass atom object, thus the atom object should be kept alive as long as the
43 /// state object is alive.
44 struct c2_state *c2_state_new(struct atom *atoms);
45 void c2_state_free(struct c2_state *state);
46 /// Returns true if value of the property is used in any condition.
47 bool c2_state_is_property_tracked(struct c2_state *state, xcb_atom_t property);
48 void c2_window_state_init(const struct c2_state *state, struct c2_window_state *window_state);
49 void c2_window_state_destroy(const struct c2_state *state, struct c2_window_state *window_state);
50 void c2_window_state_mark_dirty(const struct c2_state *state,
51 struct c2_window_state *window_state, xcb_atom_t property,
52 bool is_on_client);
53 /// If a client window of a frame window changed, we need to refresh all the on-client
54 /// properties.
55 void c2_window_state_mark_dirty_for_client_change(const struct c2_state *state,
56 struct c2_window_state *window_state);
57 void c2_window_state_update(struct c2_state *state, struct c2_window_state *window_state,
58 xcb_connection_t *c, xcb_window_t client_win,
59 xcb_window_t frame_win);
60
61 bool c2_match(struct c2_state *state, const struct win *w,
62 const struct list_node *conditions, void **pdata);
63 bool c2_match_one(const struct c2_state *state, const struct win *w,
64 const c2_condition *condlst, void **pdata);
65
66 bool c2_list_postprocess(struct c2_state *state, xcb_connection_t *c, struct list_node *list);
67 /// Return user data stored in a condition.
68 void *c2_condition_get_data(const c2_condition *condition);
69 /// Set user data stored in a condition. Return the old user data.
70 void *c2_condition_set_data(c2_condition *condlist, void *data);
71 /// Convert a c2_condition to string. The returned string is only valid until the
72 /// next call to this function, and should not be freed.
73 const char *c2_condition_to_str(const c2_condition *);
74 c2_condition *c2_condition_list_next(struct list_node *list, c2_condition *condition);
75 c2_condition *c2_condition_list_prev(struct list_node *list, c2_condition *condition);
76 c2_condition *c2_condition_list_entry(struct list_node *list);
77 /// Create a new condition list with a single condition that is always true.
78 c2_condition *c2_new_true(struct list_node *list);
79
80 // NOLINTBEGIN(bugprone-macro-parentheses)
81 #define c2_condition_list_foreach(list, i) \
82 for (c2_condition *i = \
83 list_is_empty((list)) ? NULL : c2_condition_list_entry((list)->next); \
84 i; i = c2_condition_list_next(list, i))
85 #define c2_condition_list_foreach_rev(list, i) \
86 for (c2_condition *i = \
87 list_is_empty((list)) ? NULL : c2_condition_list_entry((list)->prev); \
88 i; i = c2_condition_list_prev(list, i))
89
90 #define c2_condition_list_foreach_safe(list, i, n) \
91 for (c2_condition *i = \
92 list_is_empty((list)) ? NULL : c2_condition_list_entry((list)->next), \
93 *n = c2_condition_list_next(list, i); \
94 i; i = n, n = c2_condition_list_next(list, i))
95 // NOLINTEND(bugprone-macro-parentheses)
96
97 /**
98 * Destroy a condition list.
99 */
100 static inline void c2_list_free(struct list_node *list, c2_userdata_free f) {
101 c2_condition_list_foreach_safe(list, i, ni) {
102 c2_free_condition(i, f);
103 }
104 list_init_head(list);
105 }