diff options
Diffstat (limited to 'src/handlers')
| -rw-r--r-- | src/handlers/compositor.rs | 51 | ||||
| -rw-r--r-- | src/handlers/layer_shell.rs | 19 | ||||
| -rw-r--r-- | src/handlers/mod.rs | 42 | ||||
| -rw-r--r-- | src/handlers/xdg_shell.rs | 45 |
4 files changed, 84 insertions, 73 deletions
diff --git a/src/handlers/compositor.rs b/src/handlers/compositor.rs index e126f9df..035daafc 100644 --- a/src/handlers/compositor.rs +++ b/src/handlers/compositor.rs @@ -13,12 +13,11 @@ use smithay::wayland::shm::{ShmHandler, ShmState}; use smithay::{delegate_compositor, delegate_shm}; use super::xdg_shell; -use crate::niri::ClientState; -use crate::Niri; +use crate::niri::{ClientState, State}; -impl CompositorHandler for Niri { +impl CompositorHandler for State { fn compositor_state(&mut self) -> &mut CompositorState { - &mut self.compositor_state + &mut self.niri.compositor_state } fn client_compositor_state<'a>(&self, client: &'a Client) -> &'a CompositorClientState { @@ -41,7 +40,7 @@ impl CompositorHandler for Niri { if surface == &root_surface { // This is a root surface commit. It might have mapped a previously-unmapped toplevel. - if let Entry::Occupied(entry) = self.unmapped_windows.entry(surface.clone()) { + if let Entry::Occupied(entry) = self.niri.unmapped_windows.entry(surface.clone()) { let is_mapped = with_renderer_surface_state(surface, |state| state.buffer().is_some()); @@ -50,9 +49,11 @@ impl CompositorHandler for Niri { let window = entry.remove(); window.on_commit(); - let output = self.monitor_set.active_output().unwrap().clone(); - self.monitor_set.add_window_to_output(&output, window, true); - self.queue_redraw(output); + let output = self.niri.monitor_set.active_output().unwrap().clone(); + self.niri + .monitor_set + .add_window_to_output(&output, window, true); + self.niri.queue_redraw(output); return; } @@ -63,7 +64,7 @@ impl CompositorHandler for Niri { } // This is a commit of a previously-mapped root or a non-toplevel root. - if let Some((window, output)) = self.monitor_set.find_window_and_output(surface) { + if let Some((window, output)) = self.niri.monitor_set.find_window_and_output(surface) { // This is a commit of a previously-mapped toplevel. window.on_commit(); @@ -73,16 +74,16 @@ impl CompositorHandler for Niri { if !is_mapped { // The toplevel got unmapped. - self.monitor_set.remove_window(&window); - self.unmapped_windows.insert(surface.clone(), window); - self.queue_redraw(output); + self.niri.monitor_set.remove_window(&window); + self.niri.unmapped_windows.insert(surface.clone(), window); + self.niri.queue_redraw(output); return; } // The toplevel remains mapped. - self.monitor_set.update_window(&window); + self.niri.monitor_set.update_window(&window); - self.queue_redraw(output); + self.niri.queue_redraw(output); return; } @@ -90,21 +91,21 @@ impl CompositorHandler for Niri { } // This is a commit of a non-root or a non-toplevel root. - let root_window_output = self.monitor_set.find_window_and_output(&root_surface); + let root_window_output = self.niri.monitor_set.find_window_and_output(&root_surface); if let Some((window, output)) = root_window_output { window.on_commit(); - self.monitor_set.update_window(&window); - self.queue_redraw(output); + self.niri.monitor_set.update_window(&window); + self.niri.queue_redraw(output); return; } // This might be a popup. self.popups_handle_commit(surface); - if let Some(popup) = self.popups.find_popup(surface) { + if let Some(popup) = self.niri.popups.find_popup(surface) { if let Ok(root) = find_popup_root_surface(&popup) { - let root_window_output = self.monitor_set.find_window_and_output(&root); + let root_window_output = self.niri.monitor_set.find_window_and_output(&root); if let Some((_window, output)) = root_window_output { - self.queue_redraw(output); + self.niri.queue_redraw(output); } } } @@ -114,15 +115,15 @@ impl CompositorHandler for Niri { } } -impl BufferHandler for Niri { +impl BufferHandler for State { fn buffer_destroyed(&mut self, _buffer: &wl_buffer::WlBuffer) {} } -impl ShmHandler for Niri { +impl ShmHandler for State { fn shm_state(&self) -> &ShmState { - &self.shm_state + &self.niri.shm_state } } -delegate_compositor!(Niri); -delegate_shm!(Niri); +delegate_compositor!(State); +delegate_shm!(State); diff --git a/src/handlers/layer_shell.rs b/src/handlers/layer_shell.rs index 236ae7ab..39be2345 100644 --- a/src/handlers/layer_shell.rs +++ b/src/handlers/layer_shell.rs @@ -9,11 +9,11 @@ use smithay::wayland::shell::wlr_layer::{ WlrLayerShellState, }; -use crate::niri::Niri; +use crate::niri::State; -impl WlrLayerShellHandler for Niri { +impl WlrLayerShellHandler for State { fn shell_state(&mut self) -> &mut WlrLayerShellState { - &mut self.layer_shell_state + &mut self.niri.layer_shell_state } fn new_layer_surface( @@ -26,7 +26,7 @@ impl WlrLayerShellHandler for Niri { let output = wl_output .as_ref() .and_then(Output::from_resource) - .or_else(|| self.monitor_set.active_output().cloned()) + .or_else(|| self.niri.monitor_set.active_output().cloned()) .unwrap(); let mut map = layer_map_for_output(&output); map.map_layer(&LayerSurface::new(surface, namespace)) @@ -35,7 +35,7 @@ impl WlrLayerShellHandler for Niri { fn layer_destroyed(&mut self, surface: WlrLayerSurface) { let output = if let Some((output, mut map, layer)) = - self.monitor_set.outputs().find_map(|o| { + self.niri.monitor_set.outputs().find_map(|o| { let map = layer_map_for_output(o); let layer = map .layers() @@ -49,15 +49,16 @@ impl WlrLayerShellHandler for Niri { None }; if let Some(output) = output { - self.queue_redraw(output); + self.niri.queue_redraw(output); } } } -delegate_layer_shell!(Niri); +delegate_layer_shell!(State); -impl Niri { +impl State { pub fn layer_shell_handle_commit(&mut self, surface: &WlSurface) { let Some(output) = self + .niri .monitor_set .outputs() .find(|o| { @@ -95,6 +96,6 @@ impl Niri { } drop(map); - self.queue_redraw(output); + self.niri.queue_redraw(output); } } diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index 782b7b37..7e643d5d 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -16,62 +16,62 @@ use smithay::{ delegate_seat, delegate_tablet_manager, }; -use crate::Niri; +use crate::niri::State; -impl SeatHandler for Niri { +impl SeatHandler for State { type KeyboardFocus = WlSurface; type PointerFocus = WlSurface; - fn seat_state(&mut self) -> &mut SeatState<Niri> { - &mut self.seat_state + fn seat_state(&mut self) -> &mut SeatState<State> { + &mut self.niri.seat_state } fn cursor_image(&mut self, _seat: &Seat<Self>, image: CursorImageStatus) { - self.cursor_image = image; + self.niri.cursor_image = image; // FIXME: more granular - self.queue_redraw_all(); + self.niri.queue_redraw_all(); } fn focus_changed(&mut self, seat: &Seat<Self>, focused: Option<&WlSurface>) { - let dh = &self.display_handle; + let dh = &self.niri.display_handle; let client = focused.and_then(|s| dh.get_client(s.id()).ok()); set_data_device_focus(dh, seat, client); } } -delegate_seat!(Niri); -delegate_tablet_manager!(Niri); -delegate_pointer_gestures!(Niri); +delegate_seat!(State); +delegate_tablet_manager!(State); +delegate_pointer_gestures!(State); -impl DataDeviceHandler for Niri { +impl DataDeviceHandler for State { type SelectionUserData = (); fn data_device_state(&self) -> &DataDeviceState { - &self.data_device_state + &self.niri.data_device_state } } -impl ClientDndGrabHandler for Niri { +impl ClientDndGrabHandler for State { fn started( &mut self, _source: Option<WlDataSource>, icon: Option<WlSurface>, _seat: Seat<Self>, ) { - self.dnd_icon = icon; + self.niri.dnd_icon = icon; // FIXME: more granular - self.queue_redraw_all(); + self.niri.queue_redraw_all(); } fn dropped(&mut self, _seat: Seat<Self>) { - self.dnd_icon = None; + self.niri.dnd_icon = None; // FIXME: more granular - self.queue_redraw_all(); + self.niri.queue_redraw_all(); } } -impl ServerDndGrabHandler for Niri {} +impl ServerDndGrabHandler for State {} -delegate_data_device!(Niri); +delegate_data_device!(State); -delegate_output!(Niri); +delegate_output!(State); -delegate_presentation!(Niri); +delegate_presentation!(State); diff --git a/src/handlers/xdg_shell.rs b/src/handlers/xdg_shell.rs index 2f4448a4..b1dd9d4f 100644 --- a/src/handlers/xdg_shell.rs +++ b/src/handlers/xdg_shell.rs @@ -13,11 +13,11 @@ use smithay::wayland::shell::xdg::{ }; use crate::layout::{configure_new_window, output_size}; -use crate::Niri; +use crate::niri::State; -impl XdgShellHandler for Niri { +impl XdgShellHandler for State { fn xdg_shell_state(&mut self) -> &mut XdgShellState { - &mut self.xdg_shell_state + &mut self.niri.xdg_shell_state } fn new_toplevel(&mut self, surface: ToplevelSurface) { @@ -25,18 +25,18 @@ impl XdgShellHandler for Niri { let window = Window::new(surface); // Tell the surface the preferred size and bounds for its likely output. - let output = self.monitor_set.active_output().unwrap(); + let output = self.niri.monitor_set.active_output().unwrap(); configure_new_window(output_size(output), &window); // At the moment of creation, xdg toplevels must have no buffer. - let existing = self.unmapped_windows.insert(wl_surface, window); + let existing = self.niri.unmapped_windows.insert(wl_surface, window); assert!(existing.is_none()); } fn new_popup(&mut self, surface: PopupSurface, _positioner: PositionerState) { // FIXME: adjust the geometry so the popup doesn't overflow at least off the top and bottom // screen edges, and ideally off the view size. - if let Err(err) = self.popups.track_popup(PopupKind::Xdg(surface)) { + if let Err(err) = self.niri.popups.track_popup(PopupKind::Xdg(surface)) { warn!("error tracking popup: {err:?}"); } } @@ -101,17 +101,19 @@ impl XdgShellHandler for Niri { // location and configure size here, but the surface should be rendered fullscreen // independently from its buffer size if let Some((window, current_output)) = self + .niri .monitor_set .find_window_and_output(surface.wl_surface()) { if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { if requested_output != current_output { - self.monitor_set + self.niri + .monitor_set .move_window_to_output(window.clone(), &requested_output); } } - self.monitor_set.set_fullscreen(&window, true); + self.niri.monitor_set.set_fullscreen(&window, true); } } @@ -122,38 +124,45 @@ impl XdgShellHandler for Niri { fn unfullscreen_request(&mut self, surface: ToplevelSurface) { if let Some((window, _)) = self + .niri .monitor_set .find_window_and_output(surface.wl_surface()) { - self.monitor_set.set_fullscreen(&window, false); + self.niri.monitor_set.set_fullscreen(&window, false); } } fn toplevel_destroyed(&mut self, surface: ToplevelSurface) { - if self.unmapped_windows.remove(surface.wl_surface()).is_some() { + if self + .niri + .unmapped_windows + .remove(surface.wl_surface()) + .is_some() + { // An unmapped toplevel got destroyed. return; } let (window, output) = self + .niri .monitor_set .find_window_and_output(surface.wl_surface()) .unwrap(); - self.monitor_set.remove_window(&window); - self.queue_redraw(output); + self.niri.monitor_set.remove_window(&window); + self.niri.queue_redraw(output); } fn popup_destroyed(&mut self, surface: PopupSurface) { if let Ok(root) = find_popup_root_surface(&surface.into()) { - let root_window_output = self.monitor_set.find_window_and_output(&root); + let root_window_output = self.niri.monitor_set.find_window_and_output(&root); if let Some((_window, output)) = root_window_output { - self.queue_redraw(output); + self.niri.queue_redraw(output); } } } } -delegate_xdg_shell!(Niri); +delegate_xdg_shell!(State); pub fn send_initial_configure_if_needed(window: &Window) { let initial_configure_sent = with_states(window.toplevel().wl_surface(), |states| { @@ -171,12 +180,12 @@ pub fn send_initial_configure_if_needed(window: &Window) { } } -impl Niri { +impl State { /// Should be called on `WlSurface::commit` pub fn popups_handle_commit(&mut self, surface: &WlSurface) { - self.popups.commit(surface); + self.niri.popups.commit(surface); - if let Some(popup) = self.popups.find_popup(surface) { + if let Some(popup) = self.niri.popups.find_popup(surface) { let PopupKind::Xdg(ref popup) = popup; let initial_configure_sent = with_states(surface, |states| { states |
