Skip to content

Commit abfaceb

Browse files
committed
feat: state restoration after output unplug/re-plug
and destruction of buffers/surfaces upon output disconnect
1 parent 848700b commit abfaceb

File tree

6 files changed

+222
-194
lines changed

6 files changed

+222
-194
lines changed

src/threads/ipc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub struct InboundCommandHandler {
1111
}
1212

1313
impl InboundCommandHandler {
14+
// roll these into pandora proper?
1415
pub fn new() -> Arc<InboundCommandHandler> {
1516
let listen_addr = SocketAddr::from_abstract_name("pandora").expect(
1617
"could not construct linux named-socket address (sorry bsd?)");

src/threads/niri.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ fn run(config: DaemonConfig, pandora: Arc<dyn Daemon + Send + Sync>, cmd_queue:
8585
DaemonCommand::OutputModeChange(new_mode) => {
8686
// update state => reflow output
8787
processor.update_mode(new_mode);
88+
// not necessary once render reseat implementation is finished
8889
processor.reseat_scroll_positions(pandora.clone());
8990
},
9091
DaemonCommand::ReloadConfig(config) => {

src/threads/render.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct WallpaperThread {
4949
}
5050

5151
impl WallpaperThread {
52-
fn _log(&self, msg: String) {
52+
fn log(&self, msg: String) {
5353
self.pandora.upgrade().unwrap().log("wallpaper", msg);
5454
}
5555
fn debug(&self, msg: String) {
@@ -63,11 +63,16 @@ impl WallpaperThread {
6363
let mut conn = Connection::<RenderThreadState>::connect().unwrap();
6464
let mut thread_state = RenderThreadState {
6565
outputs: Vec::new(),
66+
detached_outputs: Vec::new(),
6667
globals: WaylandGlobals::new(&mut conn),
6768
pandora: self.pandora.clone(),
6869
};
70+
self.verbose("getting initial output states".to_string());
6971
thread_state.get_outputs(&mut conn);
72+
self.verbose("initializing wallpaper states".to_string());
73+
// thought: peek at self.cmd_queue => pull initial scroll events, if any, for initial position state?
7074
crate::wayland::render_base::initialize_wallpaper_outputs(&mut conn, &self.config, &mut thread_state);
75+
self.log("entering draw loop".to_string());
7176
self.draw_loop(&mut conn, &mut thread_state);
7277
}
7378

@@ -86,16 +91,15 @@ impl WallpaperThread {
8691
Ok(queue) =>
8792
self.handle_cmd(conn, state, &queue.recv()
8893
.expect("thread exploded during blocking read on inbound commands")),
89-
Err(_e) => (),
90-
//state.pandora.debug("wallpaper", format!("{e:?}")),
94+
Err(e) =>
95+
return self.log(format!("{e:?}")),
9196
}
9297
}
9398
}
9499
}
95100
}
96101

97102
fn handle_inbound_commands(&self, conn: &mut Connection<RenderThreadState>, state: &mut RenderThreadState) {
98-
let pandora = self.pandora.upgrade().unwrap();
99103
match self.cmd_queue.lock() {
100104
Ok(queue) => loop {
101105
match queue.try_recv() {
@@ -104,20 +108,22 @@ impl WallpaperThread {
104108
}
105109
},
106110
Err(e) =>
107-
return pandora.debug("wallpaper", format!("{e:?}")),
111+
return self.log(format!("{e:?}")),
108112
}
109113
}
110114

111115
fn handle_cmd(&self, conn: &mut Connection<RenderThreadState>, state: &mut RenderThreadState, cmd: &RenderThreadCommand) {
112116
self.verbose(format!("command: {:?}", cmd));
113117
match cmd {
114118
RenderThreadCommand::Render(_) => {
119+
// could just handle as discard old render_state & make new . . . with new scroll position? hmmmmmmm
115120
//self.render(c, state).expect("error handling render command");
116121
todo!();
117122
}
118-
RenderThreadCommand::Scroll(c) => {
119-
self.scroll(conn, state, c);
123+
RenderThreadCommand::Scroll(cmd) => {
124+
self.scroll(conn, state, cmd);
120125
},
126+
// reload config :/
121127
}
122128
}
123129

@@ -128,8 +134,10 @@ impl WallpaperThread {
128134
None => return self.debug("could not find output in state vec for scroll op".to_string()),
129135
};
130136

131-
if let OutputRenderStateVariety::Wallpaper(render_state) = output_state.render_state.as_mut().unwrap() {
137+
if let Some(OutputRenderStateVariety::Wallpaper(render_state)) = output_state.render_state.as_mut() {
132138
render_state.scroll(conn, cmd.position);
139+
} else {
140+
self.debug("received scroll command, but no wallpaper state found on attached outputs. reseat pending/workspace change from output disconnect?".to_string());
133141
}
134142
}
135143
}

src/wayland/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
pub mod render_base;
2-
pub mod render_helpers;

0 commit comments

Comments
 (0)