bspc_rs/selectors.rs
1//! This module implements selectors for `Node`, `Desktop` and `Monitor`.
2//!
3//! It works just like you would expect it from `bspc` command. However it
4//! offers you one cool feature: it checks if selector is valid at
5//! compile-time.
6//!
7//! However, in order for this to work, selector (represented by a string
8//! slice) is wrapped in struct, representing what kind of selector is that:
9//! node, dekstop or monitor.
10
11// use crate::properties::{CycleDir, Dir, Flag, Layer, SplitType, State};
12
13// pub struct MonitorSelector {}
14// pub struct DesktopSelector {}
15
16// pub enum PathJump {
17// First,
18// Second,
19// Brother,
20// Parent,
21// Dir(Dir),
22// }
23
24// pub struct Path {
25// pub root: DesktopSelector,
26// pub jumps: Vec<PathJump>,
27// }
28
29// pub enum NodeDescriptor {
30// Dir(Dir),
31// CycleDir(CycleDir),
32// Path(Path),
33// Any,
34// FirstAncestor,
35// Last,
36// Newest,
37// Older,
38// Newer,
39// Focused,
40// Pointer,
41// Biggest,
42// Smallest,
43// NodeId(i32),
44// }
45
46// pub struct NodeModifier {
47// focused: Option<bool>,
48// active: Option<bool>,
49// automatic: Option<bool>,
50// local: Option<bool>,
51// leaf: Option<bool>,
52// window: Option<bool>,
53// state: Option<State>,
54// flag: Option<Flag>,
55// layer: Option<Layer>,
56// split_type: Option<SplitType>,
57// same_class: Option<bool>,
58// descendant_of: Option<bool>,
59// ancestor_of: Option<bool>,
60// }
61
62// // TODO: make a selector and add a check at compile time for validating if
63// // the request makes sense (is correct)
64// pub struct NodeSelector {
65// pub reference: Option<Box<NodeSelector>>,
66// pub descriptor: NodeDescriptor,
67// pub modifier: Option<NodeModifier>,
68// }
69
70/// String slice inside represents node selector.
71pub struct NodeSelector<'a>(pub &'a str);
72
73/// String slice inside represents desktop selector.
74pub struct DesktopSelector<'a>(pub &'a str);
75
76/// String slice inside represents monitor selector.
77pub struct MonitorSelector<'a>(pub &'a str);
78
79pub trait Selector {
80 /// Checks if given selector is valid.
81 fn is_valid(&self) -> bool;
82
83 /// Extracts selector from wrapper.
84 fn extract(&self) -> &str;
85
86 /// Returns kind of selector, i.e. Node, Desktop or Monitor.
87 fn kind(&self) -> &str;
88}
89
90impl<'a> Selector for NodeSelector<'a> {
91 // TODO
92 fn is_valid(&self) -> bool {
93 true
94 }
95
96 fn extract(&self) -> &str {
97 self.0
98 }
99
100 fn kind(&self) -> &str {
101 "Node"
102 }
103}
104
105impl<'a> Selector for DesktopSelector<'a> {
106 // TODO
107 fn is_valid(&self) -> bool {
108 true
109 }
110
111 fn extract(&self) -> &str {
112 self.0
113 }
114
115 fn kind(&self) -> &str {
116 "Desktop"
117 }
118}
119
120impl<'a> Selector for MonitorSelector<'a> {
121 // TODO
122 fn is_valid(&self) -> bool {
123 true
124 }
125
126 fn extract(&self) -> &str {
127 self.0
128 }
129
130 fn kind(&self) -> &str {
131 "Monitor"
132 }
133}
134
135fn collect(
136 monitor_selector: Option<MonitorSelector>,
137 desktop_selector: Option<DesktopSelector>,
138 node_selector: Option<NodeSelector>,
139) -> String {
140 todo!();
141}