foreign_toplevel: Change activated to mean keyboard focus
Browse files at this commitdeef52519a237a290bee6ded8aec7dbaac1e8e9aParent: 59ff3311 changed file +16 -5
src/protocols/foreign_toplevel.rsmodified+16 -5
| @@ -100,7 +100,8 @@ pub fn refresh(state: &mut State) { | ||
| 100 | 100 | .lock() |
| 101 | 101 | .unwrap(); |
| 102 | 102 | |
| 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); | |
| 104 | 105 | |
| 105 | 106 | match protocol_state.toplevels.entry(wl_surface.clone()) { |
| 106 | 107 | Entry::Occupied(entry) => { |
| @@ -387,17 +388,27 @@ where | ||
| 387 | 388 | } |
| 388 | 389 | } |
| 389 | 390 | |
| 390 | -fn foreign_toplevel_state(states: &ToplevelStateSet) -> ArrayVec<u32, 3> { | |
| 391 | +fn to_state_vec(states: &ToplevelStateSet, has_focus: bool) -> ArrayVec<u32, 3> { | |
| 391 | 392 | let mut rv = ArrayVec::new(); |
| 392 | 393 | if states.contains(xdg_toplevel::State::Maximized) { |
| 393 | 394 | rv.push(zwlr_foreign_toplevel_handle_v1::State::Maximized as u32); |
| 394 | 395 | } |
| 395 | - if states.contains(xdg_toplevel::State::Activated) { | |
| 396 | - rv.push(zwlr_foreign_toplevel_handle_v1::State::Activated as u32); | |
| 397 | - } | |
| 398 | 396 | if states.contains(xdg_toplevel::State::Fullscreen) { |
| 399 | 397 | rv.push(zwlr_foreign_toplevel_handle_v1::State::Fullscreen as u32); |
| 400 | 398 | } |
| 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 | + | |
| 401 | 412 | rv |
| 402 | 413 | } |
| 403 | 414 |