feat: add tag rule option open_as_floating

This commit is contained in:
DreamMaoMao 2026-03-18 23:10:15 +08:00
parent 833d8a2ef1
commit 6c81384c53
3 changed files with 37 additions and 18 deletions

View file

@ -168,6 +168,7 @@ typedef struct {
float mfact; float mfact;
int32_t nmaster; int32_t nmaster;
int32_t no_render_border; int32_t no_render_border;
int32_t open_as_floating;
int32_t no_hide; int32_t no_hide;
} ConfigTagRule; } ConfigTagRule;
@ -1904,6 +1905,7 @@ bool parse_option(Config *config, char *key, char *value) {
rule->nmaster = 0; rule->nmaster = 0;
rule->mfact = 0.0f; rule->mfact = 0.0f;
rule->no_render_border = 0; rule->no_render_border = 0;
rule->open_as_floating = 0;
rule->no_hide = 0; rule->no_hide = 0;
bool parse_error = false; bool parse_error = false;
@ -1932,6 +1934,8 @@ bool parse_option(Config *config, char *key, char *value) {
rule->monitor_serial = strdup(val); rule->monitor_serial = strdup(val);
} else if (strcmp(key, "no_render_border") == 0) { } else if (strcmp(key, "no_render_border") == 0) {
rule->no_render_border = CLAMP_INT(atoi(val), 0, 1); rule->no_render_border = CLAMP_INT(atoi(val), 0, 1);
} else if (strcmp(key, "open_as_floating") == 0) {
rule->open_as_floating = CLAMP_INT(atoi(val), 0, 1);
} else if (strcmp(key, "no_hide") == 0) { } else if (strcmp(key, "no_hide") == 0) {
rule->no_hide = CLAMP_INT(atoi(val), 0, 1); rule->no_hide = CLAMP_INT(atoi(val), 0, 1);
} else if (strcmp(key, "nmaster") == 0) { } else if (strcmp(key, "nmaster") == 0) {
@ -3785,6 +3789,8 @@ void parse_tagrule(Monitor *m) {
m->pertag->mfacts[tr.id] = tr.mfact; m->pertag->mfacts[tr.id] = tr.mfact;
if (tr.no_render_border >= 0) if (tr.no_render_border >= 0)
m->pertag->no_render_border[tr.id] = tr.no_render_border; m->pertag->no_render_border[tr.id] = tr.no_render_border;
if (tr.open_as_floating >= 0)
m->pertag->open_as_floating[tr.id] = tr.open_as_floating;
} }
} }

View file

@ -1,15 +1,12 @@
bool check_hit_no_border(Client *c) { bool check_hit_no_border(Client *c) {
int32_t i;
bool hit_no_border = false; bool hit_no_border = false;
if (!render_border) { if (!render_border) {
hit_no_border = true; hit_no_border = true;
} }
for (i = 0; i < config.tag_rules_count; i++) { if (c->mon && !c->mon->isoverview &&
if (c->tags & (1 << (config.tag_rules[i].id - 1)) && c->mon->pertag->no_render_border[get_tags_first_tag_num(c->tags) + 1]) {
config.tag_rules[i].no_render_border) { hit_no_border = true;
hit_no_border = true;
}
} }
if (config.no_border_when_single && c && c->mon && if (config.no_border_when_single && c && c->mon &&
@ -19,6 +16,7 @@ bool check_hit_no_border(Client *c) {
} }
return hit_no_border; return hit_no_border;
} }
Client *termforwin(Client *w) { Client *termforwin(Client *w) {
Client *c = NULL; Client *c = NULL;

View file

@ -933,8 +933,9 @@ struct Pertag {
uint32_t curtag, prevtag; /* current and previous tag */ uint32_t curtag, prevtag; /* current and previous tag */
int32_t nmasters[LENGTH(tags) + 1]; /* number of windows in master area */ int32_t nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */ float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
bool no_hide[LENGTH(tags) + 1]; /* no_hide per tag */ int32_t no_hide[LENGTH(tags) + 1]; /* no_hide per tag */
bool no_render_border[LENGTH(tags) + 1]; /* no_render_border per tag */ int32_t no_render_border[LENGTH(tags) + 1]; /* no_render_border per tag */
int32_t open_as_floating[LENGTH(tags) + 1]; /* open_as_floating per tag */
const Layout const Layout
*ltidxs[LENGTH(tags) + 1]; /* matrix of tags and layouts indexes */ *ltidxs[LENGTH(tags) + 1]; /* matrix of tags and layouts indexes */
}; };
@ -1402,6 +1403,25 @@ void set_float_malposition(Client *tc) {
tc->float_geom.y = tc->geom.y = y; tc->float_geom.y = tc->geom.y = y;
} }
void client_reset_mon_tags(Client *c, Monitor *mon, uint32_t newtags) {
if (!newtags && mon && !mon->isoverview) {
c->tags = mon->tagset[mon->seltags];
} else if (!newtags && mon && mon->isoverview) {
c->tags = mon->ovbk_current_tagset;
} else if (newtags) {
c->tags = newtags;
} else {
c->tags = mon->tagset[mon->seltags];
}
}
void check_match_tag_floating_rule(Client *c, Monitor *mon) {
if (c->tags && !c->isfloating && mon && !c->swallowedby &&
mon->pertag->open_as_floating[get_tags_first_tag_num(c->tags) + 1]) {
c->isfloating = 1;
}
}
void applyrules(Client *c) { void applyrules(Client *c) {
/* rule matching */ /* rule matching */
const char *appid, *title; const char *appid, *title;
@ -1526,6 +1546,7 @@ void applyrules(Client *c) {
int32_t fullscreen_state_backup = int32_t fullscreen_state_backup =
c->isfullscreen || client_wants_fullscreen(c); c->isfullscreen || client_wants_fullscreen(c);
setmon(c, mon, newtags, setmon(c, mon, newtags,
!c->isopensilent && !c->isopensilent &&
!(client_is_x11_popup(c) && client_should_ignore_focus(c)) && !(client_is_x11_popup(c) && client_should_ignore_focus(c)) &&
@ -5062,7 +5083,8 @@ setfloating(Client *c, int32_t floating) {
// 让当前tag中的全屏窗口退出全屏参与平铺 // 让当前tag中的全屏窗口退出全屏参与平铺
wl_list_for_each(fc, &clients, wl_list_for_each(fc, &clients,
link) if (fc && fc != c && VISIBLEON(fc, c->mon) && link) if (fc && fc != c && VISIBLEON(fc, c->mon) &&
c->tags & fc->tags && ISFULLSCREEN(fc)) { c->tags & fc->tags && ISFULLSCREEN(fc) &&
old_floating_state) {
clear_fullscreen_flag(fc); clear_fullscreen_flag(fc);
} }
} }
@ -5375,15 +5397,8 @@ void setmon(Client *c, Monitor *m, uint32_t newtags, bool focus) {
/* Make sure window actually overlaps with the monitor */ /* Make sure window actually overlaps with the monitor */
reset_foreign_tolevel(c); reset_foreign_tolevel(c);
resize(c, c->geom, 0); resize(c, c->geom, 0);
if (!newtags && !m->isoverview) { client_reset_mon_tags(c, m, newtags);
c->tags = m->tagset[m->seltags]; check_match_tag_floating_rule(c, m);
} else if (!newtags && m->isoverview) {
c->tags = m->ovbk_current_tagset;
} else if (newtags) {
c->tags = newtags;
} else {
c->tags = m->tagset[m->seltags];
}
setfloating(c, c->isfloating); setfloating(c, c->isfloating);
setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */ setfullscreen(c, c->isfullscreen); /* This will call arrange(c->mon) */
} }