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:
parent
3b4366e5bf
commit
63909fd10d
6 changed files with 29 additions and 60 deletions
|
@ -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[13], (uint32_t) event->scroll_event.hscroll);
|
||||||
buffer_write32be(&buf[17], (uint32_t) event->scroll_event.vscroll);
|
buffer_write32be(&buf[17], (uint32_t) event->scroll_event.vscroll);
|
||||||
return 21;
|
return 21;
|
||||||
case CONTROL_EVENT_TYPE_COMMAND:
|
case CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON:
|
||||||
buf[1] = event->command_event.action;
|
case CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
return 2;
|
case CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||||
|
// no additional data
|
||||||
|
return 1;
|
||||||
default:
|
default:
|
||||||
LOGW("Unknown event type: %u", (unsigned) event->type);
|
LOGW("Unknown event type: %u", (unsigned) event->type);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -17,13 +17,9 @@ enum control_event_type {
|
||||||
CONTROL_EVENT_TYPE_TEXT,
|
CONTROL_EVENT_TYPE_TEXT,
|
||||||
CONTROL_EVENT_TYPE_MOUSE,
|
CONTROL_EVENT_TYPE_MOUSE,
|
||||||
CONTROL_EVENT_TYPE_SCROLL,
|
CONTROL_EVENT_TYPE_SCROLL,
|
||||||
CONTROL_EVENT_TYPE_COMMAND,
|
CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON,
|
||||||
};
|
CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL,
|
||||||
|
CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL,
|
||||||
enum control_event_command {
|
|
||||||
CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON,
|
|
||||||
CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL,
|
|
||||||
CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct control_event {
|
struct control_event {
|
||||||
|
@ -47,9 +43,6 @@ struct control_event {
|
||||||
int32_t hscroll;
|
int32_t hscroll;
|
||||||
int32_t vscroll;
|
int32_t vscroll;
|
||||||
} scroll_event;
|
} scroll_event;
|
||||||
struct {
|
|
||||||
enum control_event_command action;
|
|
||||||
} command_event;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -99,9 +99,7 @@ action_menu(struct controller *controller, int actions) {
|
||||||
static void
|
static void
|
||||||
press_back_or_turn_screen_on(struct controller *controller) {
|
press_back_or_turn_screen_on(struct controller *controller) {
|
||||||
struct control_event control_event;
|
struct control_event control_event;
|
||||||
control_event.type = CONTROL_EVENT_TYPE_COMMAND;
|
control_event.type = CONTROL_EVENT_TYPE_BACK_OR_SCREEN_ON;
|
||||||
control_event.command_event.action =
|
|
||||||
CONTROL_EVENT_COMMAND_BACK_OR_SCREEN_ON;
|
|
||||||
|
|
||||||
if (!controller_push_event(controller, &control_event)) {
|
if (!controller_push_event(controller, &control_event)) {
|
||||||
LOGW("Cannot turn screen on");
|
LOGW("Cannot turn screen on");
|
||||||
|
@ -111,9 +109,7 @@ press_back_or_turn_screen_on(struct controller *controller) {
|
||||||
static void
|
static void
|
||||||
expand_notification_panel(struct controller *controller) {
|
expand_notification_panel(struct controller *controller) {
|
||||||
struct control_event control_event;
|
struct control_event control_event;
|
||||||
control_event.type = CONTROL_EVENT_TYPE_COMMAND;
|
control_event.type = CONTROL_EVENT_TYPE_EXPAND_NOTIFICATION_PANEL;
|
||||||
control_event.command_event.action =
|
|
||||||
CONTROL_EVENT_COMMAND_EXPAND_NOTIFICATION_PANEL;
|
|
||||||
|
|
||||||
if (!controller_push_event(controller, &control_event)) {
|
if (!controller_push_event(controller, &control_event)) {
|
||||||
LOGW("Cannot expand notification panel");
|
LOGW("Cannot expand notification panel");
|
||||||
|
@ -123,9 +119,7 @@ expand_notification_panel(struct controller *controller) {
|
||||||
static void
|
static void
|
||||||
collapse_notification_panel(struct controller *controller) {
|
collapse_notification_panel(struct controller *controller) {
|
||||||
struct control_event control_event;
|
struct control_event control_event;
|
||||||
control_event.type = CONTROL_EVENT_TYPE_COMMAND;
|
control_event.type = CONTROL_EVENT_TYPE_COLLAPSE_NOTIFICATION_PANEL;
|
||||||
control_event.command_event.action =
|
|
||||||
CONTROL_EVENT_COMMAND_COLLAPSE_NOTIFICATION_PANEL;
|
|
||||||
|
|
||||||
if (!controller_push_event(controller, &control_event)) {
|
if (!controller_push_event(controller, &control_event)) {
|
||||||
LOGW("Cannot collapse notification panel");
|
LOGW("Cannot collapse notification panel");
|
||||||
|
|
|
@ -9,16 +9,14 @@ public final class ControlEvent {
|
||||||
public static final int TYPE_TEXT = 1;
|
public static final int TYPE_TEXT = 1;
|
||||||
public static final int TYPE_MOUSE = 2;
|
public static final int TYPE_MOUSE = 2;
|
||||||
public static final int TYPE_SCROLL = 3;
|
public static final int TYPE_SCROLL = 3;
|
||||||
public static final int TYPE_COMMAND = 4;
|
public static final int TYPE_BACK_OR_SCREEN_ON = 4;
|
||||||
|
public static final int TYPE_EXPAND_NOTIFICATION_PANEL = 5;
|
||||||
public static final int COMMAND_BACK_OR_SCREEN_ON = 0;
|
public static final int TYPE_COLLAPSE_NOTIFICATION_PANEL = 6;
|
||||||
public static final int COMMAND_EXPAND_NOTIFICATION_PANEL = 1;
|
|
||||||
public static final int COMMAND_COLLAPSE_NOTIFICATION_PANEL = 2;
|
|
||||||
|
|
||||||
private int type;
|
private int type;
|
||||||
private String text;
|
private String text;
|
||||||
private int metaState; // KeyEvent.META_*
|
private int metaState; // KeyEvent.META_*
|
||||||
private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_* or COMMAND_*
|
private int action; // KeyEvent.ACTION_* or MotionEvent.ACTION_*
|
||||||
private int keycode; // KeyEvent.KEYCODE_*
|
private int keycode; // KeyEvent.KEYCODE_*
|
||||||
private int buttons; // MotionEvent.BUTTON_*
|
private int buttons; // MotionEvent.BUTTON_*
|
||||||
private Position position;
|
private Position position;
|
||||||
|
@ -62,10 +60,9 @@ public final class ControlEvent {
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ControlEvent createCommandControlEvent(int action) {
|
public static ControlEvent createSimpleControlEvent(int type) {
|
||||||
ControlEvent event = new ControlEvent();
|
ControlEvent event = new ControlEvent();
|
||||||
event.type = TYPE_COMMAND;
|
event.type = type;
|
||||||
event.action = action;
|
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ public class ControlEventReader {
|
||||||
private static final int KEYCODE_PAYLOAD_LENGTH = 9;
|
private static final int KEYCODE_PAYLOAD_LENGTH = 9;
|
||||||
private static final int MOUSE_PAYLOAD_LENGTH = 17;
|
private static final int MOUSE_PAYLOAD_LENGTH = 17;
|
||||||
private static final int SCROLL_PAYLOAD_LENGTH = 20;
|
private static final int SCROLL_PAYLOAD_LENGTH = 20;
|
||||||
private static final int COMMAND_PAYLOAD_LENGTH = 1;
|
|
||||||
|
|
||||||
public static final int TEXT_MAX_LENGTH = 300;
|
public static final int TEXT_MAX_LENGTH = 300;
|
||||||
private static final int RAW_BUFFER_SIZE = 1024;
|
private static final int RAW_BUFFER_SIZE = 1024;
|
||||||
|
@ -64,8 +63,10 @@ public class ControlEventReader {
|
||||||
case ControlEvent.TYPE_SCROLL:
|
case ControlEvent.TYPE_SCROLL:
|
||||||
controlEvent = parseScrollControlEvent();
|
controlEvent = parseScrollControlEvent();
|
||||||
break;
|
break;
|
||||||
case ControlEvent.TYPE_COMMAND:
|
case ControlEvent.TYPE_BACK_OR_SCREEN_ON:
|
||||||
controlEvent = parseCommandControlEvent();
|
case ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
|
case ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||||
|
controlEvent = ControlEvent.createSimpleControlEvent(type);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Ln.w("Unknown event type: " + type);
|
Ln.w("Unknown event type: " + type);
|
||||||
|
@ -123,14 +124,6 @@ public class ControlEventReader {
|
||||||
return ControlEvent.createScrollControlEvent(position, hScroll, vScroll);
|
return ControlEvent.createScrollControlEvent(position, hScroll, vScroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ControlEvent parseCommandControlEvent() {
|
|
||||||
if (buffer.remaining() < COMMAND_PAYLOAD_LENGTH) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int action = toUnsigned(buffer.get());
|
|
||||||
return ControlEvent.createCommandControlEvent(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Position readPosition(ByteBuffer buffer) {
|
private static Position readPosition(ByteBuffer buffer) {
|
||||||
int x = buffer.getInt();
|
int x = buffer.getInt();
|
||||||
int y = buffer.getInt();
|
int y = buffer.getInt();
|
||||||
|
|
|
@ -77,8 +77,14 @@ public class EventController {
|
||||||
case ControlEvent.TYPE_SCROLL:
|
case ControlEvent.TYPE_SCROLL:
|
||||||
injectScroll(controlEvent.getPosition(), controlEvent.getHScroll(), controlEvent.getVScroll());
|
injectScroll(controlEvent.getPosition(), controlEvent.getHScroll(), controlEvent.getVScroll());
|
||||||
break;
|
break;
|
||||||
case ControlEvent.TYPE_COMMAND:
|
case ControlEvent.TYPE_BACK_OR_SCREEN_ON:
|
||||||
executeCommand(controlEvent.getAction());
|
pressBackOrTurnScreenOn();
|
||||||
|
break;
|
||||||
|
case ControlEvent.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||||
|
device.expandNotificationPanel();
|
||||||
|
break;
|
||||||
|
case ControlEvent.TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||||
|
device.collapsePanels();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// do nothing
|
// do nothing
|
||||||
|
@ -170,20 +176,4 @@ public class EventController {
|
||||||
int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
|
int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
|
||||||
return injectKeycode(keycode);
|
return injectKeycode(keycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean executeCommand(int action) {
|
|
||||||
switch (action) {
|
|
||||||
case ControlEvent.COMMAND_BACK_OR_SCREEN_ON:
|
|
||||||
return pressBackOrTurnScreenOn();
|
|
||||||
case ControlEvent.COMMAND_EXPAND_NOTIFICATION_PANEL:
|
|
||||||
device.expandNotificationPanel();
|
|
||||||
return true;
|
|
||||||
case ControlEvent.COMMAND_COLLAPSE_NOTIFICATION_PANEL:
|
|
||||||
device.collapsePanels();
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
Ln.w("Unsupported command: " + action);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue