summaryrefslogtreecommitdiff
path: root/app/include
diff options
context:
space:
mode:
authorKemoNine <mcrosson@users.noreply.github.com>2020-12-09 09:35:57 -0500
committerGitHub <noreply@github.com>2020-12-09 09:35:57 -0500
commit2427a4ab3308523200f9419316a10a75f237bb6c (patch)
tree9193a18fd51b26aa4eef1b0331e2ca021b20602d /app/include
parent4c92a4e50f317227ac6b086be8cde137d5c1fc4e (diff)
feature(keymaps): Keymap layer state event, highest layer API
* Fire an event w/ layer number, state, and timestamp when a layer is activated/deactivated. * Add `zmk_keymap_highest_layer_active()` query. Co-authored-by: KemoNine <mcrosson@kemonine.info>
Diffstat (limited to 'app/include')
-rw-r--r--app/include/zmk/events/layer-state-changed.h28
-rw-r--r--app/include/zmk/keymap.h5
2 files changed, 33 insertions, 0 deletions
diff --git a/app/include/zmk/events/layer-state-changed.h b/app/include/zmk/events/layer-state-changed.h
new file mode 100644
index 0000000..dc13ed6
--- /dev/null
+++ b/app/include/zmk/events/layer-state-changed.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2020 The ZMK Contributors
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#pragma once
+
+#include <zephyr.h>
+#include <zmk/event-manager.h>
+
+struct layer_state_changed {
+ struct zmk_event_header header;
+ u8_t layer;
+ bool state;
+ s64_t timestamp;
+};
+
+ZMK_EVENT_DECLARE(layer_state_changed);
+
+static inline struct layer_state_changed *create_layer_state_changed(u8_t layer, bool state) {
+ struct layer_state_changed *ev = new_layer_state_changed();
+ ev->layer = layer;
+ ev->state = state;
+ ev->timestamp = k_uptime_get();
+
+ return ev;
+}
diff --git a/app/include/zmk/keymap.h b/app/include/zmk/keymap.h
index b8f4969..88dc933 100644
--- a/app/include/zmk/keymap.h
+++ b/app/include/zmk/keymap.h
@@ -6,7 +6,12 @@
#pragma once
+typedef u32_t zmk_keymap_layers_state;
+
+u8_t zmk_keymap_layer_default();
+zmk_keymap_layers_state zmk_keymap_layer_state();
bool zmk_keymap_layer_active(u8_t layer);
+u8_t zmk_keymap_highest_layer_active();
int zmk_keymap_layer_activate(u8_t layer);
int zmk_keymap_layer_deactivate(u8_t layer);
int zmk_keymap_layer_toggle(u8_t layer);