-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsomething.rs
More file actions
183 lines (175 loc) · 5.63 KB
/
something.rs
File metadata and controls
183 lines (175 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
use std::{
any::Any,
error::Error,
sync::{Arc, RwLock},
};
mod bar;
mod workspace;
use spell_framework::{
enchant_spells,
layer_properties::{BoardType, DataType, LayerAnchor, LayerType, WindowConf},
slint_adapter::SpellMultiWinHandler,
ForeignController,
};
slint::include_modules!();
use bar::configure_bar;
use slint::ComponentHandle;
use workspace::configure_workpaces;
fn main() -> Result<(), Box<dyn Error>> {
std::env::set_var("RUST_BACKTRACE", "1");
let mut windows = SpellMultiWinHandler::conjure_spells(vec![
(
"top-bar",
WindowConf::new(
1366,
610,
(Some(LayerAnchor::TOP), None),
(0, 0, 0, 0),
LayerType::Top,
BoardType::None,
Some(30),
),
),
(
"menu",
WindowConf::new(
376,
576,
(Some(LayerAnchor::TOP), Some(LayerAnchor::LEFT)),
(5, 0, 0, 10),
LayerType::Top,
BoardType::None,
None,
),
),
(
"workspace",
WindowConf::new(
10,
738,
(Some(LayerAnchor::LEFT), None),
(0, 0, 0, 0),
LayerType::Top,
BoardType::None,
Some(10),
),
),
]);
let bar = TopBar::new().unwrap();
let menu = Menu::new().unwrap();
let workspace = Workspaces::new().unwrap();
let [ref mut way_bar, ref mut way_menu, _] = windows[..] else {
panic!("Error getting wayland handles");
};
// way_bar.set_exclusive_zone(30);
// way_bar.set_exclusive_zone(30);
// forge.add_event(Duration::from_secs(2), move |_| {
// let output = Command::new("date")
// .args(["+%I:%M"])
// .output()
// .expect("failed to execute process");
//
// let am_pm = String::from_utf8(
// Command::new("date")
// .args(["+%p"])
// .output()
// .expect("couldn't run")
// .stdout,
// )
// .unwrap();
// let mut time = String::from_utf8(output.stdout).unwrap();
// time = format!("{} {}", time.trim(), am_pm.trim());
// // println!("/{}/", time);
// bar_n.set_time_var(time.into());
// });
//
let bar_tx = way_bar.get_handler();
let menu_tx = way_menu.get_handler();
let state = menu.get_state();
let bar_state = bar.get_state();
let menu_handle = menu.as_weak().unwrap();
let bar_handle = bar.as_weak().unwrap();
configure_bar(bar, bar_tx);
configure_workpaces(workspace);
menu_tx.toggle();
// bar.global::<Rice>().on_get_volume(|| {
// let val = Command::new("sh").arg("-c").arg("pactl list sinks | grep '^[[:space:]]Volume:' | head -n $(( $SINK + 1 )) | tail -n 1 | sed -e 's,.* \\([0-9][0-9]*\\)%.*,\\1,'").output().unwrap();
// let output_str = String::from_utf8(val.stderr).unwrap();
// println!("{}",output_str);
// output_str.into()
// });
//
// let m = bar.as_weak().clone();
// forge.add_event(Duration::from_secs(1), |_| {
// // bar.global::<Rice>().invoke_get_volume();
// m._walls_window_called();
// });
enchant_spells(
windows,
vec![
Some(Arc::new(RwLock::new(bar_state))),
Some(Arc::new(RwLock::new(state))),
None,
],
vec![
Some(Box::new(move |state_value| {
println!("Entered in the callback");
let controller_val = state_value.read().unwrap();
let val = controller_val.as_any().downcast_ref::<BarState>().unwrap();
bar_handle.set_state(val.clone());
})),
Some(Box::new(move |state_value| {
println!("Entered in the callback");
let controller_val = state_value.read().unwrap();
let val = controller_val.as_any().downcast_ref::<State>().unwrap();
menu_handle.set_state(val.clone());
})),
None,
],
)
}
impl ForeignController for BarState {
fn get_type(&self, key: &str) -> DataType {
match key {
"is-search-on" => DataType::Boolean(self.is_search_on),
_ => DataType::Panic,
}
}
fn change_val(&mut self, key: &str, val: DataType) {
if key == "is-search-on" {
if let DataType::Boolean(value) = val {
self.is_search_on = value;
}
}
}
fn as_any(&self) -> &dyn Any {
self
}
}
impl ForeignController for State {
fn get_type(&self, key: &str) -> DataType {
match key {
"is-power-menu-open" => DataType::Boolean(self.is_power_menu_open),
_ => DataType::Panic,
}
}
fn change_val(&mut self, key: &str, val: DataType) {
match key {
"is-power-menu-open" => {
if let DataType::Boolean(value) = val {
self.is_power_menu_open = value;
}
}
"string-type" => self.string_type = "hello".into(),
"enumsss" => println!("{:?}", self.cards_type),
_ => {}
}
}
fn as_any(&self) -> &dyn Any {
self
}
}
// TODO the cursor doesn't change from pointer to hand when clicking buttons, so the
// cursor needs to do that.
// TODO Lookup child creation in wayland, how can it be utilised.
// TODO Lookup popup in wayland to see if that helps in anything.