mirror of
https://github.com/qingjian-team/qingjian.git
synced 2026-11-18 08:17:21 +00:00
Linux Server 读 [shortcut] switch_mode、[general] default_english 与 english_mode,设置程序在 Linux 上显示切换键与默认英文模式;Fcitx5 / Fcitx4 把 Ctrl 报成 VK 0x11 以认单击 Ctrl。 Closes #703
90 lines
2.3 KiB
Rust
90 lines
2.3 KiB
Rust
//! Linux 事件测试构造器。
|
|
use qingjian_core::Engine;
|
|
use qingjian_dictionary::Dictionary;
|
|
use qingjian_linux_server::{Router, RouterConfig};
|
|
use qingjian_platform::protocol::{
|
|
ClientMessage, KeyEvent, KeyModifiers, PROTOCOL_VERSION, SessionId,
|
|
};
|
|
use serde_json::{Value, json};
|
|
|
|
pub fn router() -> Router {
|
|
router_with(RouterConfig::default())
|
|
}
|
|
pub fn router_with(config: RouterConfig) -> Router {
|
|
let mut router = Router::new(
|
|
Engine::new(
|
|
Dictionary::parse("你好\tni hao\t100\n你\tni\t80\n泥\tni\t70\n拟\tni\t60\n").unwrap(),
|
|
),
|
|
RouterConfig {
|
|
page_size: 1,
|
|
..config
|
|
},
|
|
);
|
|
for id in [1, 2] {
|
|
router.handle(ClientMessage::OpenSession {
|
|
session: SessionId(id),
|
|
app: None,
|
|
protocol: PROTOCOL_VERSION,
|
|
});
|
|
router.handle_linux(json!({"DisplayReporting": {"session": id, "identity": {"generation": 1, "context": format!("context-{id}"), "revision": 0}}}));
|
|
caps(&mut router, id, false, false, false);
|
|
}
|
|
router
|
|
}
|
|
pub fn event(router: &mut Router, id: u64, event: Value) -> Value {
|
|
router
|
|
.handle_linux(json!({"LinuxEvent": {"session": id, "event": event}}))
|
|
.unwrap()["KeyResult"]
|
|
.clone()
|
|
}
|
|
pub fn caps(
|
|
router: &mut Router,
|
|
id: u64,
|
|
sensitive: bool,
|
|
password_field: bool,
|
|
disabled: bool,
|
|
) -> Value {
|
|
event(
|
|
router,
|
|
id,
|
|
json!({"Capabilities": {"sensitive": sensitive, "password": password_field, "disabled": disabled}}),
|
|
)
|
|
}
|
|
pub fn key(
|
|
router: &mut Router,
|
|
id: u64,
|
|
code: u32,
|
|
character: Option<char>,
|
|
release: bool,
|
|
) -> Value {
|
|
key_with(
|
|
router,
|
|
id,
|
|
code,
|
|
character,
|
|
KeyModifiers::default(),
|
|
release,
|
|
)
|
|
}
|
|
pub fn key_with(
|
|
router: &mut Router,
|
|
id: u64,
|
|
code: u32,
|
|
character: Option<char>,
|
|
modifiers: KeyModifiers,
|
|
release: bool,
|
|
) -> Value {
|
|
event(
|
|
router,
|
|
id,
|
|
json!({"Key": {"event": KeyEvent::new(code, character, modifiers), "release": release}}),
|
|
)
|
|
}
|
|
pub fn compose(router: &mut Router, id: u64, text: &str) -> Value {
|
|
let mut response = Value::Null;
|
|
for c in text.chars() {
|
|
response = key(router, id, c as u32, Some(c), false);
|
|
}
|
|
response
|
|
}
|