Skip to content

feat(core) Add preferred transport changed event#3320

Open
yrb wants to merge 1 commit intozmkfirmware:mainfrom
yrb:preferred_transport_changed_event
Open

feat(core) Add preferred transport changed event#3320
yrb wants to merge 1 commit intozmkfirmware:mainfrom
yrb:preferred_transport_changed_event

Conversation

@yrb
Copy link
Copy Markdown

@yrb yrb commented Apr 5, 2026

Adds an event on preferred transport changing. The primary use of this is to drive display updates in the case the preferred transport changes but the active endpoint does not change.

PR check-list

  • Branch has a clean commit history
  • Additional tests are included, if changing behaviors/core code that is testable.
  • Proper Copyright + License headers added to applicable files (Generally, we stick to "The ZMK Contributors" for copyrights to help avoid churn when files get edited)
  • Pre-commit used to check formatting of files, commit messages, etc.
  • Includes any necessary documentation changes.

@yrb yrb requested a review from a team as a code owner April 5, 2026 20:17
Copy link
Copy Markdown
Contributor

@snoyer snoyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I tested with a custom display and it does solve the use-case of notifying when going between &out OUT_BLE and &out OUT_USB while only one of USB or BLE is available (meaning the active endpoint has nothing to change to, as mentioned in the description, and therefore no existing endpoint_changed event is fired).

Hopefully @joelspadin can do an actual review

Comment thread app/include/zmk/events/preferred_transport_changed.h Outdated
Comment thread app/src/events/preferred_transport_changed.c Outdated
Added an event for the preferred transport changing, this is primarily
to trigger display updates.
@yrb yrb force-pushed the preferred_transport_changed_event branch from bdc1ab8 to fe3bba3 Compare April 17, 2026 09:11

#pragma once

#include <zephyr/kernel.h>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this header used for anything? Nothing below looks like it uses this to me.

* SPDX-License-Identifier: MIT
*/

#include <zephyr/kernel.h>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This include doesn't seem to be used?

Comment thread app/src/endpoints.c
}

ZMK_LISTENER(endpoint_listener, endpoint_listener);
ZMK_SUBSCRIPTION(endpoint_listener, zmk_preferred_transport_changed);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit torn on this. On one hand, it does feel more elegant to have everything that could update the selected endpoint go through the event listener instead of some things using the event listener and others calling update_current_endpoint() directly. On the other, it's a bit more processing than is strictly necessary, and a different zmk_preferred_transport_changed listener could run before this one and see the updated preferred transport before the selected endpoint is updated to match (which shouldn't be an issue because anything that cares about the selected endpoint should also be listening for zmk_endpoint_changed, but it could potentially lead to something like displays showing inconsistent data for one frame).

I'd be interested to see what @petejohanson thinks of this.

Comment thread app/src/endpoints.c
}

static int endpoint_settings_commit(void) {
update_current_endpoint();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure when this runs relative to zmk_endpoints_init(), but if it happens afterwards, then we likely need to check whether endpoint_settings_set() changed preferred_transport and send the new event if so.

This could be done by creating a new static variable to store the endpoint that's loaded from settings, then here we would just call zmk_endpoint_set_preferred_transport() with that value, though that would use up 4 bytes of memory just for that, and it would unnecessarily call endpoints_save_preferred() even though the value doesn't need to be written to settings. Alternatively, we could simply check if preferred_transport != DEFAULT_TRANSPORT and fire the change event if so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants