17#define _i3_timercmp(a, b, CMP) \
18 (((a).tv_sec == (b).tv_sec) ? ((a).tv_usec CMP(b).tv_usec) : ((a).tv_sec CMP(b).tv_sec))
27 memset(match, 0,
sizeof(
Match));
28 match->
urgent = U_DONTCHECK;
43 return (match->
title == NULL &&
44 match->
mark == NULL &&
46 match->
class == NULL &&
51 match->
urgent == U_DONTCHECK &&
52 match->
id == XCB_NONE &&
55 match->
dock == M_NODOCK &&
65 memcpy(dest, src,
sizeof(
Match));
70#define DUPLICATE_REGEX(field) \
72 if (src->field != NULL) \
73 dest->field = regex_new(src->field->pattern); \
93#define GET_FIELD_str(field) (field)
94#define GET_FIELD_i3string(field) (i3string_as_utf8(field))
95#define CHECK_WINDOW_FIELD(match_field, window_field, type) \
97 if (match->match_field != NULL) { \
98 const char *window_field_str = window->window_field == NULL \
100 : GET_FIELD_##type(window->window_field); \
101 if (strcmp(match->match_field->pattern, "__focused__") == 0 && \
102 focused && focused->window && focused->window->window_field && \
103 strcmp(window_field_str, GET_FIELD_##type(focused->window->window_field)) == 0) { \
104 LOG("window " #match_field " matches focused window\n"); \
105 } else if (regex_matches(match->match_field, window_field_str)) { \
106 LOG("window " #match_field " matches (%s)\n", window_field_str); \
116 if (match->
id != XCB_NONE) {
117 if (window->
id == match->
id) {
118 LOG(
"match made by window id (%d)\n", window->
id);
120 LOG(
"window id does not match\n");
139 if (match->
urgent == U_LATEST) {
141 if (window->
urgent.tv_sec == 0) {
146 if ((con->
window != NULL) &&
151 LOG(
"urgent matches latest\n");
154 if (match->
urgent == U_OLDEST) {
156 if (window->
urgent.tv_sec == 0) {
161 if ((con->
window != NULL) &&
167 LOG(
"urgent matches oldest\n");
182 LOG(
"workspace matches focused workspace\n");
184 LOG(
"workspace matches (%s)\n", ws->
name);
190 if (match->
dock != M_DONTCHECK) {
191 if ((window->
dock == W_DOCK_TOP && match->
dock == M_DOCK_TOP) ||
192 (window->
dock == W_DOCK_BOTTOM && match->
dock == M_DOCK_BOTTOM) ||
193 ((window->
dock == W_DOCK_TOP || window->
dock == W_DOCK_BOTTOM) &&
194 match->
dock == M_DOCK_ANY) ||
195 (window->
dock == W_NODOCK && match->
dock == M_NODOCK)) {
196 LOG(
"dock status matches\n");
198 LOG(
"dock status does not match\n");
203 if (match->
mark != NULL) {
208 bool matched =
false;
218 LOG(
"mark matches\n");
220 LOG(
"mark does not match\n");
232 if (con->
floating != FLOATING_AUTO_OFF) {
237 if (con->
floating != FLOATING_USER_OFF) {
246 case WM_FLOATING_AUTO:
247 if (con->
floating != FLOATING_AUTO_ON) {
251 case WM_FLOATING_USER:
252 if (con->
floating != FLOATING_USER_ON) {
265 LOG(
"window_mode matches\n");
296 assert(match != NULL);
297 DLOG(
"ctype=*%s*, cvalue=*%s*\n", ctype, cvalue);
299 if (strcmp(ctype,
"class") == 0) {
305 if (strcmp(ctype,
"instance") == 0) {
311 if (strcmp(ctype,
"window_role") == 0) {
317 if (strcmp(ctype,
"con_id") == 0) {
318 if (strcmp(cvalue,
"__focused__") == 0) {
325 ELOG(
"Could not parse con id \"%s\"\n", cvalue);
334 if (strcmp(ctype,
"id") == 0) {
337 ELOG(
"Could not parse window id \"%s\"\n", cvalue);
341 DLOG(
"window id as int = %d\n", match->
id);
346 if (strcmp(ctype,
"window_type") == 0) {
347 if (strcasecmp(cvalue,
"normal") == 0) {
349 }
else if (strcasecmp(cvalue,
"dialog") == 0) {
351 }
else if (strcasecmp(cvalue,
"utility") == 0) {
352 match->
window_type = A__NET_WM_WINDOW_TYPE_UTILITY;
353 }
else if (strcasecmp(cvalue,
"toolbar") == 0) {
354 match->
window_type = A__NET_WM_WINDOW_TYPE_TOOLBAR;
355 }
else if (strcasecmp(cvalue,
"splash") == 0) {
357 }
else if (strcasecmp(cvalue,
"menu") == 0) {
359 }
else if (strcasecmp(cvalue,
"dropdown_menu") == 0) {
360 match->
window_type = A__NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
361 }
else if (strcasecmp(cvalue,
"popup_menu") == 0) {
362 match->
window_type = A__NET_WM_WINDOW_TYPE_POPUP_MENU;
363 }
else if (strcasecmp(cvalue,
"tooltip") == 0) {
364 match->
window_type = A__NET_WM_WINDOW_TYPE_TOOLTIP;
365 }
else if (strcasecmp(cvalue,
"notification") == 0) {
366 match->
window_type = A__NET_WM_WINDOW_TYPE_NOTIFICATION;
368 ELOG(
"unknown window_type value \"%s\"\n", cvalue);
375 if (strcmp(ctype,
"con_mark") == 0) {
381 if (strcmp(ctype,
"title") == 0) {
387 if (strcmp(ctype,
"urgent") == 0) {
388 if (strcasecmp(cvalue,
"latest") == 0 ||
389 strcasecmp(cvalue,
"newest") == 0 ||
390 strcasecmp(cvalue,
"recent") == 0 ||
391 strcasecmp(cvalue,
"last") == 0) {
393 }
else if (strcasecmp(cvalue,
"oldest") == 0 ||
394 strcasecmp(cvalue,
"first") == 0) {
400 if (strcmp(ctype,
"workspace") == 0) {
406 if (strcmp(ctype,
"machine") == 0) {
412 if (strcmp(ctype,
"tiling") == 0) {
417 if (strcmp(ctype,
"tiling_from") == 0 &&
419 strcmp(cvalue,
"auto") == 0) {
424 if (strcmp(ctype,
"tiling_from") == 0 &&
426 strcmp(cvalue,
"user") == 0) {
431 if (strcmp(ctype,
"floating") == 0) {
436 if (strcmp(ctype,
"floating_from") == 0 &&
438 strcmp(cvalue,
"auto") == 0) {
443 if (strcmp(ctype,
"floating_from") == 0 &&
445 strcmp(cvalue,
"user") == 0) {
456 if (strcmp(ctype,
"all") == 0) {
461 ELOG(
"Unknown criterion: %s\n", ctype);
Con * con_get_workspace(Con *con)
Gets the workspace container this node is on.
Con * con_by_window_id(xcb_window_t window)
Returns the container with the given client window ID or NULL if no such container exists.
Con * con_inside_floating(Con *con)
Checks if the given container is either floating or inside some floating container.
struct pending_marks * marks
#define _i3_timercmp(a, b, CMP)
#define DUPLICATE_REGEX(field)
bool match_is_empty(Match *match)
Check if a match is empty.
void match_init(Match *match)
Initializes the Match data structure.
void match_copy(Match *dest, Match *src)
Copies the data of a match from src to dest.
void match_free(Match *match)
Frees the given match.
bool match_matches_window(Match *match, i3Window *window)
Check if a match data structure matches the given window.
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.
#define CHECK_WINDOW_FIELD(match_field, window_field, type)
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.
void regex_free(struct regex *regex)
Frees the given regular expression.
struct regex * regex_new(const char *pattern)
Creates a new 'regex' struct containing the given pattern and a PCRE compiled regular expression.
struct all_cons_head all_cons
bool parse_long(const char *str, long *out, int base)
Converts a string into a long using strtol().
char * sstrdup(const char *str)
Safe-wrapper around strdup which exits if malloc returns NULL (meaning that there is no more memory a...
#define TAILQ_FOREACH(var, head, field)
A 'Window' is a type which contains an xcb_window_t and all the related information (hints like _NET_...
struct timeval urgent
When this window was marked urgent.
enum Window::@11 dock
Whether the window says it is a dock window.
xcb_atom_t window_type
The _NET_WM_WINDOW_TYPE for this window.
A "match" is a data structure which acts like a mask or expression to match certain windows or not.
struct regex * window_role
struct regex * application
enum Match::@14 window_mode
A 'Con' represents everything from the X11 root window down to a single X11 window.
enum Con::@19 floating
floating? (= not in tiling layout) This cannot be simply a bool because we want to keep track of whet...