Пример #1
0
static void keyboardHandleKeymap(void* data,
                                 struct wl_keyboard* keyboard,
                                 uint32_t format,
                                 int fd,
                                 uint32_t size)
{
    struct xkb_keymap* keymap;
    struct xkb_state* state;
    char* mapStr;

    if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1)
    {
        close(fd);
        return;
    }

    mapStr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
    if (mapStr == MAP_FAILED) {
        close(fd);
        return;
    }

    keymap = xkb_map_new_from_string(_glfw.wl.xkb.context,
                                     mapStr,
                                     XKB_KEYMAP_FORMAT_TEXT_V1,
                                     0);
    munmap(mapStr, size);
    close(fd);

    if (!keymap)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Failed to compile keymap");
        return;
    }

    state = xkb_state_new(keymap);
    if (!state)
    {
        _glfwInputError(GLFW_PLATFORM_ERROR,
                        "Wayland: Failed to create XKB state");
        xkb_map_unref(keymap);
        return;
    }

    xkb_keymap_unref(_glfw.wl.xkb.keymap);
    xkb_state_unref(_glfw.wl.xkb.state);
    _glfw.wl.xkb.keymap = keymap;
    _glfw.wl.xkb.state = state;

    _glfw.wl.xkb.control_mask =
        1 << xkb_map_mod_get_index(_glfw.wl.xkb.keymap, "Control");
    _glfw.wl.xkb.alt_mask =
        1 << xkb_map_mod_get_index(_glfw.wl.xkb.keymap, "Mod1");
    _glfw.wl.xkb.shift_mask =
        1 << xkb_map_mod_get_index(_glfw.wl.xkb.keymap, "Shift");
    _glfw.wl.xkb.super_mask =
        1 << xkb_map_mod_get_index(_glfw.wl.xkb.keymap, "Mod4");
}
Пример #2
0
static void
input_method_keyboard_keymap(void *data,
			     struct wl_keyboard *wl_keyboard,
			     uint32_t format,
			     int32_t fd,
			     uint32_t size)
{
	struct simple_im *keyboard = data;
	char *map_str;

	if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
		close(fd);
		return;
	}

	map_str = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
	if (map_str == MAP_FAILED) {
		close(fd);
		return;
	}

	keyboard->keymap =
		xkb_map_new_from_string(keyboard->xkb_context,
					map_str,
					XKB_KEYMAP_FORMAT_TEXT_V1,
					0);

	munmap(map_str, size);
	close(fd);

	if (!keyboard->keymap) {
		fprintf(stderr, "failed to compile keymap\n");
		return;
	}

	keyboard->state = xkb_state_new(keyboard->keymap);
	if (!keyboard->state) {
		fprintf(stderr, "failed to create XKB state\n");
		xkb_map_unref(keyboard->keymap);
		return;
	}

	keyboard->control_mask =
		1 << xkb_map_mod_get_index(keyboard->keymap, "Control");
	keyboard->alt_mask =
		1 << xkb_map_mod_get_index(keyboard->keymap, "Mod1");
	keyboard->shift_mask =
		1 << xkb_map_mod_get_index(keyboard->keymap, "Shift");
}
Пример #3
0
void
WaylandInputEvent::createNewKeymap()
{
    m_xkbInfo.shift_mod  = xkb_map_mod_get_index(m_xkbInfo.keymap, XKB_MOD_NAME_SHIFT);
    m_xkbInfo.caps_mod   = xkb_map_mod_get_index(m_xkbInfo.keymap, XKB_MOD_NAME_CAPS);
    m_xkbInfo.ctrl_mod   = xkb_map_mod_get_index(m_xkbInfo.keymap, XKB_MOD_NAME_CTRL);
    m_xkbInfo.alt_mod    = xkb_map_mod_get_index(m_xkbInfo.keymap, XKB_MOD_NAME_ALT);
    m_xkbInfo.mod2_mod   = xkb_map_mod_get_index(m_xkbInfo.keymap, "Mod2");
    m_xkbInfo.mod3_mod   = xkb_map_mod_get_index(m_xkbInfo.keymap, "Mod3");
    m_xkbInfo.super_mod  = xkb_map_mod_get_index(m_xkbInfo.keymap, XKB_MOD_NAME_LOGO);
    m_xkbInfo.mod5_mod   = xkb_map_mod_get_index(m_xkbInfo.keymap, "Mod5");
    m_xkbInfo.num_led    = xkb_map_led_get_index(m_xkbInfo.keymap, XKB_LED_NAME_NUM);
    m_xkbInfo.caps_led   = xkb_map_led_get_index(m_xkbInfo.keymap, XKB_LED_NAME_CAPS);
    m_xkbInfo.scroll_led = xkb_map_led_get_index(m_xkbInfo.keymap, XKB_LED_NAME_SCROLL);

    char *keymapStr = xkb_map_get_as_string(m_xkbInfo.keymap);
    if (keymapStr == NULL){
        LOG_ERROR("WaylandX11InputEvent", "Failed to get string version of keymap");
        return;
    }
    m_xkbInfo.keymap_size = strlen(keymapStr) + 1;

    m_xkbInfo.keymap_fd = createAnonymousFile(m_xkbInfo.keymap_size);
    if (m_xkbInfo.keymap_fd < 0){
        LOG_WARNING("WaylandX11InputEvent", "Creating a keymap file for " <<
                    (unsigned long)m_xkbInfo.keymap_size <<
                    " bytes failed");
        goto err_keymapStr;
    }

    m_xkbInfo.keymap_area = (char*)mmap(NULL,
                                        m_xkbInfo.keymap_size,
                                        PROT_READ | PROT_WRITE,
                                        MAP_SHARED,
                                        m_xkbInfo.keymap_fd,
                                        0);
    if (m_xkbInfo.keymap_area == MAP_FAILED){
        LOG_WARNING("WaylandX11InputEvent", "Failed to mmap() " <<
                    (unsigned long) m_xkbInfo.keymap_size <<
                    " bytes");
        goto err_dev_zero;
    }
    strcpy(m_xkbInfo.keymap_area, keymapStr);
    free(keymapStr);

    return;

err_dev_zero:
    close(m_xkbInfo.keymap_fd);
    m_xkbInfo.keymap_fd = -1;

err_keymapStr:
    free(keymapStr);
    exit(EXIT_FAILURE);
}
Пример #4
0
static void
keyboard_handle_keymap(void *data, struct wl_keyboard *keyboard,
		       uint32_t format, int fd, uint32_t size)
{
	char *map_str;

	if (format != WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1) {
		close(fd);
		return;
	}

	map_str = (char *) mmap(nullptr, size, PROT_READ, MAP_SHARED, fd, 0);
	if (map_str == MAP_FAILED) {
		close(fd);
		return;
	}

	GLWin.keyboard.xkb.keymap = xkb_map_new_from_string(GLWin.keyboard.xkb.context,
						    map_str,
						    XKB_KEYMAP_FORMAT_TEXT_V1,
						    (xkb_keymap_compile_flags) 0);
	munmap(map_str, size);
	close(fd);

	if (!GLWin.keyboard.xkb.keymap) {
		fprintf(stderr, "failed to compile keymap\n");
		return;
	}

	GLWin.keyboard.xkb.state = xkb_state_new(GLWin.keyboard.xkb.keymap);
	if (!GLWin.keyboard.xkb.state) {
		fprintf(stderr, "failed to create XKB state\n");
		xkb_map_unref(GLWin.keyboard.xkb.keymap);
		GLWin.keyboard.xkb.keymap = nullptr;
		return;
	}

	GLWin.keyboard.xkb.control_mask =
		1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Control");
	GLWin.keyboard.xkb.alt_mask =
		1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Mod1");
	GLWin.keyboard.xkb.shift_mask =
		1 << xkb_map_mod_get_index(GLWin.keyboard.xkb.keymap, "Shift");
}