main neuswc / libswc / keyboard.h
  1/* swc: libswc/keyboard.h
  2 *
  3 * Copyright (c) 2013, 2014 Michael Forney
  4 *
  5 * Permission is hereby granted, free of charge, to any person obtaining a copy
  6 * of this software and associated documentation files (the "Software"), to deal
  7 * in the Software without restriction, including without limitation the rights
  8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9 * copies of the Software, and to permit persons to whom the Software is
 10 * furnished to do so, subject to the following conditions:
 11 *
 12 * The above copyright notice and this permission notice shall be included in
 13 * all copies or substantial portions of the Software.
 14 *
 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 21 * SOFTWARE.
 22 */
 23
 24#ifndef SWC_KEYBOARD_H
 25#define SWC_KEYBOARD_H
 26
 27#include "input.h"
 28
 29#include <wayland-util.h>
 30#include <xkbcommon/xkbcommon.h>
 31
 32/* Keycodes are offset by 8 in XKB. */
 33#define XKB_KEY(key) ((key) + 8)
 34
 35struct keyboard;
 36struct wl_client;
 37
 38struct key {
 39	struct press press;
 40	struct keyboard_handler *handler;
 41};
 42
 43struct keyboard_modifier_state {
 44	uint32_t depressed;
 45	uint32_t latched;
 46	uint32_t locked;
 47	uint32_t group;
 48};
 49
 50struct keyboard_handler {
 51	bool (*key)(struct keyboard *keyboard, uint32_t time, struct key *key,
 52	            uint32_t state);
 53	bool (*modifiers)(struct keyboard *keyboard,
 54	                  const struct keyboard_modifier_state *state);
 55
 56	struct wl_list link;
 57};
 58
 59struct xkb {
 60	struct xkb_context *context;
 61	struct xkb_state *state;
 62
 63	struct {
 64		struct xkb_keymap *map;
 65		int fd;
 66		uint32_t size;
 67		char *area;
 68	} keymap;
 69
 70	struct {
 71		uint32_t ctrl, alt, super, shift;
 72	} indices;
 73};
 74
 75struct keyboard {
 76	struct input_focus focus;
 77	struct input_focus_handler focus_handler;
 78	struct xkb xkb;
 79
 80	struct wl_array keys;
 81	struct wl_list handlers;
 82	struct keyboard_handler client_handler;
 83	struct wl_array client_keys;
 84
 85	struct keyboard_modifier_state modifier_state;
 86	uint32_t modifiers;
 87};
 88
 89struct keyboard *
 90keyboard_create(struct xkb_rule_names *names);
 91void
 92keyboard_destroy(struct keyboard *keyboard);
 93bool
 94keyboard_reset(struct keyboard *keyboard);
 95void
 96keyboard_set_focus(struct keyboard *keyboard, struct compositor_view *view);
 97struct wl_resource *
 98keyboard_bind(struct keyboard *keyboard, struct wl_client *client,
 99              uint32_t version, uint32_t id);
100void
101keyboard_handle_key(struct keyboard *keyboard, uint32_t time, uint32_t key,
102                    uint32_t state);
103
104#endif