diff --git a/src/core/state.c b/src/core/state.c index d8faebc..40da138 100644 --- a/src/core/state.c +++ b/src/core/state.c @@ -1,6 +1,7 @@ #include "core/state.h" #include +#include #include #include @@ -267,6 +268,14 @@ bool state_output_valid(const state_t *state, output_id_t id) { #endif } +void state_cycle_current_output(state_t *state, int delta) { + int64_t count = (int64_t)state->output_count; + int64_t current = (int64_t)state->current_output_index; + int64_t next = (current + (int64_t)delta) % count; + if (next < 0) next += count; + state->current_output_index = (size_t)next; +} + static inline void window_set_geometry_mode( window_t *window, window_geometry_mode_t geometry_mode) { window->geometry_mode = geometry_mode; diff --git a/src/core/state.h b/src/core/state.h index d8c43a1..ee156af 100644 --- a/src/core/state.h +++ b/src/core/state.h @@ -65,6 +65,7 @@ typedef struct state_t { output_t *outputs; size_t output_count; + size_t current_output_index; window_t *windows; size_t window_count; @@ -129,6 +130,7 @@ void state_output_set_current_workspace(state_t *state, output_id_t output_id, workspace_id_t workspace_id); size_t state_output_count(const state_t *state); bool state_output_valid(const state_t *state, output_id_t id); +void state_cycle_current_output(state_t *state, int delta); /* * state 持有的 window 集合接口