|
|
@ -1,10 +1,14 @@ |
|
|
|
use crate::ipc; |
|
|
|
use crate::ipc; |
|
|
|
|
|
|
|
use crate::util; |
|
|
|
use std::cmp; |
|
|
|
use std::cmp; |
|
|
|
use std::collections::HashMap; |
|
|
|
use std::collections::HashMap; |
|
|
|
|
|
|
|
use std::fmt; |
|
|
|
|
|
|
|
use std::os::unix::net::UnixStream; |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
pub struct Window<'a> { |
|
|
|
pub struct Window<'a> { |
|
|
|
pub node: &'a ipc::Node, |
|
|
|
node: &'a ipc::Node, |
|
|
|
|
|
|
|
workspace: &'a ipc::Node, |
|
|
|
win_props: Option<ipc::WindowProps>, |
|
|
|
win_props: Option<ipc::WindowProps>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -54,8 +58,10 @@ impl Ord for Window<'_> { |
|
|
|
} else if !self.node.focused && other.node.focused { |
|
|
|
} else if !self.node.focused && other.node.focused { |
|
|
|
std::cmp::Ordering::Less |
|
|
|
std::cmp::Ordering::Less |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
let lru_a = self.win_props.as_ref().map_or(0, |wp| wp.last_focus_time); |
|
|
|
let lru_a = |
|
|
|
let lru_b = other.win_props.as_ref().map_or(0, |wp| wp.last_focus_time); |
|
|
|
self.win_props.as_ref().map_or(0, |wp| wp.last_focus_time); |
|
|
|
|
|
|
|
let lru_b = |
|
|
|
|
|
|
|
other.win_props.as_ref().map_or(0, |wp| wp.last_focus_time); |
|
|
|
lru_a.cmp(&lru_b).reverse() |
|
|
|
lru_a.cmp(&lru_b).reverse() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -68,37 +74,61 @@ impl PartialOrd for Window<'_> { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<'a> std::fmt::Display for Window<'a> { |
|
|
|
impl<'a> std::fmt::Display for Window<'a> { |
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { |
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), std::fmt::Error> { |
|
|
|
write!( |
|
|
|
write!( |
|
|
|
f, |
|
|
|
f, |
|
|
|
"<span font_weight=\"bold\" {}>{}</span> — {} [{}]", |
|
|
|
"<span font_weight=\"bold\" {}>“{}”</span> \ |
|
|
|
|
|
|
|
<i>{}</i> \ |
|
|
|
|
|
|
|
on workspace <b>{}</b> \ |
|
|
|
|
|
|
|
<span alpha=\"20000\">id {}</span>", // Almost hide ID!
|
|
|
|
if self.node.urgent { |
|
|
|
if self.node.urgent { |
|
|
|
" background=\"darkred\" foreground=\"white\"" |
|
|
|
" background=\"darkred\" foreground=\"white\"" |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
"" |
|
|
|
"" |
|
|
|
}, |
|
|
|
}, |
|
|
|
self.get_app_name(), |
|
|
|
|
|
|
|
self.get_title(), |
|
|
|
self.get_title(), |
|
|
|
|
|
|
|
self.get_app_name(), |
|
|
|
|
|
|
|
self.workspace.name.as_ref().unwrap(), |
|
|
|
self.get_id() |
|
|
|
self.get_id() |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Gets all application windows of the tree.
|
|
|
|
fn build_windows( |
|
|
|
pub fn get_windows( |
|
|
|
|
|
|
|
tree: &ipc::Node, |
|
|
|
tree: &ipc::Node, |
|
|
|
mut win_props: HashMap<ipc::Id, ipc::WindowProps>, |
|
|
|
mut win_props: HashMap<ipc::Id, ipc::WindowProps>, |
|
|
|
) -> Vec<Window> { |
|
|
|
) -> Vec<Window> { |
|
|
|
let mut v = vec![]; |
|
|
|
let mut v = vec![]; |
|
|
|
for n in tree.iter() { |
|
|
|
for workspace in tree.workspaces() { |
|
|
|
if n.name.is_some() |
|
|
|
for n in workspace.windows() { |
|
|
|
&& (n.r#type == ipc::NodeType::Con || n.r#type == ipc::NodeType::FloatingCon) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
v.push(Window { |
|
|
|
v.push(Window { |
|
|
|
node: &n, |
|
|
|
node: &n, |
|
|
|
win_props: win_props.remove(&n.id), |
|
|
|
win_props: win_props.remove(&n.id), |
|
|
|
|
|
|
|
workspace: &workspace, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
v |
|
|
|
v |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_window_props( |
|
|
|
|
|
|
|
) -> Result<HashMap<ipc::Id, ipc::WindowProps>, serde_json::Error> { |
|
|
|
|
|
|
|
if let Ok(sock) = UnixStream::connect(util::get_swayr_socket_path()) { |
|
|
|
|
|
|
|
serde_json::from_reader(sock) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
panic!("Could not connect to socket!") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Gets all application windows of the tree.
|
|
|
|
|
|
|
|
pub fn get_windows(root_node: &ipc::Node) -> Vec<Window> { |
|
|
|
|
|
|
|
let win_props = match get_window_props() { |
|
|
|
|
|
|
|
Ok(win_props) => Some(win_props), |
|
|
|
|
|
|
|
Err(e) => { |
|
|
|
|
|
|
|
eprintln!("Got no win_props: {:?}", e); |
|
|
|
|
|
|
|
None |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
build_windows(&root_node, win_props.unwrap_or(HashMap::new())) |
|
|
|
|
|
|
|
} |
|
|
|