New switch-to-urgent-or-lru-window command; add module docs

timeout_old
Tassilo Horn 4 years ago
parent 0bd375da12
commit 0f1989acd7
  1. 2
      Cargo.toml
  2. 15
      README.md
  3. 2
      src/bin/swayr.rs
  4. 2
      src/bin/swayrd.rs
  5. 23
      src/client.rs
  6. 18
      src/con.rs
  7. 2
      src/demon.rs
  8. 2
      src/ipc.rs
  9. 10
      src/lib.rs
  10. 2
      src/util.rs

@ -1,7 +1,7 @@
[package]
name = "swayr"
version = "0.0.9"
description = "A wofi-based LRU window-switcher for sway written in Rust"
description = "A wofi-based LRU window-switcher (and more) for the sway window manager"
homepage = "https://sr.ht/~tsdh/swayr/"
repository = "https://git.sr.ht/~tsdh/swayr"
authors = ["Tassilo Horn <tsdh@gnu.org>"]

@ -1,13 +1,15 @@
# Swayr is a window switcher for sway
# Swayr is a window switcher (and more) for sway
Swayr consists of a demon, and a client. The demon `swayrd` records window
creations, deletions, and focus changes using sway's JSON IPC interface. The
client `swayr` offers subcommands, see `swayr --help`.
Swayr 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`.
Right now, there are these subcommands:
* `switch-window` displays all windows in the order urgent first, then LRU,
focused last and focuses the selected.
* `quit-window` displays all windows and quits the selected one.
* `switch-to-urgent-or-lru-window` switches to the next window with urgency
hint (if any) or to the last recently used window.
* `switch-workspace` displays all workspaces in LRU order and switches to the
selected one.
* `switch-workspace-or-window` displays all workspaces and their windows and
@ -43,7 +45,10 @@ so:
```
bindsym $mod+Delete exec env RUST_BACKTRACE=1 swayr quit-window > /tmp/swayr.log 2>&1
bindsym $mod+Space exec env RUST_BACKTRACE=1 swayr switch-window >> /tmp/swayr.log 2>&1
bindsym $mod+Shift+Space exec env RUST_BACKTRACE=1 swayr switch-workspace-or-window >> /tmp/swayr.log 2>&1
bindsym $mod+Tab exec env RUST_BACKTRACE=1 \
swayr switch-to-urgent-or-lru-window >> /tmp/swayr.log 2>&1
bindsym $mod+Shift+Space exec env RUST_BACKTRACE=1 \
swayr switch-workspace-or-window >> /tmp/swayr.log 2>&1
bindsym $mod+c exec env RUST_BACKTRACE=1 swayr execute-swaymsg-command >> /tmp/swayr.log 2>&1
bindsym $mod+Shift+c exec env RUST_BACKTRACE=1 swayr execute-swayr-command >> /tmp/swa
```

@ -1,3 +1,5 @@
//! The `swayr` binary.
#[macro_use]
extern crate clap;
use clap::Clap;

@ -1,3 +1,5 @@
//! The `swayrd` binary.
extern crate serde;
extern crate serde_json;

@ -1,3 +1,5 @@
//! Functions and data structures of the swayr client.
use crate::con;
use crate::ipc;
use crate::util;
@ -6,6 +8,8 @@ use std::fmt;
#[derive(Clap, Debug)]
pub enum SwayrCommand {
/// Switch to next urgent window (if any) or to last recently used window.
SwitchToUrgentOrLRUWindow,
/// Focus the selected window
SwitchWindow,
/// Quit the selected window
@ -30,6 +34,9 @@ impl fmt::Display for SwayrCommand {
pub fn exec_swayr_cmd(cmd: &SwayrCommand) {
match cmd {
SwayrCommand::SwitchToUrgentOrLRUWindow => {
switch_to_urgent_or_lru_window()
}
SwayrCommand::SwitchWindow => switch_window(),
SwayrCommand::QuitWindow => quit_window(),
SwayrCommand::SwitchWorkspace => switch_workspace(),
@ -62,6 +69,22 @@ fn quit_window_by_id(id: ipc::Id) {
util::swaymsg(&[format!("[con_id={}]", id).as_str(), "kill"]);
}
pub fn switch_to_urgent_or_lru_window() {
let root = con::get_tree();
let windows = con::get_windows(&root);
if let Some(win) = windows
.iter()
.filter(|w| w.is_urgent())
.next()
.or_else(|| windows.iter().next())
{
println!("Switching to {}", win);
focus_window_by_id(win.get_id())
} else {
println!("No window to switch to.")
}
}
pub fn switch_window() {
let root = con::get_tree();
let windows = con::get_windows(&root);

@ -1,3 +1,5 @@
//! Convenience data structures built from the IPC structs.
use crate::ipc;
use crate::util;
use std::cmp;
@ -61,6 +63,14 @@ impl Window<'_> {
pub fn get_title(&self) -> &str {
self.node.name.as_ref().unwrap()
}
pub fn is_urgent(&self) -> bool {
self.node.urgent
}
pub fn is_focused(&self) -> bool {
self.node.focused
}
}
impl PartialEq for Window<'_> {
@ -75,12 +85,12 @@ impl Ord for Window<'_> {
fn cmp(&self, other: &Self) -> cmp::Ordering {
if self == other {
cmp::Ordering::Equal
} else if self.node.urgent && !other.node.urgent
|| !self.node.focused && other.node.focused
} else if self.is_urgent() && !other.is_urgent()
|| !self.is_focused() && other.is_focused()
{
cmp::Ordering::Less
} else if !self.node.urgent && other.node.urgent
|| self.node.focused && !other.node.focused
} else if !self.is_urgent() && other.is_urgent()
|| self.is_focused() && !other.is_focused()
{
std::cmp::Ordering::Greater
} else {

@ -1,3 +1,5 @@
//! Functions and data structures of the swayrd demon.
use crate::ipc;
use crate::util;
use serde_json::Deserializer;

@ -1,3 +1,5 @@
//! Functions and data structures concerned with sway JSON IPC.
extern crate serde;
extern crate serde_json;
extern crate users;

@ -1,3 +1,13 @@
// 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
//! window/workspace creations, deletions, and focus changes using sway's JSON
//! IPC interface. The client `swayr` offers subcommands, see `swayr --help`.
pub mod client;
pub mod con;
pub mod demon;

@ -1,3 +1,5 @@
//! Utility functions including wofi-selection.
use std::collections::HashMap;
use std::io::Write;
use std::process as proc;

Loading…
Cancel
Save