mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-02-15 04:27:47 -05:00
feat: support match monitor make model serial
This commit is contained in:
parent
8c0838fe3e
commit
121ff2daeb
2 changed files with 140 additions and 12 deletions
|
|
@ -99,13 +99,14 @@ typedef struct {
|
|||
} ConfigWinRule;
|
||||
|
||||
typedef struct {
|
||||
const char *name; // Monitor name
|
||||
int32_t rr; // Rotate and flip (assume integer)
|
||||
float scale; // Monitor scale factor
|
||||
int32_t x, y; // Monitor position
|
||||
int32_t width, height; // Monitor resolution
|
||||
float refresh; // Refresh rate
|
||||
int32_t vrr; // variable refresh rate
|
||||
const char *name; // Monitor name
|
||||
char *make, *model, *serial; // may be NULL
|
||||
int32_t rr; // Rotate and flip (assume integer)
|
||||
float scale; // Monitor scale factor
|
||||
int32_t x, y; // Monitor position
|
||||
int32_t width, height; // Monitor resolution
|
||||
float refresh; // Refresh rate
|
||||
int32_t vrr; // variable refresh rate
|
||||
} ConfigMonitorRule;
|
||||
|
||||
// 修改后的宏定义
|
||||
|
|
@ -155,6 +156,9 @@ typedef struct {
|
|||
int32_t id;
|
||||
char *layout_name;
|
||||
char *monitor_name;
|
||||
char *monitor_make;
|
||||
char *monitor_model;
|
||||
char *monitor_serial;
|
||||
float mfact;
|
||||
int32_t nmaster;
|
||||
int32_t no_render_border;
|
||||
|
|
@ -1707,6 +1711,9 @@ bool parse_option(Config *config, char *key, char *value) {
|
|||
|
||||
// 设置默认值
|
||||
rule->name = NULL;
|
||||
rule->make = NULL;
|
||||
rule->model = NULL;
|
||||
rule->serial = NULL;
|
||||
rule->rr = 0;
|
||||
rule->scale = 1.0f;
|
||||
rule->x = INT32_MAX;
|
||||
|
|
@ -1730,6 +1737,12 @@ bool parse_option(Config *config, char *key, char *value) {
|
|||
|
||||
if (strcmp(key, "name") == 0) {
|
||||
rule->name = strdup(val);
|
||||
} else if (strcmp(key, "make") == 0) {
|
||||
rule->make = strdup(val);
|
||||
} else if (strcmp(key, "model") == 0) {
|
||||
rule->model = strdup(val);
|
||||
} else if (strcmp(key, "serial") == 0) {
|
||||
rule->serial = strdup(val);
|
||||
} else if (strcmp(key, "rr") == 0) {
|
||||
rule->rr = CLAMP_INT(atoi(val), 0, 7);
|
||||
} else if (strcmp(key, "scale") == 0) {
|
||||
|
|
@ -1778,6 +1791,9 @@ bool parse_option(Config *config, char *key, char *value) {
|
|||
rule->id = 0;
|
||||
rule->layout_name = NULL;
|
||||
rule->monitor_name = NULL;
|
||||
rule->monitor_make = NULL;
|
||||
rule->monitor_model = NULL;
|
||||
rule->monitor_serial = NULL;
|
||||
rule->nmaster = 0;
|
||||
rule->mfact = 0.0f;
|
||||
rule->no_render_border = 0;
|
||||
|
|
@ -1801,6 +1817,12 @@ bool parse_option(Config *config, char *key, char *value) {
|
|||
rule->layout_name = strdup(val);
|
||||
} else if (strcmp(key, "monitor_name") == 0) {
|
||||
rule->monitor_name = strdup(val);
|
||||
} else if (strcmp(key, "monitor_make") == 0) {
|
||||
rule->monitor_make = strdup(val);
|
||||
} else if (strcmp(key, "monitor_model") == 0) {
|
||||
rule->monitor_model = strdup(val);
|
||||
} else if (strcmp(key, "monitor_serial") == 0) {
|
||||
rule->monitor_serial = strdup(val);
|
||||
} else if (strcmp(key, "no_render_border") == 0) {
|
||||
rule->no_render_border = CLAMP_INT(atoi(val), 0, 1);
|
||||
} else if (strcmp(key, "no_hide") == 0) {
|
||||
|
|
@ -2842,6 +2864,12 @@ void free_config(void) {
|
|||
free((void *)config.tag_rules[i].layout_name);
|
||||
if (config.tag_rules[i].monitor_name)
|
||||
free((void *)config.tag_rules[i].monitor_name);
|
||||
if (config.tag_rules[i].monitor_make)
|
||||
free((void *)config.tag_rules[i].monitor_make);
|
||||
if (config.tag_rules[i].monitor_model)
|
||||
free((void *)config.tag_rules[i].monitor_model);
|
||||
if (config.tag_rules[i].monitor_serial)
|
||||
free((void *)config.tag_rules[i].monitor_serial);
|
||||
}
|
||||
free(config.tag_rules);
|
||||
config.tag_rules = NULL;
|
||||
|
|
@ -2853,6 +2881,12 @@ void free_config(void) {
|
|||
for (int32_t i = 0; i < config.monitor_rules_count; i++) {
|
||||
if (config.monitor_rules[i].name)
|
||||
free((void *)config.monitor_rules[i].name);
|
||||
if (config.monitor_rules[i].make)
|
||||
free((void *)config.monitor_rules[i].make);
|
||||
if (config.monitor_rules[i].model)
|
||||
free((void *)config.monitor_rules[i].model);
|
||||
if (config.monitor_rules[i].serial)
|
||||
free((void *)config.monitor_rules[i].serial);
|
||||
}
|
||||
free(config.monitor_rules);
|
||||
config.monitor_rules = NULL;
|
||||
|
|
@ -3352,6 +3386,7 @@ void reapply_monitor_rules(void) {
|
|||
struct wlr_output_state state;
|
||||
struct wlr_output_mode *internal_mode = NULL;
|
||||
wlr_output_state_init(&state);
|
||||
bool match_rule = false;
|
||||
|
||||
wl_list_for_each(m, &mons, link) {
|
||||
if (!m->wlr_output->enabled) {
|
||||
|
|
@ -3363,8 +3398,40 @@ void reapply_monitor_rules(void) {
|
|||
break;
|
||||
|
||||
mr = &config.monitor_rules[ji];
|
||||
if (regex_match(mr->name, m->wlr_output->name)) {
|
||||
|
||||
// 检查是否匹配的变量
|
||||
match_rule = true;
|
||||
|
||||
// 检查四个标识字段的匹配
|
||||
if (mr->name != NULL) {
|
||||
if (!regex_match(mr->name, m->wlr_output->name)) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mr->make != NULL) {
|
||||
if (m->wlr_output->make == NULL ||
|
||||
strcmp(mr->make, m->wlr_output->make) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mr->model != NULL) {
|
||||
if (m->wlr_output->model == NULL ||
|
||||
strcmp(mr->model, m->wlr_output->model) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mr->serial != NULL) {
|
||||
if (m->wlr_output->serial == NULL ||
|
||||
strcmp(mr->serial, m->wlr_output->serial) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 只有当所有指定的标识都匹配时才应用规则
|
||||
if (match_rule) {
|
||||
mx = mr->x == INT32_MAX ? m->m.x : mr->x;
|
||||
my = mr->y == INT32_MAX ? m->m.y : mr->y;
|
||||
vrr = mr->vrr >= 0 ? mr->vrr : 0;
|
||||
|
|
@ -3498,6 +3565,7 @@ void parse_tagrule(Monitor *m) {
|
|||
int32_t i, jk;
|
||||
ConfigTagRule tr;
|
||||
Client *c = NULL;
|
||||
bool match_rule = false;
|
||||
|
||||
for (i = 0; i <= LENGTH(tags); i++) {
|
||||
m->pertag->nmasters[i] = default_nmaster;
|
||||
|
|
@ -3508,9 +3576,36 @@ void parse_tagrule(Monitor *m) {
|
|||
|
||||
tr = config.tag_rules[i];
|
||||
|
||||
if (config.tag_rules_count > 0 &&
|
||||
(!tr.monitor_name ||
|
||||
regex_match(tr.monitor_name, m->wlr_output->name))) {
|
||||
match_rule = true;
|
||||
|
||||
if (tr.monitor_name != NULL) {
|
||||
if (!regex_match(tr.monitor_name, m->wlr_output->name)) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (tr.monitor_make != NULL) {
|
||||
if (m->wlr_output->make == NULL ||
|
||||
strcmp(tr.monitor_make, m->wlr_output->make) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (tr.monitor_model != NULL) {
|
||||
if (m->wlr_output->model == NULL ||
|
||||
strcmp(tr.monitor_model, m->wlr_output->model) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (tr.monitor_serial != NULL) {
|
||||
if (m->wlr_output->serial == NULL ||
|
||||
strcmp(tr.monitor_serial, m->wlr_output->serial) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (config.tag_rules_count > 0 && match_rule) {
|
||||
|
||||
for (jk = 0; jk < LENGTH(layouts); jk++) {
|
||||
if (tr.layout_name &&
|
||||
|
|
|
|||
35
src/mango.c
35
src/mango.c
|
|
@ -2694,6 +2694,7 @@ void createmon(struct wl_listener *listener, void *data) {
|
|||
Monitor *m = NULL;
|
||||
struct wlr_output_mode *internal_mode = NULL;
|
||||
bool custom_monitor_mode = false;
|
||||
bool match_rule = false;
|
||||
|
||||
if (!wlr_output_init_render(wlr_output, alloc, drw))
|
||||
return;
|
||||
|
|
@ -2734,7 +2735,39 @@ void createmon(struct wl_listener *listener, void *data) {
|
|||
break;
|
||||
|
||||
r = &config.monitor_rules[ji];
|
||||
if (regex_match(r->name, wlr_output->name)) {
|
||||
|
||||
// 检查是否匹配的变量
|
||||
match_rule = true;
|
||||
|
||||
// 检查四个标识字段的匹配
|
||||
if (r->name != NULL) {
|
||||
if (!regex_match(r->name, m->wlr_output->name)) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (r->make != NULL) {
|
||||
if (m->wlr_output->make == NULL ||
|
||||
strcmp(r->make, m->wlr_output->make) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (r->model != NULL) {
|
||||
if (m->wlr_output->model == NULL ||
|
||||
strcmp(r->model, m->wlr_output->model) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (r->serial != NULL) {
|
||||
if (m->wlr_output->serial == NULL ||
|
||||
strcmp(r->serial, m->wlr_output->serial) != 0) {
|
||||
match_rule = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (match_rule) {
|
||||
m->m.x = r->x == INT32_MAX ? INT32_MAX : r->x;
|
||||
m->m.y = r->y == INT32_MAX ? INT32_MAX : r->y;
|
||||
vrr = r->vrr >= 0 ? r->vrr : 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue