Release v0.9.0-beta.2: #<letter>:<input> shortcuts for menu switcher cmds

timeout_old
Tassilo Horn 3 years ago
parent a85913af46
commit 311a92bd12
  1. 2
      Cargo.lock
  2. 2
      Cargo.toml
  3. 19
      NEWS.md
  4. 37
      src/cmds.rs

2
Cargo.lock generated

@ -360,7 +360,7 @@ dependencies = [
[[package]] [[package]]
name = "swayr" name = "swayr"
version = "0.9.0-beta.1" version = "0.9.0-beta.2"
dependencies = [ dependencies = [
"clap", "clap",
"directories", "directories",

@ -1,6 +1,6 @@
[package] [package]
name = "swayr" name = "swayr"
version = "0.9.0-beta.1" version = "0.9.0-beta.2"
description = "A LRU window-switcher (and more) for the sway window manager" description = "A LRU window-switcher (and more) for the sway window manager"
homepage = "https://sr.ht/~tsdh/swayr/" homepage = "https://sr.ht/~tsdh/swayr/"
repository = "https://git.sr.ht/~tsdh/swayr" repository = "https://git.sr.ht/~tsdh/swayr"

@ -5,12 +5,19 @@ swayr v0.9.0
show empty workspaces which makes it possible to switch to another output show empty workspaces which makes it possible to switch to another output
currently showing an empty workspace. currently showing an empty workspace.
- All menu switching commands (`switch-window`, `switch-workspace`, and - All menu switching commands (`switch-window`, `switch-workspace`, and
`switch-workspace-or-window`) can now create and switch to not yet existing `switch-workspace-or-window`) now handle non-matching input instead of doing
workspaces. Just type a digit, a name, or `<digit>:<name>`, confirm your nothing. The input should start with any number of `#` (in order to be able
input, and it'll do. The `<digit>:<name>` format is explained in `man 5 to force a non-match), a shortcut followed by a colon, and some string as
sway`. If that format is given, `swayr` will create the workspace using required by the shortcut. The following shortcuts are supported.
`workspace number <digit>:<name>`. If just a digit or name is given, the - `w:<workspace>`: Switches to a possibly non-existing workspace.
`number` argument is not used. `<workspace>` must be a digit, a name, or `<digit>:<name>`. The
`<digit>:<name>` format is explained in `man 5 sway`. If that format is
given, `swayr` will create the workspace using `workspace number
<digit>:<name>`. If just a digit or name is given, the `number` argument
is not used.
- `s:<cmd>`: Executes the sway command `<cmd>` using `swaymsg`.
- Any other input is assumed to be a workspace name and thus handled as
`w:<input>` would do.
swayr v0.8.0 swayr v0.8.0

@ -395,10 +395,10 @@ pub fn switch_to_urgent_or_lru_window(
lazy_static! { lazy_static! {
static ref DIGIT_AND_NAME: regex::Regex = static ref DIGIT_AND_NAME: regex::Regex =
regex::Regex::new(r"(\d):(.*)").unwrap(); regex::Regex::new(r"^(\d):(.*)").unwrap();
} }
pub fn create_workspace(ws_name: &str) { fn create_workspace(ws_name: &str) {
if DIGIT_AND_NAME.is_match(ws_name) { if DIGIT_AND_NAME.is_match(ws_name) {
run_sway_command(&["workspace", "number", ws_name]); run_sway_command(&["workspace", "number", ws_name]);
} else { } else {
@ -406,13 +406,36 @@ pub fn create_workspace(ws_name: &str) {
} }
} }
lazy_static! {
static ref SPECIAL_WORKSPACE: regex::Regex =
regex::Regex::new(r"^#*w:(.*)").unwrap();
static ref SPECIAL_SWAY: regex::Regex =
regex::Regex::new(r"^#*s:(.*)").unwrap();
}
fn handle_non_matching_input(input: &str) {
if input.is_empty() {
return;
}
if let Some(c) = SPECIAL_SWAY.captures(input) {
run_sway_command(&c[1].split_ascii_whitespace().collect::<Vec<&str>>());
} else if let Some(c) = SPECIAL_WORKSPACE.captures(input) {
create_workspace(&c[1]);
} else {
create_workspace(input);
}
}
pub fn switch_window(extra_props: &HashMap<i64, con::ExtraProps>) { pub fn switch_window(extra_props: &HashMap<i64, con::ExtraProps>) {
let root = get_tree(); let root = get_tree();
let windows = con::get_windows(&root, true, extra_props); let windows = con::get_windows(&root, true, extra_props);
match util::select_from_menu("Switch to window", &windows) { match util::select_from_menu("Switch to window", &windows) {
Ok(window) => focus_window_by_id(window.get_id()), Ok(window) => focus_window_by_id(window.get_id()),
Err(ws_name) => create_workspace(&ws_name), Err(non_matching_input) => {
handle_non_matching_input(&non_matching_input)
}
} }
} }
@ -523,7 +546,9 @@ pub fn switch_workspace(extra_props: &HashMap<i64, con::ExtraProps>) {
match util::select_from_menu("Switch to workspace", &workspaces) { match util::select_from_menu("Switch to workspace", &workspaces) {
Ok(workspace) => run_sway_command(&["workspace", workspace.get_name()]), Ok(workspace) => run_sway_command(&["workspace", workspace.get_name()]),
Err(ws_name) => create_workspace(&ws_name), Err(non_matching_input) => {
handle_non_matching_input(&non_matching_input)
}
} }
} }
@ -538,7 +563,9 @@ pub fn switch_workspace_or_window(extra_props: &HashMap<i64, con::ExtraProps>) {
} }
con::WsOrWin::Win { win } => focus_window_by_id(win.get_id()), con::WsOrWin::Win { win } => focus_window_by_id(win.get_id()),
}, },
Err(ws_name) => create_workspace(&ws_name), Err(non_matching_input) => {
handle_non_matching_input(&non_matching_input)
}
} }
} }

Loading…
Cancel
Save