From 9955d921ce6491e34fb74ec94f30a7cca76826e4 Mon Sep 17 00:00:00 2001 From: LuckShiba Date: Fri, 6 Nov 2026 12:23:30 -0300 Subject: [PATCH] feat: add set/unset fullscreen/maximized-to-edges actions Adds the following actions: - `set-window-fullscreen` and `unset-window-fullscreen`; - `set-window-maximized-to-edges` and `unset-window-maximized-to-edges`; - `set-windowed-fullscreen` and `unset-windowed-fullscreen`. All of them also support an optional `--id` when called from the IPC. --- niri-config/src/binds.rs | 46 +++++++++++++++++++ niri-ipc/src/lib.rs | 69 +++++++++++++++++++++++++++++ src/input/mod.rs | 96 ++++++++++++++++++++++++++++++++++++++++ src/layout/mod.rs | 25 +++++++++++ 4 files changed, 236 insertions(+) diff --git a/niri-config/src/binds.rs b/niri-config/src/binds.rs index fff4817f..c5d067e1 100644 --- a/niri-config/src/binds.rs +++ b/niri-config/src/binds.rs @@ -291,6 +291,24 @@ pub enum Action { ToggleWindowedFullscreen, #[knuffel(skip)] ToggleWindowedFullscreenById(u64), + SetWindowFullscreen, + #[knuffel(skip)] + SetWindowFullscreenById(u64), + UnsetWindowFullscreen, + #[knuffel(skip)] + UnsetWindowFullscreenById(u64), + SetWindowMaximizedToEdges, + #[knuffel(skip)] + SetWindowMaximizedToEdgesById(u64), + UnsetWindowMaximizedToEdges, + #[knuffel(skip)] + UnsetWindowMaximizedToEdgesById(u64), + SetWindowedFullscreen, + #[knuffel(skip)] + SetWindowedFullscreenById(u64), + UnsetWindowedFullscreen, + #[knuffel(skip)] + UnsetWindowedFullscreenById(u64), #[knuffel(skip)] FocusWindow(u64), FocusWindowInColumn(#[knuffel(argument)] u8), @@ -581,6 +599,34 @@ impl From for Action { niri_ipc::Action::ToggleWindowedFullscreen { id: Some(id) } => { Self::ToggleWindowedFullscreenById(id) } + niri_ipc::Action::SetWindowFullscreen { id: None } => Self::SetWindowFullscreen, + niri_ipc::Action::SetWindowFullscreen { id: Some(id) } => { + Self::SetWindowFullscreenById(id) + } + niri_ipc::Action::UnsetWindowFullscreen { id: None } => Self::UnsetWindowFullscreen, + niri_ipc::Action::UnsetWindowFullscreen { id: Some(id) } => { + Self::UnsetWindowFullscreenById(id) + } + niri_ipc::Action::SetWindowMaximizedToEdges { id: None } => { + Self::SetWindowMaximizedToEdges + } + niri_ipc::Action::SetWindowMaximizedToEdges { id: Some(id) } => { + Self::SetWindowMaximizedToEdgesById(id) + } + niri_ipc::Action::UnsetWindowMaximizedToEdges { id: None } => { + Self::UnsetWindowMaximizedToEdges + } + niri_ipc::Action::UnsetWindowMaximizedToEdges { id: Some(id) } => { + Self::UnsetWindowMaximizedToEdgesById(id) + } + niri_ipc::Action::SetWindowedFullscreen { id: None } => Self::SetWindowedFullscreen, + niri_ipc::Action::SetWindowedFullscreen { id: Some(id) } => { + Self::SetWindowedFullscreenById(id) + } + niri_ipc::Action::UnsetWindowedFullscreen { id: None } => Self::UnsetWindowedFullscreen, + niri_ipc::Action::UnsetWindowedFullscreen { id: Some(id) } => { + Self::UnsetWindowedFullscreenById(id) + } niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id), niri_ipc::Action::FocusWindowInColumn { index } => Self::FocusWindowInColumn(index), niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious, diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs index c3711924..5120c18e 100644 --- a/niri-ipc/src/lib.rs +++ b/niri-ipc/src/lib.rs @@ -330,6 +330,75 @@ pub enum Action { #[cfg_attr(feature = "clap", arg(long))] id: Option, }, + /// Make a window fullscreen. + #[cfg_attr(feature = "clap", clap(about = "Make the focused window fullscreen"))] + SetWindowFullscreen { + /// Id of the window to make fullscreen. + /// + /// If `None`, uses the focused window. + #[cfg_attr(feature = "clap", arg(long))] + id: Option, + }, + /// Take a window out of fullscreen. + #[cfg_attr( + feature = "clap", + clap(about = "Take the focused window out of fullscreen") + )] + UnsetWindowFullscreen { + /// Id of the window to take out of fullscreen. + /// + /// If `None`, uses the focused window. + #[cfg_attr(feature = "clap", arg(long))] + id: Option, + }, + /// Maximize a window to the screen edges. + #[cfg_attr( + feature = "clap", + clap(about = "Maximize the focused window to the screen edges") + )] + SetWindowMaximizedToEdges { + /// Id of the window to maximize to edges. + /// + /// If `None`, uses the focused window. + #[cfg_attr(feature = "clap", arg(long))] + id: Option, + }, + /// Unmaximize a window from the screen edges. + #[cfg_attr( + feature = "clap", + clap(about = "Unmaximize the focused window from the screen edges") + )] + UnsetWindowMaximizedToEdges { + /// Id of the window to unmaximize from edges. + /// + /// If `None`, uses the focused window. + #[cfg_attr(feature = "clap", arg(long))] + id: Option, + }, + /// Enable windowed (fake) fullscreen on a window. + #[cfg_attr( + feature = "clap", + clap(about = "Enable windowed (fake) fullscreen on the focused window") + )] + SetWindowedFullscreen { + /// Id of the window to enable windowed fullscreen on. + /// + /// If `None`, uses the focused window. + #[cfg_attr(feature = "clap", arg(long))] + id: Option, + }, + /// Disable windowed (fake) fullscreen on a window. + #[cfg_attr( + feature = "clap", + clap(about = "Disable windowed (fake) fullscreen on the focused window") + )] + UnsetWindowedFullscreen { + /// Id of the window to disable windowed fullscreen on. + /// + /// If `None`, uses the focused window. + #[cfg_attr(feature = "clap", arg(long))] + id: Option, + }, /// Focus a window by id. FocusWindow { /// Id of the window to focus. diff --git a/src/input/mod.rs b/src/input/mod.rs index b8518e96..069a9f5d 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1100,6 +1100,102 @@ impl State { self.niri.queue_redraw_all(); } } + Action::SetWindowFullscreen => { + let focus = self.niri.layout.focus().map(|m| m.window.clone()); + if let Some(window) = focus { + self.niri.layout.set_fullscreen(&window, true); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::SetWindowFullscreenById(id) => { + let id = MappedId::specific(id); + if let Some(window) = self.niri.find_window_by_id(id) { + self.niri.layout.set_fullscreen(&window, true); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::UnsetWindowFullscreen => { + let focus = self.niri.layout.focus().map(|m| m.window.clone()); + if let Some(window) = focus { + self.niri.layout.set_fullscreen(&window, false); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::UnsetWindowFullscreenById(id) => { + let id = MappedId::specific(id); + if let Some(window) = self.niri.find_window_by_id(id) { + self.niri.layout.set_fullscreen(&window, false); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::SetWindowedFullscreen => { + let focus = self.niri.layout.focus().map(|m| m.window.clone()); + if let Some(window) = focus { + self.niri.layout.set_windowed_fullscreen(&window, true); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::SetWindowedFullscreenById(id) => { + let id = MappedId::specific(id); + if let Some(window) = self.niri.find_window_by_id(id) { + self.niri.layout.set_windowed_fullscreen(&window, true); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::UnsetWindowedFullscreen => { + let focus = self.niri.layout.focus().map(|m| m.window.clone()); + if let Some(window) = focus { + self.niri.layout.set_windowed_fullscreen(&window, false); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::UnsetWindowedFullscreenById(id) => { + let id = MappedId::specific(id); + if let Some(window) = self.niri.find_window_by_id(id) { + self.niri.layout.set_windowed_fullscreen(&window, false); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::SetWindowMaximizedToEdges => { + let focus = self.niri.layout.focus().map(|m| m.window.clone()); + if let Some(window) = focus { + self.niri.layout.set_maximized(&window, true); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::SetWindowMaximizedToEdgesById(id) => { + let id = MappedId::specific(id); + if let Some(window) = self.niri.find_window_by_id(id) { + self.niri.layout.set_maximized(&window, true); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::UnsetWindowMaximizedToEdges => { + let focus = self.niri.layout.focus().map(|m| m.window.clone()); + if let Some(window) = focus { + self.niri.layout.set_maximized(&window, false); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } + Action::UnsetWindowMaximizedToEdgesById(id) => { + let id = MappedId::specific(id); + if let Some(window) = self.niri.find_window_by_id(id) { + self.niri.layout.set_maximized(&window, false); + // FIXME: granular + self.niri.queue_redraw_all(); + } + } Action::FocusWindow(id) => { let id = MappedId::specific(id); if let Some(window) = self.niri.find_window_by_id(id) { diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 8575a1af..13594c7b 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -3583,6 +3583,31 @@ impl Layout { } } + pub fn set_windowed_fullscreen(&mut self, id: &W::Id, fullscreen: bool) { + let (_, window) = self.windows().find(|(_, win)| win.id() == id).unwrap(); + + if window.is_pending_windowed_fullscreen() == fullscreen { + return; + } + + if window.pending_sizing_mode().is_fullscreen() { + // Remove the real fullscreen. + for ws in self.workspaces_mut() { + if ws.has_window(id) { + ws.set_fullscreen(id, false); + break; + } + } + } + + // This will switch is_pending_fullscreen() to false right away. + self.with_windows_mut(|window, _| { + if window.id() == id { + window.request_windowed_fullscreen(fullscreen); + } + }); + } + pub fn toggle_windowed_fullscreen(&mut self, id: &W::Id) { let (_, window) = self.windows().find(|(_, win)| win.id() == id).unwrap(); if window.pending_sizing_mode().is_fullscreen() {