forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB055a94dIvan Molodetskikh1 year ago2247 commits

unmapped.rs89 lines, 2.9 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 /// The window has been configured.
26 Configured {
27 /// Up-to-date rules.
28 ///
29 /// We start tracking window rules when sending the initial configure, since they don't
30 /// affect anything before that.
31 rules: ResolvedWindowRules,
32
33 /// Resolved scrolling default width for this window.
34 ///
35 /// `None` means that the window will pick its own width.
36 width: Option<PresetSize>,
37
38 /// Resolved scrolling default height for this window.
39 ///
40 /// `None` means that the window will pick its own height.
41 height: Option<PresetSize>,
42
43 /// Resolved floating default width for this window.
44 ///
45 /// `None` means that the window will pick its own width.
46 floating_width: Option<PresetSize>,
47
48 /// Resolved floating default height for this window.
49 ///
50 /// `None` means that the window will pick its own height.
51 floating_height: Option<PresetSize>,
52
53 /// Whether the window should open full-width.
54 is_full_width: bool,
55
56 /// Output to open this window on.
57 ///
58 /// This can be `None` in cases like:
59 ///
60 /// - There are no outputs connected.
61 /// - This is a dialog with a parent, and there was no explicit output set, so this dialog
62 /// should fetch the parent's current output again upon mapping.
63 output: Option<Output>,
64
65 /// Workspace to open this window on.
66 workspace_name: Option<String>,
67 },
68}
69
70impl Unmapped {
71 /// Wraps a newly created window that hasn't been initially configured yet.
72 pub fn new(window: Window) -> Self {
73 Self {
74 window,
75 state: InitialConfigureState::NotConfigured {
76 wants_fullscreen: None,
77 },
78 activation_token_data: None,
79 }
80 }
81
82 pub fn needs_initial_configure(&self) -> bool {
83 matches!(self.state, InitialConfigureState::NotConfigured { .. })
84 }
85
86 pub fn toplevel(&self) -> &ToplevelSurface {
87 self.window.toplevel().expect("no X11 support")
88 }
89}