dummy_rustwlc/xkb/mod.rs
1//! Some libxkbcommon bindings.
2//!
3//! We do not wrap the full funcionality of xkb, as wlc handles
4//! most of the setup.
5
6pub mod keysyms;
7
8/*
9 * Copyright 1985, 1987, 1990, 1998 The Open Group
10 * Copyright 2008 Dan Nicholson
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in
20 * all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 *
29 * Except as contained in this notice, the names of the authors or their
30 * institutions shall not be used in advertising or otherwise to promote the
31 * sale, use or other dealings in this Software without prior written
32 * authorization from the authors.
33 */
34
35/************************************************************
36 * Copyright (c) 1993 by Silicon Graphics Computer Systems, Inc.
37 *
38 * Permission to use, copy, modify, and distribute this
39 * software and its documentation for any purpose and without
40 * fee is hereby granted, provided that the above copyright
41 * notice appear in all copies and that both that copyright
42 * notice and this permission notice appear in supporting
43 * documentation, and that the name of Silicon Graphics not be
44 * used in advertising or publicity pertaining to distribution
45 * of the software without specific prior written permission.
46 * Silicon Graphics makes no representation about the suitability
47 * of this software for any purpose. It is provided "as is"
48 * without any express or implied warranty.
49 *
50 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
51 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
52 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
53 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
54 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
55 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
56 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
57 * THE USE OR PERFORMANCE OF THIS SOFTWARE.
58 *
59 ********************************************************/
60
61/*
62 * Copyright © 2009-2012 Daniel Stone
63 * Copyright © 2012 Intel Corporation
64 * Copyright © 2012 Ran Benita
65 *
66 * Permission is hereby granted, free of charge, to any person obtaining a
67 * copy of this software and associated documentation files (the "Software"),
68 * to deal in the Software without restriction, including without limitation
69 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
70 * and/or sell copies of the Software, and to permit persons to whom the
71 * Software is furnished to do so, subject to the following conditions:
72 *
73 * The above copyright notice and this permission notice (including the next
74 * paragraph) shall be included in all copies or substantial portions of the
75 * Software.
76 *
77 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
78 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
79 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
80 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
81 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
82 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
83 * DEALINGS IN THE SOFTWARE.
84 *
85 * Author: Daniel Stone <daniel@fooishbar.org>
86 */
87
88// Keysym utils functions
89
90// An xkb keycode.
91// Keycodes are handled by wlc
92// #[derive(Debug, Clone, PartialEq, Eq)]
93// pub struct Keycode(u32);
94
95/// An xkb keysym.
96///
97/// # From xkb
98/// A number used to represent the symbols generated from a key on a keyboard.
99///
100/// A key, represented by a keycode, may generate different symbols according
101/// to keyboard state. For example, on a QWERTY keyboard, pressing the key
102/// labled \<A\> generates the symbol 'a'. If the Shift key is held, it
103/// generates the symbol 'A'. If a different layout is used, say Greek,
104/// it generates the symbol 'α'. And so on.
105///
106/// Each such symbol is represented by a keysym. Note that keysyms are
107/// somewhat more general, in that they can also represent some "function",
108/// such as "Left" or "Right" for the arrow keys. For more information,
109/// see:
110/// http://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#keysym_encoding
111///
112/// Specifically named keysyms can be found in the
113/// `xkbcommon/xkbcommon-keysyms.h` header file. Their name does not include
114/// the XKB_KEY_ prefix.
115///
116/// Besides those, any Unicode/ISO 10646 character in the range U0100 to
117/// U10FFFF can be represented by a keysym value in the range 0x01000100 to
118/// 0x0110FFFF. The name of Unicode keysyms is "U<codepoint>", e.g. "UA1B2".
119///
120/// The name of other unnamed keysyms is the hexadecimal representation of
121/// their value, e.g. "0xabcd1234". Keysym names are case-sensitive.
122///
123#[derive(Debug, Clone, PartialEq, Eq, Hash)]
124pub struct Keysym(u32);
125
126/// Represents flags used for `Keysym::from_name`
127#[repr(C)]
128#[derive(Debug, Clone, PartialEq, Eq)]
129pub enum NameFlags {
130 /// None, or "Case sensitive"
131 None = 0,
132 /// Case insensitive name search
133 CaseInsensitive = 1
134}
135
136/// Opaque keyboard state object.
137///
138/// State objects contain the active state of a keyboard (or keyboards), such
139/// as the currently effective layout and the active modifiers. It acts as a
140/// simple state machine, wherein key presses and releases are the input, and
141/// key symbols (keysyms) are the output.
142#[repr(C)]
143pub struct XKBState;
144
145/// Opaque compiled keymap object.
146///
147/// The keymap object holds all of the static keyboard information obtained
148/// from compiling XKB files.
149///
150/// A keymap is immutable after it is created (besides reference counts, etc.);
151/// if you need to change it, you must create a new one.
152#[repr(C)]
153pub struct XKBKeymap;
154
155impl Keysym {
156
157 /// Whether this keysym is a valid keysym.
158 ///
159 /// This checks whether the Keysym's value isn't `0` or `0xffffffff`.
160 ///
161 /// Tested on `libxkbcommon 0.5.0-1`, keysyms less than `0x20000000`
162 /// stopped having meaningful names (`.get_name()` returned `None`).
163 ///
164 /// # Validity
165 /// If a call to `Keysym::from_name(some_name)` returns a `Some(named_sym)`
166 /// , `named_sym.is_valid()` will return true.
167 ///
168 /// In general, whenever a Keysym `sym` passes `sym.is_valid()`,
169 /// `sym.get_name()` will be a `Some` (for keysyms less than 0x20000000).
170 ///
171 /// In addition, if `sym.get_name()` is a `Some(name)`,
172 /// `Keysym::from_name(name)` will also return a valid Keysym.
173 /// # Examples
174 /// ```rust
175 /// use rustwlc::xkb::Keysym;
176 ///
177 /// let sym = Keysym::from(0x41); // Something
178 /// assert!(sym.is_valid());
179 /// ```
180 #[inline]
181 pub fn is_valid(&self) -> bool {
182 self.0 != 0 && self.0 != 0xffffffff
183 }
184
185 /// Whether a Keysym is invalid.
186 ///
187 /// See `is_valid()`.
188 #[inline]
189 pub fn is_invalid(&self) -> bool {
190 self.0 == 0 || self.0 == 0xffffffff
191 }
192
193 /// Gets the `Keysym` as a `u32`.
194 pub fn get_code(&self) -> u32 {
195 self.0
196 }
197
198 /// Gets the Keysym for the given name.
199 ///
200 /// # Arguments
201 /// name: The name of a keysym. See docs for `get_name`.
202 /// This function will accept any name returned by that function.
203 ///
204 /// flags: A set of flags controlling how the search is done.
205 /// If the KeyboardFlags::CaseInsensitive flag is used and two keysym names
206 /// differ only by case, then the lower-case keysym is returned. For
207 /// instance, for KEY_a and KEY_A, this function would return KEY_a for the
208 /// case-insensitive search. If this functionality is needed, it is
209 /// recommended to first call this function without this flag, and if that
210 /// fails, only then to try with this flag, while possibly warning the user
211 /// that they have misspelled the name, and might get wrong results.
212 ///
213 /// returns: The keysym. If the name is invalid, returns None.
214 ///
215 /// # Examples
216 /// ```no-run
217 /// use rustwlc::xkb::{Keysym, NameFlags};
218 ///
219 /// let key_match_a = Keysym::from_name("a".to_string(), NameFlags::None);
220 /// assert!(key_match_a.is_some());
221 ///
222 /// let key_a = key_match_a.unwrap();
223 /// assert!(key_a.is_valid());
224 /// ```
225 pub fn from_name(name: String, flags: NameFlags) -> Option<Keysym> {
226 None
227 }
228
229 /// Gets name name of the keysym.
230 ///
231 /// # Examples
232 /// ```no-run
233 /// use rustwlc::xkb::{Keysym, NameFlags};
234 ///
235 /// let key = Keysym::from_name("a".to_string(), NameFlags::None).unwrap();
236 ///
237 /// assert_eq!(key.get_name(), Some("a".to_string()));
238 /// ```
239 pub fn get_name(&self) -> Option<String> {
240 None
241 }
242
243 /// Gets the Unicode/UTF8 representation of this keysym.
244 pub fn to_utf8(&self) -> Option<String> {
245 None
246 }
247
248 /// Gets the Unicode/UTF32 representation of this keysym.
249 pub fn to_utf32(&self) -> u32 {
250 unimplemented!()
251 }
252}
253
254/// An error returned from attempting to crete a Keysym.
255///
256/// Returned by `Keysym::from()`, `Keysym::from_name()`
257pub struct KeysymParseError;
258
259impl From<u32> for Keysym {
260
261 #[inline]
262 fn from(value: u32) -> Self {
263 Keysym(value)
264 }
265}