forge
Explore
Log in

Don't you dare go Hollow

Implement explicit unmapped window state tracking

Browse files at this commit

2317021a7c4a7296606533d38f1fdce96826f7dcIvan MolodetskikhParent: af6485c
niri-visual-tests/src/cases/layout.rsmodified+2 -3
@@ -145,8 +145,7 @@ impl Layout {
145145 }
146146
147147 fn add_window(&mut self, window: TestWindow, width: Option<ColumnWidth>) {
148- self.layout
149- .add_window(window.clone(), width.map(Some), false);
148+ self.layout.add_window(window.clone(), width, false);
150149 if window.communicate() {
151150 self.layout.update_window(&window);
152151 }
@@ -160,7 +159,7 @@ impl Layout {
160159 width: Option<ColumnWidth>,
161160 ) {
162161 self.layout
163- .add_window_right_of(right_of, window.clone(), width.map(Some), false);
162+ .add_window_right_of(right_of, window.clone(), width, false);
164163 if window.communicate() {
165164 self.layout.update_window(&window);
166165 }
src/handlers/compositor.rsmodified+36 -26
@@ -16,9 +16,9 @@ use smithay::wayland::dmabuf::get_dmabuf;
1616 use smithay::wayland::shm::{ShmHandler, ShmState};
1717 use smithay::{delegate_compositor, delegate_shm};
1818
19-use super::xdg_shell::{initial_configure_sent, resolve_window_rules};
2019 use crate::niri::{ClientState, State};
2120 use crate::utils::clone2;
21+use crate::window::{InitialConfigureState, Unmapped};
2222
2323 impl CompositorHandler for State {
2424 fn compositor_state(&mut self) -> &mut CompositorState {
@@ -105,29 +105,41 @@ impl CompositorHandler for State {
105105
106106 if is_mapped {
107107 // The toplevel got mapped.
108- let window = entry.remove();
108+ let Unmapped { window, state } = entry.remove();
109+
109110 window.on_commit();
110111
112+ let (width, output) =
113+ if let InitialConfigureState::Configured { width, output, .. } = state {
114+ // Check that the output is still connected.
115+ let output =
116+ output.filter(|o| self.niri.layout.monitor_for_output(o).is_some());
117+
118+ (width, output)
119+ } else {
120+ error!("window map must happen after initial configure");
121+ (None, None)
122+ };
123+
111124 let parent = window
112125 .toplevel()
113126 .parent()
114127 .and_then(|parent| self.niri.layout.find_window_and_output(&parent))
115- .map(|(win, _)| win.clone());
116-
117- let (width, output) = {
118- let config = self.niri.config.borrow();
119- let rules = resolve_window_rules(&config.window_rules, window.toplevel());
120- let output = rules
121- .open_on_output
122- .and_then(|name| self.niri.output_by_name.get(name))
123- .cloned();
124- (rules.default_width, output)
125- };
128+ // Only consider the parent if we configured the window for the same
129+ // output.
130+ //
131+ // Normally when we're following the parent, the configured output will be
132+ // None. If the configured output is set, that means it was set explicitly
133+ // by a window rule or a fullscreen request.
134+ .filter(|(_, parent_output)| {
135+ output.is_none() || output.as_ref() == Some(*parent_output)
136+ })
137+ .map(|(window, _)| window.clone());
126138
127139 let win = window.clone();
128140
129- // Open dialogs immediately to the right of their parent window.
130141 let output = if let Some(p) = parent {
142+ // Open dialogs immediately to the right of their parent window.
131143 self.niri.layout.add_window_right_of(&p, win, width, false)
132144 } else if let Some(output) = &output {
133145 self.niri
@@ -146,17 +158,10 @@ impl CompositorHandler for State {
146158 }
147159
148160 // The toplevel remains unmapped.
149- let window = entry.get().clone();
150-
151- // Send the initial configure in an idle, in case the client sent some more info
152- // after the initial commit.
153- if !initial_configure_sent(window.toplevel()) {
154- self.niri.event_loop.insert_idle(move |state| {
155- if !window.toplevel().alive() {
156- return;
157- }
158- state.send_initial_configure_if_needed(&window);
159- });
161+ let unmapped = entry.get();
162+ if unmapped.needs_initial_configure() {
163+ let toplevel = unmapped.window.toplevel().clone();
164+ self.queue_initial_configure(toplevel);
160165 }
161166 return;
162167 }
@@ -178,7 +183,12 @@ impl CompositorHandler for State {
178183 if !is_mapped {
179184 // The toplevel got unmapped.
180185 self.niri.layout.remove_window(&window);
181- self.niri.unmapped_windows.insert(surface.clone(), window);
186+
187+ // Newly-unmapped toplevels must perform the initial commit-configure sequence
188+ // afresh.
189+ let unmapped = Unmapped::new(window);
190+ self.niri.unmapped_windows.insert(surface.clone(), unmapped);
191+
182192 self.niri.queue_redraw(output);
183193 return;
184194 }
src/handlers/xdg_shell.rsmodified+168 -91
@@ -27,19 +27,7 @@ use smithay::{delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_she
2727 use crate::layout::workspace::ColumnWidth;
2828 use crate::niri::{PopupGrabState, State};
2929 use crate::utils::clone2;
30-
31-#[derive(Debug, Default)]
32-pub struct ResolvedWindowRule<'a> {
33- /// Default width for this window.
34- ///
35- /// - `None`: unset.
36- /// - `Some(None)`: set to empty.
37- /// - `Some(Some(width))`: set to a particular width.
38- pub default_width: Option<Option<ColumnWidth>>,
39-
40- /// Output to open this window on.
41- pub open_on_output: Option<&'a str>,
42-}
30+use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped};
4331
4432 fn window_matches(role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool {
4533 if let Some(app_id_re) = &m.app_id {
@@ -63,13 +51,13 @@ fn window_matches(role: &XdgToplevelSurfaceRoleAttributes, m: &Match) -> bool {
6351 true
6452 }
6553
66-pub fn resolve_window_rules<'a>(
67- rules: &'a [WindowRule],
54+pub fn resolve_window_rules(
55+ rules: &[WindowRule],
6856 toplevel: &ToplevelSurface,
69-) -> ResolvedWindowRule<'a> {
57+) -> ResolvedWindowRules {
7058 let _span = tracy_client::span!("resolve_window_rules");
7159
72- let mut resolved = ResolvedWindowRule::default();
60+ let mut resolved = ResolvedWindowRules::default();
7361
7462 with_states(toplevel.wl_surface(), |states| {
7563 let role = states
@@ -79,6 +67,8 @@ pub fn resolve_window_rules<'a>(
7967 .lock()
8068 .unwrap();
8169
70+ let mut open_on_output = None;
71+
8272 for rule in rules {
8373 if !(rule.matches.is_empty() || rule.matches.iter().any(|m| window_matches(&role, m))) {
8474 continue;
@@ -97,9 +87,11 @@ pub fn resolve_window_rules<'a>(
9787 }
9888
9989 if let Some(x) = rule.open_on_output.as_deref() {
100- resolved.open_on_output = Some(x);
90+ open_on_output = Some(x);
10191 }
10292 }
93+
94+ resolved.open_on_output = open_on_output.map(|x| x.to_owned());
10395 });
10496
10597 resolved
@@ -112,10 +104,8 @@ impl XdgShellHandler for State {
112104
113105 fn new_toplevel(&mut self, surface: ToplevelSurface) {
114106 let wl_surface = surface.wl_surface().clone();
115- let window = Window::new(surface);
116-
117- // At the moment of creation, xdg toplevels must have no buffer.
118- let existing = self.niri.unmapped_windows.insert(wl_surface, window);
107+ let unmapped = Unmapped::new(Window::new(surface));
108+ let existing = self.niri.unmapped_windows.insert(wl_surface, unmapped);
119109 assert!(existing.is_none());
120110 }
121111
@@ -273,53 +263,42 @@ impl XdgShellHandler for State {
273263 surface: ToplevelSurface,
274264 wl_output: Option<wl_output::WlOutput>,
275265 ) {
276- if surface
277- .current_state()
278- .capabilities
279- .contains(xdg_toplevel::WmCapabilities::Fullscreen)
266+ if let Some((window, current_output)) = self
267+ .niri
268+ .layout
269+ .find_window_and_output(surface.wl_surface())
280270 {
281- if let Some((window, current_output)) = self
282- .niri
283- .layout
284- .find_window_and_output(surface.wl_surface())
285- {
286- let window = window.clone();
271+ let window = window.clone();
287272
288- if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {
289- if &requested_output != current_output {
290- self.niri
291- .layout
292- .move_window_to_output(window.clone(), &requested_output);
293- }
273+ if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) {
274+ if &requested_output != current_output {
275+ self.niri
276+ .layout
277+ .move_window_to_output(window.clone(), &requested_output);
294278 }
279+ }
295280
296- self.niri.layout.set_fullscreen(&window, true);
297- } else if let Some(window) = self.niri.unmapped_windows.get(surface.wl_surface()) {
298- let config = self.niri.config.borrow();
299- let rules = resolve_window_rules(&config.window_rules, window.toplevel());
300-
301- // FIXME: take requested output into account (will need to thread this through to
302- // send_initial_configure_if_needed and commit handler).
303- let output = rules
304- .open_on_output
305- .and_then(|name| self.niri.output_by_name.get(name));
306- let mon = output.map(|o| self.niri.layout.monitor_for_output(o).unwrap());
307- let ws = mon
308- .map(|mon| mon.active_workspace_ref())
309- .or_else(|| self.niri.layout.active_workspace());
310-
311- if let Some(ws) = ws {
312- window.toplevel().with_pending_state(|state| {
313- state.size = Some(ws.view_size());
314- state.states.set(xdg_toplevel::State::Fullscreen);
315- });
281+ self.niri.layout.set_fullscreen(&window, true);
282+
283+ // A configure is required in response to this event regardless if there are pending
284+ // changes.
285+ surface.send_configure();
286+ } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(surface.wl_surface()) {
287+ match &mut unmapped.state {
288+ InitialConfigureState::NotConfigured { wants_fullscreen } => {
289+ *wants_fullscreen = Some(wl_output.as_ref().and_then(Output::from_resource));
290+
291+ // The required configure will be the initial configure.
316292 }
317- }
318- }
293+ InitialConfigureState::Configured { .. } => {
294+ // FIXME: implement this once I figure out a good way without code duplication.
319295
320- // A configure is required in response to this event. However, if an initial configure
321- // wasn't sent, then we will send this as part of the initial configure later.
322- if initial_configure_sent(&surface) {
296+ // We already sent the initial configure, so we need to reconfigure.
297+ surface.send_configure();
298+ }
299+ }
300+ } else {
301+ error!("couldn't find the toplevel in fullscreen_request()");
323302 surface.send_configure();
324303 }
325304 }
@@ -332,24 +311,27 @@ impl XdgShellHandler for State {
332311 {
333312 let window = window.clone();
334313 self.niri.layout.set_fullscreen(&window, false);
335- } else if let Some(window) = self.niri.unmapped_windows.get(surface.wl_surface()) {
336- let config = self.niri.config.borrow();
337- let rules = resolve_window_rules(&config.window_rules, window.toplevel());
338-
339- let output = rules
340- .open_on_output
341- .and_then(|name| self.niri.output_by_name.get(name));
342- let mon = output.map(|o| self.niri.layout.monitor_for_output(o).unwrap());
343- let ws = mon
344- .map(|mon| mon.active_workspace_ref())
345- .or_else(|| self.niri.layout.active_workspace());
346-
347- if let Some(ws) = ws {
348- window.toplevel().with_pending_state(|state| {
349- state.size = Some(ws.new_window_size(rules.default_width));
350- state.states.unset(xdg_toplevel::State::Fullscreen);
351- });
314+
315+ // A configure is required in response to this event regardless if there are pending
316+ // changes.
317+ surface.send_configure();
318+ } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(surface.wl_surface()) {
319+ match &mut unmapped.state {
320+ InitialConfigureState::NotConfigured { wants_fullscreen } => {
321+ *wants_fullscreen = None;
322+
323+ // The required configure will be the initial configure.
324+ }
325+ InitialConfigureState::Configured { .. } => {
326+ // FIXME: implement this once I figure out a good way without code duplication.
327+
328+ // We already sent the initial configure, so we need to reconfigure.
329+ surface.send_configure();
330+ }
352331 }
332+ } else {
333+ error!("couldn't find the toplevel in unfullscreen_request()");
334+ surface.send_configure();
353335 }
354336 }
355337
@@ -385,6 +367,14 @@ impl XdgShellHandler for State {
385367 self.niri.queue_redraw(output.clone());
386368 }
387369 }
370+
371+ fn app_id_changed(&mut self, toplevel: ToplevelSurface) {
372+ self.update_window_rules(&toplevel);
373+ }
374+
375+ fn title_changed(&mut self, toplevel: ToplevelSurface) {
376+ self.update_window_rules(&toplevel);
377+ }
388378 }
389379
390380 delegate_xdg_shell!(State);
@@ -440,7 +430,7 @@ impl KdeDecorationHandler for State {
440430
441431 delegate_kde_decoration!(State);
442432
443-pub fn initial_configure_sent(toplevel: &ToplevelSurface) -> bool {
433+fn initial_configure_sent(toplevel: &ToplevelSurface) -> bool {
444434 with_states(toplevel.wl_surface(), |states| {
445435 states
446436 .data_map
@@ -453,28 +443,82 @@ pub fn initial_configure_sent(toplevel: &ToplevelSurface) -> bool {
453443 }
454444
455445 impl State {
456- pub fn send_initial_configure_if_needed(&mut self, window: &Window) {
457- let toplevel = window.toplevel();
458- if initial_configure_sent(toplevel) {
446+ pub fn send_initial_configure(&mut self, toplevel: &ToplevelSurface) {
447+ let _span = tracy_client::span!("State::send_initial_configure");
448+
449+ let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) else {
450+ error!("window must be present in unmapped_windows in send_initial_configure()");
459451 return;
460- }
452+ };
461453
462- let _span = tracy_client::span!("State::send_initial_configure_if_needed");
454+ let Unmapped { window, state } = unmapped;
455+
456+ let InitialConfigureState::NotConfigured { wants_fullscreen } = state else {
457+ error!("window must not be already configured in send_initial_configure()");
458+ return;
459+ };
463460
464461 let config = self.niri.config.borrow();
465462 let rules = resolve_window_rules(&config.window_rules, toplevel);
466463
467- let output = rules
464+ // Pick the target monitor. First, check if we had an output set in the window rules.
465+ let mon = rules
468466 .open_on_output
469- .and_then(|name| self.niri.output_by_name.get(name));
470- let mon = output.map(|o| self.niri.layout.monitor_for_output(o).unwrap());
467+ .as_deref()
468+ .and_then(|name| self.niri.output_by_name.get(name))
469+ .and_then(|o| self.niri.layout.monitor_for_output(o));
470+
471+ // If not, check if the window requested one for fullscreen.
472+ let mon = mon.or_else(|| {
473+ wants_fullscreen
474+ .as_ref()
475+ .and_then(|x| x.as_ref())
476+ // The monitor might not exist if the output was disconnected.
477+ .and_then(|o| self.niri.layout.monitor_for_output(o))
478+ });
479+
480+ // If not, check if this is a dialog with a parent, to place it next to the parent.
481+ let mon = mon.map(|mon| (mon, false)).or_else(|| {
482+ toplevel
483+ .parent()
484+ .and_then(|parent| self.niri.layout.find_window_and_output(&parent))
485+ .map(|(_win, output)| output)
486+ .and_then(|o| self.niri.layout.monitor_for_output(o))
487+ .map(|mon| (mon, true))
488+ });
489+
490+ // If not, use the active monitor.
491+ let mon = mon.or_else(|| {
492+ self.niri
493+ .layout
494+ .active_monitor_ref()
495+ .map(|mon| (mon, false))
496+ });
497+
498+ // If we're following the parent, don't set the target output, so that when the window is
499+ // mapped, it fetches the possibly changed parent's output again, and shows up there.
500+ let output = mon
501+ .filter(|(_, parent)| !parent)
502+ .map(|(mon, _)| mon.output.clone());
503+ let mon = mon.map(|(mon, _)| mon);
504+
505+ let mut width = None;
506+
507+ // Tell the surface the preferred size and bounds for its likely output.
471508 let ws = mon
472509 .map(|mon| mon.active_workspace_ref())
473510 .or_else(|| self.niri.layout.active_workspace());
474511
475- // Tell the surface the preferred size and bounds for its likely output.
476512 if let Some(ws) = ws {
477- ws.configure_new_window(window, rules.default_width);
513+ // Set a fullscreen state if requested.
514+ if wants_fullscreen.is_some() {
515+ toplevel.with_pending_state(|state| {
516+ state.states.set(xdg_toplevel::State::Fullscreen);
517+ });
518+ }
519+
520+ width = ws.resolve_default_width(rules.default_width);
521+ ws.configure_new_window(window, width);
478522 }
479523
480524 // If the user prefers no CSD, it's a reasonable assumption that they would prefer to get
@@ -488,9 +532,32 @@ impl State {
488532 });
489533 }
490534
535+ // Set the configured settings.
536+ *state = InitialConfigureState::Configured {
537+ rules,
538+ width,
539+ output,
540+ };
541+
491542 toplevel.send_configure();
492543 }
493544
545+ pub fn queue_initial_configure(&self, toplevel: ToplevelSurface) {
546+ // Send the initial configure in an idle, in case the client sent some more info after the
547+ // initial commit.
548+ self.niri.event_loop.insert_idle(move |state| {
549+ if !toplevel.alive() {
550+ return;
551+ }
552+
553+ if let Some(unmapped) = state.niri.unmapped_windows.get(toplevel.wl_surface()) {
554+ if unmapped.needs_initial_configure() {
555+ state.send_initial_configure(&toplevel);
556+ }
557+ }
558+ });
559+ }
560+
494561 /// Should be called on `WlSurface::commit`
495562 pub fn popups_handle_commit(&mut self, surface: &WlSurface) {
496563 self.niri.popups.commit(surface);
@@ -611,6 +678,16 @@ impl State {
611678 }
612679 }
613680 }
681+
682+ pub fn update_window_rules(&mut self, toplevel: &ToplevelSurface) {
683+ let resolve = || resolve_window_rules(&self.niri.config.borrow().window_rules, toplevel);
684+
685+ if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) {
686+ if let InitialConfigureState::Configured { rules, .. } = &mut unmapped.state {
687+ *rules = resolve();
688+ }
689+ }
690+ }
614691 }
615692
616693 fn unconstrain_with_padding(
src/layout/mod.rsmodified+19 -21
@@ -531,15 +531,10 @@ impl<W: LayoutElement> Layout<W> {
531531 pub fn add_window(
532532 &mut self,
533533 window: W,
534- width: Option<Option<ColumnWidth>>,
534+ width: Option<ColumnWidth>,
535535 is_full_width: bool,
536536 ) -> Option<&Output> {
537- let width = match width {
538- Some(Some(width)) => Some(width),
539- Some(None) => None,
540- None => self.options.default_width,
541- }
542- .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
537+ let width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
543538
544539 match &mut self.monitor_set {
545540 MonitorSet::Normal {
@@ -587,15 +582,10 @@ impl<W: LayoutElement> Layout<W> {
587582 &mut self,
588583 right_of: &W,
589584 window: W,
590- width: Option<Option<ColumnWidth>>,
585+ width: Option<ColumnWidth>,
591586 is_full_width: bool,
592587 ) -> Option<&Output> {
593- let width = match width {
594- Some(Some(width)) => Some(width),
595- Some(None) => None,
596- None => self.options.default_width,
597- }
598- .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
588+ let width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
599589
600590 match &mut self.monitor_set {
601591 MonitorSet::Normal { monitors, .. } => {
@@ -623,15 +613,10 @@ impl<W: LayoutElement> Layout<W> {
623613 &mut self,
624614 output: &Output,
625615 window: W,
626- width: Option<Option<ColumnWidth>>,
616+ width: Option<ColumnWidth>,
627617 is_full_width: bool,
628618 ) {
629- let width = match width {
630- Some(Some(width)) => Some(width),
631- Some(None) => None,
632- None => self.options.default_width,
633- }
634- .unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
619+ let width = width.unwrap_or_else(|| ColumnWidth::Fixed(window.size().w));
635620
636621 let MonitorSet::Normal {
637622 monitors,
@@ -931,6 +916,19 @@ impl<W: LayoutElement> Layout<W> {
931916 Some(&mut monitors[*active_monitor_idx])
932917 }
933918
919+ pub fn active_monitor_ref(&self) -> Option<&Monitor<W>> {
920+ let MonitorSet::Normal {
921+ monitors,
922+ active_monitor_idx,
923+ ..
924+ } = &self.monitor_set
925+ else {
926+ return None;
927+ };
928+
929+ Some(&monitors[*active_monitor_idx])
930+ }
931+
934932 pub fn monitor_for_output(&self, output: &Output) -> Option<&Monitor<W>> {
935933 let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
936934 return None;
src/layout/workspace.rsmodified+9 -11
@@ -322,17 +322,19 @@ impl<W: LayoutElement> Workspace<W> {
322322 ))
323323 }
324324
325- pub fn new_window_size(
325+ pub fn resolve_default_width(
326326 &self,
327327 default_width: Option<Option<ColumnWidth>>,
328- ) -> Size<i32, Logical> {
329- let default_width = match default_width {
328+ ) -> Option<ColumnWidth> {
329+ match default_width {
330330 Some(Some(width)) => Some(width),
331331 Some(None) => None,
332332 None => self.options.default_width,
333- };
333+ }
334+ }
334335
335- let width = if let Some(width) = default_width {
336+ pub fn new_window_size(&self, width: Option<ColumnWidth>) -> Size<i32, Logical> {
337+ let width = if let Some(width) = width {
336338 let mut width = width.resolve(&self.options, self.working_area.size.w);
337339 if !self.options.border.off {
338340 width -= self.options.border.width as i32 * 2;
@@ -350,11 +352,7 @@ impl<W: LayoutElement> Workspace<W> {
350352 Size::from((width, max(height, 1)))
351353 }
352354
353- pub fn configure_new_window(
354- &self,
355- window: &Window,
356- default_width: Option<Option<ColumnWidth>>,
357- ) {
355+ pub fn configure_new_window(&self, window: &Window, width: Option<ColumnWidth>) {
358356 if let Some(output) = self.output.as_ref() {
359357 set_preferred_scale_transform(window, output);
360358 }
@@ -363,7 +361,7 @@ impl<W: LayoutElement> Workspace<W> {
363361 if state.states.contains(xdg_toplevel::State::Fullscreen) {
364362 state.size = Some(self.view_size);
365363 } else {
366- state.size = Some(self.new_window_size(default_width));
364+ state.size = Some(self.new_window_size(width));
367365 }
368366
369367 state.bounds = Some(self.toplevel_bounds());
src/lib.rsmodified+1 -0
@@ -17,6 +17,7 @@ pub mod protocols;
1717 pub mod render_helpers;
1818 pub mod ui;
1919 pub mod utils;
20+pub mod window;
2021
2122 #[cfg(not(feature = "xdp-gnome-screencast"))]
2223 pub mod dummy_pw_utils;
src/niri.rsmodified+2 -1
@@ -107,6 +107,7 @@ use crate::ui::screenshot_ui::{ScreenshotUi, ScreenshotUiRenderElement};
107107 use crate::utils::{
108108 center, get_monotonic_time, make_screenshot_path, output_size, write_png_rgba8,
109109 };
110+use crate::window::Unmapped;
110111 use crate::{animation, niri_render_elements};
111112
112113 const CLEAR_COLOR: [f32; 4] = [0.2, 0.2, 0.2, 1.];
@@ -132,7 +133,7 @@ pub struct Niri {
132133 pub global_space: Space<Window>,
133134
134135 // Windows which don't have a buffer attached yet.
135- pub unmapped_windows: HashMap<WlSurface, Window>,
136+ pub unmapped_windows: HashMap<WlSurface, Unmapped>,
136137
137138 pub output_state: HashMap<Output, OutputState>,
138139 pub output_by_name: HashMap<String, Output>,
src/window.rsadded+71 -0
@@ -0,0 +1,71 @@
1+use smithay::desktop::Window;
2+use smithay::output::Output;
3+
4+use crate::layout::workspace::ColumnWidth;
5+
6+#[derive(Debug)]
7+pub struct Unmapped {
8+ pub window: Window,
9+ pub state: InitialConfigureState,
10+}
11+
12+#[derive(Debug)]
13+pub enum InitialConfigureState {
14+ /// The window has not been initially configured yet.
15+ NotConfigured {
16+ /// Whether the window requested to be fullscreened, and the requested output, if any.
17+ wants_fullscreen: Option<Option<Output>>,
18+ },
19+ /// The window has been configured.
20+ Configured {
21+ /// Up-to-date rules.
22+ ///
23+ /// We start tracking window rules when sending the initial configure, since they don't
24+ /// affect anything before that.
25+ rules: ResolvedWindowRules,
26+
27+ /// Resolved default width for this window.
28+ ///
29+ /// `None` means that the window will pick its own width.
30+ width: Option<ColumnWidth>,
31+
32+ /// Output to open this window on.
33+ ///
34+ /// This can be `None` in cases like:
35+ ///
36+ /// - There are no outputs connected.
37+ /// - This is a dialog with a parent, and there was no explicit output set, so this dialog
38+ /// should fetch the parent's current output again upon mapping.
39+ output: Option<Output>,
40+ },
41+}
42+
43+/// Rules fully resolved for a window.
44+#[derive(Debug, Default)]
45+pub struct ResolvedWindowRules {
46+ /// Default width for this window.
47+ ///
48+ /// - `None`: unset (global default should be used).
49+ /// - `Some(None)`: set to empty (window picks its own width).
50+ /// - `Some(Some(width))`: set to a particular width.
51+ pub default_width: Option<Option<ColumnWidth>>,
52+
53+ /// Output to open this window on.
54+ pub open_on_output: Option<String>,
55+}
56+
57+impl Unmapped {
58+ /// Wraps a newly created window that hasn't been initially configured yet.
59+ pub fn new(window: Window) -> Self {
60+ Self {
61+ window,
62+ state: InitialConfigureState::NotConfigured {
63+ wants_fullscreen: None,
64+ },
65+ }
66+ }
67+
68+ pub fn needs_initial_configure(&self) -> bool {
69+ matches!(self.state, InitialConfigureState::NotConfigured { .. })
70+ }
71+}