Exemplo n.º 1
0
        private void KeymapCallback(void *data, wl_keyboard *proxy, wl_keyboard_keymap_format format, int fd, uint size)
        {
            if (format != wl_keyboard_keymap_format.XkbV1)
            {
                Libc.close(fd);
                throw new NotImplementedException("Only xkbcommon compatible keymaps are currently supported.");
            }

            var kbdStr = Libc.mmap(null, size, Libc.PROT_READ, Libc.MAP_PRIVATE, fd, 0);

            if (kbdStr == null)
            {
                Libc.close(fd);
                return;
            }

            var newKeymap = XkbCommon.xkb_keymap_new_from_string(_xkbContext, kbdStr, XkbCommon.XKB_KEYMAP_FORMAT_TEXT_V1);

            Libc.munmap(kbdStr, size);
            Libc.close(fd);

            if (newKeymap == null)
            {
                throw new OpenWindowException("Failed to create xkb keymap.");
            }

            var newState = XkbCommon.xkb_state_new(newKeymap);

            if (newState == null)
            {
                XkbCommon.xkb_keymap_unref(newKeymap);
                throw new OpenWindowException("Failed to create xkb state.");
            }

            if (_xkbKeymap != null)
            {
                XkbCommon.xkb_keymap_unref(_xkbKeymap);
            }
            if (_xkbState != null)
            {
                XkbCommon.xkb_state_unref(_xkbState);
            }

            _xkbKeymap = newKeymap;
            _xkbState  = newState;

            UpdateKeymap();
        }
Exemplo n.º 2
0
 public static extern xkb_state *xkb_state_new(xkb_keymap *keymap);
Exemplo n.º 3
0
 public static extern void xkb_keymap_unref(xkb_keymap *keymap);