Handle un-/fullscreen after initial configure
Browse files at this commit506dcd99d7fafbe94f0444aed46c2f89f29612daParent: dfbc0241 changed file +95 -6
- src/handlers/xdg_shell.rs +95 -6
src/handlers/xdg_shell.rsmodified+95 -6
| @@ -267,6 +267,8 @@ impl XdgShellHandler for State { | |||
| 267 | toplevel: ToplevelSurface, | 267 | toplevel: ToplevelSurface, |
| 268 | wl_output: Option<wl_output::WlOutput>, | 268 | wl_output: Option<wl_output::WlOutput>, |
| 269 | ) { | 269 | ) { |
| 270 | + let requested_output = wl_output.as_ref().and_then(Output::from_resource); | ||
| 271 | + | ||
| 270 | if let Some((window, current_output)) = self | 272 | if let Some((window, current_output)) = self |
| 271 | .niri | 273 | .niri |
| 272 | .layout | 274 | .layout |
| @@ -274,7 +276,7 @@ impl XdgShellHandler for State { | |||
| 274 | { | 276 | { |
| 275 | let window = window.clone(); | 277 | let window = window.clone(); |
| 276 | 278 | ||
| 277 | - if let Some(requested_output) = wl_output.as_ref().and_then(Output::from_resource) { | 279 | + if let Some(requested_output) = requested_output { |
| 278 | if &requested_output != current_output { | 280 | if &requested_output != current_output { |
| 279 | self.niri | 281 | self.niri |
| 280 | .layout | 282 | .layout |
| @@ -290,12 +292,51 @@ impl XdgShellHandler for State { | |||
| 290 | } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) { | 292 | } else if let Some(unmapped) = self.niri.unmapped_windows.get_mut(toplevel.wl_surface()) { |
| 291 | match &mut unmapped.state { | 293 | match &mut unmapped.state { |
| 292 | InitialConfigureState::NotConfigured { wants_fullscreen } => { | 294 | InitialConfigureState::NotConfigured { wants_fullscreen } => { |
| 293 | - *wants_fullscreen = Some(wl_output.as_ref().and_then(Output::from_resource)); | 295 | + *wants_fullscreen = Some(requested_output); |
| 294 | 296 | ||
| 295 | // The required configure will be the initial configure. | 297 | // The required configure will be the initial configure. |
| 296 | } | 298 | } |
| 297 | - InitialConfigureState::Configured { .. } => { | 299 | + InitialConfigureState::Configured { output, .. } => { |
| 298 | - // FIXME: implement this once I figure out a good way without code duplication. | 300 | + // Figure out the monitor following a similar logic to initial configure. |
| 301 | + // FIXME: deduplicate. | ||
| 302 | + let mon = requested_output | ||
| 303 | + .as_ref() | ||
| 304 | + // If none requested, try currently configured output. | ||
| 305 | + .or(output.as_ref()) | ||
| 306 | + .and_then(|o| self.niri.layout.monitor_for_output(o)) | ||
| 307 | + .map(|mon| (mon, false)) | ||
| 308 | + // If not, check if we have a parent with a monitor. | ||
| 309 | + .or_else(|| { | ||
| 310 | + toplevel | ||
| 311 | + .parent() | ||
| 312 | + .and_then(|parent| self.niri.layout.find_window_and_output(&parent)) | ||
| 313 | + .map(|(_win, output)| output) | ||
| 314 | + .and_then(|o| self.niri.layout.monitor_for_output(o)) | ||
| 315 | + .map(|mon| (mon, true)) | ||
| 316 | + }) | ||
| 317 | + // If not, fall back to the active monitor. | ||
| 318 | + .or_else(|| { | ||
| 319 | + self.niri | ||
| 320 | + .layout | ||
| 321 | + .active_monitor_ref() | ||
| 322 | + .map(|mon| (mon, false)) | ||
| 323 | + }); | ||
| 324 | + | ||
| 325 | + *output = mon | ||
| 326 | + .filter(|(_, parent)| !parent) | ||
| 327 | + .map(|(mon, _)| mon.output.clone()); | ||
| 328 | + let mon = mon.map(|(mon, _)| mon); | ||
| 329 | + | ||
| 330 | + let ws = mon | ||
| 331 | + .map(|mon| mon.active_workspace_ref()) | ||
| 332 | + .or_else(|| self.niri.layout.active_workspace()); | ||
| 333 | + | ||
| 334 | + if let Some(ws) = ws { | ||
| 335 | + toplevel.with_pending_state(|state| { | ||
| 336 | + state.states.set(xdg_toplevel::State::Fullscreen); | ||
| 337 | + }); | ||
| 338 | + ws.configure_new_window(&unmapped.window, None); | ||
| 339 | + } | ||
| 299 | 340 | ||
| 300 | // We already sent the initial configure, so we need to reconfigure. | 341 | // We already sent the initial configure, so we need to reconfigure. |
| 301 | toplevel.send_configure(); | 342 | toplevel.send_configure(); |
| @@ -326,8 +367,56 @@ impl XdgShellHandler for State { | |||
| 326 | 367 | ||
| 327 | // The required configure will be the initial configure. | 368 | // The required configure will be the initial configure. |
| 328 | } | 369 | } |
| 329 | - InitialConfigureState::Configured { .. } => { | 370 | + InitialConfigureState::Configured { |
| 330 | - // FIXME: implement this once I figure out a good way without code duplication. | 371 | + width, |
| 372 | + is_full_width, | ||
| 373 | + output, | ||
| 374 | + .. | ||
| 375 | + } => { | ||
| 376 | + // Figure out the monitor following a similar logic to initial configure. | ||
| 377 | + // FIXME: deduplicate. | ||
| 378 | + let mon = output | ||
| 379 | + .as_ref() | ||
| 380 | + .and_then(|o| self.niri.layout.monitor_for_output(o)) | ||
| 381 | + .map(|mon| (mon, false)) | ||
| 382 | + // If not, check if we have a parent with a monitor. | ||
| 383 | + .or_else(|| { | ||
| 384 | + toplevel | ||
| 385 | + .parent() | ||
| 386 | + .and_then(|parent| self.niri.layout.find_window_and_output(&parent)) | ||
| 387 | + .map(|(_win, output)| output) | ||
| 388 | + .and_then(|o| self.niri.layout.monitor_for_output(o)) | ||
| 389 | + .map(|mon| (mon, true)) | ||
| 390 | + }) | ||
| 391 | + // If not, fall back to the active monitor. | ||
| 392 | + .or_else(|| { | ||
| 393 | + self.niri | ||
| 394 | + .layout | ||
| 395 | + .active_monitor_ref() | ||
| 396 | + .map(|mon| (mon, false)) | ||
| 397 | + }); | ||
| 398 | + | ||
| 399 | + *output = mon | ||
| 400 | + .filter(|(_, parent)| !parent) | ||
| 401 | + .map(|(mon, _)| mon.output.clone()); | ||
| 402 | + let mon = mon.map(|(mon, _)| mon); | ||
| 403 | + | ||
| 404 | + let ws = mon | ||
| 405 | + .map(|mon| mon.active_workspace_ref()) | ||
| 406 | + .or_else(|| self.niri.layout.active_workspace()); | ||
| 407 | + | ||
| 408 | + if let Some(ws) = ws { | ||
| 409 | + toplevel.with_pending_state(|state| { | ||
| 410 | + state.states.unset(xdg_toplevel::State::Fullscreen); | ||
| 411 | + }); | ||
| 412 | + | ||
| 413 | + let configure_width = if *is_full_width { | ||
| 414 | + Some(ColumnWidth::Proportion(1.)) | ||
| 415 | + } else { | ||
| 416 | + *width | ||
| 417 | + }; | ||
| 418 | + ws.configure_new_window(&unmapped.window, configure_width); | ||
| 419 | + } | ||
| 331 | 420 | ||
| 332 | // We already sent the initial configure, so we need to reconfigure. | 421 | // We already sent the initial configure, so we need to reconfigure. |
| 333 | toplevel.send_configure(); | 422 | toplevel.send_configure(); |