From 922db0aee1ed45931b71ed6702487a47da4064fc Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sun, 27 Jun 2021 00:23:49 +0200 Subject: [PATCH] Upgrade to swayipc-3.0.0-alpha.3 --- Cargo.toml | 6 +++--- src/cmds.rs | 3 +-- src/con.rs | 18 +++++++++--------- src/demon.rs | 26 ++++++++++++++------------ src/ipc.rs | 24 ++++++++++++------------ 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d23b7bb..f767b11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,10 +9,10 @@ license = "GPL-3.0+" edition = "2018" [dependencies] -serde = { version = "1.0.117", features = ["derive"] } -serde_json = "1.0.59" +serde = { version = "1.0.126", features = ["derive"] } +serde_json = "1.0.64" clap = "3.0.0-beta.2" users = "0.11.0" -swayipc = "2.7.2" +swayipc = "3.0.0-alpha.3" toml = "0.5.8" directories = "3.0" diff --git a/src/cmds.rs b/src/cmds.rs index 2919cec..3c353b3 100644 --- a/src/cmds.rs +++ b/src/cmds.rs @@ -28,7 +28,6 @@ use std::sync::Arc; use std::sync::RwLock; use swayipc as s; -use swayipc::reply as r; pub struct ExecSwayrCmdArgs<'a> { pub cmd: &'a SwayrCommand, @@ -108,7 +107,7 @@ fn quit_window_by_id(id: i64) { run_sway_command(&[format!("[con_id={}]", id).as_str(), "kill"]); } -fn get_tree() -> r::Node { +fn get_tree() -> s::Node { match s::Connection::new() { Ok(mut con) => con.get_tree().expect("Got no root node"), Err(err) => panic!("{}", err), diff --git a/src/con.rs b/src/con.rs index 794e82e..54b71f0 100644 --- a/src/con.rs +++ b/src/con.rs @@ -22,7 +22,7 @@ use crate::util; use std::cmp; use std::collections::HashMap; use std::fmt; -use swayipc::reply as r; +use swayipc as s; pub trait DisplayFormat { fn format_for_display(&self, config: &cfg::Config) -> String; @@ -30,8 +30,8 @@ pub trait DisplayFormat { #[derive(Debug)] pub struct Window<'a> { - node: &'a r::Node, - workspace: &'a r::Node, + node: &'a s::Node, + workspace: &'a s::Node, extra_props: Option, } @@ -110,7 +110,7 @@ impl<'a> fmt::Display for Window<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!( f, - "“{}” — {} on workspace {} (id: {}, urgent: {})", + "\"{}\" — {} on workspace {} (id: {}, urgent: {})", self.get_title(), self.get_app_name(), self.workspace.name.as_ref().unwrap(), @@ -166,7 +166,7 @@ impl<'a> DisplayFormat for Window<'a> { } fn build_windows<'a>( - root: &'a r::Node, + root: &'a s::Node, include_scratchpad_windows: bool, extra_props: Option<&HashMap>, ) -> Vec> { @@ -188,7 +188,7 @@ fn build_windows<'a>( } fn build_workspaces<'a>( - root: &'a r::Node, + root: &'a s::Node, include_scratchpad: bool, extra_props: Option<&HashMap>, ) -> Vec> { @@ -221,7 +221,7 @@ fn build_workspaces<'a>( /// Gets all application windows of the tree. pub fn get_windows<'a>( - root: &'a r::Node, + root: &'a s::Node, include_scratchpad_windows: bool, extra_props: Option<&HashMap>, ) -> Vec> { @@ -235,7 +235,7 @@ pub fn get_windows<'a>( /// Gets all workspaces of the tree. pub fn get_workspaces<'a>( - root: &'a r::Node, + root: &'a s::Node, include_scratchpad: bool, extra_props: Option<&HashMap>, ) -> Vec> { @@ -310,7 +310,7 @@ pub fn select_workspace_or_window<'a>( } pub struct Workspace<'a> { - node: &'a r::Node, + node: &'a s::Node, extra_props: Option, pub windows: Vec>, } diff --git a/src/demon.rs b/src/demon.rs index c3eaeb0..47f1af5 100644 --- a/src/demon.rs +++ b/src/demon.rs @@ -28,7 +28,6 @@ use std::thread; use std::time::{SystemTime, UNIX_EPOCH}; use swayipc as s; -use swayipc::reply as r; pub fn run_demon() { let extra_props: Arc>> = @@ -42,7 +41,7 @@ pub fn run_demon() { serve_client_requests(extra_props); } -fn connect_and_subscribe() -> s::Fallible { +fn connect_and_subscribe() -> s::Fallible { s::Connection::new()? .subscribe(&[s::EventType::Window, s::EventType::Workspace]) } @@ -63,14 +62,14 @@ pub fn monitor_sway_events( let handled; match ev_result { Ok(ev) => match ev { - r::Event::Window(win_ev) => { + s::Event::Window(win_ev) => { let extra_props_clone = extra_props.clone(); handled = handle_window_event( win_ev, extra_props_clone, ); } - r::Event::Workspace(ws_ev) => { + s::Event::Workspace(ws_ev) => { let extra_props_clone = extra_props.clone(); handled = handle_workspace_event( ws_ev, @@ -101,17 +100,19 @@ pub fn monitor_sway_events( } fn handle_window_event( - ev: Box, + ev: Box, extra_props: Arc>>, ) -> bool { - let r::WindowEvent { change, container } = *ev; + let s::WindowEvent { + change, container, .. + } = *ev; match change { - r::WindowChange::New | r::WindowChange::Focus => { + s::WindowChange::New | s::WindowChange::Focus => { update_last_focus_time(container.id, extra_props); println!("Handled window event type {:?}", change); true } - r::WindowChange::Close => { + s::WindowChange::Close => { remove_extra_props(container.id, extra_props); println!("Handled window event type {:?}", change); true @@ -121,16 +122,17 @@ fn handle_window_event( } fn handle_workspace_event( - ev: Box, + ev: Box, extra_props: Arc>>, ) -> bool { - let r::WorkspaceEvent { + let s::WorkspaceEvent { change, current, old: _, + .. } = *ev; match change { - r::WorkspaceChange::Init | r::WorkspaceChange::Focus => { + s::WorkspaceChange::Init | s::WorkspaceChange::Focus => { update_last_focus_time( current .expect("No current in Init or Focus workspace event") @@ -140,7 +142,7 @@ fn handle_workspace_event( println!("Handled workspace event type {:?}", change); true } - r::WorkspaceChange::Empty => { + s::WorkspaceChange::Empty => { remove_extra_props( current.expect("No current in Empty workspace event").id, extra_props, diff --git a/src/ipc.rs b/src/ipc.rs index 7d95d09..2f7f047 100644 --- a/src/ipc.rs +++ b/src/ipc.rs @@ -17,23 +17,23 @@ use clap::Clap; use serde::{Deserialize, Serialize}; -use swayipc::reply as r; +use swayipc as s; /// Immutable Node Iterator /// /// Iterates nodes in depth-first order, tiled nodes before floating nodes. pub struct NodeIter<'a> { - stack: Vec<&'a r::Node>, + stack: Vec<&'a s::Node>, } impl<'a> NodeIter<'a> { - pub fn new(node: &'a r::Node) -> NodeIter { + pub fn new(node: &'a s::Node) -> NodeIter { NodeIter { stack: vec![node] } } } impl<'a> Iterator for NodeIter<'a> { - type Item = &'a r::Node; + type Item = &'a s::Node; fn next(&mut self) -> Option { if let Some(node) = self.stack.pop() { @@ -56,32 +56,32 @@ pub trait NodeMethods { fn iter(&self) -> NodeIter; /// Returns all nodes being application windows. - fn windows(&self) -> Vec<&r::Node>; + fn windows(&self) -> Vec<&s::Node>; /// Returns all nodes being workspaces. - fn workspaces(&self) -> Vec<&r::Node>; + fn workspaces(&self) -> Vec<&s::Node>; fn is_scratchpad(&self) -> bool; } -impl NodeMethods for r::Node { +impl NodeMethods for s::Node { fn iter(&self) -> NodeIter { NodeIter::new(self) } - fn windows(&self) -> Vec<&r::Node> { + fn windows(&self) -> Vec<&s::Node> { self.iter() .filter(|n| { - (n.node_type == r::NodeType::Con - || n.node_type == r::NodeType::FloatingCon) + (n.node_type == s::NodeType::Con + || n.node_type == s::NodeType::FloatingCon) && n.name.is_some() }) .collect() } - fn workspaces(&self) -> Vec<&r::Node> { + fn workspaces(&self) -> Vec<&s::Node> { self.iter() - .filter(|n| n.node_type == r::NodeType::Workspace) + .filter(|n| n.node_type == s::NodeType::Workspace) .collect() }