diff --git a/src/input/mod.rs b/src/input/mod.rs index e47f6130..0509ff32 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -2778,10 +2778,11 @@ impl State { return; } - if ButtonState::Pressed == button_state { - let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); - let modifiers = modifiers_from_state(mods); + let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); + let modifiers = modifiers_from_state(mods); + let mod_down = modifiers.contains(mod_key.to_modifiers()); + if ButtonState::Pressed == button_state { let mut is_mru_open = false; if let Some(mru_output) = self.niri.window_mru_ui.output() { is_mru_open = true; @@ -2862,44 +2863,41 @@ impl State { } } - if button == Some(MouseButton::Middle) && !pointer.is_grabbed() { - let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers()); - if mod_down { - let output_ws = if is_overview_open { - self.niri.workspace_under_cursor(true) - } else { - // We don't want to accidentally "catch" the wrong workspace during - // animations. - self.niri.output_under_cursor().and_then(|output| { - let mon = self.niri.layout.monitor_for_output(&output)?; - Some((output, mon.active_workspace_ref())) - }) - }; + if button == Some(MouseButton::Middle) && !pointer.is_grabbed() && mod_down { + let output_ws = if is_overview_open { + self.niri.workspace_under_cursor(true) + } else { + // We don't want to accidentally "catch" the wrong workspace during + // animations. + self.niri.output_under_cursor().and_then(|output| { + let mon = self.niri.layout.monitor_for_output(&output)?; + Some((output, mon.active_workspace_ref())) + }) + }; - if let Some((output, ws)) = output_ws { - let ws_id = ws.id(); + if let Some((output, ws)) = output_ws { + let ws_id = ws.id(); - self.niri.layout.focus_output(&output); + self.niri.layout.focus_output(&output); - let location = pointer.current_location(); - let start_data = PointerGrabStartData { - focus: None, - button: button_code, - location, - }; - let grab = SpatialMovementGrab::new(start_data, output, ws_id, false); - pointer.set_grab(self, grab, serial, Focus::Clear); - self.niri - .cursor_manager - .set_cursor_image(CursorImageStatus::Named(CursorIcon::AllScroll)); + let location = pointer.current_location(); + let start_data = PointerGrabStartData { + focus: None, + button: button_code, + location, + }; + let grab = SpatialMovementGrab::new(start_data, output, ws_id, false); + pointer.set_grab(self, grab, serial, Focus::Clear); + self.niri + .cursor_manager + .set_cursor_image(CursorImageStatus::Named(CursorIcon::AllScroll)); - // FIXME: granular. - self.niri.queue_redraw_all(); + // FIXME: granular. + self.niri.queue_redraw_all(); - // Don't activate the window under the cursor to avoid unnecessary - // scrolling when e.g. Mod+MMB clicking on a partially off-screen window. - return; - } + // Don't activate the window under the cursor to avoid unnecessary + // scrolling when e.g. Mod+MMB clicking on a partially off-screen window. + return; } } @@ -2908,7 +2906,6 @@ impl State { // Check if we need to start an interactive move. if button == Some(MouseButton::Left) && !pointer.is_grabbed() { - let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers()); if is_overview_open || mod_down { let location = pointer.current_location(); @@ -2942,72 +2939,69 @@ impl State { } } // Check if we need to start an interactive resize. - else if button == Some(MouseButton::Right) && !pointer.is_grabbed() { - let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers()); - if mod_down { - let location = pointer.current_location(); - let (output, pos_within_output) = self.niri.output_under(location).unwrap(); - let edges = self - .niri - .layout - .resize_edges_under(output, pos_within_output) - .unwrap_or(ResizeEdge::empty()); - - if !edges.is_empty() { - // See if we got a double resize-click gesture. - // FIXME: deduplicate with resize_request in xdg-shell somehow. - let time = get_monotonic_time(); - let last_cell = mapped.last_interactive_resize_start(); - let mut last = last_cell.get(); - last_cell.set(Some((time, edges))); - - // Floating windows don't have either of the double-resize-click - // gestures, so just allow it to resize. - if mapped.is_floating() { - last = None; + else if button == Some(MouseButton::Right) && !pointer.is_grabbed() && mod_down { + let location = pointer.current_location(); + let (output, pos_within_output) = self.niri.output_under(location).unwrap(); + let edges = self + .niri + .layout + .resize_edges_under(output, pos_within_output) + .unwrap_or(ResizeEdge::empty()); + + if !edges.is_empty() { + // See if we got a double resize-click gesture. + // FIXME: deduplicate with resize_request in xdg-shell somehow. + let time = get_monotonic_time(); + let last_cell = mapped.last_interactive_resize_start(); + let mut last = last_cell.get(); + last_cell.set(Some((time, edges))); + + // Floating windows don't have either of the double-resize-click + // gestures, so just allow it to resize. + if mapped.is_floating() { + last = None; + last_cell.set(None); + } + + if let Some((last_time, last_edges)) = last { + if time.saturating_sub(last_time) <= DOUBLE_CLICK_TIME { + // Allow quick resize after a triple click. last_cell.set(None); - } - if let Some((last_time, last_edges)) = last { - if time.saturating_sub(last_time) <= DOUBLE_CLICK_TIME { - // Allow quick resize after a triple click. - last_cell.set(None); - - let intersection = edges.intersection(last_edges); - if intersection.intersects(ResizeEdge::LEFT_RIGHT) { - // FIXME: don't activate once we can pass specific windows - // to actions. - self.niri.layout.activate_window(&window); - self.niri.layout.toggle_full_width(); - } - if intersection.intersects(ResizeEdge::TOP_BOTTOM) { - self.niri.layout.activate_window(&window); - self.niri.layout.reset_window_height(Some(&window)); - } - // FIXME: granular. - self.niri.queue_redraw_all(); - return; + let intersection = edges.intersection(last_edges); + if intersection.intersects(ResizeEdge::LEFT_RIGHT) { + // FIXME: don't activate once we can pass specific windows + // to actions. + self.niri.layout.activate_window(&window); + self.niri.layout.toggle_full_width(); + } + if intersection.intersects(ResizeEdge::TOP_BOTTOM) { + self.niri.layout.activate_window(&window); + self.niri.layout.reset_window_height(Some(&window)); } + // FIXME: granular. + self.niri.queue_redraw_all(); + return; } + } - self.niri.layout.activate_window(&window); + self.niri.layout.activate_window(&window); - if self - .niri - .layout - .interactive_resize_begin(window.clone(), edges) - { - let start_data = PointerGrabStartData { - focus: None, - button: button_code, - location, - }; - let grab = ResizeGrab::new(start_data, window.clone()); - pointer.set_grab(self, grab, serial, Focus::Clear); - self.niri.cursor_manager.set_cursor_image( - CursorImageStatus::Named(edges.cursor_icon()), - ); - } + if self + .niri + .layout + .interactive_resize_begin(window.clone(), edges) + { + let start_data = PointerGrabStartData { + focus: None, + button: button_code, + location, + }; + let grab = ResizeGrab::new(start_data, window.clone()); + pointer.set_grab(self, grab, serial, Focus::Clear); + self.niri + .cursor_manager + .set_cursor_image(CursorImageStatus::Named(edges.cursor_icon())); } } }