-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(behaviors): Leader key #1380
Open
nickconway
wants to merge
3
commits into
zmkfirmware:main
Choose a base branch
from
nickconway:leader-key
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,151
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
/ { | ||
behaviors { | ||
/omit-if-no-ref/ leader: leader_key { | ||
compatible = "zmk,behavior-leader-key"; | ||
label = "LEADER"; | ||
#binding-cells = <0>; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) 2022 The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: Leader key behavior | ||
|
||
compatible: "zmk,behavior-leader-key" | ||
|
||
include: zero_param.yaml | ||
|
||
properties: | ||
timerless: | ||
type: boolean | ||
timeout-ms: | ||
type: int | ||
default: 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (c) 2022, The ZMK Contributors | ||
# SPDX-License-Identifier: MIT | ||
|
||
description: Leader sequence container | ||
|
||
compatible: "zmk,leader-sequences" | ||
|
||
child-binding: | ||
description: "A leader sequence" | ||
|
||
properties: | ||
bindings: | ||
type: phandle-array | ||
required: true | ||
key-positions: | ||
type: array | ||
required: true | ||
layers: | ||
type: array | ||
default: [-1] | ||
immediate-trigger: | ||
type: boolean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#pragma once | ||
|
||
void zmk_leader_activate(int32_t timeout, bool timeout_on_activation, uint32_t position); | ||
void zmk_leader_deactivate(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2022 The ZMK Contributors | ||
* | ||
* SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
#define DT_DRV_COMPAT zmk_behavior_leader_key | ||
|
||
#include <zephyr/device.h> | ||
#include <drivers/behavior.h> | ||
#include <zephyr/logging/log.h> | ||
|
||
#include <zmk/hid.h> | ||
#include <zmk/event_manager.h> | ||
#include <zmk/events/keycode_state_changed.h> | ||
#include <zmk/behavior.h> | ||
#include <zmk/leader.h> | ||
|
||
LOG_MODULE_DECLARE(zmk, CONFIG_ZMK_LOG_LEVEL); | ||
|
||
struct behavior_leader_key_config { | ||
int32_t timeout_ms; | ||
bool timerless; | ||
}; | ||
|
||
static int behavior_leader_key_init(const struct device *dev) { return 0; } | ||
|
||
static int on_keymap_binding_pressed(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
const struct device *dev = device_get_binding(binding->behavior_dev); | ||
const struct behavior_leader_key_config *cfg = dev->config; | ||
|
||
zmk_leader_activate(cfg->timeout_ms, cfg->timerless, event.position); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you press this again while it's active, should the behavior be to deactivate to interrupt it? |
||
return ZMK_BEHAVIOR_OPAQUE; | ||
} | ||
|
||
static int on_keymap_binding_released(struct zmk_behavior_binding *binding, | ||
struct zmk_behavior_binding_event event) { | ||
return 0; | ||
} | ||
|
||
static const struct behavior_driver_api behavior_leader_key_driver_api = { | ||
.binding_pressed = on_keymap_binding_pressed, | ||
.binding_released = on_keymap_binding_released, | ||
}; | ||
|
||
#define LEAD_INST(n) \ | ||
static struct behavior_leader_key_config behavior_leader_key_config_##n = { \ | ||
.timerless = DT_INST_PROP(n, timerless), .timeout_ms = DT_INST_PROP(n, timeout_ms)}; \ | ||
BEHAVIOR_DT_INST_DEFINE(n, behavior_leader_key_init, NULL, NULL, \ | ||
&behavior_leader_key_config_##n, POST_KERNEL, \ | ||
CONFIG_KERNEL_INIT_PRIORITY_DEFAULT, &behavior_leader_key_driver_api); | ||
|
||
DT_INST_FOREACH_STATUS_OKAY(LEAD_INST) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs documenting as well. Also see the other reviewers question.