style: 更新 .clang-format 规则并重新格式化所有源文件
- 重构模块使用新的代码风格 - 老代码 (src 目录下的代码) 继续使用之前的代码风格 通过在需要不同代码风格的目录下放对应 .clang-format 配置文件实现
This commit is contained in:
@@ -6,8 +6,13 @@
|
||||
#include "core/types.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void assert_output_geometry(const output_info_t *output, int32_t x,
|
||||
int32_t y, int32_t width, int32_t height) {
|
||||
static void assert_output_geometry(
|
||||
const output_info_t *output,
|
||||
int32_t x,
|
||||
int32_t y,
|
||||
int32_t width,
|
||||
int32_t height
|
||||
) {
|
||||
assert(output);
|
||||
assert(output->geometry.x == x);
|
||||
assert(output->geometry.y == y);
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include "config/loader.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config/loader.h"
|
||||
#include "helpers.h"
|
||||
|
||||
static void test_config_loader_loads_explicit_override(const char *fixture_path) {
|
||||
static void test_config_loader_loads_explicit_override(
|
||||
const char *fixture_path
|
||||
) {
|
||||
config_test_clear_env();
|
||||
|
||||
config_loader_t loader = {0};
|
||||
@@ -22,9 +23,12 @@ static void test_config_loader_loads_explicit_override(const char *fixture_path)
|
||||
}
|
||||
|
||||
static void test_config_loader_override_has_priority_over_env(
|
||||
const char *fixture_path) {
|
||||
const char *fixture_path
|
||||
) {
|
||||
config_test_clear_env();
|
||||
assert(setenv("ZDWM_CONFIG_LIB", "/tmp/definitely-missing-config.so", 1) == 0);
|
||||
assert(
|
||||
setenv("ZDWM_CONFIG_LIB", "/tmp/definitely-missing-config.so", 1) == 0
|
||||
);
|
||||
|
||||
config_loader_t loader = {0};
|
||||
assert(config_loader_load(&loader, fixture_path));
|
||||
@@ -37,7 +41,8 @@ static void test_config_loader_override_has_priority_over_env(
|
||||
}
|
||||
|
||||
static void test_config_loader_uses_zdwm_config_lib_env(
|
||||
const char *fixture_path) {
|
||||
const char *fixture_path
|
||||
) {
|
||||
config_test_clear_env();
|
||||
assert(setenv("ZDWM_CONFIG_LIB", fixture_path, 1) == 0);
|
||||
|
||||
@@ -54,15 +59,22 @@ static void test_config_loader_uses_zdwm_config_lib_env(
|
||||
static void test_config_loader_uses_xdg_config_home(const char *fixture_path) {
|
||||
config_test_clear_env();
|
||||
|
||||
char temp_root[PATH_MAX] = {0};
|
||||
char config_dir[PATH_MAX] = {0};
|
||||
char temp_root[PATH_MAX] = {0};
|
||||
char config_dir[PATH_MAX] = {0};
|
||||
char config_path[PATH_MAX] = {0};
|
||||
|
||||
config_test_make_temp_dir(temp_root, sizeof(temp_root),
|
||||
"zdwm-config-loader-xdg");
|
||||
config_test_make_temp_dir(
|
||||
temp_root,
|
||||
sizeof(temp_root),
|
||||
"zdwm-config-loader-xdg"
|
||||
);
|
||||
config_test_join_path(config_dir, sizeof(config_dir), temp_root, "zdwm");
|
||||
config_test_join_path(config_path, sizeof(config_path), config_dir,
|
||||
"config.so");
|
||||
config_test_join_path(
|
||||
config_path,
|
||||
sizeof(config_path),
|
||||
config_dir,
|
||||
"config.so"
|
||||
);
|
||||
config_test_mkdir(config_dir);
|
||||
config_test_symlink(fixture_path, config_path);
|
||||
assert(setenv("XDG_CONFIG_HOME", temp_root, 1) == 0);
|
||||
@@ -83,17 +95,24 @@ static void test_config_loader_uses_xdg_config_home(const char *fixture_path) {
|
||||
static void test_config_loader_uses_home_fallback(const char *fixture_path) {
|
||||
config_test_clear_env();
|
||||
|
||||
char temp_root[PATH_MAX] = {0};
|
||||
char temp_root[PATH_MAX] = {0};
|
||||
char config_root[PATH_MAX] = {0};
|
||||
char zdwm_dir[PATH_MAX] = {0};
|
||||
char zdwm_dir[PATH_MAX] = {0};
|
||||
char config_path[PATH_MAX] = {0};
|
||||
|
||||
config_test_make_temp_dir(temp_root, sizeof(temp_root),
|
||||
"zdwm-config-loader-home");
|
||||
config_test_make_temp_dir(
|
||||
temp_root,
|
||||
sizeof(temp_root),
|
||||
"zdwm-config-loader-home"
|
||||
);
|
||||
config_test_join_path(config_root, sizeof(config_root), temp_root, ".config");
|
||||
config_test_join_path(zdwm_dir, sizeof(zdwm_dir), config_root, "zdwm");
|
||||
config_test_join_path(config_path, sizeof(config_path), zdwm_dir,
|
||||
"config.so");
|
||||
config_test_join_path(
|
||||
config_path,
|
||||
sizeof(config_path),
|
||||
zdwm_dir,
|
||||
"config.so"
|
||||
);
|
||||
config_test_mkdir(config_root);
|
||||
config_test_mkdir(zdwm_dir);
|
||||
config_test_symlink(fixture_path, config_path);
|
||||
@@ -116,13 +135,20 @@ static void test_config_loader_uses_home_fallback(const char *fixture_path) {
|
||||
static void test_config_loader_allows_missing_implicit_library(void) {
|
||||
config_test_clear_env();
|
||||
|
||||
char temp_root[PATH_MAX] = {0};
|
||||
char temp_root[PATH_MAX] = {0};
|
||||
char expected_path[PATH_MAX] = {0};
|
||||
|
||||
config_test_make_temp_dir(temp_root, sizeof(temp_root),
|
||||
"zdwm-config-loader-missing");
|
||||
config_test_join_path(expected_path, sizeof(expected_path), temp_root,
|
||||
"zdwm/config.so");
|
||||
config_test_make_temp_dir(
|
||||
temp_root,
|
||||
sizeof(temp_root),
|
||||
"zdwm-config-loader-missing"
|
||||
);
|
||||
config_test_join_path(
|
||||
expected_path,
|
||||
sizeof(expected_path),
|
||||
temp_root,
|
||||
"zdwm/config.so"
|
||||
);
|
||||
assert(setenv("XDG_CONFIG_HOME", temp_root, 1) == 0);
|
||||
|
||||
config_loader_t loader = {0};
|
||||
@@ -147,7 +173,8 @@ static void test_config_loader_rejects_missing_explicit_library(void) {
|
||||
}
|
||||
|
||||
static void test_config_loader_rejects_library_without_setup(
|
||||
const char *fixture_path) {
|
||||
const char *fixture_path
|
||||
) {
|
||||
config_test_clear_env();
|
||||
|
||||
config_loader_t loader = {0};
|
||||
|
||||
@@ -1,28 +1,45 @@
|
||||
#include <zdwm/config.h>
|
||||
|
||||
static bool fixture_layout(const zdwm_layout_ctx_t *ctx,
|
||||
zdwm_layout_result_t *out) {
|
||||
static bool
|
||||
fixture_layout(const zdwm_layout_ctx_t *ctx, zdwm_layout_result_t *out) {
|
||||
if (!ctx || !out) return false;
|
||||
|
||||
zdwm_layout_result_reset(out);
|
||||
if (!ctx->window_ids || ctx->window_count == 0) return true;
|
||||
|
||||
zdwm_layout_result_push(out, (zdwm_layout_item_t){
|
||||
.window_id = ctx->window_ids[0],
|
||||
.rect = ctx->workarea,
|
||||
});
|
||||
zdwm_layout_result_push(
|
||||
out,
|
||||
(zdwm_layout_item_t){
|
||||
.window_id = ctx->window_ids[0],
|
||||
.rect = ctx->workarea,
|
||||
}
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool setup(const zdwm_api_t *api, zdwm_config_builder_t *builder,
|
||||
const zdwm_output_info_t *outputs, size_t output_count) {
|
||||
bool setup(
|
||||
const zdwm_api_t *api,
|
||||
zdwm_config_builder_t *builder,
|
||||
const zdwm_output_info_t *outputs,
|
||||
size_t output_count
|
||||
) {
|
||||
if (!api || !builder || !outputs || output_count == 0) return false;
|
||||
|
||||
zdwm_layout_id_t layout_id =
|
||||
api->register_layout(builder, "test-only", "[T]", "fixture layout",
|
||||
fixture_layout);
|
||||
zdwm_layout_id_t layout_id = api->register_layout(
|
||||
builder,
|
||||
"test-only",
|
||||
"[T]",
|
||||
"fixture layout",
|
||||
fixture_layout
|
||||
);
|
||||
if (layout_id == ZDWM_LAYOUT_ID_INVALID) return false;
|
||||
|
||||
return api->define_workspace(builder, 0, "from-so", &layout_id, 1,
|
||||
layout_id) != ZDWM_WORKSPACE_ID_INVALID;
|
||||
return api->define_workspace(
|
||||
builder,
|
||||
0,
|
||||
"from-so",
|
||||
&layout_id,
|
||||
1,
|
||||
layout_id
|
||||
) != ZDWM_WORKSPACE_ID_INVALID;
|
||||
}
|
||||
|
||||
@@ -15,17 +15,20 @@ static inline void config_test_clear_env(void) {
|
||||
assert(unsetenv("HOME") == 0);
|
||||
}
|
||||
|
||||
static inline void config_test_make_temp_dir(char *path, size_t path_size,
|
||||
const char *prefix) {
|
||||
static inline void
|
||||
config_test_make_temp_dir(char *path, size_t path_size, const char *prefix) {
|
||||
int len = snprintf(path, path_size, "/tmp/%s-XXXXXX", prefix);
|
||||
assert(len > 0);
|
||||
assert((size_t)len < path_size);
|
||||
assert(mkdtemp(path) == path);
|
||||
}
|
||||
|
||||
static inline void config_test_join_path(char *out, size_t out_size,
|
||||
const char *base,
|
||||
const char *suffix) {
|
||||
static inline void config_test_join_path(
|
||||
char *out,
|
||||
size_t out_size,
|
||||
const char *base,
|
||||
const char *suffix
|
||||
) {
|
||||
int len = snprintf(out, out_size, "%s/%s", base, suffix);
|
||||
assert(len > 0);
|
||||
assert((size_t)len < out_size);
|
||||
|
||||
@@ -22,8 +22,11 @@ bool backend_next_event(backend_t *backend, event_t *event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool backend_apply_effect(backend_t *backend, const effect_t *effects,
|
||||
size_t effect_count) {
|
||||
bool backend_apply_effect(
|
||||
backend_t *backend,
|
||||
const effect_t *effects,
|
||||
size_t effect_count
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,8 +38,8 @@ static void assert_default_layouts(const runtime_init_desc_t *desc) {
|
||||
assert(desc);
|
||||
assert(layout_registry_count(&desc->layouts) == 3);
|
||||
|
||||
const layout_slot_t *tile = layout_registry_at(&desc->layouts, 0);
|
||||
const layout_slot_t *monocle = layout_registry_at(&desc->layouts, 1);
|
||||
const layout_slot_t *tile = layout_registry_at(&desc->layouts, 0);
|
||||
const layout_slot_t *monocle = layout_registry_at(&desc->layouts, 1);
|
||||
const layout_slot_t *floating = layout_registry_at(&desc->layouts, 2);
|
||||
|
||||
assert(tile);
|
||||
@@ -52,13 +55,13 @@ static void test_runtime_config_loads_user_library(const char *fixture_path) {
|
||||
|
||||
output_info_t outputs[] = {
|
||||
{
|
||||
.name = "HDMI-A-1",
|
||||
.name = "HDMI-A-1",
|
||||
.geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080},
|
||||
},
|
||||
};
|
||||
|
||||
runtime_init_desc_t desc = {
|
||||
.outputs = outputs,
|
||||
.outputs = outputs,
|
||||
.output_count = 1,
|
||||
};
|
||||
assert(runtime_config_load(fixture_path, &desc));
|
||||
@@ -79,20 +82,21 @@ static void test_runtime_config_loads_user_library(const char *fixture_path) {
|
||||
}
|
||||
|
||||
static void test_runtime_config_keeps_module_loaded_after_runtime_init(
|
||||
const char *fixture_path) {
|
||||
const char *fixture_path
|
||||
) {
|
||||
config_test_clear_env();
|
||||
|
||||
output_info_t outputs[] = {
|
||||
{
|
||||
.name = "HDMI-A-1",
|
||||
.name = "HDMI-A-1",
|
||||
.geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080},
|
||||
},
|
||||
};
|
||||
window_id_t window_ids[] = {42};
|
||||
|
||||
runtime_init_desc_t desc = {
|
||||
.backend = test_backend_create(),
|
||||
.outputs = outputs,
|
||||
.backend = test_backend_create(),
|
||||
.outputs = outputs,
|
||||
.output_count = 1,
|
||||
};
|
||||
assert(desc.backend);
|
||||
@@ -111,11 +115,11 @@ static void test_runtime_config_keeps_module_loaded_after_runtime_init(
|
||||
layout_result_t result = {0};
|
||||
|
||||
layout_ctx_t ctx = {
|
||||
.workspace_id = 0,
|
||||
.workspace_id = 0,
|
||||
.focused_window_id = window_ids[0],
|
||||
.workarea = {.x = 11, .y = 22, .width = 333, .height = 444},
|
||||
.window_ids = window_ids,
|
||||
.window_count = 1,
|
||||
.workarea = {.x = 11, .y = 22, .width = 333, .height = 444},
|
||||
.window_ids = window_ids,
|
||||
.window_count = 1,
|
||||
};
|
||||
assert(layout(&ctx, &result));
|
||||
assert(result.item_count == 1);
|
||||
@@ -132,27 +136,31 @@ static void test_runtime_config_keeps_module_loaded_after_runtime_init(
|
||||
|
||||
static void
|
||||
test_runtime_config_falls_back_to_defaults_when_implicit_library_is_missing(
|
||||
void) {
|
||||
void
|
||||
) {
|
||||
config_test_clear_env();
|
||||
|
||||
output_info_t outputs[] = {
|
||||
{
|
||||
.name = "eDP-1",
|
||||
.name = "eDP-1",
|
||||
.geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080},
|
||||
},
|
||||
{
|
||||
.name = "DP-1",
|
||||
.name = "DP-1",
|
||||
.geometry = {.x = 1920, .y = 0, .width = 2560, .height = 1440},
|
||||
},
|
||||
};
|
||||
|
||||
char temp_root[PATH_MAX] = {0};
|
||||
config_test_make_temp_dir(temp_root, sizeof(temp_root),
|
||||
"zdwm-runtime-config-missing");
|
||||
config_test_make_temp_dir(
|
||||
temp_root,
|
||||
sizeof(temp_root),
|
||||
"zdwm-runtime-config-missing"
|
||||
);
|
||||
assert(setenv("XDG_CONFIG_HOME", temp_root, 1) == 0);
|
||||
|
||||
runtime_init_desc_t desc = {
|
||||
.outputs = outputs,
|
||||
.outputs = outputs,
|
||||
.output_count = 2,
|
||||
};
|
||||
assert(runtime_config_load(nullptr, &desc));
|
||||
@@ -173,13 +181,13 @@ static void test_runtime_config_rejects_missing_explicit_library(void) {
|
||||
|
||||
output_info_t outputs[] = {
|
||||
{
|
||||
.name = "HDMI-A-1",
|
||||
.name = "HDMI-A-1",
|
||||
.geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080},
|
||||
},
|
||||
};
|
||||
|
||||
runtime_init_desc_t desc = {
|
||||
.outputs = outputs,
|
||||
.outputs = outputs,
|
||||
.output_count = 1,
|
||||
};
|
||||
assert(!runtime_config_load("/tmp/definitely-missing-config.so", &desc));
|
||||
@@ -190,18 +198,19 @@ static void test_runtime_config_rejects_missing_explicit_library(void) {
|
||||
}
|
||||
|
||||
static void test_runtime_config_rejects_library_without_setup(
|
||||
const char *fixture_path) {
|
||||
const char *fixture_path
|
||||
) {
|
||||
config_test_clear_env();
|
||||
|
||||
output_info_t outputs[] = {
|
||||
{
|
||||
.name = "HDMI-A-1",
|
||||
.name = "HDMI-A-1",
|
||||
.geometry = {.x = 0, .y = 0, .width = 1920, .height = 1080},
|
||||
},
|
||||
};
|
||||
|
||||
runtime_init_desc_t desc = {
|
||||
.outputs = outputs,
|
||||
.outputs = outputs,
|
||||
.output_count = 1,
|
||||
};
|
||||
assert(!runtime_config_load(fixture_path, &desc));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "core/runtime.h"
|
||||
|
||||
static void bootstrap(runtime_t *runtime) {
|
||||
backend_t *backend = backend_create(nullptr);
|
||||
backend_t *backend = backend_create(nullptr);
|
||||
backend_detect_t *detect = backend_detect(backend);
|
||||
|
||||
if (!backend || !detect || detect->output_count == 0) {
|
||||
@@ -12,8 +12,8 @@ static void bootstrap(runtime_t *runtime) {
|
||||
}
|
||||
|
||||
runtime_init_desc_t desc = {
|
||||
.backend = backend,
|
||||
.outputs = detect->outputs,
|
||||
.backend = backend,
|
||||
.outputs = detect->outputs,
|
||||
.output_count = detect->output_count,
|
||||
};
|
||||
if (!runtime_config_load(nullptr, &desc)) {
|
||||
|
||||
Reference in New Issue
Block a user