Reorganize a bit

timeout_old
Tassilo Horn 4 years ago
parent 12f8da1bb0
commit 8530b78d97
  1. 12
      src/client.rs
  2. 25
      src/con.rs
  3. 2
      src/lib.rs
  4. 10
      src/util.rs

@ -1,13 +1,13 @@
use crate::con;
use crate::ipc;
use crate::util;
use crate::window;
pub fn switch_window() {
let root_node = get_tree();
let mut windows = window::get_windows(&root_node);
let mut windows = con::get_windows(&root_node);
windows.sort();
if let Some(window) = util::select_window("Switch to window", &windows) {
if let Some(window) = con::select_window("Switch to window", &windows) {
util::swaymsg(vec![
format!("[con_id={}]", window.get_id()).as_str(),
"focus",
@ -17,10 +17,10 @@ pub fn switch_window() {
pub fn quit_window() {
let root_node = get_tree();
let mut windows = window::get_windows(&root_node);
let mut windows = con::get_windows(&root_node);
windows.sort_by(|a, b| a.cmp(b).reverse());
if let Some(window) = util::select_window("Quit window", &windows) {
if let Some(window) = con::select_window("Quit window", &windows) {
util::swaymsg(vec![
format!("[con_id={}]", window.get_id()).as_str(),
"kill",
@ -54,7 +54,7 @@ fn test_get_tree() {
#[test]
fn test_get_windows() {
let tree = get_tree();
let cons = window::get_windows(&tree);
let cons = con::get_windows(&tree);
println!("There are {} cons.", cons.len());

@ -49,14 +49,14 @@ 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 {
} else if self.node.urgent && !other.node.urgent
|| !self.node.focused && other.node.focused
{
cmp::Ordering::Less
} else if !self.node.urgent && other.node.urgent {
std::cmp::Ordering::Greater
} else if self.node.focused && !other.node.focused {
} else if !self.node.urgent && other.node.urgent
|| self.node.focused && !other.node.focused
{
std::cmp::Ordering::Greater
} else if !self.node.focused && other.node.focused {
std::cmp::Ordering::Less
} else {
let lru_a =
self.win_props.as_ref().map_or(0, |wp| wp.last_focus_time);
@ -73,8 +73,8 @@ impl PartialOrd for Window<'_> {
}
}
impl<'a> std::fmt::Display for Window<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
impl<'a> fmt::Display for Window<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(
f,
"<span font_weight=\"bold\" {}>{}</span> \
@ -130,5 +130,12 @@ pub fn get_windows(root_node: &ipc::Node) -> Vec<Window> {
}
};
build_windows(&root_node, win_props.unwrap_or(HashMap::new()))
build_windows(&root_node, win_props.unwrap_or_default())
}
pub fn select_window<'a>(
prompt: &'a str,
windows: &'a [Window],
) -> Option<&'a Window<'a>> {
util::wofi_select(prompt, windows)
}

@ -1,5 +1,5 @@
pub mod client;
pub mod con;
pub mod demon;
pub mod ipc;
pub mod util;
pub mod window;

@ -1,4 +1,3 @@
use crate::window;
use std::collections::HashMap;
use std::io::Write;
use std::process as proc;
@ -28,16 +27,9 @@ pub fn swaymsg(args: Vec<&str>) -> String {
String::from_utf8(output.stdout).unwrap()
}
pub fn select_window<'a>(
prompt: &'a str,
windows: &'a Vec<window::Window>,
) -> Option<&'a window::Window<'a>> {
wofi_select(prompt, windows)
}
pub fn wofi_select<'a, 'b, TS>(
prompt: &'a str,
choices: &'b Vec<TS>,
choices: &'b [TS],
) -> Option<&'b TS>
where
TS: std::fmt::Display + Sized,

Loading…
Cancel
Save