Skip to content

Commit 49cf5be

Browse files
committed
feat: Added hook to get newly connected screens (in preparation for profile manager
1 parent 66e2ba3 commit 49cf5be

File tree

4 files changed

+58
-13
lines changed

4 files changed

+58
-13
lines changed

Cargo.lock

Lines changed: 24 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

waypaper_engine_daemon/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ tracing = "0.1"
2828
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2929
wayland-egl = "0.32.5"
3030
waypaper_engine_shared = { path = "../waypaper_engine_shared" }
31+
crossbeam = "0.8.4"

waypaper_engine_daemon/src/app_state.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,16 @@ impl AppState {
2222
wpe_dir.to_string_lossy()
2323
);
2424

25+
let (new_output_tx, new_output_rx) = crossbeam::channel::unbounded();
26+
thread::spawn(move || {
27+
loop {
28+
println!("new output: {:?}", new_output_rx.recv().expect("oui"));
29+
}
30+
});
31+
2532
AppState {
2633
wpe_dir,
27-
rendering_context: RenderingContext::new(),
34+
rendering_context: RenderingContext::new(new_output_tx),
2835
}
2936
}
3037

waypaper_engine_daemon/src/wl_renderer.rs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::rc::Rc;
55
use crate::egl::EGLState;
66
use crate::wallpaper::Wallpaper;
77
use crate::wallpaper_renderer::WPRenderer;
8+
use crossbeam::channel::Sender;
89
use fps_counter::FPSCounter;
910
use gl::COLOR_BUFFER_BIT;
1011
use khronos_egl::ATTRIB_NONE;
@@ -41,7 +42,7 @@ pub struct RenderingContext {
4142
}
4243

4344
impl RenderingContext {
44-
pub fn new() -> Self {
45+
pub fn new(new_output_tx: Sender<OutputInfo>) -> Self {
4546
let connection = Rc::new(Connection::connect_to_env().unwrap());
4647
let egl_state = Rc::new(EGLState::new(connection.clone()));
4748
let (globals, event_queue): (GlobalList, EventQueue<WLState>) =
@@ -53,6 +54,7 @@ impl RenderingContext {
5354
egl_state.clone(),
5455
&globals,
5556
queue_handle,
57+
new_output_tx,
5658
);
5759

5860
tracing::info!("Created WL state");
@@ -134,6 +136,7 @@ pub struct WLState {
134136
layer_shell: LayerShell,
135137

136138
pub layers: HashMap<String, SimpleLayer>,
139+
new_output_tx: Sender<OutputInfo>,
137140
}
138141

139142
impl WLState {
@@ -142,6 +145,7 @@ impl WLState {
142145
egl_state: Rc<EGLState>,
143146
globals: &GlobalList,
144147
queue_handle: QueueHandle<Self>,
148+
new_output_tx: Sender<OutputInfo>,
145149
) -> Self {
146150
Self {
147151
connection,
@@ -156,6 +160,7 @@ impl WLState {
156160
queue_handle,
157161

158162
layers: HashMap::new(),
163+
new_output_tx,
159164
}
160165
}
161166

@@ -226,15 +231,6 @@ impl WLState {
226231
}
227232
}
228233

229-
impl Drop for SimpleLayer {
230-
fn drop(&mut self) {
231-
self.egl_state
232-
.egl
233-
.destroy_surface(self.egl_state.egl_display, self.egl_window_surface)
234-
.expect("Couldn't destroy surface");
235-
}
236-
}
237-
238234
pub struct OutputsList(HashMap<WlOutput, OutputInfo>);
239235

240236
impl OutputsList {
@@ -290,6 +286,15 @@ pub struct SimpleLayer {
290286
fps_counter: FPSCounter,
291287
}
292288

289+
impl Drop for SimpleLayer {
290+
fn drop(&mut self) {
291+
self.egl_state
292+
.egl
293+
.destroy_surface(self.egl_state.egl_display, self.egl_window_surface)
294+
.expect("Couldn't destroy surface");
295+
}
296+
}
297+
293298
impl CompositorHandler for WLState {
294299
fn scale_factor_changed(
295300
&mut self,
@@ -349,7 +354,16 @@ impl OutputHandler for WLState {
349354
&mut self.output_state
350355
}
351356

352-
fn new_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {}
357+
fn new_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, output: WlOutput) {
358+
match self.output_state.info(&output) {
359+
Some(infos) => {
360+
self.new_output_tx
361+
.send(infos)
362+
.expect("Error sending new output event");
363+
}
364+
None => tracing::error!("Could not retrieve new output info"),
365+
}
366+
}
353367

354368
fn update_output(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _output: WlOutput) {
355369
// TODO resize wallpaper if output size or scale has changed

0 commit comments

Comments
 (0)