feat(action): 实现切换当前 output 工作区功能

This commit is contained in:
2026-05-09 23:00:01 +08:00
parent 1f4659e7a4
commit 0d4a907dd8
5 changed files with 107 additions and 19 deletions

View File

@@ -164,6 +164,45 @@ void switch_workspace(runtime_t *runtime, workspace_id_t workspace_id) {
command_buffer_push(&runtime->command_buffer, &switch_workspace_cmd);
}
void switch_workspace_in_current_output(
runtime_t *runtime,
workspace_id_t workspace_id
) {
auto state = &runtime->state;
auto output = state_output_at(state, state->current_output_index);
auto workspace = state_workspace_get(state, workspace_id);
if (workspace->output_id != output->id) return;
command_t switch_workspace_cmd = {
.type = ZDWM_COMMAND_SWITCH_WORKSPACE,
.as.switch_workspace.workspace = workspace_id
};
command_buffer_push(&runtime->command_buffer, &switch_workspace_cmd);
}
void switch_workspace_by_index_in_current_output(
runtime_t *runtime,
uint32_t index
) {
auto state = &runtime->state;
auto output = state_output_at(state, state->current_output_index);
uint32_t count = 0;
for (size_t i = 0; i < state_window_count(state); ++i) {
auto workspace = state_workspace_at(state, i);
if (workspace->output_id != output->id) continue;
if (count == index) {
command_t switch_workspace_cmd = {
.type = ZDWM_COMMAND_SWITCH_WORKSPACE,
.as.switch_workspace.workspace = workspace->id,
};
command_buffer_push(&runtime->command_buffer, &switch_workspace_cmd);
return;
}
count++;
}
}
void cycle_layout(runtime_t *runtime, int32_t delta) {
auto state = &runtime->state;
auto output = state_output_at(state, state->current_output_index);

View File

@@ -19,6 +19,14 @@ void switch_workspace(
zdwm_runtime_t *runtime,
zdwm_workspace_id_t workspace_id
);
void switch_workspace_in_current_output(
zdwm_runtime_t *runtime,
zdwm_workspace_id_t workspace_id
);
void switch_workspace_by_index_in_current_output(
zdwm_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);

View File

@@ -257,7 +257,7 @@ static void runtime_arrange(runtime_t *runtime) {
}
}
policy_context_t policy_context_init(runtime_t *runtime) {
static policy_context_t policy_context_init(runtime_t *runtime) {
policy_context_t ctx = {
.bind_table = (runtime)->binding_table,
.state = &(runtime)->state,
@@ -266,14 +266,19 @@ policy_context_t policy_context_init(runtime_t *runtime) {
.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,
.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,