forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

unmapped.rs100 lines, 3.3 KiBHistoryRawDownload
1use niri_config::PresetSize;
2use smithay::desktop::Window;
3use smithay::output::Output;
4use smithay::wayland::shell::xdg::ToplevelSurface;
5use smithay::wayland::xdg_activation::XdgActivationTokenData;
6
7use super::ResolvedWindowRules;
8
9#[derive(Debug)]
10pub struct Unmapped {
11 pub window: Window,
12 pub state: InitialConfigureState,
13 /// Activation token, if one was used on this unmapped window.
14 pub activation_token_data: Option<XdgActivationTokenData>,
15}
16
17#[allow(clippy::large_enum_variant)]
18#[derive(Debug)]
19pub enum InitialConfigureState {
20 /// The window has not been initially configured yet.
21 NotConfigured {
22 /// Whether the window requested to be fullscreened, and the requested output, if any.
23 wants_fullscreen: Option<Option<Output>>,
24
25 /// Whether the window requested to be maximized.
26 wants_maximized: bool,
27 },
28 /// The window has been configured.
29 Configured {
30 /// Up-to-date rules.
31 ///
32 /// We start tracking window rules when sending the initial configure, since they don't
33 /// affect anything before that.
34 rules: ResolvedWindowRules,
35
36 /// Resolved scrolling default width for this window.
37 ///
38 /// `None` means that the window will pick its own width.
39 width: Option<PresetSize>,
40
41 /// Resolved scrolling default height for this window.
42 ///
43 /// `None` means that the window will pick its own height.
44 height: Option<PresetSize>,
45
46 /// Resolved floating default width for this window.
47 ///
48 /// `None` means that the window will pick its own width.
49 floating_width: Option<PresetSize>,
50
51 /// Resolved floating default height for this window.
52 ///
53 /// `None` means that the window will pick its own height.
54 floating_height: Option<PresetSize>,
55
56 /// Whether the window should open full-width.
57 is_full_width: bool,
58
59 /// Output to open this window on.
60 ///
61 /// This can be `None` in cases like:
62 ///
63 /// - There are no outputs connected.
64 /// - This is a dialog with a parent, and there was no explicit output set, so this dialog
65 /// should fetch the parent's current output again upon mapping.
66 output: Option<Output>,
67
68 /// Workspace to open this window on.
69 workspace_name: Option<String>,
70
71 /// Whether the window should be maximized.
72 ///
73 /// This corresponds to the window having the Maximized toplevel state. However, if the
74 /// window is also pending fullscreen, then it has the Fullscreen toplevel state, so we
75 /// need to store pending maximized elsewhere, hence this field.
76 is_pending_maximized: bool,
77 },
78}
79
80impl Unmapped {
81 /// Wraps a newly created window that hasn't been initially configured yet.
82 pub fn new(window: Window) -> Self {
83 Self {
84 window,
85 state: InitialConfigureState::NotConfigured {
86 wants_fullscreen: None,
87 wants_maximized: false,
88 },
89 activation_token_data: None,
90 }
91 }
92
93 pub fn needs_initial_configure(&self) -> bool {
94 matches!(self.state, InitialConfigureState::NotConfigured { .. })
95 }
96
97 pub fn toplevel(&self) -> &ToplevelSurface {
98 self.window.toplevel().expect("no X11 support")
99 }
100}