Add un/fullscreen support
Browse files at this commit91a809b755977f57c1c1fc0da09dfc1cd2483d87Parent: f9c7fe41 changed file +75 -1
- src/handlers/xdg_shell.rs +75 -1
src/handlers/xdg_shell.rsmodified+75 -1
| @@ -2,12 +2,14 @@ use smithay::delegate_xdg_shell; | |||
| 2 | use smithay::desktop::{PopupKind, Window}; | 2 | use smithay::desktop::{PopupKind, Window}; |
| 3 | use smithay::input::pointer::{Focus, GrabStartData as PointerGrabStartData}; | 3 | use smithay::input::pointer::{Focus, GrabStartData as PointerGrabStartData}; |
| 4 | use smithay::input::Seat; | 4 | use smithay::input::Seat; |
| 5 | +use smithay::output::Output; | ||
| 5 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 6 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| 6 | -use smithay::reexports::wayland_server::protocol::wl_seat; | ||
| 7 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 7 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 8 | +use smithay::reexports::wayland_server::protocol::{wl_output, wl_seat}; | ||
| 8 | use smithay::reexports::wayland_server::Resource; | 9 | use smithay::reexports::wayland_server::Resource; |
| 9 | use smithay::utils::{Rectangle, Serial}; | 10 | use smithay::utils::{Rectangle, Serial}; |
| 10 | use smithay::wayland::compositor::with_states; | 11 | use smithay::wayland::compositor::with_states; |
| 12 | +use smithay::wayland::seat::WaylandFocus; | ||
| 11 | use smithay::wayland::shell::xdg::{ | 13 | use smithay::wayland::shell::xdg::{ |
| 12 | PopupSurface, PositionerState, ToplevelSurface, XdgPopupSurfaceData, XdgShellHandler, | 14 | PopupSurface, PositionerState, ToplevelSurface, XdgPopupSurfaceData, XdgShellHandler, |
| 13 | XdgShellState, XdgToplevelSurfaceData, | 15 | XdgShellState, XdgToplevelSurfaceData, |
| @@ -173,6 +175,78 @@ impl XdgShellHandler for Niri { | |||
| 173 | surface.send_pending_configure(); | 175 | surface.send_pending_configure(); |
| 174 | } | 176 | } |
| 175 | 177 | ||
| 178 | + fn fullscreen_request( | ||
| 179 | + &mut self, | ||
| 180 | + surface: ToplevelSurface, | ||
| 181 | + wl_output: Option<wl_output::WlOutput>, | ||
| 182 | + ) { | ||
| 183 | + if surface | ||
| 184 | + .current_state() | ||
| 185 | + .capabilities | ||
| 186 | + .contains(xdg_toplevel::WmCapabilities::Fullscreen) | ||
| 187 | + { | ||
| 188 | + // NOTE: This is only one part of the solution. We can set the | ||
| 189 | + // location and configure size here, but the surface should be rendered fullscreen | ||
| 190 | + // independently from its buffer size | ||
| 191 | + let wl_surface = surface.wl_surface(); | ||
| 192 | + | ||
| 193 | + let output = wl_output | ||
| 194 | + .as_ref() | ||
| 195 | + .and_then(Output::from_resource) | ||
| 196 | + .or_else(|| { | ||
| 197 | + let w = self | ||
| 198 | + .space | ||
| 199 | + .elements() | ||
| 200 | + .find(|window| { | ||
| 201 | + window | ||
| 202 | + .wl_surface() | ||
| 203 | + .map(|s| s == *wl_surface) | ||
| 204 | + .unwrap_or(false) | ||
| 205 | + }) | ||
| 206 | + .cloned(); | ||
| 207 | + w.and_then(|w| self.space.outputs_for_element(&w).get(0).cloned()) | ||
| 208 | + }); | ||
| 209 | + | ||
| 210 | + if let Some(output) = output { | ||
| 211 | + let geometry = self.space.output_geometry(&output).unwrap(); | ||
| 212 | + | ||
| 213 | + surface.with_pending_state(|state| { | ||
| 214 | + state.states.set(xdg_toplevel::State::Fullscreen); | ||
| 215 | + state.size = Some(geometry.size); | ||
| 216 | + }); | ||
| 217 | + | ||
| 218 | + let window = self | ||
| 219 | + .space | ||
| 220 | + .elements() | ||
| 221 | + .find(|w| w.toplevel().wl_surface() == wl_surface) | ||
| 222 | + .unwrap() | ||
| 223 | + .clone(); | ||
| 224 | + self.space.map_element(window, geometry.loc, true); | ||
| 225 | + } | ||
| 226 | + } | ||
| 227 | + | ||
| 228 | + // The protocol demands us to always reply with a configure, | ||
| 229 | + // regardless of we fulfilled the request or not | ||
| 230 | + surface.send_configure(); | ||
| 231 | + } | ||
| 232 | + | ||
| 233 | + fn unfullscreen_request(&mut self, surface: ToplevelSurface) { | ||
| 234 | + if !surface | ||
| 235 | + .current_state() | ||
| 236 | + .states | ||
| 237 | + .contains(xdg_toplevel::State::Fullscreen) | ||
| 238 | + { | ||
| 239 | + return; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + surface.with_pending_state(|state| { | ||
| 243 | + state.states.unset(xdg_toplevel::State::Fullscreen); | ||
| 244 | + state.size = None; | ||
| 245 | + }); | ||
| 246 | + | ||
| 247 | + surface.send_pending_configure(); | ||
| 248 | + } | ||
| 249 | + | ||
| 176 | fn toplevel_destroyed(&mut self, _surface: ToplevelSurface) { | 250 | fn toplevel_destroyed(&mut self, _surface: ToplevelSurface) { |
| 177 | self.queue_redraw(); | 251 | self.queue_redraw(); |
| 178 | } | 252 | } |