def keysym_to_string(keysym): buffer = ffi.new("char[64]") r = lib.xkb_keysym_to_utf8(keysym, buffer, len(buffer)) if r == -1: raise XKBBufferTooSmall() if r == 0: return return ffi.string(buffer).decode('utf8')
def led_get_name(self, idx): """Get the name of a LED by index. Returns the name. If the index is invalid, returns None. """ r = lib.xkb_keymap_led_get_name(self._keymap, idx) if r == ffi.NULL: raise XKBInvalidLEDIndex() return ffi.string(r).decode('ascii')
def keysym_get_name(keysym): "Get the name of a keysym." name = ffi.new("char[64]") r = lib.xkb_keysym_get_name(keysym, name, len(name)) if r == -1: raise XKBInvalidKeysym() if r > len(name): raise XKBBufferTooSmall() return ffi.string(name).decode('ascii')
def mod_get_name(self, idx): """Get the name of a modifier by index. Returns the name. If the index is invalid, raises XKBInvalidModifierIndex. """ r = lib.xkb_keymap_mod_get_name(self._keymap, idx) if r == ffi.NULL: raise XKBInvalidModifierIndex() return ffi.string(r).decode('ascii')
def include_path_get(self, index): """Get a specific include path from the context's include path. Returns the include path at the specified index. If the index is invalid, returns None. """ assert isinstance(index, int) r = lib.xkb_context_include_path_get(self._context, index) if r: return ffi.string(r).decode("utf8")
def layout_get_name(self, idx): """Get the name of a layout by index. Returns the name. If the layout does not have a name, returns None. If the index is invalid, raises XKBInvalidLayoutIndex. """ if idx >= self.num_layouts(): raise XKBInvalidLayoutIndex() r = lib.xkb_keymap_layout_get_name(self._keymap, idx) if r == ffi.NULL: return return ffi.string(r).decode('ascii')
def get_as_bytes(self, format=lib.XKB_KEYMAP_FORMAT_TEXT_V1): """Get the compiled keymap as bytes. On Python 3 will return a bytes object. On Python 2 will return a str object. """ r = lib.xkb_keymap_get_as_string(self._keymap, format) if r == ffi.NULL: raise XKBKeymapReadError() kms = ffi.string(r) lib.free(r) return kms
def key_get_string(self, key): """Get the Unicode/UTF-8 string obtained from pressing a particular key in a given keyboard state. This function performs Capitalization and Control Keysym Transformations. Returns the string. If there is nothing to return, returns the empty string. """ buffer = ffi.new("char[64]") r = lib.xkb_state_key_get_utf8(self._state, key, buffer, len(buffer)) if r + 1 > len(buffer): raise XKBBufferTooSmall() return ffi.string(buffer).decode('utf8')
def _log_handler(user_data, level, message): context = ffi.from_handle(user_data) if context._log_fn: context._log_fn(context, level, ffi.string(message).decode('utf8'))