i3
match.c File Reference
#include "all.h"
Include dependency graph for match.c:

Go to the source code of this file.

Macros

#define _i3_timercmp(a, b, CMP)
 
#define DUPLICATE_REGEX(field)
 
#define GET_FIELD_str(field)
 
#define GET_FIELD_i3string(field)
 
#define CHECK_WINDOW_FIELD(match_field, window_field, type)
 

Functions

void match_init (Match *match)
 Initializes the Match data structure.
 
bool match_is_empty (Match *match)
 Check if a match is empty.
 
void match_copy (Match *dest, Match *src)
 Copies the data of a match from src to dest.
 
bool match_matches_window (Match *match, i3Window *window)
 Check if a match data structure matches the given window.
 
void match_free (Match *match)
 Frees the given match.
 
void match_parse_property (Match *match, const char *ctype, const char *cvalue)
 Interprets a ctype=cvalue pair and adds it to the given match specification.
 

Macro Definition Documentation

◆ _i3_timercmp

#define _i3_timercmp ( a,
b,
CMP )
Value:
(((a).tv_sec == (b).tv_sec) ? ((a).tv_usec CMP(b).tv_usec) : ((a).tv_sec CMP(b).tv_sec))

Definition at line 17 of file match.c.

Referenced by match_matches_window().

◆ CHECK_WINDOW_FIELD

#define CHECK_WINDOW_FIELD ( match_field,
window_field,
type )
Value:
do { \
if (match->match_field != NULL) { \
const char *window_field_str = window->window_field == NULL \
? "" \
: GET_FIELD_##type(window->window_field); \
if (strcmp(match->match_field->pattern, "__focused__") == 0 && \
focused && focused->window && focused->window->window_field && \
strcmp(window_field_str, GET_FIELD_##type(focused->window->window_field)) == 0) { \
LOG("window " #match_field " matches focused window\n"); \
} else if (regex_matches(match->match_field, window_field_str)) { \
LOG("window " #match_field " matches (%s)\n", window_field_str); \
} else { \
return false; \
} \
} \
} while (0)
bool regex_matches(struct regex *regex, const char *input)
Checks if the given regular expression matches the given input and returns true if it does.
Definition regex.c:62
struct Con * focused
Definition tree.c:13
struct Window * window
Definition data.h:718

Referenced by match_matches_window().

◆ DUPLICATE_REGEX

#define DUPLICATE_REGEX ( field)
Value:
do { \
if (src->field != NULL) \
dest->field = regex_new(src->field->pattern); \
} while (0)
struct regex * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression.
Definition regex.c:22

Referenced by match_copy().

◆ GET_FIELD_i3string

#define GET_FIELD_i3string ( field)
Value:
const char * i3string_as_utf8(i3String *str)
Returns the UTF-8 encoded version of the i3String.

◆ GET_FIELD_str

#define GET_FIELD_str ( field)
Value:
(field)

Function Documentation

◆ match_copy()

void match_copy ( Match * dest,
Match * src )

Copies the data of a match from src to dest.

Definition at line 64 of file match.c.

References DUPLICATE_REGEX.

Referenced by CFGFUN(), CFGFUN(), CFGFUN(), and CFGFUN().

◆ match_free()

void match_free ( Match * match)

Frees the given match.

It must not be used afterwards!

Definition at line 279 of file match.c.

References Match::application, Match::class, Match::error, FREE, Match::instance, Match::machine, Match::mark, regex_free(), Match::title, Match::window_role, and Match::workspace.

Referenced by _remove_matches(), CFGFUN(), con_free(), free_configuration(), json_end_map(), manage_window(), and TAILQ_HEAD().

Here is the call graph for this function:

◆ match_init()

void match_init ( Match * match)

Initializes the Match data structure.

This function is necessary because the members representing boolean values (like dock) need to be initialized with -1 instead of 0.

Definition at line 26 of file match.c.

References Match::urgent, Match::window_mode, and Match::window_type.

Referenced by CFGFUN(), open_placeholder_window(), output_init_con(), and TAILQ_HEAD().

◆ match_is_empty()

bool match_is_empty ( Match * match)

Check if a match is empty.

This is necessary while parsing commands to see whether the user specified a match at all.

Definition at line 39 of file match.c.

References Match::application, Match::class, Match::con_id, Match::dock, Match::id, Match::instance, Match::machine, Match::mark, Match::match_all_windows, Match::title, Match::urgent, Match::window_mode, Match::window_role, Match::window_type, and Match::workspace.

Referenced by CFGFUN(), CFGFUN(), CFGFUN(), CFGFUN(), cmd_focus(), cmd_layout_toggle(), cmd_scratchpad_show(), and cmd_unmark().

◆ match_matches_window()

◆ match_parse_property()

void match_parse_property ( Match * match,
const char * ctype,
const char * cvalue )

Interprets a ctype=cvalue pair and adds it to the given match specification.

Definition at line 295 of file match.c.

References Match::class, Match::con_id, DLOG, ELOG, Match::error, focused, Match::id, Match::instance, Match::machine, Match::mark, Match::match_all_windows, parse_long(), regex_free(), regex_new(), sstrdup(), Match::title, Match::urgent, Match::window_mode, Match::window_role, Match::window_type, and Match::workspace.

Referenced by CFGFUN(), and cmd_criteria_add().

Here is the call graph for this function: