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};
17 use smithay::{delegate_compositor, delegate_shm};17 use smithay::{delegate_compositor, delegate_shm};
18 18
19 use crate::niri::{ClientState, State};19 use crate::niri::{ClientState, State};
20-use crate::utils::clone2;20+use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped};
21-use crate::window::{InitialConfigureState, Unmapped};
22 21
23 impl CompositorHandler for State {22 impl CompositorHandler for State {
24 fn compositor_state(&mut self) -> &mut CompositorState {23 fn compositor_state(&mut self) -> &mut CompositorState {
@@ -109,22 +108,22 @@ impl CompositorHandler for State {
109 108
110 window.on_commit();109 window.on_commit();
111 110
112- let (width, is_full_width, output) =111+ let (rules, width, is_full_width, output) =
113 if let InitialConfigureState::Configured {112 if let InitialConfigureState::Configured {
113+ rules,
114 width,114 width,
115 is_full_width,115 is_full_width,
116 output,116 output,
117- ..
118 } = state117 } = state
119 {118 {
120 // Check that the output is still connected.119 // Check that the output is still connected.
121 let output =120 let output =
122 output.filter(|o| self.niri.layout.monitor_for_output(o).is_some());121 output.filter(|o| self.niri.layout.monitor_for_output(o).is_some());
123 122
124- (width, is_full_width, output)123+ (rules, width, is_full_width, output)
125 } else {124 } else {
126 error!("window map must happen after initial configure");125 error!("window map must happen after initial configure");
127- (None, false, None)126+ (ResolvedWindowRules::default(), None, false, None)
128 };127 };
129 128
130 let parent = window129 let parent = window
@@ -141,29 +140,30 @@ impl CompositorHandler for State {
141 .filter(|(_, parent_output)| {140 .filter(|(_, parent_output)| {
142 output.is_none() || output.as_ref() == Some(*parent_output)141 output.is_none() || output.as_ref() == Some(*parent_output)
143 })142 })
144- .map(|(window, _)| window.clone());143+ .map(|(mapped, _)| mapped.window.clone());
145 144
146- let window = window.clone();145+ let mapped = Mapped::new(window, rules);
147- let win = window.clone();146+ let window = mapped.window.clone();
148 147
149 let output = if let Some(p) = parent {148 let output = if let Some(p) = parent {
150 // Open dialogs immediately to the right of their parent window.149 // Open dialogs immediately to the right of their parent window.
151 self.niri150 self.niri
152 .layout151 .layout
153- .add_window_right_of(&p, win, width, is_full_width)152+ .add_window_right_of(&p, mapped, width, is_full_width)
154 } else if let Some(output) = &output {153 } else if let Some(output) = &output {
155 self.niri154 self.niri
156 .layout155 .layout
157- .add_window_on_output(output, win, width, is_full_width);156+ .add_window_on_output(output, mapped, width, is_full_width);
158 Some(output)157 Some(output)
159 } else {158 } else {
160- self.niri.layout.add_window(win, width, is_full_width)159+ self.niri.layout.add_window(mapped, width, is_full_width)
161 };160 };
162 161
163 if let Some(output) = output.cloned() {162 if let Some(output) = output.cloned() {
164 self.niri.layout.start_open_animation_for_window(&window);163 self.niri.layout.start_open_animation_for_window(&window);
165 164
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);
167 if new_active_window == Some(&window) {167 if new_active_window == Some(&window) {
168 self.maybe_warp_cursor_to_focus();168 self.maybe_warp_cursor_to_focus();
169 }169 }
@@ -183,8 +183,9 @@ impl CompositorHandler for State {
183 }183 }
184 184
185 // This is a commit of a previously-mapped root or a non-toplevel root.185 // 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) {186+ if let Some((mapped, output)) = self.niri.layout.find_window_and_output(surface) {
187- let (window, output) = clone2(win_out);187+ let window = mapped.window.clone();
188+ let output = output.clone();
188 189
189 window.on_commit();190 window.on_commit();
190 191
@@ -224,7 +225,9 @@ impl CompositorHandler for State {
224 225
225 // This is a commit of a non-root or a non-toplevel root.226 // This is a commit of a non-root or a non-toplevel root.
226 let root_window_output = self.niri.layout.find_window_and_output(&root_surface);227 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();
228 window.on_commit();231 window.on_commit();
229 self.niri.layout.update_window(&window);232 self.niri.layout.update_window(&window);
230 self.niri.queue_redraw(output);233 self.niri.queue_redraw(output);
src/handlers/mod.rsmodified+10 -11
@@ -144,7 +144,7 @@ impl InputMethodHandler for State {
144 self.niri144 self.niri
145 .layout145 .layout
146 .find_window_and_output(parent)146 .find_window_and_output(parent)
147- .map(|(window, _)| window.geometry())147+ .map(|(mapped, _)| mapped.window.geometry())
148 .unwrap_or_default()148 .unwrap_or_default()
149 }149 }
150 }150 }
@@ -333,25 +333,24 @@ impl ForeignToplevelHandler for State {
333 }333 }
334 334
335 fn activate(&mut self, wl_surface: WlSurface) {335 fn activate(&mut self, wl_surface: WlSurface) {
336- if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) {336+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
337- let window = window.clone();337+ let window = mapped.window.clone();
338 self.niri.layout.activate_window(&window);338 self.niri.layout.activate_window(&window);
339 self.niri.queue_redraw_all();339 self.niri.queue_redraw_all();
340 }340 }
341 }341 }
342 342
343 fn close(&mut self, wl_surface: WlSurface) {343 fn close(&mut self, wl_surface: WlSurface) {
344- if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) {344+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
345- window.toplevel().expect("no x11 support").send_close();345+ mapped.toplevel().send_close();
346 }346 }
347 }347 }
348 348
349 fn set_fullscreen(&mut self, wl_surface: WlSurface, wl_output: Option<WlOutput>) {349 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)
351 {351 {
352- if !window352+ if !mapped
353 .toplevel()353 .toplevel()
354- .expect("no x11 support")
355 .current_state()354 .current_state()
356 .capabilities355 .capabilities
357 .contains(xdg_toplevel::WmCapabilities::Fullscreen)356 .contains(xdg_toplevel::WmCapabilities::Fullscreen)
@@ -359,7 +358,7 @@ impl ForeignToplevelHandler for State {
359 return;358 return;
360 }359 }
361 360
362- let window = window.clone();361+ let window = mapped.window.clone();
363 362
364 if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {363 if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {
365 if &requested_output != current_output {364 if &requested_output != current_output {
@@ -374,8 +373,8 @@ impl ForeignToplevelHandler for State {
374 }373 }
375 374
376 fn unset_fullscreen(&mut self, wl_surface: WlSurface) {375 fn unset_fullscreen(&mut self, wl_surface: WlSurface) {
377- if let Some((window, _)) = self.niri.layout.find_window_and_output(&wl_surface) {376+ if let Some((mapped, _)) = self.niri.layout.find_window_and_output(&wl_surface) {
378- let window = window.clone();377+ let window = mapped.window.clone();
379 self.niri.layout.set_fullscreen(&window, false);378 self.niri.layout.set_fullscreen(&window, false);
380 }379 }
381 }380 }
src/handlers/xdg_shell.rsmodified+13 -12
@@ -29,7 +29,6 @@ use smithay::{
29 29
30 use crate::layout::workspace::ColumnWidth;30 use crate::layout::workspace::ColumnWidth;
31 use crate::niri::{PopupGrabState, State};31 use crate::niri::{PopupGrabState, State};
32-use crate::utils::clone2;
33 use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped};32 use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped};
34 33
35 fn window_matches(role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool {34 fn window_matches(role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool {
@@ -213,9 +212,7 @@ impl XdgShellHandler for State {
213 }212 }
214 213
215 let layout_focus = self.niri.layout.focus();214 let layout_focus = self.niri.layout.focus();
216- if Some(&root)215+ if Some(&root) != layout_focus.map(|win| win.toplevel().wl_surface()) {
217- != layout_focus.map(|win| win.toplevel().expect("no x11 support").wl_surface())
218- {
219 let _ = PopupManager::dismiss_popup(&root, &popup);216 let _ = PopupManager::dismiss_popup(&root, &popup);
220 return;217 return;
221 }218 }
@@ -278,12 +275,12 @@ impl XdgShellHandler for State {
278 ) {275 ) {
279 let requested_output = wl_output.as_ref().and_then(Output::from_resource);276 let requested_output = wl_output.as_ref().and_then(Output::from_resource);
280 277
281- if let Some((window, current_output)) = self278+ if let Some((mapped, current_output)) = self
282 .niri279 .niri
283 .layout280 .layout
284 .find_window_and_output(toplevel.wl_surface())281 .find_window_and_output(toplevel.wl_surface())
285 {282 {
286- let window = window.clone();283+ let window = mapped.window.clone();
287 284
288 if let Some(requested_output) = requested_output {285 if let Some(requested_output) = requested_output {
289 if &requested_output != current_output {286 if &requested_output != current_output {
@@ -358,12 +355,12 @@ impl XdgShellHandler for State {
358 }355 }
359 356
360 fn unfullscreen_request(&mut self, toplevel: ToplevelSurface) {357 fn unfullscreen_request(&mut self, toplevel: ToplevelSurface) {
361- if let Some((window, _)) = self358+ if let Some((mapped, _)) = self
362 .niri359 .niri
363 .layout360 .layout
364 .find_window_and_output(toplevel.wl_surface())361 .find_window_and_output(toplevel.wl_surface())
365 {362 {
366- let window = window.clone();363+ let window = mapped.window.clone();
367 self.niri.layout.set_fullscreen(&window, false);364 self.niri.layout.set_fullscreen(&window, false);
368 365
369 // A configure is required in response to this event regardless if there are pending366 // A configure is required in response to this event regardless if there are pending
@@ -453,14 +450,16 @@ impl XdgShellHandler for State {
453 .layout450 .layout
454 .find_window_and_output(surface.wl_surface());451 .find_window_and_output(surface.wl_surface());
455 452
456- let Some((window, output)) = win_out.map(clone2) else {453+ let Some((mapped, output)) = win_out else {
457 // I have no idea how this can happen, but I saw it happen once, in a weird interaction454 // I have no idea how this can happen, but I saw it happen once, in a weird interaction
458 // involving laptop going to sleep and resuming.455 // involving laptop going to sleep and resuming.
459 error!("toplevel missing from both unmapped_windows and layout");456 error!("toplevel missing from both unmapped_windows and layout");
460 return;457 return;
461 };458 };
459+ let window = mapped.window.clone();
460+ let output = output.clone();
462 461
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);
464 let was_active = active_window == Some(&window);463 let was_active = active_window == Some(&window);
465 464
466 self.niri.layout.remove_window(&window);465 self.niri.layout.remove_window(&window);
@@ -733,8 +732,8 @@ impl State {
733 };732 };
734 733
735 // Figure out if the root is a window or a layer surface.734 // 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) {735+ if let Some((mapped, output)) = self.niri.layout.find_window_and_output(&root) {
737- self.unconstrain_window_popup(popup, window, output);736+ self.unconstrain_window_popup(popup, &mapped.window, output);
738 } else if let Some((layer_surface, output)) = self.niri.layout.outputs().find_map(|o| {737 } else if let Some((layer_surface, output)) = self.niri.layout.outputs().find_map(|o| {
739 let map = layer_map_for_output(o);738 let map = layer_map_for_output(o);
740 let layer_surface = map.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)?;739 let layer_surface = map.layer_for_surface(&root, WindowSurfaceType::TOPLEVEL)?;
@@ -814,6 +813,8 @@ impl State {
814 if let InitialConfigureState::Configured { rules, .. } = &mut unmapped.state {813 if let InitialConfigureState::Configured { rules, .. } = &mut unmapped.state {
815 *rules = resolve();814 *rules = resolve();
816 }815 }
816+ } else if let Some(mapped) = self.niri.layout.find_window_mut(toplevel.wl_surface()) {
817+ mapped.rules = resolve();
817 }818 }
818 }819 }
819 }820 }
src/input.rsmodified+14 -11
@@ -379,21 +379,24 @@ impl State {
379 }379 }
380 Action::ScreenshotWindow => {380 Action::ScreenshotWindow => {
381 let active = self.niri.layout.active_window();381 let active = self.niri.layout.active_window();
382- if let Some((window, output)) = active {382+ if let Some((mapped, output)) = active {
383 self.backend.with_primary_renderer(|renderer| {383 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+ {
385 warn!("error taking screenshot: {err:?}");388 warn!("error taking screenshot: {err:?}");
386 }389 }
387 });390 });
388 }391 }
389 }392 }
390 Action::CloseWindow => {393 Action::CloseWindow => {
391- if let Some(window) = self.niri.layout.focus() {394+ if let Some(mapped) = self.niri.layout.focus() {
392- window.toplevel().expect("no x11 support").send_close();395+ mapped.toplevel().send_close();
393 }396 }
394 }397 }
395 Action::FullscreenWindow => {398 Action::FullscreenWindow => {
396- let focus = self.niri.layout.focus().cloned();399+ let focus = self.niri.layout.focus().map(|m| m.window.clone());
397 if let Some(window) = focus {400 if let Some(window) = focus {
398 self.niri.layout.toggle_fullscreen(&window);401 self.niri.layout.toggle_fullscreen(&window);
399 // FIXME: granular402 // FIXME: granular
@@ -1017,8 +1020,8 @@ impl State {
1017 let button_state = event.state();1020 let button_state = event.state();
1018 1021
1019 if ButtonState::Pressed == button_state {1022 if ButtonState::Pressed == button_state {
1020- if let Some(window) = self.niri.window_under_cursor() {1023+ if let Some(mapped) = self.niri.window_under_cursor() {
1021- let window = window.clone();1024+ let window = mapped.window.clone();
1022 self.niri.layout.activate_window(&window);1025 self.niri.layout.activate_window(&window);
1023 1026
1024 // FIXME: granular.1027 // FIXME: granular.
@@ -1177,8 +1180,8 @@ impl State {
1177 tool.tip_down(serial, event.time_msec());1180 tool.tip_down(serial, event.time_msec());
1178 1181
1179 if let Some(pos) = self.niri.tablet_cursor_location {1182 if let Some(pos) = self.niri.tablet_cursor_location {
1180- if let Some(window) = self.niri.window_under(pos) {1183+ if let Some(mapped) = self.niri.window_under(pos) {
1181- let window = window.clone();1184+ let window = mapped.window.clone();
1182 self.niri.layout.activate_window(&window);1185 self.niri.layout.activate_window(&window);
1183 1186
1184 // FIXME: granular.1187 // FIXME: granular.
@@ -1535,8 +1538,8 @@ impl State {
1535 .output_under(touch_location)1538 .output_under(touch_location)
1536 .next()1539 .next()
1537 .cloned();1540 .cloned();
1538- if let Some(window) = self.niri.window_under(touch_location) {1541+ if let Some(mapped) = self.niri.window_under(touch_location) {
1539- let window = window.clone();1542+ let window = mapped.window.clone();
1540 self.niri.layout.activate_window(&window);1543 self.niri.layout.activate_window(&window);
1541 1544
1542 // FIXME: granular.1545 // FIXME: granular.
src/layout/mod.rsmodified+26 -151
@@ -38,21 +38,14 @@ use niri_config::{CenterFocusedColumn, Config, Struts};
38 use niri_ipc::SizeChange;38 use niri_ipc::SizeChange;
39 use smithay::backend::renderer::element::solid::SolidColorRenderElement;39 use smithay::backend::renderer::element::solid::SolidColorRenderElement;
40 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;40 use smithay::backend::renderer::element::surface::WaylandSurfaceRenderElement;
41-use smithay::backend::renderer::element::{AsRenderElements, Id};41+use smithay::backend::renderer::element::Id;
42-use smithay::desktop::space::SpaceElement;
43-use smithay::desktop::Window;
44 use smithay::output::Output;42 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;
47 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;43 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
48-use smithay::utils::{Logical, Point, Rectangle, Scale, Size, Transform};44+use smithay::utils::{Logical, Point, Scale, Size, Transform};
49-use smithay::wayland::compositor::{send_surface_state, with_states};
50-use smithay::wayland::shell::xdg::SurfaceCachedState;
51 45
52 use self::monitor::Monitor;46 use self::monitor::Monitor;
53 pub use self::monitor::MonitorRenderElement;47 pub use self::monitor::MonitorRenderElement;
54 use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Workspace};48 use self::workspace::{compute_working_area, Column, ColumnWidth, OutputId, Workspace};
55-use crate::niri::WindowOffscreenId;
56 use crate::niri_render_elements;49 use crate::niri_render_elements;
57 use crate::render_helpers::renderer::NiriRenderer;50 use crate::render_helpers::renderer::NiriRenderer;
58 use crate::utils::output_size;51 use crate::utils::output_size;
@@ -229,148 +222,6 @@ impl Options {
229 }222 }
230 }223 }
231 224
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-
374 impl<W: LayoutElement> Layout<W> {225 impl<W: LayoutElement> Layout<W> {
375 pub fn new(config: &Config) -> Self {226 pub fn new(config: &Config) -> Self {
376 Self::with_options(Options::from_config(config))227 Self::with_options(Options::from_config(config))
@@ -792,6 +643,29 @@ impl<W: LayoutElement> Layout<W> {
792 }643 }
793 }644 }
794 645
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+
795 pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> {669 pub fn find_window_and_output(&self, wl_surface: &WlSurface) -> Option<(&W, &Output)> {
796 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {670 if let MonitorSet::Normal { monitors, .. } = &self.monitor_set {
797 for mon in monitors {671 for mon in monitors {
@@ -1866,6 +1740,7 @@ mod tests {
1866 use proptest::prelude::*;1740 use proptest::prelude::*;
1867 use proptest_derive::Arbitrary;1741 use proptest_derive::Arbitrary;
1868 use smithay::output::{Mode, PhysicalProperties, Subpixel};1742 use smithay::output::{Mode, PhysicalProperties, Subpixel};
1743+ use smithay::utils::Rectangle;
1869 1744
1870 use super::*;1745 use super::*;
1871 1746
src/layout/tile.rsmodified+4 -0
@@ -121,6 +121,10 @@ impl<W: LayoutElement> Tile<W> {
121 &self.window121 &self.window
122 }122 }
123 123
124+ pub fn window_mut(&mut self) -> &mut W {
125+ &mut self.window
126+ }
127+
124 pub fn into_window(self) -> W {128 pub fn into_window(self) -> W {
125 self.window129 self.window
126 }130 }
src/layout/workspace.rsmodified+17 -1
@@ -10,6 +10,7 @@ use smithay::output::Output;
10 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;10 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
11 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;11 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
12 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};12 use smithay::utils::{Logical, Point, Rectangle, Scale, Size};
13+use smithay::wayland::compositor::send_surface_state;
13 14
14 use super::tile::{Tile, TileRenderElement};15 use super::tile::{Tile, TileRenderElement};
15 use super::{LayoutElement, Options};16 use super::{LayoutElement, Options};
@@ -299,6 +300,13 @@ impl<W: LayoutElement> Workspace<W> {
299 .map(Tile::window)300 .map(Tile::window)
300 }301 }
301 302
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+
302 pub fn set_output(&mut self, output: Option<Output>) {310 pub fn set_output(&mut self, output: Option<Output>) {
303 if self.output == output {311 if self.output == output {
304 return;312 return;
@@ -407,7 +415,11 @@ impl<W: LayoutElement> Workspace<W> {
407 415
408 pub fn configure_new_window(&self, window: &Window, width: Option<ColumnWidth>) {416 pub fn configure_new_window(&self, window: &Window, width: Option<ColumnWidth>) {
409 if let Some(output) = self.output.as_ref() {417 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+ });
411 }423 }
412 424
413 window425 window
@@ -584,6 +596,10 @@ impl<W: LayoutElement> Workspace<W> {
584 self.windows().find(|win| win.is_wl_surface(wl_surface))596 self.windows().find(|win| win.is_wl_surface(wl_surface))
585 }597 }
586 598
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+
587 /// Computes the X position of the windows in the given column, in logical coordinates.603 /// Computes the X position of the windows in the given column, in logical coordinates.
588 fn column_x(&self, column_idx: usize) -> i32 {604 fn column_x(&self, column_idx: usize) -> i32 {
589 let mut x = 0;605 let mut x = 0;
src/niri.rsmodified+17 -15
@@ -114,7 +114,7 @@ use crate::utils::spawning::CHILD_ENV;
114 use crate::utils::{114 use crate::utils::{
115 center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8,115 center, center_f64, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8,
116 };116 };
117-use crate::window::Unmapped;117+use crate::window::{Mapped, Unmapped};
118 use crate::{animation, niri_render_elements};118 use crate::{animation, niri_render_elements};
119 119
120 const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];120 const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];
@@ -138,7 +138,7 @@ pub struct Niri {
138 138
139 // Each workspace corresponds to a Space. Each workspace generally has one Output mapped to it,139 // Each workspace corresponds to a Space. Each workspace generally has one Output mapped to it,
140 // however it may have none (when there are no outputs connected) or mutiple (when mirroring).140 // 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>,
142 142
143 // This space does not actually contain any windows, but all outputs are mapped into it143 // This space does not actually contain any windows, but all outputs are mapped into it
144 // according to their global position.144 // according to their global position.
@@ -631,7 +631,7 @@ impl State {
631 self.niri631 self.niri
632 .layout632 .layout
633 .focus()633 .focus()
634- .map(|win| win.toplevel().expect("no x11 support").wl_surface().clone())634+ .map(|win| win.toplevel().wl_surface().clone())
635 .map(|surface| KeyboardFocus::Layout {635 .map(|surface| KeyboardFocus::Layout {
636 surface: Some(surface),636 surface: Some(surface),
637 })637 })
@@ -1591,7 +1591,7 @@ impl Niri {
1591 ///1591 ///
1592 /// The cursor may be inside the window's activation region, but not within the window's input1592 /// The cursor may be inside the window's activation region, but not within the window's input
1593 /// region.1593 /// 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> {
1595 if self.is_locked() || self.screenshot_ui.is_open() {1595 if self.is_locked() || self.screenshot_ui.is_open() {
1596 return None;1596 return None;
1597 }1597 }
@@ -1618,7 +1618,7 @@ impl Niri {
1618 ///1618 ///
1619 /// The cursor may be inside the window's activation region, but not within the window's input1619 /// The cursor may be inside the window's activation region, but not within the window's input
1620 /// region.1620 /// region.
1621- pub fn window_under_cursor(&self) -> Option<&Window> {1621+ pub fn window_under_cursor(&self) -> Option<&Mapped> {
1622 let pos = self.seat.get_pointer().unwrap().current_location();1622 let pos = self.seat.get_pointer().unwrap().current_location();
1623 self.window_under(pos)1623 self.window_under(pos)
1624 }1624 }
@@ -1684,8 +1684,9 @@ impl Niri {
1684 let window_under = || {1684 let window_under = || {
1685 self.layout1685 self.layout
1686 .window_under(output, pos_within_output)1686 .window_under(output, pos_within_output)
1687- .and_then(|(window, win_pos_within_output)| {1687+ .and_then(|(mapped, win_pos_within_output)| {
1688 let win_pos_within_output = win_pos_within_output?;1688 let win_pos_within_output = win_pos_within_output?;
1689+ let window = &mapped.window;
1689 window1690 window
1690 .surface_under(1691 .surface_under(
1691 pos_within_output - win_pos_within_output.to_f64(),1692 pos_within_output - win_pos_within_output.to_f64(),
@@ -2409,7 +2410,8 @@ impl Niri {
2409 // The reason to do this at all is that it keeps track of whether the surface is visible or2410 // The reason to do this at all is that it keeps track of whether the surface is visible or
2410 // not in a unified way with the pointer surfaces, which makes the logic elsewhere simpler.2411 // not in a unified way with the pointer surfaces, which makes the logic elsewhere simpler.
2411 2412
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;
2413 let offscreen_id = win2415 let offscreen_id = win
2414 .user_data()2416 .user_data()
2415 .get_or_insert(WindowOffscreenId::default)2417 .get_or_insert(WindowOffscreenId::default)
@@ -2480,8 +2482,8 @@ impl Niri {
2480 // We can unconditionally send the current output's feedback to regular and layer-shell2482 // We can unconditionally send the current output's feedback to regular and layer-shell
2481 // surfaces, as they can only be displayed on a single output at a time. Even if a surface2483 // surfaces, as they can only be displayed on a single output at a time. Even if a surface
2482 // is currently invisible, this is the DMABUF feedback that it should know about.2484 // is currently invisible, this is the DMABUF feedback that it should know about.
2483- for win in self.layout.windows_for_output(output) {2485+ for mapped in self.layout.windows_for_output(output) {
2484- win.send_dmabuf_feedback(2486+ mapped.window.send_dmabuf_feedback(
2485 output,2487 output,
2486 |_, _| Some(output.clone()),2488 |_, _| Some(output.clone()),
2487 |surface, _| {2489 |surface, _| {
@@ -2600,8 +2602,8 @@ impl Niri {
2600 2602
2601 let frame_callback_time = get_monotonic_time();2603 let frame_callback_time = get_monotonic_time();
2602 2604
2603- for win in self.layout.windows_for_output(output) {2605+ for mapped in self.layout.windows_for_output(output) {
2604- win.send_frame(2606+ mapped.window.send_frame(
2605 output,2607 output,
2606 frame_callback_time,2608 frame_callback_time,
2607 FRAME_CALLBACK_THROTTLE,2609 FRAME_CALLBACK_THROTTLE,
@@ -2666,8 +2668,8 @@ impl Niri {
2666 2668
2667 let frame_callback_time = get_monotonic_time();2669 let frame_callback_time = get_monotonic_time();
2668 2670
2669- self.layout.with_windows(|win, _| {2671+ self.layout.with_windows(|mapped, _| {
2670- win.send_frame(2672+ mapped.window.send_frame(
2671 output,2673 output,
2672 frame_callback_time,2674 frame_callback_time,
2673 FRAME_CALLBACK_THROTTLE,2675 FRAME_CALLBACK_THROTTLE,
@@ -2746,8 +2748,8 @@ impl Niri {
2746 );2748 );
2747 }2749 }
2748 2750
2749- for win in self.layout.windows_for_output(output) {2751+ for mapped in self.layout.windows_for_output(output) {
2750- win.take_presentation_feedback(2752+ mapped.window.take_presentation_feedback(
2751 &mut feedback,2753 &mut feedback,
2752 surface_primary_scanout_output,2754 surface_primary_scanout_output,
2753 |surface, _| {2755 |surface, _| {
src/protocols/foreign_toplevel.rsmodified+3 -3
@@ -95,8 +95,8 @@ pub fn refresh(state: &mut State) {
95 // Save the focused window for last, this way when the focus changes, we will first deactivate95 // Save the focused window for last, this way when the focus changes, we will first deactivate
96 // the previous window and only then activate the newly focused window.96 // the previous window and only then activate the newly focused window.
97 let mut focused = None;97 let mut focused = None;
98- state.niri.layout.with_windows(|window, output| {98+ state.niri.layout.with_windows(|mapped, output| {
99- let wl_surface = window.toplevel().expect("no x11 support").wl_surface();99+ let wl_surface = mapped.toplevel().wl_surface();
100 100
101 with_states(wl_surface, |states| {101 with_states(wl_surface, |states| {
102 let role = states102 let role = states
@@ -107,7 +107,7 @@ pub fn refresh(state: &mut State) {
107 .unwrap();107 .unwrap();
108 108
109 if state.niri.keyboard_focus.surface() == Some(wl_surface) {109 if state.niri.keyboard_focus.surface() == Some(wl_surface) {
110- focused = Some((window.clone(), output.cloned()));110+ focused = Some((mapped.window.clone(), output.cloned()));
111 } else {111 } else {
112 refresh_toplevel(protocol_state, wl_surface, &role, output, false);112 refresh_toplevel(protocol_state, wl_surface, &role, output, false);
113 }113 }
src/utils/mod.rsmodified+0 -4
@@ -20,10 +20,6 @@ pub mod watcher;
20 20
21 pub static IS_SYSTEMD_SERVICE: AtomicBool = AtomicBool::new(false);21 pub static IS_SYSTEMD_SERVICE: AtomicBool = AtomicBool::new(false);
22 22
23-pub fn clone2<T: Clone, U: Clone>(t: (&T, &U)) -> (T, U) {
24- (t.0.clone(), t.1.clone())
25-}
26-
27 pub fn version() -> String {23 pub fn version() -> String {
28 format!(24 format!(
29 "{} ({})",25 "{} ({})",
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 @@
1 use crate::layout::workspace::ColumnWidth;1 use crate::layout::workspace::ColumnWidth;
2 2
3+pub mod mapped;
4+pub use mapped::Mapped;
5+
3 pub mod unmapped;6 pub mod unmapped;
4 pub use unmapped::{InitialConfigureState, Unmapped};7 pub use unmapped::{InitialConfigureState, Unmapped};
5 8