Add live-reload of output scales
Browse files at this commit69907f123d2f17bc1f9a04c0bda7430f250404deParent: 6ca3b6d4 changed files +56 -10
- src/layout/mod.rs +3 -0
- src/layout/workspace.rs +13 -3
- src/niri.rs +33 -4
- src/screenshot_ui.rs +7 -3
src/layout/mod.rsmodified+3 -0
| @@ -637,6 +637,8 @@ impl<W: LayoutElement> Layout<W> { | |||
| 637 | } | 637 | } |
| 638 | 638 | ||
| 639 | pub fn update_output_size(&mut self, output: &Output) { | 639 | pub fn update_output_size(&mut self, output: &Output) { |
| 640 | + let _span = tracy_client::span!("Layout::update_output_size"); | ||
| 641 | + | ||
| 640 | let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else { | 642 | let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else { |
| 641 | panic!() | 643 | panic!() |
| 642 | }; | 644 | }; |
| @@ -648,6 +650,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 648 | 650 | ||
| 649 | for ws in &mut mon.workspaces { | 651 | for ws in &mut mon.workspaces { |
| 650 | ws.set_view_size(view_size, working_area); | 652 | ws.set_view_size(view_size, working_area); |
| 653 | + ws.update_output_scale_transform(); | ||
| 651 | } | 654 | } |
| 652 | 655 | ||
| 653 | break; | 656 | break; |
src/layout/workspace.rsmodified+13 -3
| @@ -308,7 +308,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 308 | 308 | ||
| 309 | fn enter_output_for_window(&self, window: &W) { | 309 | fn enter_output_for_window(&self, window: &W) { |
| 310 | if let Some(output) = &self.output { | 310 | if let Some(output) = &self.output { |
| 311 | - prepare_for_output(window, output); | 311 | + set_preferred_scale_transform(window, output); |
| 312 | window.output_enter(output); | 312 | window.output_enter(output); |
| 313 | } | 313 | } |
| 314 | } | 314 | } |
| @@ -330,6 +330,15 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 330 | } | 330 | } |
| 331 | } | 331 | } |
| 332 | 332 | ||
| 333 | + pub fn update_output_scale_transform(&mut self) { | ||
| 334 | + let Some(output) = self.output.as_ref() else { | ||
| 335 | + return; | ||
| 336 | + }; | ||
| 337 | + for window in self.windows() { | ||
| 338 | + set_preferred_scale_transform(window, output); | ||
| 339 | + } | ||
| 340 | + } | ||
| 341 | + | ||
| 333 | fn toplevel_bounds(&self) -> Size<i32, Logical> { | 342 | fn toplevel_bounds(&self) -> Size<i32, Logical> { |
| 334 | let mut border = 0; | 343 | let mut border = 0; |
| 335 | if !self.options.border.off { | 344 | if !self.options.border.off { |
| @@ -363,7 +372,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 363 | let bounds = self.toplevel_bounds(); | 372 | let bounds = self.toplevel_bounds(); |
| 364 | 373 | ||
| 365 | if let Some(output) = self.output.as_ref() { | 374 | if let Some(output) = self.output.as_ref() { |
| 366 | - prepare_for_output(window, output); | 375 | + set_preferred_scale_transform(window, output); |
| 367 | } | 376 | } |
| 368 | 377 | ||
| 369 | window.toplevel().with_pending_state(|state| { | 378 | window.toplevel().with_pending_state(|state| { |
| @@ -1626,7 +1635,8 @@ fn compute_new_view_offset( | |||
| 1626 | } | 1635 | } |
| 1627 | } | 1636 | } |
| 1628 | 1637 | ||
| 1629 | -fn prepare_for_output(window: &impl LayoutElement, output: &Output) { | 1638 | +fn set_preferred_scale_transform(window: &impl LayoutElement, output: &Output) { |
| 1639 | + // FIXME: cache this on the workspace. | ||
| 1630 | let scale = output.current_scale().integer_scale(); | 1640 | let scale = output.current_scale().integer_scale(); |
| 1631 | let transform = output.current_transform(); | 1641 | let transform = output.current_transform(); |
| 1632 | window.set_preferred_scale_transform(scale, transform); | 1642 | window.set_preferred_scale_transform(scale, transform); |
src/niri.rsmodified+33 -4
| @@ -41,7 +41,7 @@ use smithay::desktop::{ | |||
| 41 | use smithay::input::keyboard::{Layout as KeyboardLayout, XkbContextHandler}; | 41 | use smithay::input::keyboard::{Layout as KeyboardLayout, XkbContextHandler}; |
| 42 | use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent}; | 42 | use smithay::input::pointer::{CursorIcon, CursorImageAttributes, CursorImageStatus, MotionEvent}; |
| 43 | use smithay::input::{Seat, SeatState}; | 43 | use smithay::input::{Seat, SeatState}; |
| 44 | -use smithay::output::Output; | 44 | +use smithay::output::{self, Output}; |
| 45 | use smithay::reexports::calloop::generic::Generic; | 45 | use smithay::reexports::calloop::generic::Generic; |
| 46 | use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; | 46 | use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; |
| 47 | use smithay::reexports::calloop::{ | 47 | use smithay::reexports::calloop::{ |
| @@ -587,11 +587,37 @@ impl State { | |||
| 587 | } | 587 | } |
| 588 | 588 | ||
| 589 | if output_config_changed { | 589 | if output_config_changed { |
| 590 | + let mut resized_outputs = vec![]; | ||
| 591 | + for output in self.niri.global_space.outputs() { | ||
| 592 | + let name = output.name(); | ||
| 593 | + let scale = self | ||
| 594 | + .niri | ||
| 595 | + .config | ||
| 596 | + .borrow() | ||
| 597 | + .outputs | ||
| 598 | + .iter() | ||
| 599 | + .find(|o| o.name == name) | ||
| 600 | + .map(|c| c.scale) | ||
| 601 | + .unwrap_or(1.); | ||
| 602 | + let scale = scale.clamp(1., 10.).ceil() as i32; | ||
| 603 | + if output.current_scale().integer_scale() != scale { | ||
| 604 | + output.change_current_state( | ||
| 605 | + None, | ||
| 606 | + None, | ||
| 607 | + Some(output::Scale::Integer(scale)), | ||
| 608 | + None, | ||
| 609 | + ); | ||
| 610 | + resized_outputs.push(output.clone()); | ||
| 611 | + } | ||
| 612 | + } | ||
| 613 | + for output in resized_outputs { | ||
| 614 | + self.niri.output_resized(output); | ||
| 615 | + } | ||
| 616 | + | ||
| 590 | self.niri.reposition_outputs(None); | 617 | self.niri.reposition_outputs(None); |
| 591 | } | 618 | } |
| 592 | 619 | ||
| 593 | self.niri.queue_redraw_all(); | 620 | self.niri.queue_redraw_all(); |
| 594 | - // FIXME: apply output scale and whatnot. | ||
| 595 | // FIXME: apply libinput device settings. | 621 | // FIXME: apply libinput device settings. |
| 596 | // FIXME: apply xdg decoration settings. | 622 | // FIXME: apply xdg decoration settings. |
| 597 | } | 623 | } |
| @@ -1168,11 +1194,14 @@ impl Niri { | |||
| 1168 | } | 1194 | } |
| 1169 | 1195 | ||
| 1170 | // If the output size changed with an open screenshot UI, close the screenshot UI. | 1196 | // If the output size changed with an open screenshot UI, close the screenshot UI. |
| 1171 | - if let Some(old_size) = self.screenshot_ui.output_size(&output) { | 1197 | + if let Some((old_size, old_scale)) = self.screenshot_ui.output_size(&output) { |
| 1172 | let output_transform = output.current_transform(); | 1198 | let output_transform = output.current_transform(); |
| 1173 | let output_mode = output.current_mode().unwrap(); | 1199 | let output_mode = output.current_mode().unwrap(); |
| 1174 | let size = output_transform.transform_size(output_mode.size); | 1200 | let size = output_transform.transform_size(output_mode.size); |
| 1175 | - if old_size != size { | 1201 | + let scale = output.current_scale().integer_scale(); |
| 1202 | + // FIXME: scale changes shouldn't matter but they currently do since I haven't quite | ||
| 1203 | + // figured out how to draw the screenshot textures in physical coordinates. | ||
| 1204 | + if old_size != size || old_scale != scale { | ||
| 1176 | self.screenshot_ui.close(); | 1205 | self.screenshot_ui.close(); |
| 1177 | self.cursor_manager | 1206 | self.cursor_manager |
| 1178 | .set_cursor_image(CursorImageStatus::default_named()); | 1207 | .set_cursor_image(CursorImageStatus::default_named()); |
src/screenshot_ui.rsmodified+7 -3
| @@ -41,6 +41,7 @@ pub enum ScreenshotUi { | |||
| 41 | 41 | ||
| 42 | pub struct OutputData { | 42 | pub struct OutputData { |
| 43 | size: Size<i32, Physical>, | 43 | size: Size<i32, Physical>, |
| 44 | + scale: i32, | ||
| 44 | texture: GlesTexture, | 45 | texture: GlesTexture, |
| 45 | texture_buffer: TextureBuffer<GlesTexture>, | 46 | texture_buffer: TextureBuffer<GlesTexture>, |
| 46 | buffers: [SolidColorBuffer; 8], | 47 | buffers: [SolidColorBuffer; 8], |
| @@ -106,10 +107,11 @@ impl ScreenshotUi { | |||
| 106 | let output_transform = output.current_transform(); | 107 | let output_transform = output.current_transform(); |
| 107 | let output_mode = output.current_mode().unwrap(); | 108 | let output_mode = output.current_mode().unwrap(); |
| 108 | let size = output_transform.transform_size(output_mode.size); | 109 | let size = output_transform.transform_size(output_mode.size); |
| 110 | + let scale = output.current_scale().integer_scale(); | ||
| 109 | let texture_buffer = TextureBuffer::from_texture( | 111 | let texture_buffer = TextureBuffer::from_texture( |
| 110 | renderer, | 112 | renderer, |
| 111 | texture.clone(), | 113 | texture.clone(), |
| 112 | - output.current_scale().integer_scale(), | 114 | + scale, |
| 113 | Transform::Normal, | 115 | Transform::Normal, |
| 114 | None, | 116 | None, |
| 115 | ); | 117 | ); |
| @@ -126,6 +128,7 @@ impl ScreenshotUi { | |||
| 126 | let locations = [Default::default(); 8]; | 128 | let locations = [Default::default(); 8]; |
| 127 | let data = OutputData { | 129 | let data = OutputData { |
| 128 | size, | 130 | size, |
| 131 | + scale, | ||
| 129 | texture, | 132 | texture, |
| 130 | texture_buffer, | 133 | texture_buffer, |
| 131 | buffers, | 134 | buffers, |
| @@ -330,9 +333,10 @@ impl ScreenshotUi { | |||
| 330 | } | 333 | } |
| 331 | } | 334 | } |
| 332 | 335 | ||
| 333 | - pub fn output_size(&self, output: &Output) -> Option<Size<i32, Physical>> { | 336 | + pub fn output_size(&self, output: &Output) -> Option<(Size<i32, Physical>, i32)> { |
| 334 | if let Self::Open { output_data, .. } = self { | 337 | if let Self::Open { output_data, .. } = self { |
| 335 | - Some(output_data.get(output)?.size) | 338 | + let data = output_data.get(output)?; |
| 339 | + Some((data.size, data.scale)) | ||
| 336 | } else { | 340 | } else { |
| 337 | None | 341 | None |
| 338 | } | 342 | } |