From 08b69d788fff7a337206e6caff5b8e310e1e771b Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sat, 26 Jun 2021 07:43:06 +0200 Subject: [PATCH] A bit renaming; add license notice to every file --- src/bin/swayr.rs | 23 ++++++++++++++++++----- src/bin/swayrd.rs | 19 ++++++++++++++++--- src/client.rs | 15 +++++++++++++++ src/cmds.rs | 19 +++++++++++++++++-- src/con.rs | 21 ++++++++++++++++++--- src/config.rs | 21 +++++++++++++++++++-- src/demon.rs | 15 +++++++++++++++ src/ipc.rs | 15 +++++++++++++++ src/lib.rs | 19 +++++++++++++++++-- src/util.rs | 40 +++++++++++++++++++++++++++++----------- 10 files changed, 179 insertions(+), 28 deletions(-) diff --git a/src/bin/swayr.rs b/src/bin/swayr.rs index c9b3cfb..c3b5f80 100644 --- a/src/bin/swayr.rs +++ b/src/bin/swayr.rs @@ -1,25 +1,38 @@ +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + //! The `swayr` binary. use clap::{crate_version, Clap}; -use swayr::client; -use swayr::ipc; /// Windows are sorted urgent first, then windows in LRU order, focused window /// last. Licensed under the GPLv3 (or later). #[derive(Clap)] #[clap( - name = "swayr -- a window switcher for sway", + name = "swayr -- a window switcher (and more) for sway", version = crate_version!(), author = "Tassilo Horn " )] struct Opts { #[clap(subcommand)] - command: ipc::SwayrCommand, + command: swayr::ipc::SwayrCommand, } fn main() { let opts: Opts = Opts::parse(); - if let Err(err) = client::send_swayr_cmd(opts.command) { + if let Err(err) = swayr::client::send_swayr_cmd(opts.command) { eprintln!("Could not send command: {}", err); } } diff --git a/src/bin/swayrd.rs b/src/bin/swayrd.rs index f355768..98fb651 100644 --- a/src/bin/swayrd.rs +++ b/src/bin/swayrd.rs @@ -1,7 +1,20 @@ -//! The `swayrd` binary. +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . -use swayr::demon; +//! The `swayrd` binary. fn main() { - demon::run_demon(); + swayr::demon::run_demon(); } diff --git a/src/client.rs b/src/client.rs index e760899..e77ca9d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,3 +1,18 @@ +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + use crate::ipc; use crate::util; use std::io::Write; diff --git a/src/cmds.rs b/src/cmds.rs index dcf808c..2919cec 100644 --- a/src/cmds.rs +++ b/src/cmds.rs @@ -1,3 +1,18 @@ +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + //! Functions and data structures of the swayr client. use crate::con; @@ -62,7 +77,7 @@ pub fn exec_swayr_cmd(args: ExecSwayrCmdArgs) { } SwayrCommand::ExecuteSwaymsgCommand => exec_swaymsg_command(), SwayrCommand::ExecuteSwayrCommand => { - if let Some(c) = util::wofi_select( + if let Some(c) = util::select_from_choices( "Select swayr command", &[ SwayrCommand::ExecuteSwaymsgCommand, @@ -343,7 +358,7 @@ impl DisplayFormat for SwaymsgCmd<'_> { pub fn exec_swaymsg_command() { let cmds = get_swaymsg_commands(); - let cmd = util::wofi_select("Execute swaymsg command", &cmds); + let cmd = util::select_from_choices("Execute swaymsg command", &cmds); if let Some(cmd) = cmd { run_sway_command(&cmd.cmd); } diff --git a/src/con.rs b/src/con.rs index d0ff4cd..46d733e 100644 --- a/src/con.rs +++ b/src/con.rs @@ -1,3 +1,18 @@ +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + //! Convenience data structures built from the IPC structs. use crate::config as cfg; @@ -258,14 +273,14 @@ pub fn select_window<'a>( prompt: &str, windows: &'a [Window], ) -> Option<&'a Window<'a>> { - util::wofi_select(prompt, windows) + util::select_from_choices(prompt, windows) } pub fn select_workspace<'a>( prompt: &str, workspaces: &'a [Workspace], ) -> Option<&'a Workspace<'a>> { - util::wofi_select(prompt, workspaces) + util::select_from_choices(prompt, workspaces) } pub enum WsOrWin<'a> { @@ -315,7 +330,7 @@ pub fn select_workspace_or_window<'a>( prompt: &'a str, ws_or_wins: &'a [WsOrWin<'a>], ) -> Option<&'a WsOrWin<'a>> { - util::wofi_select(prompt, ws_or_wins) + util::select_from_choices(prompt, ws_or_wins) } pub struct Workspace<'a> { diff --git a/src/config.rs b/src/config.rs index 1c8cc09..f635a06 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,20 @@ +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + +//! TOML configuration for swayr. + use directories::ProjectDirs; use serde::{Deserialize, Serialize}; use std::fs::DirBuilder; @@ -28,10 +45,10 @@ impl Default for Config { }), format: Some(Format { window_format: Some( - "{urgency_start}“{title}”{urgency_end}\t{app_name} on workspace {workspace_name}\t({id})" + "{urgency_start}“{title}”{urgency_end} — {app_name} on workspace {workspace_name} ({id})" .to_string(), ), - workspace_format: Some("Workspace {name}\t({id})".to_string()), + workspace_format: Some("Workspace {name} ({id})".to_string()), urgency_start: Some("".to_string()), urgency_end: Some("".to_string()) }), diff --git a/src/demon.rs b/src/demon.rs index b61d9d2..c3eaeb0 100644 --- a/src/demon.rs +++ b/src/demon.rs @@ -1,3 +1,18 @@ +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + //! Functions and data structures of the swayrd demon. use crate::cmds; diff --git a/src/ipc.rs b/src/ipc.rs index e025918..7d95d09 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -1,3 +1,18 @@ +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + //! Extensions of swayipc types and IPC structs. use clap::Clap; diff --git a/src/lib.rs b/src/lib.rs index 73ee0af..6103e96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,25 @@ +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + // TODO: Possibly just include README.md when this feature is in the release // channel. // // #![doc(include = "../README.md")] -//! **Swayr** is a wofi-based LRU window-switcher and more for the sway window -//! manager. It consists of a demon, and a client. The demon `swayrd` records +//! **Swayr** is a LRU window-switcher and more for the sway window manager. +//! It consists of a demon, and a client. The demon `swayrd` records //! window/workspace creations, deletions, and focus changes using sway's JSON //! IPC interface. The client `swayr` offers subcommands, see `swayr --help`. diff --git a/src/util.rs b/src/util.rs index a9452e8..50d9634 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,19 @@ -//! Utility functions including wofi-selection. +// Copyright (C) 2021 Tassilo Horn +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation, either version 3 of the License, or (at your option) +// any later version. +// +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +// more details. +// +// You should have received a copy of the GNU General Public License along with +// this program. If not, see . + +//! Utility functions including selection between choices using a launcher. use crate::con::DisplayFormat; use crate::config as cfg; @@ -21,7 +36,7 @@ pub fn get_swayr_socket_path() -> String { ) } -pub fn wofi_select<'a, 'b, TS>( +pub fn select_from_choices<'a, 'b, TS>( prompt: &'a str, choices: &'b [TS], ) -> Option<&'b TS> @@ -38,7 +53,7 @@ where } let default = cfg::Config::default(); - let launcher = cfg + let launcher_exec = cfg .launcher .as_ref() .and_then(|l| l.executable.as_ref()) @@ -62,23 +77,26 @@ where .map(|a| a.replace("{prompt}", prompt)) .collect(); - let mut wofi = proc::Command::new(launcher) + let mut launcher = proc::Command::new(launcher_exec) .args(args) .stdin(proc::Stdio::piped()) .stdout(proc::Stdio::piped()) .spawn() - .expect(&("Error running ".to_owned() + launcher)); + .expect(&("Error running ".to_owned() + launcher_exec)); { - let stdin = wofi.stdin.as_mut().expect("Failed to open wofi stdin"); - let wofi_input = strs.join("\n"); - println!("Wofi input:\n{}", wofi_input); + let stdin = launcher + .stdin + .as_mut() + .expect("Failed to open the launcher's stdin"); + let input = strs.join("\n"); + println!("Launcher {} input:\n{}", launcher_exec, input); stdin - .write_all(wofi_input.as_bytes()) - .expect("Failed to write to wofi stdin"); + .write_all(input.as_bytes()) + .expect("Failed to write to the launcher's stdin"); } - let output = wofi.wait_with_output().expect("Failed to read stdout"); + let output = launcher.wait_with_output().expect("Failed to read stdout"); let choice = String::from_utf8_lossy(&output.stdout); let mut choice = String::from(choice); choice.pop(); // Remove trailing \n from choice.