neuswc

patched neuswc library (tracked)
git clone https://git.daat.foo/neuswc.git
Log | Files | Refs | README | LICENSE

keyboard.h (3354B)


      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 
     35 struct keyboard;
     36 struct wl_client;
     37 
     38 struct key {
     39 	struct press press;
     40 	struct keyboard_handler *handler;
     41 };
     42 
     43 struct keyboard_modifier_state {
     44 	uint32_t depressed;
     45 	uint32_t latched;
     46 	uint32_t locked;
     47 	uint32_t group;
     48 };
     49 
     50 struct 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 
     59 struct 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 
     75 struct 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 
     89 struct keyboard *
     90 keyboard_create(struct xkb_rule_names *names);
     91 void
     92 keyboard_destroy(struct keyboard *keyboard);
     93 bool
     94 keyboard_reset(struct keyboard *keyboard);
     95 bool
     96 keyboard_set_names(struct keyboard *keyboard, struct xkb_rule_names *names);
     97 void
     98 keyboard_set_repeat(struct keyboard *keyboard, int32_t rate, int32_t delay);
     99 void
    100 keyboard_set_focus(struct keyboard *keyboard, struct compositor_view *view);
    101 struct wl_resource *
    102 keyboard_bind(struct keyboard *keyboard, struct wl_client *client,
    103               uint32_t version, uint32_t id);
    104 void
    105 keyboard_handle_key(struct keyboard *keyboard, uint32_t time, uint32_t key,
    106                     uint32_t state);
    107 /* for backends that get modifier state from outside */
    108 void
    109 keyboard_handle_modifiers(struct keyboard *keyboard, uint32_t depressed,
    110                           uint32_t latched, uint32_t locked, uint32_t group);
    111 /* swap the keymap and resend it */
    112 bool
    113 keyboard_set_keymap(struct keyboard *keyboard, struct xkb_keymap *map);
    114 
    115 #endif