Skip to content

Commit

Permalink
Remove dependency of LayoutElement on SpaceElement
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Dec 24, 2023
1 parent 324c1ef commit 0c671ee
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
49 changes: 30 additions & 19 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use smithay::output::Output;
use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1;
use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
use smithay::utils::{Logical, Point, Size, Transform};
use smithay::utils::{Logical, Point, Rectangle, Size, Transform};
use smithay::wayland::compositor::{send_surface_state, with_states};
use smithay::wayland::shell::xdg::SurfaceCachedState;

Expand All @@ -54,14 +54,18 @@ mod focus_ring;
mod monitor;
mod workspace;

pub trait LayoutElement: SpaceElement + PartialEq {
pub trait LayoutElement: PartialEq {
fn geometry(&self) -> Rectangle<i32, Logical>;
fn is_in_input_region(&self, point: Point<f64, Logical>) -> bool;
fn request_size(&self, size: Size<i32, Logical>);
fn request_fullscreen(&self, size: Size<i32, Logical>);
fn min_size(&self) -> Size<i32, Logical>;
fn max_size(&self) -> Size<i32, Logical>;
fn is_wl_surface(&self, wl_surface: &WlSurface) -> bool;
fn has_ssd(&self) -> bool;
fn set_preferred_scale_transform(&self, scale: i32, transform: Transform);
fn output_enter(&self, output: &Output);
fn output_leave(&self, output: &Output);
}

#[derive(Debug)]
Expand Down Expand Up @@ -152,6 +156,14 @@ impl Options {
}

impl LayoutElement for Window {
fn geometry(&self) -> Rectangle<i32, Logical> {
SpaceElement::geometry(self)
}

fn is_in_input_region(&self, point: Point<f64, Logical>) -> bool {
SpaceElement::is_in_input_region(self, &point)
}

fn request_size(&self, size: Size<i32, Logical>) {
self.toplevel().with_pending_state(|state| {
state.size = Some(size);
Expand Down Expand Up @@ -194,6 +206,15 @@ impl LayoutElement for Window {
self.toplevel().current_state().decoration_mode
== Some(zxdg_toplevel_decoration_v1::Mode::ServerSide)
}

fn output_enter(&self, output: &Output) {
let overlap = Rectangle::from_loc_and_size((0, 0), (i32::MAX, i32::MAX));
SpaceElement::output_enter(self, output, overlap)
}

fn output_leave(&self, output: &Output) {
SpaceElement::output_leave(self, output)
}
}

impl<W: LayoutElement> Layout<W> {
Expand Down Expand Up @@ -1268,12 +1289,10 @@ impl<W: LayoutElement> Default for MonitorSet<W> {
#[cfg(test)]
mod tests {
use std::cell::Cell;
use std::rc::Rc;

use proptest::prelude::*;
use proptest_derive::Arbitrary;
use smithay::output::{Mode, PhysicalProperties, Subpixel};
use smithay::utils::{IsAlive, Rectangle};

use super::*;

Expand Down Expand Up @@ -1336,27 +1355,15 @@ mod tests {
}
}

impl IsAlive for TestWindow {
fn alive(&self) -> bool {
true
}
}

impl SpaceElement for TestWindow {
fn bbox(&self) -> Rectangle<i32, Logical> {
impl LayoutElement for TestWindow {
fn geometry(&self) -> Rectangle<i32, Logical> {
self.0.bbox.get()
}

fn is_in_input_region(&self, _point: &Point<f64, Logical>) -> bool {
fn is_in_input_region(&self, _point: Point<f64, Logical>) -> bool {
false
}

fn set_activate(&self, _activated: bool) {}
fn output_enter(&self, _output: &Output, _overlap: Rectangle<i32, Logical>) {}
fn output_leave(&self, _output: &Output) {}
}

impl LayoutElement for TestWindow {
fn request_size(&self, size: Size<i32, Logical>) {
self.0.requested_size.set(Some(size));
}
Expand All @@ -1380,6 +1387,10 @@ mod tests {
fn has_ssd(&self) -> bool {
false
}

fn output_enter(&self, _output: &Output) {}

fn output_leave(&self, _output: &Output) {}
}

fn arbitrary_bbox() -> impl Strategy<Value = Rectangle<i32, Logical>> {
Expand Down
11 changes: 3 additions & 8 deletions src/layout/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,7 @@ impl<W: LayoutElement> Workspace<W> {
fn enter_output_for_window(&self, window: &W) {
if let Some(output) = &self.output {
prepare_for_output(window, output);

// FIXME: proper overlap.
window.output_enter(
output,
Rectangle::from_loc_and_size((0, 0), (i32::MAX, i32::MAX)),
);
window.output_enter(output);
}
}

Expand Down Expand Up @@ -752,7 +747,7 @@ impl<W: LayoutElement> Workspace<W> {
self.column_x(self.active_column_idx) - view_pos,
col.window_y(col.active_window_idx),
)) - geom.loc;
if active_win.is_in_input_region(&(pos - buf_pos.to_f64())) {
if active_win.is_in_input_region(pos - buf_pos.to_f64()) {
return Some((active_win, buf_pos));
}

Expand All @@ -766,7 +761,7 @@ impl<W: LayoutElement> Workspace<W> {

let geom = win.geometry();
let buf_pos = Point::from((x, y)) - geom.loc;
if win.is_in_input_region(&(pos - buf_pos.to_f64())) {
if win.is_in_input_region(pos - buf_pos.to_f64()) {
return Some((win, buf_pos));
}
}
Expand Down

0 comments on commit 0c671ee

Please sign in to comment.