From ecc9834b038e1a085fb6044bb625551b3b92a1ec Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Mon, 4 May 2026 17:52:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor(command):=20=E4=BB=8E=20switch=5Fworks?= =?UTF-8?q?pace=20=E5=91=BD=E4=BB=A4=E4=B8=AD=E7=A7=BB=E9=99=A4=E5=86=97?= =?UTF-8?q?=E4=BD=99=E7=9A=84=20output=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/command.h | 1 - src/core/policy.c | 39 +++++++++++++++++---------------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/core/command.h b/src/core/command.h index dd52a68..652398f 100644 --- a/src/core/command.h +++ b/src/core/command.h @@ -21,7 +21,6 @@ typedef struct manage_window_command_t { } manage_window_command_t; typedef struct switch_workspace_command_t { - output_id_t output; workspace_id_t workspace; } switch_workspace_command_t; diff --git a/src/core/policy.c b/src/core/policy.c index f88d94d..bcc6c5d 100644 --- a/src/core/policy.c +++ b/src/core/policy.c @@ -101,22 +101,18 @@ static void route_map_request( } command_buffer_push(out, &manage_window_cmd); - if (have_rule_match && action.switch_to_workspace) { - workspace_id_t workspace_id = manage_window_cmd.as.manage_window.workspace; - const workspace_t *workspace = state_workspace_get(state, workspace_id); + if (!have_rule_match || !action.switch_to_workspace) return; - if (workspace) { - command_t switch_workspace_cmd = { - .type = ZDWM_COMMAND_SWITCH_WORKSPACE, - .as.switch_workspace = { - .output = workspace->output_id, - .workspace = workspace_id, - }, - }; + workspace_id_t workspace_id = manage_window_cmd.as.manage_window.workspace; + const workspace_t *workspace = state_workspace_get(state, workspace_id); + if (!workspace) return; - command_buffer_push(out, &switch_workspace_cmd); - } - } + command_t switch_workspace_cmd = { + .type = ZDWM_COMMAND_SWITCH_WORKSPACE, + .as.switch_workspace.workspace = workspace_id, + }; + + command_buffer_push(out, &switch_workspace_cmd); } static void route_window_remove( @@ -589,13 +585,12 @@ static void change_window_state( } } -static void switch_workspace( - state_t *state, - const switch_workspace_command_t *command, - plan_t *plan -) { - auto output_id = command->output; - auto workspace_id = command->workspace; +static void +switch_workspace(state_t *state, workspace_id_t workspace_id, plan_t *plan) { + auto workspace = state_workspace_get(state, workspace_id); + if (!workspace) return; + + auto output_id = workspace->output_id; workspace_id_t old_workspace = ZDWM_WORKSPACE_ID_INVALID; if (state_output_set_current_workspace( @@ -642,7 +637,7 @@ void policy_apply_command( change_window_state(ctx, &cmd->as.state_change, plan); break; case ZDWM_COMMAND_SWITCH_WORKSPACE: - switch_workspace(state, &cmd->as.switch_workspace, plan); + switch_workspace(state, cmd->as.switch_workspace.workspace, plan); break; } }