2018-10-03 21:14:51 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
Feature #16: Advanced window matching
- Add advanced window matching system, capable of matching against
arbitrary window properties as well as a series of internal
properties, with 4 additional operators (>, <, >=, <=) useful for
integer targets, and support of logical operators. The old matching
system is removed, but compatibility with the format is retained.
- As the new matching system is pretty complicated, and I have no past
experience in writing a parser, it's pretty possible that bugs are
present. It also has inferior performance, but I hope it doesn't
matter on modern CPUs.
- It's possible to disable matching system at compile time with NO_C2=1
now.
- Add ps->o.config_file to track which config file we have actually
read. Queryable via D-Bus.
- Parse -d in first pass in get_cfg() as c2 needs to query X to get
atoms during condition parsing.
- Fix a bug in wid_get_prop_adv() that 0 == rformat is not handled
correctly.
- Fix incompatibility with FreeBSD sed in dbus-examples/cdbus-driver.sh
.
- Add recipe to generate .clang_complete in Makefile, used by Vim
clang_complete plugin.
- Add DEBUG_C2 for debugging condition string parsing. DEBUG_WINMATCH is
still used for match debugging.
- Rename win_on_wdata_change() to win_on_factor_change().
- Extra malloc() failure checks. Add const to matching cache members in
session_t. Code clean-up. Documentation update.
2013-01-28 13:39:38 +00:00
|
|
|
/*
|
|
|
|
* Compton - a compositor for X11
|
|
|
|
*
|
|
|
|
* Based on `xcompmgr` - Copyright (c) 2003, Keith Packard
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011-2013, Christopher Jeffrey
|
2018-10-03 21:24:12 +00:00
|
|
|
* See LICENSE-mit for more information.
|
Feature #16: Advanced window matching
- Add advanced window matching system, capable of matching against
arbitrary window properties as well as a series of internal
properties, with 4 additional operators (>, <, >=, <=) useful for
integer targets, and support of logical operators. The old matching
system is removed, but compatibility with the format is retained.
- As the new matching system is pretty complicated, and I have no past
experience in writing a parser, it's pretty possible that bugs are
present. It also has inferior performance, but I hope it doesn't
matter on modern CPUs.
- It's possible to disable matching system at compile time with NO_C2=1
now.
- Add ps->o.config_file to track which config file we have actually
read. Queryable via D-Bus.
- Parse -d in first pass in get_cfg() as c2 needs to query X to get
atoms during condition parsing.
- Fix a bug in wid_get_prop_adv() that 0 == rformat is not handled
correctly.
- Fix incompatibility with FreeBSD sed in dbus-examples/cdbus-driver.sh
.
- Add recipe to generate .clang_complete in Makefile, used by Vim
clang_complete plugin.
- Add DEBUG_C2 for debugging condition string parsing. DEBUG_WINMATCH is
still used for match debugging.
- Rename win_on_wdata_change() to win_on_factor_change().
- Extra malloc() failure checks. Add const to matching cache members in
session_t. Code clean-up. Documentation update.
2013-01-28 13:39:38 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-08-22 12:26:42 +00:00
|
|
|
#pragma once
|
Feature #16: Advanced window matching
- Add advanced window matching system, capable of matching against
arbitrary window properties as well as a series of internal
properties, with 4 additional operators (>, <, >=, <=) useful for
integer targets, and support of logical operators. The old matching
system is removed, but compatibility with the format is retained.
- As the new matching system is pretty complicated, and I have no past
experience in writing a parser, it's pretty possible that bugs are
present. It also has inferior performance, but I hope it doesn't
matter on modern CPUs.
- It's possible to disable matching system at compile time with NO_C2=1
now.
- Add ps->o.config_file to track which config file we have actually
read. Queryable via D-Bus.
- Parse -d in first pass in get_cfg() as c2 needs to query X to get
atoms during condition parsing.
- Fix a bug in wid_get_prop_adv() that 0 == rformat is not handled
correctly.
- Fix incompatibility with FreeBSD sed in dbus-examples/cdbus-driver.sh
.
- Add recipe to generate .clang_complete in Makefile, used by Vim
clang_complete plugin.
- Add DEBUG_C2 for debugging condition string parsing. DEBUG_WINMATCH is
still used for match debugging.
- Rename win_on_wdata_change() to win_on_factor_change().
- Extra malloc() failure checks. Add const to matching cache members in
session_t. Code clean-up. Documentation update.
2013-01-28 13:39:38 +00:00
|
|
|
|
2018-08-22 12:26:42 +00:00
|
|
|
#include <stdbool.h>
|
2022-07-17 16:45:50 +00:00
|
|
|
#include <stddef.h>
|
2024-02-13 22:47:12 +00:00
|
|
|
#include <xcb/xproto.h>
|
Feature #16: Advanced window matching
- Add advanced window matching system, capable of matching against
arbitrary window properties as well as a series of internal
properties, with 4 additional operators (>, <, >=, <=) useful for
integer targets, and support of logical operators. The old matching
system is removed, but compatibility with the format is retained.
- As the new matching system is pretty complicated, and I have no past
experience in writing a parser, it's pretty possible that bugs are
present. It also has inferior performance, but I hope it doesn't
matter on modern CPUs.
- It's possible to disable matching system at compile time with NO_C2=1
now.
- Add ps->o.config_file to track which config file we have actually
read. Queryable via D-Bus.
- Parse -d in first pass in get_cfg() as c2 needs to query X to get
atoms during condition parsing.
- Fix a bug in wid_get_prop_adv() that 0 == rformat is not handled
correctly.
- Fix incompatibility with FreeBSD sed in dbus-examples/cdbus-driver.sh
.
- Add recipe to generate .clang_complete in Makefile, used by Vim
clang_complete plugin.
- Add DEBUG_C2 for debugging condition string parsing. DEBUG_WINMATCH is
still used for match debugging.
- Rename win_on_wdata_change() to win_on_factor_change().
- Extra malloc() failure checks. Add const to matching cache members in
session_t. Code clean-up. Documentation update.
2013-01-28 13:39:38 +00:00
|
|
|
|
2018-08-22 12:26:42 +00:00
|
|
|
typedef struct _c2_lptr c2_lptr_t;
|
|
|
|
typedef struct session session_t;
|
2024-02-13 22:47:12 +00:00
|
|
|
struct c2_state;
|
2024-02-16 12:41:16 +00:00
|
|
|
/// Per-window state used for c2 condition matching.
|
|
|
|
struct c2_window_state {
|
|
|
|
/// An array of window properties. Exact how many
|
|
|
|
/// properties there are is stored inside `struct c2_state`.
|
|
|
|
struct c2_property_value *values;
|
|
|
|
};
|
2024-02-13 22:47:12 +00:00
|
|
|
struct atom;
|
2019-04-17 22:14:45 +00:00
|
|
|
struct managed_win;
|
Feature #16: Advanced window matching
- Add advanced window matching system, capable of matching against
arbitrary window properties as well as a series of internal
properties, with 4 additional operators (>, <, >=, <=) useful for
integer targets, and support of logical operators. The old matching
system is removed, but compatibility with the format is retained.
- As the new matching system is pretty complicated, and I have no past
experience in writing a parser, it's pretty possible that bugs are
present. It also has inferior performance, but I hope it doesn't
matter on modern CPUs.
- It's possible to disable matching system at compile time with NO_C2=1
now.
- Add ps->o.config_file to track which config file we have actually
read. Queryable via D-Bus.
- Parse -d in first pass in get_cfg() as c2 needs to query X to get
atoms during condition parsing.
- Fix a bug in wid_get_prop_adv() that 0 == rformat is not handled
correctly.
- Fix incompatibility with FreeBSD sed in dbus-examples/cdbus-driver.sh
.
- Add recipe to generate .clang_complete in Makefile, used by Vim
clang_complete plugin.
- Add DEBUG_C2 for debugging condition string parsing. DEBUG_WINMATCH is
still used for match debugging.
- Rename win_on_wdata_change() to win_on_factor_change().
- Extra malloc() failure checks. Add const to matching cache members in
session_t. Code clean-up. Documentation update.
2013-01-28 13:39:38 +00:00
|
|
|
|
2022-07-17 16:49:35 +00:00
|
|
|
typedef void (*c2_userdata_free)(void *);
|
2018-12-21 16:25:28 +00:00
|
|
|
c2_lptr_t *c2_parse(c2_lptr_t **pcondlst, const char *pattern, void *data);
|
Feature #16: Advanced window matching
- Add advanced window matching system, capable of matching against
arbitrary window properties as well as a series of internal
properties, with 4 additional operators (>, <, >=, <=) useful for
integer targets, and support of logical operators. The old matching
system is removed, but compatibility with the format is retained.
- As the new matching system is pretty complicated, and I have no past
experience in writing a parser, it's pretty possible that bugs are
present. It also has inferior performance, but I hope it doesn't
matter on modern CPUs.
- It's possible to disable matching system at compile time with NO_C2=1
now.
- Add ps->o.config_file to track which config file we have actually
read. Queryable via D-Bus.
- Parse -d in first pass in get_cfg() as c2 needs to query X to get
atoms during condition parsing.
- Fix a bug in wid_get_prop_adv() that 0 == rformat is not handled
correctly.
- Fix incompatibility with FreeBSD sed in dbus-examples/cdbus-driver.sh
.
- Add recipe to generate .clang_complete in Makefile, used by Vim
clang_complete plugin.
- Add DEBUG_C2 for debugging condition string parsing. DEBUG_WINMATCH is
still used for match debugging.
- Rename win_on_wdata_change() to win_on_factor_change().
- Extra malloc() failure checks. Add const to matching cache members in
session_t. Code clean-up. Documentation update.
2013-01-28 13:39:38 +00:00
|
|
|
|
2022-07-17 16:49:35 +00:00
|
|
|
c2_lptr_t *c2_free_lptr(c2_lptr_t *lp, c2_userdata_free f);
|
Feature #16: Advanced window matching
- Add advanced window matching system, capable of matching against
arbitrary window properties as well as a series of internal
properties, with 4 additional operators (>, <, >=, <=) useful for
integer targets, and support of logical operators. The old matching
system is removed, but compatibility with the format is retained.
- As the new matching system is pretty complicated, and I have no past
experience in writing a parser, it's pretty possible that bugs are
present. It also has inferior performance, but I hope it doesn't
matter on modern CPUs.
- It's possible to disable matching system at compile time with NO_C2=1
now.
- Add ps->o.config_file to track which config file we have actually
read. Queryable via D-Bus.
- Parse -d in first pass in get_cfg() as c2 needs to query X to get
atoms during condition parsing.
- Fix a bug in wid_get_prop_adv() that 0 == rformat is not handled
correctly.
- Fix incompatibility with FreeBSD sed in dbus-examples/cdbus-driver.sh
.
- Add recipe to generate .clang_complete in Makefile, used by Vim
clang_complete plugin.
- Add DEBUG_C2 for debugging condition string parsing. DEBUG_WINMATCH is
still used for match debugging.
- Rename win_on_wdata_change() to win_on_factor_change().
- Extra malloc() failure checks. Add const to matching cache members in
session_t. Code clean-up. Documentation update.
2013-01-28 13:39:38 +00:00
|
|
|
|
2024-02-13 22:47:12 +00:00
|
|
|
/// Create a new c2_state object. This is used for maintaining the internal state
|
|
|
|
/// used for c2 condition matching. This state object holds a reference to the
|
|
|
|
/// pass atom object, thus the atom object should be kept alive as long as the
|
|
|
|
/// state object is alive.
|
|
|
|
struct c2_state *c2_state_new(struct atom *atoms);
|
|
|
|
void c2_state_free(struct c2_state *state);
|
|
|
|
/// Returns true if value of the property is used in any condition.
|
|
|
|
bool c2_state_is_property_tracked(struct c2_state *state, xcb_atom_t property);
|
2024-02-16 12:41:16 +00:00
|
|
|
void c2_window_state_init(const struct c2_state *state, struct c2_window_state *window_state);
|
|
|
|
void c2_window_state_destroy(const struct c2_state *state, struct c2_window_state *window_state);
|
|
|
|
void c2_window_state_mark_dirty(const struct c2_state *state,
|
|
|
|
struct c2_window_state *window_state, xcb_atom_t property,
|
2024-02-19 13:09:35 +00:00
|
|
|
bool is_on_client);
|
2024-02-16 12:41:16 +00:00
|
|
|
void c2_window_state_update(struct c2_state *state, struct c2_window_state *window_state,
|
|
|
|
xcb_connection_t *c, xcb_window_t client_win,
|
|
|
|
xcb_window_t frame_win);
|
2024-02-13 22:47:12 +00:00
|
|
|
|
2024-02-16 15:19:36 +00:00
|
|
|
bool c2_match(struct c2_state *state, const struct managed_win *w,
|
|
|
|
const c2_lptr_t *condlst, void **pdata);
|
2018-12-21 16:25:28 +00:00
|
|
|
|
2024-02-13 22:47:12 +00:00
|
|
|
bool c2_list_postprocess(struct c2_state *state, xcb_connection_t *c, c2_lptr_t *list);
|
2022-07-17 16:45:50 +00:00
|
|
|
typedef bool (*c2_list_foreach_cb_t)(const c2_lptr_t *cond, void *data);
|
2022-07-17 17:08:23 +00:00
|
|
|
bool c2_list_foreach(const c2_lptr_t *list, c2_list_foreach_cb_t cb, void *data);
|
2022-07-17 16:45:50 +00:00
|
|
|
/// Return user data stored in a condition.
|
|
|
|
void *c2_list_get_data(const c2_lptr_t *condlist);
|
2024-02-20 00:34:26 +00:00
|
|
|
/// Convert a c2_lptr_t to string. The returned string is only valid until the
|
|
|
|
/// next call to this function, and should not be freed.
|
|
|
|
const char *c2_lptr_to_str(const c2_lptr_t *);
|
2022-07-17 16:45:50 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy a condition list.
|
|
|
|
*/
|
2022-07-17 16:49:35 +00:00
|
|
|
static inline void c2_list_free(c2_lptr_t **pcondlst, c2_userdata_free f) {
|
|
|
|
while ((*pcondlst = c2_free_lptr(*pcondlst, f))) {
|
2022-07-17 16:45:50 +00:00
|
|
|
}
|
|
|
|
*pcondlst = NULL;
|
|
|
|
}
|