New subcommand execute-swayr-command

timeout_old
Tassilo Horn 4 years ago
parent a645d067b0
commit f7a0ca24f5
  1. 3
      README.md
  2. 31
      src/bin/swayr.rs
  3. 2
      src/bin/swayrd.rs
  4. 51
      src/client.rs
  5. 10
      src/demon.rs

@ -18,6 +18,9 @@ Right now, there are these subcommands:
* `execute-swaymsg-command` displays most swaymsg which don't require
additional input and executes the selected one. That's handy especially for
less often used commands not bound to a key.
* `execute-swayr-command` displays all commands above and executes the selected
one. (This is useful for accessing swayr commands which are not bound to a
key.)
Swayr is licensed under the

@ -13,37 +13,10 @@ use swayr::client;
)]
struct Opts {
#[clap(subcommand)]
command: SwayrCommand,
}
#[derive(Clap)]
enum SwayrCommand {
/// Focus the selected window
SwitchWindow,
/// Quit the selected window
QuitWindow,
/// Switch to the selected workspace
SwitchWorkspace,
/// Switch to the selected workspace or focus the selected window
SwitchWorkspaceOrWindow,
/// Quit all windows of selected workspace or the selected window
QuitWorkspaceOrWindow,
/// Select and execute a swaymsg command
ExecuteSwaymsgCommand,
command: client::SwayrCommand,
}
fn main() {
let opts: Opts = Opts::parse();
match opts.command {
SwayrCommand::SwitchWindow => client::switch_window(),
SwayrCommand::QuitWindow => client::quit_window(),
SwayrCommand::SwitchWorkspace => client::switch_workspace(),
SwayrCommand::SwitchWorkspaceOrWindow => {
client::switch_workspace_or_window()
}
SwayrCommand::QuitWorkspaceOrWindow => {
client::quit_workspace_or_window()
}
SwayrCommand::ExecuteSwaymsgCommand => client::exec_swaymsg_command(),
}
client::exec_swayr_cmd(&opts.command);
}

@ -14,7 +14,7 @@ fn main() {
let con_props_for_ev_handler = con_props.clone();
let subscriber_handle = thread::spawn(move || {
demon::monitor_window_events(con_props_for_ev_handler)
demon::monitor_con_events(con_props_for_ev_handler)
});
match demon::serve_client_requests(con_props) {

@ -1,8 +1,59 @@
use crate::con;
use crate::ipc;
use crate::util;
use clap::Clap;
use std::fmt;
#[derive(Clap, Debug)]
pub enum SwayrCommand {
/// Focus the selected window
SwitchWindow,
/// Quit the selected window
QuitWindow,
/// Switch to the selected workspace
SwitchWorkspace,
/// Switch to the selected workspace or focus the selected window
SwitchWorkspaceOrWindow,
/// Quit all windows of selected workspace or the selected window
QuitWorkspaceOrWindow,
/// Select and execute a swaymsg command
ExecuteSwaymsgCommand,
/// Select and execute a swayr command
ExecuteSwayrCommand,
}
impl fmt::Display for SwayrCommand {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "{:?}", self)
}
}
pub fn exec_swayr_cmd(cmd: &SwayrCommand) {
match cmd {
SwayrCommand::SwitchWindow => switch_window(),
SwayrCommand::QuitWindow => quit_window(),
SwayrCommand::SwitchWorkspace => switch_workspace(),
SwayrCommand::SwitchWorkspaceOrWindow => switch_workspace_or_window(),
SwayrCommand::QuitWorkspaceOrWindow => quit_workspace_or_window(),
SwayrCommand::ExecuteSwaymsgCommand => exec_swaymsg_command(),
SwayrCommand::ExecuteSwayrCommand => {
if let Some(c) = util::wofi_select(
"Select swayr command",
&[
SwayrCommand::ExecuteSwaymsgCommand,
SwayrCommand::QuitWindow,
SwayrCommand::QuitWorkspaceOrWindow,
SwayrCommand::SwitchWindow,
SwayrCommand::SwitchWorkspace,
SwayrCommand::SwitchWorkspaceOrWindow,
],
) {
exec_swayr_cmd(c);
}
}
}
}
fn focus_window_by_id(id: &ipc::Id) {
util::swaymsg(&[format!("[con_id={}]", id).as_str(), "focus"]);
}

@ -10,7 +10,7 @@ use std::sync::RwLock;
use std::thread;
use std::time::{SystemTime, UNIX_EPOCH};
pub fn monitor_window_events(
pub fn monitor_con_events(
con_props: Arc<RwLock<HashMap<ipc::Id, ipc::ConProps>>>,
) {
let child = proc::Command::new("swaymsg")
@ -31,6 +31,8 @@ pub fn monitor_window_events(
Err(err) => eprintln!("Error handling window event:\n{:?}", err),
}
}
eprintln!("Stopped monitoring con events. Restarting...");
monitor_con_events(con_props);
}
fn update_last_focus_time(
@ -50,7 +52,7 @@ fn update_last_focus_time(
}
}
fn remove_winprops(
fn remove_con_props(
id: &ipc::Id,
con_props: Arc<RwLock<HashMap<ipc::Id, ipc::ConProps>>>,
) {
@ -70,7 +72,7 @@ fn handle_con_event(
update_last_focus_time(container.id, con_props)
}
ipc::WindowEventType::Close => {
remove_winprops(&container.id, con_props)
remove_con_props(&container.id, con_props)
}
_ => handled = false,
},
@ -84,7 +86,7 @@ fn handle_con_event(
update_last_focus_time(current.id, con_props)
}
ipc::WorkspaceEventType::Empty => {
remove_winprops(&current.id, con_props)
remove_con_props(&current.id, con_props)
}
_ => handled = false,
},

Loading…
Cancel
Save