aboutsummaryrefslogtreecommitdiffstats
path: root/default-plugins/mobile/src/input.rs
blob: d797f19cc388dee55cabd261e2143350608f24e9 (plain) (blame)
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
use zellij_tile::prelude::*;

use crate::components::modifier_bar::{CellId, ModifierBarController, TapOutcome};

#[derive(Default)]
pub struct Input {
    pub modifier_bar: ModifierBarController,
    pub ctrl_held: bool,
    pub alt_held: bool,
}

impl Input {
    pub fn merge_held_modifiers(&self, key: &KeyWithModifier) -> KeyWithModifier {
        let mut merged = key.clone();
        if self.ctrl_held {
            merged.key_modifiers.insert(KeyModifier::Ctrl);
        }
        if self.alt_held {
            merged.key_modifiers.insert(KeyModifier::Alt);
        }
        merged
    }

    pub fn handle_tap(&mut self, cell: CellId) -> TapOutcome {
        self.modifier_bar
            .handle_tap(cell, &mut self.ctrl_held, &mut self.alt_held)
    }
}