Add set/unset fullscreen/maximized-to-edges actions
Browse files at this commit9955d921ce6491e34fb74ec94f30a7cca76826e4Parent: e7a9281- feat
- add set/unset fullscreen/maximized-to-edges actions
4 changed files +236 -0
- niri-config/src/binds.rs +46 -0
- niri-ipc/src/lib.rs +69 -0
- src/input/mod.rs +96 -0
- src/layout/mod.rs +25 -0
niri-config/src/binds.rsmodified+46 -0
| @@ -291,6 +291,24 @@ pub enum Action { | |||
| 291 | ToggleWindowedFullscreen, | 291 | ToggleWindowedFullscreen, |
| 292 | #[knuffel(skip)] | 292 | #[knuffel(skip)] |
| 293 | ToggleWindowedFullscreenById(u64), | 293 | ToggleWindowedFullscreenById(u64), |
| 294 | + SetWindowFullscreen, | ||
| 295 | + #[knuffel(skip)] | ||
| 296 | + SetWindowFullscreenById(u64), | ||
| 297 | + UnsetWindowFullscreen, | ||
| 298 | + #[knuffel(skip)] | ||
| 299 | + UnsetWindowFullscreenById(u64), | ||
| 300 | + SetWindowMaximizedToEdges, | ||
| 301 | + #[knuffel(skip)] | ||
| 302 | + SetWindowMaximizedToEdgesById(u64), | ||
| 303 | + UnsetWindowMaximizedToEdges, | ||
| 304 | + #[knuffel(skip)] | ||
| 305 | + UnsetWindowMaximizedToEdgesById(u64), | ||
| 306 | + SetWindowedFullscreen, | ||
| 307 | + #[knuffel(skip)] | ||
| 308 | + SetWindowedFullscreenById(u64), | ||
| 309 | + UnsetWindowedFullscreen, | ||
| 310 | + #[knuffel(skip)] | ||
| 311 | + UnsetWindowedFullscreenById(u64), | ||
| 294 | #[knuffel(skip)] | 312 | #[knuffel(skip)] |
| 295 | FocusWindow(u64), | 313 | FocusWindow(u64), |
| 296 | FocusWindowInColumn(#[knuffel(argument)] u8), | 314 | FocusWindowInColumn(#[knuffel(argument)] u8), |
| @@ -581,6 +599,34 @@ impl From<niri_ipc::Action> for Action { | |||
| 581 | niri_ipc::Action::ToggleWindowedFullscreen { id: Some(id) } => { | 599 | niri_ipc::Action::ToggleWindowedFullscreen { id: Some(id) } => { |
| 582 | Self::ToggleWindowedFullscreenById(id) | 600 | Self::ToggleWindowedFullscreenById(id) |
| 583 | } | 601 | } |
| 602 | + niri_ipc::Action::SetWindowFullscreen { id: None } => Self::SetWindowFullscreen, | ||
| 603 | + niri_ipc::Action::SetWindowFullscreen { id: Some(id) } => { | ||
| 604 | + Self::SetWindowFullscreenById(id) | ||
| 605 | + } | ||
| 606 | + niri_ipc::Action::UnsetWindowFullscreen { id: None } => Self::UnsetWindowFullscreen, | ||
| 607 | + niri_ipc::Action::UnsetWindowFullscreen { id: Some(id) } => { | ||
| 608 | + Self::UnsetWindowFullscreenById(id) | ||
| 609 | + } | ||
| 610 | + niri_ipc::Action::SetWindowMaximizedToEdges { id: None } => { | ||
| 611 | + Self::SetWindowMaximizedToEdges | ||
| 612 | + } | ||
| 613 | + niri_ipc::Action::SetWindowMaximizedToEdges { id: Some(id) } => { | ||
| 614 | + Self::SetWindowMaximizedToEdgesById(id) | ||
| 615 | + } | ||
| 616 | + niri_ipc::Action::UnsetWindowMaximizedToEdges { id: None } => { | ||
| 617 | + Self::UnsetWindowMaximizedToEdges | ||
| 618 | + } | ||
| 619 | + niri_ipc::Action::UnsetWindowMaximizedToEdges { id: Some(id) } => { | ||
| 620 | + Self::UnsetWindowMaximizedToEdgesById(id) | ||
| 621 | + } | ||
| 622 | + niri_ipc::Action::SetWindowedFullscreen { id: None } => Self::SetWindowedFullscreen, | ||
| 623 | + niri_ipc::Action::SetWindowedFullscreen { id: Some(id) } => { | ||
| 624 | + Self::SetWindowedFullscreenById(id) | ||
| 625 | + } | ||
| 626 | + niri_ipc::Action::UnsetWindowedFullscreen { id: None } => Self::UnsetWindowedFullscreen, | ||
| 627 | + niri_ipc::Action::UnsetWindowedFullscreen { id: Some(id) } => { | ||
| 628 | + Self::UnsetWindowedFullscreenById(id) | ||
| 629 | + } | ||
| 584 | niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id), | 630 | niri_ipc::Action::FocusWindow { id } => Self::FocusWindow(id), |
| 585 | niri_ipc::Action::FocusWindowInColumn { index } => Self::FocusWindowInColumn(index), | 631 | niri_ipc::Action::FocusWindowInColumn { index } => Self::FocusWindowInColumn(index), |
| 586 | niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious, | 632 | niri_ipc::Action::FocusWindowPrevious {} => Self::FocusWindowPrevious, |
niri-ipc/src/lib.rsmodified+69 -0
| @@ -330,6 +330,75 @@ pub enum Action { | |||
| 330 | #[cfg_attr(feature = "clap", arg(long))] | 330 | #[cfg_attr(feature = "clap", arg(long))] |
| 331 | id: Option<u64>, | 331 | id: Option<u64>, |
| 332 | }, | 332 | }, |
| 333 | + /// Make a window fullscreen. | ||
| 334 | + #[cfg_attr(feature = "clap", clap(about = "Make the focused window fullscreen"))] | ||
| 335 | + SetWindowFullscreen { | ||
| 336 | + /// Id of the window to make fullscreen. | ||
| 337 | + /// | ||
| 338 | + /// If `None`, uses the focused window. | ||
| 339 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 340 | + id: Option<u64>, | ||
| 341 | + }, | ||
| 342 | + /// Take a window out of fullscreen. | ||
| 343 | + #[cfg_attr( | ||
| 344 | + feature = "clap", | ||
| 345 | + clap(about = "Take the focused window out of fullscreen") | ||
| 346 | + )] | ||
| 347 | + UnsetWindowFullscreen { | ||
| 348 | + /// Id of the window to take out of fullscreen. | ||
| 349 | + /// | ||
| 350 | + /// If `None`, uses the focused window. | ||
| 351 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 352 | + id: Option<u64>, | ||
| 353 | + }, | ||
| 354 | + /// Maximize a window to the screen edges. | ||
| 355 | + #[cfg_attr( | ||
| 356 | + feature = "clap", | ||
| 357 | + clap(about = "Maximize the focused window to the screen edges") | ||
| 358 | + )] | ||
| 359 | + SetWindowMaximizedToEdges { | ||
| 360 | + /// Id of the window to maximize to edges. | ||
| 361 | + /// | ||
| 362 | + /// If `None`, uses the focused window. | ||
| 363 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 364 | + id: Option<u64>, | ||
| 365 | + }, | ||
| 366 | + /// Unmaximize a window from the screen edges. | ||
| 367 | + #[cfg_attr( | ||
| 368 | + feature = "clap", | ||
| 369 | + clap(about = "Unmaximize the focused window from the screen edges") | ||
| 370 | + )] | ||
| 371 | + UnsetWindowMaximizedToEdges { | ||
| 372 | + /// Id of the window to unmaximize from edges. | ||
| 373 | + /// | ||
| 374 | + /// If `None`, uses the focused window. | ||
| 375 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 376 | + id: Option<u64>, | ||
| 377 | + }, | ||
| 378 | + /// Enable windowed (fake) fullscreen on a window. | ||
| 379 | + #[cfg_attr( | ||
| 380 | + feature = "clap", | ||
| 381 | + clap(about = "Enable windowed (fake) fullscreen on the focused window") | ||
| 382 | + )] | ||
| 383 | + SetWindowedFullscreen { | ||
| 384 | + /// Id of the window to enable windowed fullscreen on. | ||
| 385 | + /// | ||
| 386 | + /// If `None`, uses the focused window. | ||
| 387 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 388 | + id: Option<u64>, | ||
| 389 | + }, | ||
| 390 | + /// Disable windowed (fake) fullscreen on a window. | ||
| 391 | + #[cfg_attr( | ||
| 392 | + feature = "clap", | ||
| 393 | + clap(about = "Disable windowed (fake) fullscreen on the focused window") | ||
| 394 | + )] | ||
| 395 | + UnsetWindowedFullscreen { | ||
| 396 | + /// Id of the window to disable windowed fullscreen on. | ||
| 397 | + /// | ||
| 398 | + /// If `None`, uses the focused window. | ||
| 399 | + #[cfg_attr(feature = "clap", arg(long))] | ||
| 400 | + id: Option<u64>, | ||
| 401 | + }, | ||
| 333 | /// Focus a window by id. | 402 | /// Focus a window by id. |
| 334 | FocusWindow { | 403 | FocusWindow { |
| 335 | /// Id of the window to focus. | 404 | /// Id of the window to focus. |
src/input/mod.rsmodified+96 -0
| @@ -1100,6 +1100,102 @@ impl State { | |||
| 1100 | self.niri.queue_redraw_all(); | 1100 | self.niri.queue_redraw_all(); |
| 1101 | } | 1101 | } |
| 1102 | } | 1102 | } |
| 1103 | + Action::SetWindowFullscreen => { | ||
| 1104 | + let focus = self.niri.layout.focus().map(|m| m.window.clone()); | ||
| 1105 | + if let Some(window) = focus { | ||
| 1106 | + self.niri.layout.set_fullscreen(&window, true); | ||
| 1107 | + // FIXME: granular | ||
| 1108 | + self.niri.queue_redraw_all(); | ||
| 1109 | + } | ||
| 1110 | + } | ||
| 1111 | + Action::SetWindowFullscreenById(id) => { | ||
| 1112 | + let id = MappedId::specific(id); | ||
| 1113 | + if let Some(window) = self.niri.find_window_by_id(id) { | ||
| 1114 | + self.niri.layout.set_fullscreen(&window, true); | ||
| 1115 | + // FIXME: granular | ||
| 1116 | + self.niri.queue_redraw_all(); | ||
| 1117 | + } | ||
| 1118 | + } | ||
| 1119 | + Action::UnsetWindowFullscreen => { | ||
| 1120 | + let focus = self.niri.layout.focus().map(|m| m.window.clone()); | ||
| 1121 | + if let Some(window) = focus { | ||
| 1122 | + self.niri.layout.set_fullscreen(&window, false); | ||
| 1123 | + // FIXME: granular | ||
| 1124 | + self.niri.queue_redraw_all(); | ||
| 1125 | + } | ||
| 1126 | + } | ||
| 1127 | + Action::UnsetWindowFullscreenById(id) => { | ||
| 1128 | + let id = MappedId::specific(id); | ||
| 1129 | + if let Some(window) = self.niri.find_window_by_id(id) { | ||
| 1130 | + self.niri.layout.set_fullscreen(&window, false); | ||
| 1131 | + // FIXME: granular | ||
| 1132 | + self.niri.queue_redraw_all(); | ||
| 1133 | + } | ||
| 1134 | + } | ||
| 1135 | + Action::SetWindowedFullscreen => { | ||
| 1136 | + let focus = self.niri.layout.focus().map(|m| m.window.clone()); | ||
| 1137 | + if let Some(window) = focus { | ||
| 1138 | + self.niri.layout.set_windowed_fullscreen(&window, true); | ||
| 1139 | + // FIXME: granular | ||
| 1140 | + self.niri.queue_redraw_all(); | ||
| 1141 | + } | ||
| 1142 | + } | ||
| 1143 | + Action::SetWindowedFullscreenById(id) => { | ||
| 1144 | + let id = MappedId::specific(id); | ||
| 1145 | + if let Some(window) = self.niri.find_window_by_id(id) { | ||
| 1146 | + self.niri.layout.set_windowed_fullscreen(&window, true); | ||
| 1147 | + // FIXME: granular | ||
| 1148 | + self.niri.queue_redraw_all(); | ||
| 1149 | + } | ||
| 1150 | + } | ||
| 1151 | + Action::UnsetWindowedFullscreen => { | ||
| 1152 | + let focus = self.niri.layout.focus().map(|m| m.window.clone()); | ||
| 1153 | + if let Some(window) = focus { | ||
| 1154 | + self.niri.layout.set_windowed_fullscreen(&window, false); | ||
| 1155 | + // FIXME: granular | ||
| 1156 | + self.niri.queue_redraw_all(); | ||
| 1157 | + } | ||
| 1158 | + } | ||
| 1159 | + Action::UnsetWindowedFullscreenById(id) => { | ||
| 1160 | + let id = MappedId::specific(id); | ||
| 1161 | + if let Some(window) = self.niri.find_window_by_id(id) { | ||
| 1162 | + self.niri.layout.set_windowed_fullscreen(&window, false); | ||
| 1163 | + // FIXME: granular | ||
| 1164 | + self.niri.queue_redraw_all(); | ||
| 1165 | + } | ||
| 1166 | + } | ||
| 1167 | + Action::SetWindowMaximizedToEdges => { | ||
| 1168 | + let focus = self.niri.layout.focus().map(|m| m.window.clone()); | ||
| 1169 | + if let Some(window) = focus { | ||
| 1170 | + self.niri.layout.set_maximized(&window, true); | ||
| 1171 | + // FIXME: granular | ||
| 1172 | + self.niri.queue_redraw_all(); | ||
| 1173 | + } | ||
| 1174 | + } | ||
| 1175 | + Action::SetWindowMaximizedToEdgesById(id) => { | ||
| 1176 | + let id = MappedId::specific(id); | ||
| 1177 | + if let Some(window) = self.niri.find_window_by_id(id) { | ||
| 1178 | + self.niri.layout.set_maximized(&window, true); | ||
| 1179 | + // FIXME: granular | ||
| 1180 | + self.niri.queue_redraw_all(); | ||
| 1181 | + } | ||
| 1182 | + } | ||
| 1183 | + Action::UnsetWindowMaximizedToEdges => { | ||
| 1184 | + let focus = self.niri.layout.focus().map(|m| m.window.clone()); | ||
| 1185 | + if let Some(window) = focus { | ||
| 1186 | + self.niri.layout.set_maximized(&window, false); | ||
| 1187 | + // FIXME: granular | ||
| 1188 | + self.niri.queue_redraw_all(); | ||
| 1189 | + } | ||
| 1190 | + } | ||
| 1191 | + Action::UnsetWindowMaximizedToEdgesById(id) => { | ||
| 1192 | + let id = MappedId::specific(id); | ||
| 1193 | + if let Some(window) = self.niri.find_window_by_id(id) { | ||
| 1194 | + self.niri.layout.set_maximized(&window, false); | ||
| 1195 | + // FIXME: granular | ||
| 1196 | + self.niri.queue_redraw_all(); | ||
| 1197 | + } | ||
| 1198 | + } | ||
| 1103 | Action::FocusWindow(id) => { | 1199 | Action::FocusWindow(id) => { |
| 1104 | let id = MappedId::specific(id); | 1200 | let id = MappedId::specific(id); |
| 1105 | if let Some(window) = self.niri.find_window_by_id(id) { | 1201 | if let Some(window) = self.niri.find_window_by_id(id) { |
src/layout/mod.rsmodified+25 -0
| @@ -3583,6 +3583,31 @@ impl<W: LayoutElement> Layout<W> { | |||
| 3583 | } | 3583 | } |
| 3584 | } | 3584 | } |
| 3585 | 3585 | ||
| 3586 | + pub fn set_windowed_fullscreen(&mut self, id: &W::Id, fullscreen: bool) { | ||
| 3587 | + let (_, window) = self.windows().find(|(_, win)| win.id() == id).unwrap(); | ||
| 3588 | + | ||
| 3589 | + if window.is_pending_windowed_fullscreen() == fullscreen { | ||
| 3590 | + return; | ||
| 3591 | + } | ||
| 3592 | + | ||
| 3593 | + if window.pending_sizing_mode().is_fullscreen() { | ||
| 3594 | + // Remove the real fullscreen. | ||
| 3595 | + for ws in self.workspaces_mut() { | ||
| 3596 | + if ws.has_window(id) { | ||
| 3597 | + ws.set_fullscreen(id, false); | ||
| 3598 | + break; | ||
| 3599 | + } | ||
| 3600 | + } | ||
| 3601 | + } | ||
| 3602 | + | ||
| 3603 | + // This will switch is_pending_fullscreen() to false right away. | ||
| 3604 | + self.with_windows_mut(|window, _| { | ||
| 3605 | + if window.id() == id { | ||
| 3606 | + window.request_windowed_fullscreen(fullscreen); | ||
| 3607 | + } | ||
| 3608 | + }); | ||
| 3609 | + } | ||
| 3610 | + | ||
| 3586 | pub fn toggle_windowed_fullscreen(&mut self, id: &W::Id) { | 3611 | pub fn toggle_windowed_fullscreen(&mut self, id: &W::Id) { |
| 3587 | let (_, window) = self.windows().find(|(_, win)| win.id() == id).unwrap(); | 3612 | let (_, window) = self.windows().find(|(_, win)| win.id() == id).unwrap(); |
| 3588 | if window.pending_sizing_mode().is_fullscreen() { | 3613 | if window.pending_sizing_mode().is_fullscreen() { |