Compare commits
2 Commits
a60d9f31a7
...
0d4a907dd8
| Author | SHA1 | Date | |
|---|---|---|---|
|
0d4a907dd8
|
|||
|
1f4659e7a4
|
@@ -34,6 +34,14 @@ typedef struct zdwm_action_api_t {
|
|||||||
zdwm_runtime_t *runtime,
|
zdwm_runtime_t *runtime,
|
||||||
zdwm_workspace_id_t workspace_id
|
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_layout)(zdwm_runtime_t *runtime, int32_t delta);
|
||||||
void (*cycle_current_output)(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 (*focus_window)(zdwm_runtime_t *runtime, int32_t delta);
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
#include "config/defaults.h"
|
#include "config/defaults.h"
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <zdwm/action.h>
|
#include <zdwm/action.h>
|
||||||
#include <zdwm/types.h>
|
#include <zdwm/types.h>
|
||||||
|
|
||||||
|
#include "base/log.h"
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
|
#include "core/types.h"
|
||||||
|
|
||||||
static constexpr char launcher[] =
|
static constexpr char launcher[] =
|
||||||
"rofi -show combi -modes combi -combi-modes window,drun,run,ssh,windowcd";
|
"rofi -show combi -modes combi -combi-modes window,drun,run,ssh,windowcd";
|
||||||
@@ -67,6 +72,14 @@ static void toggle_floating(
|
|||||||
api->toggle_floating(runtime);
|
api->toggle_floating(runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void switch_workspace(
|
||||||
|
zdwm_runtime_t *runtime,
|
||||||
|
const zdwm_action_api_t *api,
|
||||||
|
const zdwm_action_arg_t *arg
|
||||||
|
) {
|
||||||
|
api->switch_workspace_by_index_in_current_output(runtime, arg->ui);
|
||||||
|
}
|
||||||
|
|
||||||
static void focus_window(
|
static void focus_window(
|
||||||
zdwm_runtime_t *runtime,
|
zdwm_runtime_t *runtime,
|
||||||
const zdwm_action_api_t *api,
|
const zdwm_action_api_t *api,
|
||||||
@@ -119,17 +132,26 @@ bool config_defaults_build(
|
|||||||
fullscreen_id,
|
fullscreen_id,
|
||||||
floating_id,
|
floating_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 0; i < output_count; i++) {
|
for (size_t i = 0; i < output_count; i++) {
|
||||||
if (api->define_workspace(
|
#define DEF_WORKSPACE(NAME) \
|
||||||
builder,
|
api->define_workspace( \
|
||||||
i,
|
builder, \
|
||||||
"main",
|
i, \
|
||||||
layout_ids,
|
(NAME), \
|
||||||
countof(layout_ids),
|
layout_ids, \
|
||||||
fair_id
|
countof(layout_ids), \
|
||||||
) == ZDWM_WORKSPACE_ID_INVALID) {
|
fair_id \
|
||||||
return false;
|
)
|
||||||
|
char *workspace_names[] = {"1 terminal", "2 Editor", "3 Browser"};
|
||||||
|
for (size_t j = 0; j < countof(workspace_names); ++j) {
|
||||||
|
auto workspace = DEF_WORKSPACE(workspace_names[j]);
|
||||||
|
if (workspace_id_invalid(workspace)) {
|
||||||
|
logger("== define workspace \"%s\" failed\n", workspace_names[j]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#undef DEF_WORKSPACE
|
||||||
}
|
}
|
||||||
|
|
||||||
auto default_mode = api->add_mode(builder, "default");
|
auto default_mode = api->add_mode(builder, "default");
|
||||||
@@ -154,11 +176,17 @@ bool config_defaults_build(
|
|||||||
BIND(default_mode, Alt "+j", focus_window, {.i = 1});
|
BIND(default_mode, Alt "+j", focus_window, {.i = 1});
|
||||||
BIND(default_mode, Alt "+k", focus_window, {.i = -1});
|
BIND(default_mode, Alt "+k", focus_window, {.i = -1});
|
||||||
|
|
||||||
|
char buffer[64] = {0};
|
||||||
|
for (uint32_t i = 0; i < 9; ++i) {
|
||||||
|
snprintf(buffer, sizeof(buffer), "%s+%d", Super, i + 1);
|
||||||
|
BIND(default_mode, buffer, switch_workspace, {.ui = i});
|
||||||
|
}
|
||||||
|
|
||||||
#undef BIND
|
#undef BIND
|
||||||
|
|
||||||
api->set_default_mode(builder, default_mode);
|
api->set_default_mode(builder, default_mode);
|
||||||
api->set_initial_mode(builder, default_mode);
|
api->set_initial_mode(builder, default_mode);
|
||||||
api->set_border_config(builder, 2, "#444444", "#005577");
|
api->set_border_config(builder, 2, "#1c2022", "#606060");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ static bool
|
|||||||
rule_action_valid(const rule_action_t *action, size_t workspace_count) {
|
rule_action_valid(const rule_action_t *action, size_t workspace_count) {
|
||||||
if (!action) return false;
|
if (!action) return false;
|
||||||
|
|
||||||
if (action->workspace == ZDWM_WORKSPACE_ID_INVALID) {
|
if (workspace_id_invalid(action->workspace)) {
|
||||||
return action->switch_to_workspace || action->fullscreen ||
|
return action->switch_to_workspace || action->fullscreen ||
|
||||||
action->maximize || action->floating;
|
action->maximize || action->floating;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -164,6 +164,45 @@ void switch_workspace(runtime_t *runtime, workspace_id_t workspace_id) {
|
|||||||
command_buffer_push(&runtime->command_buffer, &switch_workspace_cmd);
|
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) {
|
void cycle_layout(runtime_t *runtime, int32_t delta) {
|
||||||
auto state = &runtime->state;
|
auto state = &runtime->state;
|
||||||
auto output = state_output_at(state, state->current_output_index);
|
auto output = state_output_at(state, state->current_output_index);
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ void switch_workspace(
|
|||||||
zdwm_runtime_t *runtime,
|
zdwm_runtime_t *runtime,
|
||||||
zdwm_workspace_id_t workspace_id
|
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_layout(zdwm_runtime_t *runtime, int32_t delta);
|
||||||
void cycle_current_output(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 focus_window(zdwm_runtime_t *runtime, int32_t delta);
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ static void route_map_request(
|
|||||||
bool have_rule_match = rules_resolve(rules, &e->metadata, &action);
|
bool have_rule_match = rules_resolve(rules, &e->metadata, &action);
|
||||||
if (have_rule_match) {
|
if (have_rule_match) {
|
||||||
manage_window_command_t *data = &manage_window_cmd.as.manage_window;
|
manage_window_command_t *data = &manage_window_cmd.as.manage_window;
|
||||||
if (action.workspace != ZDWM_WORKSPACE_ID_INVALID) {
|
if (!workspace_id_invalid(action.workspace)) {
|
||||||
data->workspace = action.workspace;
|
data->workspace = action.workspace;
|
||||||
}
|
}
|
||||||
if (action.floating) data->floating = true;
|
if (action.floating) data->floating = true;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ rule_match_window(const rule_match_t *match, const window_metadata_t *meta) {
|
|||||||
static void rule_action_merge(const rule_action_t *src, rule_action_t *dest) {
|
static void rule_action_merge(const rule_action_t *src, rule_action_t *dest) {
|
||||||
if (!src || !dest) return;
|
if (!src || !dest) return;
|
||||||
|
|
||||||
if (src->workspace != ZDWM_WORKSPACE_ID_INVALID) {
|
if (!workspace_id_invalid(src->workspace)) {
|
||||||
dest->workspace = src->workspace;
|
dest->workspace = src->workspace;
|
||||||
}
|
}
|
||||||
dest->switch_to_workspace |= src->switch_to_workspace;
|
dest->switch_to_workspace |= src->switch_to_workspace;
|
||||||
|
|||||||
@@ -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 = {
|
policy_context_t ctx = {
|
||||||
.bind_table = (runtime)->binding_table,
|
.bind_table = (runtime)->binding_table,
|
||||||
.state = &(runtime)->state,
|
.state = &(runtime)->state,
|
||||||
@@ -266,14 +266,19 @@ policy_context_t policy_context_init(runtime_t *runtime) {
|
|||||||
.layouts = &(runtime)->layouts,
|
.layouts = &(runtime)->layouts,
|
||||||
.runtime = (runtime),
|
.runtime = (runtime),
|
||||||
.action_api = {
|
.action_api = {
|
||||||
.spawn = spawn,
|
.spawn = spawn,
|
||||||
.quit = quit,
|
.quit = quit,
|
||||||
.raise_or_run = raise_or_run,
|
.raise_or_run = raise_or_run,
|
||||||
.toggle_fullscreen = toggle_fullscreen,
|
.toggle_fullscreen = toggle_fullscreen,
|
||||||
.toggle_maximize = toggle_maximize,
|
.toggle_maximize = toggle_maximize,
|
||||||
.toggle_floating = toggle_floating,
|
.toggle_floating = toggle_floating,
|
||||||
.toggle_sticky = toggle_sticky,
|
.toggle_sticky = toggle_sticky,
|
||||||
.switch_workspace = switch_workspace,
|
|
||||||
|
.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_layout = cycle_layout,
|
||||||
.cycle_current_output = cycle_current_output,
|
.cycle_current_output = cycle_current_output,
|
||||||
.focus_window = focus_window,
|
.focus_window = focus_window,
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void state_init(
|
|||||||
workspace->layout_count = workspace_desc->layout_count;
|
workspace->layout_count = workspace_desc->layout_count;
|
||||||
workspace->name = p_strdup(workspace_desc->name);
|
workspace->name = p_strdup(workspace_desc->name);
|
||||||
|
|
||||||
if (output->current_workspace_id == ZDWM_WORKSPACE_ID_INVALID) {
|
if (workspace_id_invalid(output->current_workspace_id)) {
|
||||||
output->current_workspace_id = workspace->id;
|
output->current_workspace_id = workspace->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +62,7 @@ void state_init(
|
|||||||
|
|
||||||
for (size_t i = 0; i < state->output_count; i++) {
|
for (size_t i = 0; i < state->output_count; i++) {
|
||||||
const output_t *output = &state->outputs[i];
|
const output_t *output = &state->outputs[i];
|
||||||
if (output->current_workspace_id == ZDWM_WORKSPACE_ID_INVALID) {
|
if (workspace_id_invalid(output->current_workspace_id)) {
|
||||||
fatal("output at index %zu has no workspace", i);
|
fatal("output at index %zu has no workspace", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,3 +105,7 @@ typedef struct only_window_data_t {
|
|||||||
static inline bool window_id_invalid(window_id_t window_id) {
|
static inline bool window_id_invalid(window_id_t window_id) {
|
||||||
return window_id == ZDWM_WINDOW_ID_INVALID;
|
return window_id == ZDWM_WINDOW_ID_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool workspace_id_invalid(workspace_id_t workspace_id) {
|
||||||
|
return workspace_id == ZDWM_WORKSPACE_ID_INVALID;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user