forge
Explore
Log in

Don't you dare go Hollow

foreign_toplevel: Change activated to mean keyboard focus

Browse files at this commit

deef52519a237a290bee6ded8aec7dbaac1e8e9aIvan MolodetskikhParent: 59ff331
src/protocols/foreign_toplevel.rsmodified+16 -5
@@ -100,7 +100,8 @@ pub fn refresh(state: &mut State) {
100100 .lock()
101101 .unwrap();
102102
103- let states = foreign_toplevel_state(&role.current.states);
103+ let has_focus = state.niri.keyboard_focus.as_ref() == Some(wl_surface);
104+ let states = to_state_vec(&role.current.states, has_focus);
104105
105106 match protocol_state.toplevels.entry(wl_surface.clone()) {
106107 Entry::Occupied(entry) => {
@@ -387,17 +388,27 @@ where
387388 }
388389 }
389390
390-fn foreign_toplevel_state(states: &ToplevelStateSet) -> ArrayVec<u32, 3> {
391+fn to_state_vec(states: &ToplevelStateSet, has_focus: bool) -> ArrayVec<u32, 3> {
391392 let mut rv = ArrayVec::new();
392393 if states.contains(xdg_toplevel::State::Maximized) {
393394 rv.push(zwlr_foreign_toplevel_handle_v1::State::Maximized as u32);
394395 }
395- if states.contains(xdg_toplevel::State::Activated) {
396- rv.push(zwlr_foreign_toplevel_handle_v1::State::Activated as u32);
397- }
398396 if states.contains(xdg_toplevel::State::Fullscreen) {
399397 rv.push(zwlr_foreign_toplevel_handle_v1::State::Fullscreen as u32);
400398 }
399+
400+ // HACK: wlr-foreign-toplevel-management states:
401+ //
402+ // These have the same meaning as the states with the same names defined in xdg-toplevel
403+ //
404+ // However, clients such as sfwbar and fcitx seem to treat the activated state as keyboard
405+ // focus, i.e. they don't expect multiple windows to have it set at once. Even Waybar which
406+ // handles multiple activated windows correctly uses it in its design in such a way that
407+ // keyboard focus would make more sense. Let's do what the clients expect.
408+ if has_focus {
409+ rv.push(zwlr_foreign_toplevel_handle_v1::State::Activated as u32);
410+ }
411+
401412 rv
402413 }
403414