Skip to content

Commit 42bddb6

Browse files
committed
feat: handle output Transform state
additional cleanup: roll None into OutputRenderStateVariety (rather than wrapping it in Option) to make initialization/unwrap-and-match less clunky
1 parent d91fd52 commit 42bddb6

File tree

2 files changed

+77
-55
lines changed

2 files changed

+77
-55
lines changed

src/threads/render.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,18 @@ impl WallpaperThread {
209209

210210
let scroll_position = Some((cmd.position.0, cmd.position.1));
211211

212-
// Extract values we need to avoid borrowing conflicts
213-
let output_width = output_state.width;
214-
let output_height = output_state.height;
215-
let output_name = output_state.name.clone();
216-
let output_done = output_state.done;
217-
218-
// Create a temporary OutputState for the update_image call
219212
let temp_output_state = crate::wayland::render_base::OutputState {
220-
name: output_name,
221-
width: output_width,
222-
height: output_height,
223-
done: output_done,
224-
render_state: None, // This field won't be used in update_image
213+
name: output_state.name.clone(),
214+
width: output_state.width,
215+
height: output_state.height,
216+
done: output_state.done,
217+
transform: output_state.transform,
218+
render_state: crate::wayland::render_base::OutputRenderStateVariety::None,
225219
};
226220

227221
// Update existing wallpaper state with new image
228-
if let Some(OutputRenderStateVariety::Wallpaper(wallpaper_state)) =
229-
output_state.render_state.as_mut()
222+
if let OutputRenderStateVariety::Wallpaper(wallpaper_state) =
223+
&mut output_state.render_state
230224
{
231225
wallpaper_state.update_image(
232226
conn,
@@ -261,8 +255,8 @@ impl WallpaperThread {
261255
let new_slowdown = new_config.animation.slowdown.max(0.001);
262256

263257
for (_, output_state) in &mut state.outputs {
264-
if let Some(OutputRenderStateVariety::Wallpaper(wallpaper_state)) =
265-
output_state.render_state.as_mut()
258+
if let OutputRenderStateVariety::Wallpaper(wallpaper_state) =
259+
&mut output_state.render_state
266260
{
267261
wallpaper_state.slowdown = new_slowdown;
268262
self.verbose(format!(
@@ -296,8 +290,8 @@ impl WallpaperThread {
296290
}
297291
};
298292

299-
if let Some(OutputRenderStateVariety::Wallpaper(render_state)) =
300-
output_state.render_state.as_mut()
293+
if let OutputRenderStateVariety::Wallpaper(render_state) =
294+
&mut output_state.render_state
301295
{
302296
render_state.scroll(conn, cmd.position_x, cmd.position_y);
303297
} else {

src/wayland/render_base.rs

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::pithos::anims::spring::Spring;
33
use crate::pithos::commands::RenderMode;
44
use crate::pithos::config::DaemonConfig;
55
use crate::pithos::misc::get_viewport_dimensions;
6-
use crate::wayland::render_base::OutputRenderStateVariety::Wallpaper;
76

87
use std::collections::HashMap;
98
use std::fs::File;
@@ -86,17 +85,16 @@ impl RenderThreadState {
8685

8786
pub fn is_animating(&self) -> bool {
8887
for (_, output_state) in &self.outputs {
89-
if let Some(render_state) = &output_state.render_state {
90-
match render_state {
91-
Wallpaper(wallpaper_render_state) => {
88+
match &output_state.render_state {
89+
OutputRenderStateVariety::Wallpaper(wallpaper_render_state) => {
9290
if wallpaper_render_state.width.scroll_state.is_some() {
9391
return true;
9492
}
9593
if wallpaper_render_state.height.scroll_state.is_some() {
9694
return true;
9795
}
98-
} //Lockscreen => (),
99-
}
96+
} //OutputRenderStateVariety::Lockscreen => (),
97+
OutputRenderStateVariety::None => {}
10098
}
10199
}
102100
false
@@ -143,13 +141,26 @@ impl RenderThreadState {
143141
}
144142
}
145143

146-
#[derive(Default)]
147144
pub struct OutputState {
148145
pub name: String,
149146
pub width: i32,
150147
pub height: i32,
151148
pub done: bool,
152-
pub render_state: Option<OutputRenderStateVariety>,
149+
pub transform: wl_output::Transform,
150+
pub render_state: OutputRenderStateVariety,
151+
}
152+
153+
impl Default for OutputState {
154+
fn default() -> Self {
155+
Self {
156+
name: String::default(),
157+
width: 0,
158+
height: 0,
159+
done: false,
160+
transform: wl_output::Transform::Normal,
161+
render_state: OutputRenderStateVariety::None,
162+
}
163+
}
153164
}
154165

155166
impl OutputState {
@@ -160,26 +171,27 @@ impl OutputState {
160171
prior_state: &mut OutputState,
161172
render_state: &mut RenderThreadState,
162173
) {
163-
if let Some(kind) = &mut prior_state.render_state {
164-
let new_state = match kind {
165-
Wallpaper(wp_state) => Wallpaper(WallpaperRenderState::from_prior(
174+
match &mut prior_state.render_state {
175+
OutputRenderStateVariety::Wallpaper(wp_state) => {
176+
let new_state = OutputRenderStateVariety::Wallpaper(WallpaperRenderState::from_prior(
166177
conn, render_state, wp_state, new_output, self,
167-
)),
168-
};
169-
self.render_state = Some(new_state);
178+
));
179+
self.render_state = new_state;
180+
}
181+
OutputRenderStateVariety::None => {}
170182
}
171183
}
172184

173185
pub fn yeet(&mut self, conn: &mut Connection<RenderThreadState>) {
174-
if let Some(kind) = &self.render_state {
175-
match kind {
176-
Wallpaper(wp_state) => wp_state.yeet(conn),
177-
};
186+
match &self.render_state {
187+
OutputRenderStateVariety::Wallpaper(wp_state) => wp_state.yeet(conn),
188+
OutputRenderStateVariety::None => {}
178189
}
179190
}
180191
}
181192

182193
pub enum OutputRenderStateVariety {
194+
None,
183195
Wallpaper(WallpaperRenderState),
184196
//Lockscreen,
185197
}
@@ -634,16 +646,15 @@ fn frame_callback(ctx: EventCtx<RenderThreadState, WlCallback>) {
634646
// where we update that in the draw loop -> dispatch stuff
635647
// rly goofy ngl........
636648
for (_, os) in &mut ctx.state.outputs {
637-
if let Some(render_state) = &mut os.render_state {
638-
match render_state {
639-
OutputRenderStateVariety::Wallpaper(wallpaper_render_state) => {
640-
if wallpaper_render_state.width.scroll_state.is_some()
641-
|| wallpaper_render_state.height.scroll_state.is_some()
642-
{
643-
wallpaper_render_state.do_scroll_tick(ctx.conn);
644-
}
645-
} //OutputRenderStateVariety::Lockscreen => (),
646-
}
649+
match &mut os.render_state {
650+
OutputRenderStateVariety::Wallpaper(wallpaper_render_state) => {
651+
if wallpaper_render_state.width.scroll_state.is_some()
652+
|| wallpaper_render_state.height.scroll_state.is_some()
653+
{
654+
wallpaper_render_state.do_scroll_tick(ctx.conn);
655+
}
656+
} //OutputRenderStateVariety::Lockscreen => (),
657+
OutputRenderStateVariety::None => {}
647658
}
648659
}
649660
}
@@ -727,7 +738,8 @@ pub fn initialize_wallpaper_outputs(
727738
width,
728739
height,
729740
done,
730-
render_state: None,
741+
transform: wl_output::Transform::Normal,
742+
render_state: OutputRenderStateVariety::None,
731743
};
732744

733745
let wallpaper_state = WallpaperRenderState::new(
@@ -743,7 +755,7 @@ pub fn initialize_wallpaper_outputs(
743755

744756
// Find the actual output state and update it
745757
if let Some((_, output_state)) = state.outputs.iter_mut().find(|(_, os)| os.name == output_name) {
746-
output_state.render_state = Some(OutputRenderStateVariety::Wallpaper(wallpaper_state));
758+
output_state.render_state = OutputRenderStateVariety::Wallpaper(wallpaper_state);
747759
}
748760
}
749761
}
@@ -823,13 +835,6 @@ fn wl_output_cb(ctx: EventCtx<RenderThreadState, WlOutput>) {
823835
.find(|o| o.0.wl_output == ctx.proxy)
824836
.unwrap();
825837

826-
if output.done {
827-
println!(
828-
"received event {:?} for output that's already .done - reseat?",
829-
ctx.event
830-
);
831-
return;
832-
}
833838
match ctx.event {
834839
wl_output::Event::Name(name) => {
835840
output_state.name = name.clone().into_string().unwrap();
@@ -839,6 +844,29 @@ fn wl_output_cb(ctx: EventCtx<RenderThreadState, WlOutput>) {
839844
output_state.width = mode.width;
840845
output_state.height = mode.height;
841846
}
847+
wl_output::Event::Geometry(geometry) => {
848+
let prev_transform = output_state.transform;
849+
let new_transform = geometry.transform;
850+
851+
// Check if transform changed from/to a 90° or 270° rotation
852+
let prev_is_rotated = matches!(prev_transform,
853+
wl_output::Transform::_90 | wl_output::Transform::_270 |
854+
wl_output::Transform::Flipped90 | wl_output::Transform::Flipped270);
855+
let new_is_rotated = matches!(new_transform,
856+
wl_output::Transform::_90 | wl_output::Transform::_270 |
857+
wl_output::Transform::Flipped90 | wl_output::Transform::Flipped270);
858+
859+
// Update the transform
860+
output_state.transform = new_transform;
861+
862+
// If rotation state changed, swap width/height and flag for reseat
863+
if prev_is_rotated != new_is_rotated {
864+
let old_width = output_state.width;
865+
output_state.width = output_state.height;
866+
output_state.height = old_width;
867+
ctx.state.reseat_needed = true;
868+
}
869+
}
842870
// wl_output::Event::Scale(scale) => output.scale = Some(scale), // maybe track this for lockscreen element scaling?
843871
wl_output::Event::Done => {
844872
output_state.done = true;

0 commit comments

Comments
 (0)