forge
Explore
Log in

Don't you dare go Hollow

Prefer exclusive layer focus to on-demand on the same layer

Browse files at this commit

3514cd2e368fe1883e1ed284e701ea9c18af438dIvan MolodetskikhParent: 9608384
src/niri.rsmodified+27 -20
@@ -794,43 +794,50 @@ impl State {
794794 surface: Some(surface),
795795 })
796796 };
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+ })
806806 };
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+ })
813816 };
814817
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+
815822 let mut surface = grab_on_layer(Layer::Overlay);
816823 // FIXME: we shouldn't prioritize the top layer grabs over regular overlay input or a
817824 // fullscreen layout window. This will need tracking in grab() to avoid handing it out
818825 // in the first place. Or a better way to structure this code.
819826 surface = surface.or_else(|| grab_on_layer(Layer::Top));
820827
821- surface = surface.or_else(|| layers.layers_on(Layer::Overlay).find_map(layer_focus));
828+ surface = surface.or_else(|| focus_on_layer(Layer::Overlay));
822829
823830 if mon.render_above_top_layer() {
824831 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));
826833 } 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));
828835 surface = surface.or_else(layout_focus);
829836 }
830837
831838 // 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));
834841
835842 surface.unwrap_or(KeyboardFocus::Layout { surface: None })
836843 } else {