forge
Explore
Log in

Don't you dare go Hollow

Wrap mapped windows in a Mapped

Browse files at this commit

3963f537a4182dbcd8e1e2f262ee105473facc56Ivan MolodetskikhParent: f31e105
src/handlers/compositor.rsmodified+19 -16
@@ -17,8 +17,7 @@ use smithay::wayland::shm::{ShmHandler, ShmState};
1717 use smithay::{delegate_compositor, delegate_shm};
1818
1919 use crate::niri::{ClientState, State};
20-use crate::utils::clone2;
21-use crate::window::{InitialConfigureState, Unmapped};
20+use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped};
2221
2322 impl CompositorHandler for State {
2423 fn compositor_state(&mut self) -> &mut CompositorState {
@@ -109,22 +108,22 @@ impl CompositorHandler for State {
109108
110109 window.on_commit();
111110
112- let (width, is_full_width, output) =
111+ let (rules, width, is_full_width, output) =
113112 if let InitialConfigureState::Configured {
113+ rules,
114114 width,
115115 is_full_width,
116116 output,
117- ..
118117 } = state
119118 {
120119 // Check that the output is still connected.
121120 let output =
122121 output.filter(|o| self.niri.layout.monitor_for_output(o).is_some());
123122
124- (width, is_full_width, output)
123+ (rules, width, is_full_width, output)
125124 } else {
126125 error!("window map must happen after initial configure");
127- (None, false, None)
126+ (ResolvedWindowRules::default(), None, false, None)
128127 };
129128
130129 let parent = window
@@ -141,29 +140,30 @@ impl CompositorHandler for State {
141140 .filter(|(_, parent_output)| {
142141 output.is_none() || output.as_ref() == Some(*parent_output)
143142 })
144- .map(|(window, _)| window.clone());
143+ .map(|(mapped, _)| mapped.window.clone());
145144
146- let window = window.clone();
147- let win = window.clone();
145+ let mapped = Mapped::new(window, rules);
146+ let window = mapped.window.clone();
148147
149148 let output = if let Some(p) = parent {
150149 // Open dialogs immediately to the right of their parent window.
151150 self.niri
152151 .layout
153- .add_window_right_of(&p, win, width, is_full_width)
152+ .add_window_right_of(&p, mapped, width, is_full_width)
154153 } else if let Some(output) = &output {
155154 self.niri
156155 .layout
157- .add_window_on_output(output, win, width, is_full_width);
156+ .add_window_on_output(output, mapped, width, is_full_width);
158157 Some(output)
159158 } else {
160- self.niri.layout.add_window(win, width, is_full_width)
159+ self.niri.layout.add_window(mapped, width, is_full_width)
161160 };
162161
163162 if let Some(output) = output.cloned() {
164163 self.niri.layout.start_open_animation_for_window(&window);
165164
166- let new_active_window = self.niri.layout.active_window().map(|(w, _)| w);
165+ let new_active_window =
166+ self.niri.layout.active_window().map(|(m, _)| &m.window);
167167 if new_active_window == Some(&window) {
168168 self.maybe_warp_cursor_to_focus();
169169 }
@@ -183,8 +183,9 @@ impl CompositorHandler for State {
183183 }
184184
185185 // This is a commit of a previously-mapped root or a non-toplevel root.
186- if let Some(win_out) = self.niri.layout.find_window_and_output(surface) {
187- let (window, output) = clone2(win_out);
186+ if let Some((mapped, output)) = self.niri.layout.find_window_and_output(surface) {
187+ let window = mapped.window.clone();
188+ let output = output.clone();
188189
189190 window.on_commit();
190191
@@ -224,7 +225,9 @@ impl CompositorHandler for State {
224225
225226 // This is a commit of a non-root or a non-toplevel root.
226227 let root_window_output = self.niri.layout.find_window_and_output(&root_surface);
227- if let Some((window, output)) = root_window_output.map(clone2) {
228+ if let Some((mapped, output)) = root_window_output {
229+ let window = mapped.window.clone();
230+ let output = output.clone();
228231 window.on_commit();
229232 self.niri.layout.update_window(&window);
230233 self.niri.queue_redraw(output);
src/handlers/mod.rsmodified+10 -11
@@ -144,7 +144,7 @@ impl InputMethodHandler for State {
144144 self.niri
145145 .layout
146146 .find_window_and_output(parent)
147- .map(|(window, _)| window.geometry())
147+ .map(|(mapped, _)| mapped.window.geometry())
148148 .unwrap_or_default()
149149 }
150150 }
@@ -333,25 +333,24 @@ impl ForeignToplevelHandler for State {
333333 }
334334
335335 fn activate(&mut self, wl_surface: WlSurface) {
336- if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
337- let window = window.clone();
336+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
337+ let window = mapped.window.clone();
338338 self.niri.layout.activate_window(&window);
339339 self.niri.queue_redraw_all();
340340 }
341341 }
342342
343343 fn close(&mut self, wl_surface: WlSurface) {
344- if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
345- window.toplevel().expect("no x11 support").send_close();
344+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
345+ mapped.toplevel().send_close();
346346 }
347347 }
348348
349349 fn set_fullscreen(&mut self, wl_surface: WlSurface, wl_output: Option<WlOutput>) {
350- if let Some((window, current_output)) = self.niri.layout.find_window_and_output(&wl_surface)
350+ if let Some((mapped, current_output)) = self.niri.layout.find_window_and_output(&wl_surface)
351351 {
352- if !window
352+ if !mapped
353353 .toplevel()
354- .expect("no x11 support")
355354 .current_state()
356355 .capabilities
357356 .contains(xdg_toplevel::WmCapabilities::Fullscreen)
@@ -359,7 +358,7 @@ impl ForeignToplevelHandler for State {
359358 return;
360359 }
361360
362- let window = window.clone();
361+ let window = mapped.window.clone();
363362
364363 if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {
365364 if &requested_output != current_output {
@@ -374,8 +373,8 @@ impl ForeignToplevelHandler for State {
374373 }
375374
376375 fn unset_fullscreen(&mut self, wl_surface: WlSurface) {
377- if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
378- let window = window.clone();
376+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
377+ let window = mapped.window.clone();
379378 self.niri.layout.set_fullscreen(&window, false);
380379 }
381380 }
src/handlers/xdg_shell.rsmodified+13 -12
@@ -29,7 +29,6 @@ use smithay::{
2929
3030 use crate::layout::workspace::ColumnWidth;
3131 use crate::niri::{PopupGrabState, State};
32-use crate::utils::clone2;
3332 use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped};
3433
3534 fn window_matches(role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool {
@@ -213,9 +212,7 @@ impl XdgShellHandler for State {
213212 }
214213
215214 let layout_focus = self.niri.layout.focus();
216- if Some(&root)
217- != layout_focus.map(|win| win.toplevel().expect("no x11 support").wl_surface())
218- {
215+ if Some(&root) != layout_focus.map(|win| win.toplevel().wl_surface()) {
219216 let _ = PopupManager::dismiss_popup(&root, &popup);
220217 return;
221218 }
@@ -278,12 +275,12 @@ impl XdgShellHandler for State {
278275 ) {
279276 let requested_output = wl_output.as_ref().and_then(Output::from_resource);
280277
281- if let Some((window, current_output)) = self
278+ if let Some((mapped, current_output)) = self
282279 .niri
283280 .layout
284281 .find_window_and_output(toplevel.wl_surface())
285282 {
286- let window = window.clone();
283+ let window = mapped.window.clone();
287284
288285 if let Some(requested_output) = requested_output {
289286 if &requested_output != current_output {
@@ -358,12 +355,12 @@ impl XdgShellHandler for State {
358355 }
359356
360357 fn unfullscreen_request(&mut self, toplevel: ToplevelSurface) {
361- if let Some((window, _)) = self
358+ if let Some((mapped, _)) = self
362359 .niri
363360 .layout
364361 .find_window_and_output(toplevel.wl_surface())
365362 {
366- let window = window.clone();
363+ let window = mapped.window.clone();
367364 self.niri.layout.set_fullscreen(&window, false);
368365
369366 // A configure is required in response to this event regardless if there are pending
@@ -453,14 +450,16 @@ impl XdgShellHandler for State {
453450 .layout
454451 .find_window_and_output(surface.wl_surface());
455452
456- let Some((window, output)) = win_out.map(clone2) else {
453+ let Some((mapped, output)) = win_out else {
457454 // I have no idea how this can happen, but I saw it happen once, in a weird interaction
458455 // involving laptop going to sleep and resuming.
459456 error!("toplevel missing from both unmapped_windows and layout");
460457 return;
461458 };
459+ let window = mapped.window.clone();
460+ let output = output.clone();
462461
463- let active_window = self.niri.layout.active_window().map(|(w, _)| w);
462+ let active_window = self.niri.layout.active_window().map(|(m, _)| &m.window);
464463 let was_active = active_window == Some(&window);
465464
466465 self.niri.layout.remove_window(&window);
@@ -733,8 +732,8 @@ impl State {
733732 };
734733
735734 // Figure out if the root is a window or a layer surface.
736- if let Some((window, output)) = self.niri.layout.find_window_and_output(&root) {
737- self.unconstrain_window_popup(popup, window, output);
735+ if let Some((mapped, output)) = self.niri.layout.find_window_and_output(&root) {
736+ self.unconstrain_window_popup(popup, &mapped.window, output);
738737 } else if let Some((layer_surface, output)) = self.niri.layout.outputs().find_map(|o| {
739738 let map = layer_map_for_output(o);
740739 let layer_surface = map.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)?;
@@ -814,6 +813,8 @@ impl State {
814813 if let InitialConfigureState::Configured { rules, .. } = &mut unmapped.state {
815814 *rules = resolve();
816815 }
816+ } else if let Some(mapped) = self.niri.layout.find_window_mut(toplevel.wl_surface()) {
817+ mapped.rules = resolve();
817818 }
818819 }
819820 }
src/input.rsmodified+14 -11
@@ -379,21 +379,24 @@ impl State {
379379 }
380380 Action::ScreenshotWindow => {
381381 let active = self.niri.layout.active_window();
382- if let Some((window, output)) = active {
382+ if let Some((mapped, output)) = active {
383383 self.backend.with_primary_renderer(|renderer| {
384- if let Err(err) = self.niri.screenshot_window(renderer, output, window) {
384+ if let Err(err) =
385+ self.niri
386+ .screenshot_window(renderer, output, &mapped.window)
387+ {
385388 warn!("error taking screenshot: {err:?}");
386389 }
387390 });
388391 }
389392 }
390393 Action::CloseWindow => {
391- if let Some(window) = self.niri.layout.focus() {
392- window.toplevel().expect("no x11 support").send_close();
394+ if let Some(mapped) = self.niri.layout.focus() {
395+ mapped.toplevel().send_close();
393396 }
394397 }
395398 Action::FullscreenWindow => {
396- let focus = self.niri.layout.focus().cloned();
399+ let focus = self.niri.layout.focus().map(|m| m.window.clone());
397400 if let Some(window) = focus {
398401 self.niri.layout.toggle_fullscreen(&window);
399402 // FIXME: granular
@@ -1017,8 +1020,8 @@ impl State {
10171020 let button_state = event.state();
10181021
10191022 if ButtonState::Pressed == button_state {
1020- if let Some(window) = self.niri.window_under_cursor() {
1021- let window = window.clone();
1023+ if let Some(mapped) = self.niri.window_under_cursor() {
1024+ let window = mapped.window.clone();
10221025 self.niri.layout.activate_window(&window);
10231026
10241027 // FIXME: granular.
@@ -1177,8 +1180,8 @@ impl State {
11771180 tool.tip_down(serial, event.time_msec());
11781181
11791182 if let Some(pos) = self.niri.tablet_cursor_location {
1180- if let Some(window) = self.niri.window_under(pos) {
1181- let window = window.clone();
1183+ if let Some(mapped) = self.niri.window_under(pos) {
1184+ let window = mapped.window.clone();
11821185 self.niri.layout.activate_window(&window);
11831186
11841187 // FIXME: granular.
@@ -1535,8 +1538,8 @@ impl State {
15351538 .output_under(touch_location)
15361539 .next()
15371540 .cloned();
1538- if let Some(window) = self.niri.window_under(touch_location) {
1539- let window = window.clone();
1541+ if let Some(mapped) = self.niri.window_under(touch_location) {
1542+ let window = mapped.window.clone();
15401543 self.niri.layout.activate_window(&window);
15411544
15421545 // FIXME: granular.
src/layout/mod.rsmodified+26 -151
@@ -38,21 +38,14 @@ use niri_config::{CenterFocusedColumn, Config, Struts};
3838 use niri_ipc::SizeChange;
3939 use smithay::backend::renderer::element::solid::SolidColorRenderElement;
4040 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
41-use smithay::backend::renderer::element::{AsRenderElements, Id};
42-use smithay::desktop::space::SpaceElement;
43-use smithay::desktop::Window;
41+use smithay::backend::renderer::element::Id;
4442 use smithay::output::Output;
45-use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
46-use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
4743 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
48-use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform};
49-use smithay::wayland::compositor::{send_surface_state, with_states};
50-use smithay::wayland::shell::xdg::SurfaceCachedState;
44+use smithay::utils::{Logical, Point, Scale, Size, Transform};
5145
5246 use self::monitor::Monitor;
5347 pub use self::monitor::MonitorRenderElement;
5448 use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Workspace};
55-use crate::niri::WindowOffscreenId;
5649 use crate::niri_render_elements;
5750 use crate::render_helpers::renderer::NiriRenderer;
5851 use crate::utils::output_size;
@@ -229,148 +222,6 @@ impl Options {
229222 }
230223 }
231224
232-impl LayoutElement for Window {
233- type Id = Self;
234-
235- fn id(&self) -> &Self::Id {
236- self
237- }
238-
239- fn size(&self) -> Size<i32, Logical> {
240- self.geometry().size
241- }
242-
243- fn buf_loc(&self) -> Point<i32, Logical> {
244- Point::from((0, 0)) - self.geometry().loc
245- }
246-
247- fn is_in_input_region(&self, point: Point<f64, Logical>) -> bool {
248- let surface_local = point + self.geometry().loc.to_f64();
249- SpaceElement::is_in_input_region(self, &surface_local)
250- }
251-
252- fn render<R: NiriRenderer>(
253- &self,
254- renderer: &mut R,
255- location: Point<i32, Logical>,
256- scale: Scale<f64>,
257- ) -> Vec<LayoutElementRenderElement<R>> {
258- let buf_pos = location - self.geometry().loc;
259- self.render_elements(
260- renderer,
261- buf_pos.to_physical_precise_round(scale),
262- scale,
263- 1.,
264- )
265- }
266-
267- fn request_size(&self, size: Size<i32, Logical>) {
268- self.toplevel()
269- .expect("no x11 support")
270- .with_pending_state(|state| {
271- state.size = Some(size);
272- state.states.unset(xdg_toplevel::State::Fullscreen);
273- });
274- }
275-
276- fn request_fullscreen(&self, size: Size<i32, Logical>) {
277- self.toplevel()
278- .expect("no x11 support")
279- .with_pending_state(|state| {
280- state.size = Some(size);
281- state.states.set(xdg_toplevel::State::Fullscreen);
282- });
283- }
284-
285- fn min_size(&self) -> Size<i32, Logical> {
286- with_states(
287- self.toplevel().expect("no x11 support").wl_surface(),
288- |state| {
289- let curr = state.cached_state.current::<SurfaceCachedState>();
290- curr.min_size
291- },
292- )
293- }
294-
295- fn max_size(&self) -> Size<i32, Logical> {
296- with_states(
297- self.toplevel().expect("no x11 support").wl_surface(),
298- |state| {
299- let curr = state.cached_state.current::<SurfaceCachedState>();
300- curr.max_size
301- },
302- )
303- }
304-
305- fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool {
306- self.toplevel().expect("no x11 support").wl_surface() == wl_surface
307- }
308-
309- fn set_preferred_scale_transform(&self, scale: i32, transform: Transform) {
310- self.with_surfaces(|surface, data| {
311- send_surface_state(surface, data, scale, transform);
312- });
313- }
314-
315- fn has_ssd(&self) -> bool {
316- self.toplevel()
317- .expect("no x11 support")
318- .current_state()
319- .decoration_mode
320- == Some(zxdg_toplevel_decoration_v1::Mode::ServerSide)
321- }
322-
323- fn output_enter(&self, output: &Output) {
324- let overlap = Rectangle::from_loc_and_size((0, 0), (i32::MAX, i32::MAX));
325- SpaceElement::output_enter(self, output, overlap)
326- }
327-
328- fn output_leave(&self, output: &Output) {
329- SpaceElement::output_leave(self, output)
330- }
331-
332- fn set_offscreen_element_id(&self, id: Option<Id>) {
333- let data = self.user_data().get_or_insert(WindowOffscreenId::default);
334- data.0.replace(id);
335- }
336-
337- fn set_activated(&self, active: bool) {
338- Window::set_activated(self, active);
339- }
340-
341- fn set_bounds(&self, bounds: Size<i32, Logical>) {
342- self.toplevel()
343- .expect("no x11 support")
344- .with_pending_state(|state| {
345- state.bounds = Some(bounds);
346- });
347- }
348-
349- fn send_pending_configure(&self) {
350- self.toplevel()
351- .expect("no x11 support")
352- .send_pending_configure();
353- }
354-
355- fn is_fullscreen(&self) -> bool {
356- self.toplevel()
357- .expect("no x11 support")
358- .current_state()
359- .states
360- .contains(xdg_toplevel::State::Fullscreen)
361- }
362-
363- fn is_pending_fullscreen(&self) -> bool {
364- self.toplevel()
365- .expect("no x11 support")
366- .with_pending_state(|state| state.states.contains(xdg_toplevel::State::Fullscreen))
367- }
368-
369- fn refresh(&self) {
370- SpaceElement::refresh(self)
371- }
372-}
373-
374225 impl<W: LayoutElement> Layout<W> {
375226 pub fn new(config: &Config) -> Self {
376227 Self::with_options(Options::from_config(config))
@@ -792,6 +643,29 @@ impl<W: LayoutElement> Layout<W> {
792643 }
793644 }
794645
646+ pub fn find_window_mut(&mut self, wl_surface: &WlSurface) -> Option<&mut W> {
647+ match &mut self.monitor_set {
648+ MonitorSet::Normal { monitors, .. } => {
649+ for mon in monitors {
650+ for ws in &mut mon.workspaces {
651+ if let Some(window) = ws.find_wl_surface_mut(wl_surface) {
652+ return Some(window);
653+ }
654+ }
655+ }
656+ }
657+ MonitorSet::NoOutputs { workspaces } => {
658+ for ws in workspaces {
659+ if let Some(window) = ws.find_wl_surface_mut(wl_surface) {
660+ return Some(window);
661+ }
662+ }
663+ }
664+ }
665+
666+ None
667+ }
668+
795669 pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> {
796670 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
797671 for mon in monitors {
@@ -1866,6 +1740,7 @@ mod tests {
18661740 use proptest::prelude::*;
18671741 use proptest_derive::Arbitrary;
18681742 use smithay::output::{Mode, PhysicalProperties, Subpixel};
1743+ use smithay::utils::Rectangle;
18691744
18701745 use super::*;
18711746
src/layout/tile.rsmodified+4 -0
@@ -121,6 +121,10 @@ impl<W: LayoutElement> Tile<W> {
121121 &self.window
122122 }
123123
124+ pub fn window_mut(&mut self) -> &mut W {
125+ &mut self.window
126+ }
127+
124128 pub fn into_window(self) -> W {
125129 self.window
126130 }
src/layout/workspace.rsmodified+17 -1
@@ -10,6 +10,7 @@ use smithay::output::Output;
1010 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
1111 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
1212 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
13+use smithay::wayland::compositor::send_surface_state;
1314
1415 use super::tile::{Tile, TileRenderElement};
1516 use super::{LayoutElement, Options};
@@ -299,6 +300,13 @@ impl<W: LayoutElement> Workspace<W> {
299300 .map(Tile::window)
300301 }
301302
303+ pub fn windows_mut(&mut self) -> impl Iterator<Item = &mut W> + '_ {
304+ self.columns
305+ .iter_mut()
306+ .flat_map(|col| col.tiles.iter_mut())
307+ .map(Tile::window_mut)
308+ }
309+
302310 pub fn set_output(&mut self, output: Option<Output>) {
303311 if self.output == output {
304312 return;
@@ -407,7 +415,11 @@ impl<W: LayoutElement> Workspace<W> {
407415
408416 pub fn configure_new_window(&self, window: &Window, width: Option<ColumnWidth>) {
409417 if let Some(output) = self.output.as_ref() {
410- set_preferred_scale_transform(window, output);
418+ let scale = output.current_scale().integer_scale();
419+ let transform = output.current_transform();
420+ window.with_surfaces(|surface, data| {
421+ send_surface_state(surface, data, scale, transform);
422+ });
411423 }
412424
413425 window
@@ -584,6 +596,10 @@ impl<W: LayoutElement> Workspace<W> {
584596 self.windows().find(|win| win.is_wl_surface(wl_surface))
585597 }
586598
599+ pub fn find_wl_surface_mut(&mut self, wl_surface: &WlSurface) -> Option<&mut W> {
600+ self.windows_mut().find(|win| win.is_wl_surface(wl_surface))
601+ }
602+
587603 /// Computes the X position of the windows in the given column, in logical coordinates.
588604 fn column_x(&self, column_idx: usize) -> i32 {
589605 let mut x = 0;
src/niri.rsmodified+17 -15
@@ -114,7 +114,7 @@ use crate::utils::spawning::CHILD_ENV;
114114 use crate::utils::{
115115 center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8,
116116 };
117-use crate::window::Unmapped;
117+use crate::window::{Mapped, Unmapped};
118118 use crate::{animation, niri_render_elements};
119119
120120 const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];
@@ -138,7 +138,7 @@ pub struct Niri {
138138
139139 // Each workspace corresponds to a Space. Each workspace generally has one Output mapped to it,
140140 // however it may have none (when there are no outputs connected) or mutiple (when mirroring).
141- pub layout: Layout<Window>,
141+ pub layout: Layout<Mapped>,
142142
143143 // This space does not actually contain any windows, but all outputs are mapped into it
144144 // according to their global position.
@@ -631,7 +631,7 @@ impl State {
631631 self.niri
632632 .layout
633633 .focus()
634- .map(|win| win.toplevel().expect("no x11 support").wl_surface().clone())
634+ .map(|win| win.toplevel().wl_surface().clone())
635635 .map(|surface| KeyboardFocus::Layout {
636636 surface: Some(surface),
637637 })
@@ -1591,7 +1591,7 @@ impl Niri {
15911591 ///
15921592 /// The cursor may be inside the window's activation region, but not within the window's input
15931593 /// region.
1594- pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<&Window> {
1594+ pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<&Mapped> {
15951595 if self.is_locked() || self.screenshot_ui.is_open() {
15961596 return None;
15971597 }
@@ -1618,7 +1618,7 @@ impl Niri {
16181618 ///
16191619 /// The cursor may be inside the window's activation region, but not within the window's input
16201620 /// region.
1621- pub fn window_under_cursor(&self) -> Option<&Window> {
1621+ pub fn window_under_cursor(&self) -> Option<&Mapped> {
16221622 let pos = self.seat.get_pointer().unwrap().current_location();
16231623 self.window_under(pos)
16241624 }
@@ -1684,8 +1684,9 @@ impl Niri {
16841684 let window_under = || {
16851685 self.layout
16861686 .window_under(output, pos_within_output)
1687- .and_then(|(window, win_pos_within_output)| {
1687+ .and_then(|(mapped, win_pos_within_output)| {
16881688 let win_pos_within_output = win_pos_within_output?;
1689+ let window = &mapped.window;
16891690 window
16901691 .surface_under(
16911692 pos_within_output - win_pos_within_output.to_f64(),
@@ -2409,7 +2410,8 @@ impl Niri {
24092410 // The reason to do this at all is that it keeps track of whether the surface is visible or
24102411 // not in a unified way with the pointer surfaces, which makes the logic elsewhere simpler.
24112412
2412- for win in self.layout.windows_for_output(output) {
2413+ for mapped in self.layout.windows_for_output(output) {
2414+ let win = &mapped.window;
24132415 let offscreen_id = win
24142416 .user_data()
24152417 .get_or_insert(WindowOffscreenId::default)
@@ -2480,8 +2482,8 @@ impl Niri {
24802482 // We can unconditionally send the current output's feedback to regular and layer-shell
24812483 // surfaces, as they can only be displayed on a single output at a time. Even if a surface
24822484 // is currently invisible, this is the DMABUF feedback that it should know about.
2483- for win in self.layout.windows_for_output(output) {
2484- win.send_dmabuf_feedback(
2485+ for mapped in self.layout.windows_for_output(output) {
2486+ mapped.window.send_dmabuf_feedback(
24852487 output,
24862488 |_, _| Some(output.clone()),
24872489 |surface, _| {
@@ -2600,8 +2602,8 @@ impl Niri {
26002602
26012603 let frame_callback_time = get_monotonic_time();
26022604
2603- for win in self.layout.windows_for_output(output) {
2604- win.send_frame(
2605+ for mapped in self.layout.windows_for_output(output) {
2606+ mapped.window.send_frame(
26052607 output,
26062608 frame_callback_time,
26072609 FRAME_CALLBACK_THROTTLE,
@@ -2666,8 +2668,8 @@ impl Niri {
26662668
26672669 let frame_callback_time = get_monotonic_time();
26682670
2669- self.layout.with_windows(|win, _| {
2670- win.send_frame(
2671+ self.layout.with_windows(|mapped, _| {
2672+ mapped.window.send_frame(
26712673 output,
26722674 frame_callback_time,
26732675 FRAME_CALLBACK_THROTTLE,
@@ -2746,8 +2748,8 @@ impl Niri {
27462748 );
27472749 }
27482750
2749- for win in self.layout.windows_for_output(output) {
2750- win.take_presentation_feedback(
2751+ for mapped in self.layout.windows_for_output(output) {
2752+ mapped.window.take_presentation_feedback(
27512753 &mut feedback,
27522754 surface_primary_scanout_output,
27532755 |surface, _| {
src/protocols/foreign_toplevel.rsmodified+3 -3
@@ -95,8 +95,8 @@ pub fn refresh(state: &mut State) {
9595 // Save the focused window for last, this way when the focus changes, we will first deactivate
9696 // the previous window and only then activate the newly focused window.
9797 let mut focused = None;
98- state.niri.layout.with_windows(|window, output| {
99- let wl_surface = window.toplevel().expect("no x11 support").wl_surface();
98+ state.niri.layout.with_windows(|mapped, output| {
99+ let wl_surface = mapped.toplevel().wl_surface();
100100
101101 with_states(wl_surface, |states| {
102102 let role = states
@@ -107,7 +107,7 @@ pub fn refresh(state: &mut State) {
107107 .unwrap();
108108
109109 if state.niri.keyboard_focus.surface() == Some(wl_surface) {
110- focused = Some((window.clone(), output.cloned()));
110+ focused = Some((mapped.window.clone(), output.cloned()));
111111 } else {
112112 refresh_toplevel(protocol_state, wl_surface, &role, output, false);
113113 }
src/utils/mod.rsmodified+0 -4
@@ -20,10 +20,6 @@ pub mod watcher;
2020
2121 pub static IS_SYSTEMD_SERVICE: AtomicBool = AtomicBool::new(false);
2222
23-pub fn clone2<T: Clone, U: Clone>(t: (&T, &U)) -> (T, U) {
24- (t.0.clone(), t.1.clone())
25-}
26-
2723 pub fn version() -> String {
2824 format!(
2925 "{} ({})",
src/window/mapped.rsadded+159 -0
@@ -0,0 +1,159 @@
1+use smithay::backend::renderer::element::{AsRenderElements as _, Id};
2+use smithay::desktop::space::SpaceElement as _;
3+use smithay::desktop::Window;
4+use smithay::output::Output;
5+use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
6+use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
7+use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
8+use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform};
9+use smithay::wayland::compositor::{send_surface_state, with_states};
10+use smithay::wayland::shell::xdg::{SurfaceCachedState, ToplevelSurface};
11+
12+use super::ResolvedWindowRules;
13+use crate::layout::{LayoutElement, LayoutElementRenderElement};
14+use crate::niri::WindowOffscreenId;
15+use crate::render_helpers::renderer::NiriRenderer;
16+
17+#[derive(Debug)]
18+pub struct Mapped {
19+ pub window: Window,
20+
21+ /// Up-to-date rules.
22+ pub rules: ResolvedWindowRules,
23+}
24+
25+impl Mapped {
26+ pub fn new(window: Window, rules: ResolvedWindowRules) -> Self {
27+ Self { window, rules }
28+ }
29+
30+ pub fn toplevel(&self) -> &ToplevelSurface {
31+ self.window.toplevel().expect("no X11 support")
32+ }
33+}
34+
35+impl LayoutElement for Mapped {
36+ type Id = Window;
37+
38+ fn id(&self) -> &Self::Id {
39+ &self.window
40+ }
41+
42+ fn size(&self) -> Size<i32, Logical> {
43+ self.window.geometry().size
44+ }
45+
46+ fn buf_loc(&self) -> Point<i32, Logical> {
47+ Point::from((0, 0)) - self.window.geometry().loc
48+ }
49+
50+ fn is_in_input_region(&self, point: Point<f64, Logical>) -> bool {
51+ let surface_local = point + self.window.geometry().loc.to_f64();
52+ self.window.is_in_input_region(&surface_local)
53+ }
54+
55+ fn render<R: NiriRenderer>(
56+ &self,
57+ renderer: &mut R,
58+ location: Point<i32, Logical>,
59+ scale: Scale<f64>,
60+ ) -> Vec<LayoutElementRenderElement<R>> {
61+ let buf_pos = location - self.window.geometry().loc;
62+ self.window.render_elements(
63+ renderer,
64+ buf_pos.to_physical_precise_round(scale),
65+ scale,
66+ 1.,
67+ )
68+ }
69+
70+ fn request_size(&self, size: Size<i32, Logical>) {
71+ self.toplevel().with_pending_state(|state| {
72+ state.size = Some(size);
73+ state.states.unset(xdg_toplevel::State::Fullscreen);
74+ });
75+ }
76+
77+ fn request_fullscreen(&self, size: Size<i32, Logical>) {
78+ self.toplevel().with_pending_state(|state| {
79+ state.size = Some(size);
80+ state.states.set(xdg_toplevel::State::Fullscreen);
81+ });
82+ }
83+
84+ fn min_size(&self) -> Size<i32, Logical> {
85+ with_states(self.toplevel().wl_surface(), |state| {
86+ let curr = state.cached_state.current::<SurfaceCachedState>();
87+ curr.min_size
88+ })
89+ }
90+
91+ fn max_size(&self) -> Size<i32, Logical> {
92+ with_states(self.toplevel().wl_surface(), |state| {
93+ let curr = state.cached_state.current::<SurfaceCachedState>();
94+ curr.max_size
95+ })
96+ }
97+
98+ fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool {
99+ self.toplevel().wl_surface() == wl_surface
100+ }
101+
102+ fn set_preferred_scale_transform(&self, scale: i32, transform: Transform) {
103+ self.window.with_surfaces(|surface, data| {
104+ send_surface_state(surface, data, scale, transform);
105+ });
106+ }
107+
108+ fn has_ssd(&self) -> bool {
109+ self.toplevel().current_state().decoration_mode
110+ == Some(zxdg_toplevel_decoration_v1::Mode::ServerSide)
111+ }
112+
113+ fn output_enter(&self, output: &Output) {
114+ let overlap = Rectangle::from_loc_and_size((0, 0), (i32::MAX, i32::MAX));
115+ self.window.output_enter(output, overlap)
116+ }
117+
118+ fn output_leave(&self, output: &Output) {
119+ self.window.output_leave(output)
120+ }
121+
122+ fn set_offscreen_element_id(&self, id: Option<Id>) {
123+ let data = self
124+ .window
125+ .user_data()
126+ .get_or_insert(WindowOffscreenId::default);
127+ data.0.replace(id);
128+ }
129+
130+ fn set_activated(&self, active: bool) {
131+ self.window.set_activated(active);
132+ }
133+
134+ fn set_bounds(&self, bounds: Size<i32, Logical>) {
135+ self.toplevel().with_pending_state(|state| {
136+ state.bounds = Some(bounds);
137+ });
138+ }
139+
140+ fn send_pending_configure(&self) {
141+ self.toplevel().send_pending_configure();
142+ }
143+
144+ fn is_fullscreen(&self) -> bool {
145+ self.toplevel()
146+ .current_state()
147+ .states
148+ .contains(xdg_toplevel::State::Fullscreen)
149+ }
150+
151+ fn is_pending_fullscreen(&self) -> bool {
152+ self.toplevel()
153+ .with_pending_state(|state| state.states.contains(xdg_toplevel::State::Fullscreen))
154+ }
155+
156+ fn refresh(&self) {
157+ self.window.refresh();
158+ }
159+}
src/window/mod.rsmodified+3 -0
@@ -1,5 +1,8 @@
11 use crate::layout::workspace::ColumnWidth;
22
3+pub mod mapped;
4+pub use mapped::Mapped;
5+
36 pub mod unmapped;
47 pub use unmapped::{InitialConfigureState, Unmapped};
58