Index: libs/ui/chooser_action_handler_wheel.c |
— | — | @@ -32,6 +32,12 @@ |
33 | 33 | const struct chooser_action_handler_wheel_params* params;
|
34 | 34 | params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
35 | 35 | if (params->version != CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION) return -1;
|
| 36 | + data->actionhandlerdata = malloc(sizeof(struct chooser_action_handler_wheel_data));
|
| 37 | + if (!data->actionhandlerdata) return -2;
|
| 38 | + struct chooser_action_handler_wheel_data* adata;
|
| 39 | + adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
|
| 40 | + adata->timeout_remaining = params->timeout_initial;
|
| 41 | + adata->lasttick = USEC_TIMER;
|
36 | 42 | return 0;
|
37 | 43 | }
|
38 | 44 |
|
— | — | @@ -41,8 +47,11 @@ |
42 | 48 | {
|
43 | 49 | const struct chooser_action_handler_wheel_params* params;
|
44 | 50 | params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
| 51 | + struct chooser_action_handler_wheel_data* adata;
|
| 52 | + adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
|
45 | 53 | if (params->eventfilter && params->eventfilter(data, event, which, value))
|
46 | 54 | return CHOOSER_RESULT_OK;
|
| 55 | + adata->timeout_remaining = params->timeout_idle;
|
47 | 56 | int spi = params->stepsperitem;
|
48 | 57 | switch (event)
|
49 | 58 | {
|
— | — | @@ -79,6 +88,28 @@ |
80 | 89 | return CHOOSER_RESULT_OK;
|
81 | 90 | }
|
82 | 91 |
|
| 92 | +static enum chooser_result chooser_action_handler_wheel_handletick(struct chooser_data* data)
|
| 93 | +{
|
| 94 | + const struct chooser_action_handler_wheel_params* params;
|
| 95 | + params = (const struct chooser_action_handler_wheel_params*)(data->info->actionhandlerparams);
|
| 96 | + struct chooser_action_handler_wheel_data* adata;
|
| 97 | + adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
|
| 98 | + if (adata->timeout_remaining == TIMEOUT_BLOCK) return CHOOSER_RESULT_OK;
|
| 99 | + long time = USEC_TIMER;
|
| 100 | + adata->timeout_remaining -= time - adata->lasttick;
|
| 101 | + adata->lasttick = time;
|
| 102 | + if (adata->timeout_remaining < 0)
|
| 103 | + {
|
| 104 | + if (params->timeout_item == CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_NULL)
|
| 105 | + return CHOOSER_RESULT_CANCEL;
|
| 106 | + else if (params->timeout_item != CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_KEEP)
|
| 107 | + data->selected = &data->info->items[params->timeout_item];
|
| 108 | + return CHOOSER_RESULT_FINISHED;
|
| 109 | + }
|
| 110 | + if (params->tick_force_redraw) return CHOOSER_RESULT_REDRAW;
|
| 111 | + return CHOOSER_RESULT_OK;
|
| 112 | +}
|
| 113 | +
|
83 | 114 | static int chooser_action_handler_wheel_stepsperitem(struct chooser_data* data)
|
84 | 115 | {
|
85 | 116 | const struct chooser_action_handler_wheel_params* params;
|
— | — | @@ -86,13 +117,18 @@ |
87 | 118 | return params->stepsperitem;
|
88 | 119 | }
|
89 | 120 |
|
| 121 | +static void chooser_ction_handler_wheel_destroy(struct chooser_data* data)
|
| 122 | +{
|
| 123 | + free(data->actionhandlerdata);
|
| 124 | +}
|
90 | 125 |
|
| 126 | +
|
91 | 127 | const struct chooser_action_handler chooser_action_handler_wheel =
|
92 | 128 | {
|
93 | 129 | .version = CHOOSER_ACTION_HANDLER_VERSION,
|
94 | 130 | .init = chooser_action_handler_wheel_init,
|
95 | 131 | .handleevent = chooser_action_handler_wheel_handleevent,
|
96 | | - .handletick = NULL,
|
| 132 | + .handletick = chooser_action_handler_wheel_handletick,
|
97 | 133 | .stepsperitem = chooser_action_handler_wheel_stepsperitem,
|
98 | | - .destroy = NULL
|
| 134 | + .destroy = chooser_ction_handler_wheel_destroy
|
99 | 135 | };
|
Index: libs/ui/chooser_action_handler_wheel.h |
— | — | @@ -38,6 +38,9 @@ |
39 | 39 | CHOOSER_ACTION_HANDLER_WHEEL_ACTION_CANCEL
|
40 | 40 | };
|
41 | 41 |
|
| 42 | +#define CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_NULL -1
|
| 43 | +#define CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_KEEP -2
|
| 44 | +
|
42 | 45 | #define CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION 1
|
43 | 46 |
|
44 | 47 | struct chooser_action_handler_wheel_params
|
— | — | @@ -45,11 +48,21 @@ |
46 | 49 | int version;
|
47 | 50 | int stepsperitem;
|
48 | 51 | bool (*eventfilter)(struct chooser_data* data, enum button_event event, int which, int value);
|
| 52 | + long timeout_initial;
|
| 53 | + long timeout_idle;
|
| 54 | + int timeout_item;
|
| 55 | + bool tick_force_redraw;
|
49 | 56 | int buttoncount;
|
50 | 57 | enum chooser_action_handler_wheel_action buttonmap[];
|
51 | 58 | };
|
52 | 59 |
|
| 60 | +struct chooser_action_handler_wheel_data
|
| 61 | +{
|
| 62 | + long timeout_remaining;
|
| 63 | + long lasttick;
|
| 64 | +};
|
53 | 65 |
|
| 66 | +
|
54 | 67 | extern const struct chooser_action_handler chooser_action_handler_wheel;
|
55 | 68 |
|
56 | 69 |
|