Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ if ((NOT CONFIG_ZMK_SPLIT) OR CONFIG_ZMK_SPLIT_ROLE_CENTRAL)
target_sources(app PRIVATE src/conditional_layer.c)
target_sources(app PRIVATE src/endpoints.c)
target_sources(app PRIVATE src/events/endpoint_changed.c)
target_sources(app PRIVATE src/events/preferred_transport_changed.c)
target_sources(app PRIVATE src/hid_listener.c)
target_sources(app PRIVATE src/keymap.c)
target_sources(app PRIVATE src/events/layer_state_changed.c)
Expand Down
18 changes: 18 additions & 0 deletions app/include/zmk/events/preferred_transport_changed.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) 2026 The ZMK Contributors
*
* SPDX-License-Identifier: MIT
*/

#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.


#include <zmk/endpoints_types.h>
#include <zmk/event_manager.h>

struct zmk_preferred_transport_changed {
enum zmk_transport transport;
};

ZMK_EVENT_DECLARE(zmk_preferred_transport_changed);
5 changes: 4 additions & 1 deletion app/src/endpoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <zmk/events/ble_active_profile_changed.h>
#include <zmk/events/usb_conn_state_changed.h>
#include <zmk/events/endpoint_changed.h>
#include <zmk/events/preferred_transport_changed.h>

#include <zephyr/logging/log.h>

Expand Down Expand Up @@ -135,7 +136,8 @@ int zmk_endpoint_set_preferred_transport(enum zmk_transport transport) {

endpoints_save_preferred();

update_current_endpoint();
raise_zmk_preferred_transport_changed(
(struct zmk_preferred_transport_changed){.transport = preferred_transport});

return 0;
}
Expand Down Expand Up @@ -502,6 +504,7 @@ static int endpoint_listener(const zmk_event_t *eh) {
}

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.

#if IS_ENABLED(CONFIG_ZMK_USB)
ZMK_SUBSCRIPTION(endpoint_listener, zmk_usb_conn_state_changed);
#endif
Expand Down
10 changes: 10 additions & 0 deletions app/src/events/preferred_transport_changed.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright (c) 2026 The ZMK Contributors
*
* 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?

#include <zmk/events/preferred_transport_changed.h>

ZMK_EVENT_IMPL(zmk_preferred_transport_changed);
Loading