forge
Explore
Log in

Don't you dare go Hollow

Add un/fullscreen support

Browse files at this commit

91a809b755977f57c1c1fc0da09dfc1cd2483d87Ivan MolodetskikhParent: f9c7fe4
src/handlers/xdg_shell.rsmodified+75 -1
@@ -2,12 +2,14 @@ use smithay::delegate_xdg_shell;
22 use smithay::desktop::{PopupKind, Window};
33 use smithay::input::pointer::{Focus, GrabStartData as PointerGrabStartData};
44 use smithay::input::Seat;
5+use smithay::output::Output;
56 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
6-use smithay::reexports::wayland_server::protocol::wl_seat;
77 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
8+use smithay::reexports::wayland_server::protocol::{wl_output, wl_seat};
89 use smithay::reexports::wayland_server::Resource;
910 use smithay::utils::{Rectangle, Serial};
1011 use smithay::wayland::compositor::with_states;
12+use smithay::wayland::seat::WaylandFocus;
1113 use smithay::wayland::shell::xdg::{
1214 PopupSurface, PositionerState, ToplevelSurface, XdgPopupSurfaceData, XdgShellHandler,
1315 XdgShellState, XdgToplevelSurfaceData,
@@ -173,6 +175,78 @@ impl XdgShellHandler for Niri {
173175 surface.send_pending_configure();
174176 }
175177
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+
176250 fn toplevel_destroyed(&mut self, _surface: ToplevelSurface) {
177251 self.queue_redraw();
178252 }