From e7f746cceec3dfa1644d9e8afeb6400f837e8c61 Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Thu, 7 Mar 2024 16:54:19 +0100 Subject: [PATCH] shell: resize_request better handle tiled windows --- src/shell/layout/tiling/mod.rs | 2 +- src/shell/mod.rs | 139 +++++++++++++++++++-------------- 2 files changed, 82 insertions(+), 59 deletions(-) diff --git a/src/shell/layout/tiling/mod.rs b/src/shell/layout/tiling/mod.rs index 9287d357..af3361ca 100644 --- a/src/shell/layout/tiling/mod.rs +++ b/src/shell/layout/tiling/mod.rs @@ -2443,7 +2443,7 @@ impl TilingLayout { edges } - pub fn menu_resize( + pub fn resize_request( &self, mut node_id: NodeId, edge: ResizeEdge, diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 1c8cfab4..de90788d 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -2619,23 +2619,23 @@ impl Shell { return; }; - let new_loc = if edge.contains(ResizeEdge::LEFT) { + let new_loc = if edge.contains(ResizeEdge::LEFT) { Point::::from((geometry.loc.x, geometry.loc.y + (geometry.size.h / 2))) - } else if edge.contains(ResizeEdge::RIGHT) { - Point::::from(( - geometry.loc.x + geometry.size.w, - geometry.loc.y + (geometry.size.h / 2), - )) - } else if edge.contains(ResizeEdge::TOP) { + } else if edge.contains(ResizeEdge::RIGHT) { + Point::::from(( + geometry.loc.x + geometry.size.w, + geometry.loc.y + (geometry.size.h / 2), + )) + } else if edge.contains(ResizeEdge::TOP) { Point::::from((geometry.loc.x + (geometry.size.w / 2), geometry.loc.y)) - } else if edge.contains(ResizeEdge::BOTTOM) { - Point::::from(( - geometry.loc.x + (geometry.size.w / 2), - geometry.loc.y + geometry.size.h, - )) - } else { - return; - }; + } else if edge.contains(ResizeEdge::BOTTOM) { + Point::::from(( + geometry.loc.x + (geometry.size.w / 2), + geometry.loc.y + geometry.size.h, + )) + } else { + return; + }; let focus = Some((mapped.clone().into(), (new_loc - geometry.loc).as_logical())); @@ -2643,49 +2643,49 @@ impl Shell { start_data.focus = focus.clone(); let grab: ResizeGrab = if let Some(grab) = floating_layer.resize_request( - mapped, - seat, + mapped, + seat, start_data.clone(), - edge, - ReleaseMode::Click, + edge, + ReleaseMode::Click, ) { - grab.into() + grab.into() } else if let Some(ws) = state.common.shell.space_for_mut(&mapped) { - let Some(node_id) = mapped.tiling_node_id.lock().unwrap().clone() else { - return; - }; - let Some((node, left_up_idx, orientation)) = + let Some(node_id) = mapped.tiling_node_id.lock().unwrap().clone() else { + return; + }; + let Some((node, left_up_idx, orientation)) = ws.tiling_layer.resize_request(node_id, edge) - else { - return; - }; - ResizeForkGrab::new( - start_data, - new_loc.to_f64(), - node, - left_up_idx, - orientation, - ws.output.downgrade(), - ReleaseMode::Click, - ) - .into() + else { + return; + }; + ResizeForkGrab::new( + start_data, + new_loc.to_f64(), + node, + left_up_idx, + orientation, + ws.output.downgrade(), + ReleaseMode::Click, + ) + .into() } else { return; - }; + }; - let ptr = seat.get_pointer().unwrap(); - let serial = SERIAL_COUNTER.next_serial(); - ptr.motion( - state, + let ptr = seat.get_pointer().unwrap(); + let serial = SERIAL_COUNTER.next_serial(); + ptr.motion( + state, focus, - &MotionEvent { - location: new_loc.as_logical().to_f64(), - serial, - time: 0, - }, - ); - ptr.frame(state); - ptr.set_grab(state, grab, serial, Focus::Keep); + &MotionEvent { + location: new_loc.as_logical().to_f64(), + serial, + time: 0, + }, + ); + ptr.frame(state); + ptr.set_grab(state, grab, serial, Focus::Keep); } } @@ -2871,20 +2871,43 @@ impl Shell { return; }; - if let Some(grab) = floating_layer.resize_request( + let grab: ResizeGrab = if let Some(grab) = floating_layer.resize_request( &mapped, seat, start_data.clone(), edges, ReleaseMode::NoMouseButtons, ) { - seat.get_pointer().unwrap().set_grab( - state, - grab, - serial.unwrap_or_else(|| SERIAL_COUNTER.next_serial()), - Focus::Clear, - ); - } + grab.into() + } else if let Some(ws) = state.common.shell.space_for_mut(&mapped) { + let Some(node_id) = mapped.tiling_node_id.lock().unwrap().clone() else { + return; + }; + let Some((node, left_up_idx, orientation)) = + ws.tiling_layer.resize_request(node_id, edges) + else { + return; + }; + ResizeForkGrab::new( + start_data, + seat.get_pointer().unwrap().current_location().as_global(), + node, + left_up_idx, + orientation, + ws.output.downgrade(), + ReleaseMode::NoMouseButtons, + ) + .into() + } else { + return; + }; + + seat.get_pointer().unwrap().set_grab( + state, + grab, + serial.unwrap_or_else(|| SERIAL_COUNTER.next_serial()), + Focus::Clear, + ); } } }