Refactor exec_swayr_cmd args into separat struct

timeout_old
Tassilo Horn 4 years ago
parent 44492a77e0
commit 233be20479
  1. 36
      src/cmds.rs
  2. 5
      src/demon.rs

@ -13,42 +13,43 @@ use std::sync::RwLock;
use swayipc as s; use swayipc as s;
use swayipc::reply as r; use swayipc::reply as r;
pub struct ExecSwayrCmdArgs<'a> {
pub cmd: &'a SwayrCommand,
pub extra_props: Arc<RwLock<HashMap<i64, ipc::ExtraProps>>>,
}
impl fmt::Display for SwayrCommand { impl fmt::Display for SwayrCommand {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "<b>{:?}</b>", self) write!(f, "<b>{:?}</b>", self)
} }
} }
pub fn exec_swayr_cmd( pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) {
cmd: &SwayrCommand, let props = args.extra_props;
extra_props: Arc<RwLock<HashMap<i64, ipc::ExtraProps>>>, match args.cmd {
) {
match cmd {
SwayrCommand::SwitchToUrgentOrLRUWindow => { SwayrCommand::SwitchToUrgentOrLRUWindow => {
switch_to_urgent_or_lru_window(Some(&*extra_props.read().unwrap())) switch_to_urgent_or_lru_window(Some(&*props.read().unwrap()))
} }
SwayrCommand::SwitchWindow => { SwayrCommand::SwitchWindow => {
switch_window(Some(&*extra_props.read().unwrap())) switch_window(Some(&*props.read().unwrap()))
} }
SwayrCommand::NextWindow => focus_next_window_in_direction( SwayrCommand::NextWindow => focus_next_window_in_direction(
Direction::Forward, Direction::Forward,
Some(&*extra_props.read().unwrap()), Some(&*props.read().unwrap()),
), ),
SwayrCommand::PrevWindow => focus_next_window_in_direction( SwayrCommand::PrevWindow => focus_next_window_in_direction(
Direction::Backward, Direction::Backward,
Some(&*extra_props.read().unwrap()), Some(&*props.read().unwrap()),
), ),
SwayrCommand::QuitWindow => { SwayrCommand::QuitWindow => quit_window(Some(&*props.read().unwrap())),
quit_window(Some(&*extra_props.read().unwrap()))
}
SwayrCommand::SwitchWorkspace => { SwayrCommand::SwitchWorkspace => {
switch_workspace(Some(&*extra_props.read().unwrap())) switch_workspace(Some(&*props.read().unwrap()))
} }
SwayrCommand::SwitchWorkspaceOrWindow => { SwayrCommand::SwitchWorkspaceOrWindow => {
switch_workspace_or_window(Some(&*extra_props.read().unwrap())) switch_workspace_or_window(Some(&*props.read().unwrap()))
} }
SwayrCommand::QuitWorkspaceOrWindow => { SwayrCommand::QuitWorkspaceOrWindow => {
quit_workspace_or_window(Some(&*extra_props.read().unwrap())) quit_workspace_or_window(Some(&*props.read().unwrap()))
} }
SwayrCommand::ExecuteSwaymsgCommand => exec_swaymsg_command(), SwayrCommand::ExecuteSwaymsgCommand => exec_swaymsg_command(),
SwayrCommand::ExecuteSwayrCommand => { SwayrCommand::ExecuteSwayrCommand => {
@ -66,7 +67,10 @@ pub fn exec_swayr_cmd(
SwayrCommand::PrevWindow, SwayrCommand::PrevWindow,
], ],
) { ) {
exec_swayr_cmd(c, extra_props); exec_swayr_cmd(ExecSwayrCmdArgs {
cmd: c,
extra_props: props,
});
} }
} }
} }

@ -203,7 +203,10 @@ fn handle_client_request(
let mut cmd_str = String::new(); let mut cmd_str = String::new();
if stream.read_to_string(&mut cmd_str).is_ok() { if stream.read_to_string(&mut cmd_str).is_ok() {
if let Ok(cmd) = serde_json::from_str::<ipc::SwayrCommand>(&cmd_str) { if let Ok(cmd) = serde_json::from_str::<ipc::SwayrCommand>(&cmd_str) {
cmds::exec_swayr_cmd(&cmd, extra_props); cmds::exec_swayr_cmd(cmds::ExecSwayrCmdArgs {
cmd: &cmd,
extra_props,
});
} else { } else {
eprintln!( eprintln!(
"Could not serialize following string to SwayrCommand.\n{}", "Could not serialize following string to SwayrCommand.\n{}",

Loading…
Cancel
Save