Remove dependency of LayoutElement on SpaceElement
Browse files at this commit0c671ee493a00a7ca96ec637ac54623d369134a6Parent: 324c1ef2 changed files +33 -27
- src/layout/mod.rs +30 -19
- src/layout/workspace.rs +3 -8
src/layout/mod.rsmodified+30 -19
| @@ -39,7 +39,7 @@ use smithay::output::Output; | |||
| 39 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; | 39 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; |
| 40 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; | 40 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel; |
| 41 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 41 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| 42 | -use smithay::utils::{Logical, Point, Size, Transform}; | 42 | +use smithay::utils::{Logical, Point, Rectangle, Size, Transform}; |
| 43 | use smithay::wayland::compositor::{send_surface_state, with_states}; | 43 | use smithay::wayland::compositor::{send_surface_state, with_states}; |
| 44 | use smithay::wayland::shell::xdg::SurfaceCachedState; | 44 | use smithay::wayland::shell::xdg::SurfaceCachedState; |
| 45 | 45 | ||
| @@ -54,7 +54,9 @@ mod focus_ring; | |||
| 54 | mod monitor; | 54 | mod monitor; |
| 55 | mod workspace; | 55 | mod workspace; |
| 56 | 56 | ||
| 57 | -pub trait LayoutElement: SpaceElement + PartialEq { | 57 | +pub trait LayoutElement: PartialEq { |
| 58 | + fn geometry(&self) -> Rectangle<i32, Logical>; | ||
| 59 | + fn is_in_input_region(&self, point: Point<f64, Logical>) -> bool; | ||
| 58 | fn request_size(&self, size: Size<i32, Logical>); | 60 | fn request_size(&self, size: Size<i32, Logical>); |
| 59 | fn request_fullscreen(&self, size: Size<i32, Logical>); | 61 | fn request_fullscreen(&self, size: Size<i32, Logical>); |
| 60 | fn min_size(&self) -> Size<i32, Logical>; | 62 | fn min_size(&self) -> Size<i32, Logical>; |
| @@ -62,6 +64,8 @@ pub trait LayoutElement: SpaceElement + PartialEq { | |||
| 62 | fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool; | 64 | fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool; |
| 63 | fn has_ssd(&self) -> bool; | 65 | fn has_ssd(&self) -> bool; |
| 64 | fn set_preferred_scale_transform(&self, scale: i32, transform: Transform); | 66 | fn set_preferred_scale_transform(&self, scale: i32, transform: Transform); |
| 67 | + fn output_enter(&self, output: &Output); | ||
| 68 | + fn output_leave(&self, output: &Output); | ||
| 65 | } | 69 | } |
| 66 | 70 | ||
| 67 | #[derive(Debug)] | 71 | #[derive(Debug)] |
| @@ -152,6 +156,14 @@ impl Options { | |||
| 152 | } | 156 | } |
| 153 | 157 | ||
| 154 | impl LayoutElement for Window { | 158 | impl LayoutElement for Window { |
| 159 | + fn geometry(&self) -> Rectangle<i32, Logical> { | ||
| 160 | + SpaceElement::geometry(self) | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + fn is_in_input_region(&self, point: Point<f64, Logical>) -> bool { | ||
| 164 | + SpaceElement::is_in_input_region(self, &point) | ||
| 165 | + } | ||
| 166 | + | ||
| 155 | fn request_size(&self, size: Size<i32, Logical>) { | 167 | fn request_size(&self, size: Size<i32, Logical>) { |
| 156 | self.toplevel().with_pending_state(|state| { | 168 | self.toplevel().with_pending_state(|state| { |
| 157 | state.size = Some(size); | 169 | state.size = Some(size); |
| @@ -194,6 +206,15 @@ impl LayoutElement for Window { | |||
| 194 | self.toplevel().current_state().decoration_mode | 206 | self.toplevel().current_state().decoration_mode |
| 195 | == Some(zxdg_toplevel_decoration_v1::Mode::ServerSide) | 207 | == Some(zxdg_toplevel_decoration_v1::Mode::ServerSide) |
| 196 | } | 208 | } |
| 209 | + | ||
| 210 | + fn output_enter(&self, output: &Output) { | ||
| 211 | + let overlap = Rectangle::from_loc_and_size((0, 0), (i32::MAX, i32::MAX)); | ||
| 212 | + SpaceElement::output_enter(self, output, overlap) | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + fn output_leave(&self, output: &Output) { | ||
| 216 | + SpaceElement::output_leave(self, output) | ||
| 217 | + } | ||
| 197 | } | 218 | } |
| 198 | 219 | ||
| 199 | impl<W: LayoutElement> Layout<W> { | 220 | impl<W: LayoutElement> Layout<W> { |
| @@ -1268,12 +1289,10 @@ impl<W: LayoutElement> Default for MonitorSet<W> { | |||
| 1268 | #[cfg(test)] | 1289 | #[cfg(test)] |
| 1269 | mod tests { | 1290 | mod tests { |
| 1270 | use std::cell::Cell; | 1291 | use std::cell::Cell; |
| 1271 | - use std::rc::Rc; | ||
| 1272 | 1292 | ||
| 1273 | use proptest::prelude::*; | 1293 | use proptest::prelude::*; |
| 1274 | use proptest_derive::Arbitrary; | 1294 | use proptest_derive::Arbitrary; |
| 1275 | use smithay::output::{Mode, PhysicalProperties, Subpixel}; | 1295 | use smithay::output::{Mode, PhysicalProperties, Subpixel}; |
| 1276 | - use smithay::utils::{IsAlive, Rectangle}; | ||
| 1277 | 1296 | ||
| 1278 | use super::*; | 1297 | use super::*; |
| 1279 | 1298 | ||
| @@ -1336,27 +1355,15 @@ mod tests { | |||
| 1336 | } | 1355 | } |
| 1337 | } | 1356 | } |
| 1338 | 1357 | ||
| 1339 | - impl IsAlive for TestWindow { | 1358 | + impl LayoutElement for TestWindow { |
| 1340 | - fn alive(&self) -> bool { | 1359 | + fn geometry(&self) -> Rectangle<i32, Logical> { |
| 1341 | - true | ||
| 1342 | - } | ||
| 1343 | - } | ||
| 1344 | - | ||
| 1345 | - impl SpaceElement for TestWindow { | ||
| 1346 | - fn bbox(&self) -> Rectangle<i32, Logical> { | ||
| 1347 | self.0.bbox.get() | 1360 | self.0.bbox.get() |
| 1348 | } | 1361 | } |
| 1349 | 1362 | ||
| 1350 | - fn is_in_input_region(&self, _point: &Point<f64, Logical>) -> bool { | 1363 | + fn is_in_input_region(&self, _point: Point<f64, Logical>) -> bool { |
| 1351 | false | 1364 | false |
| 1352 | } | 1365 | } |
| 1353 | 1366 | ||
| 1354 | - fn set_activate(&self, _activated: bool) {} | ||
| 1355 | - fn output_enter(&self, _output: &Output, _overlap: Rectangle<i32, Logical>) {} | ||
| 1356 | - fn output_leave(&self, _output: &Output) {} | ||
| 1357 | - } | ||
| 1358 | - | ||
| 1359 | - impl LayoutElement for TestWindow { | ||
| 1360 | fn request_size(&self, size: Size<i32, Logical>) { | 1367 | fn request_size(&self, size: Size<i32, Logical>) { |
| 1361 | self.0.requested_size.set(Some(size)); | 1368 | self.0.requested_size.set(Some(size)); |
| 1362 | } | 1369 | } |
| @@ -1380,6 +1387,10 @@ mod tests { | |||
| 1380 | fn has_ssd(&self) -> bool { | 1387 | fn has_ssd(&self) -> bool { |
| 1381 | false | 1388 | false |
| 1382 | } | 1389 | } |
| 1390 | + | ||
| 1391 | + fn output_enter(&self, _output: &Output) {} | ||
| 1392 | + | ||
| 1393 | + fn output_leave(&self, _output: &Output) {} | ||
| 1383 | } | 1394 | } |
| 1384 | 1395 | ||
| 1385 | fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> { | 1396 | fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> { |
src/layout/workspace.rsmodified+3 -8
| @@ -294,12 +294,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 294 | fn enter_output_for_window(&self, window: &W) { | 294 | fn enter_output_for_window(&self, window: &W) { |
| 295 | if let Some(output) = &self.output { | 295 | if let Some(output) = &self.output { |
| 296 | prepare_for_output(window, output); | 296 | prepare_for_output(window, output); |
| 297 | - | 297 | + window.output_enter(output); |
| 298 | - // FIXME: proper overlap. | ||
| 299 | - window.output_enter( | ||
| 300 | - output, | ||
| 301 | - Rectangle::from_loc_and_size((0, 0), (i32::MAX, i32::MAX)), | ||
| 302 | - ); | ||
| 303 | } | 298 | } |
| 304 | } | 299 | } |
| 305 | 300 | ||
| @@ -752,7 +747,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 752 | self.column_x(self.active_column_idx) - view_pos, | 747 | self.column_x(self.active_column_idx) - view_pos, |
| 753 | col.window_y(col.active_window_idx), | 748 | col.window_y(col.active_window_idx), |
| 754 | )) - geom.loc; | 749 | )) - geom.loc; |
| 755 | - if active_win.is_in_input_region(&(pos - buf_pos.to_f64())) { | 750 | + if active_win.is_in_input_region(pos - buf_pos.to_f64()) { |
| 756 | return Some((active_win, buf_pos)); | 751 | return Some((active_win, buf_pos)); |
| 757 | } | 752 | } |
| 758 | 753 | ||
| @@ -766,7 +761,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 766 | 761 | ||
| 767 | let geom = win.geometry(); | 762 | let geom = win.geometry(); |
| 768 | let buf_pos = Point::from((x, y)) - geom.loc; | 763 | let buf_pos = Point::from((x, y)) - geom.loc; |
| 769 | - if win.is_in_input_region(&(pos - buf_pos.to_f64())) { | 764 | + if win.is_in_input_region(pos - buf_pos.to_f64()) { |
| 770 | return Some((win, buf_pos)); | 765 | return Some((win, buf_pos)); |
| 771 | } | 766 | } |
| 772 | } | 767 | } |