diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-23 14:16:36 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-03-23 15:45:44 +0400 |
| commit | f3f02aca2058dd7adc4d75707ded2b5d8887a258 (patch) | |
| tree | ff5fdc1a81a5270f0f52a609c9f70a3afd79cf80 /src | |
| parent | 021a2a1af771421e39a990bb1eac624e0ef274de (diff) | |
| download | niri-f3f02aca2058dd7adc4d75707ded2b5d8887a258.tar.gz niri-f3f02aca2058dd7adc4d75707ded2b5d8887a258.tar.bz2 niri-f3f02aca2058dd7adc4d75707ded2b5d8887a258.zip | |
Lift output clones from queue_redraw()
Diffstat (limited to 'src')
| -rw-r--r-- | src/backend/tty.rs | 8 | ||||
| -rw-r--r-- | src/backend/winit.rs | 6 | ||||
| -rw-r--r-- | src/handlers/compositor.rs | 12 | ||||
| -rw-r--r-- | src/handlers/layer_shell.rs | 4 | ||||
| -rw-r--r-- | src/handlers/xdg_shell.rs | 6 | ||||
| -rw-r--r-- | src/input.rs | 8 | ||||
| -rw-r--r-- | src/niri.rs | 68 |
7 files changed, 57 insertions, 55 deletions
diff --git a/src/backend/tty.rs b/src/backend/tty.rs index fdf25df8..83315662 100644 --- a/src/backend/tty.rs +++ b/src/backend/tty.rs @@ -884,7 +884,7 @@ impl Tty { // Power on all monitors if necessary and queue a redraw on the new one. niri.event_loop.insert_idle(move |state| { state.niri.activate_monitors(&mut state.backend); - state.niri.queue_redraw(output); + state.niri.queue_redraw(&output); }); Ok(()) @@ -1067,7 +1067,7 @@ impl Tty { .non_continuous_frame(surface.vblank_frame_name); surface.vblank_frame = Some(vblank_frame); - niri.queue_redraw(output); + niri.queue_redraw(&output); } else { niri.send_frame_callbacks(&output); } @@ -1100,7 +1100,7 @@ impl Tty { } if output_state.unfinished_animations_remain { - niri.queue_redraw(output); + niri.queue_redraw(&output); } else { niri.send_frame_callbacks(&output); } @@ -1538,7 +1538,7 @@ impl Tty { output.change_current_state(Some(wl_mode), None, None, None); output.set_preferred(wl_mode); output_state.frame_clock = FrameClock::new(Some(refresh_interval(mode))); - niri.output_resized(output); + niri.output_resized(&output); } for (connector, crtc) in device.drm_scanner.crtcs() { diff --git a/src/backend/winit.rs b/src/backend/winit.rs index ca80f339..2f342b41 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -102,13 +102,11 @@ impl Winit { mode.width = size.w.clamp(0, u16::MAX as i32) as u16; mode.height = size.h.clamp(0, u16::MAX as i32) as u16; - state.niri.output_resized(winit.output.clone()); + state.niri.output_resized(&winit.output); } WinitEvent::Input(event) => state.process_input_event(event), WinitEvent::Focus(_) => (), - WinitEvent::Redraw => state - .niri - .queue_redraw(state.backend.winit().output.clone()), + WinitEvent::Redraw => state.niri.queue_redraw(&state.backend.winit().output), WinitEvent::CloseRequested => state.niri.stop_signal.stop(), }) .unwrap(); diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index 19489f2c..e6f950a3 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -168,7 +168,7 @@ impl CompositorHandler for State { self.maybe_warp_cursor_to_focus(); } - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); } return; } @@ -206,7 +206,7 @@ impl CompositorHandler for State { let unmapped = Unmapped::new(window); self.niri.unmapped_windows.insert(surface.clone(), unmapped); - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); return; } @@ -216,7 +216,7 @@ impl CompositorHandler for State { // Popup placement depends on window size which might have changed. self.update_reactive_popups(&window, &output); - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); return; } @@ -230,7 +230,7 @@ impl CompositorHandler for State { let output = output.clone(); window.on_commit(); self.niri.layout.update_window(&window); - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); return; } @@ -238,7 +238,7 @@ impl CompositorHandler for State { self.popups_handle_commit(surface); if let Some(popup) = self.niri.popups.find_popup(surface) { if let Some(output) = self.output_for_popup(&popup) { - self.niri.queue_redraw(output.clone()); + self.niri.queue_redraw(&output.clone()); } } @@ -263,7 +263,7 @@ impl CompositorHandler for State { for (output, state) in &self.niri.output_state { if let Some(lock_surface) = &state.lock_surface { if lock_surface.wl_surface() == surface { - self.niri.queue_redraw(output.clone()); + self.niri.queue_redraw(&output.clone()); break; } } diff --git a/src/handlers/layer_shell.rs b/src/handlers/layer_shell.rs index 117f14e1..bf1832fb 100644 --- a/src/handlers/layer_shell.rs +++ b/src/handlers/layer_shell.rs @@ -50,7 +50,7 @@ impl WlrLayerShellHandler for State { None }; if let Some(output) = output { - self.niri.output_resized(output); + self.niri.output_resized(&output); } } @@ -107,6 +107,6 @@ impl State { } drop(map); - self.niri.output_resized(output); + self.niri.output_resized(&output); } } diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index 1c200ee5..db629171 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -391,12 +391,12 @@ impl XdgShellHandler for State { self.maybe_warp_cursor_to_focus(); } - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); } fn popup_destroyed(&mut self, surface: PopupSurface) { if let Some(output) = self.output_for_popup(&PopupKind::Xdg(surface)) { - self.niri.queue_redraw(output.clone()); + self.niri.queue_redraw(&output.clone()); } } @@ -756,7 +756,7 @@ impl State { self.niri.layout.update_window(&window); if let Some(output) = output { - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); } } } diff --git a/src/input.rs b/src/input.rs index f84d85f1..f01d66a5 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1449,7 +1449,7 @@ impl State { .workspace_switch_gesture_update(delta_y, timestamp); if let Some(output) = res { if let Some(output) = output { - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); } handled = true; } @@ -1460,7 +1460,7 @@ impl State { .view_offset_gesture_update(delta_x, timestamp); if let Some(output) = res { if let Some(output) = output { - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); } handled = true; } @@ -1494,13 +1494,13 @@ impl State { .layout .workspace_switch_gesture_end(event.cancelled()); if let Some(output) = res { - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); handled = true; } let res = self.niri.layout.view_offset_gesture_end(event.cancelled()); if let Some(output) = res { - self.niri.queue_redraw(output); + self.niri.queue_redraw(&output); handled = true; } diff --git a/src/niri.rs b/src/niri.rs index baf62c5b..7984d3c4 100644 --- a/src/niri.rs +++ b/src/niri.rs @@ -338,6 +338,27 @@ pub enum CenterCoords { #[derive(Default)] pub struct WindowOffscreenId(pub RefCell<Option<Id>>); +impl RedrawState { + fn queue_redraw(self) -> Self { + match self { + RedrawState::Idle => RedrawState::Queued, + RedrawState::WaitingForEstimatedVBlank(token) => { + RedrawState::WaitingForEstimatedVBlankAndQueued(token) + } + + // A redraw is already queued. + value @ (RedrawState::Queued | RedrawState::WaitingForEstimatedVBlankAndQueued(_)) => { + value + } + + // We're waiting for VBlank, request a redraw afterwards. + RedrawState::WaitingForVBlank { .. } => RedrawState::WaitingForVBlank { + redraw_needed: true, + }, + } + } +} + impl Default for SurfaceFrameThrottlingState { fn default() -> Self { Self { @@ -863,7 +884,7 @@ impl State { } } for output in resized_outputs { - self.niri.output_resized(output); + self.niri.output_resized(&output); } self.backend.on_output_config_changed(&mut self.niri); @@ -955,7 +976,7 @@ impl State { } } ScreenCastToNiri::StopCast { session_id } => self.niri.stop_cast(session_id), - ScreenCastToNiri::Redraw(output) => self.niri.queue_redraw(output), + ScreenCastToNiri::Redraw(output) => self.niri.queue_redraw(&output), } } @@ -1423,7 +1444,7 @@ impl Niri { new_position.x, new_position.y ); output.change_current_state(None, None, None, Some(new_position)); - self.queue_redraw(output); + self.queue_redraw(&output); } } } @@ -1548,27 +1569,26 @@ impl Niri { } } - pub fn output_resized(&mut self, output: Output) { - let output_size = output_size(&output); + pub fn output_resized(&mut self, output: &Output) { + let output_size = output_size(output); let is_locked = self.is_locked(); - layer_map_for_output(&output).arrange(); - self.layout.update_output_size(&output); + layer_map_for_output(output).arrange(); + self.layout.update_output_size(output); - if let Some(state) = self.output_state.get_mut(&output) { + if let Some(state) = self.output_state.get_mut(output) { state.background_buffer.resize(output_size); state.lock_color_buffer.resize(output_size); if is_locked { if let Some(lock_surface) = &state.lock_surface { - configure_lock_surface(lock_surface, &output); + configure_lock_surface(lock_surface, output); } } } // If the output size changed with an open screenshot UI, close the screenshot UI. - if let Some((old_size, old_scale, old_transform)) = self.screenshot_ui.output_size(&output) - { + if let Some((old_size, old_scale, old_transform)) = self.screenshot_ui.output_size(output) { let transform = output.current_transform(); let output_mode = output.current_mode().unwrap(); let size = transform.transform_size(output_mode.size); @@ -1879,31 +1899,15 @@ impl Niri { /// Schedules an immediate redraw on all outputs if one is not already scheduled. pub fn queue_redraw_all(&mut self) { - let outputs: Vec<_> = self.output_state.keys().cloned().collect(); - for output in outputs { - self.queue_redraw(output); + for state in self.output_state.values_mut() { + state.redraw_state = mem::take(&mut state.redraw_state).queue_redraw(); } } /// Schedules an immediate redraw if one is not already scheduled. - pub fn queue_redraw(&mut self, output: Output) { - let state = self.output_state.get_mut(&output).unwrap(); - state.redraw_state = match mem::take(&mut state.redraw_state) { - RedrawState::Idle => RedrawState::Queued, - RedrawState::WaitingForEstimatedVBlank(token) => { - RedrawState::WaitingForEstimatedVBlankAndQueued(token) - } - - // A redraw is already queued. - value @ (RedrawState::Queued | RedrawState::WaitingForEstimatedVBlankAndQueued(_)) => { - value - } - - // We're waiting for VBlank, request a redraw afterwards. - RedrawState::WaitingForVBlank { .. } => RedrawState::WaitingForVBlank { - redraw_needed: true, - }, - }; + pub fn queue_redraw(&mut self, output: &Output) { + let state = self.output_state.get_mut(output).unwrap(); + state.redraw_state = mem::take(&mut state.redraw_state).queue_redraw(); } pub fn redraw_queued_outputs(&mut self, backend: &mut Backend) { |
