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 | use smithay::output::Output; | 7 | use smithay::output::Output; |
| 8 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; | 8 | use smithay::reexports::wayland_protocols::xdg::decoration::zv1::server::zxdg_toplevel_decoration_v1; |
| 9 | use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_positioner::ConstraintAdjustment; | 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 | use smithay::reexports::wayland_server::protocol::wl_output; | 11 | use smithay::reexports::wayland_server::protocol::wl_output; |
| 12 | use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; | 12 | use smithay::reexports::wayland_server::protocol::wl_seat::WlSeat; |
| 13 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; | 13 | use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface; |
| @@ -30,9 +30,11 @@ use smithay::{ | |||
| 30 | delegate_kde_decoration, delegate_xdg_decoration, delegate_xdg_foreign, delegate_xdg_shell, | 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 | use crate::layout::workspace::ColumnWidth; | 34 | use crate::layout::workspace::ColumnWidth; |
| 34 | use crate::niri::{PopupGrabState, State}; | 35 | use crate::niri::{PopupGrabState, State}; |
| 35 | use crate::resize_grab::ResizeGrab; | 36 | use crate::resize_grab::ResizeGrab; |
| 37 | +use crate::utils::{get_monotonic_time, ResizeEdge}; | ||
| 36 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; | 38 | use crate::window::{InitialConfigureState, ResolvedWindowRules, Unmapped, WindowRef}; |
| 37 | 39 | ||
| 38 | impl XdgShellHandler for State { | 40 | impl XdgShellHandler for State { |
| @@ -65,7 +67,7 @@ impl XdgShellHandler for State { | |||
| 65 | surface: ToplevelSurface, | 67 | surface: ToplevelSurface, |
| 66 | _seat: WlSeat, | 68 | _seat: WlSeat, |
| 67 | serial: Serial, | 69 | serial: Serial, |
| 68 | - edges: ResizeEdge, | 70 | + edges: xdg_toplevel::ResizeEdge, |
| 69 | ) { | 71 | ) { |
| 70 | let pointer = self.niri.seat.get_pointer().unwrap(); | 72 | let pointer = self.niri.seat.get_pointer().unwrap(); |
| 71 | if !pointer.has_grab(serial) { | 73 | if !pointer.has_grab(serial) { |
| @@ -89,16 +91,37 @@ impl XdgShellHandler for State { | |||
| 89 | return; | 91 | return; |
| 90 | }; | 92 | }; |
| 91 | 93 | ||
| 94 | + let edges = ResizeEdge::from(edges); | ||
| 92 | let window = mapped.window.clone(); | 95 | let window = mapped.window.clone(); |
| 93 | - if !self | 96 | + |
| 94 | - .niri | 97 | + // See if we got a double resize-click gesture. |
| 95 | - .layout | 98 | + let time = get_monotonic_time(); |
| 96 | - .interactive_resize_begin(window.clone(), edges.into()) | 99 | + let last_cell = mapped.last_interactive_resize_start(); |
| 97 | - { | 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 | return; | 122 | return; |
| 99 | } | 123 | } |
| 100 | 124 | ||
| 101 | - let grab = ResizeGrab::new(start_data, window); | ||
| 102 | pointer.set_grab(self, grab, serial, Focus::Clear); | 125 | pointer.set_grab(self, grab, serial, Focus::Clear); |
| 103 | self.niri.interactive_resize_ongoing = true; | 126 | self.niri.interactive_resize_ongoing = true; |
| 104 | } | 127 | } |
src/input.rsmodified+40 -7
| @@ -31,7 +31,9 @@ use crate::niri::State; | |||
| 31 | use crate::resize_grab::ResizeGrab; | 31 | use crate::resize_grab::ResizeGrab; |
| 32 | use crate::ui::screenshot_ui::ScreenshotUi; | 32 | use crate::ui::screenshot_ui::ScreenshotUi; |
| 33 | use crate::utils::spawning::spawn; | 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 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 38 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 37 | pub enum CompositorMod { | 39 | pub enum CompositorMod { |
| @@ -1076,7 +1078,6 @@ impl State { | |||
| 1076 | if ButtonState::Pressed == button_state { | 1078 | if ButtonState::Pressed == button_state { |
| 1077 | if let Some(mapped) = self.niri.window_under_cursor() { | 1079 | if let Some(mapped) = self.niri.window_under_cursor() { |
| 1078 | let window = mapped.window.clone(); | 1080 | let window = mapped.window.clone(); |
| 1079 | - self.niri.layout.activate_window(&window); | ||
| 1080 | 1081 | ||
| 1081 | // Check if we need to start an interactive resize. | 1082 | // Check if we need to start an interactive resize. |
| 1082 | if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() { | 1083 | if event.button() == Some(MouseButton::Right) && !pointer.is_grabbed() { |
| @@ -1093,23 +1094,55 @@ impl State { | |||
| 1093 | .layout | 1094 | .layout |
| 1094 | .resize_edges_under(output, pos_within_output) | 1095 | .resize_edges_under(output, pos_within_output) |
| 1095 | .unwrap(); | 1096 | .unwrap(); |
| 1096 | - if self | 1097 | + |
| 1097 | - .niri | 1098 | + // See if we got a double resize-click gesture. |
| 1098 | - .layout | 1099 | + // FIXME: deduplicate with resize_request in xdg-shell somehow. |
| 1099 | - .interactive_resize_begin(window.clone(), edges) | 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 | let start_data = PointerGrabStartData { | 1132 | let start_data = PointerGrabStartData { |
| 1102 | focus: None, | 1133 | focus: None, |
| 1103 | button: event.button_code(), | 1134 | button: event.button_code(), |
| 1104 | location, | 1135 | location, |
| 1105 | }; | 1136 | }; |
| 1106 | - let grab = ResizeGrab::new(start_data, window); | 1137 | + let grab = ResizeGrab::new(start_data, window.clone()); |
| 1107 | pointer.set_grab(self, grab, serial, Focus::Clear); | 1138 | pointer.set_grab(self, grab, serial, Focus::Clear); |
| 1108 | self.niri.interactive_resize_ongoing = true; | 1139 | self.niri.interactive_resize_ongoing = true; |
| 1109 | } | 1140 | } |
| 1110 | } | 1141 | } |
| 1111 | } | 1142 | } |
| 1112 | 1143 | ||
| 1144 | + self.niri.layout.activate_window(&window); | ||
| 1145 | + | ||
| 1113 | // FIXME: granular. | 1146 | // FIXME: granular. |
| 1114 | self.niri.queue_redraw_all(); | 1147 | self.niri.queue_redraw_all(); |
| 1115 | } else if let Some(output) = self.niri.output_under_cursor() { | 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 | use std::cmp::{max, min}; | 2 | use std::cmp::{max, min}; |
| 3 | +use std::time::Duration; | ||
| 3 | 4 | ||
| 4 | use niri_config::WindowRule; | 5 | use niri_config::WindowRule; |
| 5 | use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; | 6 | use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRenderElement}; |
| @@ -27,6 +28,7 @@ use crate::render_helpers::renderer::NiriRenderer; | |||
| 27 | use crate::render_helpers::snapshot::RenderSnapshot; | 28 | use crate::render_helpers::snapshot::RenderSnapshot; |
| 28 | use crate::render_helpers::surface::render_snapshot_from_surface_tree; | 29 | use crate::render_helpers::surface::render_snapshot_from_surface_tree; |
| 29 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; | 30 | use crate::render_helpers::{BakedBuffer, RenderTarget, SplitElements}; |
| 31 | +use crate::utils::ResizeEdge; | ||
| 30 | 32 | ||
| 31 | #[derive(Debug)] | 33 | #[derive(Debug)] |
| 32 | pub struct Mapped { | 34 | pub struct Mapped { |
| @@ -61,6 +63,11 @@ pub struct Mapped { | |||
| 61 | 63 | ||
| 62 | /// State of an ongoing interactive resize. | 64 | /// State of an ongoing interactive resize. |
| 63 | interactive_resize: Option<InteractiveResize>, | 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 | /// Interactive resize state. | 73 | /// Interactive resize state. |
| @@ -100,6 +107,7 @@ impl Mapped { | |||
| 100 | animate_serials: Vec::new(), | 107 | animate_serials: Vec::new(), |
| 101 | animation_snapshot: None, | 108 | animation_snapshot: None, |
| 102 | interactive_resize: None, | 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 | pub fn store_animation_snapshot(&mut self, renderer: &mut GlesRenderer) { | 207 | pub fn store_animation_snapshot(&mut self, renderer: &mut GlesRenderer) { |
| 200 | self.animation_snapshot = Some(self.render_snapshot(renderer)); | 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 | impl Drop for Mapped { | 216 | impl Drop for Mapped { |