forge
Explore
Log in

Don't you dare go Hollow

Remove some commented out code

Browse files at this commit

78090e1140b99d245c6932d10e084e7f11d34083Ivan MolodetskikhParent: 99533bd
src/grabs/mod.rsdeleted+0 -5
@@ -1,5 +0,0 @@
1-pub mod move_grab;
2-pub use move_grab::MoveSurfaceGrab;
3-
4-pub mod resize_grab;
5-pub use resize_grab::ResizeSurfaceGrab;
src/grabs/move_grab.rsdeleted+0 -78
@@ -1,78 +0,0 @@
1-use smithay::desktop::Window;
2-use smithay::input::pointer::{
3- AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
4- PointerInnerHandle, RelativeMotionEvent,
5-};
6-use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
7-use smithay::utils::{Logical, Point};
8-use smithay::wayland::seat::WaylandFocus;
9-
10-use crate::Niri;
11-
12-pub struct MoveSurfaceGrab {
13- pub start_data: PointerGrabStartData<Niri>,
14- pub window: Window,
15- pub initial_window_location: Point<i32, Logical>,
16-}
17-
18-impl PointerGrab<Niri> for MoveSurfaceGrab {
19- fn motion(
20- &mut self,
21- data: &mut Niri,
22- handle: &mut PointerInnerHandle<'_, Niri>,
23- _focus: Option<(WlSurface, Point<i32, Logical>)>,
24- event: &MotionEvent,
25- ) {
26- // While the grab is active, no client has pointer focus
27- handle.motion(data, None, event);
28-
29- // let delta = event.location - self.start_data.location;
30- // let new_location = self.initial_window_location.to_f64() + delta;
31- // let (window, space) = data
32- // .monitor_set
33- // .find_window_and_space(self.window.wl_surface().as_ref().unwrap())
34- // .unwrap();
35- // space.map_element(window.clone(), new_location.to_i32_round(), true);
36- }
37-
38- fn relative_motion(
39- &mut self,
40- data: &mut Niri,
41- handle: &mut PointerInnerHandle<'_, Niri>,
42- focus: Option<(WlSurface, Point<i32, Logical>)>,
43- event: &RelativeMotionEvent,
44- ) {
45- handle.relative_motion(data, focus, event);
46- }
47-
48- fn button(
49- &mut self,
50- data: &mut Niri,
51- handle: &mut PointerInnerHandle<'_, Niri>,
52- event: &ButtonEvent,
53- ) {
54- handle.button(data, event);
55-
56- // The button is a button code as defined in the
57- // Linux kernel's linux/input-event-codes.h header file, e.g. BTN_LEFT.
58- const BTN_LEFT: u32 = 0x110;
59-
60- if !handle.current_pressed().contains(&BTN_LEFT) {
61- // No more buttons are pressed, release the grab.
62- handle.unset_grab(data, event.serial, event.time);
63- }
64- }
65-
66- fn axis(
67- &mut self,
68- data: &mut Niri,
69- handle: &mut PointerInnerHandle<'_, Niri>,
70- details: AxisFrame,
71- ) {
72- handle.axis(data, details)
73- }
74-
75- fn start_data(&self) -> &PointerGrabStartData<Niri> {
76- &self.start_data
77- }
78-}
src/grabs/resize_grab.rsdeleted+0 -288
@@ -1,288 +0,0 @@
1-use std::cell::RefCell;
2-
3-use smithay::desktop::Window;
4-use smithay::input::pointer::{
5- AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab,
6- PointerInnerHandle, RelativeMotionEvent,
7-};
8-use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
9-use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
10-use smithay::utils::{Logical, Point, Rectangle, Size};
11-use smithay::wayland::compositor;
12-use smithay::wayland::shell::xdg::SurfaceCachedState;
13-
14-use crate::Niri;
15-
16-bitflags::bitflags! {
17- #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
18- pub struct ResizeEdge: u32 {
19- const TOP = 0b0001;
20- const BOTTOM = 0b0010;
21- const LEFT = 0b0100;
22- const RIGHT = 0b1000;
23-
24- const TOP_LEFT = Self::TOP.bits() | Self::LEFT.bits();
25- const BOTTOM_LEFT = Self::BOTTOM.bits() | Self::LEFT.bits();
26-
27- const TOP_RIGHT = Self::TOP.bits() | Self::RIGHT.bits();
28- const BOTTOM_RIGHT = Self::BOTTOM.bits() | Self::RIGHT.bits();
29- }
30-}
31-
32-impl From<xdg_toplevel::ResizeEdge> for ResizeEdge {
33- #[inline]
34- fn from(x: xdg_toplevel::ResizeEdge) -> Self {
35- Self::from_bits(x as u32).unwrap()
36- }
37-}
38-
39-pub struct ResizeSurfaceGrab {
40- start_data: PointerGrabStartData<Niri>,
41- window: Window,
42-
43- edges: ResizeEdge,
44-
45- initial_rect: Rectangle<i32, Logical>,
46- last_window_size: Size<i32, Logical>,
47-}
48-
49-impl ResizeSurfaceGrab {
50- pub fn start(
51- start_data: PointerGrabStartData<Niri>,
52- window: Window,
53- edges: ResizeEdge,
54- initial_window_rect: Rectangle<i32, Logical>,
55- ) -> Self {
56- let initial_rect = initial_window_rect;
57-
58- ResizeSurfaceState::with(window.toplevel().wl_surface(), |state| {
59- *state = ResizeSurfaceState::Resizing {
60- edges,
61- initial_rect,
62- };
63- });
64-
65- Self {
66- start_data,
67- window,
68- edges,
69- initial_rect,
70- last_window_size: initial_rect.size,
71- }
72- }
73-}
74-
75-impl PointerGrab<Niri> for ResizeSurfaceGrab {
76- fn motion(
77- &mut self,
78- data: &mut Niri,
79- handle: &mut PointerInnerHandle<'_, Niri>,
80- _focus: Option<(WlSurface, Point<i32, Logical>)>,
81- event: &MotionEvent,
82- ) {
83- // While the grab is active, no client has pointer focus
84- handle.motion(data, None, event);
85-
86- let mut delta = event.location - self.start_data.location;
87-
88- let mut new_window_width = self.initial_rect.size.w;
89- let mut new_window_height = self.initial_rect.size.h;
90-
91- if self.edges.intersects(ResizeEdge::LEFT | ResizeEdge::RIGHT) {
92- if self.edges.intersects(ResizeEdge::LEFT) {
93- delta.x = -delta.x;
94- }
95-
96- new_window_width = (self.initial_rect.size.w as f64 + delta.x) as i32;
97- }
98-
99- if self.edges.intersects(ResizeEdge::TOP | ResizeEdge::BOTTOM) {
100- if self.edges.intersects(ResizeEdge::TOP) {
101- delta.y = -delta.y;
102- }
103-
104- new_window_height = (self.initial_rect.size.h as f64 + delta.y) as i32;
105- }
106-
107- let (min_size, max_size) =
108- compositor::with_states(self.window.toplevel().wl_surface(), |states| {
109- let data = states.cached_state.current::<SurfaceCachedState>();
110- (data.min_size, data.max_size)
111- });
112-
113- let min_width = min_size.w.max(1);
114- let min_height = min_size.h.max(1);
115-
116- let max_width = (max_size.w == 0).then(i32::max_value).unwrap_or(max_size.w);
117- let max_height = (max_size.h == 0).then(i32::max_value).unwrap_or(max_size.h);
118-
119- self.last_window_size = Size::from((
120- new_window_width.max(min_width).min(max_width),
121- new_window_height.max(min_height).min(max_height),
122- ));
123-
124- let xdg = self.window.toplevel();
125- xdg.with_pending_state(|state| {
126- state.states.set(xdg_toplevel::State::Resizing);
127- state.size = Some(self.last_window_size);
128- });
129-
130- xdg.send_pending_configure();
131- }
132-
133- fn relative_motion(
134- &mut self,
135- data: &mut Niri,
136- handle: &mut PointerInnerHandle<'_, Niri>,
137- focus: Option<(WlSurface, Point<i32, Logical>)>,
138- event: &RelativeMotionEvent,
139- ) {
140- handle.relative_motion(data, focus, event);
141- }
142-
143- fn button(
144- &mut self,
145- data: &mut Niri,
146- handle: &mut PointerInnerHandle<'_, Niri>,
147- event: &ButtonEvent,
148- ) {
149- handle.button(data, event);
150-
151- // The button is a button code as defined in the
152- // Linux kernel's linux/input-event-codes.h header file, e.g. BTN_LEFT.
153- const BTN_LEFT: u32 = 0x110;
154-
155- if !handle.current_pressed().contains(&BTN_LEFT) {
156- // No more buttons are pressed, release the grab.
157- handle.unset_grab(data, event.serial, event.time);
158-
159- let xdg = self.window.toplevel();
160- xdg.with_pending_state(|state| {
161- state.states.unset(xdg_toplevel::State::Resizing);
162- state.size = Some(self.last_window_size);
163- });
164-
165- xdg.send_pending_configure();
166-
167- ResizeSurfaceState::with(xdg.wl_surface(), |state| {
168- *state = ResizeSurfaceState::WaitingForLastCommit {
169- edges: self.edges,
170- initial_rect: self.initial_rect,
171- };
172- });
173- }
174- }
175-
176- fn axis(
177- &mut self,
178- data: &mut Niri,
179- handle: &mut PointerInnerHandle<'_, Niri>,
180- details: AxisFrame,
181- ) {
182- handle.axis(data, details)
183- }
184-
185- fn start_data(&self) -> &PointerGrabStartData<Niri> {
186- &self.start_data
187- }
188-}
189-
190-/// State of the resize operation.
191-///
192-/// It is stored inside of WlSurface,
193-/// and can be accessed using [`ResizeSurfaceState::with`]
194-#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
195-enum ResizeSurfaceState {
196- #[default]
197- Idle,
198- Resizing {
199- edges: ResizeEdge,
200- /// The initial window size and location.
201- initial_rect: Rectangle<i32, Logical>,
202- },
203- /// Resize is done, we are now waiting for last commit, to do the final move
204- WaitingForLastCommit {
205- edges: ResizeEdge,
206- /// The initial window size and location.
207- initial_rect: Rectangle<i32, Logical>,
208- },
209-}
210-
211-impl ResizeSurfaceState {
212- fn with<F, T>(surface: &WlSurface, cb: F) -> T
213- where
214- F: FnOnce(&mut Self) -> T,
215- {
216- compositor::with_states(surface, |states| {
217- states.data_map.insert_if_missing(RefCell::<Self>::default);
218- let state = states.data_map.get::<RefCell<Self>>().unwrap();
219-
220- cb(&mut state.borrow_mut())
221- })
222- }
223-
224- fn commit(&mut self) -> Option<(ResizeEdge, Rectangle<i32, Logical>)> {
225- match *self {
226- Self::Resizing {
227- edges,
228- initial_rect,
229- } => Some((edges, initial_rect)),
230- Self::WaitingForLastCommit {
231- edges,
232- initial_rect,
233- } => {
234- // The resize is done, let's go back to idle
235- *self = Self::Idle;
236-
237- Some((edges, initial_rect))
238- }
239- Self::Idle => None,
240- }
241- }
242-}
243-
244-pub fn handle_commit(window: &Window) -> Option<()> {
245- // FIXME
246- let surface = window.toplevel().wl_surface();
247- ResizeSurfaceState::with(surface, |state| {
248- state.commit();
249- });
250-
251- // let mut window_loc = space.element_location(&window)?;
252- // let geometry = window.geometry();
253-
254- // let new_loc: Point<Option<i32>, Logical> = ResizeSurfaceState::with(surface, |state| {
255- // state
256- // .commit()
257- // .and_then(|(edges, initial_rect)| {
258- // // If the window is being resized by top or left, its location must be adjusted
259- // // accordingly.
260- // edges.intersects(ResizeEdge::TOP_LEFT).then(|| {
261- // let new_x = edges
262- // .intersects(ResizeEdge::LEFT)
263- // .then_some(initial_rect.loc.x + (initial_rect.size.w - geometry.size.w));
264-
265- // let new_y = edges
266- // .intersects(ResizeEdge::TOP)
267- // .then_some(initial_rect.loc.y + (initial_rect.size.h - geometry.size.h));
268-
269- // (new_x, new_y).into()
270- // })
271- // })
272- // .unwrap_or_default()
273- // });
274-
275- // if let Some(new_x) = new_loc.x {
276- // window_loc.x = new_x;
277- // }
278- // if let Some(new_y) = new_loc.y {
279- // window_loc.y = new_y;
280- // }
281-
282- // if new_loc.x.is_some() || new_loc.y.is_some() {
283- // // If TOP or LEFT side of the window got resized, we have to move it
284- // space.map_element(window, window_loc, false);
285- // }
286-
287- Some(())
288-}
src/handlers/compositor.rsmodified+0 -2
@@ -13,7 +13,6 @@ use smithay::wayland::shm::{ShmHandler, ShmState};
13 use smithay::{delegate_compositor, delegate_shm};13 use smithay::{delegate_compositor, delegate_shm};
14 14
15 use super::xdg_shell;15 use super::xdg_shell;
16-use crate::grabs::resize_grab;
17 use crate::niri::ClientState;16 use crate::niri::ClientState;
18 use crate::Niri;17 use crate::Niri;
19 18
@@ -81,7 +80,6 @@ impl CompositorHandler for Niri {
81 }80 }
82 81
83 // The toplevel remains mapped.82 // The toplevel remains mapped.
84- resize_grab::handle_commit(&window);
85 self.monitor_set.update_window(&window);83 self.monitor_set.update_window(&window);
86 84
87 self.queue_redraw(output);85 self.queue_redraw(output);
src/handlers/xdg_shell.rsmodified+18 -126
@@ -1,20 +1,17 @@
1 use smithay::delegate_xdg_shell;1 use smithay::delegate_xdg_shell;
2 use smithay::desktop::{find_popup_root_surface, PopupKind, Window};2 use smithay::desktop::{find_popup_root_surface, PopupKind, Window};
3-use smithay::input::pointer::{Focus, GrabStartData as PointerGrabStartData};
4-use smithay::input::Seat;
5 use smithay::output::Output;3 use smithay::output::Output;
6-use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;4+use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self, ResizeEdge};
5+use smithay::reexports::wayland_server::protocol::wl_output;
6+use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat;
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::utils::Serial;
9-use smithay::reexports::wayland_server::Resource;
10-use smithay::utils::{Rectangle, Serial};
11 use smithay::wayland::compositor::with_states;9 use smithay::wayland::compositor::with_states;
12 use smithay::wayland::shell::xdg::{10 use smithay::wayland::shell::xdg::{
13 PopupSurface, PositionerState, ToplevelSurface, XdgPopupSurfaceData, XdgShellHandler,11 PopupSurface, PositionerState, ToplevelSurface, XdgPopupSurfaceData, XdgShellHandler,
14 XdgShellState, XdgToplevelSurfaceData,12 XdgShellState, XdgToplevelSurfaceData,
15 };13 };
16 14
17-use crate::grabs::{MoveSurfaceGrab, ResizeSurfaceGrab};
18 use crate::layout::{configure_new_window, output_size};15 use crate::layout::{configure_new_window, output_size};
19 use crate::Niri;16 use crate::Niri;
20 17
@@ -36,77 +33,26 @@ impl XdgShellHandler for Niri {
36 assert!(existing.is_none());33 assert!(existing.is_none());
37 }34 }
38 35
39- fn new_popup(&mut self, surface: PopupSurface, positioner: PositionerState) {36+ fn new_popup(&mut self, surface: PopupSurface, _positioner: PositionerState) {
40- surface.with_pending_state(|state| {37+ // FIXME: adjust the geometry so the popup doesn't overflow at least off the top and bottom
41- // NOTE: This is not really necessary as the default geometry38+ // screen edges, and ideally off the view size.
42- // is already set the same way, but for demonstrating how
43- // to set the initial popup geometry this code is left as
44- // an example
45- state.geometry = positioner.get_geometry();
46- });
47 if let Err(err) = self.popups.track_popup(PopupKind::Xdg(surface)) {39 if let Err(err) = self.popups.track_popup(PopupKind::Xdg(surface)) {
48 warn!("error tracking popup: {err:?}");40 warn!("error tracking popup: {err:?}");
49 }41 }
50 }42 }
51 43
52- fn move_request(&mut self, surface: ToplevelSurface, seat: wl_seat::WlSeat, serial: Serial) {44+ fn move_request(&mut self, _surface: ToplevelSurface, _seat: WlSeat, _serial: Serial) {
53 // FIXME45 // FIXME
54-
55- // let seat = Seat::from_resource(&seat).unwrap();
56-
57- // let wl_surface = surface.wl_surface();
58-
59- // if let Some(start_data) = check_grab(&seat, wl_surface, serial) {
60- // let pointer = seat.get_pointer().unwrap();
61-
62- // let (window, space) = self.monitor_set.find_window_and_space(wl_surface).unwrap();
63- // let initial_window_location = space.element_location(&window).unwrap();
64-
65- // let grab = MoveSurfaceGrab {
66- // start_data,
67- // window: window.clone(),
68- // initial_window_location,
69- // };
70-
71- // pointer.set_grab(self, grab, serial, Focus::Clear);
72- // }
73 }46 }
74 47
75 fn resize_request(48 fn resize_request(
76 &mut self,49 &mut self,
77- surface: ToplevelSurface,50+ _surface: ToplevelSurface,
78- seat: wl_seat::WlSeat,51+ _seat: WlSeat,
79- serial: Serial,52+ _serial: Serial,
80- edges: xdg_toplevel::ResizeEdge,53+ _edges: ResizeEdge,
81 ) {54 ) {
82 // FIXME55 // FIXME
83-
84- // let seat = Seat::from_resource(&seat).unwrap();
85-
86- // let wl_surface = surface.wl_surface();
87-
88- // if let Some(start_data) = check_grab(&seat, wl_surface, serial) {
89- // let pointer = seat.get_pointer().unwrap();
90-
91- // let (window, space) = self.monitor_set.find_window_and_space(wl_surface).unwrap();
92- // let initial_window_location = space.element_location(&window).unwrap();
93- // let initial_window_size = window.geometry().size;
94-
95- // surface.with_pending_state(|state| {
96- // state.states.set(xdg_toplevel::State::Resizing);
97- // });
98-
99- // surface.send_pending_configure();
100-
101- // let grab = ResizeSurfaceGrab::start(
102- // start_data,
103- // window.clone(),
104- // edges.into(),
105- // Rectangle::from_loc_and_size(initial_window_location, initial_window_size),
106- // );
107-
108- // pointer.set_grab(self, grab, serial, Focus::Clear);
109- // }
110 }56 }
111 57
112 fn reposition_request(58 fn reposition_request(
@@ -115,11 +61,9 @@ impl XdgShellHandler for Niri {
115 positioner: PositionerState,61 positioner: PositionerState,
116 token: u32,62 token: u32,
117 ) {63 ) {
64+ // FIXME: adjust the geometry so the popup doesn't overflow at least off the top and bottom
65+ // screen edges, and ideally off the view size.
118 surface.with_pending_state(|state| {66 surface.with_pending_state(|state| {
119- // NOTE: This is again a simplification, a proper compositor would
120- // calculate the geometry of the popup here. For simplicity we just
121- // use the default implementation here that does not take the
122- // window position and output constraints into account.
123 let geometry = positioner.get_geometry();67 let geometry = positioner.get_geometry();
124 state.geometry = geometry;68 state.geometry = geometry;
125 state.positioner = positioner;69 state.positioner = positioner;
@@ -127,48 +71,20 @@ impl XdgShellHandler for Niri {
127 surface.send_repositioned(token);71 surface.send_repositioned(token);
128 }72 }
129 73
130- fn grab(&mut self, _surface: PopupSurface, _seat: wl_seat::WlSeat, _serial: Serial) {74+ fn grab(&mut self, _surface: PopupSurface, _seat: WlSeat, _serial: Serial) {
131 // FIXME popup grabs75 // FIXME popup grabs
132 }76 }
133 77
134 fn maximize_request(&mut self, surface: ToplevelSurface) {78 fn maximize_request(&mut self, surface: ToplevelSurface) {
135- if surface79+ // FIXME
136- .current_state()
137- .capabilities
138- .contains(xdg_toplevel::WmCapabilities::Maximize)
139- {
140- // let wl_surface = surface.wl_surface();
141- // let (window, space) = self.monitor_set.find_window_and_space(wl_surface).unwrap();
142- // let geometry = space
143- // .output_geometry(space.outputs().next().unwrap())
144- // .unwrap();
145-
146- // surface.with_pending_state(|state| {
147- // state.states.set(xdg_toplevel::State::Maximized);
148- // state.size = Some(geometry.size);
149- // });
150- // space.map_element(window.clone(), geometry.loc, true);
151- }
152 80
153 // The protocol demands us to always reply with a configure,81 // The protocol demands us to always reply with a configure,
154 // regardless of we fulfilled the request or not82 // regardless of we fulfilled the request or not
155 surface.send_configure();83 surface.send_configure();
156 }84 }
157 85
158- fn unmaximize_request(&mut self, surface: ToplevelSurface) {86+ fn unmaximize_request(&mut self, _surface: ToplevelSurface) {
159- if !surface87+ // FIXME
160- .current_state()
161- .states
162- .contains(xdg_toplevel::State::Maximized)
163- {
164- return;
165- }
166-
167- surface.with_pending_state(|state| {
168- state.states.unset(xdg_toplevel::State::Maximized);
169- state.size = None;
170- });
171- surface.send_pending_configure();
172 }88 }
173 89
174 fn fullscreen_request(90 fn fullscreen_request(
@@ -237,32 +153,8 @@ impl XdgShellHandler for Niri {
237 }153 }
238 }154 }
239 155
240-// Xdg Shell
241 delegate_xdg_shell!(Niri);156 delegate_xdg_shell!(Niri);
242 157
243-fn check_grab(
244- seat: &Seat<Niri>,
245- surface: &WlSurface,
246- serial: Serial,
247-) -> Option<PointerGrabStartData<Niri>> {
248- let pointer = seat.get_pointer()?;
249-
250- // Check that this surface has a click grab.
251- if !pointer.has_grab(serial) {
252- return None;
253- }
254-
255- let start_data = pointer.grab_start_data()?;
256-
257- let (focus, _) = start_data.focus.as_ref()?;
258- // If the focus was for a different surface, ignore the request.
259- if !focus.id().same_client_as(&surface.id()) {
260- return None;
261- }
262-
263- Some(start_data)
264-}
265-
266 pub fn send_initial_configure_if_needed(window: &Window) {158 pub fn send_initial_configure_if_needed(window: &Window) {
267 let initial_configure_sent = with_states(window.toplevel().wl_surface(), |states| {159 let initial_configure_sent = with_states(window.toplevel().wl_surface(), |states| {
268 states160 states
src/layout.rsmodified+1 -1
@@ -1847,7 +1847,7 @@ impl<W: LayoutElement> Column<W> {
1847 1847
1848 fn toggle_full_width(&mut self, view_size: Size<i32, Logical>) {1848 fn toggle_full_width(&mut self, view_size: Size<i32, Logical>) {
1849 let width = match self.width {1849 let width = match self.width {
1850- ColumnWidth::Proportion(1.) => {1850+ ColumnWidth::Proportion(x) if x == 1. => {
1851 // FIXME: would be good to restore to previous width here.1851 // FIXME: would be good to restore to previous width here.
1852 ColumnWidth::default()1852 ColumnWidth::default()
1853 }1853 }
src/main.rsmodified+0 -1
@@ -6,7 +6,6 @@ mod handlers;
6 mod animation;6 mod animation;
7 mod backend;7 mod backend;
8 mod frame_clock;8 mod frame_clock;
9-mod grabs;
10 mod input;9 mod input;
11 mod layout;10 mod layout;
12 mod niri;11 mod niri;