feat(core): 添加 command 定义及 command_buffer 维护功能
This commit is contained in:
38
src/core/command.h
Normal file
38
src/core/command.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/types.h"
|
||||
#include "core/wm_desc.h"
|
||||
|
||||
typedef enum command_type_t {
|
||||
ZDWM_COMMAND_MANAGE_WINDOW,
|
||||
ZDWM_COMMAND_SWITCH_WORKSPACE
|
||||
} command_type_t;
|
||||
|
||||
typedef struct manage_window_command_t {
|
||||
workspace_id_t workspace;
|
||||
bool floating;
|
||||
bool switch_to_workspace;
|
||||
window_info_t info;
|
||||
} manage_window_command_t;
|
||||
|
||||
typedef struct switch_workspace_command_t {
|
||||
output_id_t output;
|
||||
workspace_id_t workspace;
|
||||
} switch_workspace_command_t;
|
||||
|
||||
/**
|
||||
* @brief 非 owning 的命令值对象
|
||||
* @details
|
||||
* command_t 自身不拥有任何堆内存;其当前所有 payload 中出现的指针字段均为借用
|
||||
* 语义。
|
||||
*
|
||||
* 因此 command_t 支持按值浅拷贝,且不需要单独的 cleanup 接口。若接收方需要在
|
||||
* 源数据生命周期之外继续持有相关内容,必须自行复制。
|
||||
*/
|
||||
typedef struct command_t {
|
||||
command_type_t type;
|
||||
union {
|
||||
manage_window_command_t manage_window;
|
||||
switch_workspace_command_t switch_workspace;
|
||||
} as;
|
||||
} command_t;
|
||||
23
src/core/command_buffer.c
Normal file
23
src/core/command_buffer.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "core/command_buffer.h"
|
||||
|
||||
#include "base/array.h"
|
||||
#include "base/memory.h"
|
||||
#include "core/command.h"
|
||||
|
||||
void command_buffer_reset(command_buffer_t *buffer) {
|
||||
if (!buffer->items || !buffer->capacity) return;
|
||||
|
||||
p_clear(buffer->items, buffer->capacity);
|
||||
buffer->count = 0;
|
||||
}
|
||||
|
||||
void command_buffer_cleanup(command_buffer_t *buffer) {
|
||||
p_delete(&buffer->items);
|
||||
buffer->count = 0;
|
||||
buffer->capacity = 0;
|
||||
}
|
||||
|
||||
void command_buffer_push(command_buffer_t *buffer, const command_t *command) {
|
||||
command_t *cmd = array_push(buffer->items, buffer->count, buffer->capacity);
|
||||
*cmd = *command;
|
||||
}
|
||||
15
src/core/command_buffer.h
Normal file
15
src/core/command_buffer.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "core/command.h"
|
||||
|
||||
typedef struct command_buffer_t {
|
||||
command_t *items;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} command_buffer_t;
|
||||
|
||||
void command_buffer_reset(command_buffer_t *buffer);
|
||||
void command_buffer_cleanup(command_buffer_t *buffer);
|
||||
void command_buffer_push(command_buffer_t *buffer, const command_t *command);
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <stddef.h>
|
||||
|
||||
#include "core/backend.h"
|
||||
#include "core/command_buffer.h"
|
||||
#include "core/layout.h"
|
||||
#include "core/rules.h"
|
||||
#include "core/state.h"
|
||||
@@ -23,6 +24,7 @@ typedef struct runtime_t {
|
||||
bool running;
|
||||
bool will_restart;
|
||||
|
||||
command_buffer_t command_buffer;
|
||||
state_t state;
|
||||
layout_registry_t layouts;
|
||||
rules_t rules;
|
||||
|
||||
Reference in New Issue
Block a user