Merge commands with other control events

Several commands were grouped under the same event type "command", with
a separate field to indicate the actual command.

Move these commands at the same level as other control events. It will
allow to implement commands with arguments.
This commit is contained in:
Romain Vimont
2019-05-30 16:07:24 +02:00
parent 3b4366e5bf
commit 63909fd10d
6 changed files with 29 additions and 60 deletions

View File

@@ -43,9 +43,11 @@ control_event_serialize(const struct control_event *event, unsigned char *buf) {
buffer_write32be(&buf[13], (uint32_t) event->scroll_event.hscroll);
buffer_write32be(&buf[17], (uint32_t) event->scroll_event.vscroll);
return 21;
case CONTROL_EVENT_TYPE_COMMAND:
buf[1] = event->command_event.action;
return 2;
case CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON:
case CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL:
case CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL:
// no additional data
return 1;
default:
LOGW("Unknown event type: %u", (unsigned) event->type);
return 0;

View File

@@ -17,13 +17,9 @@ enum control_event_type {
CONTROL_EVENT_TYPE_TEXT,
CONTROL_EVENT_TYPE_MOUSE,
CONTROL_EVENT_TYPE_SCROLL,
CONTROL_EVENT_TYPE_COMMAND,
};
enum control_event_command {
CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON,
CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL,
CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL,
CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON,
CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL,
CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL,
};
struct control_event {
@@ -47,9 +43,6 @@ struct control_event {
int32_t hscroll;
int32_t vscroll;
} scroll_event;
struct {
enum control_event_command action;
} command_event;
};
};

View File

@@ -99,9 +99,7 @@ action_menu(struct controller *controller, int actions) {
static void
press_back_or_turn_screen_on(struct controller *controller) {
struct control_event control_event;
control_event.type = CONTROL_EVENT_TYPE_COMMAND;
control_event.command_event.action =
CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON;
control_event.type = CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON;
if (!controller_push_event(controller, &control_event)) {
LOGW("Cannot turn screen on");
@@ -111,9 +109,7 @@ press_back_or_turn_screen_on(struct controller *controller) {
static void
expand_notification_panel(struct controller *controller) {
struct control_event control_event;
control_event.type = CONTROL_EVENT_TYPE_COMMAND;
control_event.command_event.action =
CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL;
control_event.type = CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL;
if (!controller_push_event(controller, &control_event)) {
LOGW("Cannot expand notification panel");
@@ -123,9 +119,7 @@ expand_notification_panel(struct controller *controller) {
static void
collapse_notification_panel(struct controller *controller) {
struct control_event control_event;
control_event.type = CONTROL_EVENT_TYPE_COMMAND;
control_event.command_event.action =
CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL;
control_event.type = CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL;
if (!controller_push_event(controller, &control_event)) {
LOGW("Cannot collapse notification panel");