Prefer exclusive layer focus to on-demand on the same layer
Browse files at this commit3514cd2e368fe1883e1ed284e701ea9c18af438dParent: 96083841 changed file +27 -20
- src/niri.rs +27 -20
src/niri.rsmodified+27 -20
| @@ -794,43 +794,50 @@ impl State { | ||
| 794 | 794 | surface: Some(surface), |
| 795 | 795 | }) |
| 796 | 796 | }; |
| 797 | - let layer_focus = |surface: &LayerSurface| { | |
| 798 | - let can_receive_exclusive_focus = surface.cached_state().keyboard_interactivity | |
| 799 | - == wlr_layer::KeyboardInteractivity::Exclusive; | |
| 800 | - let is_on_demand_surface = | |
| 801 | - Some(surface) == self.niri.layer_shell_on_demand_focus.as_ref(); | |
| 802 | - | |
| 803 | - (can_receive_exclusive_focus || is_on_demand_surface) | |
| 804 | - .then(|| surface.wl_surface().clone()) | |
| 805 | - .map(|surface| KeyboardFocus::LayerShell { surface }) | |
| 797 | + | |
| 798 | + let excl_focus_on_layer = |layer| { | |
| 799 | + layers.layers_on(layer).find_map(|surface| { | |
| 800 | + let can_receive_exclusive_focus = surface.cached_state().keyboard_interactivity | |
| 801 | + == wlr_layer::KeyboardInteractivity::Exclusive; | |
| 802 | + can_receive_exclusive_focus | |
| 803 | + .then(|| surface.wl_surface().clone()) | |
| 804 | + .map(|surface| KeyboardFocus::LayerShell { surface }) | |
| 805 | + }) | |
| 806 | 806 | }; |
| 807 | - let on_d_focus = |surface: &LayerSurface| { | |
| 808 | - let is_on_demand_surface = | |
| 809 | - Some(surface) == self.niri.layer_shell_on_demand_focus.as_ref(); | |
| 810 | - is_on_demand_surface | |
| 811 | - .then(|| surface.wl_surface().clone()) | |
| 812 | - .map(|surface| KeyboardFocus::LayerShell { surface }) | |
| 807 | + | |
| 808 | + let on_d_focus_on_layer = |layer| { | |
| 809 | + layers.layers_on(layer).find_map(|surface| { | |
| 810 | + let is_on_demand_surface = | |
| 811 | + Some(surface) == self.niri.layer_shell_on_demand_focus.as_ref(); | |
| 812 | + is_on_demand_surface | |
| 813 | + .then(|| surface.wl_surface().clone()) | |
| 814 | + .map(|surface| KeyboardFocus::LayerShell { surface }) | |
| 815 | + }) | |
| 813 | 816 | }; |
| 814 | 817 | |
| 818 | + // Prefer exclusive focus on a layer, then check on-demand focus. | |
| 819 | + let focus_on_layer = | |
| 820 | + |layer| excl_focus_on_layer(layer).or_else(|| on_d_focus_on_layer(layer)); | |
| 821 | + | |
| 815 | 822 | let mut surface = grab_on_layer(Layer::Overlay); |
| 816 | 823 | // FIXME: we shouldn't prioritize the top layer grabs over regular overlay input or a |
| 817 | 824 | // fullscreen layout window. This will need tracking in grab() to avoid handing it out |
| 818 | 825 | // in the first place. Or a better way to structure this code. |
| 819 | 826 | surface = surface.or_else(|| grab_on_layer(Layer::Top)); |
| 820 | 827 | |
| 821 | - surface = surface.or_else(|| layers.layers_on(Layer::Overlay).find_map(layer_focus)); | |
| 828 | + surface = surface.or_else(|| focus_on_layer(Layer::Overlay)); | |
| 822 | 829 | |
| 823 | 830 | if mon.render_above_top_layer() { |
| 824 | 831 | surface = surface.or_else(layout_focus); |
| 825 | - surface = surface.or_else(|| layers.layers_on(Layer::Top).find_map(layer_focus)); | |
| 832 | + surface = surface.or_else(|| focus_on_layer(Layer::Top)); | |
| 826 | 833 | } else { |
| 827 | - surface = surface.or_else(|| layers.layers_on(Layer::Top).find_map(layer_focus)); | |
| 834 | + surface = surface.or_else(|| focus_on_layer(Layer::Top)); | |
| 828 | 835 | surface = surface.or_else(layout_focus); |
| 829 | 836 | } |
| 830 | 837 | |
| 831 | 838 | // Bottom and background layers can receive on-demand focus only. |
| 832 | - surface = surface.or_else(|| layers.layers_on(Layer::Bottom).find_map(on_d_focus)); | |
| 833 | - surface = surface.or_else(|| layers.layers_on(Layer::Background).find_map(on_d_focus)); | |
| 839 | + surface = surface.or_else(|| on_d_focus_on_layer(Layer::Bottom)); | |
| 840 | + surface = surface.or_else(|| on_d_focus_on_layer(Layer::Background)); | |
| 834 | 841 | |
| 835 | 842 | surface.unwrap_or(KeyboardFocus::Layout { surface: None }) |
| 836 | 843 | } else { |