Add macro documentation and translate remaining Chinese comments

Co-authored-by: squassina <8495707+squassina@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-02-18 08:56:21 +00:00
parent 73995e5828
commit c08c9c4fb8
3 changed files with 27 additions and 11 deletions

View file

@ -27,21 +27,21 @@ void get_layer_target_geometry(LayerSurface *l, struct wlr_box *target_box) {
const struct wlr_layer_surface_v1_state *state = &l->layer_surface->current; const struct wlr_layer_surface_v1_state *state = &l->layer_surface->current;
// 限制区域 // Exclusive zone handling:
// waybar一般都是大于0,表示要占用多少区域,所以计算位置也要用全部区域作为基准 // Waybar typically uses > 0, indicating how much area to reserve (use full
// 如果是-1可能表示独占所有可用空间 // monitor bounds) If -1, may indicate exclusive use of all available space
// 如果是0应该是表示使用exclusive_zone外的可用区域 // If 0, indicates use of available area outside exclusive zones
struct wlr_box bounds; struct wlr_box bounds;
if (state->exclusive_zone > 0 || state->exclusive_zone == -1) if (state->exclusive_zone > 0 || state->exclusive_zone == -1)
bounds = l->mon->m; bounds = l->mon->m;
else else
bounds = l->mon->w; bounds = l->mon->w;
// 初始化几何位置 // Initialize geometry
struct wlr_box box = {.width = state->desired_width, struct wlr_box box = {.width = state->desired_width,
.height = state->desired_height}; .height = state->desired_height};
// 水平方向定位 // Horizontal positioning
const int32_t both_horiz = const int32_t both_horiz =
ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
if (box.width == 0) { if (box.width == 0) {
@ -56,7 +56,7 @@ void get_layer_target_geometry(LayerSurface *l, struct wlr_box *target_box) {
box.x = bounds.x + ((bounds.width - box.width) / 2); box.x = bounds.x + ((bounds.width - box.width) / 2);
} }
// 垂直方向定位 // Vertical positioning
const int32_t both_vert = const int32_t both_vert =
ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
if (box.height == 0) { if (box.height == 0) {
@ -71,7 +71,7 @@ void get_layer_target_geometry(LayerSurface *l, struct wlr_box *target_box) {
box.y = bounds.y + ((bounds.height - box.height) / 2); box.y = bounds.y + ((bounds.height - box.height) / 2);
} }
// 应用边距 // Apply margins
if (box.width == 0) { if (box.width == 0) {
box.x += state->margin.left; box.x += state->margin.left;
box.width = bounds.width - (state->margin.left + state->margin.right); box.width = bounds.width - (state->margin.left + state->margin.right);
@ -412,8 +412,8 @@ void init_fadeout_layers(LayerSurface *l) {
fadeout_layer->animation_type_close = l->animation_type_close; fadeout_layer->animation_type_close = l->animation_type_close;
fadeout_layer->animation_type_open = l->animation_type_open; fadeout_layer->animation_type_open = l->animation_type_open;
// 这里snap节点的坐标设置是使用的相对坐标不能用绝对坐标 // Snapshot node coordinates use relative coordinates, not absolute
// 这跟普通node有区别 // This differs from regular nodes
fadeout_layer->animation.initial.x = 0; fadeout_layer->animation.initial.x = 0;
fadeout_layer->animation.initial.y = 0; fadeout_layer->animation.initial.y = 0;

View file

@ -59,7 +59,7 @@ int32_t regex_match(const char *pattern, const char *str) {
} }
pcre2_code *re = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED, pcre2_code *re = pcre2_compile((PCRE2_SPTR)pattern, PCRE2_ZERO_TERMINATED,
PCRE2_UTF, // 启用 UTF-8 支持 PCRE2_UTF, // Enable UTF-8 support
&errnum, &erroffset, NULL); &errnum, &erroffset, NULL);
if (!re) { if (!re) {
PCRE2_UCHAR errbuf[256]; PCRE2_UCHAR errbuf[256];

View file

@ -97,31 +97,43 @@
/* macros */ /* macros */
#define MAX(A, B) ((A) > (B) ? (A) : (B)) #define MAX(A, B) ((A) > (B) ? (A) : (B))
#define MIN(A, B) ((A) < (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B))
/* Get value if >= 0, otherwise return 0 */
#define GEZERO(A) ((A) >= 0 ? (A) : 0) #define GEZERO(A) ((A) >= 0 ? (A) : 0)
/* Remove caps lock modifier from mask */
#define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS) #define CLEANMASK(mask) (mask & ~WLR_MODIFIER_CAPS)
/* Check if client A is fully inside its monitor bounds */
#define INSIDEMON(A) \ #define INSIDEMON(A) \
(A->geom.x >= A->mon->m.x && A->geom.y >= A->mon->m.y && \ (A->geom.x >= A->mon->m.x && A->geom.y >= A->mon->m.y && \
A->geom.x + A->geom.width <= A->mon->m.x + A->mon->m.width && \ A->geom.x + A->geom.width <= A->mon->m.x + A->mon->m.width && \
A->geom.y + A->geom.height <= A->mon->m.y + A->mon->m.height) A->geom.y + A->geom.height <= A->mon->m.y + A->mon->m.height)
/* Check if geometry A is fully inside monitor M bounds */
#define GEOMINSIDEMON(A, M) \ #define GEOMINSIDEMON(A, M) \
(A->x >= M->m.x && A->y >= M->m.y && \ (A->x >= M->m.x && A->y >= M->m.y && \
A->x + A->width <= M->m.x + M->m.width && \ A->x + A->width <= M->m.x + M->m.width && \
A->y + A->height <= M->m.y + M->m.height) A->y + A->height <= M->m.y + M->m.height)
/* Check if client is in tiled state (not floating, minimized, killing, etc.) */
#define ISTILED(A) \ #define ISTILED(A) \
(A && !(A)->isfloating && !(A)->isminimized && !(A)->iskilling && \ (A && !(A)->isfloating && !(A)->isminimized && !(A)->iskilling && \
!(A)->ismaximizescreen && !(A)->isfullscreen && !(A)->isunglobal) !(A)->ismaximizescreen && !(A)->isfullscreen && !(A)->isunglobal)
/* Check if client is tiled for scroller layout (less restrictive than ISTILED)
*/
#define ISSCROLLTILED(A) \ #define ISSCROLLTILED(A) \
(A && !(A)->isfloating && !(A)->isminimized && !(A)->iskilling && \ (A && !(A)->isfloating && !(A)->isminimized && !(A)->iskilling && \
!(A)->isunglobal) !(A)->isunglobal)
/* Check if client C is visible on monitor M (matching tags) */
#define VISIBLEON(C, M) \ #define VISIBLEON(C, M) \
((C) && (M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags])) ((C) && (M) && (C)->mon == (M) && ((C)->tags & (M)->tagset[(M)->seltags]))
#define LENGTH(X) (sizeof X / sizeof X[0]) #define LENGTH(X) (sizeof X / sizeof X[0])
#define END(A) ((A) + LENGTH(A)) #define END(A) ((A) + LENGTH(A))
/* Generate bitmask for all tags */
#define TAGMASK ((1 << LENGTH(tags)) - 1) #define TAGMASK ((1 << LENGTH(tags)) - 1)
/* Register event listener: adds signal handler H to event E with listener L */
#define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L))) #define LISTEN(E, L, H) wl_signal_add((E), ((L)->notify = (H), (L)))
/* Check if client is in any fullscreen-like state */
#define ISFULLSCREEN(A) \ #define ISFULLSCREEN(A) \
((A)->isfullscreen || (A)->ismaximizescreen || \ ((A)->isfullscreen || (A)->ismaximizescreen || \
(A)->overview_ismaximizescreenbak || (A)->overview_isfullscreenbak) (A)->overview_ismaximizescreenbak || (A)->overview_isfullscreenbak)
/* Register static event listener (allocates listener internally) */
#define LISTEN_STATIC(E, H) \ #define LISTEN_STATIC(E, H) \
do { \ do { \
struct wl_listener *_l = ecalloc(1, sizeof(*_l)); \ struct wl_listener *_l = ecalloc(1, sizeof(*_l)); \
@ -129,18 +141,22 @@
wl_signal_add((E), _l); \ wl_signal_add((E), _l); \
} while (0) } while (0)
/* Apply integer property from rule to object if set (>= 0) */
#define APPLY_INT_PROP(obj, rule, prop) \ #define APPLY_INT_PROP(obj, rule, prop) \
if (rule->prop >= 0) \ if (rule->prop >= 0) \
obj->prop = rule->prop obj->prop = rule->prop
/* Apply float property from rule to object if set (> 0.0) */
#define APPLY_FLOAT_PROP(obj, rule, prop) \ #define APPLY_FLOAT_PROP(obj, rule, prop) \
if (rule->prop > 0.0f) \ if (rule->prop > 0.0f) \
obj->prop = rule->prop obj->prop = rule->prop
/* Apply string property from rule to object if set (not NULL) */
#define APPLY_STRING_PROP(obj, rule, prop) \ #define APPLY_STRING_PROP(obj, rule, prop) \
if (rule->prop != NULL) \ if (rule->prop != NULL) \
obj->prop = rule->prop obj->prop = rule->prop
/* Number of pre-calculated animation curve points for performance */
#define BAKED_POINTS_COUNT 256 #define BAKED_POINTS_COUNT 256
/* enums */ /* enums */