commit e100aafb05ec0ceedbca8e7afe0e23081c65c3a4
parent 450d43ff44f2ce39e0d74f72dc35447647faa74c
Author: Stacy Harper <contact@stacyharper.net>
Date: Thu, 26 Aug 2021 19:20:20 +0200
Add landscape layers
Diffstat:
4 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -29,5 +29,13 @@ static enum layout_id layers[] = {
NumLayouts //signals the last item, may not be omitted
};
+/* layers is an ordered list of layouts, used to cycle through */
+static enum layout_id landscape_layers[] = {
+ Landscape, //First layout is the default layout on startup
+ Special,
+ Emoji,
+ NumLayouts //signals the last item, may not be omitted
+};
+
#endif // config_def_h_INCLUDED
diff --git a/keyboard.c b/keyboard.c
@@ -97,7 +97,14 @@ void kbd_init(struct kbd *kb, struct layout * layouts, char * layer_names_list)
}
fprintf(stderr, "Found %d layers\n",i);
- kb->layout = &kb->layouts[kb->layers[kb->layer_index]];
+ enum layout_id layer;
+ if (kb->landscape) {
+ layer = kb->landscape_layers[kb->layer_index];
+ } else {
+ layer = kb->layers[kb->layer_index];
+ }
+
+ kb->layout = &kb->layouts[layer];
kb->prevlayout = kb->layout;
/* upload keymap */
@@ -236,10 +243,21 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
case NextLayer:
//switch to the next layout in the layer sequence
kb->layer_index++;
- if (kb->layers[kb->layer_index] == NumLayouts) {
+ enum layout_id layer;
+ if (kb->landscape) {
+ layer = kb->landscape_layers[kb->layer_index];
+ } else {
+ layer = kb->layers[kb->layer_index];
+ }
+ if (layer == NumLayouts) {
kb->layer_index = 0;
+ if (kb->landscape) {
+ layer = kb->landscape_layers[kb->layer_index];
+ } else {
+ layer = kb->layers[kb->layer_index];
+ }
}
- kbd_switch_layout(kb, &kb->layouts[kb->layers[kb->layer_index]]);
+ kbd_switch_layout(kb, &kb->layouts[layer]);
break;
case BackLayer:
//switch to the previously active layout
diff --git a/keyboard.h b/keyboard.h
@@ -84,6 +84,7 @@ struct kbd {
bool print;
uint32_t w, h, s;
+ bool landscape;
uint8_t mods;
uint8_t compose;
struct key *last_press;
@@ -92,6 +93,7 @@ struct kbd {
struct layout *layouts;
enum layout_id *layers;
+ enum layout_id *landscape_layers;
struct drwsurf *surf;
struct zwp_virtual_keyboard_v1 *vkbd;
diff --git a/main.c b/main.c
@@ -238,6 +238,21 @@ seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) {}
static void
display_handle_geometry(void *data, struct wl_output *wl_output, int x, int y, int physical_width, int physical_height, int subpixel, const char *make, const char *model, int transform)
{
+ if (transform % 2 == 0) {
+ keyboard.landscape = false;
+ } else {
+ keyboard.landscape = true;
+ }
+
+ enum layout_id layer;
+ if (keyboard.landscape) {
+ layer = keyboard.landscape_layers[0];
+ } else {
+ layer = keyboard.layers[0];
+ }
+
+ keyboard.layout = &keyboard.layouts[layer];
+ keyboard.prevlayout = keyboard.layout;
}
static void
@@ -379,6 +394,7 @@ main(int argc, char **argv) {
/* keyboard settings */
keyboard.layers = (enum layout_id *) &layers;
+ keyboard.landscape_layers = (enum layout_id *) &landscape_layers;
keyboard.scheme = scheme;
keyboard.layer_index = 0;
keyboard.scheme1 = scheme1;