Files
zdwm/src/core/rules.c
Zedhugh Chen 079f41ce8a refactor: 从 core 中抽出跨模块契约建立 interface/common 模块分层
引入 interface/(零实现声明层)与 common/(共享 ADT 操作层),把跨模块
契约从 core 实现里抽出来,依赖方向回到单向(base ← interface ← common ←
各实现层)。docs/module-layering.org 记录完整方案与判定标准。

interface/(纯类型与多态接口声明,零 .c):
- types.h / event.h / backend.h 从 core 移入
- effect.h 新建(effect_t 从 plan.h 抽出)

common/(多实现层共用的自包含操作,.h + .c):
- event.{h,c}:event_reset / event_cleanup
- listeners.{h,c}:listeners 维护(add / cleanup);notify 留 core
- window.{h,c}:window_list + layer_props/metadata cleanup + window_classify_layer
- workspace.{h,c}:workspace_desc(从 wm_desc.h 拆出,改真实函数)

window 相关整理:
- window_layer_type_t 上浮 interface/types.h(common 的 classify 需要)
- window_classify_layer 移 common/window
- window_info_t 独立成 core/window_info.h(state/command 共享,不寄生)
- 删除 wm_desc.h,base/window_list 并入 common/window

全项目 include 路径同步更新
2026-06-25 03:00:30 +08:00

85 lines
2.0 KiB
C

#include "core/rules.h"
#include <stddef.h>
#include <string.h>
#include <zdwm/types.h>
#include "base/memory.h"
#include "interface/types.h"
bool rules_move(rules_t *src, rules_t *dest) {
if (!dest || !src) return false;
dest->items = src->items;
dest->count = src->count;
dest->capacity = src->capacity;
src->items = nullptr;
src->count = 0;
src->capacity = 0;
return true;
}
void rules_cleanup(rules_t *rules) {
for (size_t i = 0; i < rules->count; ++i) {
rule_match_t *match = &rules->items[i].match;
rule_action_t *action = &rules->items[i].action;
p_delete(&match->app_id);
p_delete(&match->role);
p_delete(&match->class_name);
p_delete(&match->instance_name);
p_clear(action, 1);
action->workspace = ZDWM_WORKSPACE_ID_INVALID;
}
p_delete(&rules->items);
rules->capacity = 0;
rules->count = 0;
}
static inline bool str_match(const char *pattern, const char *value) {
return !pattern || (value && strcmp(pattern, value) == 0);
}
static bool
rule_match_window(const rule_match_t *match, const window_metadata_t *meta) {
return str_match(match->app_id, meta->app_id) &&
str_match(match->role, meta->role) &&
str_match(match->class_name, meta->class_name) &&
str_match(match->instance_name, meta->instance_name);
}
static void rule_action_merge(const rule_action_t *src, rule_action_t *dest) {
if (!src || !dest) return;
if (!workspace_id_invalid(src->workspace)) {
dest->workspace = src->workspace;
}
dest->switch_to_workspace |= src->switch_to_workspace;
dest->fullscreen |= src->fullscreen;
dest->maximize |= src->maximize;
dest->floating |= src->floating;
}
bool rules_resolve(
const rules_t *rules,
const window_metadata_t *metadata,
rule_action_t *action_out
) {
if (!action_out) return false;
bool matched = false;
for (size_t i = 0; i < rules->count; ++i) {
if (!rule_match_window(&rules->items[i].match, metadata)) continue;
matched = true;
rule_action_merge(&rules->items[i].action, action_out);
}
return matched;
}