wvkbd/keyboard.h

156 lines
4.9 KiB
C
Raw Permalink Normal View History

2021-08-25 23:45:59 +02:00
#ifndef __KEYBOARD_H
#define __KEYBOARD_H
#include "drw.h"
#define MAX_LAYERS 25
2020-09-11 01:25:28 -07:00
enum key_type;
enum key_modifier_type;
struct clr_scheme;
struct key;
struct layout;
struct kbd;
enum key_type {
Pad = 0, // Padding, not a pressable key
Code, // A normal key emitting a keycode
Mod, // A modifier key
Copy, // Copy key, copies the unicode value specified in code (creates and
// activates temporary keymap)
// used for keys that are not part of the keymap
Layout, // Layout switch to a specific layout
BackLayer, // Layout switch to the layout that was previously active
NextLayer, // Layout switch to the next layout in the layers sequence
Compose, // Compose modifier key, switches to a specific associated layout
// upon next keypress
EndRow, // Incidates the end of a key row
Last, // Indicated the end of a layout
2020-09-11 01:25:28 -07:00
};
/* Modifiers passed to the virtual_keyboard protocol. They are based on
* wayland's wl_keyboard, which doesn't document them.
*/
enum key_modifier_type {
NoMod = 0,
Shift = 1,
CapsLock = 2,
Ctrl = 4,
Alt = 8,
2020-09-11 01:25:28 -07:00
Super = 64,
AltGr = 128,
};
2022-01-08 16:23:51 -05:00
enum key_draw_type {
2023-09-06 09:28:09 +02:00
None = 0,
Unpress,
2022-01-08 16:23:51 -05:00
Press,
Swipe,
};
2020-09-11 01:25:28 -07:00
struct clr_scheme {
Color fg;
Color bg;
Color high;
Color swipe;
2020-09-11 01:25:28 -07:00
Color text;
char *font;
int rounding;
PangoFontDescription *font_description;
2020-09-11 01:25:28 -07:00
};
struct key {
2021-08-24 09:53:34 +02:00
const char *label; // primary label
const char *shift_label; // secondary label
const double width; // relative width (1.0)
2020-09-11 01:25:28 -07:00
const enum key_type type;
2021-08-24 09:53:34 +02:00
const uint32_t
code; /* code: key scancode or modifier name (see
* `/usr/include/linux/input-event-codes.h` for scancode names, and
* `keyboard.h` for modifiers)
* XKB keycodes are +8 */
struct layout *layout; // pointer back to the parent layout that holds this
// key
const uint32_t code_mod; /* modifier to force when this key is pressed */
2021-08-24 09:53:34 +02:00
uint8_t scheme; // index of the scheme to use
bool reset_mod; /* reset modifiers when clicked */
2020-09-11 01:25:28 -07:00
2021-08-24 09:53:34 +02:00
// actual coordinates on the surface (pixels), will be computed automatically
// for all keys
uint32_t x, y, w, h;
2020-09-11 01:25:28 -07:00
};
struct layout {
struct key *keys;
2021-08-24 09:53:34 +02:00
const char *keymap_name;
2021-08-24 13:08:49 +02:00
const char *name;
bool abc; //is this an alphabetical/abjad layout or not? (i.e. something that is a primary input layout)
2021-08-24 09:53:34 +02:00
uint32_t keyheight; // absolute height (pixels)
2020-09-11 01:25:28 -07:00
};
struct kbd {
2021-08-25 23:45:59 +02:00
bool debug;
2020-09-11 01:25:28 -07:00
struct layout *layout;
struct clr_scheme *schemes;
2020-09-11 01:25:28 -07:00
2021-08-24 13:08:49 +02:00
bool print;
bool print_intersect;
uint32_t w, h;
double scale;
double preferred_scale, preferred_fractional_scale;
2021-08-26 19:20:20 +02:00
bool landscape;
2020-09-11 01:25:28 -07:00
uint8_t mods;
2021-08-25 23:45:59 +02:00
uint8_t compose;
2020-09-11 01:25:28 -07:00
struct key *last_press;
struct key *last_swipe;
struct layout *prevlayout; //the previous layout, needed to keep track of keymap changes
2021-08-24 13:08:49 +02:00
size_t layer_index;
struct layout *last_abc_layout; //the last alphabetical layout to fall back to (may be further away than prevlayout)
size_t last_abc_index; //the layer index of the last alphabetical layout
2021-08-24 13:08:49 +02:00
struct layout *layouts;
enum layout_id *layers;
2021-08-26 19:20:20 +02:00
enum layout_id *landscape_layers;
2020-09-11 01:25:28 -07:00
struct drwsurf *surf;
2023-09-06 09:28:09 +02:00
struct drwsurf *popup_surf;
2020-09-11 01:25:28 -07:00
struct zwp_virtual_keyboard_v1 *vkbd;
2023-09-06 09:28:09 +02:00
uint32_t last_popup_x, last_popup_y, last_popup_w, last_popup_h;
2020-09-11 01:25:28 -07:00
};
void draw_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
uint32_t height, uint32_t border, Color color, int rounding);
void draw_over_inset(struct drwsurf *ds, uint32_t x, uint32_t y, uint32_t width,
uint32_t height, uint32_t border, Color color, int rounding);
2020-09-11 01:25:28 -07:00
void kbd_init(struct kbd *kb, struct layout *layouts,
char *layer_names_list, char *landscape_layer_names_list);
2021-08-25 23:45:59 +02:00
void kbd_init_layout(struct layout *l, uint32_t width, uint32_t height);
struct key *kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y);
size_t kbd_get_layer_index(struct kbd *kb, struct layout *l);
2021-08-25 23:45:59 +02:00
void kbd_unpress_key(struct kbd *kb, uint32_t time);
void kbd_release_key(struct kbd *kb, uint32_t time);
void kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y);
2021-08-25 23:45:59 +02:00
void kbd_press_key(struct kbd *kb, struct key *k, uint32_t time);
void kbd_print_key_stdout(struct kbd *kb, struct key *k);
2023-09-06 09:28:09 +02:00
void kbd_clear_last_popup(struct kbd *kb);
2022-01-08 16:23:51 -05:00
void kbd_draw_key(struct kbd *kb, struct key *k, enum key_draw_type);
2021-08-25 23:45:59 +02:00
void kbd_draw_layout(struct kbd *kb);
void kbd_resize(struct kbd *kb, struct layout *layouts, uint8_t layoutcount);
uint8_t kbd_get_rows(struct layout *l);
double kbd_get_row_length(struct key *k);
void kbd_next_layer(struct kbd *kb, struct key *k, bool invert);
void kbd_switch_layout(struct kbd *kb, struct layout *l, size_t layer_index);
2021-08-25 23:45:59 +02:00
void create_and_upload_keymap(struct kbd *kb, const char *name,
uint32_t comp_unichr, uint32_t comp_shift_unichr);
2021-08-25 23:45:59 +02:00
#ifndef LAYOUT
#error "make sure to define LAYOUT"
#endif
#include LAYOUT
#endif