opt: optimize code struct

This commit is contained in:
DreamMaoMao 2025-07-18 13:12:05 +08:00
parent 59c9bbbc90
commit f8403ea7ff

View file

@ -114,17 +114,17 @@
wl_signal_add((E), _l); \ wl_signal_add((E), _l); \
} while (0) } while (0)
#define APPLY_INT_PROP(prop) \ #define APPLY_INT_PROP(obj, rule, prop) \
if (r->prop >= 0) \ if (rule->prop >= 0) \
c->prop = r->prop obj->prop = rule->prop
#define APPLY_FLOAT_PROP(prop) \ #define APPLY_FLOAT_PROP(obj, rule, prop) \
if (r->prop > 0.0f) \ if (rule->prop > 0.0f) \
c->prop = r->prop obj->prop = rule->prop
#define APPLY_STRING_PROP(prop) \ #define APPLY_STRING_PROP(obj, rule, prop) \
if (r->prop != NULL) \ if (rule->prop != NULL) \
c->prop = r->prop obj->prop = rule->prop
#define BAKED_POINTS_COUNT 256 #define BAKED_POINTS_COUNT 256
@ -1039,28 +1039,28 @@ void toggle_hotarea(int x_root, int y_root) {
} }
static void apply_rule_properties(Client *c, const ConfigWinRule *r) { static void apply_rule_properties(Client *c, const ConfigWinRule *r) {
APPLY_INT_PROP(isterm); APPLY_INT_PROP(c, r, isterm);
APPLY_INT_PROP(noswallow); APPLY_INT_PROP(c, r, noswallow);
APPLY_INT_PROP(nofadein); APPLY_INT_PROP(c, r, nofadein);
APPLY_INT_PROP(nofadeout); APPLY_INT_PROP(c, r, nofadeout);
APPLY_INT_PROP(no_force_center); APPLY_INT_PROP(c, r, no_force_center);
APPLY_INT_PROP(isfloating); APPLY_INT_PROP(c, r, isfloating);
APPLY_INT_PROP(isfullscreen); APPLY_INT_PROP(c, r, isfullscreen);
APPLY_INT_PROP(isnoborder); APPLY_INT_PROP(c, r, isnoborder);
APPLY_INT_PROP(isopensilent); APPLY_INT_PROP(c, r, isopensilent);
APPLY_INT_PROP(isnamedscratchpad); APPLY_INT_PROP(c, r, isnamedscratchpad);
APPLY_INT_PROP(isglobal); APPLY_INT_PROP(c, r, isglobal);
APPLY_INT_PROP(isoverlay); APPLY_INT_PROP(c, r, isoverlay);
APPLY_INT_PROP(isunglobal); APPLY_INT_PROP(c, r, isunglobal);
APPLY_INT_PROP(scratchpad_width); APPLY_INT_PROP(c, r, scratchpad_width);
APPLY_INT_PROP(scratchpad_height); APPLY_INT_PROP(c, r, scratchpad_height);
APPLY_FLOAT_PROP(scroller_proportion); APPLY_FLOAT_PROP(c, r, scroller_proportion);
APPLY_FLOAT_PROP(focused_opacity); APPLY_FLOAT_PROP(c, r, focused_opacity);
APPLY_FLOAT_PROP(unfocused_opacity); APPLY_FLOAT_PROP(c, r, unfocused_opacity);
APPLY_STRING_PROP(animation_type_open); APPLY_STRING_PROP(c, r, animation_type_open);
APPLY_STRING_PROP(animation_type_close); APPLY_STRING_PROP(c, r, animation_type_close);
} }
int applyrulesgeom(Client *c) { int applyrulesgeom(Client *c) {
@ -2020,6 +2020,7 @@ void maplayersurfacenotify(struct wl_listener *listener, void *data) {
LayerSurface *l = wl_container_of(listener, l, map); LayerSurface *l = wl_container_of(listener, l, map);
struct wlr_layer_surface_v1 *layer_surface = l->layer_surface; struct wlr_layer_surface_v1 *layer_surface = l->layer_surface;
int ji; int ji;
ConfigLayerRule *r;
l->mapped = 1; l->mapped = 1;
@ -2045,23 +2046,13 @@ void maplayersurfacenotify(struct wl_listener *listener, void *data) {
break; break;
if (strcmp(config.layer_rules[ji].layer_name, if (strcmp(config.layer_rules[ji].layer_name,
l->layer_surface->namespace) == 0) { l->layer_surface->namespace) == 0) {
if (config.layer_rules[ji].noblur > 0) {
l->noblur = 1; r = &config.layer_rules[ji];
} APPLY_INT_PROP(l, r, noblur);
if (config.layer_rules[ji].noanim > 0) { APPLY_INT_PROP(l, r, noanim);
l->noanim = 1; APPLY_INT_PROP(l, r, noshadow);
} APPLY_STRING_PROP(l, r, animation_type_open);
if (config.layer_rules[ji].noshadow > 0) { APPLY_STRING_PROP(l, r, animation_type_close);
l->noshadow = 1;
}
if (config.layer_rules[ji].animation_type_open) {
l->animation_type_open =
config.layer_rules[ji].animation_type_open;
}
if (config.layer_rules[ji].animation_type_close) {
l->animation_type_close =
config.layer_rules[ji].animation_type_close;
}
} }
} }