opt: optimize monitorrule setting

This commit is contained in:
DreamMaoMao 2026-06-27 17:28:42 +08:00
parent b0326d710c
commit 43f3678eb6
2 changed files with 12 additions and 19 deletions

View file

@ -429,7 +429,7 @@ Config config;
bool parse_config_file(Config *config, const char *file_path, bool must_exist); bool parse_config_file(Config *config, const char *file_path, bool must_exist);
bool apply_rule_to_state(Monitor *m, const ConfigMonitorRule *rule, bool apply_rule_to_state(Monitor *m, const ConfigMonitorRule *rule,
struct wlr_output_state *state, int vrr, int custom); struct wlr_output_state *state);
bool monitor_matches_rule(Monitor *m, const ConfigMonitorRule *rule); bool monitor_matches_rule(Monitor *m, const ConfigMonitorRule *rule);
// Helper function to trim whitespace from start and end of a string // Helper function to trim whitespace from start and end of a string
@ -4062,7 +4062,7 @@ void reset_blur_params(void) {
void reapply_monitor_rules(void) { void reapply_monitor_rules(void) {
ConfigMonitorRule *mr; ConfigMonitorRule *mr;
Monitor *m = NULL; Monitor *m = NULL;
int32_t ji, vrr, custom; int32_t ji;
int32_t mx, my; int32_t mx, my;
wl_list_for_each(m, &mons, link) { wl_list_for_each(m, &mons, link) {
@ -4078,12 +4078,9 @@ void reapply_monitor_rules(void) {
if (monitor_matches_rule(m, mr)) { if (monitor_matches_rule(m, mr)) {
mx = mr->x == INT32_MAX ? m->m.x : mr->x; mx = mr->x == INT32_MAX ? m->m.x : mr->x;
my = mr->y == INT32_MAX ? m->m.y : mr->y; my = mr->y == INT32_MAX ? m->m.y : mr->y;
vrr = mr->vrr >= 0 ? mr->vrr : 0;
custom = mr->custom >= 0 ? mr->custom : 0;
m->hdr_enable = mr->hdr >= 0 ? mr->hdr : 0;
m->prefer_disable = mr->disable >= 0 ? mr->disable : 0;
(void)apply_rule_to_state(m, mr, &m->pending, vrr, custom); apply_rule_to_state(m, mr, &m->pending);
wlr_output_layout_add(output_layout, m->wlr_output, mx, my); wlr_output_layout_add(output_layout, m->wlr_output, mx, my);
break; break;
} }

View file

@ -3408,9 +3408,11 @@ bool monitor_matches_rule(Monitor *m, const ConfigMonitorRule *rule) {
/* 将规则中的显示参数应用到 wlr_output_state 中,返回是否设置了自定义模式 */ /* 将规则中的显示参数应用到 wlr_output_state 中,返回是否设置了自定义模式 */
bool apply_rule_to_state(Monitor *m, const ConfigMonitorRule *rule, bool apply_rule_to_state(Monitor *m, const ConfigMonitorRule *rule,
struct wlr_output_state *state, int vrr, int custom) { struct wlr_output_state *state) {
bool mode_set = false; bool mode_set = false;
m->vrr_global_enable = vrr; m->vrr_global_enable = rule->vrr >= 0 ? rule->vrr : 0;
m->hdr_enable = rule->hdr >= 0 ? rule->hdr : 0;
m->prefer_disable = rule->disable >= 0 ? rule->disable : 0;
if (rule->width > 0 && rule->height > 0 && rule->refresh > 0) { if (rule->width > 0 && rule->height > 0 && rule->refresh > 0) {
struct wlr_output_mode *internal_mode = get_nearest_output_mode( struct wlr_output_mode *internal_mode = get_nearest_output_mode(
@ -3418,14 +3420,14 @@ bool apply_rule_to_state(Monitor *m, const ConfigMonitorRule *rule,
if (internal_mode) { if (internal_mode) {
wlr_output_state_set_mode(state, internal_mode); wlr_output_state_set_mode(state, internal_mode);
mode_set = true; mode_set = true;
} else if (custom || wlr_output_is_headless(m->wlr_output)) { } else if (rule->custom || wlr_output_is_headless(m->wlr_output)) {
wlr_output_state_set_custom_mode( wlr_output_state_set_custom_mode(
state, rule->width, rule->height, state, rule->width, rule->height,
(int32_t)roundf(rule->refresh * 1000)); (int32_t)roundf(rule->refresh * 1000));
mode_set = true; mode_set = true;
} }
} }
if (vrr) { if (m->vrr_global_enable) {
enable_adaptive_sync(m, state); enable_adaptive_sync(m, state);
} else { } else {
disable_adaptive_sync(m, state); disable_adaptive_sync(m, state);
@ -3441,7 +3443,7 @@ void createmon(struct wl_listener *listener, void *data) {
struct wlr_output *wlr_output = data; struct wlr_output *wlr_output = data;
const ConfigMonitorRule *r; const ConfigMonitorRule *r;
uint32_t i; uint32_t i;
int32_t ji, vrr, custom; int32_t ji;
Monitor *m = NULL; Monitor *m = NULL;
bool custom_monitor_mode = false; bool custom_monitor_mode = false;
@ -3505,14 +3507,8 @@ void createmon(struct wl_listener *listener, void *data) {
if (monitor_matches_rule(m, r)) { if (monitor_matches_rule(m, r)) {
m->m.x = r->x == INT32_MAX ? INT32_MAX : r->x; m->m.x = r->x == INT32_MAX ? INT32_MAX : r->x;
m->m.y = r->y == INT32_MAX ? INT32_MAX : r->y; m->m.y = r->y == INT32_MAX ? INT32_MAX : r->y;
vrr = r->vrr >= 0 ? r->vrr : 0;
custom = r->custom >= 0 ? r->custom : 0;
scale = r->scale;
rr = r->rr;
m->hdr_enable = r->hdr;
m->prefer_disable = r->disable >= 0 ? r->disable : 0;
if (apply_rule_to_state(m, r, &m->pending, vrr, custom)) { if (apply_rule_to_state(m, r, &m->pending)) {
custom_monitor_mode = true; custom_monitor_mode = true;
} }
break; // 只应用第一个匹配规则 break; // 只应用第一个匹配规则