Skip to content

Commit 29e55e3

Browse files
committed
Merge branch 'maint/reduce-events'
2 parents d31aa5d + 445a392 commit 29e55e3

24 files changed

+232
-387
lines changed

src/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,13 @@ set(DBB-FIRMWARE-UI-SOURCES
7474
${CMAKE_SOURCE_DIR}/src/ui/components/trinary_input_string.c
7575
${CMAKE_SOURCE_DIR}/src/ui/components/waiting.c
7676
${CMAKE_SOURCE_DIR}/src/ui/components/screensaver.c
77-
${CMAKE_SOURCE_DIR}/src/ui/components/entry_screen.c
7877
${CMAKE_SOURCE_DIR}/src/ui/components/knight_rider.c
7978
${CMAKE_SOURCE_DIR}/src/ui/components/right_arrow.c
8079
${CMAKE_SOURCE_DIR}/src/ui/components/left_arrow.c
8180
${CMAKE_SOURCE_DIR}/src/ui/components/icon_button.c
8281
${CMAKE_SOURCE_DIR}/src/ui/components/confirm_gesture.c
8382
${CMAKE_SOURCE_DIR}/src/ui/components/label.c
8483
${CMAKE_SOURCE_DIR}/src/ui/components/confirm.c
85-
${CMAKE_SOURCE_DIR}/src/ui/components/confirm_button.c
8684
${CMAKE_SOURCE_DIR}/src/ui/components/keyboard_switch.c
8785
${CMAKE_SOURCE_DIR}/src/ui/components/orientation_arrows.c
8886
${CMAKE_SOURCE_DIR}/src/ui/components/info_centered.c

src/rust/bitbox02-sys/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,10 @@ const BITBOX02_SOURCES: &[&str] = &[
200200
"src/u2f/u2f_app.c",
201201
"src/u2f/u2f_packet.c",
202202
"src/ui/components/button.c",
203-
"src/ui/components/confirm_button.c",
204203
"src/ui/components/confirm_gesture.c",
205204
"src/ui/components/confirm_transaction.c",
206205
"src/ui/components/confirm.c",
207206
"src/ui/components/empty.c",
208-
"src/ui/components/entry_screen.c",
209207
"src/ui/components/icon_button.c",
210208
"src/ui/components/image.c",
211209
"src/ui/components/info_centered.c",

src/ui/components/confirm.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,19 @@ typedef struct {
3131
void* user_data;
3232
} data_t;
3333

34-
static void _dispatch_confirm(component_t* self)
34+
static void _on_confirm(void* user_data)
3535
{
36+
component_t* self = (component_t*)user_data;
3637
data_t* data = (data_t*)self->data;
3738
if (data->callback) {
3839
data->callback(true, data->user_data);
3940
data->callback = NULL;
4041
}
4142
}
4243

43-
static void _on_event(const event_t* event, component_t* component)
44+
static void _on_cancel(void* user_data)
4445
{
45-
if (event->id == EVENT_CONFIRM) {
46-
_dispatch_confirm(component);
47-
}
48-
}
49-
50-
static void _on_confirm(component_t* component)
51-
{
52-
component_t* self = component->parent;
53-
_dispatch_confirm(self);
54-
}
55-
56-
static void _on_cancel(component_t* component)
57-
{
58-
component_t* self = component->parent;
46+
component_t* self = (component_t*)user_data;
5947
data_t* data = (data_t*)self->data;
6048
if (data->callback) {
6149
data->callback(false, data->user_data);
@@ -71,7 +59,7 @@ static void _on_cancel(component_t* component)
7159
static const component_functions_t _component_functions = {
7260
.cleanup = ui_util_component_cleanup,
7361
.render = ui_util_component_render_subcomponents,
74-
.on_event = _on_event,
62+
.on_event = NULL,
7563
};
7664

7765
/********************************** Create Instance **********************************/
@@ -154,17 +142,18 @@ component_t* confirm_create(
154142
// Create buttons
155143
if (!params->accept_only) {
156144
ui_util_add_sub_component(
157-
confirm, icon_button_create(slider_position, ICON_BUTTON_CROSS, _on_cancel));
145+
confirm, icon_button_create(slider_position, ICON_BUTTON_CROSS, _on_cancel, confirm));
158146
}
159147
if (params->longtouch) {
160-
ui_util_add_sub_component(confirm, confirm_gesture_create());
148+
ui_util_add_sub_component(confirm, confirm_gesture_create(_on_confirm, confirm));
161149
} else {
162150
ui_util_add_sub_component(
163151
confirm,
164152
icon_button_create(
165153
slider_position,
166154
params->accept_is_nextarrow ? ICON_BUTTON_NEXT : ICON_BUTTON_CHECK,
167-
_on_confirm));
155+
_on_confirm,
156+
confirm));
168157
}
169158

170159
return confirm;

src/ui/components/confirm_button.c

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/ui/components/confirm_button.h

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/ui/components/confirm_gesture.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ typedef struct {
3636
bool confirmed; // Confirm event occurred
3737
uint16_t active_count; // Start at an offset to allow movement on first touch
3838
uint16_t bottom_arrow_slidein; // from zero to arrow height * SCALE
39+
void (*callback)(void* user_data);
40+
void* user_data;
3941
} confirm_data_t;
4042

4143
bool confirm_gesture_is_active(component_t* component)
@@ -84,9 +86,9 @@ static void _render(component_t* component)
8486

8587
// The user confirms when the top and bottom arrows touch
8688
if (y0 + arrow_height > y1 && !data->confirmed) {
87-
event_t event;
88-
event.id = EVENT_CONFIRM;
89-
emit_event(&event);
89+
if (data->callback) {
90+
data->callback(data->user_data);
91+
}
9092
data->confirmed = true;
9193
}
9294
}
@@ -155,7 +157,7 @@ static component_functions_t _component_functions = {
155157
/**
156158
* Creates a confirm_gesture component on the top slider.
157159
*/
158-
component_t* confirm_gesture_create(void)
160+
component_t* confirm_gesture_create(void (*callback)(void*), void* user_data)
159161
{
160162
confirm_data_t* data = malloc(sizeof(confirm_data_t));
161163
if (!data) {
@@ -167,6 +169,8 @@ component_t* confirm_gesture_create(void)
167169
data->confirmed = false;
168170
data->active_count = SCALE - 1;
169171
data->bottom_arrow_slidein = 0;
172+
data->callback = callback;
173+
data->user_data = user_data;
170174

171175
component_t* confirm_gesture = malloc(sizeof(component_t));
172176
if (!confirm_gesture) {

src/ui/components/confirm_gesture.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* Creates a confirm_gesture component on the top slider.
2525
* @param[in] parent The parent component.
2626
*/
27-
component_t* confirm_gesture_create(void);
27+
component_t* confirm_gesture_create(void (*callback)(void* user_data), void* user_data);
2828

2929
bool confirm_gesture_is_active(component_t* component);
3030

src/ui/components/confirm_transaction.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
#include "confirm_transaction.h"
16-
#include "confirm_button.h"
16+
#include "confirm_gesture.h"
1717
#include "icon_button.h"
1818
#include "label.h"
1919
#include "ui_images.h"
@@ -50,23 +50,22 @@ static void _render(component_t* component)
5050
}
5151
}
5252

53-
static void _on_event(const event_t* event, component_t* component)
53+
static void _cancel_cb(void* user_data)
5454
{
55-
if (event->id == EVENT_CONFIRM) {
56-
data_t* data = (data_t*)component->data;
57-
if (data->callback) {
58-
data->callback(true, data->user_data);
59-
data->callback = NULL;
60-
}
55+
component_t* self = (component_t*)user_data;
56+
data_t* data = (data_t*)self->data;
57+
if (data->callback != NULL) {
58+
data->callback(false, data->user_data);
59+
data->callback = NULL;
6160
}
6261
}
6362

64-
static void _cancel(component_t* cancel_button)
63+
static void _confirm_cb(void* user_data)
6564
{
66-
component_t* component = cancel_button->parent;
67-
data_t* data = (data_t*)component->data;
68-
if (data->callback != NULL) {
69-
data->callback(false, data->user_data);
65+
component_t* self = (component_t*)user_data;
66+
data_t* data = (data_t*)self->data;
67+
if (data->callback) {
68+
data->callback(true, data->user_data);
7069
data->callback = NULL;
7170
}
7271
}
@@ -79,7 +78,7 @@ static void _cancel(component_t* cancel_button)
7978
static const component_functions_t _component_functions = {
8079
.cleanup = ui_util_component_cleanup,
8180
.render = _render,
82-
.on_event = _on_event,
81+
.on_event = NULL,
8382
};
8483

8584
/********************************** Create Instance **********************************/
@@ -118,9 +117,15 @@ static component_t* _confirm_transaction_create(
118117
confirm->dimension.width = SCREEN_WIDTH;
119118
confirm->dimension.height = SCREEN_HEIGHT;
120119

121-
ui_util_add_sub_component(confirm, icon_button_create(top_slider, ICON_BUTTON_CROSS, _cancel));
120+
ui_util_add_sub_component(
121+
confirm, icon_button_create(top_slider, ICON_BUTTON_CROSS, _cancel_cb, confirm));
122122

123-
ui_util_add_sub_component(confirm, confirm_button_create(longtouch, ICON_BUTTON_NEXT));
123+
if (longtouch) {
124+
ui_util_add_sub_component(confirm, confirm_gesture_create(_confirm_cb, confirm));
125+
} else {
126+
ui_util_add_sub_component(
127+
confirm, icon_button_create(top_slider, ICON_BUTTON_NEXT, _confirm_cb, confirm));
128+
}
124129

125130
if (data->has_address) {
126131
ui_util_add_sub_component(

src/ui/components/entry_screen.c

Lines changed: 0 additions & 84 deletions
This file was deleted.

src/ui/components/entry_screen.h

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)