forge
Explore
Log in

Don't you dare go Hollow

Add draft popup implementation

Browse files at this commit

3959d1eaa10f97f2377f8174b711c8c30a2f3949Ivan MolodetskikhParent: 91c7763
Missing grabs and positioning but gets the job sufficiently done for now.
src/handlers/compositor.rsmodified+1 -2
@@ -9,7 +9,6 @@ use smithay::wayland::compositor::{
9 use smithay::wayland::shm::{ShmHandler, ShmState};9 use smithay::wayland::shm::{ShmHandler, ShmState};
10 use smithay::{delegate_compositor, delegate_shm};10 use smithay::{delegate_compositor, delegate_shm};
11 11
12-use super::xdg_shell;
13 use crate::grabs::resize_grab;12 use crate::grabs::resize_grab;
14 use crate::niri::ClientState;13 use crate::niri::ClientState;
15 use crate::Niri;14 use crate::Niri;
@@ -43,7 +42,7 @@ impl CompositorHandler for Niri {
43 }42 }
44 };43 };
45 44
46- xdg_shell::handle_commit(&self.space, surface);45+ self.xdg_handle_commit(surface);
47 resize_grab::handle_commit(&mut self.space, surface);46 resize_grab::handle_commit(&mut self.space, surface);
48 47
49 self.queue_redraw();48 self.queue_redraw();
src/handlers/xdg_shell.rsmodified+75 -26
@@ -1,5 +1,5 @@
1 use smithay::delegate_xdg_shell;1 use smithay::delegate_xdg_shell;
2-use smithay::desktop::{Space, 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::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;5 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
@@ -9,8 +9,8 @@ use smithay::reexports::wayland_server::Resource;
9 use smithay::utils::{Rectangle, Serial};9 use smithay::utils::{Rectangle, Serial};
10 use smithay::wayland::compositor::with_states;10 use smithay::wayland::compositor::with_states;
11 use smithay::wayland::shell::xdg::{11 use smithay::wayland::shell::xdg::{
12- PopupSurface, PositionerState, ToplevelSurface, XdgShellHandler, XdgShellState,12+ PopupSurface, PositionerState, ToplevelSurface, XdgPopupSurfaceData, XdgShellHandler,
13- XdgToplevelSurfaceData,13+ XdgShellState, XdgToplevelSurfaceData,
14 };14 };
15 15
16 use crate::grabs::{MoveSurfaceGrab, ResizeSurfaceGrab};16 use crate::grabs::{MoveSurfaceGrab, ResizeSurfaceGrab};
@@ -26,8 +26,17 @@ impl XdgShellHandler for Niri {
26 self.space.map_element(window, (0, 0), false);26 self.space.map_element(window, (0, 0), false);
27 }27 }
28 28
29- fn new_popup(&mut self, _surface: PopupSurface, _positioner: PositionerState) {29+ fn new_popup(&mut self, surface: PopupSurface, positioner: PositionerState) {
30- // TODO: Popup handling using PopupManager30+ surface.with_pending_state(|state| {
31+ // NOTE: This is not really necessary as the default geometry
32+ // is already set the same way, but for demonstrating how
33+ // to set the initial popup geometry this code is left as
34+ // an example
35+ state.geometry = positioner.get_geometry();
36+ });
37+ if let Err(err) = self.popups.track_popup(PopupKind::Xdg(surface)) {
38+ warn!("error tracking popup: {err:?}");
39+ }
31 }40 }
32 41
33 fn move_request(&mut self, surface: ToplevelSurface, seat: wl_seat::WlSeat, serial: Serial) {42 fn move_request(&mut self, surface: ToplevelSurface, seat: wl_seat::WlSeat, serial: Serial) {
@@ -96,6 +105,24 @@ impl XdgShellHandler for Niri {
96 }105 }
97 }106 }
98 107
108+ fn reposition_request(
109+ &mut self,
110+ surface: PopupSurface,
111+ positioner: PositionerState,
112+ token: u32,
113+ ) {
114+ surface.with_pending_state(|state| {
115+ // NOTE: This is again a simplification, a proper compositor would
116+ // calculate the geometry of the popup here. For simplicity we just
117+ // use the default implementation here that does not take the
118+ // window position and output constraints into account.
119+ let geometry = positioner.get_geometry();
120+ state.geometry = geometry;
121+ state.positioner = positioner;
122+ });
123+ surface.send_repositioned(token);
124+ }
125+
99 fn grab(&mut self, _surface: PopupSurface, _seat: wl_seat::WlSeat, _serial: Serial) {126 fn grab(&mut self, _surface: PopupSurface, _seat: wl_seat::WlSeat, _serial: Serial) {
100 // TODO popup grabs127 // TODO popup grabs
101 }128 }
@@ -181,26 +208,48 @@ fn check_grab(
181 Some(start_data)208 Some(start_data)
182 }209 }
183 210
184-/// Should be called on `WlSurface::commit`211+impl Niri {
185-pub fn handle_commit(space: &Space<Window>, surface: &WlSurface) -> Option<()> {212+ /// Should be called on `WlSurface::commit`
186- let window = space213+ pub fn xdg_handle_commit(&mut self, surface: &WlSurface) {
187- .elements()214+ self.popups.commit(surface);
188- .find(|w| w.toplevel().wl_surface() == surface)
189- .cloned()?;
190-
191- let initial_configure_sent = with_states(surface, |states| {
192- states
193- .data_map
194- .get::<XdgToplevelSurfaceData>()
195- .unwrap()
196- .lock()
197- .unwrap()
198- .initial_configure_sent
199- });
200-
201- if !initial_configure_sent {
202- window.toplevel().send_configure();
203- }
204 215
205- Some(())216+ if let Some(window) = self
217+ .space
218+ .elements()
219+ .find(|w| w.toplevel().wl_surface() == surface)
220+ .cloned()
221+ {
222+ let initial_configure_sent = with_states(surface, |states| {
223+ states
224+ .data_map
225+ .get::<XdgToplevelSurfaceData>()
226+ .unwrap()
227+ .lock()
228+ .unwrap()
229+ .initial_configure_sent
230+ });
231+
232+ if !initial_configure_sent {
233+ window.toplevel().send_configure();
234+ }
235+ }
236+
237+ if let Some(popup) = self.popups.find_popup(surface) {
238+ let PopupKind::Xdg(ref popup) = popup;
239+ let initial_configure_sent = with_states(surface, |states| {
240+ states
241+ .data_map
242+ .get::<XdgPopupSurfaceData>()
243+ .unwrap()
244+ .lock()
245+ .unwrap()
246+ .initial_configure_sent
247+ });
248+ if !initial_configure_sent {
249+ // NOTE: This should never fail as the initial configure is always
250+ // allowed.
251+ popup.send_configure().expect("initial configure failed");
252+ }
253+ }
254+ }
206 }255 }
src/niri.rsmodified+4 -1
@@ -6,7 +6,7 @@ use smithay::backend::renderer::element::render_elements;
6 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};6 use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement};
7 use smithay::backend::renderer::ImportAll;7 use smithay::backend::renderer::ImportAll;
8 use smithay::desktop::space::{space_render_elements, SpaceRenderElements};8 use smithay::desktop::space::{space_render_elements, SpaceRenderElements};
9-use smithay::desktop::{Space, Window, WindowSurfaceType};9+use smithay::desktop::{PopupManager, Space, Window, WindowSurfaceType};
10 use smithay::input::keyboard::XkbConfig;10 use smithay::input::keyboard::XkbConfig;
11 use smithay::input::{Seat, SeatState};11 use smithay::input::{Seat, SeatState};
12 use smithay::output::Output;12 use smithay::output::Output;
@@ -42,6 +42,7 @@ pub struct Niri {
42 pub output_manager_state: OutputManagerState,42 pub output_manager_state: OutputManagerState,
43 pub seat_state: SeatState<Self>,43 pub seat_state: SeatState<Self>,
44 pub data_device_state: DataDeviceState,44 pub data_device_state: DataDeviceState,
45+ pub popups: PopupManager,
45 46
46 pub seat: Seat<Self>,47 pub seat: Seat<Self>,
47 pub output: Option<Output>,48 pub output: Option<Output>,
@@ -137,6 +138,7 @@ impl Niri {
137 output_manager_state,138 output_manager_state,
138 seat_state,139 seat_state,
139 data_device_state,140 data_device_state,
141+ popups: PopupManager::default(),
140 142
141 seat,143 seat,
142 output: None,144 output: None,
@@ -225,6 +227,7 @@ impl Niri {
225 });227 });
226 228
227 self.space.refresh();229 self.space.refresh();
230+ self.popups.cleanup();
228 }231 }
229 }232 }
230 233