commit 2fd0cfc89c188701d9385edd103b1fd1a84c1e21
parent 8a844c085772ccbaeef151e9dc1f0bbc36c013e6
Author: Maarten van Gompel <proycon@anaproy.nl>
Date: Tue, 24 Aug 2021 13:08:49 +0200
implemented configurable layers
Diffstat:
M | keyboard.h | | | 77 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ |
M | layout.mobintl.h | | | 133 | ++++++++++++++++++++++++++++++++++++++++++------------------------------------- |
M | main.c | | | 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- |
3 files changed, 199 insertions(+), 85 deletions(-)
diff --git a/keyboard.h b/keyboard.h
@@ -6,14 +6,17 @@ struct layout;
struct kbd;
enum key_type {
- Pad = 0,
- Code,
- Mod,
- Layout,
- EndRow,
- Last,
- Compose,
- Copy,
+ 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
};
/* Modifiers passed to the virtual_keyboard protocol. They are based on
@@ -61,18 +64,24 @@ struct key {
struct layout {
struct key *keys;
const char *keymap_name;
+ const char *name;
uint32_t keyheight; // absolute height (pixels)
};
struct kbd {
struct layout *layout;
- struct layout *prevlayout;
struct clr_scheme scheme;
struct clr_scheme scheme1;
+ bool print;
uint32_t w, h;
uint8_t mods;
struct key *last_press;
+ struct layout *prevlayout;
+ size_t layer_index;
+
+ enum layout_ids *layers;
+ struct layout **layouts;
struct drwsurf *surf;
struct zwp_virtual_keyboard_v1 *vkbd;
@@ -82,6 +91,7 @@ static inline void draw_inset(struct drwsurf *d, uint32_t x, uint32_t y,
uint32_t width, uint32_t height, uint32_t border,
uint32_t color);
+static void kbd_init(struct kbd *kb);
static void kbd_init_layout(struct layout *l, uint32_t width, uint32_t height);
static struct key *kbd_get_key(struct kbd *kb, uint32_t x, uint32_t y);
static void kbd_unpress_key(struct kbd *kb, uint32_t time);
@@ -92,6 +102,20 @@ static void kbd_resize(struct kbd *kb, uint32_t w, uint32_t h,
struct layout *layouts, uint8_t layoutcount);
static uint8_t kbd_get_rows(struct layout *l);
static double kbd_get_row_length(struct key *k);
+static void kbd_switch_layout(struct kbd *kb, struct layout *l);
+
+void
+kbd_switch_layout(struct kbd *kb, struct layout *l) {
+ const struct layout * prevlayout = kb->prevlayout;
+ kb->prevlayout = kb->layout;
+ kb->layout = l;
+ if ((!prevlayout) ||
+ (strcmp(prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
+ fprintf(stderr, "Switching to keymap %s\n", kb->layout->keymap_name);
+ create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
+ }
+ kbd_draw_layout(kb);
+}
uint8_t
kbd_get_rows(struct layout *l) {
@@ -106,6 +130,14 @@ kbd_get_rows(struct layout *l) {
return rows + 1;
}
+
+void kbd_init(struct kbd *kb) {
+ kb->layout = kb->layouts[kb->layer_index];
+
+ /* upload keymap */
+ create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
+}
+
void
kbd_init_layout(struct layout *l, uint32_t width, uint32_t height) {
uint32_t x = 0, y = 0;
@@ -237,7 +269,12 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
kbd_draw_key(kb, k, kb->mods & k->code);
zwp_virtual_keyboard_v1_modifiers(kb->vkbd, kb->mods, 0, 0, 0);
break;
+ case Layout:
+ //switch to the layout determined by the key
+ kbd_switch_layout(kb, k->layout);
+ break;
case Compose:
+ //switch to the associated layout determined by the *next* keypress
if (compose == 0) {
compose = 1;
} else {
@@ -245,16 +282,21 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
}
kbd_draw_key(kb, k, (bool)compose);
break;
- case Layout:
- kb->layout = k->layout;
- if ((!kb->prevlayout) ||
- (strcmp(kb->prevlayout->keymap_name, kb->layout->keymap_name) != 0)) {
- fprintf(stderr, "Switching to keymap %s\n", kb->layout->keymap_name);
- create_and_upload_keymap(kb->layout->keymap_name, 0, 0);
+ case NextLayer:
+ //switch to the next layout in the layer sequence
+ kb->layer_index++;
+ if (kb->layers[kb->layer_index] == NumLayouts) {
+ kb->layer_index = 0;
}
- kb->prevlayout = kb->layout;
- kbd_draw_layout(kb);
+ kbd_switch_layout(kb, kb->layouts[kb->layer_index]);
+ break;
+ case BackLayer:
+ //switch to the previously active layout
+ if (kb->prevlayout)
+ kbd_switch_layout(kb, kb->prevlayout);
+ break;
case Copy:
+ //copy code as unicode chr by setting a temporary keymap
kb->last_press = k;
kbd_draw_key(kb, k, true);
fprintf(stderr, "pressing copy key\n");
@@ -317,7 +359,6 @@ kbd_resize(struct kbd *kb, uint32_t w, uint32_t h, struct layout *layouts,
drwsurf_resize(d, w, h);
for (int i = 0; i < layoutcount; i++) {
- fprintf(stderr, "i=%d\n", i);
kbd_init_layout(&layouts[i], w, h);
}
kbd_draw_layout(kb);
diff --git a/layout.mobintl.h b/layout.mobintl.h
@@ -9,15 +9,8 @@
/* spacing between keys */
#define KBD_KEY_BORDER 2
-#include "keymap.mobintl.h"
-#include "keyboard.h"
-
-/* font (see `man fonts-conf` for instructions) */
-static const char *fc_font_pattern =
- "Monospace:size=16:antialias=true:hinting=true";
-
/* layout declarations */
-enum layout_names {
+enum layout_ids {
Full = 0,
Special,
Simple,
@@ -64,6 +57,23 @@ enum layout_names {
NumLayouts,
};
+/* layers is an ordered list of layouts, used to cycle through */
+enum layout_ids layers[] = {
+ Full, //First layout is the default layout on startup
+ Special,
+ Simple,
+ Cyrillic,
+ NumLayouts //signals the last item, may not be omitted
+};
+
+#include "keymap.mobintl.h"
+#include "keyboard.h"
+
+/* font (see `man fonts-conf` for instructions) */
+static const char *fc_font_pattern =
+ "Monospace:size=16:antialias=true:hinting=true";
+
+
static struct key keys_full[], keys_special[], keys_simple[], keys_cyrillic[],
keys_compose_a[], keys_compose_e[], keys_compose_y[], keys_compose_u[],
keys_compose_i[], keys_compose_o[], keys_compose_q[], keys_compose_w[],
@@ -78,10 +88,11 @@ static struct key keys_full[], keys_special[], keys_simple[], keys_cyrillic[],
keys_compose_cyr_che[], keys_compose_cyr_g[], keys_compose_cyr_k[];
static struct layout layouts[NumLayouts] = {
- [Full] = {keys_full, "latin"}, // third parameter is the keymap name
- [Special] = {keys_special, "latin"},
- [Simple] = {keys_simple, "latin"},
- [Cyrillic] = {keys_cyrillic, "cyrillic"},
+ [Full] = {keys_full, "latin", "full"}, // second parameter is the keymap name
+ // third parameter is the layout name
+ [Special] = {keys_special, "latin", "special"},
+ [Simple] = {keys_simple, "latin", "simple"},
+ [Cyrillic] = {keys_cyrillic, "cyrillic", "cyrillic"},
[ComposeA] = {keys_compose_a, "latin"},
[ComposeE] = {keys_compose_e, "latin"},
[ComposeY] = {keys_compose_y, "latin"},
@@ -123,12 +134,13 @@ static struct layout layouts[NumLayouts] = {
[ComposeCyrK] = {keys_compose_cyr_k, "cyrillic"},
};
-const enum layout_names DefaultLayout = Full;
/* keyboard settings */
static struct kbd keyboard = {
/* default layout */
- .layout = &layouts[DefaultLayout],
+ .layouts = &layouts,
+ .layers = &layers,
+ .layer_index = 0,
.scheme =
{
/* colors */
@@ -239,7 +251,7 @@ static struct key keys_full[] = {
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Sym", "Sym", 1.0, Layout, 0, &layouts[Special], .scheme = 1},
+ {"Sym", "Sym", 1.0, NextLayer, .scheme = 1},
{"Alt", "Alt", 1.0, Mod, Alt, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -299,8 +311,7 @@ static struct key keys_special[] = {
{"⌫", "⌫", 1.0, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0,
- &layouts[(DefaultLayout == Simple) ? Full : Simple], .scheme = 1},
+ {"Abc", "Abc", 1.0, NextLayer, .scheme = 1},
{"Alt", "Alt", 1.0, Mod, Alt, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -349,8 +360,7 @@ static struct key keys_simple[] = {
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0,
- &layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, NextLayer, .scheme = 1},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA, &layouts[ComposeMath]},
{"", "", 4.0, Code, KEY_SPACE},
@@ -416,8 +426,7 @@ static struct key keys_cyrillic[] = {
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0,
- &layouts[(DefaultLayout == Cyrillic) ? Full : DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, NextLayer, .scheme = 1},
{"Cmp", "Cmp", 1.0, Compose, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -447,7 +456,7 @@ static struct key keys_compose_a[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer, .scheme = 1},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -475,7 +484,7 @@ static struct key keys_compose_e[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout]},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -496,7 +505,7 @@ static struct key keys_compose_y[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -524,7 +533,7 @@ static struct key keys_compose_u[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -552,7 +561,7 @@ static struct key keys_compose_o[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -581,7 +590,7 @@ static struct key keys_compose_i[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -623,7 +632,7 @@ static struct key keys_compose_q[] = {
{"😴", "", 1.0, Copy, 0x1f634, 0, 0},
{"⌫", "⌫", 2.0, Code, KEY_BACKSPACE},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout]},
+ {"Abc", "Abc", 1.0, BackLayer},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 5.0, Code, KEY_SPACE},
{".", "?", 1.0, Code, KEY_DOT},
@@ -640,7 +649,7 @@ static struct key keys_compose_w[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -662,7 +671,7 @@ static struct key keys_compose_r[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -686,7 +695,7 @@ static struct key keys_compose_t[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -705,7 +714,7 @@ static struct key keys_compose_p[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -730,7 +739,7 @@ static struct key keys_compose_s[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -752,7 +761,7 @@ static struct key keys_compose_d[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -771,7 +780,7 @@ static struct key keys_compose_f[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -792,7 +801,7 @@ static struct key keys_compose_g[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -813,7 +822,7 @@ static struct key keys_compose_h[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -832,7 +841,7 @@ static struct key keys_compose_j[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -853,7 +862,7 @@ static struct key keys_compose_k[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -875,7 +884,7 @@ static struct key keys_compose_l[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -897,7 +906,7 @@ static struct key keys_compose_z[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -917,7 +926,7 @@ static struct key keys_compose_x[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -941,7 +950,7 @@ static struct key keys_compose_c[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -959,7 +968,7 @@ static struct key keys_compose_v[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -978,7 +987,7 @@ static struct key keys_compose_b[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1002,7 +1011,7 @@ static struct key keys_compose_n[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer, .scheme = 1},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1021,7 +1030,7 @@ static struct key keys_compose_m[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[DefaultLayout], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1040,7 +1049,7 @@ static struct key keys_compose_cyr_i[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1058,7 +1067,7 @@ static struct key keys_compose_cyr_j[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1076,7 +1085,7 @@ static struct key keys_compose_cyr_e[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1094,7 +1103,7 @@ static struct key keys_compose_cyr_u[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1112,7 +1121,7 @@ static struct key keys_compose_cyr_l[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1130,7 +1139,7 @@ static struct key keys_compose_cyr_n[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1149,7 +1158,7 @@ static struct key keys_compose_cyr_che[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1168,7 +1177,7 @@ static struct key keys_compose_cyr_tse[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1186,7 +1195,7 @@ static struct key keys_compose_cyr_g[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1204,7 +1213,7 @@ static struct key keys_compose_cyr_k[] = {
{"", "", 7, Pad},
{"⌫", "⌫", 1.5, Code, KEY_BACKSPACE, .scheme = 1},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0, &layouts[Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_EQUAL},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1236,8 +1245,7 @@ static struct key keys_compose_math[] = {
{"_", "_", 1, Code, KEY_MINUS, 0, Shift},
{"", "", 2, Pad},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0,
- &layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA, &layouts[ComposeMath]},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1267,8 +1275,7 @@ static struct key keys_compose_punctuation[] = {
{",", ",", 1, Code, KEY_COMMA},
{"", "", 2, Pad},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0,
- &layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA, &layouts[ComposeMath]},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1294,8 +1301,7 @@ static struct key keys_compose_bracket[] = {
{"⇧", "⇧", 2, Mod, Shift, .scheme = 1},
{"", "", 8, Pad},
{"", "", 0.0, EndRow},
- {"Abc", "Abc", 1.0, Layout, 0,
- &layouts[(DefaultLayout == Simple) ? Special : Cyrillic], .scheme = 1},
+ {"Abc", "Abc", 1.0, BackLayer},
{"Ctr", "Ctr", 1.0, Mod, Ctrl, .scheme = 1},
{",", "'", 1.0, Code, KEY_COMMA, &layouts[ComposeMath]},
{"", "", 4.0, Code, KEY_SPACE},
@@ -1303,3 +1309,4 @@ static struct key keys_compose_bracket[] = {
{"Enter", "Enter", 2.0, Code, KEY_ENTER, .scheme = 1},
{"", "", 0.0, Last},
};
+
diff --git a/main.c b/main.c
@@ -135,6 +135,19 @@ static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
#endif
#include LAYOUT
+char *
+estrdup(const char *s)
+{
+ char *p;
+
+ if (!(p = strdup(s))) {
+ fprintf(stderr, "strdup:");
+ exit(6);
+ }
+
+ return p;
+}
+
void
wl_touch_down(void *data, struct wl_touch *wl_touch, uint32_t serial,
uint32_t time, struct wl_surface *surface, int32_t id,
@@ -296,8 +309,62 @@ create_and_upload_keymap(const char *name, uint32_t comp_unichr,
free((void *)keymap_str);
}
+void
+usage(char *argv0)
+{
+ fprintf(stderr, "usage: %s [-hov] [-H height] [-fn font] [-l layers] [-s initial_layer]\n", argv0);
+ fprintf(stderr, "Options:\n");
+ fprintf(stderr, " -D - Enable debug\n");
+ fprintf(stderr, " -o - Print press keys to standard output\n");
+ fprintf(stderr, " -l - Comma separated list of layers\n");
+ fprintf(stderr, " -H [int] - Height in pixels\n");
+ fprintf(stderr, " -fn [font] - Set font (Xft, e.g: DejaVu Sans:bold:size=20)\n");
+}
+
int
main(int argc, char **argv) {
+ /* parse command line arguments */
+ int i;
+ char *layer_names_list = NULL;
+ char *tmp;
+ uint32_t height = KBD_PIXEL_HEIGHT;
+
+ if ((tmp = getenv("WVKBD_LAYERS")))
+ layer_names_list = estrdup(tmp);
+ if ((tmp = getenv("WVKBD_HEIGHT")))
+ height = atoi(tmp);
+
+
+ for (i = 1; argv[i]; i++) {
+ if (!strcmp(argv[i], "-v")) {
+ printf("wvkbd-%s", VERSION);
+ exit(0);
+ } else if (!strcmp(argv[i], "-h")) {
+ usage(argv[0]);
+ exit(0);
+ } else if (!strcmp(argv[i], "-l")) {
+ if (i >= argc - 1) {
+ usage(argv[0]);
+ exit(1);
+ }
+ if (layer_names_list)
+ free(layer_names_list);
+ layer_names_list = estrdup(argv[++i]);
+ } else if (!strcmp(argv[i], "-H")) {
+ if (i >= argc - 1) {
+ usage(argv[0]);
+ exit(1);
+ }
+ height = atoi(argv[++i]);
+ } else if (!strcmp(argv[i], "-o")) {
+ keyboard.print = true;
+ } else {
+ fprintf(stderr, "Invalid argument: %s\n", argv[i]);
+ usage(argv[0]);
+ exit(1);
+ }
+ }
+
/* connect to compositor */
display = wl_display_connect(NULL);
if (display == NULL) {
@@ -326,8 +393,7 @@ main(int argc, char **argv) {
keyboard.vkbd =
zwp_virtual_keyboard_manager_v1_create_virtual_keyboard(vkbd_mgr, seat);
- /* upload keymap */
- create_and_upload_keymap(layouts[DefaultLayout].keymap_name, 0, 0);
+ kbd_init(&keyboard);
/* assign kbd state */
keyboard.surf = &draw_surf;
@@ -340,9 +406,9 @@ main(int argc, char **argv) {
layer_surface = zwlr_layer_shell_v1_get_layer_surface(
layer_shell, draw_surf.surf, wl_output, layer, namespace);
- zwlr_layer_surface_v1_set_size(layer_surface, 0, KBD_PIXEL_HEIGHT);
+ zwlr_layer_surface_v1_set_size(layer_surface, 0, height);
zwlr_layer_surface_v1_set_anchor(layer_surface, anchor);
- zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, KBD_PIXEL_HEIGHT);
+ zwlr_layer_surface_v1_set_exclusive_zone(layer_surface, height);
zwlr_layer_surface_v1_set_keyboard_interactivity(layer_surface, false);
zwlr_layer_surface_v1_add_listener(layer_surface, &layer_surface_listener,
NULL);