Started swayrd

timeout_old
Tassilo Horn 4 years ago
parent a767e2d0ba
commit 60eef662ba
  1. 45
      src/bin/swayrd.rs
  2. 70
      src/ipc.rs

@ -1,6 +1,47 @@
use swayr::con; extern crate serde;
extern crate serde_json;
use serde_json::Deserializer;
use std::collections::HashMap;
use std::process as proc;
use std::sync::Arc;
use std::sync::RwLock;
use std::thread;
use swayr::ipc; use swayr::ipc;
fn main() { fn main() {
println!("swayd here!"); let win_props: Arc<RwLock<HashMap<ipc::Id, ipc::WindowProps>>> =
Arc::new(RwLock::new(HashMap::new()));
let subscriber_handle = thread::spawn(|| {
let x = proc::Command::new("swaymsg")
.arg("-t")
.arg("subscribe")
.arg("[window]")
.output()
.expect("Failed to subscribe to window events");
println!(
"{}",
String::from_utf8(x.stdout).expect("Wrong string data!")
);
let child = proc::Command::new("swaymsg")
.arg("--monitor")
.arg("-t")
.arg("subscribe")
.arg("'[window]'")
.stdout(proc::Stdio::piped())
.spawn()
.expect("Failed to subscribe to window events");
let stdout: std::process::ChildStdout = child.stdout.unwrap();
// TODO: Before the WindowEvents, there's one Reply. How to read that?
let stream = Deserializer::from_reader(stdout).into_iter::<ipc::WindowEvent>();
for res in stream {
match res {
Ok(msg) => println!("Got msg: {:?}", msg),
Err(err) => panic!("{:?}", err),
}
}
});
subscriber_handle.join();
} }

@ -9,7 +9,7 @@ pub type Id = u32;
pub type Dim = u16; pub type Dim = u16;
pub type Pid = u16; pub type Pid = u16;
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
#[allow(dead_code)] #[allow(dead_code)]
pub struct Rect { pub struct Rect {
pub x: Dim, pub x: Dim,
@ -19,7 +19,7 @@ pub struct Rect {
} }
// TODO: Maybe there are more? // TODO: Maybe there are more?
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
pub enum Border { pub enum Border {
#[serde(rename = "none")] #[serde(rename = "none")]
None, None,
@ -30,7 +30,7 @@ pub enum Border {
} }
// TODO: Maybe there are more? // TODO: Maybe there are more?
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
pub enum Layout { pub enum Layout {
#[serde(rename = "splith")] #[serde(rename = "splith")]
SplitH, SplitH,
@ -46,7 +46,7 @@ pub enum Layout {
None, None,
} }
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
pub enum Orientation { pub enum Orientation {
#[serde(rename = "horizontal")] #[serde(rename = "horizontal")]
Horizontal, Horizontal,
@ -70,7 +70,7 @@ pub enum NodeType {
FloatingCon, FloatingCon,
} }
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
pub enum ShellType { pub enum ShellType {
#[serde(rename = "xdg_shell")] #[serde(rename = "xdg_shell")]
XdgShell, XdgShell,
@ -78,7 +78,7 @@ pub enum ShellType {
XWayland, XWayland,
} }
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
#[allow(dead_code)] #[allow(dead_code)]
pub struct WindowProperties { pub struct WindowProperties {
pub class: Option<String>, pub class: Option<String>,
@ -88,7 +88,7 @@ pub struct WindowProperties {
//pub transient_for: DONTKNOW, //pub transient_for: DONTKNOW,
} }
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
#[allow(dead_code)] #[allow(dead_code)]
pub struct Node { pub struct Node {
pub id: Id, pub id: Id,
@ -121,22 +121,22 @@ pub struct Node {
} }
impl Node { impl Node {
pub fn iter(&self) -> PreOrderNodeIter { pub fn iter(&self) -> NodeIter {
PreOrderNodeIter::new(self) NodeIter::new(self)
} }
} }
pub struct PreOrderNodeIter<'a> { pub struct NodeIter<'a> {
stack: Vec<&'a Node>, stack: Vec<&'a Node>,
} }
impl<'a> PreOrderNodeIter<'a> { impl<'a> NodeIter<'a> {
fn new(node: &'a Node) -> PreOrderNodeIter { fn new(node: &'a Node) -> NodeIter {
PreOrderNodeIter { stack: vec![node] } NodeIter { stack: vec![node] }
} }
} }
impl<'a> Iterator for PreOrderNodeIter<'a> { impl<'a> Iterator for NodeIter<'a> {
type Item = &'a Node; type Item = &'a Node;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -184,3 +184,45 @@ fn test_get_tree() {
println!(" id: {}, type: {:?}", n.id, n.r#type); println!(" id: {}, type: {:?}", n.id, n.r#type);
} }
} }
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub enum WindowEventType {
#[serde(rename = "new")]
New,
#[serde(rename = "close")]
Close,
#[serde(rename = "focus")]
Focus,
#[serde(rename = "title")]
Title,
#[serde(rename = "fullscreen_mode")]
FullscreenMode,
#[serde(rename = "move")]
Move,
#[serde(rename = "floating")]
Floating,
#[serde(rename = "urgent")]
Urgent,
#[serde(rename = "mark")]
Mark,
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub struct Reply {
pub success: bool,
pub error: String,
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub struct WindowEvent {
pub change: WindowEventType,
pub container: Node,
}
pub struct WindowProps {
/// Milliseconds since UNIX epoch.
last_focus_time: u128,
}

Loading…
Cancel
Save