Upgrade to swayipc-3.0.0-alpha.3

timeout_old
Tassilo Horn 3 years ago
parent f9d7b0d805
commit 922db0aee1
  1. 6
      Cargo.toml
  2. 3
      src/cmds.rs
  3. 18
      src/con.rs
  4. 26
      src/demon.rs
  5. 24
      src/ipc.rs

@ -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"

@ -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),

@ -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<ipc::ExtraProps>,
}
@ -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<i64, ipc::ExtraProps>>,
) -> Vec<Window<'a>> {
@ -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<i64, ipc::ExtraProps>>,
) -> Vec<Workspace<'a>> {
@ -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<i64, ipc::ExtraProps>>,
) -> Vec<Window<'a>> {
@ -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<i64, ipc::ExtraProps>>,
) -> Vec<Workspace<'a>> {
@ -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<ipc::ExtraProps>,
pub windows: Vec<Window<'a>>,
}

@ -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<RwLock<HashMap<i64, ipc::ExtraProps>>> =
@ -42,7 +41,7 @@ pub fn run_demon() {
serve_client_requests(extra_props);
}
fn connect_and_subscribe() -> s::Fallible<s::EventIterator> {
fn connect_and_subscribe() -> s::Fallible<s::EventStream> {
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<r::WindowEvent>,
ev: Box<s::WindowEvent>,
extra_props: Arc<RwLock<HashMap<i64, ipc::ExtraProps>>>,
) -> 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<r::WorkspaceEvent>,
ev: Box<s::WorkspaceEvent>,
extra_props: Arc<RwLock<HashMap<i64, ipc::ExtraProps>>>,
) -> 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,

@ -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<Self::Item> {
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()
}

Loading…
Cancel
Save