mirror of
https://github.com/swaywm/sway.git
synced 2026-04-28 06:46:26 -04:00
parent
cf1ed777ae
commit
7b530bf448
63 changed files with 463 additions and 644 deletions
|
|
@ -3,8 +3,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <strings.h>
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#include <pcre2.h>
|
||||
#include <pcre.h>
|
||||
#include "sway/criteria.h"
|
||||
#include "sway/tree/container.h"
|
||||
#include "sway/config.h"
|
||||
|
|
@ -41,19 +40,17 @@ bool criteria_is_empty(struct criteria *criteria) {
|
|||
char *error = NULL;
|
||||
|
||||
// Returns error string on failure or NULL otherwise.
|
||||
static bool generate_regex(pcre2_code **regex, char *value) {
|
||||
int errorcode;
|
||||
PCRE2_SIZE offset;
|
||||
static bool generate_regex(pcre **regex, char *value) {
|
||||
const char *reg_err;
|
||||
int offset;
|
||||
|
||||
*regex = pcre_compile(value, PCRE_UTF8 | PCRE_UCP, ®_err, &offset, NULL);
|
||||
|
||||
*regex = pcre2_compile((PCRE2_SPTR)value, PCRE2_ZERO_TERMINATED, PCRE2_UTF | PCRE2_UCP, &errorcode, &offset, NULL);
|
||||
if (!*regex) {
|
||||
PCRE2_UCHAR buffer[256];
|
||||
pcre2_get_error_message(errorcode, buffer, sizeof(buffer));
|
||||
|
||||
const char *fmt = "Regex compilation for '%s' failed: %s";
|
||||
int len = strlen(fmt) + strlen(value) + strlen((char*) buffer) - 3;
|
||||
int len = strlen(fmt) + strlen(value) + strlen(reg_err) - 3;
|
||||
error = malloc(len);
|
||||
snprintf(error, len, fmt, value, buffer);
|
||||
snprintf(error, len, fmt, value, reg_err);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +66,7 @@ static bool pattern_create(struct pattern **pattern, char *value) {
|
|||
if (strcmp(value, "__focused__") == 0) {
|
||||
(*pattern)->match_type = PATTERN_FOCUSED;
|
||||
} else {
|
||||
(*pattern)->match_type = PATTERN_PCRE2;
|
||||
(*pattern)->match_type = PATTERN_PCRE;
|
||||
if (!generate_regex(&(*pattern)->regex, value)) {
|
||||
return false;
|
||||
};
|
||||
|
|
@ -80,7 +77,7 @@ static bool pattern_create(struct pattern **pattern, char *value) {
|
|||
static void pattern_destroy(struct pattern *pattern) {
|
||||
if (pattern) {
|
||||
if (pattern->regex) {
|
||||
pcre2_code_free(pattern->regex);
|
||||
pcre_free(pattern->regex);
|
||||
}
|
||||
free(pattern);
|
||||
}
|
||||
|
|
@ -102,11 +99,8 @@ void criteria_destroy(struct criteria *criteria) {
|
|||
free(criteria);
|
||||
}
|
||||
|
||||
static int regex_cmp(const char *item, const pcre2_code *regex) {
|
||||
pcre2_match_data *match_data = pcre2_match_data_create_from_pattern(regex, NULL);
|
||||
int result = pcre2_match(regex, (PCRE2_SPTR)item, strlen(item), 0, 0, match_data, NULL);
|
||||
pcre2_match_data_free(match_data);
|
||||
return result;
|
||||
static int regex_cmp(const char *item, const pcre *regex) {
|
||||
return pcre_exec(regex, NULL, item, strlen(item), 0, 0, NULL, 0);
|
||||
}
|
||||
|
||||
#if HAVE_XWAYLAND
|
||||
|
|
@ -161,7 +155,7 @@ static bool criteria_matches_container(struct criteria *criteria,
|
|||
bool exists = false;
|
||||
struct sway_container *con = container;
|
||||
for (int i = 0; i < con->marks->length; ++i) {
|
||||
if (regex_cmp(con->marks->items[i], criteria->con_mark->regex) >= 0) {
|
||||
if (regex_cmp(con->marks->items[i], criteria->con_mark->regex) == 0) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -198,8 +192,8 @@ static bool criteria_matches_view(struct criteria *criteria,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case PATTERN_PCRE2:
|
||||
if (regex_cmp(title, criteria->title->regex) < 0) {
|
||||
case PATTERN_PCRE:
|
||||
if (regex_cmp(title, criteria->title->regex) != 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -218,8 +212,8 @@ static bool criteria_matches_view(struct criteria *criteria,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case PATTERN_PCRE2:
|
||||
if (regex_cmp(shell, criteria->shell->regex) < 0) {
|
||||
case PATTERN_PCRE:
|
||||
if (regex_cmp(shell, criteria->shell->regex) != 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -238,8 +232,8 @@ static bool criteria_matches_view(struct criteria *criteria,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case PATTERN_PCRE2:
|
||||
if (regex_cmp(app_id, criteria->app_id->regex) < 0) {
|
||||
case PATTERN_PCRE:
|
||||
if (regex_cmp(app_id, criteria->app_id->regex) != 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -270,8 +264,8 @@ static bool criteria_matches_view(struct criteria *criteria,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case PATTERN_PCRE2:
|
||||
if (regex_cmp(class, criteria->class->regex) < 0) {
|
||||
case PATTERN_PCRE:
|
||||
if (regex_cmp(class, criteria->class->regex) != 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -290,8 +284,8 @@ static bool criteria_matches_view(struct criteria *criteria,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case PATTERN_PCRE2:
|
||||
if (regex_cmp(instance, criteria->instance->regex) < 0) {
|
||||
case PATTERN_PCRE:
|
||||
if (regex_cmp(instance, criteria->instance->regex) != 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -310,8 +304,8 @@ static bool criteria_matches_view(struct criteria *criteria,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case PATTERN_PCRE2:
|
||||
if (regex_cmp(window_role, criteria->window_role->regex) < 0) {
|
||||
case PATTERN_PCRE:
|
||||
if (regex_cmp(window_role, criteria->window_role->regex) != 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -369,8 +363,8 @@ static bool criteria_matches_view(struct criteria *criteria,
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case PATTERN_PCRE2:
|
||||
if (regex_cmp(ws->name, criteria->workspace->regex) < 0) {
|
||||
case PATTERN_PCRE:
|
||||
if (regex_cmp(ws->name, criteria->workspace->regex) != 0) {
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue