Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
9648b7a387 | ||
|
149702753f |
@ -75,6 +75,8 @@ control_msg_serialize(const struct control_msg *msg, unsigned char *buf) {
|
||||
buf[1] = msg->set_screen_power_mode.mode;
|
||||
return 2;
|
||||
case CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON:
|
||||
buf[1] = msg->back_or_screen_on.action;
|
||||
return 2;
|
||||
case CONTROL_MSG_TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
case CONTROL_MSG_TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
case CONTROL_MSG_TYPE_GET_CLIPBOARD:
|
||||
|
@ -66,6 +66,9 @@ struct control_msg {
|
||||
struct {
|
||||
enum screen_power_mode mode;
|
||||
} set_screen_power_mode;
|
||||
struct {
|
||||
enum android_keyevent_action action;
|
||||
} back_or_screen_on;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -99,9 +99,14 @@ action_menu(struct controller *controller, int actions) {
|
||||
|
||||
// turn the screen on if it was off, press BACK otherwise
|
||||
static void
|
||||
press_back_or_turn_screen_on(struct controller *controller) {
|
||||
press_back_or_turn_screen_on(struct controller *controller, int action) {
|
||||
assert(action == ACTION_DOWN || action == ACTION_UP);
|
||||
|
||||
struct control_msg msg;
|
||||
msg.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON;
|
||||
msg.back_or_screen_on.action = action == ACTION_DOWN
|
||||
? AKEY_EVENT_ACTION_DOWN
|
||||
: AKEY_EVENT_ACTION_UP;
|
||||
|
||||
if (!controller_push_msg(controller, &msg)) {
|
||||
LOGW("Could not request 'press back or turn screen on'");
|
||||
@ -521,31 +526,36 @@ input_manager_process_mouse_button(struct input_manager *im,
|
||||
// simulated from touch events, so it's a duplicate
|
||||
return;
|
||||
}
|
||||
if (event->type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (control && event->button == SDL_BUTTON_RIGHT) {
|
||||
press_back_or_turn_screen_on(im->controller);
|
||||
|
||||
// double-click on black borders resize to fit the device screen
|
||||
if (event->type == SDL_MOUSEBUTTONDOWN
|
||||
&& event->button == SDL_BUTTON_LEFT
|
||||
&& event->clicks == 2) {
|
||||
bool outside = is_outside_device_screen(im, event->x, event->y);
|
||||
if (outside) {
|
||||
screen_resize_to_fit(im->screen);
|
||||
return;
|
||||
}
|
||||
if (control && event->button == SDL_BUTTON_MIDDLE) {
|
||||
action_home(im->controller, ACTION_DOWN | ACTION_UP);
|
||||
return;
|
||||
}
|
||||
// double-click on black borders resize to fit the device screen
|
||||
if (event->button == SDL_BUTTON_LEFT && event->clicks == 2) {
|
||||
bool outside =
|
||||
is_outside_device_screen(im, event->x, event->y);
|
||||
if (outside) {
|
||||
screen_resize_to_fit(im->screen);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// otherwise, send the click event to the device
|
||||
}
|
||||
|
||||
if (!control) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->button == SDL_BUTTON_MIDDLE) {
|
||||
int action = event->type == SDL_MOUSEBUTTONDOWN ? ACTION_DOWN
|
||||
: ACTION_UP;
|
||||
action_home(im->controller, action);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->button == SDL_BUTTON_RIGHT) {
|
||||
int action = event->type == SDL_MOUSEBUTTONDOWN ? ACTION_DOWN
|
||||
: ACTION_UP;
|
||||
press_back_or_turn_screen_on(im->controller, action);
|
||||
return;
|
||||
}
|
||||
|
||||
struct control_msg msg;
|
||||
if (convert_mouse_button(event, im->screen, &msg)) {
|
||||
if (!controller_push_msg(im->controller, &msg)) {
|
||||
|
@ -140,14 +140,18 @@ static void test_serialize_inject_scroll_event(void) {
|
||||
static void test_serialize_back_or_screen_on(void) {
|
||||
struct control_msg msg = {
|
||||
.type = CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||
.back_or_screen_on = {
|
||||
.action = AKEY_EVENT_ACTION_UP,
|
||||
},
|
||||
};
|
||||
|
||||
unsigned char buf[CONTROL_MSG_SERIALIZED_MAX_SIZE];
|
||||
int size = control_msg_serialize(&msg, buf);
|
||||
assert(size == 1);
|
||||
assert(size == 2);
|
||||
|
||||
const unsigned char expected[] = {
|
||||
CONTROL_MSG_TYPE_BACK_OR_SCREEN_ON,
|
||||
AKEY_EVENT_ACTION_UP,
|
||||
};
|
||||
assert(!memcmp(buf, expected, sizeof(expected)));
|
||||
}
|
||||
|
@ -85,6 +85,13 @@ public final class ControlMessage {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static ControlMessage createBackOrScreenOn(int action) {
|
||||
ControlMessage msg = new ControlMessage();
|
||||
msg.type = TYPE_BACK_OR_SCREEN_ON;
|
||||
msg.action = action;
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static ControlMessage createEmpty(int type) {
|
||||
ControlMessage msg = new ControlMessage();
|
||||
msg.type = type;
|
||||
|
@ -13,6 +13,7 @@ public class ControlMessageReader {
|
||||
private static final int INJECT_TOUCH_EVENT_PAYLOAD_LENGTH = 21;
|
||||
private static final int INJECT_SCROLL_EVENT_PAYLOAD_LENGTH = 20;
|
||||
private static final int SET_SCREEN_POWER_MODE_PAYLOAD_LENGTH = 1;
|
||||
private static final int BACK_OR_SCREEN_ON_PAYLOAD_LENGTH = 1;
|
||||
|
||||
public static final int TEXT_MAX_LENGTH = 300;
|
||||
public static final int CLIPBOARD_TEXT_MAX_LENGTH = 4093;
|
||||
@ -73,6 +74,8 @@ public class ControlMessageReader {
|
||||
msg = parseSetScreenPowerMode();
|
||||
break;
|
||||
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
||||
msg = parseBackOrScreenOn();
|
||||
break;
|
||||
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
case ControlMessage.TYPE_COLLAPSE_NOTIFICATION_PANEL:
|
||||
case ControlMessage.TYPE_GET_CLIPBOARD:
|
||||
@ -164,6 +167,14 @@ public class ControlMessageReader {
|
||||
return ControlMessage.createSetScreenPowerMode(mode);
|
||||
}
|
||||
|
||||
private ControlMessage parseBackOrScreenOn() {
|
||||
if (buffer.remaining() < BACK_OR_SCREEN_ON_PAYLOAD_LENGTH) {
|
||||
return null;
|
||||
}
|
||||
int action = toUnsigned(buffer.get());
|
||||
return ControlMessage.createBackOrScreenOn(action);
|
||||
}
|
||||
|
||||
private static Position readPosition(ByteBuffer buffer) {
|
||||
int x = buffer.getInt();
|
||||
int y = buffer.getInt();
|
||||
|
@ -26,6 +26,9 @@ public class Controller {
|
||||
private final MotionEvent.PointerProperties[] pointerProperties = new MotionEvent.PointerProperties[PointersState.MAX_POINTERS];
|
||||
private final MotionEvent.PointerCoords[] pointerCoords = new MotionEvent.PointerCoords[PointersState.MAX_POINTERS];
|
||||
|
||||
private boolean backPressed;
|
||||
private boolean powerPressed;
|
||||
|
||||
public Controller(Device device, DesktopConnection connection) {
|
||||
this.device = device;
|
||||
this.connection = connection;
|
||||
@ -88,7 +91,7 @@ public class Controller {
|
||||
injectScroll(msg.getPosition(), msg.getHScroll(), msg.getVScroll());
|
||||
break;
|
||||
case ControlMessage.TYPE_BACK_OR_SCREEN_ON:
|
||||
pressBackOrTurnScreenOn();
|
||||
pressBackOrTurnScreenOn(msg.getAction());
|
||||
break;
|
||||
case ControlMessage.TYPE_EXPAND_NOTIFICATION_PANEL:
|
||||
device.expandNotificationPanel();
|
||||
@ -223,8 +226,33 @@ public class Controller {
|
||||
return device.injectInputEvent(event, InputManager.INJECT_INPUT_EVENT_MODE_ASYNC);
|
||||
}
|
||||
|
||||
private boolean pressBackOrTurnScreenOn() {
|
||||
int keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
|
||||
return injectKeycode(keycode);
|
||||
private boolean pressBackOrTurnScreenOn(int action) {
|
||||
int keycode = -1;
|
||||
if (action == KeyEvent.ACTION_UP) {
|
||||
// if BACK or POWER were pressed, this action is the corresponding release event (regardless of the screen state)
|
||||
if (backPressed) {
|
||||
keycode = KeyEvent.KEYCODE_BACK;
|
||||
backPressed = false;
|
||||
} else if (powerPressed) {
|
||||
keycode = KeyEvent.KEYCODE_POWER;
|
||||
powerPressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (keycode == -1) {
|
||||
keycode = device.isScreenOn() ? KeyEvent.KEYCODE_BACK : KeyEvent.KEYCODE_POWER;
|
||||
}
|
||||
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
if (keycode == KeyEvent.KEYCODE_BACK) {
|
||||
backPressed = true;
|
||||
powerPressed = false;
|
||||
} else {
|
||||
backPressed = false;
|
||||
powerPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return injectKeyEvent(action, keycode, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -145,6 +145,7 @@ public class ControlMessageReaderTest {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
DataOutputStream dos = new DataOutputStream(bos);
|
||||
dos.writeByte(ControlMessage.TYPE_BACK_OR_SCREEN_ON);
|
||||
dos.writeByte(KeyEvent.ACTION_UP);
|
||||
|
||||
byte[] packet = bos.toByteArray();
|
||||
|
||||
@ -152,6 +153,7 @@ public class ControlMessageReaderTest {
|
||||
ControlMessage event = reader.next();
|
||||
|
||||
Assert.assertEquals(ControlMessage.TYPE_BACK_OR_SCREEN_ON, event.getType());
|
||||
Assert.assertEquals(KeyEvent.ACTION_UP, event.getAction());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user