static void
clutter_wayland_handle_keymap (void *data,
                               struct wl_keyboard *keyboard,
                               uint32_t format,
                               int32_t fd,
                               uint32_t size)
{
  ClutterInputDeviceWayland *device = data;
  struct xkb_context *ctx;
  struct xkb_keymap *keymap;
  char *map_str;

  if (device->xkb)
    {
      xkb_state_unref (device->xkb);
      device->xkb = NULL;
    }

  ctx = xkb_context_new (0);
  if (!ctx)
    {
      close (fd);
      return;
    }

  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;
    }

  keymap = xkb_map_new_from_string (ctx,
                                    map_str,
                                    XKB_KEYMAP_FORMAT_TEXT_V1,
                                    0);
  xkb_context_unref (ctx);
  munmap (map_str, size);
  close (fd);

  if (!keymap)
    {
      g_warning ("failed to compile keymap\n");
      return;
    }

  device->xkb = xkb_state_new(keymap);
  xkb_map_unref (keymap);
  if (!device->xkb)
    {
      g_warning ("failed to create XKB state object\n");
      return;
    }
}
Esempio n. 2
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");
}
void EglFSWaylandInput::releaseKeymap()
{
    if (m_xkbState)
        xkb_state_unref(m_xkbState);
    if (m_xkbKeymap)
        xkb_map_unref(m_xkbKeymap);
    if (m_xkbContext)
        xkb_context_unref(m_xkbContext);
}
Esempio n. 4
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");
}
Esempio n. 5
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");
}
Esempio n. 6
0
/* KEYBOARD LISTENER */
static void keyboard_handle_keymap(void *data,
                                   struct wl_keyboard *wl_keyboard,
                                   uint32_t format,
                                   int32_t fd,
                                   uint32_t size)
{
    struct vo_wayland_state *wl = 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;
    }

    wl->input.xkb.keymap = xkb_keymap_new_from_buffer(wl->input.xkb.context,
                                                      map_str,
                                                      size,
                                                      XKB_KEYMAP_FORMAT_TEXT_V1,
                                                      0);

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

    if (!wl->input.xkb.keymap) {
        MP_ERR(wl, "failed to compile keymap\n");
        return;
    }

    wl->input.xkb.state = xkb_state_new(wl->input.xkb.keymap);
    if (!wl->input.xkb.state) {
        MP_ERR(wl, "failed to create XKB state\n");
        xkb_map_unref(wl->input.xkb.keymap);
        wl->input.xkb.keymap = NULL;
        return;
    }
}
Esempio n. 7
0
static void
input_handle_keymap(void *data, struct wl_keyboard *keyboard, uint32_t format,
		    int fd, uint32_t size)
{
	struct wayland_input *input = data;
	struct xkb_keymap *keymap;
	char *map_str;

	if (!data) {
		close(fd);
		return;
	}

	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;
	}

	keymap = xkb_map_new_from_string(input->compositor->base.xkb_context,
					 map_str,
					 XKB_KEYMAP_FORMAT_TEXT_V1,
					 0);
	munmap(map_str, size);
	close(fd);

	if (!keymap) {
		weston_log("failed to compile keymap\n");
		return;
	}

	weston_seat_init_keyboard(&input->base, keymap);
	xkb_map_unref(keymap);
}
Esempio n. 8
0
WaylandInputEvent::~WaylandInputEvent()
{
    if (!m_wlEventSource)
        wl_event_source_remove(m_wlEventSource);

    if (m_xkbInfo.keymap)
        xkb_map_unref(m_xkbInfo.keymap);

    if (m_xkbInfo.keymap_area)
        munmap(m_xkbInfo.keymap_area, m_xkbInfo.keymap_size);

    if (m_xkbInfo.keymap_fd >= 0)
        close(m_xkbInfo.keymap_fd);

    xkb_context_unref(m_xkbContext);

    free((char*)m_xkbNames.rules);
    free((char*)m_xkbNames.model);
    free((char*)m_xkbNames.layout);
    free((char*)m_xkbNames.variant);
    free((char*)m_xkbNames.options);
}
Esempio n. 9
0
int main()
{
    xkb_rule_names names;
    names.rules = strdup("evdev");
    names.model = strdup("pc105");
    names.layout = strdup("us");
    names.variant = strdup("");
    names.options = strdup("");

    xkb_context *context = xkb_context_new(xkb_context_flags(0));
    if (context) {
        xkb_keymap * keymap = xkb_map_new_from_names(context, &names, xkb_map_compile_flags(0));
        if (keymap) {
            xkb_state *state = xkb_state_new(keymap);
            if (state)
                xkb_state_unref(state);
            xkb_map_unref(keymap);
        }
        xkb_context_unref(context);
    }

    return 0;
}
Esempio n. 10
0
void 
_ecore_wl_input_del(Ecore_Wl_Input *input)
{
   if (!input) return;

   _pointer_update_stop(input);

   if (input->cursor_name) eina_stringshare_del(input->cursor_name);
   input->cursor_name = NULL;

   if (input->touch_focus)
     {
        input->touch_focus = NULL;
     }

   if (input->pointer_focus)
     {
        Ecore_Wl_Window *win = NULL;

        if ((win = input->pointer_focus))
          win->pointer_device = NULL;

        input->pointer_focus = NULL;
     }

   if (input->keyboard_focus)
     {
        Ecore_Wl_Window *win = NULL;

        if ((win = input->keyboard_focus))
          win->keyboard_device = NULL;

        input->keyboard_focus = NULL;
     }

   if (input->data_types.data)
     {
        char **t;

        wl_array_for_each(t, &input->data_types)
          free(*t);
        wl_array_release(&input->data_types);
     }

   if (input->data_source) wl_data_source_destroy(input->data_source);
   input->data_source = NULL;

   if (input->drag_source) _ecore_wl_dnd_del(input->drag_source);
   input->drag_source = NULL;

   if (input->selection_source) _ecore_wl_dnd_del(input->selection_source);
   input->selection_source = NULL;

   if (input->data_device) wl_data_device_destroy(input->data_device);

   if (input->xkb.state)
     xkb_state_unref(input->xkb.state);
   if (input->xkb.keymap)
     xkb_map_unref(input->xkb.keymap);

   if (input->cursor_surface)
     wl_surface_destroy(input->cursor_surface);

   _ecore_wl_disp->inputs = eina_inlist_remove
      (_ecore_wl_disp->inputs, EINA_INLIST_GET(input));
   if (input->seat) wl_seat_destroy(input->seat);

   if (input->repeat.tmr) ecore_timer_del(input->repeat.tmr);
   input->repeat.tmr = NULL;

   free(input);
}
Esempio n. 11
0
static int uxkb_desc_init(struct kbd_desc **out,
			  const char *layout,
			  const char *variant,
			  const char *options)
{
	int ret;
	struct kbd_desc *desc;
	struct xkb_rule_names rmlvo = {
		.rules = "evdev",
		.model = "evdev",
		.layout = layout,
		.variant = variant,
		.options = options,
	};

	if (!out)
		return -EINVAL;

	desc = malloc(sizeof(*desc));
	if (!desc)
		return -ENOMEM;

	memset(desc, 0, sizeof(*desc));
	desc->ref = 1;
	desc->ops = &uxkb_desc_ops;

	desc->uxkb.ctx = xkb_context_new(0);
	if (!desc->uxkb.ctx) {
		ret = -ENOMEM;
		goto err_desc;
	}

	desc->uxkb.keymap = xkb_map_new_from_names(desc->uxkb.ctx, &rmlvo, 0);
	if (!desc->uxkb.keymap) {
		log_warn("failed to create keymap (%s, %s, %s), "
			 "reverting to default US keymap",
			 layout, variant, options);

		rmlvo.layout = "us";
		rmlvo.variant = "";
		rmlvo.options = "";

		desc->uxkb.keymap = xkb_map_new_from_names(desc->uxkb.ctx,
							   &rmlvo, 0);
		if (!desc->uxkb.keymap) {
			log_warn("failed to create keymap");
			ret = -EFAULT;
			goto err_ctx;
		}
	}

	log_debug("new keyboard description (%s, %s, %s)",
			layout, variant, options);
	*out = desc;
	return 0;

err_ctx:
	xkb_context_unref(desc->uxkb.ctx);
err_desc:
	free(desc);
	return ret;
}

static void uxkb_desc_ref(struct kbd_desc *desc)
{
	if (!desc || !desc->ref)
		return;

	++desc->ref;
}

static void uxkb_desc_unref(struct kbd_desc *desc)
{
	if (!desc || !desc->ref || --desc->ref)
		return;

	log_debug("destroying keyboard description");
	xkb_map_unref(desc->uxkb.keymap);
	xkb_context_unref(desc->uxkb.ctx);
	free(desc);
}

static int uxkb_desc_alloc(struct kbd_desc *desc, struct kbd_dev **out)
{
	struct kbd_dev *kbd;

	kbd = malloc(sizeof(*kbd));
	if (!kbd)
		return -ENOMEM;

	memset(kbd, 0, sizeof(*kbd));
	kbd->ref = 1;
	kbd->desc = desc;
	kbd->ops = &uxkb_dev_ops;

	kbd->uxkb.state = xkb_state_new(desc->uxkb.keymap);
	if (!kbd->uxkb.state) {
		free(kbd);
		return -ENOMEM;
	}

	kbd_desc_ref(desc);
	*out = kbd;
	return 0;
}

static void uxkb_keysym_to_string(uint32_t keysym, char *str, size_t size)
{
	xkb_keysym_get_name(keysym, str, size);
}