base: 将通用动态数组操作接入 layout/state/config
This commit is contained in:
@@ -4,13 +4,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "base/array.h"
|
||||
#include "base/memory.h"
|
||||
|
||||
void layout_result_init(layout_result_t *result) {
|
||||
result->item_count = 0;
|
||||
result->item_capacity = INIT_CAPACITY;
|
||||
result->items = p_new(layout_item_t, result->item_capacity);
|
||||
}
|
||||
#include "core/types.h"
|
||||
|
||||
void layout_result_cleanup(layout_result_t *result) {
|
||||
p_delete(&result->items);
|
||||
@@ -19,19 +15,9 @@ void layout_result_cleanup(layout_result_t *result) {
|
||||
}
|
||||
|
||||
void layout_result_push(layout_result_t *result, layout_item_t item) {
|
||||
if (result->item_count == result->item_capacity) {
|
||||
size_t new_capacity = next_capacity(result->item_capacity);
|
||||
p_realloc(&result->items, new_capacity);
|
||||
result->item_capacity = new_capacity;
|
||||
}
|
||||
|
||||
result->items[result->item_count++] = item;
|
||||
}
|
||||
|
||||
void layout_registry_init(layout_registry_t *registry) {
|
||||
registry->slot_count = 0;
|
||||
registry->slot_capacity = INIT_CAPACITY;
|
||||
registry->slots = p_new(layout_slot_t, registry->slot_capacity);
|
||||
layout_item_t *slot =
|
||||
array_push(result->items, result->item_count, result->item_capacity);
|
||||
*slot = item;
|
||||
}
|
||||
|
||||
void layout_registry_cleanup(layout_registry_t *registry) {
|
||||
@@ -77,22 +63,16 @@ layout_id_t layout_register(layout_registry_t *registry, const char *name,
|
||||
layout_fn fn) {
|
||||
if (!name || !symbol) return ZDWM_LAYOUT_ID_INVALID;
|
||||
|
||||
if (registry->slot_count == registry->slot_capacity) {
|
||||
size_t new_capacity = next_capacity(registry->slot_capacity);
|
||||
p_realloc(®istry->slots, new_capacity);
|
||||
registry->slot_capacity = new_capacity;
|
||||
}
|
||||
layout_id_t id = (layout_id_t)registry->slot_count;
|
||||
|
||||
layout_slot_t *r = ®istry->slots[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;
|
||||
|
||||
registry->slot_count++;
|
||||
return id;
|
||||
return r->id;
|
||||
}
|
||||
|
||||
layout_fn layout_get(const layout_registry_t *registry, layout_id_t id) {
|
||||
|
||||
@@ -47,24 +47,10 @@ typedef struct layout_registry_t {
|
||||
size_t slot_capacity;
|
||||
} layout_registry_t;
|
||||
|
||||
/*
|
||||
* 调用约束:
|
||||
* - result 必须是有效的非空指针
|
||||
* - 除 init 之外,其余 result 相关接口都要求 result 已初始化
|
||||
* - 传入空指针或未初始化对象属于调用方错误
|
||||
*/
|
||||
void layout_result_init(layout_result_t *result);
|
||||
void layout_result_cleanup(layout_result_t *result);
|
||||
|
||||
void layout_result_push(layout_result_t *result, layout_item_t item);
|
||||
|
||||
/*
|
||||
* 调用约束:
|
||||
* - registry 必须是有效的非空指针
|
||||
* - 除 init 之外,其余 registry 相关接口都要求 registry 已初始化
|
||||
* - 传入空指针或未初始化对象属于调用方错误
|
||||
*/
|
||||
void layout_registry_init(layout_registry_t *registry);
|
||||
void layout_registry_cleanup(layout_registry_t *registry);
|
||||
bool layout_registry_move(layout_registry_t *src, layout_registry_t *dest);
|
||||
size_t layout_registry_count(const layout_registry_t *registry);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "base/array.h"
|
||||
#include "base/log.h"
|
||||
#include "base/memory.h"
|
||||
#include "core/types.h"
|
||||
@@ -257,19 +258,19 @@ const window_t *state_window_add(state_t *state, const window_info_t *info) {
|
||||
window_id_t id = info->id;
|
||||
window_t *window = (window_t *)state_window_get(state, id);
|
||||
if (!window) {
|
||||
if (state->window_count == state->window_capacity) {
|
||||
size_t capacity = next_capacity(state->window_capacity);
|
||||
p_realloc(&state->windows, capacity);
|
||||
p_realloc(&state->stack_order, capacity);
|
||||
state->window_capacity = capacity;
|
||||
size_t index = state->window_count;
|
||||
size_t old_capacity = state->window_capacity;
|
||||
window =
|
||||
array_push(state->windows, state->window_count, state->window_capacity);
|
||||
if (old_capacity != state->window_capacity) {
|
||||
p_realloc(&state->stack_order, state->window_capacity);
|
||||
}
|
||||
window = &state->windows[state->window_count];
|
||||
|
||||
p_clear(window, 1);
|
||||
window->id = id;
|
||||
window->workspace_id = ZDWM_WORKSPACE_ID_INVALID;
|
||||
|
||||
state->stack_order[state->window_count] = id;
|
||||
state->window_count++;
|
||||
state->stack_order[index] = id;
|
||||
}
|
||||
|
||||
state_window_set_geometry_mode(state, id, info->geometry_mode);
|
||||
|
||||
Reference in New Issue
Block a user