feat(action): 实现 switch_workspace cycle_layout 和 cycle_output 操作
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <paths.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
@@ -151,3 +152,28 @@ void toggle_sticky(runtime_t *runtime) {
|
||||
};
|
||||
command_buffer_push(&runtime->command_buffer, &window_set_sticky_cmd);
|
||||
}
|
||||
|
||||
void switch_workspace(runtime_t *runtime, workspace_id_t workspace_id) {
|
||||
auto workspace = state_workspace_get(&runtime->state, workspace_id);
|
||||
if (!workspace) 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 cycle_layout(runtime_t *runtime, int32_t delta) {
|
||||
auto state = &runtime->state;
|
||||
auto output = state_output_at(state, state->current_output_index);
|
||||
auto workspace = state_workspace_get(state, output->current_workspace_id);
|
||||
if (!state_workspace_cycle_layout(state, workspace->id, delta)) return;
|
||||
|
||||
runtime->plan.need_relayout = true;
|
||||
}
|
||||
|
||||
void cycle_current_output(zdwm_runtime_t *runtime, int32_t delta) {
|
||||
auto state = &runtime->state;
|
||||
state_cycle_current_output(state, delta);
|
||||
}
|
||||
|
||||
@@ -145,24 +145,35 @@ static void state_workspace_adjust_focused_window(
|
||||
workspace->focused_window_id = ZDWM_WINDOW_ID_INVALID;
|
||||
}
|
||||
|
||||
bool state_workspace_cycle_layout(state_t *state, workspace_id_t workspace_id) {
|
||||
bool state_workspace_cycle_layout(
|
||||
state_t *state,
|
||||
workspace_id_t workspace_id,
|
||||
int32_t delta
|
||||
) {
|
||||
workspace_t *workspace =
|
||||
(workspace_t *)state_workspace_get(state, workspace_id);
|
||||
if (!workspace) return false;
|
||||
|
||||
size_t next_index = 0;
|
||||
int32_t index = 0;
|
||||
bool matched = false;
|
||||
for (size_t i = 0; i < workspace->layout_count; i++) {
|
||||
auto layout_count = (int32_t)workspace->layout_count;
|
||||
for (int32_t i = 0; i < layout_count; i++) {
|
||||
if (workspace->layout_id == workspace->available_layouts[i]) {
|
||||
next_index = (i + 1) % workspace->layout_count;
|
||||
matched = true;
|
||||
index = i;
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!matched) return false;
|
||||
|
||||
auto next_layout_id = workspace->available_layouts[next_index];
|
||||
auto new_index = index + delta;
|
||||
new_index %= layout_count;
|
||||
if (new_index < 0) new_index += layout_count;
|
||||
|
||||
if (new_index == index) return false;
|
||||
|
||||
auto next_layout_id = workspace->available_layouts[new_index];
|
||||
workspace->layout_id = next_layout_id;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,11 @@ void state_cleanup(state_t *state);
|
||||
*/
|
||||
const workspace_t *state_workspace_get(const state_t *state, workspace_id_t id);
|
||||
const workspace_t *state_workspace_at(const state_t *state, size_t index);
|
||||
bool state_workspace_cycle_layout(state_t *state, workspace_id_t workspace_id);
|
||||
bool state_workspace_cycle_layout(
|
||||
state_t *state,
|
||||
workspace_id_t workspace_id,
|
||||
int32_t delta
|
||||
);
|
||||
bool state_workspace_set_layout_by_index(
|
||||
state_t *state,
|
||||
workspace_id_t workspace_id,
|
||||
|
||||
Reference in New Issue
Block a user