feat: hot reload monitor rule

This commit is contained in:
DreamMaoMao 2025-07-27 10:27:37 +08:00
parent f19790de45
commit 3c1c90cf5b
2 changed files with 49 additions and 10 deletions

View file

@ -2566,6 +2566,53 @@ void reset_blur_params(void) {
}
}
void reapply_monitor_rules(void) {
ConfigMonitorRule *mr;
Monitor *m;
int ji, jk;
struct wlr_output_state state;
wlr_output_state_init(&state);
wl_list_for_each(m, &mons, link) {
if (!m->wlr_output->enabled) {
continue;
}
for (ji = 0; ji < config.monitor_rules_count; ji++) {
if (config.monitor_rules_count < 1)
break;
mr = &config.monitor_rules[ji];
if (!mr->name || regex_match(mr->name, m->wlr_output->name)) {
m->mfact = mr->mfact;
m->nmaster = mr->nmaster;
m->m.x = mr->x;
m->m.y = mr->y;
if (mr->layout) {
for (jk = 0; jk < LENGTH(layouts); jk++) {
if (strcmp(layouts[jk].name, mr->layout) == 0) {
m->lt = &layouts[jk];
}
}
}
if (mr->width > 0 && mr->height > 0 && mr->refresh > 0) {
wlr_output_state_set_custom_mode(
&state, mr->width, mr->height, mr->refresh * 1000);
}
wlr_output_state_set_scale(&state, mr->scale);
wlr_output_state_set_transform(&state, mr->rr);
wlr_output_layout_add(output_layout, m->wlr_output, mr->x,
mr->y);
}
}
wlr_output_commit_state(m->wlr_output, &state);
wlr_output_state_finish(&state);
}
}
void reload_config(const Arg *arg) {
Client *c;
Monitor *m;
@ -2634,5 +2681,7 @@ void reload_config(const Arg *arg) {
}
}
reapply_monitor_rules();
arrange(selmon, false);
}

View file

@ -423,16 +423,6 @@ struct Monitor {
char last_surface_ws_name[256];
};
typedef struct {
const char *name;
float mfact;
int nmaster;
float scale;
const Layout *lt;
enum wl_output_transform rr;
int x, y;
} MonitorRule;
typedef struct {
struct wlr_pointer_constraint_v1 *constraint;
struct wl_listener destroy;