mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-03-10 05:34:05 -04:00
feat: monitor arg support multi spec match in disptach
This commit is contained in:
parent
43d0f0f54a
commit
6667708d9a
3 changed files with 76 additions and 6 deletions
|
|
@ -104,4 +104,73 @@ Monitor *get_monitor_nearest_to(int32_t lx, int32_t ly) {
|
|||
|
||||
return output_from_wlr_output(
|
||||
wlr_output_layout_output_at(output_layout, closest_x, closest_y));
|
||||
}
|
||||
|
||||
bool match_monitor_spec(char *spec, Monitor *m) {
|
||||
if (!spec || !m)
|
||||
return false;
|
||||
|
||||
// if the spec does not contain a colon, treat it as a match on the monitor
|
||||
// name
|
||||
if (strchr(spec, ':') == NULL) {
|
||||
return regex_match(spec, m->wlr_output->name);
|
||||
}
|
||||
|
||||
char *spec_copy = strdup(spec);
|
||||
if (!spec_copy)
|
||||
return false;
|
||||
|
||||
char *name_rule = NULL;
|
||||
char *make_rule = NULL;
|
||||
char *model_rule = NULL;
|
||||
char *serial_rule = NULL;
|
||||
|
||||
char *token = strtok(spec_copy, "&&");
|
||||
while (token) {
|
||||
char *colon = strchr(token, ':');
|
||||
if (colon) {
|
||||
*colon = '\0';
|
||||
char *key = token;
|
||||
char *value = colon + 1;
|
||||
|
||||
if (strcmp(key, "name") == 0)
|
||||
name_rule = strdup(value);
|
||||
else if (strcmp(key, "make") == 0)
|
||||
make_rule = strdup(value);
|
||||
else if (strcmp(key, "model") == 0)
|
||||
model_rule = strdup(value);
|
||||
else if (strcmp(key, "serial") == 0)
|
||||
serial_rule = strdup(value);
|
||||
}
|
||||
token = strtok(NULL, "&&");
|
||||
}
|
||||
|
||||
bool match = true;
|
||||
|
||||
if (name_rule) {
|
||||
if (!regex_match(name_rule, m->wlr_output->name))
|
||||
match = false;
|
||||
}
|
||||
if (make_rule) {
|
||||
if (!m->wlr_output->make || strcmp(make_rule, m->wlr_output->make) != 0)
|
||||
match = false;
|
||||
}
|
||||
if (model_rule) {
|
||||
if (!m->wlr_output->model ||
|
||||
strcmp(model_rule, m->wlr_output->model) != 0)
|
||||
match = false;
|
||||
}
|
||||
if (serial_rule) {
|
||||
if (!m->wlr_output->serial ||
|
||||
strcmp(serial_rule, m->wlr_output->serial) != 0)
|
||||
match = false;
|
||||
}
|
||||
|
||||
free(spec_copy);
|
||||
free(name_rule);
|
||||
free(make_rule);
|
||||
free(model_rule);
|
||||
free(serial_rule);
|
||||
|
||||
return match;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue