引入 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 路径同步更新
94 lines
2.3 KiB
C
94 lines
2.3 KiB
C
#include "core/layout.h"
|
|
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "base/array.h"
|
|
#include "base/memory.h"
|
|
#include "interface/types.h"
|
|
|
|
void layout_result_cleanup(layout_result_t *result) {
|
|
p_delete(&result->items);
|
|
result->item_count = 0;
|
|
result->item_capacity = 0;
|
|
}
|
|
|
|
void layout_result_push(layout_result_t *result, layout_item_t item) {
|
|
layout_item_t *slot =
|
|
array_push(result->items, result->item_count, result->item_capacity);
|
|
*slot = item;
|
|
}
|
|
|
|
void layout_registry_cleanup(layout_registry_t *registry) {
|
|
for (size_t i = 0; i < registry->slot_count; ++i) {
|
|
layout_slot_t *r = ®istry->slots[i];
|
|
p_delete(&r->name);
|
|
p_delete(&r->symbol);
|
|
p_delete(&r->description);
|
|
r->fn = nullptr;
|
|
r->id = ZDWM_LAYOUT_ID_INVALID;
|
|
}
|
|
|
|
p_delete(®istry->slots);
|
|
registry->slot_count = 0;
|
|
registry->slot_capacity = 0;
|
|
}
|
|
|
|
bool layout_registry_move(layout_registry_t *src, layout_registry_t *dest) {
|
|
if (!src || !dest) return false;
|
|
|
|
dest->slots = src->slots;
|
|
dest->slot_count = src->slot_count;
|
|
dest->slot_capacity = src->slot_capacity;
|
|
|
|
src->slots = nullptr;
|
|
src->slot_count = 0;
|
|
src->slot_capacity = 0;
|
|
|
|
return true;
|
|
}
|
|
|
|
size_t layout_registry_count(const layout_registry_t *registry) {
|
|
return registry->slot_count;
|
|
}
|
|
|
|
const layout_slot_t *
|
|
layout_registry_at(const layout_registry_t *registry, size_t index) {
|
|
if (index >= registry->slot_count) return nullptr;
|
|
return ®istry->slots[index];
|
|
}
|
|
|
|
layout_id_t layout_register(
|
|
layout_registry_t *registry,
|
|
const char *name,
|
|
const char *symbol,
|
|
const char *description,
|
|
layout_fn fn
|
|
) {
|
|
if (!name || !symbol) return ZDWM_LAYOUT_ID_INVALID;
|
|
|
|
layout_id_t id = (layout_id_t)registry->slot_count;
|
|
layout_slot_t *r =
|
|
array_push(registry->slots, registry->slot_count, registry->slot_capacity);
|
|
r->id = id;
|
|
r->name = p_strdup(name);
|
|
r->symbol = p_strdup(symbol);
|
|
r->description = p_strdup_nullable(description);
|
|
r->fn = fn;
|
|
|
|
return r->id;
|
|
}
|
|
|
|
layout_fn layout_get(const layout_registry_t *registry, layout_id_t id) {
|
|
const layout_slot_t *layout_slot = layout_slot_get(registry, id);
|
|
if (layout_slot) return layout_slot->fn;
|
|
return nullptr;
|
|
}
|
|
|
|
const layout_slot_t *
|
|
layout_slot_get(const layout_registry_t *registry, layout_id_t id) {
|
|
if (id >= registry->slot_count) return nullptr;
|
|
return ®istry->slots[id];
|
|
}
|