forge
Explore
Log in

Don't you dare go Hollow

Implement toggle-windowed-fullscreen

Browse files at this commit

39f52b75856936db01325aa1c7f15fe8f379485dIvan MolodetskikhParent: b447b1f
Windowed, or fake, or detached, fullscreen, is when a window thinks that it's
fullscreen, but the compositor treats it as a normal window.
niri-config/src/lib.rsmodified+9 -0
@@ -1476,6 +1476,9 @@ pub enum Action {
1476 FullscreenWindow,1476 FullscreenWindow,
1477 #[knuffel(skip)]1477 #[knuffel(skip)]
1478 FullscreenWindowById(u64),1478 FullscreenWindowById(u64),
1479+ ToggleWindowedFullscreen,
1480+ #[knuffel(skip)]
1481+ ToggleWindowedFullscreenById(u64),
1479 #[knuffel(skip)]1482 #[knuffel(skip)]
1480 FocusWindow(u64),1483 FocusWindow(u64),
1481 FocusWindowInColumn(#[knuffel(argument)] u8),1484 FocusWindowInColumn(#[knuffel(argument)] u8),
@@ -1680,6 +1683,12 @@ impl From<niri_ipc::Action> for Action {
1680 niri_ipc::Action::CloseWindow { id: Some(id) } => Self::CloseWindowById(id),1683 niri_ipc::Action::CloseWindow { id: Some(id) } => Self::CloseWindowById(id),
1681 niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow,1684 niri_ipc::Action::FullscreenWindow { id: None } => Self::FullscreenWindow,
1682 niri_ipc::Action::FullscreenWindow { id: Some(id) } => Self::FullscreenWindowById(id),1685 niri_ipc::Action::FullscreenWindow { id: Some(id) } => Self::FullscreenWindowById(id),
1686+ niri_ipc::Action::ToggleWindowedFullscreen { id: None } => {
1687+ Self::ToggleWindowedFullscreen
1688+ }
1689+ niri_ipc::Action::ToggleWindowedFullscreen { id: Some(id) } => {
1690+ Self::ToggleWindowedFullscreenById(id)
1691+ }
1683 niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id),1692 niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id),
1684 niri_ipc::Action::FocusWindowInColumn { index } => Self::FocusWindowInColumn(index),1693 niri_ipc::Action::FocusWindowInColumn { index } => Self::FocusWindowInColumn(index),
1685 niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious,1694 niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious,
niri-ipc/src/lib.rsmodified+12 -0
@@ -221,6 +221,18 @@ pub enum Action {
221 #[cfg_attr(feature = "clap", arg(long))]221 #[cfg_attr(feature = "clap", arg(long))]
222 id: Option<u64>,222 id: Option<u64>,
223 },223 },
224+ /// Toggle windowed (fake) fullscreen on a window.
225+ #[cfg_attr(
226+ feature = "clap",
227+ clap(about = "Toggle windowed (fake) fullscreen on the focused window")
228+ )]
229+ ToggleWindowedFullscreen {
230+ /// Id of the window to toggle windowed fullscreen of.
231+ ///
232+ /// If `None`, uses the focused window.
233+ #[cfg_attr(feature = "clap", arg(long))]
234+ id: Option<u64>,
235+ },
224 /// Focus a window by id.236 /// Focus a window by id.
225 FocusWindow {237 FocusWindow {
226 /// Id of the window to focus.238 /// Id of the window to focus.
src/input/mod.rsmodified+17 -0
@@ -690,6 +690,23 @@ impl State {
690 self.niri.queue_redraw_all();690 self.niri.queue_redraw_all();
691 }691 }
692 }692 }
693+ Action::ToggleWindowedFullscreen => {
694+ let focus = self.niri.layout.focus().map(|m| m.window.clone());
695+ if let Some(window) = focus {
696+ self.niri.layout.toggle_windowed_fullscreen(&window);
697+ // FIXME: granular
698+ self.niri.queue_redraw_all();
699+ }
700+ }
701+ Action::ToggleWindowedFullscreenById(id) => {
702+ let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
703+ let window = window.map(|(_, m)| m.window.clone());
704+ if let Some(window) = window {
705+ self.niri.layout.toggle_windowed_fullscreen(&window);
706+ // FIXME: granular
707+ self.niri.queue_redraw_all();
708+ }
709+ }
693 Action::FocusWindow(id) => {710 Action::FocusWindow(id) => {
694 let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);711 let window = self.niri.layout.windows().find(|(_, m)| m.id().get() == id);
695 let window = window.map(|(_, m)| m.window.clone());712 let window = window.map(|(_, m)| m.window.clone());
src/layout/mod.rsmodified+41 -0
@@ -244,6 +244,13 @@ pub trait LayoutElement {
244 Some(requested)244 Some(requested)
245 }245 }
246 246
247+ fn is_pending_windowed_fullscreen(&self) -> bool {
248+ false
249+ }
250+ fn request_windowed_fullscreen(&mut self, value: bool) {
251+ let _ = value;
252+ }
253+
247 fn is_child_of(&self, parent: &Self) -> bool;254 fn is_child_of(&self, parent: &Self) -> bool;
248 255
249 fn rules(&self) -> &ResolvedWindowRules;256 fn rules(&self) -> &ResolvedWindowRules;
@@ -3458,6 +3465,20 @@ impl<W: LayoutElement> Layout<W> {
3458 }3465 }
3459 3466
3460 pub fn set_fullscreen(&mut self, id: &W::Id, is_fullscreen: bool) {3467 pub fn set_fullscreen(&mut self, id: &W::Id, is_fullscreen: bool) {
3468+ // Check if this is a request to unset the windowed fullscreen state.
3469+ if !is_fullscreen {
3470+ let mut handled = false;
3471+ self.with_windows_mut(|window, _| {
3472+ if window.id() == id && window.is_pending_windowed_fullscreen() {
3473+ window.request_windowed_fullscreen(false);
3474+ handled = true;
3475+ }
3476+ });
3477+ if handled {
3478+ return;
3479+ }
3480+ }
3481+
3461 if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {3482 if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
3462 if move_.tile.window().id() == id {3483 if move_.tile.window().id() == id {
3463 return;3484 return;
@@ -3487,6 +3508,26 @@ impl<W: LayoutElement> Layout<W> {
3487 }3508 }
3488 }3509 }
3489 3510
3511+ pub fn toggle_windowed_fullscreen(&mut self, id: &W::Id) {
3512+ let (_, window) = self.windows().find(|(_, win)| win.id() == id).unwrap();
3513+ if window.is_pending_fullscreen() {
3514+ // Remove the real fullscreen.
3515+ for ws in self.workspaces_mut() {
3516+ if ws.has_window(id) {
3517+ ws.set_fullscreen(id, false);
3518+ break;
3519+ }
3520+ }
3521+ }
3522+
3523+ // This will switch is_pending_fullscreen() to false right away.
3524+ self.with_windows_mut(|window, _| {
3525+ if window.id() == id {
3526+ window.request_windowed_fullscreen(!window.is_pending_windowed_fullscreen());
3527+ }
3528+ });
3529+ }
3530+
3490 pub fn workspace_switch_gesture_begin(&mut self, output: &Output, is_touchpad: bool) {3531 pub fn workspace_switch_gesture_begin(&mut self, output: &Output, is_touchpad: bool) {
3491 let monitors = match &mut self.monitor_set {3532 let monitors = match &mut self.monitor_set {
3492 MonitorSet::Normal { monitors, .. } => monitors,3533 MonitorSet::Normal { monitors, .. } => monitors,
src/layout/tests.rsmodified+75 -0
@@ -29,6 +29,8 @@ struct TestWindowInner {
29 pending_fullscreen: Cell<bool>,29 pending_fullscreen: Cell<bool>,
30 pending_activated: Cell<bool>,30 pending_activated: Cell<bool>,
31 is_fullscreen: Cell<bool>,31 is_fullscreen: Cell<bool>,
32+ is_windowed_fullscreen: Cell<bool>,
33+ is_pending_windowed_fullscreen: Cell<bool>,
32 }34 }
33 35
34 #[derive(Debug, Clone)]36 #[derive(Debug, Clone)]
@@ -72,6 +74,8 @@ impl TestWindow {
72 pending_fullscreen: Cell::new(false),74 pending_fullscreen: Cell::new(false),
73 pending_activated: Cell::new(false),75 pending_activated: Cell::new(false),
74 is_fullscreen: Cell::new(false),76 is_fullscreen: Cell::new(false),
77+ is_windowed_fullscreen: Cell::new(false),
78+ is_pending_windowed_fullscreen: Cell::new(false),
75 }))79 }))
76 }80 }
77 81
@@ -101,6 +105,13 @@ impl TestWindow {
101 changed = true;105 changed = true;
102 }106 }
103 107
108+ if self.0.is_windowed_fullscreen.get() != self.0.is_pending_windowed_fullscreen.get() {
109+ self.0
110+ .is_windowed_fullscreen
111+ .set(self.0.is_pending_windowed_fullscreen.get());
112+ changed = true;
113+ }
114+
104 changed115 changed
105 }116 }
106 }117 }
@@ -144,6 +155,10 @@ impl LayoutElement for TestWindow {
144 ) {155 ) {
145 self.0.requested_size.set(Some(size));156 self.0.requested_size.set(Some(size));
146 self.0.pending_fullscreen.set(is_fullscreen);157 self.0.pending_fullscreen.set(is_fullscreen);
158+
159+ if is_fullscreen {
160+ self.0.is_pending_windowed_fullscreen.set(false);
161+ }
147 }162 }
148 163
149 fn min_size(&self) -> Size<i32, Logical> {164 fn min_size(&self) -> Size<i32, Logical> {
@@ -191,10 +206,18 @@ impl LayoutElement for TestWindow {
191 fn set_floating(&mut self, _floating: bool) {}206 fn set_floating(&mut self, _floating: bool) {}
192 207
193 fn is_fullscreen(&self) -> bool {208 fn is_fullscreen(&self) -> bool {
209+ if self.0.is_windowed_fullscreen.get() {
210+ return false;
211+ }
212+
194 self.0.is_fullscreen.get()213 self.0.is_fullscreen.get()
195 }214 }
196 215
197 fn is_pending_fullscreen(&self) -> bool {216 fn is_pending_fullscreen(&self) -> bool {
217+ if self.0.is_pending_windowed_fullscreen.get() {
218+ return false;
219+ }
220+
198 self.0.pending_fullscreen.get()221 self.0.pending_fullscreen.get()
199 }222 }
200 223
@@ -202,6 +225,14 @@ impl LayoutElement for TestWindow {
202 self.0.requested_size.get()225 self.0.requested_size.get()
203 }226 }
204 227
228+ fn is_pending_windowed_fullscreen(&self) -> bool {
229+ self.0.is_pending_windowed_fullscreen.get()
230+ }
231+
232+ fn request_windowed_fullscreen(&mut self, value: bool) {
233+ self.0.is_pending_windowed_fullscreen.set(value);
234+ }
235+
205 fn is_child_of(&self, parent: &Self) -> bool {236 fn is_child_of(&self, parent: &Self) -> bool {
206 self.0.parent_id.get() == Some(parent.0.id)237 self.0.parent_id.get() == Some(parent.0.id)
207 }238 }
@@ -374,6 +405,7 @@ enum Op {
374 window: usize,405 window: usize,
375 is_fullscreen: bool,406 is_fullscreen: bool,
376 },407 },
408+ ToggleWindowedFullscreen(#[proptest(strategy = "1..=5usize")] usize),
377 FocusColumnLeft,409 FocusColumnLeft,
378 FocusColumnRight,410 FocusColumnRight,
379 FocusColumnFirst,411 FocusColumnFirst,
@@ -901,14 +933,26 @@ impl Op {
901 layout.remove_window(&id, Transaction::new());933 layout.remove_window(&id, Transaction::new());
902 }934 }
903 Op::FullscreenWindow(id) => {935 Op::FullscreenWindow(id) => {
936+ if !layout.has_window(&id) {
937+ return;
938+ }
904 layout.toggle_fullscreen(&id);939 layout.toggle_fullscreen(&id);
905 }940 }
906 Op::SetFullscreenWindow {941 Op::SetFullscreenWindow {
907 window,942 window,
908 is_fullscreen,943 is_fullscreen,
909 } => {944 } => {
945+ if !layout.has_window(&window) {
946+ return;
947+ }
910 layout.set_fullscreen(&window, is_fullscreen);948 layout.set_fullscreen(&window, is_fullscreen);
911 }949 }
950+ Op::ToggleWindowedFullscreen(id) => {
951+ if !layout.has_window(&id) {
952+ return;
953+ }
954+ layout.toggle_windowed_fullscreen(&id);
955+ }
912 Op::FocusColumnLeft => layout.focus_left(),956 Op::FocusColumnLeft => layout.focus_left(),
913 Op::FocusColumnRight => layout.focus_right(),957 Op::FocusColumnRight => layout.focus_right(),
914 Op::FocusColumnFirst => layout.focus_column_first(),958 Op::FocusColumnFirst => layout.focus_column_first(),
@@ -3187,6 +3231,37 @@ fn unfullscreen_with_large_border() {
3187 check_ops_with_options(options, &ops);3231 check_ops_with_options(options, &ops);
3188 }3232 }
3189 3233
3234+#[test]
3235+fn fullscreen_to_windowed_fullscreen() {
3236+ let ops = [
3237+ Op::AddOutput(0),
3238+ Op::AddWindow {
3239+ params: TestWindowParams::new(0),
3240+ },
3241+ Op::FullscreenWindow(0),
3242+ Op::Communicate(0), // Make sure it goes into fullscreen.
3243+ Op::ToggleWindowedFullscreen(0),
3244+ ];
3245+
3246+ check_ops(&ops);
3247+}
3248+
3249+#[test]
3250+fn windowed_fullscreen_to_fullscreen() {
3251+ let ops = [
3252+ Op::AddOutput(0),
3253+ Op::AddWindow {
3254+ params: TestWindowParams::new(0),
3255+ },
3256+ Op::FullscreenWindow(0),
3257+ Op::Communicate(0), // Commit fullscreen state.
3258+ Op::ToggleWindowedFullscreen(0), // Switch is_fullscreen() to false.
3259+ Op::FullscreenWindow(0), // Switch is_fullscreen() back to true.
3260+ ];
3261+
3262+ check_ops(&ops);
3263+}
3264+
3190 fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool {3265 fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool {
3191 if parent_id == id {3266 if parent_id == id {
3192 return true;3267 return true;
src/window/mapped.rsmodified+92 -4
@@ -120,6 +120,36 @@ pub struct Mapped {
120 ///120 ///
121 /// Used for double-resize-click tracking.121 /// Used for double-resize-click tracking.
122 last_interactive_resize_start: Cell<Option<(Duration, ResizeEdge)>>,122 last_interactive_resize_start: Cell<Option<(Duration, ResizeEdge)>>,
123+
124+ /// Whether this window is in windowed (fake) fullscreen.
125+ ///
126+ /// In this mode, the underlying window is told that it's fullscreen, while keeping it as
127+ /// a regular, non-fullscreen tile.
128+ is_windowed_fullscreen: bool,
129+
130+ /// Whether this window is pending to go to windowed (fake) fullscreen.
131+ ///
132+ /// Several places in the layout code assume that is_fullscreen() can flip only on a commit.
133+ /// Which is something that we do want to flip when changing is_windowed_fullscreen. Flipping
134+ /// it right away would mean remembering to call layout.update_window() after any operation
135+ /// that may change is_windowed_fullscreen, which is quite tricky and error-prone, especially
136+ /// for deeply nested operations.
137+ ///
138+ /// It's also not clear what's the best way to go about it. Ideally we'd wait for configure ack
139+ /// and commit before "committing" to is_windowed_fullscreen, however, since it's not real
140+ /// Wayland state, we may end up with no Wayland state change to configure at all.
141+ ///
142+ /// For example: when the window is in real fullscreen, but its non-fullscreen size matches
143+ /// its fullscreen size. Then turning on is_windowed_fullscreen will both keep the
144+ /// fullscreen state, and keep the size (since it matches), resulting in no configure.
145+ ///
146+ /// So we work around this by "committing" is_pending_windowed_fullscreen to
147+ /// is_windowed_fullscreen on receiving any actual window commit, and whenever
148+ /// is_pending_windowed_fullscreen changes, we mark the window as needs_configure. This does
149+ /// mean some unnecessary delays in some cases, but it also means being able to better
150+ /// synchronize our windowed fullscreen state to the real window updates, so that's good I
151+ /// guess.
152+ is_pending_windowed_fullscreen: bool,
123 }153 }
124 154
125 niri_render_elements! {155 niri_render_elements! {
@@ -209,6 +239,8 @@ impl Mapped {
209 pending_transactions: Vec::new(),239 pending_transactions: Vec::new(),
210 interactive_resize: None,240 interactive_resize: None,
211 last_interactive_resize_start: Cell::new(None),241 last_interactive_resize_start: Cell::new(None),
242+ is_windowed_fullscreen: false,
243+ is_pending_windowed_fullscreen: false,
212 }244 }
213 }245 }
214 246
@@ -608,10 +640,21 @@ impl LayoutElement for Mapped {
608 animate: bool,640 animate: bool,
609 transaction: Option<Transaction>,641 transaction: Option<Transaction>,
610 ) {642 ) {
643+ // Going into real fullscreen resets windowed fullscreen.
644+ if is_fullscreen {
645+ self.is_pending_windowed_fullscreen = false;
646+
647+ if self.is_windowed_fullscreen {
648+ // Make sure we receive a commit to update self.is_windowed_fullscreen to false
649+ // later on.
650+ self.needs_configure = true;
651+ }
652+ }
653+
611 let changed = self.toplevel().with_pending_state(|state| {654 let changed = self.toplevel().with_pending_state(|state| {
612 let changed = state.size != Some(size);655 let changed = state.size != Some(size);
613 state.size = Some(size);656 state.size = Some(size);
614- if is_fullscreen {657+ if is_fullscreen || self.is_pending_windowed_fullscreen {
615 state.states.set(xdg_toplevel::State::Fullscreen);658 state.states.set(xdg_toplevel::State::Fullscreen);
616 } else {659 } else {
617 state.states.unset(xdg_toplevel::State::Fullscreen);660 state.states.unset(xdg_toplevel::State::Fullscreen);
@@ -660,7 +703,8 @@ impl LayoutElement for Mapped {
660 703
661 let same_size = last_sent.size.unwrap_or_default() == size;704 let same_size = last_sent.size.unwrap_or_default() == size;
662 let has_fullscreen = last_sent.states.contains(xdg_toplevel::State::Fullscreen);705 let has_fullscreen = last_sent.states.contains(xdg_toplevel::State::Fullscreen);
663- (same_size && !has_fullscreen).then_some(last_serial)706+ let same_fullscreen = has_fullscreen == self.is_pending_windowed_fullscreen;
707+ (same_size && same_fullscreen).then_some(last_serial)
664 });708 });
665 709
666 if let Some(serial) = already_sent {710 if let Some(serial) = already_sent {
@@ -687,7 +731,9 @@ impl LayoutElement for Mapped {
687 let changed = self.toplevel().with_pending_state(|state| {731 let changed = self.toplevel().with_pending_state(|state| {
688 let changed = state.size != Some(size);732 let changed = state.size != Some(size);
689 state.size = Some(size);733 state.size = Some(size);
690- state.states.unset(xdg_toplevel::State::Fullscreen);734+ if !self.is_pending_windowed_fullscreen {
735+ state.states.unset(xdg_toplevel::State::Fullscreen);
736+ }
691 changed737 changed
692 });738 });
693 739
@@ -934,6 +980,10 @@ impl LayoutElement for Mapped {
934 }980 }
935 981
936 fn is_fullscreen(&self) -> bool {982 fn is_fullscreen(&self) -> bool {
983+ if self.is_windowed_fullscreen {
984+ return false;
985+ }
986+
937 with_toplevel_role(self.toplevel(), |role| {987 with_toplevel_role(self.toplevel(), |role| {
938 role.current988 role.current
939 .states989 .states
@@ -942,6 +992,10 @@ impl LayoutElement for Mapped {
942 }992 }
943 993
944 fn is_pending_fullscreen(&self) -> bool {994 fn is_pending_fullscreen(&self) -> bool {
995+ if self.is_pending_windowed_fullscreen {
996+ return false;
997+ }
998+
945 self.toplevel()999 self.toplevel()
946 .with_pending_state(|state| state.states.contains(xdg_toplevel::State::Fullscreen))1000 .with_pending_state(|state| state.states.contains(xdg_toplevel::State::Fullscreen))
947 }1001 }
@@ -1014,7 +1068,7 @@ impl LayoutElement for Mapped {
1014 1068
1015 if let Some((mut size, fullscreen)) = pending {1069 if let Some((mut size, fullscreen)) = pending {
1016 // If the pending change is fullscreen, we can't use that size.1070 // If the pending change is fullscreen, we can't use that size.
1017- if fullscreen {1071+ if fullscreen && !self.is_pending_windowed_fullscreen {
1018 return None;1072 return None;
1019 }1073 }
1020 1074
@@ -1034,6 +1088,33 @@ impl LayoutElement for Mapped {
1034 }1088 }
1035 }1089 }
1036 1090
1091+ fn is_pending_windowed_fullscreen(&self) -> bool {
1092+ self.is_pending_windowed_fullscreen
1093+ }
1094+
1095+ fn request_windowed_fullscreen(&mut self, value: bool) {
1096+ if self.is_pending_windowed_fullscreen == value {
1097+ return;
1098+ }
1099+
1100+ self.is_pending_windowed_fullscreen = value;
1101+
1102+ // Set the fullscreen state to match.
1103+ //
1104+ // When going from windowed to real fullscreen, we'll use request_size() which will set the
1105+ // fullscreen state back.
1106+ self.toplevel().with_pending_state(|state| {
1107+ if value {
1108+ state.states.set(xdg_toplevel::State::Fullscreen);
1109+ } else {
1110+ state.states.unset(xdg_toplevel::State::Fullscreen);
1111+ }
1112+ });
1113+
1114+ // Make sure we recieve a commit later to update self.is_windowed_fullscreen.
1115+ self.needs_configure = true;
1116+ }
1117+
1037 fn is_child_of(&self, parent: &Self) -> bool {1118 fn is_child_of(&self, parent: &Self) -> bool {
1038 self.toplevel().parent().as_ref() == Some(parent.toplevel().wl_surface())1119 self.toplevel().parent().as_ref() == Some(parent.toplevel().wl_surface())
1039 }1120 }
@@ -1098,5 +1179,12 @@ impl LayoutElement for Mapped {
1098 self.request_size_once = Some(RequestSizeOnce::UseWindowSize);1179 self.request_size_once = Some(RequestSizeOnce::UseWindowSize);
1099 }1180 }
1100 }1181 }
1182+
1183+ // HACK: this is not really accurate because the commit might be for an earlier serial than
1184+ // when we requested windowed fullscren. But we don't actually care much, since this is
1185+ // entirely compositor state. We're only tying it to configure/commit as a workaround to
1186+ // the rest of the code expecting that fullscreen doesn't suddenly just change in the
1187+ // middle of something.
1188+ self.is_windowed_fullscreen = self.is_pending_windowed_fullscreen;
1101 }1189 }
1102 }1190 }