A bit renaming; add license notice to every file

timeout_old
Tassilo Horn 3 years ago
parent 41199b2f09
commit 08b69d788f
  1. 23
      src/bin/swayr.rs
  2. 19
      src/bin/swayrd.rs
  3. 15
      src/client.rs
  4. 19
      src/cmds.rs
  5. 21
      src/con.rs
  6. 21
      src/config.rs
  7. 15
      src/demon.rs
  8. 15
      src/ipc.rs
  9. 19
      src/lib.rs
  10. 40
      src/util.rs

@ -1,25 +1,38 @@
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
//! 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 <tsdh@gnu.org>"
)]
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);
}
}

@ -1,7 +1,20 @@
//! The `swayrd` binary.
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
use swayr::demon;
//! The `swayrd` binary.
fn main() {
demon::run_demon();
swayr::demon::run_demon();
}

@ -1,3 +1,18 @@
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
use crate::ipc;
use crate::util;
use std::io::Write;

@ -1,3 +1,18 @@
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
//! 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);
}

@ -1,3 +1,18 @@
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
//! 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> {

@ -1,3 +1,20 @@
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
//! 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}<b>“{title}”</b>{urgency_end}\t<i>{app_name}</i> on workspace {workspace_name}\t<span alpha=\"20000\">({id})</span>"
"{urgency_start}<b>“{title}”</b>{urgency_end} — <i>{app_name}</i> on workspace {workspace_name} <span alpha=\"20000\">({id})</span>"
.to_string(),
),
workspace_format: Some("<b>Workspace {name}</b>\t<span alpha=\"20000\">({id})</span>".to_string()),
workspace_format: Some("<b>Workspace {name}</b> <span alpha=\"20000\">({id})</span>".to_string()),
urgency_start: Some("<span background=\"darkred\" foreground=\"yellow\">".to_string()),
urgency_end: Some("</span>".to_string())
}),

@ -1,3 +1,18 @@
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
//! Functions and data structures of the swayrd demon.
use crate::cmds;

@ -1,3 +1,18 @@
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
//! Extensions of swayipc types and IPC structs.
use clap::Clap;

@ -1,10 +1,25 @@
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
// 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`.

@ -1,4 +1,19 @@
//! Utility functions including wofi-selection.
// Copyright (C) 2021 Tassilo Horn <tsdh@gnu.org>
//
// 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 <https://www.gnu.org/licenses/>.
//! 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.

Loading…
Cancel
Save