Implement double-resize-click to reset height/toggle full width
Browse files at this commite454cd6282eb52709a397e72abec01ed65f6c4c1Parent: 1c14a0a3 changed files +84 -16
- src/handlers/xdg_shell.rs +31 -8
- src/input.rs +40 -7
- src/window/mapped.rs +13 -1
src/handlers/xdg_shell.rsmodified+31 -8
| @@ -7,7 +7,7 @@ use smithay::input::pointer::Focus; | ||
| 7 | 7 | use smithay::output::Output; |
| 8 | 8 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; |
| 9 | 9 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_positioner::ConstraintAdjustment; |
| 10 | -use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self, ResizeEdge}; | |
| 10 | +use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel::{self}; | |
| 11 | 11 | use smithay::reexports::wayland_server::protocol::wl_output; |
| 12 | 12 | use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; |
| 13 | 13 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| @@ -30,9 +30,11 @@ use smithay::{ | ||
| 30 | 30 | delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_foreign, delegate_xdg_shell, |
| 31 | 31 | }; |
| 32 | 32 | |
| 33 | +use crate::input::DOUBLE_CLICK_TIME; | |
| 33 | 34 | use crate::layout::workspace::ColumnWidth; |
| 34 | 35 | use crate::niri::{PopupGrabState, State}; |
| 35 | 36 | use crate::resize_grab::ResizeGrab; |
| 37 | +use crate::utils::{get_monotonic_time, ResizeEdge}; | |
| 36 | 38 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; |
| 37 | 39 | |
| 38 | 40 | impl XdgShellHandler for State { |
| @@ -65,7 +67,7 @@ impl XdgShellHandler for State { | ||
| 65 | 67 | surface: ToplevelSurface, |
| 66 | 68 | _seat: WlSeat, |
| 67 | 69 | serial: Serial, |
| 68 | - edges: ResizeEdge, | |
| 70 | + edges: xdg_toplevel::ResizeEdge, | |
| 69 | 71 | ) { |
| 70 | 72 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 71 | 73 | if !pointer.has_grab(serial) { |
| @@ -89,16 +91,37 @@ impl XdgShellHandler for State { | ||
| 89 | 91 | return; |
| 90 | 92 | }; |
| 91 | 93 | |
| 94 | + let edges = ResizeEdge::from(edges); | |
| 92 | 95 | let window = mapped.window.clone(); |
| 93 | - if !self | |
| 94 | - .niri | |
| 95 | - .layout | |
| 96 | - .interactive_resize_begin(window.clone(), edges.into()) | |
| 97 | - { | |
| 96 | + | |
| 97 | + // See if we got a double resize-click gesture. | |
| 98 | + let time = get_monotonic_time(); | |
| 99 | + let last_cell = mapped.last_interactive_resize_start(); | |
| 100 | + let last = last_cell.get(); | |
| 101 | + last_cell.set(Some((time, edges))); | |
| 102 | + if let Some((last_time, last_edges)) = last { | |
| 103 | + if time.saturating_sub(last_time) <= DOUBLE_CLICK_TIME { | |
| 104 | + let intersection = edges.intersection(last_edges); | |
| 105 | + if intersection.intersects(ResizeEdge::LEFT_RIGHT) { | |
| 106 | + // FIXME: don't activate once we can pass specific windows to actions. | |
| 107 | + self.niri.layout.activate_window(&window); | |
| 108 | + self.niri.layout.toggle_full_width(); | |
| 109 | + } | |
| 110 | + if intersection.intersects(ResizeEdge::TOP_BOTTOM) { | |
| 111 | + // FIXME: don't activate once we can pass specific windows to actions. | |
| 112 | + self.niri.layout.activate_window(&window); | |
| 113 | + self.niri.layout.reset_window_height(); | |
| 114 | + } | |
| 115 | + return; | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + let grab = ResizeGrab::new(start_data, window.clone()); | |
| 120 | + | |
| 121 | + if !self.niri.layout.interactive_resize_begin(window, edges) { | |
| 98 | 122 | return; |
| 99 | 123 | } |
| 100 | 124 | |
| 101 | - let grab = ResizeGrab::new(start_data, window); | |
| 102 | 125 | pointer.set_grab(self, grab, serial, Focus::Clear); |
| 103 | 126 | self.niri.interactive_resize_ongoing = true; |
| 104 | 127 | } |
src/input.rsmodified+40 -7
| @@ -31,7 +31,9 @@ use crate::niri::State; | ||
| 31 | 31 | use crate::resize_grab::ResizeGrab; |
| 32 | 32 | use crate::ui::screenshot_ui::ScreenshotUi; |
| 33 | 33 | use crate::utils::spawning::spawn; |
| 34 | -use crate::utils::{center, get_monotonic_time}; | |
| 34 | +use crate::utils::{center, get_monotonic_time, ResizeEdge}; | |
| 35 | + | |
| 36 | +pub const DOUBLE_CLICK_TIME: Duration = Duration::from_millis(400); | |
| 35 | 37 | |
| 36 | 38 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 37 | 39 | pub enum CompositorMod { |
| @@ -1076,7 +1078,6 @@ impl State { | ||
| 1076 | 1078 | if ButtonState::Pressed == button_state { |
| 1077 | 1079 | if let Some(mapped) = self.niri.window_under_cursor() { |
| 1078 | 1080 | let window = mapped.window.clone(); |
| 1079 | - self.niri.layout.activate_window(&window); | |
| 1080 | 1081 | |
| 1081 | 1082 | // Check if we need to start an interactive resize. |
| 1082 | 1083 | if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() { |
| @@ -1093,23 +1094,55 @@ impl State { | ||
| 1093 | 1094 | .layout |
| 1094 | 1095 | .resize_edges_under(output, pos_within_output) |
| 1095 | 1096 | .unwrap(); |
| 1096 | - if self | |
| 1097 | - .niri | |
| 1098 | - .layout | |
| 1099 | - .interactive_resize_begin(window.clone(), edges) | |
| 1097 | + | |
| 1098 | + // See if we got a double resize-click gesture. | |
| 1099 | + // FIXME: deduplicate with resize_request in xdg-shell somehow. | |
| 1100 | + let time = get_monotonic_time(); | |
| 1101 | + let last_cell = mapped.last_interactive_resize_start(); | |
| 1102 | + let last = last_cell.get(); | |
| 1103 | + last_cell.set(Some((time, edges))); | |
| 1104 | + let mut did_gesture = false; | |
| 1105 | + if let Some((last_time, last_edges)) = last { | |
| 1106 | + if time.saturating_sub(last_time) <= DOUBLE_CLICK_TIME { | |
| 1107 | + let intersection = edges.intersection(last_edges); | |
| 1108 | + if intersection.intersects(ResizeEdge::LEFT_RIGHT) { | |
| 1109 | + // FIXME: don't activate once we can pass specific windows to | |
| 1110 | + // actions. | |
| 1111 | + self.niri.layout.activate_window(&window); | |
| 1112 | + self.niri.layout.toggle_full_width(); | |
| 1113 | + } | |
| 1114 | + if intersection.intersects(ResizeEdge::TOP_BOTTOM) { | |
| 1115 | + // FIXME: don't activate once we can pass specific windows to | |
| 1116 | + // actions. | |
| 1117 | + self.niri.layout.activate_window(&window); | |
| 1118 | + self.niri.layout.reset_window_height(); | |
| 1119 | + } | |
| 1120 | + did_gesture = true; | |
| 1121 | + } | |
| 1122 | + } | |
| 1123 | + | |
| 1124 | + self.niri.layout.activate_window(&window); | |
| 1125 | + | |
| 1126 | + if !did_gesture | |
| 1127 | + && self | |
| 1128 | + .niri | |
| 1129 | + .layout | |
| 1130 | + .interactive_resize_begin(window.clone(), edges) | |
| 1100 | 1131 | { |
| 1101 | 1132 | let start_data = PointerGrabStartData { |
| 1102 | 1133 | focus: None, |
| 1103 | 1134 | button: event.button_code(), |
| 1104 | 1135 | location, |
| 1105 | 1136 | }; |
| 1106 | - let grab = ResizeGrab::new(start_data, window); | |
| 1137 | + let grab = ResizeGrab::new(start_data, window.clone()); | |
| 1107 | 1138 | pointer.set_grab(self, grab, serial, Focus::Clear); |
| 1108 | 1139 | self.niri.interactive_resize_ongoing = true; |
| 1109 | 1140 | } |
| 1110 | 1141 | } |
| 1111 | 1142 | } |
| 1112 | 1143 | |
| 1144 | + self.niri.layout.activate_window(&window); | |
| 1145 | + | |
| 1113 | 1146 | // FIXME: granular. |
| 1114 | 1147 | self.niri.queue_redraw_all(); |
| 1115 | 1148 | } else if let Some(output) = self.niri.output_under_cursor() { |
src/window/mapped.rsmodified+13 -1
| @@ -1,5 +1,6 @@ | ||
| 1 | -use std::cell::RefCell; | |
| 1 | +use std::cell::{Cell, RefCell}; | |
| 2 | 2 | use std::cmp::{max, min}; |
| 3 | +use std::time::Duration; | |
| 3 | 4 | |
| 4 | 5 | use niri_config::WindowRule; |
| 5 | 6 | use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; |
| @@ -27,6 +28,7 @@ use crate::render_helpers::renderer::NiriRenderer; | ||
| 27 | 28 | use crate::render_helpers::snapshot::RenderSnapshot; |
| 28 | 29 | use crate::render_helpers::surface::render_snapshot_from_surface_tree; |
| 29 | 30 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; |
| 31 | +use crate::utils::ResizeEdge; | |
| 30 | 32 | |
| 31 | 33 | #[derive(Debug)] |
| 32 | 34 | pub struct Mapped { |
| @@ -61,6 +63,11 @@ pub struct Mapped { | ||
| 61 | 63 | |
| 62 | 64 | /// State of an ongoing interactive resize. |
| 63 | 65 | interactive_resize: Option<InteractiveResize>, |
| 66 | + | |
| 67 | + /// Last time interactive resize was started. | |
| 68 | + /// | |
| 69 | + /// Used for double-resize-click tracking. | |
| 70 | + last_interactive_resize_start: Cell<Option<(Duration, ResizeEdge)>>, | |
| 64 | 71 | } |
| 65 | 72 | |
| 66 | 73 | /// Interactive resize state. |
| @@ -100,6 +107,7 @@ impl Mapped { | ||
| 100 | 107 | animate_serials: Vec::new(), |
| 101 | 108 | animation_snapshot: None, |
| 102 | 109 | interactive_resize: None, |
| 110 | + last_interactive_resize_start: Cell::new(None), | |
| 103 | 111 | } |
| 104 | 112 | } |
| 105 | 113 | |
| @@ -199,6 +207,10 @@ impl Mapped { | ||
| 199 | 207 | pub fn store_animation_snapshot(&mut self, renderer: &mut GlesRenderer) { |
| 200 | 208 | self.animation_snapshot = Some(self.render_snapshot(renderer)); |
| 201 | 209 | } |
| 210 | + | |
| 211 | + pub fn last_interactive_resize_start(&self) -> &Cell<Option<(Duration, ResizeEdge)>> { | |
| 212 | + &self.last_interactive_resize_start | |
| 213 | + } | |
| 202 | 214 | } |
| 203 | 215 | |
| 204 | 216 | impl Drop for Mapped { |