定义公共用户自定义配置需要用到的接口和数据结构
This commit is contained in:
44
include/zdwm/config.h
Normal file
44
include/zdwm/config.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef ZDWM_CONFIG_H
|
||||
#define ZDWM_CONFIG_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <zdwm/layout.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ZDWM_CONFIG_ABI_VERSION 1u
|
||||
|
||||
typedef struct zdwm_config_builder_t zdwm_config_builder_t;
|
||||
|
||||
typedef struct zdwm_builtin_layouts_t {
|
||||
zdwm_layout_fn tile;
|
||||
zdwm_layout_fn monocle;
|
||||
} zdwm_builtin_layouts_t;
|
||||
|
||||
typedef struct zdwm_api_t {
|
||||
uint32_t abi_version;
|
||||
zdwm_builtin_layouts_t builtin_layouts;
|
||||
|
||||
zdwm_layout_id_t (*register_layout)(zdwm_config_builder_t *builder,
|
||||
const char *name, const char *symbol,
|
||||
const char *description,
|
||||
zdwm_layout_fn fn);
|
||||
|
||||
bool (*define_workspace)(zdwm_config_builder_t *builder, size_t output_index,
|
||||
const char *name, const zdwm_layout_id_t *layout_ids,
|
||||
size_t layout_count,
|
||||
zdwm_layout_id_t initial_layout_id);
|
||||
} zdwm_api_t;
|
||||
|
||||
bool zdwm_config_setup(const zdwm_api_t *api, zdwm_config_builder_t *builder,
|
||||
const zdwm_output_info_t *outputs, size_t output_count);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZDWM_CONFIG_H */
|
||||
61
include/zdwm/layout.h
Normal file
61
include/zdwm/layout.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef ZDWM_LAYOUT_H
|
||||
#define ZDWM_LAYOUT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <zdwm/types.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct zdwm_layout_ctx_t {
|
||||
zdwm_workspace_id_t workspace_id;
|
||||
zdwm_window_id_t focused_window_id;
|
||||
zdwm_rect_t workarea;
|
||||
const zdwm_window_id_t *window_ids;
|
||||
size_t window_count;
|
||||
} zdwm_layout_ctx_t;
|
||||
|
||||
typedef struct zdwm_layout_item_t {
|
||||
zdwm_window_id_t window_id;
|
||||
zdwm_rect_t rect;
|
||||
} zdwm_layout_item_t;
|
||||
|
||||
typedef struct zdwm_layout_result_t {
|
||||
zdwm_layout_item_t *items;
|
||||
size_t item_count;
|
||||
size_t item_capacity;
|
||||
} zdwm_layout_result_t;
|
||||
|
||||
typedef bool (*zdwm_layout_fn)(const zdwm_layout_ctx_t *ctx,
|
||||
zdwm_layout_result_t *out);
|
||||
|
||||
static inline void zdwm_layout_result_reset(zdwm_layout_result_t *result) {
|
||||
if (!result) abort();
|
||||
result->item_count = 0;
|
||||
}
|
||||
|
||||
static inline void zdwm_layout_result_push(zdwm_layout_result_t *result,
|
||||
zdwm_layout_item_t item) {
|
||||
if (!result) abort();
|
||||
|
||||
if (result->item_count == result->item_capacity) {
|
||||
size_t capacity = result->item_capacity ? result->item_capacity * 2u : 4u;
|
||||
zdwm_layout_item_t *items =
|
||||
realloc(result->items, capacity * sizeof(*result->items));
|
||||
if (!items) abort();
|
||||
result->items = items;
|
||||
result->item_capacity = capacity;
|
||||
}
|
||||
|
||||
result->items[result->item_count++] = item;
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZDWM_LAYOUT_H */
|
||||
36
include/zdwm/types.h
Normal file
36
include/zdwm/types.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef ZDWM_TYPES_H
|
||||
#define ZDWM_TYPES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint32_t zdwm_layout_id_t;
|
||||
typedef uint32_t zdwm_window_id_t;
|
||||
typedef uint32_t zdwm_workspace_id_t;
|
||||
|
||||
/* clang-format off */
|
||||
#define ZDWM_LAYOUT_ID_INVALID ((zdwm_layout_id_t)UINT32_MAX)
|
||||
#define ZDWM_WINDOW_ID_INVALID ((zdwm_window_id_t)0)
|
||||
#define ZDWM_WORKSPACE_ID_INVALID ((zdwm_workspace_id_t)UINT32_MAX)
|
||||
/* clang-format on */
|
||||
|
||||
typedef struct zdwm_rect_t {
|
||||
int32_t x;
|
||||
int32_t y;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
} zdwm_rect_t;
|
||||
|
||||
typedef struct zdwm_output_info_t {
|
||||
const char *name;
|
||||
zdwm_rect_t geometry;
|
||||
} zdwm_output_info_t;
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZDWM_TYPES_H */
|
||||
Reference in New Issue
Block a user