Move all traits one layer up
Browse files at this commit03a9fd8af3bbd8a0e6dbc33516dce83cce564166Parent: dcc6a5510 changed files +407 -388
- src/backend/mod.rs +35 -6
- src/backend/tty.rs +54 -66
- src/backend/winit.rs +43 -60
- src/handlers/compositor.rs +26 -25
- src/handlers/layer_shell.rs +10 -9
- src/handlers/mod.rs +21 -21
- src/handlers/xdg_shell.rs +27 -18
- src/input.rs +114 -116
- src/main.rs +13 -5
- src/niri.rs +64 -62
src/backend/mod.rsmodified+35 -6
| @@ -1,6 +1,7 @@ | |||
| 1 | use smithay::backend::renderer::gles::GlesRenderer; | 1 | use smithay::backend::renderer::gles::GlesRenderer; |
| 2 | use smithay::output::Output; | 2 | use smithay::output::Output; |
| 3 | 3 | ||
| 4 | +use crate::input::CompositorMod; | ||
| 4 | use crate::niri::OutputRenderElements; | 5 | use crate::niri::OutputRenderElements; |
| 5 | use crate::Niri; | 6 | use crate::Niri; |
| 6 | 7 | ||
| @@ -49,19 +50,47 @@ impl Backend { | |||
| 49 | } | 50 | } |
| 50 | } | 51 | } |
| 51 | 52 | ||
| 52 | - pub fn tty(&mut self) -> Option<&mut Tty> { | 53 | + pub fn mod_key(&self) -> CompositorMod { |
| 54 | + match self { | ||
| 55 | + Backend::Tty(_) => CompositorMod::Super, | ||
| 56 | + Backend::Winit(_) => CompositorMod::Alt, | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + pub fn change_vt(&mut self, vt: i32) { | ||
| 61 | + match self { | ||
| 62 | + Backend::Tty(tty) => tty.change_vt(vt), | ||
| 63 | + Backend::Winit(_) => (), | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + pub fn suspend(&mut self) { | ||
| 68 | + match self { | ||
| 69 | + Backend::Tty(tty) => tty.suspend(), | ||
| 70 | + Backend::Winit(_) => (), | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + pub fn toggle_debug_tint(&mut self) { | ||
| 75 | + match self { | ||
| 76 | + Backend::Tty(tty) => tty.toggle_debug_tint(), | ||
| 77 | + Backend::Winit(winit) => winit.toggle_debug_tint(), | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + pub fn tty(&mut self) -> &mut Tty { | ||
| 53 | if let Self::Tty(v) = self { | 82 | if let Self::Tty(v) = self { |
| 54 | - Some(v) | 83 | + v |
| 55 | } else { | 84 | } else { |
| 56 | - None | 85 | + panic!("backend is not Tty"); |
| 57 | } | 86 | } |
| 58 | } | 87 | } |
| 59 | 88 | ||
| 60 | - pub fn winit(&mut self) -> Option<&mut Winit> { | 89 | + pub fn winit(&mut self) -> &mut Winit { |
| 61 | if let Self::Winit(v) = self { | 90 | if let Self::Winit(v) = self { |
| 62 | - Some(v) | 91 | + v |
| 63 | } else { | 92 | } else { |
| 64 | - None | 93 | + panic!("backend is not Winit") |
| 65 | } | 94 | } |
| 66 | } | 95 | } |
| 67 | } | 96 | } |
src/backend/tty.rsmodified+54 -66
| @@ -30,16 +30,15 @@ use smithay::utils::DeviceFd; | |||
| 30 | use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner}; | 30 | use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner}; |
| 31 | use smithay_drm_extras::edid::EdidInfo; | 31 | use smithay_drm_extras::edid::EdidInfo; |
| 32 | 32 | ||
| 33 | -use crate::input::{BackendAction, CompositorMod}; | 33 | +use crate::niri::OutputRenderElements; |
| 34 | -use crate::niri::{Data, OutputRenderElements}; | 34 | +use crate::{LoopData, Niri}; |
| 35 | -use crate::Niri; | ||
| 36 | 35 | ||
| 37 | const BACKGROUND_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.]; | 36 | const BACKGROUND_COLOR: [f32; 4] = [0.1, 0.1, 0.1, 1.]; |
| 38 | const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888]; | 37 | const SUPPORTED_COLOR_FORMATS: &[Fourcc] = &[Fourcc::Argb8888, Fourcc::Abgr8888]; |
| 39 | 38 | ||
| 40 | pub struct Tty { | 39 | pub struct Tty { |
| 41 | session: LibSeatSession, | 40 | session: LibSeatSession, |
| 42 | - udev_dispatcher: Dispatcher<'static, UdevBackend, Data>, | 41 | + udev_dispatcher: Dispatcher<'static, UdevBackend, LoopData>, |
| 43 | primary_gpu_path: PathBuf, | 42 | primary_gpu_path: PathBuf, |
| 44 | output_device: Option<OutputDevice>, | 43 | output_device: Option<OutputDevice>, |
| 45 | } | 44 | } |
| @@ -69,44 +68,45 @@ struct TtyOutputState { | |||
| 69 | } | 68 | } |
| 70 | 69 | ||
| 71 | impl Tty { | 70 | impl Tty { |
| 72 | - pub fn new(event_loop: LoopHandle<'static, Data>) -> Self { | 71 | + pub fn new(event_loop: LoopHandle<'static, LoopData>) -> Self { |
| 73 | let (session, notifier) = LibSeatSession::new().unwrap(); | 72 | let (session, notifier) = LibSeatSession::new().unwrap(); |
| 74 | let seat_name = session.seat(); | 73 | let seat_name = session.seat(); |
| 75 | 74 | ||
| 76 | let udev_backend = UdevBackend::new(session.seat()).unwrap(); | 75 | let udev_backend = UdevBackend::new(session.seat()).unwrap(); |
| 77 | - let udev_dispatcher = Dispatcher::new(udev_backend, move |event, _, data: &mut Data| { | 76 | + let udev_dispatcher = |
| 78 | - let tty = data.backend.tty().unwrap(); | 77 | + Dispatcher::new(udev_backend, move |event, _, data: &mut LoopData| { |
| 79 | - let niri = &mut data.niri; | 78 | + let tty = data.state.backend.tty(); |
| 79 | + let niri = &mut data.state.niri; | ||
| 80 | 80 | ||
| 81 | - match event { | 81 | + match event { |
| 82 | - UdevEvent::Added { device_id, path } => { | 82 | + UdevEvent::Added { device_id, path } => { |
| 83 | - if !tty.session.is_active() { | 83 | + if !tty.session.is_active() { |
| 84 | - debug!("skipping UdevEvent::Added as session is inactive"); | 84 | + debug!("skipping UdevEvent::Added as session is inactive"); |
| 85 | - return; | 85 | + return; |
| 86 | - } | 86 | + } |
| 87 | 87 | ||
| 88 | - if let Err(err) = tty.device_added(device_id, &path, niri) { | 88 | + if let Err(err) = tty.device_added(device_id, &path, niri) { |
| 89 | - warn!("error adding device: {err:?}"); | 89 | + warn!("error adding device: {err:?}"); |
| 90 | - } | 90 | + } |
| 91 | - } | ||
| 92 | - UdevEvent::Changed { device_id } => { | ||
| 93 | - if !tty.session.is_active() { | ||
| 94 | - debug!("skipping UdevEvent::Changed as session is inactive"); | ||
| 95 | - return; | ||
| 96 | } | 91 | } |
| 92 | + UdevEvent::Changed { device_id } => { | ||
| 93 | + if !tty.session.is_active() { | ||
| 94 | + debug!("skipping UdevEvent::Changed as session is inactive"); | ||
| 95 | + return; | ||
| 96 | + } | ||
| 97 | 97 | ||
| 98 | - tty.device_changed(device_id, niri) | 98 | + tty.device_changed(device_id, niri) |
| 99 | - } | ||
| 100 | - UdevEvent::Removed { device_id } => { | ||
| 101 | - if !tty.session.is_active() { | ||
| 102 | - debug!("skipping UdevEvent::Removed as session is inactive"); | ||
| 103 | - return; | ||
| 104 | } | 99 | } |
| 100 | + UdevEvent::Removed { device_id } => { | ||
| 101 | + if !tty.session.is_active() { | ||
| 102 | + debug!("skipping UdevEvent::Removed as session is inactive"); | ||
| 103 | + return; | ||
| 104 | + } | ||
| 105 | 105 | ||
| 106 | - tty.device_removed(device_id, niri) | 106 | + tty.device_removed(device_id, niri) |
| 107 | + } | ||
| 107 | } | 108 | } |
| 108 | - } | 109 | + }); |
| 109 | - }); | ||
| 110 | event_loop | 110 | event_loop |
| 111 | .register_dispatcher(udev_dispatcher.clone()) | 111 | .register_dispatcher(udev_dispatcher.clone()) |
| 112 | .unwrap(); | 112 | .unwrap(); |
| @@ -117,43 +117,16 @@ impl Tty { | |||
| 117 | let input_backend = LibinputInputBackend::new(libinput.clone()); | 117 | let input_backend = LibinputInputBackend::new(libinput.clone()); |
| 118 | event_loop | 118 | event_loop |
| 119 | .insert_source(input_backend, |mut event, _, data| { | 119 | .insert_source(input_backend, |mut event, _, data| { |
| 120 | - let tty = data.backend.tty().unwrap(); | 120 | + data.state.process_libinput_event(&mut event); |
| 121 | - let niri = &mut data.niri; | 121 | + data.state.process_input_event(event); |
| 122 | - | ||
| 123 | - niri.process_libinput_event(&mut event); | ||
| 124 | - match niri.process_input_event(CompositorMod::Super, event) { | ||
| 125 | - BackendAction::None => (), | ||
| 126 | - BackendAction::ChangeVt(vt) => tty.change_vt(vt), | ||
| 127 | - BackendAction::Suspend => { | ||
| 128 | - if let Err(err) = suspend() { | ||
| 129 | - warn!("error suspending: {err:?}"); | ||
| 130 | - } | ||
| 131 | - } | ||
| 132 | - BackendAction::Screenshot => { | ||
| 133 | - let active = niri.monitor_set.active_output().cloned(); | ||
| 134 | - if let Some(active) = active { | ||
| 135 | - if let Err(err) = niri.screenshot(tty.renderer(), &active) { | ||
| 136 | - warn!("error taking screenshot: {err:?}"); | ||
| 137 | - } | ||
| 138 | - } | ||
| 139 | - } | ||
| 140 | - BackendAction::ToggleDebugTint => { | ||
| 141 | - if let Some(device) = tty.output_device.as_mut() { | ||
| 142 | - for (_, compositor) in &mut device.surfaces { | ||
| 143 | - compositor | ||
| 144 | - .set_debug_flags(compositor.debug_flags() ^ DebugFlags::TINT); | ||
| 145 | - } | ||
| 146 | - } | ||
| 147 | - } | ||
| 148 | - }; | ||
| 149 | }) | 122 | }) |
| 150 | .unwrap(); | 123 | .unwrap(); |
| 151 | 124 | ||
| 152 | let udev_dispatcher_c = udev_dispatcher.clone(); | 125 | let udev_dispatcher_c = udev_dispatcher.clone(); |
| 153 | event_loop | 126 | event_loop |
| 154 | .insert_source(notifier, move |event, _, data| { | 127 | .insert_source(notifier, move |event, _, data| { |
| 155 | - let tty = data.backend.tty().unwrap(); | 128 | + let tty = data.state.backend.tty(); |
| 156 | - let niri = &mut data.niri; | 129 | + let niri = &mut data.state.niri; |
| 157 | 130 | ||
| 158 | match event { | 131 | match event { |
| 159 | SessionEvent::PauseSession => { | 132 | SessionEvent::PauseSession => { |
| @@ -289,7 +262,7 @@ impl Tty { | |||
| 289 | let token = niri | 262 | let token = niri |
| 290 | .event_loop | 263 | .event_loop |
| 291 | .insert_source(drm_notifier, move |event, metadata, data| { | 264 | .insert_source(drm_notifier, move |event, metadata, data| { |
| 292 | - let tty = data.backend.tty().unwrap(); | 265 | + let tty = data.state.backend.tty(); |
| 293 | match event { | 266 | match event { |
| 294 | DrmEvent::VBlank(crtc) => { | 267 | DrmEvent::VBlank(crtc) => { |
| 295 | tracy_client::Client::running() | 268 | tracy_client::Client::running() |
| @@ -336,6 +309,7 @@ impl Tty { | |||
| 336 | } | 309 | } |
| 337 | 310 | ||
| 338 | let output = data | 311 | let output = data |
| 312 | + .state | ||
| 339 | .niri | 313 | .niri |
| 340 | .global_space | 314 | .global_space |
| 341 | .outputs() | 315 | .outputs() |
| @@ -345,10 +319,10 @@ impl Tty { | |||
| 345 | }) | 319 | }) |
| 346 | .unwrap() | 320 | .unwrap() |
| 347 | .clone(); | 321 | .clone(); |
| 348 | - let output_state = data.niri.output_state.get_mut(&output).unwrap(); | 322 | + let output_state = data.state.niri.output_state.get_mut(&output).unwrap(); |
| 349 | output_state.waiting_for_vblank = false; | 323 | output_state.waiting_for_vblank = false; |
| 350 | output_state.frame_clock.presented(presentation_time); | 324 | output_state.frame_clock.presented(presentation_time); |
| 351 | - data.niri.queue_redraw(output); | 325 | + data.state.niri.queue_redraw(output); |
| 352 | } | 326 | } |
| 353 | DrmEvent::Error(error) => error!("DRM error: {error}"), | 327 | DrmEvent::Error(error) => error!("DRM error: {error}"), |
| 354 | }; | 328 | }; |
| @@ -589,11 +563,25 @@ impl Tty { | |||
| 589 | } | 563 | } |
| 590 | } | 564 | } |
| 591 | 565 | ||
| 592 | - fn change_vt(&mut self, vt: i32) { | 566 | + pub fn change_vt(&mut self, vt: i32) { |
| 593 | if let Err(err) = self.session.change_vt(vt) { | 567 | if let Err(err) = self.session.change_vt(vt) { |
| 594 | error!("error changing VT: {err}"); | 568 | error!("error changing VT: {err}"); |
| 595 | } | 569 | } |
| 596 | } | 570 | } |
| 571 | + | ||
| 572 | + pub fn suspend(&self) { | ||
| 573 | + if let Err(err) = suspend() { | ||
| 574 | + warn!("error suspending: {err:?}"); | ||
| 575 | + } | ||
| 576 | + } | ||
| 577 | + | ||
| 578 | + pub fn toggle_debug_tint(&mut self) { | ||
| 579 | + if let Some(device) = self.output_device.as_mut() { | ||
| 580 | + for (_, compositor) in &mut device.surfaces { | ||
| 581 | + compositor.set_debug_flags(compositor.debug_flags() ^ DebugFlags::TINT); | ||
| 582 | + } | ||
| 583 | + } | ||
| 584 | + } | ||
| 597 | } | 585 | } |
| 598 | 586 | ||
| 599 | fn refresh_interval(mode: DrmMode) -> Duration { | 587 | fn refresh_interval(mode: DrmMode) -> Duration { |
src/backend/winit.rsmodified+43 -60
| @@ -3,7 +3,7 @@ use std::time::Duration; | |||
| 3 | use smithay::backend::renderer::damage::OutputDamageTracker; | 3 | use smithay::backend::renderer::damage::OutputDamageTracker; |
| 4 | use smithay::backend::renderer::gles::GlesRenderer; | 4 | use smithay::backend::renderer::gles::GlesRenderer; |
| 5 | use smithay::backend::renderer::{DebugFlags, Renderer}; | 5 | use smithay::backend::renderer::{DebugFlags, Renderer}; |
| 6 | -use smithay::backend::winit::{self, WinitError, WinitEvent, WinitEventLoop, WinitGraphicsBackend}; | 6 | +use smithay::backend::winit::{self, WinitError, WinitEvent, WinitGraphicsBackend}; |
| 7 | use smithay::output::{Mode, Output, PhysicalProperties, Subpixel}; | 7 | use smithay::output::{Mode, Output, PhysicalProperties, Subpixel}; |
| 8 | use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; | 8 | use smithay::reexports::calloop::timer::{TimeoutAction, Timer}; |
| 9 | use smithay::reexports::calloop::LoopHandle; | 9 | use smithay::reexports::calloop::LoopHandle; |
| @@ -12,25 +12,23 @@ use smithay::reexports::winit::dpi::LogicalSize; | |||
| 12 | use smithay::reexports::winit::window::WindowBuilder; | 12 | use smithay::reexports::winit::window::WindowBuilder; |
| 13 | use smithay::utils::Transform; | 13 | use smithay::utils::Transform; |
| 14 | 14 | ||
| 15 | -use crate::input::{BackendAction, CompositorMod}; | 15 | +use crate::niri::OutputRenderElements; |
| 16 | -use crate::niri::{Data, OutputRenderElements}; | ||
| 17 | use crate::utils::get_monotonic_time; | 16 | use crate::utils::get_monotonic_time; |
| 18 | -use crate::Niri; | 17 | +use crate::{LoopData, Niri}; |
| 19 | 18 | ||
| 20 | pub struct Winit { | 19 | pub struct Winit { |
| 21 | output: Output, | 20 | output: Output, |
| 22 | backend: WinitGraphicsBackend<GlesRenderer>, | 21 | backend: WinitGraphicsBackend<GlesRenderer>, |
| 23 | - winit_event_loop: WinitEventLoop, | ||
| 24 | damage_tracker: OutputDamageTracker, | 22 | damage_tracker: OutputDamageTracker, |
| 25 | } | 23 | } |
| 26 | 24 | ||
| 27 | impl Winit { | 25 | impl Winit { |
| 28 | - pub fn new(event_loop: LoopHandle<Data>) -> Self { | 26 | + pub fn new(event_loop: LoopHandle<LoopData>) -> Self { |
| 29 | let builder = WindowBuilder::new() | 27 | let builder = WindowBuilder::new() |
| 30 | .with_inner_size(LogicalSize::new(1280.0, 800.0)) | 28 | .with_inner_size(LogicalSize::new(1280.0, 800.0)) |
| 31 | // .with_resizable(false) | 29 | // .with_resizable(false) |
| 32 | .with_title("niri"); | 30 | .with_title("niri"); |
| 33 | - let (backend, winit_event_loop) = winit::init_from_builder(builder).unwrap(); | 31 | + let (backend, mut winit_event_loop) = winit::init_from_builder(builder).unwrap(); |
| 34 | 32 | ||
| 35 | let mode = Mode { | 33 | let mode = Mode { |
| 36 | size: backend.window_size().physical_size, | 34 | size: backend.window_size().physical_size, |
| @@ -59,8 +57,39 @@ impl Winit { | |||
| 59 | let timer = Timer::immediate(); | 57 | let timer = Timer::immediate(); |
| 60 | event_loop | 58 | event_loop |
| 61 | .insert_source(timer, move |_, _, data| { | 59 | .insert_source(timer, move |_, _, data| { |
| 62 | - let winit = data.backend.winit().unwrap(); | 60 | + let res = winit_event_loop.dispatch_new_events(|event| match event { |
| 63 | - winit.dispatch(&mut data.niri); | 61 | + WinitEvent::Resized { size, .. } => { |
| 62 | + let winit = data.state.backend.winit(); | ||
| 63 | + winit.output.change_current_state( | ||
| 64 | + Some(Mode { | ||
| 65 | + size, | ||
| 66 | + refresh: 60_000, | ||
| 67 | + }), | ||
| 68 | + None, | ||
| 69 | + None, | ||
| 70 | + None, | ||
| 71 | + ); | ||
| 72 | + data.state.niri.output_resized(winit.output.clone()); | ||
| 73 | + } | ||
| 74 | + WinitEvent::Input(event) => data.state.process_input_event(event), | ||
| 75 | + WinitEvent::Focus(_) => (), | ||
| 76 | + WinitEvent::Refresh => data | ||
| 77 | + .state | ||
| 78 | + .niri | ||
| 79 | + .queue_redraw(data.state.backend.winit().output.clone()), | ||
| 80 | + }); | ||
| 81 | + | ||
| 82 | + // I want this to stop compiling if more errors are added. | ||
| 83 | + #[allow(clippy::single_match)] | ||
| 84 | + match res { | ||
| 85 | + Err(WinitError::WindowClosed) => { | ||
| 86 | + data.state.niri.stop_signal.stop(); | ||
| 87 | + data.state | ||
| 88 | + .niri | ||
| 89 | + .remove_output(&data.state.backend.winit().output); | ||
| 90 | + } | ||
| 91 | + Ok(()) => (), | ||
| 92 | + } | ||
| 64 | TimeoutAction::ToDuration(Duration::from_micros(16667)) | 93 | TimeoutAction::ToDuration(Duration::from_micros(16667)) |
| 65 | }) | 94 | }) |
| 66 | .unwrap(); | 95 | .unwrap(); |
| @@ -68,7 +97,6 @@ impl Winit { | |||
| 68 | Self { | 97 | Self { |
| 69 | output, | 98 | output, |
| 70 | backend, | 99 | backend, |
| 71 | - winit_event_loop, | ||
| 72 | damage_tracker, | 100 | damage_tracker, |
| 73 | } | 101 | } |
| 74 | } | 102 | } |
| @@ -88,56 +116,6 @@ impl Winit { | |||
| 88 | niri.add_output(self.output.clone(), None); | 116 | niri.add_output(self.output.clone(), None); |
| 89 | } | 117 | } |
| 90 | 118 | ||
| 91 | - fn dispatch(&mut self, niri: &mut Niri) { | ||
| 92 | - let renderer = self.backend.renderer(); | ||
| 93 | - let res = self | ||
| 94 | - .winit_event_loop | ||
| 95 | - .dispatch_new_events(|event| match event { | ||
| 96 | - WinitEvent::Resized { size, .. } => { | ||
| 97 | - self.output.change_current_state( | ||
| 98 | - Some(Mode { | ||
| 99 | - size, | ||
| 100 | - refresh: 60_000, | ||
| 101 | - }), | ||
| 102 | - None, | ||
| 103 | - None, | ||
| 104 | - None, | ||
| 105 | - ); | ||
| 106 | - niri.output_resized(self.output.clone()); | ||
| 107 | - } | ||
| 108 | - WinitEvent::Input(event) => { | ||
| 109 | - match niri.process_input_event(CompositorMod::Alt, event) { | ||
| 110 | - BackendAction::None => (), | ||
| 111 | - BackendAction::ChangeVt(_) => (), | ||
| 112 | - BackendAction::Suspend => (), | ||
| 113 | - BackendAction::Screenshot => { | ||
| 114 | - let active = niri.monitor_set.active_output().cloned(); | ||
| 115 | - if let Some(active) = active { | ||
| 116 | - if let Err(err) = niri.screenshot(renderer, &active) { | ||
| 117 | - warn!("error taking screenshot: {err:?}"); | ||
| 118 | - } | ||
| 119 | - } | ||
| 120 | - } | ||
| 121 | - BackendAction::ToggleDebugTint => { | ||
| 122 | - renderer.set_debug_flags(renderer.debug_flags() ^ DebugFlags::TINT); | ||
| 123 | - } | ||
| 124 | - } | ||
| 125 | - } | ||
| 126 | - WinitEvent::Focus(_) => (), | ||
| 127 | - WinitEvent::Refresh => niri.queue_redraw(self.output.clone()), | ||
| 128 | - }); | ||
| 129 | - | ||
| 130 | - // I want this to stop compiling if more errors are added. | ||
| 131 | - #[allow(clippy::single_match)] | ||
| 132 | - match res { | ||
| 133 | - Err(WinitError::WindowClosed) => { | ||
| 134 | - niri.stop_signal.stop(); | ||
| 135 | - niri.remove_output(&self.output); | ||
| 136 | - } | ||
| 137 | - Ok(()) => (), | ||
| 138 | - } | ||
| 139 | - } | ||
| 140 | - | ||
| 141 | pub fn seat_name(&self) -> String { | 119 | pub fn seat_name(&self) -> String { |
| 142 | "winit".to_owned() | 120 | "winit".to_owned() |
| 143 | } | 121 | } |
| @@ -175,4 +153,9 @@ impl Winit { | |||
| 175 | self.backend.window().request_redraw(); | 153 | self.backend.window().request_redraw(); |
| 176 | } | 154 | } |
| 177 | } | 155 | } |
| 156 | + | ||
| 157 | + pub fn toggle_debug_tint(&mut self) { | ||
| 158 | + let renderer = self.backend.renderer(); | ||
| 159 | + renderer.set_debug_flags(renderer.debug_flags() ^ DebugFlags::TINT); | ||
| 160 | + } | ||
| 178 | } | 161 | } |
src/handlers/compositor.rsmodified+26 -25
| @@ -13,12 +13,11 @@ use smithay::wayland::shm::{ShmHandler, ShmState}; | |||
| 13 | use smithay::{delegate_compositor, delegate_shm}; | 13 | use smithay::{delegate_compositor, delegate_shm}; |
| 14 | 14 | ||
| 15 | use super::xdg_shell; | 15 | use super::xdg_shell; |
| 16 | -use crate::niri::ClientState; | 16 | +use crate::niri::{ClientState, State}; |
| 17 | -use crate::Niri; | ||
| 18 | 17 | ||
| 19 | -impl CompositorHandler for Niri { | 18 | +impl CompositorHandler for State { |
| 20 | fn compositor_state(&mut self) -> &mut CompositorState { | 19 | fn compositor_state(&mut self) -> &mut CompositorState { |
| 21 | - &mut self.compositor_state | 20 | + &mut self.niri.compositor_state |
| 22 | } | 21 | } |
| 23 | 22 | ||
| 24 | fn client_compositor_state<'a>(&self, client: &'a Client) -> &'a CompositorClientState { | 23 | fn client_compositor_state<'a>(&self, client: &'a Client) -> &'a CompositorClientState { |
| @@ -41,7 +40,7 @@ impl CompositorHandler for Niri { | |||
| 41 | 40 | ||
| 42 | if surface == &root_surface { | 41 | if surface == &root_surface { |
| 43 | // This is a root surface commit. It might have mapped a previously-unmapped toplevel. | 42 | // This is a root surface commit. It might have mapped a previously-unmapped toplevel. |
| 44 | - if let Entry::Occupied(entry) = self.unmapped_windows.entry(surface.clone()) { | 43 | + if let Entry::Occupied(entry) = self.niri.unmapped_windows.entry(surface.clone()) { |
| 45 | let is_mapped = | 44 | let is_mapped = |
| 46 | with_renderer_surface_state(surface, |state| state.buffer().is_some()); | 45 | with_renderer_surface_state(surface, |state| state.buffer().is_some()); |
| 47 | 46 | ||
| @@ -50,9 +49,11 @@ impl CompositorHandler for Niri { | |||
| 50 | let window = entry.remove(); | 49 | let window = entry.remove(); |
| 51 | window.on_commit(); | 50 | window.on_commit(); |
| 52 | 51 | ||
| 53 | - let output = self.monitor_set.active_output().unwrap().clone(); | 52 | + let output = self.niri.monitor_set.active_output().unwrap().clone(); |
| 54 | - self.monitor_set.add_window_to_output(&output, window, true); | 53 | + self.niri |
| 55 | - self.queue_redraw(output); | 54 | + .monitor_set |
| 55 | + .add_window_to_output(&output, window, true); | ||
| 56 | + self.niri.queue_redraw(output); | ||
| 56 | return; | 57 | return; |
| 57 | } | 58 | } |
| 58 | 59 | ||
| @@ -63,7 +64,7 @@ impl CompositorHandler for Niri { | |||
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | // This is a commit of a previously-mapped root or a non-toplevel root. | 66 | // This is a commit of a previously-mapped root or a non-toplevel root. |
| 66 | - if let Some((window, output)) = self.monitor_set.find_window_and_output(surface) { | 67 | + if let Some((window, output)) = self.niri.monitor_set.find_window_and_output(surface) { |
| 67 | // This is a commit of a previously-mapped toplevel. | 68 | // This is a commit of a previously-mapped toplevel. |
| 68 | window.on_commit(); | 69 | window.on_commit(); |
| 69 | 70 | ||
| @@ -73,16 +74,16 @@ impl CompositorHandler for Niri { | |||
| 73 | 74 | ||
| 74 | if !is_mapped { | 75 | if !is_mapped { |
| 75 | // The toplevel got unmapped. | 76 | // The toplevel got unmapped. |
| 76 | - self.monitor_set.remove_window(&window); | 77 | + self.niri.monitor_set.remove_window(&window); |
| 77 | - self.unmapped_windows.insert(surface.clone(), window); | 78 | + self.niri.unmapped_windows.insert(surface.clone(), window); |
| 78 | - self.queue_redraw(output); | 79 | + self.niri.queue_redraw(output); |
| 79 | return; | 80 | return; |
| 80 | } | 81 | } |
| 81 | 82 | ||
| 82 | // The toplevel remains mapped. | 83 | // The toplevel remains mapped. |
| 83 | - self.monitor_set.update_window(&window); | 84 | + self.niri.monitor_set.update_window(&window); |
| 84 | 85 | ||
| 85 | - self.queue_redraw(output); | 86 | + self.niri.queue_redraw(output); |
| 86 | return; | 87 | return; |
| 87 | } | 88 | } |
| 88 | 89 | ||
| @@ -90,21 +91,21 @@ impl CompositorHandler for Niri { | |||
| 90 | } | 91 | } |
| 91 | 92 | ||
| 92 | // This is a commit of a non-root or a non-toplevel root. | 93 | // This is a commit of a non-root or a non-toplevel root. |
| 93 | - let root_window_output = self.monitor_set.find_window_and_output(&root_surface); | 94 | + let root_window_output = self.niri.monitor_set.find_window_and_output(&root_surface); |
| 94 | if let Some((window, output)) = root_window_output { | 95 | if let Some((window, output)) = root_window_output { |
| 95 | window.on_commit(); | 96 | window.on_commit(); |
| 96 | - self.monitor_set.update_window(&window); | 97 | + self.niri.monitor_set.update_window(&window); |
| 97 | - self.queue_redraw(output); | 98 | + self.niri.queue_redraw(output); |
| 98 | return; | 99 | return; |
| 99 | } | 100 | } |
| 100 | 101 | ||
| 101 | // This might be a popup. | 102 | // This might be a popup. |
| 102 | self.popups_handle_commit(surface); | 103 | self.popups_handle_commit(surface); |
| 103 | - if let Some(popup) = self.popups.find_popup(surface) { | 104 | + if let Some(popup) = self.niri.popups.find_popup(surface) { |
| 104 | if let Ok(root) = find_popup_root_surface(&popup) { | 105 | if let Ok(root) = find_popup_root_surface(&popup) { |
| 105 | - let root_window_output = self.monitor_set.find_window_and_output(&root); | 106 | + let root_window_output = self.niri.monitor_set.find_window_and_output(&root); |
| 106 | if let Some((_window, output)) = root_window_output { | 107 | if let Some((_window, output)) = root_window_output { |
| 107 | - self.queue_redraw(output); | 108 | + self.niri.queue_redraw(output); |
| 108 | } | 109 | } |
| 109 | } | 110 | } |
| 110 | } | 111 | } |
| @@ -114,15 +115,15 @@ impl CompositorHandler for Niri { | |||
| 114 | } | 115 | } |
| 115 | } | 116 | } |
| 116 | 117 | ||
| 117 | -impl BufferHandler for Niri { | 118 | +impl BufferHandler for State { |
| 118 | fn buffer_destroyed(&mut self, _buffer: &wl_buffer::WlBuffer) {} | 119 | fn buffer_destroyed(&mut self, _buffer: &wl_buffer::WlBuffer) {} |
| 119 | } | 120 | } |
| 120 | 121 | ||
| 121 | -impl ShmHandler for Niri { | 122 | +impl ShmHandler for State { |
| 122 | fn shm_state(&self) -> &ShmState { | 123 | fn shm_state(&self) -> &ShmState { |
| 123 | - &self.shm_state | 124 | + &self.niri.shm_state |
| 124 | } | 125 | } |
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | -delegate_compositor!(Niri); | 128 | +delegate_compositor!(State); |
| 128 | -delegate_shm!(Niri); | 129 | +delegate_shm!(State); |
src/handlers/layer_shell.rsmodified+10 -9
| @@ -9,11 +9,11 @@ use smithay::wayland::shell::wlr_layer::{ | |||
| 9 | WlrLayerShellState, | 9 | WlrLayerShellState, |
| 10 | }; | 10 | }; |
| 11 | 11 | ||
| 12 | -use crate::niri::Niri; | 12 | +use crate::niri::State; |
| 13 | 13 | ||
| 14 | -impl WlrLayerShellHandler for Niri { | 14 | +impl WlrLayerShellHandler for State { |
| 15 | fn shell_state(&mut self) -> &mut WlrLayerShellState { | 15 | fn shell_state(&mut self) -> &mut WlrLayerShellState { |
| 16 | - &mut self.layer_shell_state | 16 | + &mut self.niri.layer_shell_state |
| 17 | } | 17 | } |
| 18 | 18 | ||
| 19 | fn new_layer_surface( | 19 | fn new_layer_surface( |
| @@ -26,7 +26,7 @@ impl WlrLayerShellHandler for Niri { | |||
| 26 | let output = wl_output | 26 | let output = wl_output |
| 27 | .as_ref() | 27 | .as_ref() |
| 28 | .and_then(Output::from_resource) | 28 | .and_then(Output::from_resource) |
| 29 | - .or_else(|| self.monitor_set.active_output().cloned()) | 29 | + .or_else(|| self.niri.monitor_set.active_output().cloned()) |
| 30 | .unwrap(); | 30 | .unwrap(); |
| 31 | let mut map = layer_map_for_output(&output); | 31 | let mut map = layer_map_for_output(&output); |
| 32 | map.map_layer(&LayerSurface::new(surface, namespace)) | 32 | map.map_layer(&LayerSurface::new(surface, namespace)) |
| @@ -35,7 +35,7 @@ impl WlrLayerShellHandler for Niri { | |||
| 35 | 35 | ||
| 36 | fn layer_destroyed(&mut self, surface: WlrLayerSurface) { | 36 | fn layer_destroyed(&mut self, surface: WlrLayerSurface) { |
| 37 | let output = if let Some((output, mut map, layer)) = | 37 | let output = if let Some((output, mut map, layer)) = |
| 38 | - self.monitor_set.outputs().find_map(|o| { | 38 | + self.niri.monitor_set.outputs().find_map(|o| { |
| 39 | let map = layer_map_for_output(o); | 39 | let map = layer_map_for_output(o); |
| 40 | let layer = map | 40 | let layer = map |
| 41 | .layers() | 41 | .layers() |
| @@ -49,15 +49,16 @@ impl WlrLayerShellHandler for Niri { | |||
| 49 | None | 49 | None |
| 50 | }; | 50 | }; |
| 51 | if let Some(output) = output { | 51 | if let Some(output) = output { |
| 52 | - self.queue_redraw(output); | 52 | + self.niri.queue_redraw(output); |
| 53 | } | 53 | } |
| 54 | } | 54 | } |
| 55 | } | 55 | } |
| 56 | -delegate_layer_shell!(Niri); | 56 | +delegate_layer_shell!(State); |
| 57 | 57 | ||
| 58 | -impl Niri { | 58 | +impl State { |
| 59 | pub fn layer_shell_handle_commit(&mut self, surface: &WlSurface) { | 59 | pub fn layer_shell_handle_commit(&mut self, surface: &WlSurface) { |
| 60 | let Some(output) = self | 60 | let Some(output) = self |
| 61 | + .niri | ||
| 61 | .monitor_set | 62 | .monitor_set |
| 62 | .outputs() | 63 | .outputs() |
| 63 | .find(|o| { | 64 | .find(|o| { |
| @@ -95,6 +96,6 @@ impl Niri { | |||
| 95 | } | 96 | } |
| 96 | drop(map); | 97 | drop(map); |
| 97 | 98 | ||
| 98 | - self.queue_redraw(output); | 99 | + self.niri.queue_redraw(output); |
| 99 | } | 100 | } |
| 100 | } | 101 | } |
src/handlers/mod.rsmodified+21 -21
| @@ -16,62 +16,62 @@ use smithay::{ | |||
| 16 | delegate_seat, delegate_tablet_manager, | 16 | delegate_seat, delegate_tablet_manager, |
| 17 | }; | 17 | }; |
| 18 | 18 | ||
| 19 | -use crate::Niri; | 19 | +use crate::niri::State; |
| 20 | 20 | ||
| 21 | -impl SeatHandler for Niri { | 21 | +impl SeatHandler for State { |
| 22 | type KeyboardFocus = WlSurface; | 22 | type KeyboardFocus = WlSurface; |
| 23 | type PointerFocus = WlSurface; | 23 | type PointerFocus = WlSurface; |
| 24 | 24 | ||
| 25 | - fn seat_state(&mut self) -> &mut SeatState<Niri> { | 25 | + fn seat_state(&mut self) -> &mut SeatState<State> { |
| 26 | - &mut self.seat_state | 26 | + &mut self.niri.seat_state |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | fn cursor_image(&mut self, _seat: &Seat<Self>, image: CursorImageStatus) { | 29 | fn cursor_image(&mut self, _seat: &Seat<Self>, image: CursorImageStatus) { |
| 30 | - self.cursor_image = image; | 30 | + self.niri.cursor_image = image; |
| 31 | // FIXME: more granular | 31 | // FIXME: more granular |
| 32 | - self.queue_redraw_all(); | 32 | + self.niri.queue_redraw_all(); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | fn focus_changed(&mut self, seat: &Seat<Self>, focused: Option<&WlSurface>) { | 35 | fn focus_changed(&mut self, seat: &Seat<Self>, focused: Option<&WlSurface>) { |
| 36 | - let dh = &self.display_handle; | 36 | + let dh = &self.niri.display_handle; |
| 37 | let client = focused.and_then(|s| dh.get_client(s.id()).ok()); | 37 | let client = focused.and_then(|s| dh.get_client(s.id()).ok()); |
| 38 | set_data_device_focus(dh, seat, client); | 38 | set_data_device_focus(dh, seat, client); |
| 39 | } | 39 | } |
| 40 | } | 40 | } |
| 41 | -delegate_seat!(Niri); | 41 | +delegate_seat!(State); |
| 42 | -delegate_tablet_manager!(Niri); | 42 | +delegate_tablet_manager!(State); |
| 43 | -delegate_pointer_gestures!(Niri); | 43 | +delegate_pointer_gestures!(State); |
| 44 | 44 | ||
| 45 | -impl DataDeviceHandler for Niri { | 45 | +impl DataDeviceHandler for State { |
| 46 | type SelectionUserData = (); | 46 | type SelectionUserData = (); |
| 47 | fn data_device_state(&self) -> &DataDeviceState { | 47 | fn data_device_state(&self) -> &DataDeviceState { |
| 48 | - &self.data_device_state | 48 | + &self.niri.data_device_state |
| 49 | } | 49 | } |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | -impl ClientDndGrabHandler for Niri { | 52 | +impl ClientDndGrabHandler for State { |
| 53 | fn started( | 53 | fn started( |
| 54 | &mut self, | 54 | &mut self, |
| 55 | _source: Option<WlDataSource>, | 55 | _source: Option<WlDataSource>, |
| 56 | icon: Option<WlSurface>, | 56 | icon: Option<WlSurface>, |
| 57 | _seat: Seat<Self>, | 57 | _seat: Seat<Self>, |
| 58 | ) { | 58 | ) { |
| 59 | - self.dnd_icon = icon; | 59 | + self.niri.dnd_icon = icon; |
| 60 | // FIXME: more granular | 60 | // FIXME: more granular |
| 61 | - self.queue_redraw_all(); | 61 | + self.niri.queue_redraw_all(); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | fn dropped(&mut self, _seat: Seat<Self>) { | 64 | fn dropped(&mut self, _seat: Seat<Self>) { |
| 65 | - self.dnd_icon = None; | 65 | + self.niri.dnd_icon = None; |
| 66 | // FIXME: more granular | 66 | // FIXME: more granular |
| 67 | - self.queue_redraw_all(); | 67 | + self.niri.queue_redraw_all(); |
| 68 | } | 68 | } |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | -impl ServerDndGrabHandler for Niri {} | 71 | +impl ServerDndGrabHandler for State {} |
| 72 | 72 | ||
| 73 | -delegate_data_device!(Niri); | 73 | +delegate_data_device!(State); |
| 74 | 74 | ||
| 75 | -delegate_output!(Niri); | 75 | +delegate_output!(State); |
| 76 | 76 | ||
| 77 | -delegate_presentation!(Niri); | 77 | +delegate_presentation!(State); |
src/handlers/xdg_shell.rsmodified+27 -18
| @@ -13,11 +13,11 @@ use smithay::wayland::shell::xdg::{ | |||
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | use crate::layout::{configure_new_window, output_size}; | 15 | use crate::layout::{configure_new_window, output_size}; |
| 16 | -use crate::Niri; | 16 | +use crate::niri::State; |
| 17 | 17 | ||
| 18 | -impl XdgShellHandler for Niri { | 18 | +impl XdgShellHandler for State { |
| 19 | fn xdg_shell_state(&mut self) -> &mut XdgShellState { | 19 | fn xdg_shell_state(&mut self) -> &mut XdgShellState { |
| 20 | - &mut self.xdg_shell_state | 20 | + &mut self.niri.xdg_shell_state |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | fn new_toplevel(&mut self, surface: ToplevelSurface) { | 23 | fn new_toplevel(&mut self, surface: ToplevelSurface) { |
| @@ -25,18 +25,18 @@ impl XdgShellHandler for Niri { | |||
| 25 | let window = Window::new(surface); | 25 | let window = Window::new(surface); |
| 26 | 26 | ||
| 27 | // Tell the surface the preferred size and bounds for its likely output. | 27 | // Tell the surface the preferred size and bounds for its likely output. |
| 28 | - let output = self.monitor_set.active_output().unwrap(); | 28 | + let output = self.niri.monitor_set.active_output().unwrap(); |
| 29 | configure_new_window(output_size(output), &window); | 29 | configure_new_window(output_size(output), &window); |
| 30 | 30 | ||
| 31 | // At the moment of creation, xdg toplevels must have no buffer. | 31 | // At the moment of creation, xdg toplevels must have no buffer. |
| 32 | - let existing = self.unmapped_windows.insert(wl_surface, window); | 32 | + let existing = self.niri.unmapped_windows.insert(wl_surface, window); |
| 33 | assert!(existing.is_none()); | 33 | assert!(existing.is_none()); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | fn new_popup(&mut self, surface: PopupSurface, _positioner: PositionerState) { | 36 | fn new_popup(&mut self, surface: PopupSurface, _positioner: PositionerState) { |
| 37 | // FIXME: adjust the geometry so the popup doesn't overflow at least off the top and bottom | 37 | // FIXME: adjust the geometry so the popup doesn't overflow at least off the top and bottom |
| 38 | // screen edges, and ideally off the view size. | 38 | // screen edges, and ideally off the view size. |
| 39 | - if let Err(err) = self.popups.track_popup(PopupKind::Xdg(surface)) { | 39 | + if let Err(err) = self.niri.popups.track_popup(PopupKind::Xdg(surface)) { |
| 40 | warn!("error tracking popup: {err:?}"); | 40 | warn!("error tracking popup: {err:?}"); |
| 41 | } | 41 | } |
| 42 | } | 42 | } |
| @@ -101,17 +101,19 @@ impl XdgShellHandler for Niri { | |||
| 101 | // location and configure size here, but the surface should be rendered fullscreen | 101 | // location and configure size here, but the surface should be rendered fullscreen |
| 102 | // independently from its buffer size | 102 | // independently from its buffer size |
| 103 | if let Some((window, current_output)) = self | 103 | if let Some((window, current_output)) = self |
| 104 | + .niri | ||
| 104 | .monitor_set | 105 | .monitor_set |
| 105 | .find_window_and_output(surface.wl_surface()) | 106 | .find_window_and_output(surface.wl_surface()) |
| 106 | { | 107 | { |
| 107 | if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { | 108 | if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { |
| 108 | if requested_output != current_output { | 109 | if requested_output != current_output { |
| 109 | - self.monitor_set | 110 | + self.niri |
| 111 | + .monitor_set | ||
| 110 | .move_window_to_output(window.clone(), &requested_output); | 112 | .move_window_to_output(window.clone(), &requested_output); |
| 111 | } | 113 | } |
| 112 | } | 114 | } |
| 113 | 115 | ||
| 114 | - self.monitor_set.set_fullscreen(&window, true); | 116 | + self.niri.monitor_set.set_fullscreen(&window, true); |
| 115 | } | 117 | } |
| 116 | } | 118 | } |
| 117 | 119 | ||
| @@ -122,38 +124,45 @@ impl XdgShellHandler for Niri { | |||
| 122 | 124 | ||
| 123 | fn unfullscreen_request(&mut self, surface: ToplevelSurface) { | 125 | fn unfullscreen_request(&mut self, surface: ToplevelSurface) { |
| 124 | if let Some((window, _)) = self | 126 | if let Some((window, _)) = self |
| 127 | + .niri | ||
| 125 | .monitor_set | 128 | .monitor_set |
| 126 | .find_window_and_output(surface.wl_surface()) | 129 | .find_window_and_output(surface.wl_surface()) |
| 127 | { | 130 | { |
| 128 | - self.monitor_set.set_fullscreen(&window, false); | 131 | + self.niri.monitor_set.set_fullscreen(&window, false); |
| 129 | } | 132 | } |
| 130 | } | 133 | } |
| 131 | 134 | ||
| 132 | fn toplevel_destroyed(&mut self, surface: ToplevelSurface) { | 135 | fn toplevel_destroyed(&mut self, surface: ToplevelSurface) { |
| 133 | - if self.unmapped_windows.remove(surface.wl_surface()).is_some() { | 136 | + if self |
| 137 | + .niri | ||
| 138 | + .unmapped_windows | ||
| 139 | + .remove(surface.wl_surface()) | ||
| 140 | + .is_some() | ||
| 141 | + { | ||
| 134 | // An unmapped toplevel got destroyed. | 142 | // An unmapped toplevel got destroyed. |
| 135 | return; | 143 | return; |
| 136 | } | 144 | } |
| 137 | 145 | ||
| 138 | let (window, output) = self | 146 | let (window, output) = self |
| 147 | + .niri | ||
| 139 | .monitor_set | 148 | .monitor_set |
| 140 | .find_window_and_output(surface.wl_surface()) | 149 | .find_window_and_output(surface.wl_surface()) |
| 141 | .unwrap(); | 150 | .unwrap(); |
| 142 | - self.monitor_set.remove_window(&window); | 151 | + self.niri.monitor_set.remove_window(&window); |
| 143 | - self.queue_redraw(output); | 152 | + self.niri.queue_redraw(output); |
| 144 | } | 153 | } |
| 145 | 154 | ||
| 146 | fn popup_destroyed(&mut self, surface: PopupSurface) { | 155 | fn popup_destroyed(&mut self, surface: PopupSurface) { |
| 147 | if let Ok(root) = find_popup_root_surface(&surface.into()) { | 156 | if let Ok(root) = find_popup_root_surface(&surface.into()) { |
| 148 | - let root_window_output = self.monitor_set.find_window_and_output(&root); | 157 | + let root_window_output = self.niri.monitor_set.find_window_and_output(&root); |
| 149 | if let Some((_window, output)) = root_window_output { | 158 | if let Some((_window, output)) = root_window_output { |
| 150 | - self.queue_redraw(output); | 159 | + self.niri.queue_redraw(output); |
| 151 | } | 160 | } |
| 152 | } | 161 | } |
| 153 | } | 162 | } |
| 154 | } | 163 | } |
| 155 | 164 | ||
| 156 | -delegate_xdg_shell!(Niri); | 165 | +delegate_xdg_shell!(State); |
| 157 | 166 | ||
| 158 | pub fn send_initial_configure_if_needed(window: &Window) { | 167 | pub fn send_initial_configure_if_needed(window: &Window) { |
| 159 | let initial_configure_sent = with_states(window.toplevel().wl_surface(), |states| { | 168 | let initial_configure_sent = with_states(window.toplevel().wl_surface(), |states| { |
| @@ -171,12 +180,12 @@ pub fn send_initial_configure_if_needed(window: &Window) { | |||
| 171 | } | 180 | } |
| 172 | } | 181 | } |
| 173 | 182 | ||
| 174 | -impl Niri { | 183 | +impl State { |
| 175 | /// Should be called on `WlSurface::commit` | 184 | /// Should be called on `WlSurface::commit` |
| 176 | pub fn popups_handle_commit(&mut self, surface: &WlSurface) { | 185 | pub fn popups_handle_commit(&mut self, surface: &WlSurface) { |
| 177 | - self.popups.commit(surface); | 186 | + self.niri.popups.commit(surface); |
| 178 | 187 | ||
| 179 | - if let Some(popup) = self.popups.find_popup(surface) { | 188 | + if let Some(popup) = self.niri.popups.find_popup(surface) { |
| 180 | let PopupKind::Xdg(ref popup) = popup; | 189 | let PopupKind::Xdg(ref popup) = popup; |
| 181 | let initial_configure_sent = with_states(surface, |states| { | 190 | let initial_configure_sent = with_states(surface, |states| { |
| 182 | states | 191 | states |
src/input.rsmodified+114 -116
| @@ -17,7 +17,7 @@ use smithay::input::pointer::{ | |||
| 17 | use smithay::utils::SERIAL_COUNTER; | 17 | use smithay::utils::SERIAL_COUNTER; |
| 18 | use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; | 18 | use smithay::wayland::tablet_manager::{TabletDescriptor, TabletSeatTrait}; |
| 19 | 19 | ||
| 20 | -use crate::niri::Niri; | 20 | +use crate::niri::State; |
| 21 | use crate::utils::get_monotonic_time; | 21 | use crate::utils::get_monotonic_time; |
| 22 | 22 | ||
| 23 | enum Action { | 23 | enum Action { |
| @@ -56,14 +56,6 @@ enum Action { | |||
| 56 | ToggleFullWidth, | 56 | ToggleFullWidth, |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | -pub enum BackendAction { | ||
| 60 | - None, | ||
| 61 | - ChangeVt(i32), | ||
| 62 | - Suspend, | ||
| 63 | - Screenshot, | ||
| 64 | - ToggleDebugTint, | ||
| 65 | -} | ||
| 66 | - | ||
| 67 | pub enum CompositorMod { | 59 | pub enum CompositorMod { |
| 68 | Super, | 60 | Super, |
| 69 | Alt, | 61 | Alt, |
| @@ -148,12 +140,8 @@ fn action(comp_mod: CompositorMod, keysym: KeysymHandle, mods: ModifiersState) - | |||
| 148 | } | 140 | } |
| 149 | } | 141 | } |
| 150 | 142 | ||
| 151 | -impl Niri { | 143 | +impl State { |
| 152 | - pub fn process_input_event<I: InputBackend>( | 144 | + pub fn process_input_event<I: InputBackend>(&mut self, event: InputEvent<I>) { |
| 153 | - &mut self, | ||
| 154 | - comp_mod: CompositorMod, | ||
| 155 | - event: InputEvent<I>, | ||
| 156 | - ) -> BackendAction { | ||
| 157 | let _span = tracy_client::span!("process_input_event"); | 145 | let _span = tracy_client::span!("process_input_event"); |
| 158 | trace!("process_input_event"); | 146 | trace!("process_input_event"); |
| 159 | 147 | ||
| @@ -161,14 +149,18 @@ impl Niri { | |||
| 161 | // doesn't always trigger due to damage, etc. So run it here right before it might prove | 149 | // doesn't always trigger due to damage, etc. So run it here right before it might prove |
| 162 | // important. Besides, animations affect the input, so it's best to have up-to-date values | 150 | // important. Besides, animations affect the input, so it's best to have up-to-date values |
| 163 | // here. | 151 | // here. |
| 164 | - self.monitor_set.advance_animations(get_monotonic_time()); | 152 | + self.niri |
| 153 | + .monitor_set | ||
| 154 | + .advance_animations(get_monotonic_time()); | ||
| 155 | + | ||
| 156 | + let comp_mod = self.backend.mod_key(); | ||
| 165 | 157 | ||
| 166 | match event { | 158 | match event { |
| 167 | InputEvent::Keyboard { event, .. } => { | 159 | InputEvent::Keyboard { event, .. } => { |
| 168 | let serial = SERIAL_COUNTER.next_serial(); | 160 | let serial = SERIAL_COUNTER.next_serial(); |
| 169 | let time = Event::time_msec(&event); | 161 | let time = Event::time_msec(&event); |
| 170 | 162 | ||
| 171 | - let action = self.seat.get_keyboard().unwrap().input( | 163 | + let action = self.niri.seat.get_keyboard().unwrap().input( |
| 172 | self, | 164 | self, |
| 173 | event.key_code(), | 165 | event.key_code(), |
| 174 | event.state(), | 166 | event.state(), |
| @@ -188,16 +180,16 @@ impl Niri { | |||
| 188 | Action::None => unreachable!(), | 180 | Action::None => unreachable!(), |
| 189 | Action::Quit => { | 181 | Action::Quit => { |
| 190 | info!("quitting because quit bind was pressed"); | 182 | info!("quitting because quit bind was pressed"); |
| 191 | - self.stop_signal.stop() | 183 | + self.niri.stop_signal.stop() |
| 192 | } | 184 | } |
| 193 | Action::ChangeVt(vt) => { | 185 | Action::ChangeVt(vt) => { |
| 194 | - return BackendAction::ChangeVt(vt); | 186 | + self.backend.change_vt(vt); |
| 195 | } | 187 | } |
| 196 | Action::Suspend => { | 188 | Action::Suspend => { |
| 197 | - return BackendAction::Suspend; | 189 | + self.backend.suspend(); |
| 198 | } | 190 | } |
| 199 | Action::ToggleDebugTint => { | 191 | Action::ToggleDebugTint => { |
| 200 | - return BackendAction::ToggleDebugTint; | 192 | + self.backend.toggle_debug_tint(); |
| 201 | } | 193 | } |
| 202 | Action::Spawn(command) => { | 194 | Action::Spawn(command) => { |
| 203 | if let Err(err) = Command::new(command).spawn() { | 195 | if let Err(err) = Command::new(command).spawn() { |
| @@ -205,132 +197,139 @@ impl Niri { | |||
| 205 | } | 197 | } |
| 206 | } | 198 | } |
| 207 | Action::Screenshot => { | 199 | Action::Screenshot => { |
| 208 | - return BackendAction::Screenshot; | 200 | + let active = self.niri.monitor_set.active_output().cloned(); |
| 201 | + if let Some(active) = active { | ||
| 202 | + if let Err(err) = | ||
| 203 | + self.niri.screenshot(self.backend.renderer(), &active) | ||
| 204 | + { | ||
| 205 | + warn!("error taking screenshot: {err:?}"); | ||
| 206 | + } | ||
| 207 | + } | ||
| 209 | } | 208 | } |
| 210 | Action::CloseWindow => { | 209 | Action::CloseWindow => { |
| 211 | - if let Some(window) = self.monitor_set.focus() { | 210 | + if let Some(window) = self.niri.monitor_set.focus() { |
| 212 | window.toplevel().send_close(); | 211 | window.toplevel().send_close(); |
| 213 | } | 212 | } |
| 214 | } | 213 | } |
| 215 | Action::ToggleFullscreen => { | 214 | Action::ToggleFullscreen => { |
| 216 | - let focus = self.monitor_set.focus().cloned(); | 215 | + let focus = self.niri.monitor_set.focus().cloned(); |
| 217 | if let Some(window) = focus { | 216 | if let Some(window) = focus { |
| 218 | - self.monitor_set.toggle_fullscreen(&window); | 217 | + self.niri.monitor_set.toggle_fullscreen(&window); |
| 219 | } | 218 | } |
| 220 | } | 219 | } |
| 221 | Action::MoveLeft => { | 220 | Action::MoveLeft => { |
| 222 | - self.monitor_set.move_left(); | 221 | + self.niri.monitor_set.move_left(); |
| 223 | // FIXME: granular | 222 | // FIXME: granular |
| 224 | - self.queue_redraw_all(); | 223 | + self.niri.queue_redraw_all(); |
| 225 | } | 224 | } |
| 226 | Action::MoveRight => { | 225 | Action::MoveRight => { |
| 227 | - self.monitor_set.move_right(); | 226 | + self.niri.monitor_set.move_right(); |
| 228 | // FIXME: granular | 227 | // FIXME: granular |
| 229 | - self.queue_redraw_all(); | 228 | + self.niri.queue_redraw_all(); |
| 230 | } | 229 | } |
| 231 | Action::MoveDown => { | 230 | Action::MoveDown => { |
| 232 | - self.monitor_set.move_down(); | 231 | + self.niri.monitor_set.move_down(); |
| 233 | // FIXME: granular | 232 | // FIXME: granular |
| 234 | - self.queue_redraw_all(); | 233 | + self.niri.queue_redraw_all(); |
| 235 | } | 234 | } |
| 236 | Action::MoveUp => { | 235 | Action::MoveUp => { |
| 237 | - self.monitor_set.move_up(); | 236 | + self.niri.monitor_set.move_up(); |
| 238 | // FIXME: granular | 237 | // FIXME: granular |
| 239 | - self.queue_redraw_all(); | 238 | + self.niri.queue_redraw_all(); |
| 240 | } | 239 | } |
| 241 | Action::FocusLeft => { | 240 | Action::FocusLeft => { |
| 242 | - self.monitor_set.focus_left(); | 241 | + self.niri.monitor_set.focus_left(); |
| 243 | } | 242 | } |
| 244 | Action::FocusRight => { | 243 | Action::FocusRight => { |
| 245 | - self.monitor_set.focus_right(); | 244 | + self.niri.monitor_set.focus_right(); |
| 246 | } | 245 | } |
| 247 | Action::FocusDown => { | 246 | Action::FocusDown => { |
| 248 | - self.monitor_set.focus_down(); | 247 | + self.niri.monitor_set.focus_down(); |
| 249 | } | 248 | } |
| 250 | Action::FocusUp => { | 249 | Action::FocusUp => { |
| 251 | - self.monitor_set.focus_up(); | 250 | + self.niri.monitor_set.focus_up(); |
| 252 | } | 251 | } |
| 253 | Action::MoveToWorkspaceDown => { | 252 | Action::MoveToWorkspaceDown => { |
| 254 | - self.monitor_set.move_to_workspace_down(); | 253 | + self.niri.monitor_set.move_to_workspace_down(); |
| 255 | // FIXME: granular | 254 | // FIXME: granular |
| 256 | - self.queue_redraw_all(); | 255 | + self.niri.queue_redraw_all(); |
| 257 | } | 256 | } |
| 258 | Action::MoveToWorkspaceUp => { | 257 | Action::MoveToWorkspaceUp => { |
| 259 | - self.monitor_set.move_to_workspace_up(); | 258 | + self.niri.monitor_set.move_to_workspace_up(); |
| 260 | // FIXME: granular | 259 | // FIXME: granular |
| 261 | - self.queue_redraw_all(); | 260 | + self.niri.queue_redraw_all(); |
| 262 | } | 261 | } |
| 263 | Action::SwitchWorkspaceDown => { | 262 | Action::SwitchWorkspaceDown => { |
| 264 | - self.monitor_set.switch_workspace_down(); | 263 | + self.niri.monitor_set.switch_workspace_down(); |
| 265 | // FIXME: granular | 264 | // FIXME: granular |
| 266 | - self.queue_redraw_all(); | 265 | + self.niri.queue_redraw_all(); |
| 267 | } | 266 | } |
| 268 | Action::SwitchWorkspaceUp => { | 267 | Action::SwitchWorkspaceUp => { |
| 269 | - self.monitor_set.switch_workspace_up(); | 268 | + self.niri.monitor_set.switch_workspace_up(); |
| 270 | // FIXME: granular | 269 | // FIXME: granular |
| 271 | - self.queue_redraw_all(); | 270 | + self.niri.queue_redraw_all(); |
| 272 | } | 271 | } |
| 273 | Action::ConsumeIntoColumn => { | 272 | Action::ConsumeIntoColumn => { |
| 274 | - self.monitor_set.consume_into_column(); | 273 | + self.niri.monitor_set.consume_into_column(); |
| 275 | // FIXME: granular | 274 | // FIXME: granular |
| 276 | - self.queue_redraw_all(); | 275 | + self.niri.queue_redraw_all(); |
| 277 | } | 276 | } |
| 278 | Action::ExpelFromColumn => { | 277 | Action::ExpelFromColumn => { |
| 279 | - self.monitor_set.expel_from_column(); | 278 | + self.niri.monitor_set.expel_from_column(); |
| 280 | // FIXME: granular | 279 | // FIXME: granular |
| 281 | - self.queue_redraw_all(); | 280 | + self.niri.queue_redraw_all(); |
| 282 | } | 281 | } |
| 283 | Action::ToggleWidth => { | 282 | Action::ToggleWidth => { |
| 284 | - self.monitor_set.toggle_width(); | 283 | + self.niri.monitor_set.toggle_width(); |
| 285 | } | 284 | } |
| 286 | Action::ToggleFullWidth => { | 285 | Action::ToggleFullWidth => { |
| 287 | - self.monitor_set.toggle_full_width(); | 286 | + self.niri.monitor_set.toggle_full_width(); |
| 288 | } | 287 | } |
| 289 | Action::FocusMonitorLeft => { | 288 | Action::FocusMonitorLeft => { |
| 290 | - if let Some(output) = self.output_left() { | 289 | + if let Some(output) = self.niri.output_left() { |
| 291 | - self.monitor_set.focus_output(&output); | 290 | + self.niri.monitor_set.focus_output(&output); |
| 292 | self.move_cursor_to_output(&output); | 291 | self.move_cursor_to_output(&output); |
| 293 | } | 292 | } |
| 294 | } | 293 | } |
| 295 | Action::FocusMonitorRight => { | 294 | Action::FocusMonitorRight => { |
| 296 | - if let Some(output) = self.output_right() { | 295 | + if let Some(output) = self.niri.output_right() { |
| 297 | - self.monitor_set.focus_output(&output); | 296 | + self.niri.monitor_set.focus_output(&output); |
| 298 | self.move_cursor_to_output(&output); | 297 | self.move_cursor_to_output(&output); |
| 299 | } | 298 | } |
| 300 | } | 299 | } |
| 301 | Action::FocusMonitorDown => { | 300 | Action::FocusMonitorDown => { |
| 302 | - if let Some(output) = self.output_down() { | 301 | + if let Some(output) = self.niri.output_down() { |
| 303 | - self.monitor_set.focus_output(&output); | 302 | + self.niri.monitor_set.focus_output(&output); |
| 304 | self.move_cursor_to_output(&output); | 303 | self.move_cursor_to_output(&output); |
| 305 | } | 304 | } |
| 306 | } | 305 | } |
| 307 | Action::FocusMonitorUp => { | 306 | Action::FocusMonitorUp => { |
| 308 | - if let Some(output) = self.output_up() { | 307 | + if let Some(output) = self.niri.output_up() { |
| 309 | - self.monitor_set.focus_output(&output); | 308 | + self.niri.monitor_set.focus_output(&output); |
| 310 | self.move_cursor_to_output(&output); | 309 | self.move_cursor_to_output(&output); |
| 311 | } | 310 | } |
| 312 | } | 311 | } |
| 313 | Action::MoveToMonitorLeft => { | 312 | Action::MoveToMonitorLeft => { |
| 314 | - if let Some(output) = self.output_left() { | 313 | + if let Some(output) = self.niri.output_left() { |
| 315 | - self.monitor_set.move_to_output(&output); | 314 | + self.niri.monitor_set.move_to_output(&output); |
| 316 | self.move_cursor_to_output(&output); | 315 | self.move_cursor_to_output(&output); |
| 317 | } | 316 | } |
| 318 | } | 317 | } |
| 319 | Action::MoveToMonitorRight => { | 318 | Action::MoveToMonitorRight => { |
| 320 | - if let Some(output) = self.output_right() { | 319 | + if let Some(output) = self.niri.output_right() { |
| 321 | - self.monitor_set.move_to_output(&output); | 320 | + self.niri.monitor_set.move_to_output(&output); |
| 322 | self.move_cursor_to_output(&output); | 321 | self.move_cursor_to_output(&output); |
| 323 | } | 322 | } |
| 324 | } | 323 | } |
| 325 | Action::MoveToMonitorDown => { | 324 | Action::MoveToMonitorDown => { |
| 326 | - if let Some(output) = self.output_down() { | 325 | + if let Some(output) = self.niri.output_down() { |
| 327 | - self.monitor_set.move_to_output(&output); | 326 | + self.niri.monitor_set.move_to_output(&output); |
| 328 | self.move_cursor_to_output(&output); | 327 | self.move_cursor_to_output(&output); |
| 329 | } | 328 | } |
| 330 | } | 329 | } |
| 331 | Action::MoveToMonitorUp => { | 330 | Action::MoveToMonitorUp => { |
| 332 | - if let Some(output) = self.output_up() { | 331 | + if let Some(output) = self.niri.output_up() { |
| 333 | - self.monitor_set.move_to_output(&output); | 332 | + self.niri.monitor_set.move_to_output(&output); |
| 334 | self.move_cursor_to_output(&output); | 333 | self.move_cursor_to_output(&output); |
| 335 | } | 334 | } |
| 336 | } | 335 | } |
| @@ -340,7 +339,7 @@ impl Niri { | |||
| 340 | InputEvent::PointerMotion { event, .. } => { | 339 | InputEvent::PointerMotion { event, .. } => { |
| 341 | let serial = SERIAL_COUNTER.next_serial(); | 340 | let serial = SERIAL_COUNTER.next_serial(); |
| 342 | 341 | ||
| 343 | - let pointer = self.seat.get_pointer().unwrap(); | 342 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 344 | let mut pos = pointer.current_location(); | 343 | let mut pos = pointer.current_location(); |
| 345 | 344 | ||
| 346 | pos += event.delta(); | 345 | pos += event.delta(); |
| @@ -349,9 +348,9 @@ impl Niri { | |||
| 349 | let mut min_y = i32::MAX; | 348 | let mut min_y = i32::MAX; |
| 350 | let mut max_x = 0; | 349 | let mut max_x = 0; |
| 351 | let mut max_y = 0; | 350 | let mut max_y = 0; |
| 352 | - for output in self.global_space.outputs() { | 351 | + for output in self.niri.global_space.outputs() { |
| 353 | // FIXME: smarter clamping. | 352 | // FIXME: smarter clamping. |
| 354 | - let geom = self.global_space.output_geometry(output).unwrap(); | 353 | + let geom = self.niri.global_space.output_geometry(output).unwrap(); |
| 355 | min_x = min_x.min(geom.loc.x); | 354 | min_x = min_x.min(geom.loc.x); |
| 356 | min_y = min_y.min(geom.loc.y); | 355 | min_y = min_y.min(geom.loc.y); |
| 357 | max_x = max_x.max(geom.loc.x + geom.size.w); | 356 | max_x = max_x.max(geom.loc.x + geom.size.w); |
| @@ -361,7 +360,7 @@ impl Niri { | |||
| 361 | pos.x = pos.x.clamp(min_x as f64, max_x as f64); | 360 | pos.x = pos.x.clamp(min_x as f64, max_x as f64); |
| 362 | pos.y = pos.y.clamp(min_y as f64, max_y as f64); | 361 | pos.y = pos.y.clamp(min_y as f64, max_y as f64); |
| 363 | 362 | ||
| 364 | - let under = self.surface_under_and_global_space(pos); | 363 | + let under = self.niri.surface_under_and_global_space(pos); |
| 365 | 364 | ||
| 366 | pointer.motion( | 365 | pointer.motion( |
| 367 | self, | 366 | self, |
| @@ -385,20 +384,20 @@ impl Niri { | |||
| 385 | 384 | ||
| 386 | // Redraw to update the cursor position. | 385 | // Redraw to update the cursor position. |
| 387 | // FIXME: redraw only outputs overlapping the cursor. | 386 | // FIXME: redraw only outputs overlapping the cursor. |
| 388 | - self.queue_redraw_all(); | 387 | + self.niri.queue_redraw_all(); |
| 389 | } | 388 | } |
| 390 | InputEvent::PointerMotionAbsolute { event, .. } => { | 389 | InputEvent::PointerMotionAbsolute { event, .. } => { |
| 391 | - let output = self.global_space.outputs().next().unwrap(); | 390 | + let output = self.niri.global_space.outputs().next().unwrap(); |
| 392 | 391 | ||
| 393 | - let output_geo = self.global_space.output_geometry(output).unwrap(); | 392 | + let output_geo = self.niri.global_space.output_geometry(output).unwrap(); |
| 394 | 393 | ||
| 395 | let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64(); | 394 | let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64(); |
| 396 | 395 | ||
| 397 | let serial = SERIAL_COUNTER.next_serial(); | 396 | let serial = SERIAL_COUNTER.next_serial(); |
| 398 | 397 | ||
| 399 | - let pointer = self.seat.get_pointer().unwrap(); | 398 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 400 | 399 | ||
| 401 | - let under = self.surface_under_and_global_space(pos); | 400 | + let under = self.niri.surface_under_and_global_space(pos); |
| 402 | 401 | ||
| 403 | pointer.motion( | 402 | pointer.motion( |
| 404 | self, | 403 | self, |
| @@ -412,10 +411,10 @@ impl Niri { | |||
| 412 | 411 | ||
| 413 | // Redraw to update the cursor position. | 412 | // Redraw to update the cursor position. |
| 414 | // FIXME: redraw only outputs overlapping the cursor. | 413 | // FIXME: redraw only outputs overlapping the cursor. |
| 415 | - self.queue_redraw_all(); | 414 | + self.niri.queue_redraw_all(); |
| 416 | } | 415 | } |
| 417 | InputEvent::PointerButton { event, .. } => { | 416 | InputEvent::PointerButton { event, .. } => { |
| 418 | - let pointer = self.seat.get_pointer().unwrap(); | 417 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 419 | 418 | ||
| 420 | let serial = SERIAL_COUNTER.next_serial(); | 419 | let serial = SERIAL_COUNTER.next_serial(); |
| 421 | 420 | ||
| @@ -424,12 +423,12 @@ impl Niri { | |||
| 424 | let button_state = event.state(); | 423 | let button_state = event.state(); |
| 425 | 424 | ||
| 426 | if ButtonState::Pressed == button_state && !pointer.is_grabbed() { | 425 | if ButtonState::Pressed == button_state && !pointer.is_grabbed() { |
| 427 | - if let Some(window) = self.window_under_cursor() { | 426 | + if let Some(window) = self.niri.window_under_cursor() { |
| 428 | let window = window.clone(); | 427 | let window = window.clone(); |
| 429 | - self.monitor_set.activate_window(&window); | 428 | + self.niri.monitor_set.activate_window(&window); |
| 430 | } else { | 429 | } else { |
| 431 | - let output = self.output_under_cursor().unwrap(); | 430 | + let output = self.niri.output_under_cursor().unwrap(); |
| 432 | - self.monitor_set.activate_output(&output); | 431 | + self.niri.monitor_set.activate_output(&output); |
| 433 | } | 432 | } |
| 434 | }; | 433 | }; |
| 435 | 434 | ||
| @@ -473,21 +472,21 @@ impl Niri { | |||
| 473 | frame = frame.stop(Axis::Vertical); | 472 | frame = frame.stop(Axis::Vertical); |
| 474 | } | 473 | } |
| 475 | 474 | ||
| 476 | - self.seat.get_pointer().unwrap().axis(self, frame); | 475 | + self.niri.seat.get_pointer().unwrap().axis(self, frame); |
| 477 | } | 476 | } |
| 478 | InputEvent::TabletToolAxis { event, .. } => { | 477 | InputEvent::TabletToolAxis { event, .. } => { |
| 479 | // FIXME: allow mapping tablet to different outputs. | 478 | // FIXME: allow mapping tablet to different outputs. |
| 480 | - let output = self.global_space.outputs().next().unwrap(); | 479 | + let output = self.niri.global_space.outputs().next().unwrap(); |
| 481 | 480 | ||
| 482 | - let output_geo = self.global_space.output_geometry(output).unwrap(); | 481 | + let output_geo = self.niri.global_space.output_geometry(output).unwrap(); |
| 483 | 482 | ||
| 484 | let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64(); | 483 | let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64(); |
| 485 | 484 | ||
| 486 | let serial = SERIAL_COUNTER.next_serial(); | 485 | let serial = SERIAL_COUNTER.next_serial(); |
| 487 | 486 | ||
| 488 | - let pointer = self.seat.get_pointer().unwrap(); | 487 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 489 | 488 | ||
| 490 | - let under = self.surface_under_and_global_space(pos); | 489 | + let under = self.niri.surface_under_and_global_space(pos); |
| 491 | 490 | ||
| 492 | pointer.motion( | 491 | pointer.motion( |
| 493 | self, | 492 | self, |
| @@ -499,7 +498,7 @@ impl Niri { | |||
| 499 | }, | 498 | }, |
| 500 | ); | 499 | ); |
| 501 | 500 | ||
| 502 | - let tablet_seat = self.seat.tablet_seat(); | 501 | + let tablet_seat = self.niri.seat.tablet_seat(); |
| 503 | let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device())); | 502 | let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device())); |
| 504 | let tool = tablet_seat.get_tool(&event.tool()); | 503 | let tool = tablet_seat.get_tool(&event.tool()); |
| 505 | if let (Some(tablet), Some(tool)) = (tablet, tool) { | 504 | if let (Some(tablet), Some(tool)) = (tablet, tool) { |
| @@ -533,10 +532,10 @@ impl Niri { | |||
| 533 | 532 | ||
| 534 | // Redraw to update the cursor position. | 533 | // Redraw to update the cursor position. |
| 535 | // FIXME: redraw only outputs overlapping the cursor. | 534 | // FIXME: redraw only outputs overlapping the cursor. |
| 536 | - self.queue_redraw_all(); | 535 | + self.niri.queue_redraw_all(); |
| 537 | } | 536 | } |
| 538 | InputEvent::TabletToolTip { event, .. } => { | 537 | InputEvent::TabletToolTip { event, .. } => { |
| 539 | - let tool = self.seat.tablet_seat().get_tool(&event.tool()); | 538 | + let tool = self.niri.seat.tablet_seat().get_tool(&event.tool()); |
| 540 | 539 | ||
| 541 | if let Some(tool) = tool { | 540 | if let Some(tool) = tool { |
| 542 | match event.tip_state() { | 541 | match event.tip_state() { |
| @@ -544,14 +543,14 @@ impl Niri { | |||
| 544 | let serial = SERIAL_COUNTER.next_serial(); | 543 | let serial = SERIAL_COUNTER.next_serial(); |
| 545 | tool.tip_down(serial, event.time_msec()); | 544 | tool.tip_down(serial, event.time_msec()); |
| 546 | 545 | ||
| 547 | - let pointer = self.seat.get_pointer().unwrap(); | 546 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 548 | if !pointer.is_grabbed() { | 547 | if !pointer.is_grabbed() { |
| 549 | - if let Some(window) = self.window_under_cursor() { | 548 | + if let Some(window) = self.niri.window_under_cursor() { |
| 550 | let window = window.clone(); | 549 | let window = window.clone(); |
| 551 | - self.monitor_set.activate_window(&window); | 550 | + self.niri.monitor_set.activate_window(&window); |
| 552 | } else { | 551 | } else { |
| 553 | - let output = self.output_under_cursor().unwrap(); | 552 | + let output = self.niri.output_under_cursor().unwrap(); |
| 554 | - self.monitor_set.activate_output(&output); | 553 | + self.niri.monitor_set.activate_output(&output); |
| 555 | } | 554 | } |
| 556 | }; | 555 | }; |
| 557 | } | 556 | } |
| @@ -563,17 +562,17 @@ impl Niri { | |||
| 563 | } | 562 | } |
| 564 | InputEvent::TabletToolProximity { event, .. } => { | 563 | InputEvent::TabletToolProximity { event, .. } => { |
| 565 | // FIXME: allow mapping tablet to different outputs. | 564 | // FIXME: allow mapping tablet to different outputs. |
| 566 | - let output = self.global_space.outputs().next().unwrap(); | 565 | + let output = self.niri.global_space.outputs().next().unwrap(); |
| 567 | 566 | ||
| 568 | - let output_geo = self.global_space.output_geometry(output).unwrap(); | 567 | + let output_geo = self.niri.global_space.output_geometry(output).unwrap(); |
| 569 | 568 | ||
| 570 | let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64(); | 569 | let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64(); |
| 571 | 570 | ||
| 572 | let serial = SERIAL_COUNTER.next_serial(); | 571 | let serial = SERIAL_COUNTER.next_serial(); |
| 573 | 572 | ||
| 574 | - let pointer = self.seat.get_pointer().unwrap(); | 573 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 575 | 574 | ||
| 576 | - let under = self.surface_under_and_global_space(pos); | 575 | + let under = self.niri.surface_under_and_global_space(pos); |
| 577 | 576 | ||
| 578 | pointer.motion( | 577 | pointer.motion( |
| 579 | self, | 578 | self, |
| @@ -585,8 +584,8 @@ impl Niri { | |||
| 585 | }, | 584 | }, |
| 586 | ); | 585 | ); |
| 587 | 586 | ||
| 588 | - let tablet_seat = self.seat.tablet_seat(); | 587 | + let tablet_seat = self.niri.seat.tablet_seat(); |
| 589 | - let tool = tablet_seat.add_tool::<Self>(&self.display_handle, &event.tool()); | 588 | + let tool = tablet_seat.add_tool::<Self>(&self.niri.display_handle, &event.tool()); |
| 590 | let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device())); | 589 | let tablet = tablet_seat.get_tablet(&TabletDescriptor::from(&event.device())); |
| 591 | if let (Some(under), Some(tablet)) = (under, tablet) { | 590 | if let (Some(under), Some(tablet)) = (under, tablet) { |
| 592 | match event.state() { | 591 | match event.state() { |
| @@ -602,7 +601,7 @@ impl Niri { | |||
| 602 | } | 601 | } |
| 603 | } | 602 | } |
| 604 | InputEvent::TabletToolButton { event, .. } => { | 603 | InputEvent::TabletToolButton { event, .. } => { |
| 605 | - let tool = self.seat.tablet_seat().get_tool(&event.tool()); | 604 | + let tool = self.niri.seat.tablet_seat().get_tool(&event.tool()); |
| 606 | 605 | ||
| 607 | if let Some(tool) = tool { | 606 | if let Some(tool) = tool { |
| 608 | tool.button( | 607 | tool.button( |
| @@ -615,14 +614,15 @@ impl Niri { | |||
| 615 | } | 614 | } |
| 616 | InputEvent::DeviceAdded { device } => { | 615 | InputEvent::DeviceAdded { device } => { |
| 617 | if device.has_capability(DeviceCapability::TabletTool) { | 616 | if device.has_capability(DeviceCapability::TabletTool) { |
| 618 | - self.seat | 617 | + self.niri.seat.tablet_seat().add_tablet::<Self>( |
| 619 | - .tablet_seat() | 618 | + &self.niri.display_handle, |
| 620 | - .add_tablet::<Self>(&self.display_handle, &TabletDescriptor::from(&device)); | 619 | + &TabletDescriptor::from(&device), |
| 620 | + ); | ||
| 621 | } | 621 | } |
| 622 | } | 622 | } |
| 623 | InputEvent::DeviceRemoved { device } => { | 623 | InputEvent::DeviceRemoved { device } => { |
| 624 | if device.has_capability(DeviceCapability::TabletTool) { | 624 | if device.has_capability(DeviceCapability::TabletTool) { |
| 625 | - let tablet_seat = self.seat.tablet_seat(); | 625 | + let tablet_seat = self.niri.seat.tablet_seat(); |
| 626 | 626 | ||
| 627 | tablet_seat.remove_tablet(&TabletDescriptor::from(&device)); | 627 | tablet_seat.remove_tablet(&TabletDescriptor::from(&device)); |
| 628 | 628 | ||
| @@ -634,7 +634,7 @@ impl Niri { | |||
| 634 | } | 634 | } |
| 635 | InputEvent::GestureSwipeBegin { event } => { | 635 | InputEvent::GestureSwipeBegin { event } => { |
| 636 | let serial = SERIAL_COUNTER.next_serial(); | 636 | let serial = SERIAL_COUNTER.next_serial(); |
| 637 | - let pointer = self.seat.get_pointer().unwrap(); | 637 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 638 | pointer.gesture_swipe_begin( | 638 | pointer.gesture_swipe_begin( |
| 639 | self, | 639 | self, |
| 640 | &GestureSwipeBeginEvent { | 640 | &GestureSwipeBeginEvent { |
| @@ -645,7 +645,7 @@ impl Niri { | |||
| 645 | ); | 645 | ); |
| 646 | } | 646 | } |
| 647 | InputEvent::GestureSwipeUpdate { event } => { | 647 | InputEvent::GestureSwipeUpdate { event } => { |
| 648 | - let pointer = self.seat.get_pointer().unwrap(); | 648 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 649 | pointer.gesture_swipe_update( | 649 | pointer.gesture_swipe_update( |
| 650 | self, | 650 | self, |
| 651 | &GestureSwipeUpdateEvent { | 651 | &GestureSwipeUpdateEvent { |
| @@ -656,7 +656,7 @@ impl Niri { | |||
| 656 | } | 656 | } |
| 657 | InputEvent::GestureSwipeEnd { event } => { | 657 | InputEvent::GestureSwipeEnd { event } => { |
| 658 | let serial = SERIAL_COUNTER.next_serial(); | 658 | let serial = SERIAL_COUNTER.next_serial(); |
| 659 | - let pointer = self.seat.get_pointer().unwrap(); | 659 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 660 | pointer.gesture_swipe_end( | 660 | pointer.gesture_swipe_end( |
| 661 | self, | 661 | self, |
| 662 | &GestureSwipeEndEvent { | 662 | &GestureSwipeEndEvent { |
| @@ -668,7 +668,7 @@ impl Niri { | |||
| 668 | } | 668 | } |
| 669 | InputEvent::GesturePinchBegin { event } => { | 669 | InputEvent::GesturePinchBegin { event } => { |
| 670 | let serial = SERIAL_COUNTER.next_serial(); | 670 | let serial = SERIAL_COUNTER.next_serial(); |
| 671 | - let pointer = self.seat.get_pointer().unwrap(); | 671 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 672 | pointer.gesture_pinch_begin( | 672 | pointer.gesture_pinch_begin( |
| 673 | self, | 673 | self, |
| 674 | &GesturePinchBeginEvent { | 674 | &GesturePinchBeginEvent { |
| @@ -679,7 +679,7 @@ impl Niri { | |||
| 679 | ); | 679 | ); |
| 680 | } | 680 | } |
| 681 | InputEvent::GesturePinchUpdate { event } => { | 681 | InputEvent::GesturePinchUpdate { event } => { |
| 682 | - let pointer = self.seat.get_pointer().unwrap(); | 682 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 683 | pointer.gesture_pinch_update( | 683 | pointer.gesture_pinch_update( |
| 684 | self, | 684 | self, |
| 685 | &GesturePinchUpdateEvent { | 685 | &GesturePinchUpdateEvent { |
| @@ -694,7 +694,7 @@ impl Niri { | |||
| 694 | } | 694 | } |
| 695 | InputEvent::GesturePinchEnd { event } => { | 695 | InputEvent::GesturePinchEnd { event } => { |
| 696 | let serial = SERIAL_COUNTER.next_serial(); | 696 | let serial = SERIAL_COUNTER.next_serial(); |
| 697 | - let pointer = self.seat.get_pointer().unwrap(); | 697 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 698 | pointer.gesture_pinch_end( | 698 | pointer.gesture_pinch_end( |
| 699 | self, | 699 | self, |
| 700 | &GesturePinchEndEvent { | 700 | &GesturePinchEndEvent { |
| @@ -706,7 +706,7 @@ impl Niri { | |||
| 706 | } | 706 | } |
| 707 | InputEvent::GestureHoldBegin { event } => { | 707 | InputEvent::GestureHoldBegin { event } => { |
| 708 | let serial = SERIAL_COUNTER.next_serial(); | 708 | let serial = SERIAL_COUNTER.next_serial(); |
| 709 | - let pointer = self.seat.get_pointer().unwrap(); | 709 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 710 | pointer.gesture_hold_begin( | 710 | pointer.gesture_hold_begin( |
| 711 | self, | 711 | self, |
| 712 | &GestureHoldBeginEvent { | 712 | &GestureHoldBeginEvent { |
| @@ -718,7 +718,7 @@ impl Niri { | |||
| 718 | } | 718 | } |
| 719 | InputEvent::GestureHoldEnd { event } => { | 719 | InputEvent::GestureHoldEnd { event } => { |
| 720 | let serial = SERIAL_COUNTER.next_serial(); | 720 | let serial = SERIAL_COUNTER.next_serial(); |
| 721 | - let pointer = self.seat.get_pointer().unwrap(); | 721 | + let pointer = self.niri.seat.get_pointer().unwrap(); |
| 722 | pointer.gesture_hold_end( | 722 | pointer.gesture_hold_end( |
| 723 | self, | 723 | self, |
| 724 | &GestureHoldEndEvent { | 724 | &GestureHoldEndEvent { |
| @@ -735,8 +735,6 @@ impl Niri { | |||
| 735 | InputEvent::TouchFrame { .. } => (), | 735 | InputEvent::TouchFrame { .. } => (), |
| 736 | InputEvent::Special(_) => (), | 736 | InputEvent::Special(_) => (), |
| 737 | } | 737 | } |
| 738 | - | ||
| 739 | - BackendAction::None | ||
| 740 | } | 738 | } |
| 741 | 739 | ||
| 742 | pub fn process_libinput_event(&mut self, event: &mut InputEvent<LibinputInputBackend>) { | 740 | pub fn process_libinput_event(&mut self, event: &mut InputEvent<LibinputInputBackend>) { |
src/main.rsmodified+13 -5
| @@ -16,8 +16,9 @@ use std::env; | |||
| 16 | use std::ffi::OsString; | 16 | use std::ffi::OsString; |
| 17 | 17 | ||
| 18 | use clap::Parser; | 18 | use clap::Parser; |
| 19 | -use niri::{Data, Niri}; | 19 | +use niri::{Niri, State}; |
| 20 | use smithay::reexports::calloop::EventLoop; | 20 | use smithay::reexports::calloop::EventLoop; |
| 21 | +use smithay::reexports::wayland_server::Display; | ||
| 21 | use tracing_subscriber::EnvFilter; | 22 | use tracing_subscriber::EnvFilter; |
| 22 | 23 | ||
| 23 | #[derive(Parser)] | 24 | #[derive(Parser)] |
| @@ -28,6 +29,11 @@ struct Cli { | |||
| 28 | command: Vec<OsString>, | 29 | command: Vec<OsString>, |
| 29 | } | 30 | } |
| 30 | 31 | ||
| 32 | +struct LoopData { | ||
| 33 | + display: Display<State>, | ||
| 34 | + state: State, | ||
| 35 | +} | ||
| 36 | + | ||
| 31 | fn main() { | 37 | fn main() { |
| 32 | env::set_var("RUST_BACKTRACE", "1"); | 38 | env::set_var("RUST_BACKTRACE", "1"); |
| 33 | 39 | ||
| @@ -43,7 +49,9 @@ fn main() { | |||
| 43 | let _client = tracy_client::Client::start(); | 49 | let _client = tracy_client::Client::start(); |
| 44 | 50 | ||
| 45 | let mut event_loop = EventLoop::try_new().unwrap(); | 51 | let mut event_loop = EventLoop::try_new().unwrap(); |
| 46 | - let mut data = Data::new(event_loop.handle(), event_loop.get_signal()); | 52 | + let mut display = Display::new().unwrap(); |
| 53 | + let state = State::new(event_loop.handle(), event_loop.get_signal(), &mut display); | ||
| 54 | + let mut data = LoopData { display, state }; | ||
| 47 | 55 | ||
| 48 | if let Some((command, args)) = cli.command.split_first() { | 56 | if let Some((command, args)) = cli.command.split_first() { |
| 49 | if let Err(err) = std::process::Command::new(command).args(args).spawn() { | 57 | if let Err(err) = std::process::Command::new(command).args(args).spawn() { |
| @@ -56,9 +64,9 @@ fn main() { | |||
| 56 | let _span = tracy_client::span!("loop callback"); | 64 | let _span = tracy_client::span!("loop callback"); |
| 57 | 65 | ||
| 58 | // These should be called periodically, before flushing the clients. | 66 | // These should be called periodically, before flushing the clients. |
| 59 | - data.niri.monitor_set.refresh(); | 67 | + data.state.niri.monitor_set.refresh(); |
| 60 | - data.niri.popups.cleanup(); | 68 | + data.state.niri.popups.cleanup(); |
| 61 | - data.niri.update_focus(); | 69 | + data.state.update_focus(); |
| 62 | 70 | ||
| 63 | { | 71 | { |
| 64 | let _span = tracy_client::span!("flush_clients"); | 72 | let _span = tracy_client::span!("flush_clients"); |
src/niri.rsmodified+64 -62
| @@ -58,10 +58,11 @@ use crate::dbus::mutter_service_channel::ServiceChannel; | |||
| 58 | use crate::frame_clock::FrameClock; | 58 | use crate::frame_clock::FrameClock; |
| 59 | use crate::layout::{MonitorRenderElement, MonitorSet}; | 59 | use crate::layout::{MonitorRenderElement, MonitorSet}; |
| 60 | use crate::utils::{center, get_monotonic_time, load_default_cursor}; | 60 | use crate::utils::{center, get_monotonic_time, load_default_cursor}; |
| 61 | +use crate::LoopData; | ||
| 61 | 62 | ||
| 62 | pub struct Niri { | 63 | pub struct Niri { |
| 63 | pub start_time: std::time::Instant, | 64 | pub start_time: std::time::Instant, |
| 64 | - pub event_loop: LoopHandle<'static, Data>, | 65 | + pub event_loop: LoopHandle<'static, LoopData>, |
| 65 | pub stop_signal: LoopSignal, | 66 | pub stop_signal: LoopSignal, |
| 66 | pub display_handle: DisplayHandle, | 67 | pub display_handle: DisplayHandle, |
| 67 | 68 | ||
| @@ -84,14 +85,14 @@ pub struct Niri { | |||
| 84 | pub layer_shell_state: WlrLayerShellState, | 85 | pub layer_shell_state: WlrLayerShellState, |
| 85 | pub shm_state: ShmState, | 86 | pub shm_state: ShmState, |
| 86 | pub output_manager_state: OutputManagerState, | 87 | pub output_manager_state: OutputManagerState, |
| 87 | - pub seat_state: SeatState<Self>, | 88 | + pub seat_state: SeatState<State>, |
| 88 | pub tablet_state: TabletManagerState, | 89 | pub tablet_state: TabletManagerState, |
| 89 | pub pointer_gestures_state: PointerGesturesState, | 90 | pub pointer_gestures_state: PointerGesturesState, |
| 90 | pub data_device_state: DataDeviceState, | 91 | pub data_device_state: DataDeviceState, |
| 91 | pub popups: PopupManager, | 92 | pub popups: PopupManager, |
| 92 | pub presentation_state: PresentationState, | 93 | pub presentation_state: PresentationState, |
| 93 | 94 | ||
| 94 | - pub seat: Seat<Self>, | 95 | + pub seat: Seat<State>, |
| 95 | 96 | ||
| 96 | pub pointer_buffer: Option<(TextureBuffer<GlesTexture>, Point<i32, Physical>)>, | 97 | pub pointer_buffer: Option<(TextureBuffer<GlesTexture>, Point<i32, Physical>)>, |
| 97 | pub cursor_image: CursorImageStatus, | 98 | pub cursor_image: CursorImageStatus, |
| @@ -112,14 +113,17 @@ pub struct OutputState { | |||
| 112 | pub frame_clock: FrameClock, | 113 | pub frame_clock: FrameClock, |
| 113 | } | 114 | } |
| 114 | 115 | ||
| 115 | -pub struct Data { | 116 | +pub struct State { |
| 116 | - pub display: Display<Niri>, | ||
| 117 | pub backend: Backend, | 117 | pub backend: Backend, |
| 118 | pub niri: Niri, | 118 | pub niri: Niri, |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | -impl Data { | 121 | +impl State { |
| 122 | - pub fn new(event_loop: LoopHandle<'static, Self>, stop_signal: LoopSignal) -> Self { | 122 | + pub fn new( |
| 123 | + event_loop: LoopHandle<'static, LoopData>, | ||
| 124 | + stop_signal: LoopSignal, | ||
| 125 | + display: &mut Display<State>, | ||
| 126 | + ) -> Self { | ||
| 123 | let has_display = | 127 | let has_display = |
| 124 | env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some(); | 128 | env::var_os("WAYLAND_DISPLAY").is_some() || env::var_os("DISPLAY").is_some(); |
| 125 | 129 | ||
| @@ -129,45 +133,76 @@ impl Data { | |||
| 129 | Backend::Tty(Tty::new(event_loop.clone())) | 133 | Backend::Tty(Tty::new(event_loop.clone())) |
| 130 | }; | 134 | }; |
| 131 | 135 | ||
| 132 | - let mut display = Display::new().unwrap(); | 136 | + let mut niri = Niri::new(event_loop, stop_signal, display, backend.seat_name()); |
| 133 | - let mut niri = Niri::new(event_loop, stop_signal, &mut display, backend.seat_name()); | ||
| 134 | backend.init(&mut niri); | 137 | backend.init(&mut niri); |
| 135 | 138 | ||
| 136 | - Self { | 139 | + Self { backend, niri } |
| 137 | - display, | 140 | + } |
| 138 | - backend, | 141 | + |
| 139 | - niri, | 142 | + pub fn move_cursor(&mut self, location: Point<f64, Logical>) { |
| 143 | + let under = self.niri.surface_under_and_global_space(location); | ||
| 144 | + self.niri.seat.get_pointer().unwrap().motion( | ||
| 145 | + self, | ||
| 146 | + under, | ||
| 147 | + &MotionEvent { | ||
| 148 | + location, | ||
| 149 | + serial: SERIAL_COUNTER.next_serial(), | ||
| 150 | + time: get_monotonic_time().as_millis() as u32, | ||
| 151 | + }, | ||
| 152 | + ); | ||
| 153 | + // FIXME: granular | ||
| 154 | + self.niri.queue_redraw_all(); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + pub fn move_cursor_to_output(&mut self, output: &Output) { | ||
| 158 | + let geo = self.niri.global_space.output_geometry(output).unwrap(); | ||
| 159 | + self.move_cursor(center(geo).to_f64()); | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + pub fn update_focus(&mut self) { | ||
| 163 | + let focus = self.niri.layer_surface_focus().or_else(|| { | ||
| 164 | + self.niri | ||
| 165 | + .monitor_set | ||
| 166 | + .focus() | ||
| 167 | + .map(|win| win.toplevel().wl_surface().clone()) | ||
| 168 | + }); | ||
| 169 | + let keyboard = self.niri.seat.get_keyboard().unwrap(); | ||
| 170 | + if keyboard.current_focus() != focus { | ||
| 171 | + keyboard.set_focus(self, focus, SERIAL_COUNTER.next_serial()); | ||
| 172 | + // FIXME: can be more granular. | ||
| 173 | + self.niri.queue_redraw_all(); | ||
| 140 | } | 174 | } |
| 141 | } | 175 | } |
| 142 | } | 176 | } |
| 143 | 177 | ||
| 144 | impl Niri { | 178 | impl Niri { |
| 145 | pub fn new( | 179 | pub fn new( |
| 146 | - event_loop: LoopHandle<'static, Data>, | 180 | + event_loop: LoopHandle<'static, LoopData>, |
| 147 | stop_signal: LoopSignal, | 181 | stop_signal: LoopSignal, |
| 148 | - display: &mut Display<Self>, | 182 | + display: &mut Display<State>, |
| 149 | seat_name: String, | 183 | seat_name: String, |
| 150 | ) -> Self { | 184 | ) -> Self { |
| 151 | let start_time = std::time::Instant::now(); | 185 | let start_time = std::time::Instant::now(); |
| 152 | 186 | ||
| 153 | let display_handle = display.handle(); | 187 | let display_handle = display.handle(); |
| 154 | 188 | ||
| 155 | - let compositor_state = CompositorState::new::<Self>(&display_handle); | 189 | + let compositor_state = CompositorState::new::<State>(&display_handle); |
| 156 | - let xdg_shell_state = XdgShellState::new_with_capabilities::<Self>( | 190 | + let xdg_shell_state = XdgShellState::new_with_capabilities::<State>( |
| 157 | &display_handle, | 191 | &display_handle, |
| 158 | [WmCapabilities::Fullscreen], | 192 | [WmCapabilities::Fullscreen], |
| 159 | ); | 193 | ); |
| 160 | - let layer_shell_state = WlrLayerShellState::new::<Self>(&display_handle); | 194 | + let layer_shell_state = WlrLayerShellState::new::<State>(&display_handle); |
| 161 | - let shm_state = ShmState::new::<Self>(&display_handle, vec![]); | 195 | + let shm_state = ShmState::new::<State>(&display_handle, vec![]); |
| 162 | - let output_manager_state = OutputManagerState::new_with_xdg_output::<Self>(&display_handle); | 196 | + let output_manager_state = |
| 197 | + OutputManagerState::new_with_xdg_output::<State>(&display_handle); | ||
| 163 | let mut seat_state = SeatState::new(); | 198 | let mut seat_state = SeatState::new(); |
| 164 | - let tablet_state = TabletManagerState::new::<Self>(&display_handle); | 199 | + let tablet_state = TabletManagerState::new::<State>(&display_handle); |
| 165 | - let pointer_gestures_state = PointerGesturesState::new::<Self>(&display_handle); | 200 | + let pointer_gestures_state = PointerGesturesState::new::<State>(&display_handle); |
| 166 | - let data_device_state = DataDeviceState::new::<Self>(&display_handle); | 201 | + let data_device_state = DataDeviceState::new::<State>(&display_handle); |
| 167 | let presentation_state = | 202 | let presentation_state = |
| 168 | - PresentationState::new::<Self>(&display_handle, CLOCK_MONOTONIC as u32); | 203 | + PresentationState::new::<State>(&display_handle, CLOCK_MONOTONIC as u32); |
| 169 | 204 | ||
| 170 | - let mut seat: Seat<Self> = seat_state.new_wl_seat(&display_handle, seat_name); | 205 | + let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, seat_name); |
| 171 | // FIXME: get Xkb and repeat interval from GNOME dconf. | 206 | // FIXME: get Xkb and repeat interval from GNOME dconf. |
| 172 | let xkb = XkbConfig { | 207 | let xkb = XkbConfig { |
| 173 | layout: "us,ru", | 208 | layout: "us,ru", |
| @@ -182,6 +217,7 @@ impl Niri { | |||
| 182 | event_loop | 217 | event_loop |
| 183 | .insert_source(socket_source, move |client, _, data| { | 218 | .insert_source(socket_source, move |client, _, data| { |
| 184 | if let Err(err) = data | 219 | if let Err(err) = data |
| 220 | + .state | ||
| 185 | .niri | 221 | .niri |
| 186 | .display_handle | 222 | .display_handle |
| 187 | .insert_client(client, Arc::new(ClientState::default())) | 223 | .insert_client(client, Arc::new(ClientState::default())) |
| @@ -280,7 +316,7 @@ impl Niri { | |||
| 280 | ); | 316 | ); |
| 281 | event_loop | 317 | event_loop |
| 282 | .insert_source(display_source, |_, _, data| { | 318 | .insert_source(display_source, |_, _, data| { |
| 283 | - data.display.dispatch_clients(&mut data.niri).unwrap(); | 319 | + data.display.dispatch_clients(&mut data.state).unwrap(); |
| 284 | Ok(PostAction::Continue) | 320 | Ok(PostAction::Continue) |
| 285 | }) | 321 | }) |
| 286 | .unwrap(); | 322 | .unwrap(); |
| @@ -331,7 +367,7 @@ impl Niri { | |||
| 331 | self.monitor_set.add_output(output.clone()); | 367 | self.monitor_set.add_output(output.clone()); |
| 332 | 368 | ||
| 333 | let state = OutputState { | 369 | let state = OutputState { |
| 334 | - global: output.create_global::<Niri>(&self.display_handle), | 370 | + global: output.create_global::<State>(&self.display_handle), |
| 335 | queued_redraw: None, | 371 | queued_redraw: None, |
| 336 | waiting_for_vblank: false, | 372 | waiting_for_vblank: false, |
| 337 | frame_clock: FrameClock::new(refresh_interval), | 373 | frame_clock: FrameClock::new(refresh_interval), |
| @@ -477,26 +513,6 @@ impl Niri { | |||
| 477 | .cloned() | 513 | .cloned() |
| 478 | } | 514 | } |
| 479 | 515 | ||
| 480 | - pub fn move_cursor(&mut self, location: Point<f64, Logical>) { | ||
| 481 | - let under = self.surface_under_and_global_space(location); | ||
| 482 | - self.seat.get_pointer().unwrap().motion( | ||
| 483 | - self, | ||
| 484 | - under, | ||
| 485 | - &MotionEvent { | ||
| 486 | - location, | ||
| 487 | - serial: SERIAL_COUNTER.next_serial(), | ||
| 488 | - time: get_monotonic_time().as_millis() as u32, | ||
| 489 | - }, | ||
| 490 | - ); | ||
| 491 | - // FIXME: granular | ||
| 492 | - self.queue_redraw_all(); | ||
| 493 | - } | ||
| 494 | - | ||
| 495 | - pub fn move_cursor_to_output(&mut self, output: &Output) { | ||
| 496 | - let geo = self.global_space.output_geometry(output).unwrap(); | ||
| 497 | - self.move_cursor(center(geo).to_f64()); | ||
| 498 | - } | ||
| 499 | - | ||
| 500 | fn layer_surface_focus(&self) -> Option<WlSurface> { | 516 | fn layer_surface_focus(&self) -> Option<WlSurface> { |
| 501 | let output = self.monitor_set.active_output()?; | 517 | let output = self.monitor_set.active_output()?; |
| 502 | let layers = layer_map_for_output(output); | 518 | let layers = layer_map_for_output(output); |
| @@ -508,20 +524,6 @@ impl Niri { | |||
| 508 | Some(surface.wl_surface().clone()) | 524 | Some(surface.wl_surface().clone()) |
| 509 | } | 525 | } |
| 510 | 526 | ||
| 511 | - pub fn update_focus(&mut self) { | ||
| 512 | - let focus = self.layer_surface_focus().or_else(|| { | ||
| 513 | - self.monitor_set | ||
| 514 | - .focus() | ||
| 515 | - .map(|win| win.toplevel().wl_surface().clone()) | ||
| 516 | - }); | ||
| 517 | - let keyboard = self.seat.get_keyboard().unwrap(); | ||
| 518 | - if keyboard.current_focus() != focus { | ||
| 519 | - keyboard.set_focus(self, focus, SERIAL_COUNTER.next_serial()); | ||
| 520 | - // FIXME: can be more granular. | ||
| 521 | - self.queue_redraw_all(); | ||
| 522 | - } | ||
| 523 | - } | ||
| 524 | - | ||
| 525 | /// Schedules an immediate redraw on all outputs if one is not already scheduled. | 527 | /// Schedules an immediate redraw on all outputs if one is not already scheduled. |
| 526 | pub fn queue_redraw_all(&mut self) { | 528 | pub fn queue_redraw_all(&mut self) { |
| 527 | let outputs: Vec<_> = self.output_state.keys().cloned().collect(); | 529 | let outputs: Vec<_> = self.output_state.keys().cloned().collect(); |
| @@ -541,7 +543,7 @@ impl Niri { | |||
| 541 | // Timer::immediate() adds a millisecond of delay for some reason. | 543 | // Timer::immediate() adds a millisecond of delay for some reason. |
| 542 | // This should be fixed in calloop v0.11: https://github.com/Smithay/calloop/issues/142 | 544 | // This should be fixed in calloop v0.11: https://github.com/Smithay/calloop/issues/142 |
| 543 | let idle = self.event_loop.insert_idle(move |data| { | 545 | let idle = self.event_loop.insert_idle(move |data| { |
| 544 | - data.niri.redraw(&mut data.backend, &output); | 546 | + data.state.niri.redraw(&mut data.state.backend, &output); |
| 545 | }); | 547 | }); |
| 546 | state.queued_redraw = Some(idle); | 548 | state.queued_redraw = Some(idle); |
| 547 | } | 549 | } |