mux: explicitly update tab/pane active status on focus change

Previously, we'd record the focused pane only in the per-client
view.

That status didn't propagate through the model fully, leading to
inconsistencies when using activate-pane-direction.

This commit does the full model update to force that through.
I may regret this later: the focus state was intended to be
a per-client attribute and this effectively prevents that
from ever being useful.

Maybe the per-client state should just be removed?
Will ponder that later.

refs: https://github.com/wez/wezterm/issues/3448
refs: https://github.com/wez/wezterm/issues/3387

Also sneaking in here is not updating the last input time
for a client unless the input was taken by a user.
This commit is contained in:
Wez Furlong committed 2023-04-04 17:31:35 -07:00
1 parent 9d44d6d864
commit 11dc59b613
3 files changed
+58 -6

No files matched your search

+17
View File
@@ -492,6 +492,23 @@ pdu! {
}
impl Pdu {
/// Returns true if this type of Pdu represents action taken
/// directly by a user, rather than background traffic on
/// a live connection
pub fn is_user_input(&self) -> bool {
match self {
Self::WriteToPane(_)
| Self::SendKeyDown(_)
| Self::SendMouseEvent(_)
| Self::SendPaste(_)
| Self::Resize(_)
| Self::SetClipboard(_)
| Self::SetPaneZoomed(_)
| Self::SpawnV2(_) => true,
_ => false,
}
}
pub fn stream_decode(buffer: &mut Vec<u8>) -> anyhow::Result<Option<DecodedPdu>> {
let mut cursor = Cursor::new(buffer.as_slice());
match Self::decode(&mut cursor) {
+1
View File
@@ -91,6 +91,7 @@ As features stabilize some brief notes about them will accumulate here.
produce a warning about the remote home directory not being readable to
the local machine or vice versa. #3442
* `wezterm.config_builder` now works with `table.insert(config.keys, {..})`
* mux: `wezterm cli activate-pane-direction` inconsistent behavior with remote mux. #3387 #3448
### 20230326-111934-3666303c
+40 -6
View File
@@ -247,7 +247,9 @@ impl SessionHandler {
let serial = decoded.serial;
if let Some(client_id) = &self.client_id {
Mux::get().client_had_input(client_id);
if decoded.pdu.is_user_input() {
Mux::get().client_had_input(client_id);
}
}
let send_response = move |result: anyhow::Result<Pdu>| {
@@ -303,13 +305,45 @@ impl SessionHandler {
Pdu::SetFocusedPane(SetFocusedPane { pane_id }) => {
let client_id = self.client_id.clone();
spawn_into_main_thread(async move {
let mux = Mux::get();
let _identity = mux.with_identity(client_id);
mux.record_focus_for_current_identity(pane_id);
mux.notify(mux::MuxNotification::PaneFocused(pane_id));
catch(
move || {
let mux = Mux::get();
let _identity = mux.with_identity(client_id);
log::info!("doing SetFocusedPane {pane_id}");
let pane = mux
.get_pane(pane_id)
.ok_or_else(|| anyhow::anyhow!("pane {pane_id} not found"))?;
let (_domain_id, window_id, tab_id) = mux
.resolve_pane_id(pane_id)
.ok_or_else(|| anyhow::anyhow!("pane {pane_id} not found"))?;
{
let mut window =
mux.get_window_mut(window_id).ok_or_else(|| {
anyhow::anyhow!("window {window_id} not found")
})?;
let tab_idx = window.idx_by_id(tab_id).ok_or_else(|| {
anyhow::anyhow!(
"tab {tab_id} isn't really in window {window_id}!?"
)
})?;
window.save_and_then_set_active(tab_idx);
}
let tab = mux
.get_tab(tab_id)
.ok_or_else(|| anyhow::anyhow!("tab {tab_id} not found"))?;
tab.set_active_pane(&pane);
mux.record_focus_for_current_identity(pane_id);
mux.notify(mux::MuxNotification::PaneFocused(pane_id));
Ok(Pdu::UnitResponse(UnitResponse {}))
},
send_response,
)
})
.detach();
send_response(Ok(Pdu::UnitResponse(UnitResponse {})))
}
Pdu::GetClientList(GetClientList) => {
spawn_into_main_thread(async move {