mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-03-10 05:34:05 -04:00
fix: avoid mutual influence of monitor rules
This commit is contained in:
parent
fd68f188c6
commit
89a4ec83a0
2 changed files with 60 additions and 123 deletions
|
|
@ -372,6 +372,9 @@ typedef int32_t (*FuncType)(const Arg *);
|
|||
Config config;
|
||||
|
||||
bool parse_config_file(Config *config, const char *file_path, bool must_exist);
|
||||
bool apply_rule_to_state(Monitor *m, const ConfigMonitorRule *rule,
|
||||
struct wlr_output_state *state, int vrr, int custom);
|
||||
bool monitor_matches_rule(Monitor *m, const ConfigMonitorRule *rule);
|
||||
|
||||
// Helper function to trim whitespace from start and end of a string
|
||||
void trim_whitespace(char *str) {
|
||||
|
|
@ -3563,14 +3566,12 @@ void reapply_monitor_rules(void) {
|
|||
int32_t ji, vrr, custom;
|
||||
int32_t mx, my;
|
||||
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) {
|
||||
if (!m->wlr_output->enabled)
|
||||
continue;
|
||||
}
|
||||
|
||||
wlr_output_state_init(&state);
|
||||
|
||||
for (ji = 0; ji < config.monitor_rules_count; ji++) {
|
||||
if (config.monitor_rules_count < 1)
|
||||
|
|
@ -3578,73 +3579,22 @@ void reapply_monitor_rules(void) {
|
|||
|
||||
mr = &config.monitor_rules[ji];
|
||||
|
||||
// 检查是否匹配的变量
|
||||
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) {
|
||||
if (monitor_matches_rule(m, mr)) {
|
||||
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;
|
||||
custom = mr->custom >= 0 ? mr->custom : 0;
|
||||
|
||||
if (mr->width > 0 && mr->height > 0 && mr->refresh > 0) {
|
||||
internal_mode = get_nearest_output_mode(
|
||||
m->wlr_output, mr->width, mr->height, mr->refresh);
|
||||
if (internal_mode) {
|
||||
wlr_output_state_set_mode(&state, internal_mode);
|
||||
} else if (custom ||
|
||||
wlr_output_is_headless(m->wlr_output)) {
|
||||
wlr_output_state_set_custom_mode(
|
||||
&state, mr->width, mr->height,
|
||||
(int32_t)roundf(mr->refresh * 1000));
|
||||
}
|
||||
}
|
||||
|
||||
if (vrr) {
|
||||
enable_adaptive_sync(m, &state);
|
||||
} else {
|
||||
wlr_output_state_set_adaptive_sync_enabled(&state, false);
|
||||
}
|
||||
|
||||
wlr_output_state_set_scale(&state, mr->scale);
|
||||
wlr_output_state_set_transform(&state, mr->rr);
|
||||
(void)apply_rule_to_state(m, mr, &state, vrr, custom);
|
||||
wlr_output_layout_add(output_layout, m->wlr_output, mx, my);
|
||||
wlr_output_commit_state(m->wlr_output, &state);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
wlr_output_commit_state(m->wlr_output, &state);
|
||||
wlr_output_state_finish(&state);
|
||||
updatemons(NULL, NULL);
|
||||
}
|
||||
updatemons(NULL, NULL);
|
||||
}
|
||||
|
||||
void reapply_cursor_style(void) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue