From 95c810c855a27a28f4dfa7dc6b949fef0901c7b2 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 13 Aug 2023 12:46:53 +0400 Subject: Refactor everything, add initial tiling code --- src/grabs/move_grab.rs | 12 ++++--- src/grabs/resize_grab.rs | 82 ++++++++++++++++++++++++------------------------ 2 files changed, 49 insertions(+), 45 deletions(-) (limited to 'src/grabs') diff --git a/src/grabs/move_grab.rs b/src/grabs/move_grab.rs index 699921d1..67a1f285 100644 --- a/src/grabs/move_grab.rs +++ b/src/grabs/move_grab.rs @@ -5,6 +5,7 @@ use smithay::input::pointer::{ }; use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; use smithay::utils::{Logical, Point}; +use smithay::wayland::seat::WaylandFocus; use crate::Niri; @@ -25,10 +26,13 @@ impl PointerGrab for MoveSurfaceGrab { // While the grab is active, no client has pointer focus handle.motion(data, None, event); - let delta = event.location - self.start_data.location; - let new_location = self.initial_window_location.to_f64() + delta; - data.space - .map_element(self.window.clone(), new_location.to_i32_round(), true); + // let delta = event.location - self.start_data.location; + // let new_location = self.initial_window_location.to_f64() + delta; + // let (window, space) = data + // .monitor_set + // .find_window_and_space(self.window.wl_surface().as_ref().unwrap()) + // .unwrap(); + // space.map_element(window.clone(), new_location.to_i32_round(), true); } fn relative_motion( diff --git a/src/grabs/resize_grab.rs b/src/grabs/resize_grab.rs index 2bc2f194..819e0b6a 100644 --- a/src/grabs/resize_grab.rs +++ b/src/grabs/resize_grab.rs @@ -1,6 +1,6 @@ use std::cell::RefCell; -use smithay::desktop::{Space, Window}; +use smithay::desktop::Window; use smithay::input::pointer::{ AxisFrame, ButtonEvent, GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, @@ -241,48 +241,48 @@ impl ResizeSurfaceState { } } -/// Should be called on `WlSurface::commit` -pub fn handle_commit(space: &mut Space, surface: &WlSurface) -> Option<()> { - let window = space - .elements() - .find(|w| w.toplevel().wl_surface() == surface) - .cloned()?; - - let mut window_loc = space.element_location(&window)?; - let geometry = window.geometry(); - - let new_loc: Point, Logical> = ResizeSurfaceState::with(surface, |state| { - state - .commit() - .and_then(|(edges, initial_rect)| { - // If the window is being resized by top or left, its location must be adjusted - // accordingly. - edges.intersects(ResizeEdge::TOP_LEFT).then(|| { - let new_x = edges - .intersects(ResizeEdge::LEFT) - .then_some(initial_rect.loc.x + (initial_rect.size.w - geometry.size.w)); - - let new_y = edges - .intersects(ResizeEdge::TOP) - .then_some(initial_rect.loc.y + (initial_rect.size.h - geometry.size.h)); - - (new_x, new_y).into() - }) - }) - .unwrap_or_default() +pub fn handle_commit(window: &Window) -> Option<()> { + // FIXME + let surface = window.toplevel().wl_surface(); + ResizeSurfaceState::with(surface, |state| { + state.commit(); }); - if let Some(new_x) = new_loc.x { - window_loc.x = new_x; - } - if let Some(new_y) = new_loc.y { - window_loc.y = new_y; - } - - if new_loc.x.is_some() || new_loc.y.is_some() { - // If TOP or LEFT side of the window got resized, we have to move it - space.map_element(window, window_loc, false); - } + // let mut window_loc = space.element_location(&window)?; + // let geometry = window.geometry(); + + // let new_loc: Point, Logical> = ResizeSurfaceState::with(surface, |state| { + // state + // .commit() + // .and_then(|(edges, initial_rect)| { + // // If the window is being resized by top or left, its location must be adjusted + // // accordingly. + // edges.intersects(ResizeEdge::TOP_LEFT).then(|| { + // let new_x = edges + // .intersects(ResizeEdge::LEFT) + // .then_some(initial_rect.loc.x + (initial_rect.size.w - geometry.size.w)); + + // let new_y = edges + // .intersects(ResizeEdge::TOP) + // .then_some(initial_rect.loc.y + (initial_rect.size.h - geometry.size.h)); + + // (new_x, new_y).into() + // }) + // }) + // .unwrap_or_default() + // }); + + // if let Some(new_x) = new_loc.x { + // window_loc.x = new_x; + // } + // if let Some(new_y) = new_loc.y { + // window_loc.y = new_y; + // } + + // if new_loc.x.is_some() || new_loc.y.is_some() { + // // If TOP or LEFT side of the window got resized, we have to move it + // space.map_element(window, window_loc, false); + // } Some(()) } -- cgit