zed_xim/
lib.rs

1//! Implements the X Input Method (XIM) protocol.
2//!
3//! XIM is the input method framework used for X11 applications. To clarify, it provides
4//! a strategy for users of non-English keyboard to type symbols using only keys that are
5//! available on the keyboard. XIM involves two processes. One is the server, which waits
6//! for keyboard input in order to compose it into a symbol. The other is the client, which
7//! is usually a normal X11 application that waits for and acts on XIM events.
8//!
9//! This crate provides the following features:
10//!
11//! - An implementation of an XIM client, via the [`Client`] trait (requires the `client`
12//!   feature).
13//! - An implementation of an XIM server, via the [`Server`] trait (requires the `server`
14//!   feature).
15//! - A wrapper around [`x11rb`](x11rb-library), the X rust bindings. See the [`x11rb`] module
16//!   for more information (requires the `x11rb-client` or `x11rb-server` feature).
17//! - A wrapper around [`x11-dl`](x11dl-library), the standard X11 library. See the [`xlib`]
18//!   module for more information (requires the `xlib-client` feature).
19//!
20//! [x11rb-library]: https://crates.io/crates/x11rb
21//! [x11dl-library]: https://crates.io/crates/x11-dl
22
23#![no_std]
24#![allow(clippy::uninlined_format_args, clippy::too_many_arguments)]
25#![cfg_attr(not(feature = "xlib-client"), forbid(unsafe_code))]
26#![forbid(future_incompatible)]
27
28extern crate alloc;
29
30#[cfg(feature = "std")]
31extern crate std;
32
33#[cfg(feature = "client")]
34mod client;
35#[cfg(feature = "server")]
36mod server;
37
38#[cfg(any(feature = "x11rb-server", feature = "x11rb-client"))]
39pub mod x11rb;
40#[cfg(feature = "xlib-client")]
41pub mod xlib;
42
43#[cfg(feature = "client")]
44pub use crate::client::{Client, ClientError, ClientHandler};
45
46#[cfg(feature = "server")]
47pub const ALL_LOCALES: &str = include_str!("./all_locales.txt");
48
49#[cfg(feature = "server")]
50pub use crate::server::{
51    InputContext, InputMethod, Server, ServerCore, ServerError, ServerHandler, UserInputContext,
52    XimConnection, XimConnections,
53};
54pub type AHashMap<K, V> = hashbrown::HashMap<K, V, ahash::RandomState>;
55pub use xim_parser::*;
56
57#[allow(non_snake_case, dead_code)]
58struct Atoms<Atom> {
59    XIM_SERVERS: Atom,
60    LOCALES: Atom,
61    TRANSPORT: Atom,
62    XIM_XCONNECT: Atom,
63    XIM_PROTOCOL: Atom,
64}
65
66impl<Atom> Atoms<Atom> {
67    #[allow(unused)]
68    pub fn new<E, F>(f: F) -> Result<Self, E>
69    where
70        F: Fn(&'static str) -> Result<Atom, E>,
71    {
72        Ok(Self {
73            XIM_SERVERS: f("XIM_SERVERS")?,
74            LOCALES: f("LOCALES")?,
75            TRANSPORT: f("TRANSPORT")?,
76            XIM_XCONNECT: f("_XIM_XCONNECT")?,
77            XIM_PROTOCOL: f("_XIM_PROTOCOL")?,
78        })
79    }
80
81    #[allow(unused)]
82    pub fn new_null<E, F>(f: F) -> Result<Self, E>
83    where
84        F: Fn(&'static str) -> Result<Atom, E>,
85    {
86        Ok(Self {
87            XIM_SERVERS: f("XIM_SERVERS\0")?,
88            LOCALES: f("LOCALES\0")?,
89            TRANSPORT: f("TRANSPORT\0")?,
90            XIM_XCONNECT: f("_XIM_XCONNECT\0")?,
91            XIM_PROTOCOL: f("_XIM_PROTOCOL\0")?,
92        })
93    }
94}