refactor(action): 重新设计 action 实现方式
This commit is contained in:
@@ -3,30 +3,29 @@
|
||||
#include <stdint.h>
|
||||
#include <zdwm/action.h>
|
||||
|
||||
typedef struct runtime_t runtime_t;
|
||||
|
||||
void spawn(const char *command);
|
||||
void quit(zdwm_runtime_t *runtime, bool restart);
|
||||
void quit(runtime_t *runtime, bool restart);
|
||||
void raise_or_run(
|
||||
zdwm_runtime_t *runtime,
|
||||
runtime_t *runtime,
|
||||
const char *class_name,
|
||||
const char *command
|
||||
);
|
||||
|
||||
void toggle_fullscreen(zdwm_runtime_t *runtime);
|
||||
void toggle_maximize(zdwm_runtime_t *runtime);
|
||||
void toggle_floating(zdwm_runtime_t *runtime);
|
||||
void toggle_sticky(zdwm_runtime_t *runtime);
|
||||
void switch_workspace(
|
||||
zdwm_runtime_t *runtime,
|
||||
zdwm_workspace_id_t workspace_id
|
||||
);
|
||||
void toggle_fullscreen(runtime_t *runtime);
|
||||
void toggle_maximize(runtime_t *runtime);
|
||||
void toggle_floating(runtime_t *runtime);
|
||||
void toggle_sticky(runtime_t *runtime);
|
||||
void switch_workspace(runtime_t *runtime, zdwm_workspace_id_t workspace_id);
|
||||
void switch_workspace_in_current_output(
|
||||
zdwm_runtime_t *runtime,
|
||||
runtime_t *runtime,
|
||||
zdwm_workspace_id_t workspace_id
|
||||
);
|
||||
void switch_workspace_by_index_in_current_output(
|
||||
zdwm_runtime_t *runtime,
|
||||
runtime_t *runtime,
|
||||
uint32_t index
|
||||
);
|
||||
void cycle_layout(zdwm_runtime_t *runtime, int32_t delta);
|
||||
void cycle_current_output(zdwm_runtime_t *runtime, int32_t delta);
|
||||
void focus_window(zdwm_runtime_t *runtime, int32_t delta);
|
||||
void cycle_layout(runtime_t *runtime, int32_t delta);
|
||||
void cycle_current_output(runtime_t *runtime, int32_t delta);
|
||||
void focus_window(runtime_t *runtime, int32_t delta);
|
||||
|
||||
@@ -43,8 +43,7 @@ binding_table_add_mode(binding_table_t *table, const char *mode_name) {
|
||||
}
|
||||
|
||||
zdwm_binding_mode_id_t id = (zdwm_binding_mode_id_t)table->count;
|
||||
binding_mode_t *new_mode =
|
||||
array_push(table->modes, table->count, table->capacity);
|
||||
auto new_mode = array_push(table->modes, table->count, table->capacity);
|
||||
new_mode->name = mode_name;
|
||||
new_mode->id = id;
|
||||
|
||||
@@ -166,8 +165,7 @@ bool binding_table_add_bind(
|
||||
binding_table_t *table,
|
||||
zdwm_binding_mode_id_t mode_id,
|
||||
const char *key_sequence,
|
||||
zdwm_action_fn fn,
|
||||
zdwm_action_arg_t arg
|
||||
zdwm_action_t action
|
||||
) {
|
||||
binding_mode_t *mode = binding_table_get_mode(table, mode_id);
|
||||
if (!mode) return false;
|
||||
@@ -176,12 +174,11 @@ bool binding_table_add_bind(
|
||||
xkb_keysym_t keysym = XKB_KEY_NoSymbol;
|
||||
if (!parse_key_sequence(key_sequence, &modifiers, &keysym)) return false;
|
||||
|
||||
key_binding_t *item = array_push(mode->items, mode->count, mode->capacity);
|
||||
item->key_str = key_sequence;
|
||||
item->modifiers = modifiers;
|
||||
item->keysym = keysym;
|
||||
item->fn = fn;
|
||||
item->arg = arg;
|
||||
auto item = array_push(mode->items, mode->count, mode->capacity);
|
||||
item->key_str = key_sequence;
|
||||
item->modifiers = modifiers;
|
||||
item->keysym = keysym;
|
||||
item->action = action;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -12,8 +12,7 @@ typedef struct key_binding_t {
|
||||
const char *key_str;
|
||||
modifier_mask_t modifiers;
|
||||
keysym_t keysym;
|
||||
zdwm_action_fn *fn;
|
||||
zdwm_action_arg_t arg;
|
||||
zdwm_action_t action;
|
||||
} key_binding_t;
|
||||
|
||||
/**
|
||||
@@ -37,8 +36,7 @@ binding_table_add_mode(binding_table_t *table, const char *mode_name);
|
||||
* @param table 按键绑定表
|
||||
* @param mode_id 模式 ID
|
||||
* @param key_sequence 按键序列的字符串表达
|
||||
* @param fn 用户行为函数
|
||||
* @param arg 用户行为函数所需的参数
|
||||
* @param action 用户行为描述
|
||||
*
|
||||
* @return 添加成功返回 true 否则返回 false
|
||||
*/
|
||||
@@ -46,8 +44,7 @@ bool binding_table_add_bind(
|
||||
binding_table_t *table,
|
||||
zdwm_binding_mode_id_t mode_id,
|
||||
const char *key_sequence,
|
||||
zdwm_action_fn fn,
|
||||
zdwm_action_arg_t arg
|
||||
zdwm_action_t action
|
||||
);
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,8 +18,17 @@
|
||||
#include "core/window.h"
|
||||
#include "core/wm_desc.h"
|
||||
|
||||
static void
|
||||
route_key_press(const policy_context_t *ctx, const key_press_event_t *e) {
|
||||
static void policy_resolve_action(
|
||||
const state_t *state,
|
||||
const zdwm_action_t *action,
|
||||
command_buffer_t *out
|
||||
) {}
|
||||
|
||||
static void route_key_press(
|
||||
const policy_context_t *ctx,
|
||||
const key_press_event_t *e,
|
||||
command_buffer_t *out
|
||||
) {
|
||||
auto binding_table = ctx->bind_table;
|
||||
|
||||
size_t count = 0;
|
||||
@@ -29,7 +38,8 @@ route_key_press(const policy_context_t *ctx, const key_press_event_t *e) {
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
auto binding = &bindings[i];
|
||||
if (binding->modifiers == e->modifiers && binding->keysym == e->keysym) {
|
||||
binding->fn(ctx->runtime, &ctx->action_api, &binding->arg);
|
||||
policy_resolve_action(ctx->state, &binding->action, out);
|
||||
/* binding->fn(ctx->runtime, &ctx->action_api, &binding->arg); */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -264,7 +274,7 @@ void policy_route_event(
|
||||
auto state = ctx->state;
|
||||
switch (event->type) {
|
||||
case ZDWM_EVENT_KEY_PRESS:
|
||||
route_key_press(ctx, &event->as.key_press);
|
||||
route_key_press(ctx, &event->as.key_press, out);
|
||||
break;
|
||||
case ZDWM_EVENT_POINTER_ENTER:
|
||||
route_pointer_enter(state, event->as.pointer_enter.window, out);
|
||||
|
||||
@@ -17,8 +17,6 @@ typedef struct policy_context_t {
|
||||
const rules_t *rules;
|
||||
const border_config_t *border;
|
||||
const layout_registry_t *layouts;
|
||||
const zdwm_action_api_t action_api;
|
||||
zdwm_runtime_t *runtime;
|
||||
} policy_context_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -266,25 +266,6 @@ static policy_context_t policy_context_init(runtime_t *runtime) {
|
||||
.rules = &(runtime)->rules,
|
||||
.border = &(runtime)->border,
|
||||
.layouts = &(runtime)->layouts,
|
||||
.runtime = (runtime),
|
||||
.action_api = {
|
||||
.spawn = spawn,
|
||||
.quit = quit,
|
||||
.raise_or_run = raise_or_run,
|
||||
.toggle_fullscreen = toggle_fullscreen,
|
||||
.toggle_maximize = toggle_maximize,
|
||||
.toggle_floating = toggle_floating,
|
||||
.toggle_sticky = toggle_sticky,
|
||||
|
||||
.switch_workspace = switch_workspace,
|
||||
.switch_workspace_in_current_output = switch_workspace_in_current_output,
|
||||
.switch_workspace_by_index_in_current_output =
|
||||
switch_workspace_by_index_in_current_output,
|
||||
|
||||
.cycle_layout = cycle_layout,
|
||||
.cycle_current_output = cycle_current_output,
|
||||
.focus_window = focus_window,
|
||||
},
|
||||
};
|
||||
return ctx;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ typedef struct runtime_init_desc_t {
|
||||
listeners_t listeners;
|
||||
} runtime_init_desc_t;
|
||||
|
||||
typedef struct zdwm_runtime_t {
|
||||
typedef struct runtime_t {
|
||||
bool running;
|
||||
bool will_restart;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user