forge
Explore
Log in

Don't you dare go Hollow

input: Extract mod_down upwards

Browse files at this commit

2e07282977cfa7df23062dd13bb5832c3e542e42Ivan MolodetskikhParent: cba0454
View diff with whitespace ignored.
src/input/mod.rsmodified+91 -97
@@ -2778,10 +2778,11 @@ impl State {
2778 return;2778 return;
2779 }2779 }
2780 2780
2781- if ButtonState::Pressed == button_state {2781+ let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();
2782- let mods = self.niri.seat.get_keyboard().unwrap().modifier_state();2782+ let modifiers = modifiers_from_state(mods);
2783- let modifiers = modifiers_from_state(mods);2783+ let mod_down = modifiers.contains(mod_key.to_modifiers());
2784 2784
2785+ if ButtonState::Pressed == button_state {
2785 let mut is_mru_open = false;2786 let mut is_mru_open = false;
2786 if let Some(mru_output) = self.niri.window_mru_ui.output() {2787 if let Some(mru_output) = self.niri.window_mru_ui.output() {
2787 is_mru_open = true;2788 is_mru_open = true;
@@ -2862,44 +2863,41 @@ impl State {
2862 }2863 }
2863 }2864 }
2864 2865
2865- if button == Some(MouseButton::Middle) && !pointer.is_grabbed() {2866+ if button == Some(MouseButton::Middle) && !pointer.is_grabbed() && mod_down {
2866- let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());2867+ let output_ws = if is_overview_open {
2867- if mod_down {2868+ self.niri.workspace_under_cursor(true)
2868- let output_ws = if is_overview_open {2869+ } else {
2869- self.niri.workspace_under_cursor(true)2870+ // We don't want to accidentally "catch" the wrong workspace during
2870- } else {2871+ // animations.
2871- // We don't want to accidentally "catch" the wrong workspace during2872+ self.niri.output_under_cursor().and_then(|output| {
2872- // animations.2873+ let mon = self.niri.layout.monitor_for_output(&output)?;
2873- self.niri.output_under_cursor().and_then(|output| {2874+ Some((output, mon.active_workspace_ref()))
2874- let mon = self.niri.layout.monitor_for_output(&output)?;2875+ })
2875- Some((output, mon.active_workspace_ref()))2876+ };
2876- })
2877- };
2878 2877
2879- if let Some((output, ws)) = output_ws {2878+ if let Some((output, ws)) = output_ws {
2880- let ws_id = ws.id();2879+ let ws_id = ws.id();
2881 2880
2882- self.niri.layout.focus_output(&output);2881+ self.niri.layout.focus_output(&output);
2883 2882
2884- let location = pointer.current_location();2883+ let location = pointer.current_location();
2885- let start_data = PointerGrabStartData {2884+ let start_data = PointerGrabStartData {
2886- focus: None,2885+ focus: None,
2887- button: button_code,2886+ button: button_code,
2888- location,2887+ location,
2889- };2888+ };
2890- let grab = SpatialMovementGrab::new(start_data, output, ws_id, false);2889+ let grab = SpatialMovementGrab::new(start_data, output, ws_id, false);
2891- pointer.set_grab(self, grab, serial, Focus::Clear);2890+ pointer.set_grab(self, grab, serial, Focus::Clear);
2892- self.niri2891+ self.niri
2893- .cursor_manager2892+ .cursor_manager
2894- .set_cursor_image(CursorImageStatus::Named(CursorIcon::AllScroll));2893+ .set_cursor_image(CursorImageStatus::Named(CursorIcon::AllScroll));
2895 2894
2896- // FIXME: granular.2895+ // FIXME: granular.
2897- self.niri.queue_redraw_all();2896+ self.niri.queue_redraw_all();
2898 2897
2899- // Don't activate the window under the cursor to avoid unnecessary2898+ // Don't activate the window under the cursor to avoid unnecessary
2900- // scrolling when e.g. Mod+MMB clicking on a partially off-screen window.2899+ // scrolling when e.g. Mod+MMB clicking on a partially off-screen window.
2901- return;2900+ return;
2902- }
2903 }2901 }
2904 }2902 }
2905 2903
@@ -2908,7 +2906,6 @@ impl State {
2908 2906
2909 // Check if we need to start an interactive move.2907 // Check if we need to start an interactive move.
2910 if button == Some(MouseButton::Left) && !pointer.is_grabbed() {2908 if button == Some(MouseButton::Left) && !pointer.is_grabbed() {
2911- let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());
2912 if is_overview_open || mod_down {2909 if is_overview_open || mod_down {
2913 let location = pointer.current_location();2910 let location = pointer.current_location();
2914 2911
@@ -2942,72 +2939,69 @@ impl State {
2942 }2939 }
2943 }2940 }
2944 // Check if we need to start an interactive resize.2941 // Check if we need to start an interactive resize.
2945- else if button == Some(MouseButton::Right) && !pointer.is_grabbed() {2942+ else if button == Some(MouseButton::Right) && !pointer.is_grabbed() && mod_down {
2946- let mod_down = modifiers_from_state(mods).contains(mod_key.to_modifiers());2943+ let location = pointer.current_location();
2947- if mod_down {2944+ let (output, pos_within_output) = self.niri.output_under(location).unwrap();
2948- let location = pointer.current_location();2945+ let edges = self
2949- let (output, pos_within_output) = self.niri.output_under(location).unwrap();2946+ .niri
2950- let edges = self2947+ .layout
2951- .niri2948+ .resize_edges_under(output, pos_within_output)
2952- .layout2949+ .unwrap_or(ResizeEdge::empty());
2953- .resize_edges_under(output, pos_within_output)2950+
2954- .unwrap_or(ResizeEdge::empty());2951+ if !edges.is_empty() {
2955-2952+ // See if we got a double resize-click gesture.
2956- if !edges.is_empty() {2953+ // FIXME: deduplicate with resize_request in xdg-shell somehow.
2957- // See if we got a double resize-click gesture.2954+ let time = get_monotonic_time();
2958- // FIXME: deduplicate with resize_request in xdg-shell somehow.2955+ let last_cell = mapped.last_interactive_resize_start();
2959- let time = get_monotonic_time();2956+ let mut last = last_cell.get();
2960- let last_cell = mapped.last_interactive_resize_start();2957+ last_cell.set(Some((time, edges)));
2961- let mut last = last_cell.get();2958+
2962- last_cell.set(Some((time, edges)));2959+ // Floating windows don't have either of the double-resize-click
2963-2960+ // gestures, so just allow it to resize.
2964- // Floating windows don't have either of the double-resize-click2961+ if mapped.is_floating() {
2965- // gestures, so just allow it to resize.2962+ last = None;
2966- if mapped.is_floating() {2963+ last_cell.set(None);
2967- last = None;2964+ }
2965+
2966+ if let Some((last_time, last_edges)) = last {
2967+ if time.saturating_sub(last_time) <= DOUBLE_CLICK_TIME {
2968+ // Allow quick resize after a triple click.
2968 last_cell.set(None);2969 last_cell.set(None);
2969- }
2970 2970
2971- if let Some((last_time, last_edges)) = last {2971+ let intersection = edges.intersection(last_edges);
2972- if time.saturating_sub(last_time) <= DOUBLE_CLICK_TIME {2972+ if intersection.intersects(ResizeEdge::LEFT_RIGHT) {
2973- // Allow quick resize after a triple click.2973+ // FIXME: don't activate once we can pass specific windows
2974- last_cell.set(None);2974+ // to actions.
2975-2975+ self.niri.layout.activate_window(&window);
2976- let intersection = edges.intersection(last_edges);2976+ self.niri.layout.toggle_full_width();
2977- if intersection.intersects(ResizeEdge::LEFT_RIGHT) {2977+ }
2978- // FIXME: don't activate once we can pass specific windows2978+ if intersection.intersects(ResizeEdge::TOP_BOTTOM) {
2979- // to actions.2979+ self.niri.layout.activate_window(&window);
2980- self.niri.layout.activate_window(&window);2980+ self.niri.layout.reset_window_height(Some(&window));
2981- self.niri.layout.toggle_full_width();
2982- }
2983- if intersection.intersects(ResizeEdge::TOP_BOTTOM) {
2984- self.niri.layout.activate_window(&window);
2985- self.niri.layout.reset_window_height(Some(&window));
2986- }
2987- // FIXME: granular.
2988- self.niri.queue_redraw_all();
2989- return;
2990 }2981 }
2982+ // FIXME: granular.
2983+ self.niri.queue_redraw_all();
2984+ return;
2991 }2985 }
2986+ }
2992 2987
2993- self.niri.layout.activate_window(&window);2988+ self.niri.layout.activate_window(&window);
2994 2989
2995- if self2990+ if self
2996- .niri2991+ .niri
2997- .layout2992+ .layout
2998- .interactive_resize_begin(window.clone(), edges)2993+ .interactive_resize_begin(window.clone(), edges)
2999- {2994+ {
3000- let start_data = PointerGrabStartData {2995+ let start_data = PointerGrabStartData {
3001- focus: None,2996+ focus: None,
3002- button: button_code,2997+ button: button_code,
3003- location,2998+ location,
3004- };2999+ };
3005- let grab = ResizeGrab::new(start_data, window.clone());3000+ let grab = ResizeGrab::new(start_data, window.clone());
3006- pointer.set_grab(self, grab, serial, Focus::Clear);3001+ pointer.set_grab(self, grab, serial, Focus::Clear);
3007- self.niri.cursor_manager.set_cursor_image(3002+ self.niri
3008- CursorImageStatus::Named(edges.cursor_icon()),3003+ .cursor_manager
3009- );3004+ .set_cursor_image(CursorImageStatus::Named(edges.cursor_icon()));
3010- }
3011 }3005 }
3012 }3006 }
3013 }3007 }