aboutsummaryrefslogtreecommitdiff
path: root/src/client/shell/input_source.rs
blob: 7997c72f90faa7a194062d0f45498eb35d90f204 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use super::*;

impl ClientShellState {
    fn wants_ascii_input(&self) -> bool {
        if let Some(overlay) = self.overlay.as_ref() {
            return matches!(
                overlay,
                ClientShellOverlay::ConfirmClose(_)
                    | ClientShellOverlay::Help(_)
                    | ClientShellOverlay::Navigator(_)
                    | ClientShellOverlay::WorktreeRemove(_)
                    | ClientShellOverlay::ContextMenu(_)
                    | ClientShellOverlay::GlobalMenu(_)
            );
        }
        matches!(
            self.mode,
            ClientShellMode::Prefix
                | ClientShellMode::Navigate
                | ClientShellMode::Resize
                | ClientShellMode::Copy
        )
    }

    pub(crate) fn reconcile_input_source(&mut self) {
        // Keep the platform restore token while another window has focus. Restoring
        // through a global key injection is only safe after this client regains focus.
        if self.outer_focused == Some(false) {
            return;
        }
        let desired = self.config.switch_ascii_input_source_in_prefix && self.wants_ascii_input();
        if desired != self.ascii_input_source_active {
            self.ascii_input_source_active = desired;
            self.pending_input_source_changes.push(desired);
        }
    }

    pub(crate) fn take_input_source_changes(&mut self) -> Vec<bool> {
        std::mem::take(&mut self.pending_input_source_changes)
    }
}